/out,tor_3d,out
!  tor_3d.mac  11/24/01  account for skewed periodic models
!  tor_3d.mac  11/02/01  print options
!  tor_3d.mac  original
!  
!  computes the torque for 3D machines 
!
!  arg1 = 0         print torque on rotor by maxwell's stress
!       = 1         print torque bu virtual work
!       = all else, print all the torques
!
!
*get,_rout,active,,rout
*if,_rout,ne,31,then
  fini
  /post1
*endif
rsys
csys
esel,,mat,,5
nsle
csys
*get,_zmin,node,,mnloc,z
*get,_zmax,node,,mxloc,z
_symfac=1
*if,(_zmax-_zmin),ne,0,then
_symfac=ggeom*stkthk/(_zmax-_zmin)
*endif
csys,1
nsel,r,loc,z,_zmin-.0001,_zmin+.0001   !  11/24/01 
*get,_mntheta,node,,mnloc,y
*get,_mxtheta,node,,mxloc,y
_symang=nint(360/(_mxtheta-_mntheta))
esel,,mat,,5
nsle
esln
esel,r,mat,,1
nsle
nsel,r,loc,z,_zmin-.0000001,_zmax+.000001
esln,,1
esel,r,mat,,1
nsle
csys,1
*get,_rmax,node,,mxloc,x
cm,ce,elem
nsel,r,loc,x,_rmax-.000001,_rmax+1
esln,r
nsle
cm,ce1,elem
cmsel,,ce
cmsel,u,ce1
cm,tor_sta,elem
nsle


esel,,mat,,2,3
nsle
esln
esel,r,mat,,1
nsle
nsel,r,loc,z,_zmin-.0000001,_zmax+.000001
esln,,1
esel,r,mat,,1
nsle
cm,tor_rot,elem
cmsel,a,tor_sta

csys

etab,fx,nmisc,4
etab,fy,nmisc,5
etab,fz,nmisc,6
etab,fmx,fmag,x
etab,fmy,fmag,y
etab,fmz,fmag,z
etab,xc,cent,x
etab,yc,cent,y
etab,zc,cent,z
smult,t1,xc,fy
smult,t2,yc,fx
sadd,t3,t1,t2,1,-1
vcross,tx,ty,tz,xc,yc,zc,fx,fy,fz
vcross,tmx,tmy,tmz,xc,yc,zc,fmx,fmy,fmz
cmsel,,tor_sta
ssum
*get,tor_sta,ssum,,item,tz
*get,tormsta,ssum,,item,tmz
tor_sta=_symfac*tor_sta*_symang
tormsta=_symfac*tormsta*_symang
cmsel,,tor_rot
ssum
*get,tor_rot,ssum,,item,tz
*get,tormrot,ssum,,item,tmz
tor_rot=_symfac*tor_rot*_symang
tormrot=_symfac*tormrot*_symang
*msg,info
 Method to compute torque:_______ Maxwells stress
*msg,info,nint(tormsta*10000)/10000
 Torque on stator(Nm):___________ %g

*msg,info,nint(tormrot*10000)/10000
 Torque on rotor(Nm):____________ %g
/nopr
/out,tor_3d,sum
*msg,info
___________TORQUE FOR 3D MACHINES__________
*MSG,INFO

*msg,info,_symfac
 Axial Symmetry factor:_________ %g
*msg,info,_symang
 Angular Symmetry factor:_______ %g

*if,arg1,eq,1,then
*msg,info
 Method to compute torque:_______ Virtual work
*msg,info,nint(tor_sta*10000)/10000,nint(141.9*tor_sta*10)/10
 Torque on stator(Nm):___________ %g  ( %g oz-in)
*msg,info,nint(tor_rot*10000)/10000,nint(141.9*tor_rot*10)/10
 Torque on rotor(Nm):____________ %g  ( %g oz-in)
*msg,info

*elseif,arg1,eq,0,then
*msg,info
 Method to compute torque:______ Maxwell's stress tensor
!*msg,info,nint(tormsta*10000)/10000,nint(141.9*tormsta*10)/10
! Torque on stator(Nm):___________ %g  ( %g oz-in)

*msg,info,nint(tormrot*10000)/10000,nint(141.9*tormrot*10)/10
 Torque on rotor(Nm):___________ %g  ( %g oz-in)
*else

/com, option to print all the torque calculations

*msg,info
 Method to compute torque:_______ Virtual work
*msg,info,nint(tor_sta*10000)/10000,nint(141.9*tor_sta*10)/10
 Torque on stator(Nm):___________ %g  ( %g oz-in)
*msg,info,nint(tor_rot*10000)/10000,nint(141.9*tor_rot*10)/10
 Torque on rotor(Nm):____________ %g  ( %g oz-in)
*msg,info

*msg,info
 Method to compute torque:______ Maxwell's stress tensor
*msg,info,nint(tormsta*10000)/10000,nint(141.9*tormsta*10)/10
 Torque on stator(Nm):___________ %g  ( %g oz-in)

*msg,info,nint(tormrot*10000)/10000,nint(141.9*tormrot*10)/10
 Torque on rotor(Nm):___________ %g  ( %g oz-in)

*endif


*msg,info
________________________________________________


/out,tor_3d,out,,append

*if,_mg1,eq,0,then
 *uili,tor_3d,sum
*endif


/out