From 9d38f555ed5ee48855a7c548fa54cac94f517e13 Mon Sep 17 00:00:00 2001 From: AnHeuermann <38031952+AnHeuermann@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:47:26 +0100 Subject: [PATCH] Fixing doc for parse_basemodelica, create_odeproblem * Updating doc string for parse_basemodelica: Default is ANTLR * Updating doc string for create_odeproblem: Only returns sys. * Fixing Markdown in README --- README.md | 8 ++++---- src/BaseModelica.jl | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b023815..ec9566d 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,11 @@ 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'"; @@ -36,14 +36,13 @@ package 'FirstOrder' 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 @@ -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)) ``` diff --git a/src/BaseModelica.jl b/src/BaseModelica.jl index fa48cbc..13d18e6 100644 --- a/src/BaseModelica.jl +++ b/src/BaseModelica.jl @@ -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) ``` @@ -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...)