Sometimes certain part of a ParamML document may need to be repeated so many times. In fact the number of repetitions may be user defined. Repeat objects are used to clone a set of objects multiple times.
Many structures are composed of repetitions of structural components.
For example,
multiple girders in a bridge at different transverse location.
multiple web stiffeners along a girder.
multiple panels of a tower.
multiple floors of a building.
A component can be defined once and placed inside a Repeat object to clone and position at certain geometric intervals. Anything inside a Repeat object is repeated number of times defined by its parameters.
Every Repeat object must have these parameters:
S (start)
E (end)
I (increment)
CTRL (control parameter)
and the definition of the actual control parameter. Repeat element could be nested.
Authors with previous programming experience often see ParamML as a programming language. There is nothing wrong with that and it is true that ParamML has building blocks of a fully functional programming language. The problem is that most people are familiar with procedural programming languages, and if they try to use ParamML like a procedural language, they will bring nothing but confusion and frustration on themselves.
If one wants to think of a programming language, he needs to think of ParamML as a functional programming language where the statements (in the case of ParamML, parameters) are executed as needed basis (lazy evaluation).
At the center of this confusion is the Repeat object. Repeat object of ParamML is often seen equivalent to a loop in a procedural language. That is not correct. Repeat object is merely a powerful array (list) definition. It can also be seen as a generator. If one wants to aggregate computation on this list, he needs to think recursive. This concept is reinforced with Example 1 below.
<O T="Repeat">
.
.
</O>
Parent elements: Project, Group, Repeat
Child elements: Parameter, Surface, Circle, Point, Line, Volume, Group, Repeat (nested)
Below is a simple ParamML code that sums up the numbers given in a range. If 0 to 9 is entered, all the numbers from 0 to 9 need to be summed up and give the output 45.
Thinking recursively, because ParamML is more like a functional language, say A is a list of numbers, the sum of all the numbers in A are:
A[0].Tot = i
A[i].Tot = i + A[i-1].Tot;
Here is a Repeat object called A with Tot parameter. Notice that Tot is defined twice, one for i equals zero and one definition for i greater than zero.
<O N="A" T="Repeat" CTRL="i" I="1" E="9" S="0" i="0">
<!-- if i is equal to 0, then parameter Tot is equal to i -->
<O T="Group">
<P N="Guard" V="i .LE. 0" />
<P N="Tot" V="i" />
</O>
<!-- if i is greater than 0, then parameter Tot is equal to i plus previous Tot -->
<O T="Group">
<P N="Guard" V="i .GT. 0" />
<P N="Tot" V="i + A[i-1].Tot" />
</O>
</O>
A[9] is the last item in list A, so A[9].Tot would give the total of number from 0 to 9.
In order to see this result, use the following design code run:
<O N="Test Code" T="DesignCode">
<P N="Total" V="A[EndNum].Tot" />
<O N="Check 1" T="Check">
<P N="Criteria" V="Total .GE. 45" />
</O>
</O>
<O T="DesignRun">
<P N="Code" V="Test Code" T="DesignCode" />
</O>
Now the computed sum can be seen under design code in OpenBrIM.
Here is the full code of the sample project:
<O N="Sum Numbers" T="Project">
<!-- Sum numbers from 0 to 9 -->
<O T="Group">
<P N="EndUserInputFields" V="1" />
<P N="StartNum" V="0" />
<P N="EndNum" V="9" />
</O>
<!-- First we have a repeat node that goes from 0 to 9 on control parameter i -->
<O N="A" T="Repeat" CTRL="i" I="1" E="EndNum" S="StartNum" i="0">
<!-- if i is equal to 0, then parameter Tot is equal to i -->
<O T="Group">
<P N="Guard" V="i .LE. 0" />
<P N="Tot" V="i" />
</O>
<!-- if i is greater than 0, then parameter Tot is equal to i plus previous Tot -->
<O T="Group">
<P N="Guard" V="i .GT. 0" />
<P N="Tot" V="i + A[i-1].Tot" />
</O>
</O>
<!-- Let's create a DesignCode so we can see the results in the program.
The design code has a parameter called Total which is set to the last iteration (which is 9) of parameter Tot in repeat A.
You will see that Total will be equal to 45 which is the sum of numbers from 0 to 9. -->
<O N="Test Code" T="DesignCode">
<P N="Total" V="A[EndNum].Tot" />
<O N="Check 1" T="Check">
<P N="Criteria" V="Total .GE. 45" />
</O>
</O>
<O T="DesignRun">
<P N="Code" V="Test Code" T="DesignCode" />
</O>
</O>
<O T="Project" N="Repeat: Sample 1">
<O T="Group">
<P N="EndUserInputFields" V="1"/>
<P N="height" V="20" />
<P N="width" V="1" />
<P N="depth" V="2" />
<P N="count" V="4" D="Number of columns" />
</O>
<O T="Repeat">
<P N="S" V="1" />
<P N="E" V="count" />
<P N="I" V="1" />
<P N="CTRL" V="index" T="Text"/>
<P N="index" V="0" />
<O T="Line" N="Rectangular Column">
<O T="Point" X=" index * 5 " Y="0" Z="0" />
<O T="Point" X=" index * 5 " Y="0" Z="height" />
<O T="Section" N="Rectangular">
<O T="Shape">
<O T="Point" X="‐width/2" Y="‐depth/2" Z="0" />
<O T="Point" X="‐width/2" Y="depth/2" Z="0" />
<O T="Point" X="width/2" Y="depth/2" Z="0" />
<O T="Point" X="width/2" Y="‐depth/2" Z="0" />
</O>
</O>
</O>
</O>
</O>