Declarations
model Name(...) { ... } groups declarations and simultaneous equations.
Semicolons end declarations; // introduces a comment and /// attaches documentation.
Names are case-sensitive.
model Current(parameter voltage: V = 12, parameter resistance: Ohm = 4) { variable current: A; relation ohm { voltage = resistance * current; } observable measured_current: A = current;}The example describes Ohm’s law. Its default inputs give a current of 3 A.
| Declaration | Meaning |
|---|---|
parameter voltage: V = 12; |
A fixed input, here 12 volts |
variable current: A; |
An unknown determined by the equations |
state x: 1; |
A quantity that carries state across time |
input u: 1;, output y: 1; |
Causal signal endpoints of a model or component |
observable measured_current: A = current; |
A named measurement of the solution |
Parameters can appear in the model signature, as above, or inside its body.
Signature parameters can be bound explicitly when instantiating a
component.
Bare declaration numbers use coherent SI units; 1 as a type means dimensionless.
State and initial data
Section titled “State and initial data”model Decay() { parameter rate: 1 / s = 2; state x: 1; initial { x = 1; } relation evolution { derivative(x) = -rate * x; } observable remaining: 1 = x;}The initial equation sets and the evolution equation gives when is in seconds. An omitted initial value does not imply zero. See equations and state for clocked state.
Spatial fields and boundaries
Section titled “Spatial fields and boundaries”model Square() { domain body = box(0, 1, 0, 1); domain left = boundary(body, axis = 0, side = lower); variable temperature: K on body; relation uniform on body { temperature = 300[K]; }}box(0, 1, 0, 1) describes a square in the spatial coordinates.
left is its lower boundary on axis 0. on body makes temperature a spatial
field on that support. The equation fixes it to 300 K throughout the body.
A vector uses both a dimension and a component count:
variable displacement: vector<m, 2> on body;.
A spatial field declaration describes its physical values; mesh and numerical
approximation choices belong to the execution setup.
The continuum reference shows full models with all four boundaries. The fields lesson explains the difference between a physical field and its numerical coefficients.
Measurements
Section titled “Measurements”An observable adds a named expression without adding an equation. For example,
inside the current model:
observable power: W = voltage * current;After solving, read it with
result.observe(model.observable("power")).value; the default inputs give 36 W.
The voltage divider includes a full
compile-and-run example with current, voltage, and power observations.