OpenModelica Link - Run Modelica Simulations (Start → Load → Simulate)

Integrating OpenModelica into your application is a big win when you need fast iteration on dynamic system models: you can run simulations, validate behavior, and automate design studies (parameter sweeps, regression tests, optimization loops) without leaving your scripting environment.

With om_link, JSLAB can act as the “driver” for OpenModelica: start the tool, send Modelica commands, load models, simulate, and collect results programmatically.


Why this matters

OpenModelica is commonly used for:

  • multi-domain system simulation (mechanical, electrical, thermal, control, hydraulics…)

  • behavior validation early in design (before hardware exists)

  • automated testing of model changes in CI pipelines

  • design-space exploration (repeatable simulation runs with different parameters)

Connecting it to JSLAB means you can combine:

  • your own preprocessing/postprocessing code,

  • custom visualization,

  • data logging,

  • and multi-run automation,
    all around a proven Modelica simulation engine.


JavaScript Example

This minimal example shows the full lifecycle:

  1. Start OpenModelica

  2. Query version

  3. Define a tiny model (demo)

  4. Load a .mo model file

  5. List available classes

  6. Run a simulation (BouncingBall)

  7. Close the connection

// OpenModelica Link

await om_link.start(exe); // Start OpenModelica
disp(await om_link.sendExpression("getVersion()"));

// Simple inline test model
disp(await om_link.sendExpression("model a end a;"));

// Load a Modelica file (.mo)
disp(await om_link.sendExpression('loadFile("' + model + '")'));

// Inspect loaded classes
disp(await om_link.sendExpression("getClassNames()"));

// Run a simulation (example model)
disp(await om_link.sendExpression("simulate(BouncingBall)"));

// Close connection
await om_link.close();


Notes / Tips

  • sendExpression(...) sends commands directly to the OpenModelica scripting interface (OMC). This is the core primitive you’ll use for everything: loading libraries, setting parameters, running simulations, exporting results, etc.

  • getClassNames() is useful to confirm what the loaded file/library contains (and that your load succeeded).

  • simulate(...) returns a result structure from OpenModelica; depending on your setup you can then load/plot the produced result file (e.g., *.mat) in your JSLAB workflow.


Where to go next

If you want to turn this into a real engineering workflow, the typical next steps are:

  • Set model parameters before simulation (e.g., mass, stiffness, controller gains)

  • Run multiple simulations (parameter sweep / Monte Carlo)

  • Parse and plot results automatically (time histories, phase plots, metrics)

  • Export reports (plots + tables) from the same script that runs the simulation