! ============================================================
! M07 - Reto de ampliacion grafica
! Verifica que la pendiente carga-desplazamiento es constante.
! ============================================================

/CLEAR,START
/FILNAME,m07_graphics_challenge,1
/UNITS,SI

beam_l=1.0
beam_h=0.10
beam_b=0.05
mesh_h=0.05
young=210E9
nu=0.30
select_tol=MIN(beam_h,beam_b)*1E-5
n_substeps=10
slope_tol=0.02
challenge_passes=0
slope_a=0
slope_b=0

*DO,case_idx,1,2
  *IF,case_idx,EQ,1,THEN
    tip_force=-500
  *ELSE
    tip_force=-1000
  *ENDIF

  /PREP7
  /NOPR
  VCLEAR,ALL
  VDELE,ALL,ALL
  /GOPR
  ET,1,SOLID185
  KEYOPT,1,2,3
  MP,EX,1,young
  MP,PRXY,1,nu
  TYPE,1
  MAT,1
  BLOCK,0,beam_l,0,beam_h,0,beam_b
  div_x=beam_l/mesh_h
  div_y=beam_h/mesh_h
  div_z=beam_b/mesh_h
  MSHAPE,0,3D
  MSHKEY,1
  LSEL,S,LENGTH,,beam_l
  LESIZE,ALL,,,div_x,,1
  LSEL,S,LENGTH,,beam_h
  LESIZE,ALL,,,div_y,,1
  LSEL,S,LENGTH,,beam_b
  LESIZE,ALL,,,div_z,,1
  ALLSEL,ALL
  VMESH,ALL

  SELTOL,select_tol
  NSEL,S,LOC,X,0
  CM,fixed_nodes,NODE
  ALLSEL,ALL
  NSEL,S,LOC,X,beam_l
  CM,tip_nodes,NODE
  *GET,n_tip,NODE,0,COUNT
  ALLSEL,ALL
  NSEL,S,LOC,X,beam_l
  NSEL,R,LOC,Y,0
  NSEL,R,LOC,Z,0
  *GET,corner_node,NODE,0,NUM,MIN
  ALLSEL,ALL
  SELTOL,

  FINISH
  /SOLU
  CMSEL,S,fixed_nodes
  D,ALL,ALL,0
  ALLSEL,ALL
  CMSEL,S,tip_nodes
  F,ALL,FY,tip_force/n_tip
  ALLSEL,ALL
  ANTYPE,STATIC
  NLGEOM,OFF
  KBC,0
  NSUBST,n_substeps
  OUTRES,ALL,ALL
  TIME,1
  SOLVE
  FINISH

  /POST1
  SET,LAST
  *GET,uy_corner,NODE,corner_node,U,Y
  *IF,case_idx,EQ,1,THEN
    uy_a=uy_corner
    slope_a=uy_a/tip_force
  *ELSE
    uy_b=uy_corner
    slope_b=uy_b/tip_force
  *ENDIF
*ENDDO

slope_ratio=ABS(slope_a/slope_b-1)
*IF,slope_ratio,LT,slope_tol,THEN
  challenge_passes=1
*ENDIF

*CFOPEN,m07_graphics_slope_audit,csv
*VWRITE
('case,tip_force_N,uy_corner_m,slope_m_per_N,passes')
*VWRITE,('A'),-500,uy_a,slope_a,challenge_passes
(A,',',E16.8,',',E16.8,',',E16.8,',',F2.0)
*VWRITE,('B'),-1000,uy_b,slope_b,challenge_passes
(A,',',E16.8,',',E16.8,',',E16.8,',',F2.0)
*VWRITE,('ratio'),slope_ratio,challenge_passes
(A,',',E16.8,',',F2.0)
*CFCLOS

*IF,challenge_passes,EQ,1,THEN
  /COM,M07 GRAPHICS CHALLENGE PASSED
*ELSE
  /COM,M07 GRAPHICS CHALLENGE FAILED - slope not constant
*ENDIF

FINISH
