/out,g_mark,out
/com, g_mark  9/18/01   no magnet option
/com, g_mark.mac   3/24/01
!  Determines the marker node for orientation identification of the rotor
!  This node is used for rotor movement for rotsol1 and rotsol2
!
!  For full models, the marker node is the center of the magnet which
!  is on the X axis at the time the model was generated.
!
!  For periodic models, the marker node is the lower edge of the model
!  at the time the model was generated.
!
!  output parameter:  mrk_nod  (node number)
!
cmsel,,stator
csys,1
*get,_thy1,node,,mnloc,y
*get,_thy2,node,,mxloc,y
*if,_thy2-_thy1,gt,180,then
  _full=1
*else
  _full=0
*endif


*if,_full,eq,1,then
 esel,,mat,,3
 nsle
 *get,_elmn3,elem,,num,min
 *get,_esys3,elem,_elmn3,attr,esys
 *if,_esys3,gt,0,then
  esel,,esys,,_esys3
 *else
  /com, no magnet    !  9/18/01
  esel,,mat,,3
  *get,_emn3,elem,,num,min
  *get,_emn3r,elem,_emn3,attr,real
  esel,r,real,,_emn3r
 *endif
 nsle
 *get,_ecnt3,elem,,count
 *do,_iesy2,1,2*_ecnt3
  *get,_ecnt3b,elem,,count
  esln
  nsle
  esel,r,mat,,3
  nsle
  *get,_ecnt3a,elem,,count
  *if,_ecnt3a,eq,_ecnt3b,exit
 *enddo
 nsle
 cm,_cefull,elem
 csys,1
 *get,_nct_y1,node,,mnloc,y
 *get,_nct_y2,node,,mxloc,y
 *get,_rdmn_3,node,,mnloc,x
 *if,_nct_y2-_nct_y1,gt,180,then
  /com, magnet straddles the -X axis
  cm,cn3,node
  csys,1
  nsel,r,loc,y,0,179.9999
  *get,_nct_y2,node,,mnloc,y
  cmsel,,cn3
  nsel,r,loc,y,-179.9999,0
  *get,_nct_y1,node,,mxloc,y
  _dthe3=360+_nct_y1-_nct_y2
  _ave_th=_nct_y2+_dthe3/2
  cmdel,cn3
 *else
  _ave_th=.5*(_nct_y2+_nct_y1)
 *endif
 nsle
 mrk_nod=node(_rdmn_3,_ave_th,0)
 _logic=1
*else
 /com, periodic model
 esel,,mat,,2
 nsle
 csys,1
 *get,_nct_y1,node,,mnloc,y
 *get,_nct_y2,node,,mxloc,y
 *get,_rdmn_3,node,,mnloc,x
 *get,_elmn2,elem,,num,min
 esel,,,,_elmn2
 nsle
 *get,_ymin2,node,,mnloc,y
 *get,_xmin2,node,,mnloc,x
 _mrk1=node(_xmin2,_ymin2,0)
  esel,,mat,,2
  nsle


 *if,_nct_y2-_nct_y1,gt,180,then
  /com, rotor straddles the -X axis
  local,21,1
  cscir,21,1

  *get,_nct_y1,node,,mnloc,y
  *get,_nct_y2,node,,mxloc,y
  _dthy2=abs(_nct_y2-ny(_mrk1))
  _dthy1=abs(_nct_y1-ny(_mrk1))
  *if,_dthy2,lt,_dthy1,then
   /com,min node is closer to _y2 end of rotor
   mrk_nod=node(_rdmn_3,_nct_y2,0)
   _logic=2
  *else
  /com,min node is closer to _y1 end of rotor
   mrk_nod=node(_rdmn_3,_nct_y1,0)
   _logic=3
  *endif
  csys,1
 *else
  /com, rotor does not straddle the -X axis
  _dthy2=abs(_nct_y2-ny(_mrk1))
  _dthy1=abs(_nct_y1-ny(_mrk1))
  *if,_dthy2,lt,_dthy1,then
   /com,min node is closer to _y2 end of rotor
   mrk_nod=node(_rdmn_3,_nct_y2,0)
   _logic=4
  *else
  /com,min node is closer to _y1 end of rotor
   mrk_nod=node(_rdmn_3,_nct_y1,0)
   _logic=5
  *endif
 *endif
*endif
csys,1
rot_thet=ny(mrk_nod)
*stat,mrk_nod
*stat,_logic
/out
*msg,info,mrk_nod,rot_thet
Marker node ( %i ) is at %g degrees