# Build a Modelica network

AI agent getting started? Read [Agents: start here](https://docs.openeng.io/agents/start-here.md) first.

Check a connected Modelica case, build its outputs and review results across branches.

Source: https://docs.openeng.io/guides/modelica-network/

A Modelica network connects saved components to engineering parts. A build compiles and simulates
that network. Its results carry the inputs they were built from, so a link can distinguish a
current result from one that needs rebuilding.

## Publish the types

An organisation administrator publishes the build and Modelica types through the ontology SDK,
using the Modelica pack and the organisation's part and specification types. Include the
relationship from the part type to the component type. Review and publish this through
[a type change set](https://docs.openeng.io/configure/types.md). Types are shared across the organisation; the network's
objects and relationships are saved on a project branch.

## Save parts and connect components

Choose the project and a working branch. Use the objects SDK, or ask an agent using it, to save
the network. Functions, steps, cases, outputs and components appear as ordinary objects in
**Explore**; open their details to inspect them.

1. Save three parts carrying resistance, capacitance and voltage.
2. Save source, resistor, capacitor and ground components. Bind the first three to their parts
   through refinement relationships; ground needs no part. Each component declares its Modelica
   class, library, ports and parameter bindings.
3. Connect source `p` to resistor `p`, resistor `n` to capacitor `p`, and ground `p` to capacitor
   `n`. Save a case containing all four components and an experiment stop time.
4. Call `checkCase` through the objects SDK. This incomplete network reports source `n` as an
   open port. Add the connection from capacitor `n` to source `n`, then check again. An empty
   successful check shows **No check violations**. Correct the named objects and ports when
   violations remain. A clear check does not promise compilation will succeed: omitting ground,
   for example, can pass this check and fail compilation.

You can also check a case from the web. Open the case and choose **Check case** beside **Build**;
a clear check shows **No check violations**. A case has no editable fields in the web, but a writer
still sees **Build** and **Check case** on it.

A component's source is a labelled multiline field. **Edit** opens the property draft where
available; **Save** confirms it and **Discard** abandons it. Enter inserts a newline;
Command+Enter uses the form's normal submission. Read mode preserves line breaks.

## Save the build and inspect its result

1. Through the objects SDK, save the compile and simulate functions, then the two steps applying
   them. Saving each step creates its declared output objects in the same commit: the compile
   step's `compiled-model` and the simulation step's `result`.
2. Link a specification to `result` with a voltage bound of at most 5 V. Its selector names the
   capacitor component, variable `v` and quantity `voltage`.
3. Open `result` and choose **Build**. The control shows **Building…**, then **Build started**
   with the confirmed run. The compile step runs first; simulation follows after its compiled
   model is available. Open the run's step records to inspect progress and logs. If the case is
   refused, **The case check has violations.** remains beside Build with the named violations.
4. Read **Values** below the output's properties. An indexed value names its component,
   variable, sweep point and reduction, and shows the number and unit together. **Run**, **Ref**
   and **Engine** identify its provenance; Run opens the step run. An opaque output instead
   shows **No indexed values**.
5. Read **Links**. For this selector link, **Result** shows **Current** and **Bounds** shows
   **In bounds** when the voltage meets the limit. **Review**, **Bounds** and **Result** are
   separate states; one does not determine the others.

## Change an input and rebuild

Change the resistor part's resistance on the branch, then reload the link status. **Result**
shows **Stale** and **Bounds** shows **No value**. A change to a property that feeds no parameter
leaves this result **Current**. Choose **Build** again to rebuild with the changed input. Both
steps run because the network bundle changed; a successful rebuild makes the result **Current**.

**No result** means no result exists for the declared key. **Not visible** withholds the value and
its provenance. **Too many links** shows no partial value. Read these states before relying on a
number; see [tracked links and bounds](https://docs.openeng.io/guides/link-status.md) for the other link states.

## Sweep a parameter

Through the objects SDK, add a case sweep of the resistor member's `R` over 50 values. A build
runs one compile and 50 simulations. Give a specification link's selector one sweep point to
read that point's value.

Change 38 values and choose **Build** again. The decision says **Some requested outputs are
already current; nothing was started.** and **12 of 50 cases are already current**. Choose
**Run stale** to run the 38 changed cases, reusing the compile result. **Run all** requests every
target again, including current upstream work. **Cancel** starts nothing. If everything is
current, the control can report **No build started; requested outputs are current**.

## Merge the branch

Results follow content keys across branches. Two branches with equal inputs can both show
**Current** from the same run; its **Ref** still names the branch where it ran.

A merge moves no result and results do not block it. On the destination, matching inputs show
**Current**; changed inputs without a matching result show **Stale**. Build on a working branch:
a build on merge-only `main` is refused, with the existing branch choice. After merging, `main`
can read the branch's result as **Current** when its content key matches. Definitions on a
merge-only branch also change through a merge. Deleting the working branch keeps its runs
available to project readers.
