! ANSYS REVISION 5.3, fmagbx.MAC, Modified on 95/09/21, (SID) = 3.1
/gopr
/out,data
!   fmagbx.mac
!   Macro to apply the magnetic boundary conditions (MXWF and MVDI)
!   arg1  = first component name
!   arg2  = 2nd component name
!   arg3  = 3rd component name
!   arg4  = 4th component name
!   arg5  = 5th component name
!   arg6  = 6th component name
!   arg7  = 7th component name
!   arg8  = 8th component name
!   arg9  = 9th component name
!
! This macro generates a character array _cmpn which contains
! the names of the components for which force conditions were 
! applied.
!  
!           ANSYS Revision 5.3
!
*set,_elmtd
*dim,_elmtd,,3
_nodo=0
*get,_rout,active,,rout
*if,_rout,ne,17,then
 *if,_rout,ne,21,then
 _nodo=10      !    
 fini
 /solu
 *endif
*endif
!   /nerr,0,1e5,-1
!  *if,_nodo,eq,1,:end
*if,_nodo,eq,0,then
*get,_dimn,active,,solu,dimn        ! 1=axisym, 2=planar, 3=3d
*get,_mnu,active,,menu
_iappl=0
*set,_cmpn
*dim,_cmpn,char,9
_cmpn(1)='  ','  ','  ','  ','  ','  ','  ','  ','  '
/uis,msgpop,3
/nerr,0,1e5,-1
!     start of new code   c_5/8/95
_arg1=arg1
*get,_cchk,parm,_arg1,type
*if,_cchk,eq,0,then
 *if,_mnu,eq,1,then
 *msg,warn
  Component name must be input to apply force boundary conditions
 *else
 *msg,warn 
 Component name must be input (and enclosed in single quotes)
 *endif
*endif
*if,_cchk,ge,3,then
_cmpn(1)=arg1
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif

_arg1=arg2
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(2)=arg2
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif


_arg1=arg3
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(3)=arg3
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif


_arg1=arg4
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(4)=arg4
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif


_arg1=arg5
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(5)=arg5
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif


_arg1=arg6
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(6)=arg6
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif


_arg1=arg7
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(7)=arg7
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif

_arg1=arg8
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(8)=arg8
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif


_arg1=arg9
*get,_cchk,parm,_arg1,type
*if,_cchk,ge,3,then
_cmpn(9)=arg9
*elseif,_arg1,ne,0,then
 *msg,warn
 The Component name must consist of valid character string
*endif

!     end of new code   c_5/8/95

!   *stat,_cmpn

*set,_actm
*dim,_actm,,9


cm,_curei,elem
cm,_curni,node

!/nerr,0,1e4,-1
*do,_icom,1,9
!   /nopr

_errlv=0
_nodo=0
*if,_cmpn(_icom),eq,' ',then
  _nodo=1
  _errlv=_errlv+1
*endif

*if,_nodo,eq,0,then

*get,_type,comp,%_cmpn(_icom)%,type
*if,_type,eq,0,then
!   this is NOT a valid component
     *msg,warn,_cmpn(_icom)
     Component %c is not defined.
      _nodo=1
      _errlv=_errlv+1
      _elnum=0
*else
!   check for elements
   cmsel,,%_cmpn(_icom)%
   *get,_elnum,elem,,count
   *if,_elnum,eq,0,then
    *msg,warn,_cmpn(_icom)
    Component %c has no elements associated with it.&
    No force boundary conditions were applied to this component
    _cmpn(_icom)='  '
   *endif
*endif

*if,_elnum,ne,0,then
nsle
esln
cmsel,u,%_cmpn(_icom)%
*get,_elnum1,elem,,count
!  check the surrounding elements, make sure they have free 
!  space permeability
cm,_curel1,elem
*do,_icom1,1,_elnum1
!    /com, top of the loop on elements _elnum1
_nodo=0
*get,_elnum2,elem,,count
*if,_elnum2,eq,0,exit
*get,_elmx2,elem,,num,max
*get,_elmatc,elem,_elmx2,attr,mat
*get,_elmtd(1),murx,_elmatc,,,const,1
*get,_elmtd(2),mury,_elmatc,,,const,1
*if,_dimn,eq,3,then
  *get,_elmtd(3),murz,_elmatc,,,const,1
*endif
!   *vscfun,_magflg,sum,_elmtd(1)
_imatlm=2
*if,_dimn,eq,3,then
_imatlm=3
*endif
*do,_imat1,1,_imatlm
!   /nopr
 *if,_elmtd(_imat1),ne,0,then
  *if,_elmtd(_imat1),gt,1,then
   _nodo=2
   _errlv=_errlv+1
  *endif
 *endif
*enddo
_bh11=0
*get,_bh11,bh,_elmatc,type      !    6/3#2
*if,_bh11,ne,0,then
   _nodo=2
   _errlv=_errlv+1
*endif
*if,_elmtd(1)+_elmtd(2)+_elmtd(3),eq,0,then
  *if,_bh11,eq,0,then
    _nodo=3
  *endif
*elseif,_elmtd(2),ne,0,then
  *if,_elmtd(1),eq,0,then
    _nodo=2
    _errlv=_errlv+1
  *endif
*endif

*if,_dimn,eq,3,then
 *if,_elmtd(3),ne,0,then
  *if,_elmtd(1)*_elmtd(2),eq,0,then
    _nodo=2
    _errlv=_errlv+1
  *endif
 *endif
*endif

*if,_nodo,eq,2,then
 *msg,warn,_elmatc,_cmpn(_icom)
 Some of the elements (Material %i ) surrounding the part&
 do not correspond to free space. No force boundary&
 conditions applied for component %c
*endif

*if,_nodo,eq,3,then
 *msg,warn,_cmpn(_icom),_elmatc,_elmatc
 Some of the elements surrounding the part ( %c ) do not have&
 material properties (Material %i ). Be sure that Material %i has&
 free space permeability assigned.
_nodo=0
*endif

cmsel,,_curel1
esel,u,mat,,_elmatc
cm,_curel1,elem

*enddo


*if,_errlv,eq,0,then
keyw,fmagbx,1              ! set keyword for FMAGSUM

!  apply MVDI & Maxwells stress conditions
cmsel,,%_cmpn(_icom)%
nsle
bf,all,mvdi,1
nsel,r,ext
esln
cmsel,u,%_cmpn(_icom)%
!   *msg,info,_cmpn(_icom)
!   MXWF for component: %c
sf,all,mxwf
*if,_qacheck,eq,1,then
sflis
*endif
_iappl=_iappl+1
_actm(_icom)=1
*endif


*endif

*else

_actm(_icom)=0
_cmpn(_icom)='  '

*endif

*enddo

/nerr,1,1e5
*if,_iappl,ge,1,then
*set,_cmpnw
*dim,_cmpnw,char,1,9
*set,_chnum
*dim,_chnum,char,9
_chnum(1)='one','two','three','four','five','six','seven','eight','nine'
*do,_icom1,1,8
  *do,_icom2,1,9-_icom1+1
    *if,_actm(_icom1),eq,0,then
     *do,_icom3,_icom1,8
      _actm(_icom3)=_actm(_icom3+1)
      _cmpn(_icom3)=_cmpn(_icom3+1)
     *enddo
   *endif
 *enddo
*enddo
*do,_icom1,1,_iappl
_cmpnw(1,_icom1)=_cmpn(_icom1)
*enddo
/nopr
*if,_mnu,ne,0,then
/out,fmagbx,out
*endif

*if,_iappl,gt,1,then
*msg,info,_chnum(_iappl)
The force boundary conditions have been applied to the&
following %c components:
*else
*msg,info
The force boundary conditions have been applied to component:
*endif
*msg,info

*vwrite,_cmpnw(1,1),_cmpnw(1,2),_cmpnw(1,3),_cmpnw(1,4)
(4(3x,a8))
*if,_iappl,ge,5,then
*vwrite,_cmpnw(1,5),_cmpnw(1,6),_cmpnw(1,7),_cmpnw(1,8),_cmpnw(1,9)
(4(3x,a8))
*endif
/out

*if,_mnu*(_mg1-1),ne,0,then
  *uili,fmagbx,out
*endif


*endif
cmsel,,_curei
cmsel,,_curni
cmdele,_curei
cmdele,_curni
cmdele,_curel1
!  :end
*endif
*if,_idbug,eq,0,then
!  delete parameters except for arry of component names.
*set,_actm  $ *set,_chnum $  *set,_cmpnw
*set,_elmtd $
_elmx2= $   _elnum=  $  _elnum2= $   _errlv= $   _appl= $   _icom1=
_imat1= $   _imatlm= $   _mnu=   $   _nodo= $   _rout=
_icom2= $    _icom3= $  _elmatc= $   _elnum1= $ _iappl= $ _icom=
*endif
/nerr