Skip to content

About

Backend for OMJL. A Modelica Compiler and environment written in Julia

Topics

Resources

Stars

4 stars

Watchers

8 watching

Forks

Latest commit

 

History

214 Commits

Folders and files

Repository files navigation

Github Action CI License: OSMC-PL

About OMBackend.jl

OMBackend.jl is one component of OMJL, the Modelica compiler infrastructure for Julia. It lowers the flat model produced by OMFrontend.jl to its own intermediate representation, OMJLIR (src/IR), runs its passes there (src/Backend/Passes), generates the simulation code (src/SimCode) and from it a system that can be simulated with DifferentialEquations.jl and ModelingToolkit.jl (src/CodeGeneration).

Requirements

  • Julia 1.13
  • Git
  • A checkout of the sibling OM*.jl packages next to this repository (see below)

Dependencies

The main runtime dependencies are pulled in by Project.toml. The most relevant ones are:

  • DifferentialEquations.jl, OrdinaryDiffEq.jl, DiffEqBase.jl, DiffEqCallbacks.jl, Sundials.jl
  • ModelingToolkit.jl, Symbolics.jl, SymbolicUtils.jl
  • Graphs.jl, MetaGraphs.jl, DataStructures.jl, MacroTools.jl, Setfield.jl
  • Plots.jl
  • ExportAll.jl, DocStringExtensions.jl, JuliaFormatter.jl

The OMJL ecosystem packages are developed from sibling checkouts next to OMBackend.jl, as the CI does (Pkg.develop of each, .github/workflows/CI.yml). OMBackend uses Absyn, MetaModelica, OMFrontend, OMRuntimeExternalC and SCode; DAE, ImmutableList, ListUtil and OMParser are OMFrontend's:

  • Absyn.jl
  • DAE.jl
  • ImmutableList.jl
  • ListUtil.jl
  • MetaModelica.jl
  • OMFrontend.jl
  • OMParser.jl
  • OMRuntimeExternalC.jl
  • SCode.jl

Layout:

OMJL-workspace/
├── Absyn.jl/
├── DAE.jl/
├── ImmutableList.jl/
├── ListUtil.jl/
├── MetaModelica.jl/
├── OMBackend.jl/        <-- this repository
├── OMFrontend.jl/
├── OMParser.jl/
├── OMRuntimeExternalC.jl/
└── SCode.jl/

OMRuntimeExternalC.jl is not in the General registry. The others are served by the OpenModelica Julia registry, but the developed checkouts take precedence and are used for development.

Installation

Add the OpenModelica Julia registry once per Julia depot:

julia> import Pkg
julia> Pkg.Registry.add("General")
julia> Pkg.Registry.add(Pkg.RegistrySpec(url = "https://github.com/OpenModelica/OpenModelicaRegistry.git"))

From the OMBackend.jl directory, activate the project, develop the sibling checkouts and build:

julia> import Pkg
julia> Pkg.activate(".")
julia> Pkg.develop([Pkg.PackageSpec(path = joinpath("..", p)) for p in
                    ("Absyn.jl", "DAE.jl", "ImmutableList.jl", "ListUtil.jl", "MetaModelica.jl",
                     "OMFrontend.jl", "OMParser.jl", "OMRuntimeExternalC.jl", "SCode.jl")])
julia> Pkg.build(verbose = true)

deps/build.jl builds OMFrontend, and with it OMParser's parser library.

Then load the package:

julia> using OMBackend

Running tests

From the OMBackend.jl directory:

julia> import Pkg
julia> Pkg.activate(".")
julia> Pkg.test()

Or directly:

julia> include("test/runtests.jl")

Example use

Given a Modelica model flattened by OMFrontend.jl, pass the flat model and its functions to OMBackend.translate and then simulate (examples/ has more).

model BouncingBallReals
  parameter Real e = 0.7;
  parameter Real g = 9.81;
  Real h(start = 1);
  Real v;
equation
  der(h) = v;
  der(v) = -g;
  when h <= 0 then
    reinit(v, -e * pre(v));
  end when;
end BouncingBallReals;
julia> import OMFrontend
julia> scode = OMFrontend.translateToSCode(OMFrontend.parseFile("BouncingBallReals.mo"))
julia> (fm, cache) = OMFrontend.instantiateSCodeToFM("BouncingBallReals", scode)
julia> OMBackend.translate(fm; functionList = OMFrontend.cacheToFunctionList(cache))
julia> OMBackend.simulateModel("BouncingBallReals"; tspan = (0.0, 2.5))

image

Citation

If you use OMBackend.jl in academic work, please cite the entries in CITATION.bib.

License

OMBackend.jl is distributed under the OSMC Public License. See LICENSE.md.

About

Backend for OMJL. A Modelica Compiler and environment written in Julia

Topics

Resources

Stars

4 stars

Watchers

8 watching

Forks

Releases

Packages

Used by

Contributors

Languages