! ANSYS REVISION 5.2, MAGSOLV.MAC, Modified on 95/06/26, (SID) = 1.4
/uis,msgpop,3
/gopr
*get,_nops,active,,prkey
*get,_mnu,active,,menu
*get,_arout,active,,rout
/out,mvpsol,out
/nerr,0,1e7,-1
!*if,_arout,ne,21,then 
 finish
 /solu
!*endif
*if,_mg1,eq,1,then
 /gst,off
*endif

 antyp,static
/COM,   MACRO FOR SOLVING ELECTROMAGNETIC FIELD PROBLEMS
/COM,
/COM,   *** ASSUMPTIONS
/COM,         All nodes and elements are selected prior to executing macro
/COM,         
/COM,   *** INPUT PARAMETERS
/COM,       ARG1 = THREE DIMENSIONAL FORMULATION
/COM,              (OPTIONS:0 (MVP), 1 (MVP-RSP), 2(RSP), 3(DSP), 4(GSP))
/COM,              If default, its check the types of elements which are
/com,              present in the model.
/com,                 if sourc36 are present=> uses DSP
/com,                 if 96 & no 36         => uses RSP
/com,                 if 96 & 97            => uses MVP-RSP
/com,                 if 97 & no 96         => uses MVP only 
/com,                 if 2D                 => uses MVP
/com,              To use GSP, "4" must be used.
/COM,       ARG2 = NO. RAMPED ITERATIONS, 1ST LOAD STEP (MVP)
/COM,              (OPTIONS:-1 (SKIP RAMPED L.S.), "n" (n ITERATIONS)
/COM,              (DEFAULT = 5)
/COM,       ARG3 = CONVERGENCE CRITERIA, CSG  (MVP)
/COM,              (DEFAULT = 1E-3)
/COM,       ARG4 = CONVERGENCE CRITERIA, FLUX (MSP)
/COM,              (DEFAULT = 1E-3)
/COM,       ARG5 = MAXIMUM NUMBER OF EQUILIBRIUM ITERATIONS
/COM,              (DEFAULT = 25) 
/COM,       ARG6 = ISSUE BIOT COMMAND ("NEW" OPTION ONLY)
/COM,               (OPTIONS:0 (no), 1 (yes)
/COM,              (DEFAULT = 0) 
/COM,
/COM,       VALID FOR ALL STATIC MAGNETICS ANALYSES
/COM,
/COM,   *** ANSYS REVISION 5.2 UPDATE 1 3/29/95

*get,_unit,active,,solu,emunit      ! 1=mks, 2=cgs, 3=user
*get,_mu,active,,solu,muzro
*get,_dimn,active,,solu,dimn        ! 1=axisym, 2=planar, 3=3d 
*stat
!  set default parameter values
*if,arg2,eq,0,then
 arg2=2
*endif
*if,arg3,eq,0,then
 arg3=1e-2
*endif
*if,arg4,eq,0,then
 arg4=1e-3
*endif
*if,arg5,eq,0,then
 arg5=25
*endif
arg6=1

!  /out,scratch
*if,_dimn,eq,3,then
 !  check for option to use certain courc36 elements for 3D
 *if,no_curr,eq,1,then
  /com, no contribution from any current sourc36
  esel,none
  esel,,ename,,36
  cm,uce_36,elem
 *elseif,no_curr,eq,2,then
  /com, only contributions from 36's which are active
  esel,r,ename,,36
  cm,ce_36,elem
  esel,,ename,,36
  cmsel,u,ce_36
  cm,uce_36,elem
  cmdel,ce_36
 *endif
 !nsle
 !eplo
*endif



/com, determine if current sources are present (sourc36) if so , then
/com, use the dsp, not the rsp, check other combinations also

*if,arg1,eq,0,then
 esel,none
 esel,,ename,,96
 *get,ecnt96,elem,,count
 *if,ecnt96,gt,0,then
   arg1=2
 *endif
 esel,none
 esel,,ename,,36
 *get,ecnt36,elem,,count
 *if,ecnt36,gt,0,then
    arg1=3
 *endif
 esel,none
 esel,,ename,,97
 *get,ecnt97,elem,,count
 *if,ecnt96*ecnt97,gt,0,then
    arg1=1
 *endif

 *if,ecnt96,eq,0,then
   *if,ecnt97,ne,0,then
     arg1=0
   *endif
 *endif

 *if,_dimn,ne,3,then
  arg1=0
 *endif
*endif

*msg,info,arg1
solution  type:  %i


*if,_mg1,eq,0,then
 alls
 sfedel,all,all,all
 bfdel,all,mvdi
 esel,,mat,,5
 cm,s_iron,elem
 esel,,mat,,2,3
 cm,r_iron,elem
 fmagbc,'r_iron'
 fmagbc,'s_iron'
 /out,mvpsol,out,,append
*endif

nsel,all
esel,all

*if,runlinr,eq,0,then
 /com, determine if problem is nonlinear (_nonlin=0 (linear), =1 (nonlinear))
 *get,_elec,elem,,count
 *set,_matm
 *dim,_matm,,_elec
 /uis,msgpop,3
 *do,_nmat,1,_elec
  *get,_mxelem,elem,,num,max
  *if,_mxelem,eq,0,exit
  *get,_matm(_nmat),elem,_mxelem,attr,mat
  _nonlin=1
  *get,_bht,bh,_matm(_nmat),type         !       6/23/95
  *if,_bht,gt,0,exit
  _nonlin=0
  esel,u,mat,,_matm(_nmat)
 *enddo
 _nmat=_nmat-1
*else
 tbdel,bh,all
 _nonlin=0
*endif
esel,all
nsel,all

*stat,_nonlin
/uis,msgpop
/uis,msgpop,3


*if,_dimn,ne,3,then                    ! 2-d mvp
 *if,_nonlin,eq,0,then
  outres,all,last
  solve
 *else
  *if,arg2,ne,-1,then
   nsubs,arg2
   kbc,0
   neqit,1
   outres,all,none
   solve
   kbc,1
   cnvtol,csg,,arg3
   neqit,arg5
   nsubs,1
   outres,all,last
   solve
  *else
   kbc,1
   cnvtol,csg,,arg3
   neqit,arg5
   nsubs,1
   outres,all,last
   solve
  *endif
 *endif
*endif

*if,_dimn,eq,3,then                    ! 3-d mvp
 *if,arg1,eq,0,then
  *if,_nonlin,eq,0,then
   outres,all,last
   solve
  *else
   *if,arg2,ne,-1,then
    nsubs,arg2
    kbc,0
    neqit,1
    outres,all,none
    solve
    kbc,1
    cnvtol,csg,,arg3
    cnvtol,amps,-1
    neqit,arg5
    nsubs,1
    outres,all,last
    solve
   *else
    kbc,1
    cnvtol,csg,,arg3
    cnvtol,amps,-1
    neqit,arg5
    nsubs,1
    outres,all,last
    solve
   *endif
  *endif
 *endif
*endif

*if,_dimn,eq,3,then                    ! 3-d mvp-rsp       
 *if,arg1,eq,1,then
  *if,arg6,eq,1,then
   /com, 3-d mvp-rsp 
   *if,no_curr,gt,0,then
    cmsel,u,uce_36
   *endif
   biot,new
  *endif
  *if,_nonlin,eq,0,then
   outres,all,last
   solve
  *else
   *if,arg2,ne,-1,then
    nsubs,arg2
    kbc,0
    neqit,1
    outres,all,none
    solve
    kbc,1
    cnvtol,csg,,arg3
    cnvtol,amps,-1
    cnvtol,flux,,arg4
    neqit,arg5
    nsubs,1
    outres,all,last
    solve
   *else
    kbc,1
    cnvtol,csg,,arg3
    cnvtol,amps,-1
    cnvtol,flux,,arg4
    neqit,arg5
    nsubs,1
    outres,all,last
    solve
   *endif
  *endif
 *endif
*endif

*if,_dimn,eq,3,then                    ! 3-d rsp
 *if,arg1,eq,2,then
  *if,arg6,eq,1,then
   /com, 3-d rsp  
   *if,no_curr,gt,0,then
    cmsel,u,uce_36
   *endif
   biot,new
  *endif
   eqslv,front         !  11/17/01
  *if,s_jcg,eq,1,then        ! 3/31/01
   eqslv,jcg
  *elseif,s_spar,eq,1,then
   eqslv,sparse
  *elseif,s_pcg,eq,1,then
   eqslv,pcg
  *endif
  *if,_nonlin,eq,0,then
   outres,all,last
   magopt,0
   solve
  *else
   outres,all,last
   cnvtol,flux,,arg4
   neqit,arg5
   magopt,0
   nropt,full,,on
   solve
  *endif
 *endif
*endif

_val=abs(_dimn-3)+abs(arg1-3)
*if,_val,lt,.001,then                    ! 3-d dsp
  /com,  DSP
  *if,arg6,eq,1,then
   /com, 3-d dsp  
   *if,no_curr,gt,0,then
    cmsel,u,uce_36
   *endif
   biot,new
  *endif
  eqslv,front         !  11/17/01
  *if,s_jcg,eq,1,then        ! 3/31/01
   eqslv,jcg
  *elseif,s_spar,eq,1,then
   eqslv,sparse
  *elseif,s_pcg,eq,1,then
   eqslv,pcg
  *endif
  *if,_nonlin,eq,0,then
   magopt,2
   outres,all,none
   solve
   magopt,3
   outres,all,last
   solve
  *else
   magopt,2
   outres,all,none
   solve
   magopt,3
   cnvtol,flux,,arg4
   outres,all,last
   neqit,arg5
   nropt,full,,on
   solve
  *endif
*endif

_val=abs(_dimn-3)+abs(arg1-4)
*if,_val,lt,.001,then                    ! 3-d gsp
  *if,arg6,eq,1,then
   /com, 3-d gsp  
   *if,no_curr,gt,0,then
    cmsel,u,uce_36
   *endif
   biot,new
  *endif
  eqslv,front         !  11/17/01
  *if,s_jcg,eq,1,then        ! 3/31/01
   eqslv,jcg
  *elseif,s_spar,eq,1,then
   eqslv,sparse
  *elseif,s_pcg,eq,1,then
   eqslv,pcg
  *endif
  *if,_nonlin,eq,0,then
   outres,all,none
   magopt,1
   solve
   magopt,2
   outres,all,none
   solve
   magopt,3
   outres,all,last
   solve
  *else
   cnvtol,flux,,arg4
   outres,all,none
   neqit,arg5
   nropt,full,,on
   magopt,1
   solve
   magopt,2
   outres,all,none
   solve
   magopt,3
   cnvtol,flux,,arg4
   outres,all,last
   neqit,arg5
   nropt,full,,on
   solve
  *endif
*endif

*get,_cumls,active,,solu,ncmls
*get,_cumit,active,,solu,ncmit
*get,_cnvv,active,,solu,cscv
*get,_cnvs,active,,solu,mfcv
/nopr
*if,_ok,ne,1,then
 /out,magsolv,out
 *msg,info
%/___________ MAGNETICS SOLUTION SUMMARY ______________
 *if,arg1,lt,1,then
  *msg,info
%/Formulation option: MVP
  *elseif,arg1,eq,1,then
  *msg,info
%/Formulation option: MVP-RSP
  *elseif,arg1,eq,2,then
  *msg,info
%/Formulation option: RSP
  *elseif,arg1,eq,3,then
  *msg,info
%/Formulation option: DSP
  *elseif,arg1,eq,4,then
  *msg,info
%/Formulation option: GSP
 *endif
 *msg,info,_cumls
%/Solution data load step number = %g
 *msg,info,_cumit
%/Solution cumulative iteration number = %g
 *if,_nonlin,eq,1,then
  *if,arg1,le,1,then
  *msg,info,_cnvv
%/Current segment convergence value = %g
  *msg,info,arg3
Current segment convergence tolerance = %g
 *else
  *msg,info,_cnvs
%/Magnetic flux convergence value = %g
  *msg,info,arg4
Magnetic flux convergence tolerance = %g
  *endif
 *endif
 *if,arg6,eq,1,then
  *msg,info
%/Biot Savart Integration calculation performed
 *endif
 *msg,info
%/_____________________________________________________
/out,mvpsol,out,,append
*endif
*if,_ok,ne,1,then
 *list,magsolv,out
 *if,_mnu,ne,0,then
  *if,_nomsg,eq,0,then
  *uilist,magsolv,out
  *endif
 *endif
*endif
_unit=
_dimn=
_mu=
_cumls=
_cumit=
_cnvv=
_cnvs=
_nonlin=
_matm=
_nmat=
_mxelem=
_bht=
_elec=

_mnu=
_arout=
_ok=
_tr_cal=0
*if,_mg1,eq,1,then
  /gst,on
*endif
*if,_nops,eq,0,then
 /nopr
 _nops=
 *else
 _nops=
 /go
*endif
/out
! cmdel,uce_36
/gopr