modelica-json is a translator that parses the Modelica language to JSON. Two translation modes have been implemented : The first mode aims to parse Modelica packages and takes into input a directory of .mo files. The other mode aims to parse CDL files and takes a single .mo file compliant with the CDL language as input. For more information on the CDL Language, please refer to the OpenBuildingControl project website.
See the directory test/FromModelica
from modelica-json for simple examples from Modelica and CDL to detailed and simplified JSON.
First, set the MODELICAPATH environment variable by adding the following line to your ~/.bashrc file:
export MODELICAPATH=${MODELICAPATH}:/usr/local/Modelica/Library/
The parser requires Java and node. The java dependency can be installed using:
sudo apt-get install default-jdk default-jre
The node version should be >= 18 and you can use Node Version Manager to set it up. Following is using 0.39.7 version:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install 18
To install dependencies of the parser, run
make install
To compile the Java files, run
make compile
To run the test cases, run
npm test
To get more help, run
node app.js -h
To clean the current installation, run
make clean-installation
-
First, make sure that both the
modelica-json
directory and theModelica Buildings Library
directory are in the folders that do not require administrator access. By saving the directories in driver other thanC:\
would typical avoid the administrator access issue. -
Then, create the
MODELICAPATH
environment variable and set the value as the path of Modelica Buildings Library, likeE:\modelica-buildings
orE:\modelica-buildings-master
. -
Install Java SE Development Kit (64-bit version), Java Runtime Environment (64-bit version) and Node.js.
-
Add
path\to\your\nodejs
to thePath
environment. -
In batch file
InstallOnWindows.bat
, updateJAVA_HOME
path in lineset JAVA_HOME=path\to\your\jdk
. -
Finally, to install dependencies and compile the Java files, run
InstallOnWindows.bat
.
To test the installation, from the \modelica-json
directory, run the parser on Command Prompt:
node app.js -f test\FromModelica\Enable.mo
Now the \modelica-json
directory should have a new folder json
and in the folder, there should be a file in the path test\FromModelica\Enable.json
.
The parser can be run with the app.js file as follows:
node app.js -f <path of the file to parse>
The only required input is the path of the file or package to be parsed.
This parser takes a .mo file in input and has three possible outputs, that can be specified with the argument -o :
- raw-json : detailed transcription of a Modelica file in JSON
- json: simplified JSON format, easier to read an interpret
- semantic: generate semantic model from semantic information included within
annotation
in the Modelica file - cxf: generate CXF representation in
.jsonld
of a CDL sequence complying with ASHRAE S231P - doc: create the documentation of the sequence of operation in an HTML document
- doc+: create the documentation of the sequence of operation and the list of all variables in an HTML document
We offer two different modes of translation that can be chosen with the argument -m :
- modelica : Parses a Modelica package (must be a directory)
- cdl (default) : Parses a CDL file.
Logging level. The choices are error
, warn
, info
(default), verbose
, debug
.
Specify the output directory. The default option is the current directory.
If -p
flag is specified, the JSON output conforms to prettyprint. The default option is false
.
If --elementary
flag is specified, the CXF (jsonld) files for the elementary blocks are also generated. Else, they are ignored. The default option is false
.
-o
/--output
should be cxf
.
If --cxfCore
flag is specified, generate the CXF-core.jsonld files for all the elementary blocks. The default option is false
.
-o
/--output
should be cxf
, -f
/--file
should be path/to/CDL
and --elementary
flag must be used.
The JSON representation of Modelica and CXF models must be compliant with the corresponding JSON Schema. This is applicable for the JSON and CXF output respectively.
JSON Schemas describe the data format and file structure to ensure the quality of the JSON files.
Two schemas are available (links to the raw files) :
- schema-cxf.json validates the JSON files parsed from CDL classes to form CXF representations
- schema-modelica.json validates the JSON files parsed from Modelica models
Graphical viewers are available (please use right click + open in a new tab or refresh the page if necessary - this is not optimized for Firefox) :
CXF-Core.jsonld contains the CXF representation of all CDL elementary blocks, classes and relationships.
To generate the CXF-Core.jsonld
, use:
node app.js -f <path/to/modelica-buildings>/Buildings/Controls/OBC/CDL -o cxf --elementary --cxfCore
The CXF-Core.jsonld
file will be generated in cxf
folder.
When parsing a file using app.js
, the schema is chosen according to the mode.
To validate an existing JSON file against the schema, run
node validation.js -f <path to the json file>
The default schema is CDL. To chose the Modelica schema, run:
node validation.js -f <path to the json file> -m modelica
Modified 3-clause BSD, see LICENSE.md.
See copyright notice.