Skip to content

Switch solver from Rodas5P to Rodas5Pr and log resolved solver settings#33

Open
AnHeuermann wants to merge 7 commits intomainfrom
bound-error-alg-var
Open

Switch solver from Rodas5P to Rodas5Pr and log resolved solver settings#33
AnHeuermann wants to merge 7 commits intomainfrom
bound-error-alg-var

Conversation

@AnHeuermann
Copy link
Member

@AnHeuermann AnHeuermann commented Mar 19, 2026

Issue

Addresses SciML/BaseModelica.jl#101.

Changes

Configurable solver (SimulateSettings)

Add a SimulateSettings struct (analogous to CompareSettings) that holds the ODE solver and the saveat_n grid size for purely algebraic systems. A module-level singleton _SIM_SETTINGS is exposed via configure_simulate!() and simulate_settings(), and the struct can also be passed explicitly to run_simulate, test_model, and main.

# Change the global default
configure_simulate!(solver = OrdinaryDiffEqBDF.FBDF())

# Or pass per-call
main(sim_settings = SimulateSettings(solver = Rodas5P()))

Solver switch: Rodas5P → Rodas5Pr (default)

The default solver is now Rodas5Pr, a Rosenbrock-W variant with additional residual control. The previous switch to FBDF is now opt-in via SimulateSettings.

Purely algebraic system detection

After structural_simplify, some models have unknowns that are all algebraic (zero rows in the mass matrix). For these, the adaptive step controller has nothing to drive small steps and the dense interpolant error is unbounded. run_simulate now detects this via the mass matrix diagonal and falls back to a uniform saveat grid with adaptive = false.

Resolved solver settings in the log

Before solving, init() is called to resolve all defaults. The simulation log now records the fully-merged settings — solver name, saveat, abstol, reltol, adaptive, dense — so results are reproducible without reading source code.

Fixture-based tests (no OMC required)

runtests.jl is split into per-concern files and two new tests run from checked-in .bmo files and reference CSVs without needing an OMC installation:

  • bus_usage.jlModelica.Blocks.Examples.BusUsage: no unknowns after simplification; exercises the no-state saveat path.
  • amplifier_with_op_amp.jlModelica.Electrical.Analog.Examples.AmplifierWithOpAmpDetailed: full parse → simulate → reference verification against MAP-LIB results.

@AnHeuermann AnHeuermann self-assigned this Mar 19, 2026
@AnHeuermann AnHeuermann changed the title Switch solver from Rodas5P to FBDF and log resolved solver settings Switch solver from Rodas5P to Rodas5Pr and log resolved solver settings Mar 19, 2026
@AnHeuermann
Copy link
Member Author

I might have broken Modelica.Electrical.Analog.Examples.CharacteristicIdealDiodes.bmo on my local version / in this PR. Need to check that before merging.

AnHeuermann and others added 6 commits March 20, 2026 12:42
Replace Rodas5P with FBDF throughout run_simulate. Before solving, call
init() to resolve all default kwargs (abstol, reltol, adaptive, dense,
saveat) and write them to the simulation log. Fix saveat splatting bug
where a NamedTuple was spread as positional args instead of kwargs,
causing a convert(Vector{Float64}, ::Float64) error when the ODEProblem
carries a scalar saveat in its own kwargs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Introduce SimulateSettings struct so the ODE solver can be selected via
configure_simulate!() or passed directly to run_simulate/test_model/main.
Switch the default solver from Rodas5P to Rodas5Pr and log resolved
solver settings (abstol, reltol, adaptive, dense, saveat) by calling
init() before solve().

Split runtests.jl into per-concern files and add two fixture-based tests
that run without OMC: BusUsage (no-state model, saveat-grid path) and
AmplifierWithOpAmpDetailed (parse + simulate + reference verification).
Copy the required .bmo files and MAP-LIB reference results into
test/fixtures/.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@AnHeuermann AnHeuermann force-pushed the bound-error-alg-var branch from 37b727e to 9c166c8 Compare March 20, 2026 12:32
@AnHeuermann
Copy link
Member Author

The results are very bad with Rodas5Pr:

Stage Passed Total Rate
Base Modelica Export (OpenModelica) 452 457 98.9%
Parsing (BaseModelica.jl) 73 452 16.2%
Simulation (MTK.jl) 45 73 61.6%
Reference Comparison (MAP-LIB) 43 45 95.6%

A lot of models are failing simulation with Solver returned: Unstable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant