5.2.5.5. Misuse: Conditional test value¶
Description: Similar to the conditional reset value situation, the use of conditional statements in the test value may be valid CellML, but should be avoided. TODO why??
Note that:
all elements are in the same component;
the order values of resets are not shown; and
all variables have dimensionless units.
component: ConditionalTestValue
├─ variable: t
├─ variable: x initially 0
└─ variable: y initially 0
└─ reset:
├─ when y == (if t == 1 then 1 else 0)
└─ then y = 1
See CellML syntax
<variable name="t" units="dimensionless" />
<variable name="x" units="dimensionless" initial_value="0" />
<variable name="y" units="dimensionless" initial_value="0" />
<reset variable="y" test_variable="x">
<!-- The test value is conditional: -->
<test_value>
<piecewise>
<piece>
<!-- Conditional statement to decide the test value. -->
<apply><eq/>
<ci>t</ci>
<cn cellml:units="dimensionless">1</cn>
</apply>
<!-- If the condition is met, the test value is 0. -->
<cn cellml:units="dimensionless">0</cn>
</piece>
<otherwise>
<!-- If the condition above is not met, the test value is 10. -->
<cn cellml:units="dimensionless">10</cn>
</otherwise>
</piecewise>
</test_value>
<!-- The reset value is constant: -->
<reset_value>
<cn cellml:units="dimensionless">1</cn>
</reset_value>
</reset>
It is valid, though probably not advisable, to use conditional statements (the MathML piecewise, piece and otherwise items) when specifying a test value.
Alternative approaches which avoid this are shown below.
5.2.5.5.1. Suggestions¶
Simply by moving the conditional statement from the test value and into a variable in the maths block gets around the problem. TODO really?? What is the problem actually?? Shouldn’t it be addressed with other resets so that we can use the order to decide how they behave??
component: AvoidConditionalTestValue
├─ variable: t
├─ variable: x initially 0
├─ variable: y initially 0
│ └─ reset:
│ ├─ when y == r
│ └─ then y = 1
├─ variable: r
│
└─ math:
└─ r = (if t == 1 then 1 else 0)
See CellML syntax
<variable name="t" units="dimensionless" />
<variable name="x" units="dimensionless" initial_value="0" />
<variable name="y" units="dimensionless" initial_value="0" />
<!-- Adding a dummy variable to transfer the conditional statement to: -->
<variable name="r" units="dimensionless" />
<reset variable="y" test_variable="x">
<!-- The test value is no longer conditional. -->
<test_value>
<ci>r</ci>
</test_value>
<reset_value>
<cn cellml:units="dimensionless">1</cn>
</reset_value>
</reset>
<!-- Moving the conditional statement into the MathML block, setting
the value to the new dummy variable: -->
<math>
<apply>
<eq/>
<ci>r</ci>
<piecewise>
<piece>
<!-- Conditional statement to decide the test value. -->
<apply>
<eq/>
<ci>t</ci>
<cn cellml:units="dimensionless">1</cn>
</apply>
<!-- If the condition is met, the test value is 0. -->
<cn cellml:units="dimensionless">0</cn>
</piece>
<otherwise>
<!-- If the condition above is not met, the test value is 10. -->
<cn cellml:units="dimensionless">10</cn>
</otherwise>
</piecewise>
</apply>
</math>