/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   ARG2 = Voltage U1a
/com   ARG3 = Voltage U1b
/com   ARG4 = Voltage U2a
/com   ARG5 = Voltage U2b
/com ***********************************************************************
!
_targ1=ARG1           ! Temporary ARG variables
_targ2=ARG2
_targ3=ARG3
_targ4=ARG4
_targ5=ARG5
!
/out
!
!----------------- First Analysis ----------------
!--------------- V1 = U1a, V2 = U2a --------------
!
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,_targ2
alls
cmsel,u,elec1
d,all,volt,_targ3
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 = U1b, V2 = U2b --------------
!
/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,_targ4
alls
cmsel,u,elec1
d,all,volt,_targ5
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=(_q1b*_targ2-_q1a*_targ4)/(_targ5*_targ2-_targ3*_targ4)
_c11=_q1a/_targ2-_c12*_targ3/_targ2
_c21=(_q2b*_targ3-_q2a*_targ5)/(_targ4*_targ3-_targ2*_targ5)
_c22=_q2a/_targ3-_c21*_targ2/_targ3
!
_cap=(_c11*_c22-_c12*_c12)/(_c11+_c22+2.0*_c12)
_cap=_cap*16*atan(1.0)*8.854e-6
!
*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=
_targ2=
_targ3=
_targ4=
_targ5=
_q1a=
_q2a=
_q1b=
_q2b=
_c11=
_c12=
_c22=
_c21=
_cap=

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