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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.mo linguist-language=Modelica
*.bmo linguist-language=Modelica
*.html.tpl linguist-language=HTML
4 changes: 2 additions & 2 deletions .github/workflows/test_julia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
julia-version: [1.11]
julia-version: [1.12]
fail-fast: false
runs-on: ${{ matrix.os }}
timeout-minutes: 60
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
julia-version: [1.11]
julia-version: [1.12]
omc-version: [stable]
python-version: ['3.10']
fail-fast: false
Expand Down
2 changes: 2 additions & 0 deletions TestBaseModelica/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.CondaPkg/
test/test_out/
771 changes: 384 additions & 387 deletions TestBaseModelica/Manifest.toml

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions TestBaseModelica/Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
name = "TestBaseModelica"
uuid = "bba3f925-4bbc-4b14-b723-9b95a7c9c63c"
authors = ["AnHeuermann <[email protected]>"]
version = "0.1.0"
authors = ["AnHeuermann <[email protected]>"]

[deps]
BaseModelica = "a17d5099-185d-4ff5-b5d3-51aa4569e56d"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"

[sources]
BaseModelica = {rev = "main", url = "https://github.com/SciML/BaseModelica.jl.git"}

[compat]
ModelingToolkit = "10"
OrdinaryDiffEq = "6"
SciMLBase = "2"

[extras]
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Expand Down
36 changes: 18 additions & 18 deletions TestBaseModelica/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ Test coupling of Base Modelica export off OpenModelica and

For a Base Modelica file exported by OpenModelica parsing with
[BaseModelica.jl](https://github.com/SciML/BaseModelica.jl) and simulating with
[DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl) is
[OrdinaryDiffEq.jl](https://github.com/SciML/OrdinaryDiffEq.jl) is
tested.

## Dependencies

- Julia
- Julia packages
- Julia
- Julia packages

## Precompilation

To speed up the execution of the test and reduce the TTFP-overhad of Julia there are two options:

1. Precompile this package with
[PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl) and
start a new Julia session for each test.
[PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl) and
start a new Julia session for each test.

```julia
julia> using PackageCompiler
(@v1.11) pkg> activate .
julia> create_sysimage(["TestBaseModelica"]; sysimage_path="TestBaseModelica.so", precompile_execution_file="precompile_skript.jl" )
```
```julia
julia> using PackageCompiler
(@v1.11) pkg> activate .
julia> create_sysimage(["TestBaseModelica"]; sysimage_path="TestBaseModelica.so", precompile_execution_file="precompile_skript.jl" )
```

```bash
time julia --project=$(pwd) -e 'using TestBaseModelica; solver_settings=SolverSettings(start_time=0.0, stop_time=1.0, interval=0.02, tolerance=1e-6); test_settings=TestSettings(modelname="ExampleFirstOrder", output_directory="ExampleFirstOrder", solver_settings=solver_settings); run_test(joinpath("examples", "ExampleFirstOrder.mo"); settings=test_settings)'
```bash
time julia --project=$(pwd) -e 'using TestBaseModelica; solver_settings=SolverSettings(start_time=0.0, stop_time=1.0, interval=0.02, tolerance=1e-6); test_settings=TestSettings(modelname="FirstOrder", output_directory="FirstOrder", solver_settings=solver_settings); run_test(joinpath("examples", "FirstOrder.bmo"); settings=test_settings)'

time julia --sysimage=TestBaseModelica.so -e 'using .TestBaseModelica; solver_settings=SolverSettings(start_time=0.0, stop_time=1.0, interval=0.02, tolerance=1e-6); test_settings=TestSettings(modelname="ExampleFirstOrder", output_directory="ExampleFirstOrder", solver_settings=solver_settings); run_test(joinpath("examples", "ExampleFirstOrder.mo"); settings=test_settings)'
```
time julia --sysimage=TestBaseModelica.so -e 'using .TestBaseModelica; solver_settings=SolverSettings(start_time=0.0, stop_time=1.0, interval=0.02, tolerance=1e-6); test_settings=TestSettings(modelname="FirstOrder", output_directory="FirstOrder", solver_settings=solver_settings); run_test(joinpath("examples", "FirstOrder.bmo"); settings=test_settings)'
```

2. Keep a Julia daemon running in the background for all tests by using
[DaemonMode.jl](https://github.com/dmolina/DaemonMode.jl)
[DaemonMode.jl](https://github.com/dmolina/DaemonMode.jl)

## How to use

Expand All @@ -49,9 +49,9 @@ solver_settings = SolverSettings(
)

test_settings = TestSettings(
modelname = "ExampleFirstOrder",
output_directory = "ExampleFirstOrder",
modelname = "FirstOrder",
output_directory = "FirstOrder",
solver_settings = solver_settings)

run_test(joinpath("examples", "ExampleFirstOrder.mo"); settings = test_settings)
run_test(joinpath("examples", "FirstOrder.bmo"); settings = test_settings)
```
177 changes: 177 additions & 0 deletions TestBaseModelica/examples/CauerLowPassAnalog.bmo
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
//! base 0.1.0
package 'CauerLowPassAnalog'
model 'CauerLowPassAnalog' "Cauer low pass filter with analog components"
parameter Real 'l1'(unit = "H", quantity = "Inductance") = 1.304 "Filter coefficient I1";
parameter Real 'l2'(unit = "H", quantity = "Inductance") = 0.8586 "Filter coefficient I2";
parameter Real 'c1'(min = 0.0, unit = "F", quantity = "Capacitance") = 1.072 "Filter coefficient c1";
parameter Real 'c2'(min = 0.0, unit = "F", quantity = "Capacitance") = 1.0 / (2.906997720064 * 'l1') "Filter coefficient c2";
parameter Real 'c3'(min = 0.0, unit = "F", quantity = "Capacitance") = 1.682 "Filter coefficient c3";
parameter Real 'c4'(min = 0.0, unit = "F", quantity = "Capacitance") = 1.0 / (1.392270203025 * 'l2') "Filter coefficient c4";
parameter Real 'c5'(min = 0.0, unit = "F", quantity = "Capacitance") = 0.7262 "Filter coefficient c5";
Real 'G.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'G.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C1.v'(fixed = true, start = 0.0, unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'C1.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C1.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C1.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C1.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C1.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'C1.C'(start = 1.0, min = 0.0, unit = "F", quantity = "Capacitance") = 'c1' "Capacitance";
Real 'C2.v'(start = 0.0, unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'C2.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C2.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C2.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C2.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C2.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'C2.C'(start = 1.0, min = 0.0, unit = "F", quantity = "Capacitance") = 'c2' "Capacitance";
Real 'C3.v'(fixed = true, start = 0.0, unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'C3.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C3.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C3.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C3.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C3.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'C3.C'(start = 1.0, min = 0.0, unit = "F", quantity = "Capacitance") = 'c3' "Capacitance";
Real 'C4.v'(start = 0.0, unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'C4.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C4.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C4.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C4.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C4.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'C4.C'(start = 1.0, min = 0.0, unit = "F", quantity = "Capacitance") = 'c4' "Capacitance";
Real 'C5.v'(fixed = true, start = 0.0, unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'C5.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C5.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C5.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'C5.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'C5.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'C5.C'(start = 1.0, min = 0.0, unit = "F", quantity = "Capacitance") = 'c5' "Capacitance";
Real 'L1.v'(unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'L1.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'L1.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'L1.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'L1.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'L1.i'(fixed = true, start = 0.0, unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'L1.L'(start = 1.0, unit = "H", quantity = "Inductance") = 'l1' "Inductance";
Real 'L2.v'(unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'L2.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'L2.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'L2.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'L2.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'L2.i'(fixed = true, start = 0.0, unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'L2.L'(start = 1.0, unit = "H", quantity = "Inductance") = 'l2' "Inductance";
parameter Real 'R1.R'(start = 1.0, unit = "Ohm", quantity = "Resistance") = 1.0 "Resistance at temperature T_ref";
parameter Real 'R1.T_ref'(nominal = 300.0, start = 288.15, min = 0.0, displayUnit = "degC", unit = "K", quantity = "ThermodynamicTemperature") = 300.15 "Reference temperature";
parameter Real 'R1.alpha'(unit = "1/K", quantity = "LinearTemperatureCoefficient") = 0.0 "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))";
Real 'R1.v'(unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'R1.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'R1.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'R1.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'R1.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'R1.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Boolean 'R1.useHeatPort' = false "= true, if heatPort is enabled" annotation(Evaluate = true);
parameter Real 'R1.T'(nominal = 300.0, start = 288.15, min = 0.0, displayUnit = "degC", unit = "K", quantity = "ThermodynamicTemperature") = 'R1.T_ref' "Fixed device temperature if useHeatPort = false";
Real 'R1.LossPower'(unit = "W", quantity = "Power") "Loss power leaving component via heatPort";
Real 'R1.T_heatPort'(nominal = 300.0, start = 288.15, min = 0.0, displayUnit = "degC", unit = "K", quantity = "ThermodynamicTemperature") "Temperature of heatPort";
Real 'R1.R_actual'(unit = "Ohm", quantity = "Resistance") "Actual resistance = R*(1 + alpha*(T_heatPort - T_ref))";
parameter Real 'R2.R'(start = 1.0, unit = "Ohm", quantity = "Resistance") = 1.0 "Resistance at temperature T_ref";
parameter Real 'R2.T_ref'(nominal = 300.0, start = 288.15, min = 0.0, displayUnit = "degC", unit = "K", quantity = "ThermodynamicTemperature") = 300.15 "Reference temperature";
parameter Real 'R2.alpha'(unit = "1/K", quantity = "LinearTemperatureCoefficient") = 0.0 "Temperature coefficient of resistance (R_actual = R*(1 + alpha*(T_heatPort - T_ref))";
Real 'R2.v'(unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'R2.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'R2.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'R2.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'R2.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'R2.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Boolean 'R2.useHeatPort' = false "= true, if heatPort is enabled" annotation(Evaluate = true);
parameter Real 'R2.T'(nominal = 300.0, start = 288.15, min = 0.0, displayUnit = "degC", unit = "K", quantity = "ThermodynamicTemperature") = 'R2.T_ref' "Fixed device temperature if useHeatPort = false";
Real 'R2.LossPower'(unit = "W", quantity = "Power") "Loss power leaving component via heatPort";
Real 'R2.T_heatPort'(nominal = 300.0, start = 288.15, min = 0.0, displayUnit = "degC", unit = "K", quantity = "ThermodynamicTemperature") "Temperature of heatPort";
Real 'R2.R_actual'(unit = "Ohm", quantity = "Resistance") "Actual resistance = R*(1 + alpha*(T_heatPort - T_ref))";
parameter Real 'V.V'(start = 1.0, unit = "V", quantity = "ElectricPotential") = 1.0 "Height of step";
Real 'V.v'(unit = "V", quantity = "ElectricPotential") "Voltage drop of the two pins (= p.v - n.v)";
Real 'V.p.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'V.p.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'V.n.v'(unit = "V", quantity = "ElectricPotential") "Potential at the pin";
Real 'V.n.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing into the pin";
Real 'V.i'(unit = "A", quantity = "ElectricCurrent") "Current flowing from pin p to pin n";
parameter Real 'V.signalSource.height' = 'V.V' "Height of step";
Real 'V.signalSource.y' "Connector of Real output signal";
parameter Real 'V.signalSource.offset' = 'V.offset' "Offset of output signal y";
parameter Real 'V.signalSource.startTime'(unit = "s", quantity = "Time") = 'V.startTime' "Output y = offset for time < startTime";
parameter Real 'V.offset'(unit = "V", quantity = "ElectricPotential") = 0.0 "Voltage offset";
parameter Real 'V.startTime'(unit = "s", quantity = "Time") = 1.0 "Time offset";
equation
'L1.p.v' = 'C1.p.v';
'L1.p.v' = 'C2.p.v';
'L1.p.v' = 'R1.n.v';
'C2.n.v' = 'L2.p.v';
'C2.n.v' = 'C4.p.v';
'C2.n.v' = 'C3.p.v';
'C2.n.v' = 'L1.n.v';
'C4.n.v' = 'R2.p.v';
'C4.n.v' = 'C5.p.v';
'C4.n.v' = 'L2.n.v';
'V.n.v' = 'G.p.v';
'V.n.v' = 'R2.n.v';
'V.n.v' = 'C1.n.v';
'V.n.v' = 'C5.n.v';
'V.n.v' = 'C3.n.v';
'R1.p.v' = 'V.p.v';
'V.n.i' + 'R2.n.i' + 'C5.n.i' + 'C3.n.i' + 'C1.n.i' + 'G.p.i' = 0.0;
'L2.p.i' + 'L1.n.i' + 'C4.p.i' + 'C3.p.i' + 'C2.n.i' = 0.0;
'R2.p.i' + 'L2.n.i' + 'C5.p.i' + 'C4.n.i' = 0.0;
'V.p.i' + 'R1.p.i' = 0.0;
'R1.n.i' + 'L1.p.i' + 'C2.p.i' + 'C1.p.i' = 0.0;
'G.p.v' = 0.0;
'C1.i' = 'C1.C' * der('C1.v');
0.0 = 'C1.p.i' + 'C1.n.i';
'C1.i' = 'C1.p.i';
'C1.v' = 'C1.p.v' - 'C1.n.v';
'C2.i' = 'C2.C' * der('C2.v');
0.0 = 'C2.p.i' + 'C2.n.i';
'C2.i' = 'C2.p.i';
'C2.v' = 'C2.p.v' - 'C2.n.v';
'C3.i' = 'C3.C' * der('C3.v');
0.0 = 'C3.p.i' + 'C3.n.i';
'C3.i' = 'C3.p.i';
'C3.v' = 'C3.p.v' - 'C3.n.v';
'C4.i' = 'C4.C' * der('C4.v');
0.0 = 'C4.p.i' + 'C4.n.i';
'C4.i' = 'C4.p.i';
'C4.v' = 'C4.p.v' - 'C4.n.v';
'C5.i' = 'C5.C' * der('C5.v');
0.0 = 'C5.p.i' + 'C5.n.i';
'C5.i' = 'C5.p.i';
'C5.v' = 'C5.p.v' - 'C5.n.v';
'L1.L' * der('L1.i') = 'L1.v';
0.0 = 'L1.p.i' + 'L1.n.i';
'L1.i' = 'L1.p.i';
'L1.v' = 'L1.p.v' - 'L1.n.v';
'L2.L' * der('L2.i') = 'L2.v';
0.0 = 'L2.p.i' + 'L2.n.i';
'L2.i' = 'L2.p.i';
'L2.v' = 'L2.p.v' - 'L2.n.v';
assert(1.0 + 'R1.alpha' * ('R1.T_heatPort' - 'R1.T_ref') >= 2.220446049250313e-16, "Temperature outside scope of model!", AssertionLevel.error);
'R1.R_actual' = 'R1.R' * (1.0 + 'R1.alpha' * ('R1.T_heatPort' - 'R1.T_ref'));
'R1.v' = 'R1.R_actual' * 'R1.i';
'R1.LossPower' = 'R1.v' * 'R1.i';
'R1.T_heatPort' = 'R1.T';
0.0 = 'R1.p.i' + 'R1.n.i';
'R1.i' = 'R1.p.i';
'R1.v' = 'R1.p.v' - 'R1.n.v';
assert(1.0 + 'R2.alpha' * ('R2.T_heatPort' - 'R2.T_ref') >= 2.220446049250313e-16, "Temperature outside scope of model!", AssertionLevel.error);
'R2.R_actual' = 'R2.R' * (1.0 + 'R2.alpha' * ('R2.T_heatPort' - 'R2.T_ref'));
'R2.v' = 'R2.R_actual' * 'R2.i';
'R2.LossPower' = 'R2.v' * 'R2.i';
'R2.T_heatPort' = 'R2.T';
0.0 = 'R2.p.i' + 'R2.n.i';
'R2.i' = 'R2.p.i';
'R2.v' = 'R2.p.v' - 'R2.n.v';
'V.signalSource.y' = 'V.signalSource.offset' + (if time < 'V.signalSource.startTime' then 0.0 else 'V.signalSource.height');
'V.v' = 'V.signalSource.y';
0.0 = 'V.p.i' + 'V.n.i';
'V.i' = 'V.p.i';
'V.v' = 'V.p.v' - 'V.n.v';
annotation(experiment(StopTime = 60));
end 'CauerLowPassAnalog';
end 'CauerLowPassAnalog';
Loading
Loading