System Modeler in WLJS

Modelica models from Wolfram System Modeler 15.0, simulated in the WLJS notebook's Wolfram kernel (no System Modeler window). Part of [wljs-agent-skills](https://github.com/ptown16801-lang/wljs-agent-skills). The kernel runs with internet off.

circuit`sim = SystemModelSimulate["IntroductoryExamples.ComponentBased.ElectricCircuit", 10]; SystemModelPlot[circuit`sim, {"inductor1.i", "capacitor1.v"}, PlotRange -> All, PlotLegends -> {"inductor current (A)", "capacitor voltage (V)"}]

Parameter sweep

The same circuit with three values of `resistor1.R`, each a separate simulation; the results come back as Wolfram Language data.

circuit`sweep = Table[SystemModelSimulate["IntroductoryExamples.ComponentBased.ElectricCircuit", 10, <|"ParameterValues" -> {"resistor1.R" -> r}|>], {r, {1, 10, 100}}]; Plot[Evaluate[#["capacitor1.v"][t] & /@ circuit`sweep], {t, 0, 10}, PlotRange -> All, PlotLegends -> {"R1 = 1 Ω", "R1 = 10 Ω", "R1 = 100 Ω"}, AxesLabel -> {"t (s)", "capacitor voltage (V)"}]

A mechanical example from the Modelica Standard Library

`Modelica.Mechanics.Rotational.Examples.First`: a motor drives two inertias through a gearbox and an elastic shaft.

first`sim = SystemModelSimulate["Modelica.Mechanics.Rotational.Examples.First", 1]; SystemModelPlot[first`sim, {"inertia1.w", "inertia2.w", "inertia3.w"}, PlotRange -> All, PlotLegends -> {"inertia1.w", "inertia2.w", "inertia3.w"}] "Speed of inertia1 at t = 1 s: " <> ToString[NumberForm[first`sim["inertia1.w", 1], 4]] <> " rad/s" NotebookSave[EvaluationNotebook[], FileNameJoin[{$HomeDirectory, "Documents", "Claude", "portfolio-build", "showcase-notebooks", "system-modeler-in-wljs.wln"}]];