Repository navigation
Description
Note: this relies on the work done in PR #1489 for issue #1487.
An NLA system can contain equations that don't all have the same unknowns (e.g., one equation in a only and another in a and b). The analyser checks for overconstraint one NLA equation at a time: it compares the number of equations in the system with the number of unknowns of that equation. So a system with as many equations as unknowns is still reported as overconstrained.
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" xmlns:cellml="http://www.cellml.org/cellml/2.0#" name="mixed">
<component name="main">
<variable name="t" units="dimensionless"/>
<variable name="x" units="dimensionless" initial_value="0"/>
<variable name="a" units="dimensionless" initial_value="1"/>
<variable name="b" units="dimensionless" initial_value="1"/>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply><eq/>
<apply><diff/><bvar><ci>t</ci></bvar><ci>x</ci></apply>
<cn cellml:units="dimensionless">1</cn>
</apply>
<apply><eq/>
<apply><sin/><ci>a</ci></apply>
<ci>x</ci>
</apply>
<apply><eq/>
<apply><times/><ci>a</ci><ci>b</ci></apply>
<apply><plus/><ci>x</ci><cn cellml:units="dimensionless">2</cn></apply>
</apply>
</math>
</component>
</model>sin(a) = x and a*b = x+2 form a single NLA system with 2 equations and 2 unknowns (a and b).
Expected: a valid DAE model, with an NLA system that solves for both a and b:
void objectiveFunction0(double *u, double *f, void *data)
{
...
algebraicVariables[0] = u[0];
algebraicVariables[1] = u[1];
f[0] = sin(algebraicVariables[0])-states[0];
f[1] = algebraicVariables[0]*algebraicVariables[1]-(states[0]+2.0);
}Actual: the analyser reports Variable 'a' in component 'main' is overconstrained. and the model type is AnalyserModel::Type::OVERCONSTRAINED.
Cause
- Analyser: the overconstraint check in
Analyser::AnalyserImpl::analyseModel()comparesmNlaSiblings.size() + 1withmUnknownVariables.size()for each NLA equation. Forsin(a) = x, that's 2 equations for 1 unknown (a). Underconstraint is already also checked across the whole NLA system (Analyser/Generator: various issues with a variable initialised by another variable #1487), but overconstraint isn't. - Generator: checking the whole system in the analyser isn't enough on its own.
Generator::GeneratorImpl::addNlaSystemsCode()takes an NLA system's unknowns from the first equation only. If the analyser accepted the model above, the generator would produce an objective function with 2 residuals but 1 unknown, andbwould never be solved:
void objectiveFunction0(double *u, double *f, void *data)
{
...
algebraicVariables[0] = u[0];
f[0] = sin(algebraicVariables[0])-states[0];
f[1] = algebraicVariables[0]*algebraicVariables[1]-(states[0]+2.0);
}
void findRoot0(...)
{
...
double u[1];
...
}Suggested fix
- Analyser: check overconstraint per NLA system: the number of equations against the number of distinct unknowns across all of its equations.
- Generator: build each NLA system's unknowns from all of its equations, and use them for the
uarray inobjectiveFunction[INDEX]()andfindRoot[INDEX]().
Activity
agarny commentedon Oct 6, 2026
Closing since we may not need to worry about this once we have merged PR #1400 in (for issue #1050).