Docs/Getting Started/Your First Model

Your First Model

This guide walks you through building a classic spring-mass-damper system in CoModel from scratch: setting an initial condition as the excitation, configuring parameters, running the simulation, and inspecting the results. Along the way you will become familiar with the editor's main operations and the simulation workflow.

The target model

We will build the following one-dimensional translational system:

  • A fixed end, Fixed;
  • A spring, Spring;
  • A damper, Damper;
  • A mass, Mass.

The spring and the damper are in parallel: one end connects to the fixed end, the other to the mass. Instead of applying an external force, we give the spring a 0.2 m initial deformation as the excitation: after release, the spring's restoring force and the damper's dissipation act together, and the system returns to equilibrium through decaying oscillation—one of the most classic transient responses of a mechanical system.

Step 1: Create the model

  1. Sign in to CoModel and click Models in the left navigation.
  2. Click New Model.
  3. Fill in the dialog:
    • Model name: SpringMassDamper
    • Description: Introductory example of a one-dimensional spring-mass-damper system
  4. Click Create; the graphical editor opens automatically.

New Model dialog

Naming tip: the model name must be a valid Julia module name starting with an uppercase letter, e.g. SpringMassDamper. If the name is reported as taken, append a number or a suffix.

Step 2: Drag in components

The editor is divided into three main areas:

  • Left sidebar: the component library, browsable by physical domain or searchable;
  • Center canvas: the modeling area, supporting drag-and-drop, connections, zoom, and pan;
  • Right panel: the properties panel and the Code View, switchable.

Locate the following components in the library on the left and drag them onto the canvas one by one:

Component Category Role
Fixed Mechanical · Translational Fixed reference end (anchors velocity)
Spring Mechanical · Translational Spring; provides the restoring force
Damper Mechanical · Translational Damper; provides the dissipative force
Mass Mechanical · Translational Movable mass

While dragging, a translucent placeholder preview appears; release the mouse and the component is placed on the canvas. Each component gets a unique instance name automatically, e.g. spring1, mass1.

Dragging components from the library onto the canvas

Category tip: the mechanical domain is subdivided by submodule (Mechanical · Translational, Mechanical · Rotational, etc.). Pick components under Mechanical · Translational—identically named components (such as Spring, Damper) have different port types under different subcategories, and a rotational port cannot connect to a translational one.

Adjust component positions

Select a component and drag to move it. While moving:

  • The canvas shows blue alignment guides automatically;
  • If grid snapping is enabled (bottom status bar), the component snaps in 10 px steps;
  • Connections re-route automatically to follow the port positions.

Place Fixed on the left, Spring and Damper in the middle, and Mass on the right so the physical topology is easy to read.

Step 3: Connect ports

Hover over a component port: it highlights and enlarges. Press and hold the mouse to pull out a rubber-band line. As the line approaches a compatible port, the target port highlights; release the mouse to complete the connection.

Connect as follows:

  1. Fixed port flange → Spring port flange_a.
  2. Fixed port flange → Damper port flange_a.
  3. Spring port flange_b → Mass port flange.
  4. Damper port flange_b → Mass port flange.

Connecting component ports to form the physical topology

Port compatibility tip: mechanical translational ports connect only to mechanical translational ports. If you try to connect to another physical domain (such as an electrical pin), the system warns in red and rejects the connection.

Once connected, the Code View on the right generates the corresponding connect(...) statements automatically, for example:

connect(fixed1.flange, spring1.flange_a)
connect(fixed1.flange, damper1.flange_a)
connect(spring1.flange_b, mass1.flange)
connect(damper1.flange_b, mass1.flange)

Step 4: Edit parameters and initial conditions

Edit parameters

  1. Click the Spring component on the canvas; the properties panel on the right lists its parameters (with units).
  2. Find the parameter k (spring stiffness) and change the default value to 1500.0, unit N/m.
  3. Select Damper and change the parameter d (damping coefficient) to 50.0, unit N·s/m.
  4. Select Mass and change the parameter m (mass) to 5.0, unit kg; leave the parameter g (gravitational acceleration) at its default 0—this example considers horizontal motion, with no gravity.

Parameter changes sync in real time to the instantiation statements in the Code View, for example:

@named damper1 = ModelingToolkitStandardLibrary.Mechanical.Translational.Damper(d=50)
@named mass1 = ModelingToolkitStandardLibrary.Mechanical.Translational.Mass(g=0, m=5)
@named spring1 = ModelingToolkitStandardLibrary.Mechanical.Translational.Spring(k=1500)

Editing component parameters in the properties panel

Set the initial condition (excitation)

Under zero initial conditions, a spring-mass-damper system with no deformation and no external force stays still forever—an object at equilibrium has no reason to move. We make the system start from a non-equilibrium state: select spring1 on the canvas, expand the Initial Conditions section in the properties panel on the right, and set an initial value for the state delta_s (the spring's internal deformation coordinate):

spring1.delta_s => 0.2   # initial spring deformation 0.2 m, i.e. an initial restoring force of k·delta_s = 300 N

The simulation is driven by this initial deformation: as the spring returns to its natural length, the mass undergoes decaying oscillation, and the system eventually settles back to equilibrium.

Rebuild tip: the initial condition is stored with the model's graphical state but is not part of the canvas topology—when you rebuild a model (e.g. re-create it on another machine, or redraw it after a reinstall), the components, connections, and parameters all come back, but the initial condition does not; it must be set again. This is the most common cause of "the same model produces only flat lines on another machine". To self-check, look at the System(...) constructor in the Code View: it should contain the line initialization_eqs = [spring1.delta_s ~ 0.2]; if that line is missing, the excitation has not been set.

Position semantics tip: the translational component library used here (Mechanical.Translational) is velocity-based modeling—Fixed constrains velocity only, no component carries absolute position information, and the mass position mass1.s is merely the integral of velocity (no restoring force, no reference point). When the spring deformation is released, mass1.s therefore rests at "initial value + 0.2 m" (delta_s + s = constant is conserved throughout): this is the net slippage of the mass as the spring returns to its natural length. Whether the mass is "pulled toward" the wall or "pushed away" from it depends on the mounting orientation—the model itself does not encode that. If you want the position-based picture of "wall at the origin, known spring natural length, mass pulled back to the equilibrium position", use the Mechanical.TranslationalModelica component family instead: set spring.s_rel0 = 0 and give the mass the initial condition mass.s = 0.2, and you get the classic picture of "oscillating from 0.2 m of stretch back to 0".

The Initial Conditions box accepts either a number or the name of a model-level parameter (define the parameter under Model Properties first, then reference it by name)—the latter lets parameter sweeps vary the initial state in bulk. Clearing the box restores the component's default guess (all zeros here, so the system stays still).

Step 5: Save the model

Click Save in the top toolbar, or press Ctrl + S. On save, the system:

  1. Generates the complete .jl source file from the current canvas;
  2. Persists the graphical state (nodes, connections, parameters, positions) to the instance database;
  3. Creates a version snapshot;
  4. Shows a Saved just now status at the top.

CoModel also autosaves every 5 minutes to prevent accidental loss.

Editor top toolbar and save status

Step 6: Configure and run the simulation

  1. Click Run Simulation in the top toolbar; the simulation configuration panel opens.
  2. Configure the following:
    • Solver: choose Tsit5 (a non-stiff ODE solver, suitable for this example).
    • Stop Time: 10.0, unit s.
    • Step size / tolerances: keep the defaults.
  3. Click Submit; the simulation job enters the server-side queue.

If the model has unsaved changes, the system saves them first, then submits the simulation job.

How the simulation runs

After submission, you can watch the job status in the bottom status bar or the simulation panel on the right:

  1. Pending: the job is queued.
  2. Running: the server-side solving kernel is compiling the system and integrating it.
  3. Completed: the simulation finished and the results are ready to view.

Simulation configuration panel with live progress

The first compile is slower: CoModel compiles the model on the server and caches the result. The first run may take a dozen or so seconds; recomputation after parameter changes is significantly faster.

Step 7: View the results

When the simulation completes, the results load automatically. In the results panel you can:

  1. Select the variables to plot, e.g. spring1₊delta_s(t) (spring deformation).
  2. Inspect the curves over time.
  3. Zoom and pan the curves, or export the results as CSV / PNG.

For this example you should see:

  • Spring deformation delta_s: starts at 0.2 m and decays over several cycles (theoretical period about 0.38 s), approaching 0 after roughly 2 s—the spring has returned to its natural length;
  • Mass position mass1.s: net slippage from 0 to 0.2 m (see the position-semantics tip in Step 4), a side effect of the deformation release;
  • Decay rate is set by damping and mass (with these parameters the amplitude drops to about 15% per cycle): the larger the damping, the faster the oscillation decays.

Simulation result curves panel

Step 8: Share the model

  1. Click Share in the top toolbar.
  2. Enter your colleague's registered email to share the model with them.
  3. After they sign in, the model appears under the Shared with Me tab on the Models page (read-only), with no local installation of any kind.

FAQ

Ports do not highlight / connection fails while drawing?

  • Make sure both ports belong to the same physical domain (all are mechanical translational in this example).
  • Make sure the components come from the same subcategory: only Mechanical · Translational components interconnect; Mechanical · Rotational components have different port types.

The simulation reports unconnected required ports?

  • Check whether any component has a critical port left unconnected. For example, the flange of Mass must connect to at least one mechanical element.
  • Check the validation results in the bottom status bar; click an error entry to locate the component.

The result curve is a flat zero?

  • The system is at equilibrium: with no initial deformation and no external force, a spring-mass-damper system stays still indefinitely.
  • Confirm you set a nonzero initial value for delta_s (e.g. 0.2) in the Initial Conditions section of spring1.
  • Rebuilt models are the classic trap: dragging a model back together (on a new machine, or after a reinstall) restores the components, connections, and parameters, but not the initial condition—set it again. Check the Code View: the System(...) constructor should contain initialization_eqs = [spring1.delta_s ~ 0.2], which confirms the excitation is in place.

The result curve is empty?

  • Confirm the simulation status is Completed, not Failed or Cancelled.
  • Check that you selected the right variables to plot.

Next steps

You have completed your first CoModel model. From here you can:

  • Change the initial value of delta_s to -0.2 and watch the response to deformation in the opposite direction, or increase Damper's d and watch the oscillation decay faster;
  • Define a model-level parameter under Model Properties, reference it in the initial condition, and use Parameter Sweeps to study the response across initial deformations in bulk;
  • Swap component parameters and observe how the response changes;
  • Add more components, such as a second mass or an external force source;
  • Import an FMU or an ONNX model and try AI + physics hybrid modeling;
  • Read Model Management to learn how to manage and share your models.