---
url: /dyad/stable/manual/syntax.md
description: >-
  Learn to express physical systems, reusable components, discrete-time
  behavior, and graphical models in Dyad.
---

# Language Guide {#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](/tutorials/getting-started#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](language/syntax-reference.md).

## Read a component {#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›

```dyad
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
end
```

Temperatures 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](language/connectors.md) explains how `connect(...)` generates their connection equations.

## Assemble components {#Assemble-components}

A larger component can contain instances of other components. This model compares two bodies with different cooling rates:

```dyad
component CoolingComparison
  fast = CoolingBody(tau=10)
  slow = CoolingBody(tau=30)
end
```

`fast` 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](components.md) for composition, inheritance, and reusable partial components.

## Define an analysis {#Define-an-analysis}

An analysis configures a computation on a model. This analysis uses `TransientAnalysis` to simulate both bodies for 180 seconds:

```dyad
analysis CoolingTransient
  extends TransientAnalysis(stop=180)
  model = CoolingComparison()
end
```

`extends 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:

```julia
result = CoolingTransient()
```

The result contains the simulated response and analysis artifacts. See [Analyses](analyses.md) for running, plotting, and inspecting results, and [Getting Started](/tutorials/getting-started#getting_started) for the complete build-and-simulate workflow.

## Choose a modeling task {#Choose-a-modeling-task}

| I want to…                                                               | Read                                                                     |
|:------------------------------------------------------------------------ |:------------------------------------------------------------------------ |
| Declare parameters and variables; write equations and initial conditions | [Parameters, Variables, and Equations](language/values-and-equations.md) |
| Build a reusable part or assemble a subsystem                            | [Components and Reuse](components.md)                                    |
| Connect physical ports or pass a signal                                  | [Connectors and Networks](language/connectors.md)                        |
| Write a sampled controller or difference equation                        | [Discrete-Time Modeling](language/discrete-time.md)                      |
| Share a medium and transport fluid properties                            | [Media and Fluids](language/media-and-fluids.md)                         |
| Give a component an icon and arrange its diagram                         | [Graphical Models and Metadata](language/metadata.md)                    |
| Look up a declaration, operator, or relation                             | [Syntax Reference](language/syntax-reference.md)                         |
| Configure a simulation or another workflow                               | [Analyses](analyses.md)                                                  |

Continue with [Parameters, Variables, and Equations](language/values-and-equations.md), or use the keyword index to find a specific form.

## Syntax index {#Syntax-index}

Each entry links a language form to its explanation or reference.

### Components {#syntax-components}

`component`, instance declarations, `extends`, and `partial component`: [Components and Reuse](components.md).

### Analyses {#syntax-analyses}

`analysis` configures a computation on a model: [Analyses](analyses.md); [syntax](/manual/language/syntax-reference#Analyses).

### Importing libraries {#syntax-importing-libraries}

`using` imports definitions and typed Julia functions: [Libraries and Julia functions](/manual/language/values-and-equations#Libraries-and-Julia-functions).

### Variables {#syntax-variables}

`variable x::Real` declares an unknown: [Parameters and variables](/manual/language/values-and-equations#Choose-the-kind-of-quantity).

### Parameters {#syntax-parameters}

`parameter` declares a setting; `final parameter` prevents modification: [Parameters and variables](/manual/language/values-and-equations#Choose-the-kind-of-quantity).

#### Parameters from a file {#Parameters-from-a-file}

`apply "dyad://MyLibrary/settings.toml"` loads instance settings: [Loading parameters from a file](/manual/language/loading-parameters#syntax-apply).

#### Structural parameters {#syntax-structural-parameters}

`structural parameter` controls model construction: [Arrays and repeated equations](/manual/language/values-and-equations#Arrays-and-repeated-equations).

### Connectors {#syntax-connectors}

`connector` defines an interface and its connection semantics: [Connectors and Networks](language/connectors.md).

### Relations: equations and connections {#syntax-relations}

`relations` introduces equations and connections: [equations](/manual/language/values-and-equations#Write-equations); [connections](language/connectors.md).

### Expressions {#syntax-expressions}

Literals, references, operators, and calls: [Expressions and time](/manual/language/values-and-equations#Expressions-and-time).

#### Operators {#syntax-operators}

Arithmetic, comparison, and logical operators: [expression reference](/manual/language/syntax-reference#Expressions).

#### Function calls {#syntax-function-calls}

Calls such as `sin(time)` and typed Julia imports: [Libraries and Julia functions](/manual/language/values-and-equations#Libraries-and-Julia-functions).

#### Conditional expressions {#syntax-conditional-expressions}

`condition ? a : b` chooses a value: [Expressions and time](/manual/language/values-and-equations#Expressions-and-time).

#### Literals {#syntax-literals}

Numbers, strings, booleans, and arrays: [expression reference](/manual/language/syntax-reference#Expressions).

#### Time {#syntax-time}

`time` and `der(x)` express continuous-time behavior: [equations](/manual/language/values-and-equations#Write-equations); [clock ticks](language/discrete-time.md).

### Arrays {#syntax-arrays}

Dimensions, indexing, literals, and comprehensions: [arrays](/manual/language/values-and-equations#Arrays-and-repeated-equations); [component arrays](/manual/components#Arrays-of-components).

### Clocks {#syntax-clocks}

`@[...]` binds clocks; `x@(clk-1)` reads a past sample: [Clocks and discrete-time models](language/discrete-time.md).

### Structural relations {#syntax-control-flow}

Loops and structural branches choose sets of equations: [Structural choices](/manual/language/values-and-equations#Structural-choices).

#### Enums and switch-case {#syntax-enums-and-switch-case}

`enum` defines alternatives; `switch` selects relations: [Enums and switch](/manual/language/syntax-reference#Enums-and-switch).

#### If statements {#syntax-if-statements}

A relation `if` selects model structure: [Structural choices](/manual/language/values-and-equations#Structural-choices).

### Metadata {#syntax-metadata}

Definition and element annotations: [Graphical Models and Metadata](language/metadata.md).

#### Linked metadata {#syntax-linked-metadata}

`{^tag}` uses an entry from `_links`: [Linked metadata](/manual/language/metadata#Linked-metadata).
