/out,mv_rotor,out
!   mv_rotor.mac
!    moves the rotor side of the model by a specified fraction of the 
!    radial gap. The rotor is not rotated. The movement is along the +X axis
!    This macro alters the model, be sure to save it before the macro is called
!
!    Since this involves the use of the strucutral and magnetics, there are two possible
!    solution paths.  
!     (1)  If the available products are ANSYS Mechanical and ANSYS EMAG, then the
!          solutions must be performed in separate programs.
!
!    arg1 =fraction of the radial gap (between 0 and .95)
!    arg2 = 0, The procedure is to be accomplished in 2 steps. The first step
!              is for moving the rotor mesh using ANSYS MEchanical. The second step
!              is accomplished using ANSYS EMAG using the moved rotor mesh from
!              ANSYS MEchanical.
!         = 1, Both steps are solved in ANSYS Multi Physics
!
!    
*if,arg1,eq,1,then
  mv_rotor=0
*endif


*if,mv_rotor,eq,0,then

fini

_frac=arg1

esel,,mat,,2,3
nsle
csys,1
*get,_rdmx,node,,mxloc,x
esel,,mat,,5
nsle
*get,_rdmn,node,,mnloc,x
csys
_dgap=_rdmn-_rdmx

_err=0

*if,_frac,le,0,then
 _err=1
 /nerr
 /out
 *msg,error,_dr
 The input fraction must be > 0 and < .95 of radial gap-no action
 /out,mv_rotor,out,,append
 /nerr,0,1e5
*endif

*if,_frac,gt,.95,then
 _err=1
 /nerr
 /out
 *msg,error,_dr
 The input fraction is too close to the radial gap of machine-no action
 /out,mv_rotor,out,,append
 /nerr,0,1e5
*endif
*if,_err,eq,1,:end


/prep7
esel,all
*get,_elmx,elem,,num,max
*set,_etyp
*dim,_etyp,,_elmx,2
*do,_i1,1,100
 _elmx=0
 *get,_elmx,elem,,num,max
 *if,_elmx,eq,0,exit
 *get,_etyp(_i1,1),elem,_elmx,attr,type
 esel,u,type,,_etyp(_i1,1)
 *get,_etyp(_i1,2),etyp,_etyp(_i1,1),attr,enam
 *if,_etyp(_i1,2),eq,13,then
  et,_etyp(_i1,1),42
 *else
  et,_etyp(_i1,1),82
 *endif
*enddo
n_type=_i1

alls
cedel,all,all
numc,cp

cmsel,,rotor
csys,1
*get,rdmx,node,,mxloc,x
nsel,r,ext
nsel,r,loc,x,rdmx-.0001,rdmx+1
cm,ce_node,node
cmsel,,stator
esel,r,mat,,1
cmsel,,ce_node
ceintf

mp,ex,1,1e5
rp7,,1

cmsel,,stator
esel,r,mat,,5,6
nsle
d,all,all

cmsel,,rotor
esel,r,mat,,2,3
nsle
d,all,ux,_frac*_dgap


/sol
alls
solve
fini
!


/prep7
upcoords,1

cedel,all,all

mv_rotor=1

save,mv_rotor,db

*endif

*if,arg1,eq,1,then
  mv_rotor=1
*endif

*if,mv_rotor,eq,1,then

 *do,_i1,1,n_type
  et,_etyp(_i1,1),_etyp(_i1,2)
 *enddo
 cmsel,,stator
 esel,r,mat,,1
 cmsel,,ce_node
 ceintf
 alls

 mvpsol

 fini
 /post1
 fmagsum,'r_iron'

*endif

:end
/out