Step 4 — Store data in arrays
We want to test four heights without creating four independent parameters:
*DIM,heights,ARRAY,4
heights(1)=0.08
heights(2)=0.10
heights(3)=0.12
heights(4)=0.14
*DIM reserve an array. Each position contains an alternative. The array describes data;
still doesn't indicate what to do with them.
Step 5 — Iterate through alternatives with *DO
*DO,i,1,4
trial_h=heights(i)
trial_i=beam_b*trial_h**3/12
trial_uy=ABS(tip_force)*beam_l**3/(3*young*trial_i)
trial_stress=ABS(tip_force)*beam_l*(trial_h/2)/trial_i
*ENDDO
The Index i successively takes the values 1, 2, 3 and 4. On every lap,
trial_h represents a different height. Analytical calculation costs practically nothing;
that's why it's a good place to learn loops. Running a full simulation on each lap will arrive at M09.
Step 6 — Convert limits to a decision
passes=0
*IF,trial_uy,LE,uy_limit,THEN
*IF,trial_stress,LE,stress_limit,THEN
passes=1
*IF,selected_h,EQ,0,THEN
selected_h=trial_h
*ENDIF
*ENDIF
*ENDIF
selected_h starts at zero. It's only updated for the first valid alternative,
so at the end it contains the lowest admissible height of an ordered array.
| Height | Deflection | Stress | Status |
|---|---|---|---|
| 80 mm | 0,744 mm | 18,75 MPa | Fails deflection limit |
| 100 mm | 0,381 mm | 12,00 MPa | Fails deflection limit |
| 120 mm | 0,220 mm | 8,33 MPa | Complies |
| 140 mm | 0,139 mm | 6,12 MPa | Complies |
The first valid candidate is 120 mm.
Step 7 — Write reusable evidence
A table is more useful than values buried in the output:
*CFOPEN,m01_design_table,csv
*VWRITE
('height_m,uy_ref_m,sigma_ref_pa,passes')
! Inside the loop:
*VWRITE,trial_h,trial_uy,trial_stress,passes
(E16.8,',',E16.8,',',E16.8,',',F2.0)
*CFCLOS
When executing the deliverable, it will appear m01_design_table.csv on the Working Directory.
Open it in a text editor before taking it to a spreadsheet: you must be able to understand its structure without relying on another application.