!  /nopr
/uis,msgpop,3
/out,_mvrotor,out
!    mvrotor.mac
!    Moves the lower edge of the rotor to this angle from the 
!    existing position
!
!    Assumes stator is defined as component "STATOR"
!    and rotor is defined as "ROTOR"
!
!    Assumes that permach has been called. If not,  the rotor will be moved
!    but the model will not be connected by this macro.  A message is
!    printed if the mvrotor was requested to stitch the rotor/stator and
!    the periodic conditions were not applied before mvrotor was used.
!    
!
!     arg1 = angle (D) measured CCW from +X axis
!
!     arg2 = 0 no action (The rotor is moved, but they are not stitched.)
!          = 1 call macro to connect the rotor to the stator
!     arg9 = 1, user is prompted for the angle of the rotor
!
alls
csys,1
*get,thmn,node,,mnloc,y
*get,thmx,node,,mxloc,y
*get,_mnu,active,,menu
*if,_nomsg,eq,0,then
*if,_mnu,ne,0,then
 *if,arg9,eq,1,then
  *if,abs(thmx-thmn),lt,200,then
   *ask,_arg1,Enter the Angle of Position for the Rotor,0
  *else
   *ask,_arg1,Enter the Angle Increment for the Rotor,0
  *endif
  arg1=_arg1    !  7/19/97
 *endif
*endif
*endif
fini
_evod=1        !   sets flag to odd condition
/prep7
immed,0
_ierror=0
_appsti=arg2
*msg,info,arg1
  move to angle: %g
!  check for full models
*if,(thmx-thmn),gt,200,then
a_rg1=arg1
_thtinc=arg1      !   2/18/96
!   it is a full model
!  first rotate
cmsel,,rotor
*get,cur_a,node,mrk_nod,loc,y
_cthtmn=cur_a
csys,1
!  ngen,2,,all,,,0,a_rg1-cur_a
ngen,2,,all,,,0,a_rg1
cmsel,,rotor
nsel,r,ext
*get,rdmx,node,,mxloc,x
nsel,r,loc,x,rdmx-.00001,rdmx+1
*get,_ncount,node,,count      !  1//30/96
cm,ce_n,node
cmsel,,stator
esel,r,mat,,1
cmsel,,ce_n
cedel,all,,,any
numc,ce
ceintf,.1



*else
!  it is periodic model


*if,arg2,ne,0,then
!   check periodic conditions 
cmsel,,stator
csys,1
nsel,r,ext
*get,_rmin,node,,mnloc,x
*get,_rmax,node,,mxloc,x
_rave=(_rmin+_rmax)/2
*get,_thtmax,node,,mxloc,y
_perndr=node(_rave,_thtmax,0)

*get,_cpmx,active,,cp
*get,_cemx,active,,ce

nsel,,,,_perndr
nsel,r,cp,,1,_cpmx
*get,_ncpnd,node,,count

nsel,,,,_perndr
nsel,r,ce,,1,_cemx
*get,_ncend,node,,count
*if,_ncpnd,ne,0,then
_evod=2        !    sets to even condition
*endif
*if,_ncend+_ncpnd,eq,0,then
!    no periodic conditions have been applied
!    determine which condition is to be applied
_appsti=0
_ierror=1
*endif

*endif

cmsel,,rotor
csys,1
*get,_cthtmx,node,,mxloc,y
*get,_cthtmn,node,,mnloc,y
_thtinc=arg1-_cthtmn
nsle

*if,_ierror,eq,0,then

ngen,2,,all,,,0,_thtinc
*if,_appsti,eq,1,then
  stitch6,arg3
  cmsel,,_cerotor               !  1//30/96
  *get,_ncount,node,,count      !  1//30/96
*endif    !  end of if logic for _appsti=1

!  complete the connection of the edge nodes which may not have been
!  connected by the stitch6 macro.
!  locate the edge nodes
*get,_cpmx,active,,cp
*get,_cemx,active,,ce
*set,_pernd
*dim,_pernd,,4,4
_pernd(1,3)=10,1,10,1
_pernd(1,4)=1,-1,1,1
*set,_cpce
*dim,_cpce,char,2
*set,_invr
*dim,_invr,table,4
_invr(1,0)=-1e8,-.1,.1,1e8
_invr(1,1)=0,1,1,0
_cpce(1)='ce','cp'
csys,1
cmsel,,stator
*get,_rmin,node,,mnloc,x
*get,_thtmax,node,,mxloc,y
*get,_thtmin,node,,mnloc,y
_pernd(1,1)=node(_rmin,_thtmax,0)
_pernd(2,1)=node(_rmin,_thtmin,0)
nsel,,,,_pernd(1,1)
nsel,a,,,_pernd(2,1)
esln
nsle
nsel,u,,,_pernd(1,1)
nsel,u,,,_pernd(2,1)

*get,_rmax,node,,mxloc,x
_pernd(3,1)=node(_rmax,_thtmax,0)
_pernd(4,1)=node(_rmax,_thtmin,0)
_cpcemx=_cpmx+_cemx



alls
 _cemx=_cemx+1
 ce,_cemx,0,_pernd(1,1),az,1,_pernd(2,1),az,_pernd(_evod,4)
 _cemx=_cemx+1
 ce,_cemx,0,_pernd(3,1),az,1,_pernd(4,1),az,_pernd(_evod,4)

*endif   ! end of error condition logic

*endif    !   bypass logic for periodic models



cmsel,,rotor
*get,_ecnt,elem,,count
!   update the magnet position
_idmag=0
_do_mag=10
*if,_ierror,eq,0,then

*set,_magno
*dim,_magno,,_ecnt
*if,rad_mag,eq,0,then
  *do,_ifdmag,1,_ecnt
    /gopr
    *get,_mxelem,elem,,num,max
    *if,_mxelem,eq,0,exit
    *get,_matno,elem,_mxelem,attr,mat
    *get,_mgxx,mgxx,_matno,,,const,1
    *get,_mgyy,mgyy,_matno,,,const,1
    *if,abs(_mgxx)+abs(_mgyy),ne,0,then
      _do_mag=0
      _mxelem=0
      _idmag=_idmag+1
      _magno(_idmag)=_matno
     *endif
     esel,u,mat,,_matno
  *enddo
*endif
_nummag=0

*set,_esyflg                                    !  11/01/94
*dim,_esyflg,,10000                             !  11/01/94

*if,rad_mag+_do_mag,eq,0,then
 *do,_jfdmag,1,_idmag
  /gopr
  *msg,info,_jfdmag
  outer loop: _jfdmag
  _matno=_magno(_jfdmag)
  cmsel,,rotor
  esel,r,mat,,_matno
  *get,_ecnt,elem,,count
  cm,_curmod,elem
  *do,_ishmag,1,_ecnt
   /gopr
   *msg,info,_ishmag
   inner loop: _ishmag  %i
   *get,_mxelem,elem,,num,max
   *if,_mxelem,eq,0,exit
   *get,_curesy,elem,_mxelem,attr,esys

   *if,_esyflg(_curesy),eq,0,then                  !  11/01/94
    esel,,,,_mxelem
    nsle
    *get,_mxnode,node,,num,max
    csys,_curesy
    nrot,all
    *get,_cesysa,node,_mxnode,ang,xy
    _newang=_cesysa+_thtinc
    local,_curesy,0,0,0,0,_newang
    csys
    nrot,all
    cmsel,,_curmod
    esel,u,esys,,_curesy
    cm,_curmod,elem
    _mxelem=0
    _nummag=_nummag+1
    _esyflg(_curesy)=1                               !  11/01/94
   *else                                            !  11/01/94
    _nummag=_nummag+1                                !  11/01/94
    cmsel,,_curmod                                   !  11/01/94
    esel,u,esys,,_curesy                             !  11/01/94
    cm,_curmod,elem                                  !  11/01/94
   *endif                                           !  11/01/94
  *enddo
 *enddo
 _ishmag=_ishmag-1
*endif



*endif   !  end of logic error condition

*set,_styno
*dim,_styno,char,2
_styno(1)='No','Yes'
alls
*set,_esyflg
/out
/nopr
/out,mvrotor,out
*msg,info
>________________MOVEMENT OF THE ROTOR_________________<
*if,_ierror,eq,0,then

*if,(thmx-thmn),lt,180,then
 *msg,info,_cthtmn
 OLD angle of the lower edge of the rotor:__________ %g
 *msg,info,arg1
 NEW angle of lower edge of the rotor:______________ %g
*else
 *msg,info,arg1
 Increment of Rotation of rotor(D):_________________ %g
*endif

 *msg,info,_ncount
 Number of nodes in rotor:__________________________ %i
*if,rad_mag,eq,0,then
 *msg,info,_nummag
 Number of magnet coordinate systems moved:_________ %i
*endif

*endif

*msg,info,_styno(_appsti+1)
 Was the Rotor "Stitched" to the Stator ?:__________ %c

*if,_ierror,eq,1,then
*msg,info
  THE MODEL DID not HAVE NOT ANY PERIODIC CONDITIONS
*msg,info
  THE STATOR COULD not BE CONNECTED TO THE ROTOR.
*msg,info
  USE THE <EVEN_BC> TO APPLY THE PERIODIC CONDITIONS.
*endif

*msg,info
>______________________________________________________<
/out
*list,mvrotor,out

*if,_nomsg,eq,0,then
 *uilist,mvrotor,out
 /uis,msgpop
 dsys
 /pbc,cp,1    !  2/17/96
 /pbc,ce,1    !  2/17/96
 *get,_dist,graph,1,dist
 /dist,,_dist
 _dist=
 /pbc,all
 /pbc,ce,1
 eplot
 immed,1
*endif
/gopr