Skip to content
Open
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,25 @@ import Pkg;
Pkg.add("BaseModelica");
```

# Example
## Example

A Base Modelica model is in the file `ExampleFirstOrder.mo`. Inside of the file is a Base Modelica model specifying a simple first order linear differential equation:

```
```modelica
package 'FirstOrder'
model 'FirstOrder'
parameter Real 'x0' = 0 "Initial value for 'x'";
Real 'x' "Real variable called 'x'";
initial equation
'x' = 'x0' "Set initial value of 'x' to 'x0'";
equation
der('x') = 1.0 - 'x';
der('x') = 1.0 - 'x';
end 'FirstOrder';
end 'FirstOrder';
```

To parse the model in the file to ModelingToolkit, use the `parse_basemodelica` function:

```julia
```julia
using BaseModelica

Expand All @@ -63,6 +62,7 @@ sol = solve(prob)
```

If the model contains an experiment annotation like:

```modelica
annotation(experiment(StartTime = 0, StopTime = 2.0, Tolerance = 1e-06, Interval = 0.004))
```
Expand Down
18 changes: 10 additions & 8 deletions src/BaseModelica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ include("antlr_parser.jl")
include("evaluator.jl")

"""
parse_basemodelica(filename::String; parser::Symbol=:julia)::System
parse_basemodelica(filename::String; parser::Symbol=:antlr)::System

Parses a BaseModelica .mo file into a ModelingToolkit System.

## Arguments
- `filename::String`: Path to the .mo file to parse
- `parser::Symbol=:julia`: Parser to use. Options:
- `:julia` - ParserCombinator parser (default)
- `:antlr` - ANTLR parser
- `parser::Symbol=:antlr`: Parser to use. Options:
- `:antlr` - ANTLR parser (default)
- `:julia` - ParserCombinator parser

## Example

```julia
# Use ANTLR parser (default)
parse_basemodelica("testfiles/NewtonCoolingBase.bmo")
parse_basemodelica("testfiles/NewtonCoolingBase.bmo", parser=:antlr)
parse_basemodelica("testfiles/NewtonCoolingBase.bmo", parser = :antlr)
# Use ParserCombinator parser
parse_basemodelica("testfiles/NewtonCoolingBase.bmo", parser = :julia)
```
Expand Down Expand Up @@ -136,14 +136,16 @@ If an experiment annotation is present, StartTime, StopTime, and Tolerance are a
- `kwargs...`: Additional keyword arguments passed to ODEProblem

## Returns
- A tuple `(prob, sys)` where `prob` is the ODEProblem and `sys` is the System
- An `ODEProblem`. If an experiment annotation is present, `tspan`, `reltol`, and `saveat`
are set from it. Otherwise `tspan` defaults to `(0.0, 1.0)`. User-supplied `kwargs`
always take precedence over annotation values.

## Example
```julia
using BaseModelica

prob, sys = create_odeproblem("testfiles/Experiment.bmo")
# The tspan and tolerances are automatically set from the annotation
prob = create_odeproblem("testfiles/Experiment.bmo")
# tspan, reltol, and saveat are automatically set from the experiment annotation
```
"""
function create_odeproblem(filename::String; parser::Symbol = :antlr, u0 = [], kwargs...)
Expand Down