Skip to content

Analyser: well-posed NLA system reported as overconstrained when its equations have different unknowns #1488

Closed

Description

@agarny

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() compares mNlaSiblings.size() + 1 with mUnknownVariables.size() for each NLA equation. For sin(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, and b would 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

  1. Analyser: check overconstraint per NLA system: the number of equations against the number of distinct unknowns across all of its equations.
  2. Generator: build each NLA system's unknowns from all of its equations, and use them for the u array in objectiveFunction[INDEX]() and findRoot[INDEX]().

Activity

  1. self-assigned this
    on Oct 5, 2026
  2. agarny commented on Oct 6, 2026

    @agarny
    ContributorAuthor

    Closing since we may not need to worry about this once we have merged PR #1400 in (for issue #1050).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions