Language Guide ​
Dyad models physical systems with components, parameters, variables, connectors, and equations. An analysis specifies what to compute with a model, such as its response over time.
Start with Getting Started to build and simulate a model. Use this guide to understand the language and choose a modeling pattern. For exact forms and implementation limits, use the Syntax Reference.
Read a component ​
CoolingBody models a warm body cooling toward ambient temperature. Its equations determine the temperature, and its output connector makes that temperature available to other components. Download as a Dyad projectlanguage_intro.zipOpen in Dyad Studio
connector TemperatureOutput
output value::Real
end
component CoolingBody
parameter tau::Real = 30
parameter Tambient::Real = 293.15
parameter T0::Real = 353.15
variable T::Real
temperature = TemperatureOutput()
relations
initial T = T0
der(T) = (Tambient - T) / tau
temperature.value = T
endTemperatures in this example are in kelvin, and tau is in seconds. A positive tau sets how quickly the body approaches ambient temperature.
| Part of the definition | What it means in this model |
|---|---|
connector TemperatureOutput | Defines an interface carrying a temperature signal. Its output field is supplied by the component. |
component CoolingBody | Names a reusable model of a cooling body. |
parameter tau::Real = 30 | Declares a model setting with a default value. Each body can have a different time constant. |
parameter Tambient and parameter T0 | Set the ambient temperature and the body's initial temperature. |
variable T::Real | Declares the body's temperature as an unknown that the equations determine. |
temperature = TemperatureOutput() | Adds an instance of that connector to the body. |
relations | Starts the equations and connections that define behavior. |
initial T = T0 | Constrains the temperature at the start of the simulation. |
der(T) = (Tambient - T) / tau | Describes the rate of temperature change. |
temperature.value = T | Makes the output signal equal to the body's temperature. |
::Real declares a real-valued type. Parameters stay fixed during a simulation; variables can change as the model evolves. An equation states that its two sides are equal, so the equations in relations are solved together. Their order does not prescribe a sequence of assignments.
A connector makes a component's interface explicit. This example exposes a measurement signal. Physical connectors can also carry conserved flows, such as heat flow or electrical current; Connectors and Networks explains how connect(...) generates their connection equations.
Assemble components ​
A larger component can contain instances of other components. This model compares two bodies with different cooling rates:
component CoolingComparison
fast = CoolingBody(tau=10)
slow = CoolingBody(tau=30)
endfast and slow each have their own parameters, temperature variable, and output connector. tau=10 modifies the default for the fast body. Both bodies retain the default ambient and initial temperatures. The names fast.T and slow.T distinguish their temperatures in the assembled model.
This assembly contains two independent bodies. An assembly with interacting parts adds a relations block and connects their ports. See Components and Reuse for composition, inheritance, and reusable partial components.
Define an analysis ​
An analysis configures a computation on a model. This analysis uses TransientAnalysis to simulate both bodies for 180 seconds:
analysis CoolingTransient
extends TransientAnalysis(stop=180)
model = CoolingComparison()
endextends TransientAnalysis(...) selects the analysis implementation and configures its stop time. model = CoolingComparison() supplies the assembled model. The analysis uses the initial equations declared by each body.
The compiler translates the definitions into ModelingToolkit models and Julia analysis functions. After compiling the library, call the generated analysis function:
result = CoolingTransient()The result contains the simulated response and analysis artifacts. See Analyses for running, plotting, and inspecting results, and Getting Started for the complete build-and-simulate workflow.
Choose a modeling task ​
| I want to… | Read |
|---|---|
| Declare parameters and variables; write equations and initial conditions | Parameters, Variables, and Equations |
| Build a reusable part or assemble a subsystem | Components and Reuse |
| Connect physical ports or pass a signal | Connectors and Networks |
| Write a sampled controller or difference equation | Discrete-Time Modeling |
| Share a medium and transport fluid properties | Media and Fluids |
| Give a component an icon and arrange its diagram | Graphical Models and Metadata |
| Look up a declaration, operator, or relation | Syntax Reference |
| Configure a simulation or another workflow | Analyses |
Continue with Parameters, Variables, and Equations, or use the keyword index to find a specific form.
Syntax index ​
Each entry links a language form to its explanation or reference.
Components ​
component, instance declarations, extends, and partial component: Components and Reuse.
Analyses ​
analysis configures a computation on a model: Analyses; syntax.
Importing libraries ​
using imports definitions and typed Julia functions: Libraries and Julia functions.
Variables ​
variable x::Real declares an unknown: Parameters and variables.
Parameters ​
parameter declares a setting; final parameter prevents modification: Parameters and variables.
Parameters from a file ​
apply "dyad://MyLibrary/settings.toml" loads instance settings: Loading parameters from a file.
Structural parameters ​
structural parameter controls model construction: Arrays and repeated equations.
Connectors ​
connector defines an interface and its connection semantics: Connectors and Networks.
Relations: equations and connections ​
relations introduces equations and connections: equations; connections.
Expressions ​
Literals, references, operators, and calls: Expressions and time.
Operators ​
Arithmetic, comparison, and logical operators: expression reference.
Function calls ​
Calls such as sin(time) and typed Julia imports: Libraries and Julia functions.
Conditional expressions ​
condition ? a : b chooses a value: Expressions and time.
Literals ​
Numbers, strings, booleans, and arrays: expression reference.
Time ​
time and der(x) express continuous-time behavior: equations; clock ticks.
Arrays ​
Dimensions, indexing, literals, and comprehensions: arrays; component arrays.
Clocks ​
@[...] binds clocks; x@(clk-1) reads a past sample: Clocks and discrete-time models.
Structural relations ​
Loops and structural branches choose sets of equations: Structural choices.
Enums and switch-case ​
enum defines alternatives; switch selects relations: Enums and switch.
If statements ​
A relation if selects model structure: Structural choices.
Metadata ​
Definition and element annotations: Graphical Models and Metadata.
Linked metadata ​
{^tag} uses an entry from _links: Linked metadata.