! ============================================================
! M02 - Bug hunt
! ============================================================
/CLEAR,START                        ! Do not use this as a production template.
/FILNAME,m02_bug_hunt,1
/TITLE,M02 - Bug hunt
/UNITS,SI

beam_l=1.0
beam_h=0.10
beam_b=0.05
young=210E9
nu=0.30
mesh_h=0.025

/PREP7
ET,1,SOLID185
MP,EX,1,young
MP,PRXY,1,nu
TYPE,1
MAT,1
BLOCK,0,beam_l,0,beam_h,0,beam_b
ESIZE,mesh_h
VMESH,ALL

ALLSEL,ALL                          ! ALLSEL,ALL restores the complete selection before auditing global counts.
*GET,n_nodes,NODE,0,COUNT           ! *GET stores in n_nodes the total number of nodes in the active model.
*GET,n_elements,ELEM,0,COUNT

NSEL,S,NODE,,1,15                   ! NSEL,S,NODE selects nodes by ID range, not by geometric coordinate.
CM,fixed_nodes,NODE                 ! CM,fixed_nodes saves the current selection as a reusable component.
ALLSEL,ALL

NSEL,S,LOC,X,beam_l                 ! DEFECT 2: ALLSEL runs before the tip is saved.
ALLSEL,ALL
CM,tip_nodes,NODE

LOCAL,11,CART,beam_l,0,0            ! LOCAL,11 defines a Cartesian system with origin at the beam tip.
CSYS,11                             ! CSYS,11 activates the local system to select by LOC at the tip.
NSEL,S,LOC,X,0
CM,tip_local_nodes,NODE
ALLSEL,ALL

SELTOL,mesh_h                       ! SELTOL sets the coincidence tolerance for selections by LOC.
NSEL,S,LOC,Y,beam_h
CM,top_nodes,NODE
ALLSEL,ALL

ESEL,S,CENT,X,0.4*beam_l,0.6*beam_l     ! ESEL,S,CENT,X selects elements whose centroid falls in the central band.
CM,mid_elems,ELEM
*GET,n_elements_after,ELEM,0,COUNT

*CFOPEN,m02_bug_hunt_audit,csv
*VWRITE
('n_nodes,n_elements,n_elements_after')
*VWRITE,n_nodes,n_elements,n_elements_after
(F10.0,',',F10.0,',',F10.0)
*CFCLOS

/COM,BUG HUNT FINISHED - diagnose five logical defects
FINISH



