! *************************** REV52 ********************************* !
!                          PEXAUTO.MAC                                ! 
!   Macro to automatically exclude elements w single displacements    !
!                 and forces for a p-method model                     !
!                      RWG September 12, 1995                         !
! Last Modified:                                                      !
!                                                                     !
! This macro is to be issued at the end of a Pro/ENGINEER /prep7      !
! batch input file.                                                   !
!                                                                     !
! Usage:  PEXAUTO                                                     !
!                                                                     !
! ******************************************************************* !
!
/nopr                   ! Suppress command echo

_YES=0
_NO=1

! Operate on the mesh to mark elements for exclusion, if
! they have applied forces or displacements.
! For forces, any element having a node that is force loaded is excluded.
! For displacements, any element having a single node displacement 
! constraint is excluded (ie, all the nodes on an element's face
! must be constrained in order to not exclude the element).
!
_val=1e30
_nval=-1e30

_enum=0
esel,none
cm,noexcel,elem   ! no exclude element list for load steps
esel,all

! combine all loads/bc cases into 1 case for P exclude checking.
!
*DO,J_NUM_LS,1,_LSNUM
  lsread,J_NUM_LS
*ENDDO

nsel,s,f,f,_nval,_val
cm,ff,node
esln,s,0
! component of elements with applied forces
cm,floaded,elem

nsel,s,d,u,_nval,_val
cm,du,node
!
! Check displacement conditions, if displacements are applied 
! to an element face, then do not exclude.
!
esln,s,0
! component of elements with applied displacements
cm,enodes,elem   ! elements attached to displacement constrained nodes
*get,_enode,elem,,count

      ! check each element to determine if an entire face is constrained
      ! and do not exclude element if it is.
      ! Note: A given element will still be excluded even if an entire
      ! face is constrained and there also happens to be an applied force.
      !
      ! It is not checking for particular displacement DOF.
*DO,_j,1,_enode
_exclude=_yes
cmsel,s,enodes
_enum=elnext(_enum)
esel,s,,,_enum
nsle          ! selected nodes in this element
cmsel,r,du    ! now only nodes that had original displacements are selected
!
! Get the face number that is defined by the selected nodes.
!
_face=nmface(_enum)   ! if multiple faces, this returns lowest numbered face
	              ! if no faces, returns 0
*if,_face,gt,0,then
! do NOT exclude this element
_exclude=_no

*else
*get,_nn,node,,count    ! number of nodes currently selected on element
                        ! with displacement constraints.
esln,s    ! select other elements attached to selected node
nsle      ! nodes in this element set
cmsel,r,du    ! nodes that have displacements applied
*get,_nnd,node,,count   ! if this is greater than _nn, do not exclude
*if,_nnd,gt,_nn,then
_exclude=_no
*endif

*endif     ! of _face,gt,0

*if,_exclude,eq,_no,then
cmsel,s,noexcel
esel,a,,,_enum
cm,noexcel,elem   ! no exclude element(s)
*endif

*ENDDO  ! end of _J

cmsel,s,du
cmsel,a,ff
esln,s,0          ! all elements with displaced or loaded nodes

cmsel,u,noexcel
cmsel,a,floaded

cm,exclude,elem
PEXCLUDE,ALL

nsel,all
esel,all
!
/GO
