Skip to content
Marc & Structures
Index

Save your progress

Enter your email and we will send a secure sign-in link. There is no password and the first link creates your account.

Demonstration ~12 min · ~30 min remaining

Arrays, loops, and decisions

Iterate over alternatives with *DO, turn limits into decisions, and write reusable evidence.

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.

HeightDeflectionStressStatus
80 mm0,744 mm18,75 MPaFails deflection limit
100 mm0,381 mm12,00 MPaFails deflection limit
120 mm0,220 mm8,33 MPaComplies
140 mm0,139 mm6,12 MPaComplies

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.