Skip to content
Get started

Equations and state

Language overview · Install this source revision

Use relation name { left = right; }, optionally on support and at activation before the body. A relation can contain several ordered pairs of left and right expressions; all its equations hold simultaneously. For example, voltage = resistance * current expresses Ohm’s law, not an assignment.

Both sides are checked before the compiler forms a typed residual. A bare exact zero can take the other side’s dimension after expression admission; multiplying an invalid expression by zero does not make it admissible. A valid equation does not by itself establish that a numerical backend can solve it.

derivative(x) denotes the time derivative of an eligible continuous state, dividing its dimension by time. Spatial operators such as grad, div, trace and normal have separate support rules; the continuum examples show their existing standard declarations without selecting a discretization.

The ODE lesson uses state x: 1; initial { x = 1; } and the residual derivative(x) + rate * x = 0. Its complete source-installed example exercises State.initial(plan) and a run. The simultaneous initial equation belongs to the Model; a solver guess, tolerance or time step does not change that initial condition.

Use a supported accepted State for continuation rather than constructing a fresh initial State at every output time. An initial value is a mathematical input, not an implicit result of choosing a solver.

clocked.eqi — compilation example
model Counter() {
clock tick = periodic(1[s] / 10, phase = 0[s] / 1);
state memory: 1 at tick;
initial { memory = 0; }
relation advance at tick {
next(memory) - pre(memory) - 1 = 0;
}
}

The clock specifies a period of exactly 1/10 second and a phase of zero. pre(memory) refers to the pre-tick value; next(memory) participates in the candidate update. relation advance at tick activates the equation on that clock. pre and next require a state owned by that exact periodic clock; derivative is rejected there. This compilation example does not select a Python periodic execution method.

Clocked example source · relation parser · Next: Composition