Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions test/ExampleDAE/ExampleDAEs.jl → examples/ExampleDAEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ import DAE.ClassInf
include("helloWorld.jl")
include("bouncingBall.jl")
include("vanDerPol.jl")
include("influenca.jl")
include("lotkaVolterra.jl")
include("simpleMech.jl")
include("simpleCircuit.jl")

export helloWorld_DAE
export bouncingBall_DAE
export vanDerPol_DAE
export influenca_DAE
export lotkaVolterra_DAE
export simpleMech_DAE
export simpleCircuit_DAE
Expand Down
31 changes: 31 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# OMBackend examples

This directory contains example models expressed as hand-built `DAE.DAE_LIST`
values — the intermediate representation OMBackend consumes from the frontend.
They double as the test suite's stable backend contract (`test/runtests.jl`
includes `ExampleDAEs.jl` from here).

## Models (`ExampleDAEs.jl`)

| Binding | Model name | Notes |
|----------------------|-------------------------|-----------------------------|
| `helloWorld_DAE` | `HelloWorld` | trivial scalar ODE |
| `lotkaVolterra_DAE` | `LotkaVolterra` | predator–prey ODE |
| `vanDerPol_DAE` | `VanDerPol` | stiff oscillator |
| `bouncingBall_DAE` | `BouncingBall` | hybrid / events |
| `simpleMech_DAE` | `SimpleMechanicalSystem`| mechanical |
| `simpleCircuit_DAE` | `SimpleCircuit` | electrical |

(`HelloWorld`, `LotkaVolterra` and `VanDerPol` are verified to translate and
simulate to `retcode = Success` via the MTK backend on Julia 1.12 / Windows.)

## Run

From an environment where `OMBackend` is available (e.g. the OMJL dev project):

```julia
julia --project=. examples/simulate_examples.jl
```

This translates each model with `OMBackend.translate(...; BackendMode = OMBackend.MTK_MODE)`
and simulates it with `OMBackend.simulateModel(name; tspan, solver)`.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions examples/simulate_examples.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Runnable demo: translate + simulate the example DAEs through the OMBackend MTK
# pipeline. Run from an environment where OMBackend is available:
#
# julia --project=. examples/simulate_examples.jl
#
import OMBackend
include(joinpath(@__DIR__, "ExampleDAEs.jl"))
import .ExampleDAEs

# (model name, ExampleDAEs binding, tspan)
const CASES = [
("HelloWorld", :helloWorld_DAE, (0.0, 1.0)),
("LotkaVolterra", :lotkaVolterra_DAE, (0.0, 10.0)),
("VanDerPol", :vanDerPol_DAE, (0.0, 10.0)),
]

for (name, sym, tspan) in CASES
dae = getproperty(ExampleDAEs, sym)
OMBackend.translate(dae; BackendMode = OMBackend.MTK_MODE)
sol = OMBackend.simulateModel(name; tspan = tspan)
inner = hasproperty(sol, :diffEqSol) ? getfield(sol, :diffEqSol) : sol
rc = try; string(inner.retcode); catch; "?"; end
@info "simulated $name" tspan retcode = rc
end
File renamed without changes.
6 changes: 0 additions & 6 deletions test/ExampleDAE/README.md

This file was deleted.

25 changes: 0 additions & 25 deletions test/ExampleDAE/influenca.jl

This file was deleted.

4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ using Test
using Dates
using DifferentialEquations: ReturnCode

include("./ExampleDAE/ExampleDAEs.jl")
include("../examples/ExampleDAEs.jl")
import .ExampleDAEs

@testset "OMBackend" begin
Expand Down Expand Up @@ -117,7 +117,7 @@ import .ExampleDAEs
ENV["OMJL_LOG_DIR"] = $(repr(tmp))
cd($(repr(repoRoot)))
include("src/OMBackend.jl")
include("test/ExampleDAE/ExampleDAEs.jl")
include("examples/ExampleDAEs.jl")
using .ExampleDAEs
println("same_module=", OMBackend === OMBackend.CodeGeneration.OMBackend)
OMBackend.translate(ExampleDAEs.helloWorld_DAE; BackendMode = OMBackend.MTK_MODE)
Expand Down
Loading