/nopr
/out,scratch
/com
/com *** BEMCAP Command Macro ***   Version March 18, 2003
/com
/com *** Calculates the capacitance between two electrodes
/com *** using Trefftz BEM 
/com ***********************************************************************
/com   ARGUMENTS
/com
/com   ARG1 = Merging radius
/com ***********************************************************************
!
_targ1=ARG1           ! Temporary ARG variables
!
/out
!
!----------------- First Analysis ----------------
!--------------- V1 = 1.0, V2 = 1.0 -------------
!
save
!
*get,_anmodu,active,,rout
 *if,anmodu,ne,21,then
  /out,scratch
  finish
  /SOLU                          ! enter solver if not there already
  /out
 *endif
!
ANTYPE,STAT 
ALLSEL
!
cmsel,s,elec1
d,all,volt,1.0
alls
cmsel,u,elec1
d,all,volt,1.0
alls
!
tzegen,,,,,,,,,2         ! create Trefftz model
!
/SOLU
!
/tst,t9testt1,7,_targ1     ! merging
!
SOLVE
fini
!
/post1
*get,_q1a,TREF,,SMQ1
*get,_q2a,TREF,,SMQ2
fini
!
parsav,new,param,tmp
!
!----------------- Second Analysis ---------------
!--------------- V1 = 1.0, V2 = -1.0 -------------
!
/clear,nostart
resume
parres,new,param,tmp
!
*get,_anmodu,active,,rout
 *if,anmodu,ne,21,then
  /out,scratch
  finish
  /SOLU                          ! enter solver if not there already
  /out
 *endif
!
ANTYPE,STAT 
ALLSEL
!
cmsel,s,elec1
d,all,volt,1.0
alls
cmsel,u,elec1
d,all,volt,-1.0
alls
!
fini
!
tzegen,,,,,,,,,2         ! create Trefftz model
!
/SOLU
!
/tst,t9testt1,7,_targ1   ! merging
!
SOLVE
fini
!
/post1
*get,_q1b,TREF,,SMQ1
*get,_q2b,TREF,,SMQ2
fini
!
!-------------- Capacitance Calculation -----------
!
_c12=(_q1a-_q1b)/2.0
_c11=(_q1a+_q1b)/2.0
_c21=(_q2a+_q2b)/2.0
_c22=(_q2a-_q2b)/2.0
!
_cap=(_c11*_c22-_c12*_c12)/(_c11+_c22+2.0*_c12)
_cap=_cap*16*atan(1.0)*8.854e-6
!
_check=_q2b-_c21+_c22
!
*vwrite,_q1a
('Q1a = ',f10.4)
*vwrite,_q2a
('Q2a = ',f10.4)
*vwrite,_q1b
('Q1b = ',f10.4)
*vwrite,_q2b
('Q2b = ',f10.4)
*vwrite,_c11
('c11 = ',f10.4)
*vwrite,_c12
('c12 = ',f10.4)
*vwrite,_c21
('c21 = ',f10.4)
*vwrite,_c22
('c22 = ',f10.4)
*vwrite,_cap
('Total Capacitance = ',f10.7)

!
/delete,param,tmp
!
! delete local parameters
_targ1=
_q1a=
_q2a=
_q1b=
_q2b=
_c11=
_c12=
_c22=
_c21=
_cap=

! *****************  End of BEMCAP.MAC  *******************
