Skip to content

JKRT/OMFrontend.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

133 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Github Action CI Documentation License: OSMC-PL

OMFrontend.jl

An experimental implementation of the OpenModelica New Frontend (NF) in Julia. The package parses Modelica source, lowers it to SCode, and instantiates it into FlatModelica or DAE form.

For the full compiler suite that builds on top of this package, see OpenModelica.jl. The API exposed here is deliberately low-level; for higher-level use cases, prefer OM.jl.

Release Status

This package is under active development. Interfaces may change without notice, and breaking changes should be expected between releases.

Example Use

Given the following Modelica model in HelloWorld.mo:

model HelloWorld
  Real x(start = 1, fixed = true);
  parameter Real a = 1;
equation
  der(x) = -a * x;
end HelloWorld;

The shortest path from source to a flat model is flattenModel:

using OMFrontend
(FM, functions) = OMFrontend.flattenModel("HelloWorld", "HelloWorld.mo")
println(OMFrontend.toString(FM))

The output is the flat representation of the model:

class HelloWorld
  Real x(fixed = true, start = 1.0);
  parameter Real a = 1.0;
equation
  der(x) = -a * x;
end HelloWorld;

If finer control is needed, the same result can be produced step by step:

absynProgram  = OMFrontend.parseFile("HelloWorld.mo")
scodeProgram  = OMFrontend.translateToSCode(absynProgram)
(FM, funcs)   = OMFrontend.instantiateSCodeToFM("HelloWorld", scodeProgram)

To obtain the DAE form instead of FlatModelica, call instantiateSCodeToDAE on the SCode program returned by translateToSCode. See DAE.jl for the data structure.

Flattening Models from the Modelica Standard Library

flattenModelWithMSL loads MSL on demand (cached after the first call) and flattens a model from it directly:

(FM, funcs) = OMFrontend.flattenModelWithMSL(
  "Modelica.Electrical.Analog.Examples.AD_DA_conversion";
  MSL_Version = "MSL:4.0.0",
)

Supported versions are "MSL:3.2.3" and "MSL:4.0.0". Pass forceReload = true to drop the cached library and reparse from disk.

Combining a User Model with Libraries

Custom libraries can be loaded once and then reused:

libKey = OMFrontend.loadLibrary("/path/to/MyLib.mo")

(FM, funcs) = OMFrontend.flattenModelWithLibraries(
  "MyPackage.Examples.Demo",
  "MyModel.mo";
  libraries = [libKey],
  MSL = true,
  MSL_Version = "MSL:4.0.0",
)

loadPackageDirectory(path) is the equivalent loader for libraries organised as a package.mo directory tree.

Inspecting and Exporting Results

A flat model and its function tree can be rendered as a string or written to disk:

str = OMFrontend.toFlatModelica((FM, funcs))
OMFrontend.exportDAERepresentationToFile("HelloWorld.flat.mo", str)

For debugging the lowering pipeline, OMFrontend.enableDumpDebug() writes the flat model after each compiler phase to the working directory. OMFrontend.disableDumpDebug() turns it off again.

Issues, Questions, and Contributing

OMFrontend.jl is a component of OM.jl, and the API reflects that low-level role.

For questions or collaboration ideas, contact details are available on my LiU page.

About

Experimental implementation of NF. That is a Modelica frontend in 100% Julia

Topics

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE.md
Unknown
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors