Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update code generation section to add CXF #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
37 changes: 21 additions & 16 deletions specification/source/codeGeneration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,25 @@ Translation of a Control Sequence using a JSON Intermediate Format

Control companies that choose to not use C-code generation or the FMI standard to
execute CDL-compliant control sequences can develop translators from
CDL to their native language. To aid in this process, a CDL to JSON translator
can be used. Such a translator is currently being developed at
https://github.com/lbl-srg/modelica-json.
This translator parses CDL-compliant control sequences to a JSON format.
The parser generates the following output formats:

1. A JSON representation of the control sequence,
2. a simplified version of this JSON representation, and
3. an html-formated documentation of the control sequence.
CDL to their native language. To aid in this process, an intermediate
Control eXchange Format (CXF) can be used. CXF is a JSON-LD representation
of a CDL sequence, serialized in JSON. `Modelica-json <https://github.com/lbl-srg/modelica-json>`_
is a reference implementation of such a CDL to CXF translator.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The translator is not a "reference implementation" as the translator is not part of the standard. Just write it is a translator.

This translator first parses CDL-compliant control sequences to a abstract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write "an abstract"

syntax tree in JSON format and then generates a CXF representation from it.
The ``modelica-json`` tool can also parse Modelica code and it
can generate the following output formats:

1. A JSON representation of the control sequence (CDL) or the Modelica
file(``raw-json``),
2. A simplified version of this JSON representation (``json``),
3. A semantic model from the control sequnce or the Modelica file
(``semantic``) and
4. A CXF representation of the control sequence (``cxf``).

To translate CDL-compliant control sequences to the language that is used
by the target building automation system, the simplified JSON representation
is most suited.
by the target building automation system, the Control eXchange Format (CXF)
representation is most suited.

As an illustrative example, consider the composite control block shown in
:numref:`fig_custom_control_block` and reproduced in
Expand All @@ -142,17 +148,16 @@ Executing the command

.. code-block:: bash

node modelica-json/app.js -f CustomPWithLimiter.mo -o json-simplified
node modelica-json/app.js -f CustomPWithLimiter.mo -o cxf

will produce a file called ``CustomPWithLimiter-simplified.json`` that
will produce a file called ``CustomPWithLimiter.jsonld`` that
looks as follows:

.. literalinclude:: img/codeGeneration/CustomPWithLimiter/CustomPWithLimiter-simplified.json
.. literalinclude:: img/codeGeneration/CustomPWithLimiter/CustomPWithLimiter.jsonld
:language: json
:linenos:

Note that the graphical annotations are not shown.
The JSON representation can then be parsed and converted to another block-diagram
The representation can then be parsed and converted to another block-diagram
language.
Note that ``CDL.Reals.MultiplyByParameter`` is an elementary CDL block
(see :numref:`sec_ele_blo`).
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"@context": {
"S231P": "https://data.ashrae.org/S231P#"
},
"@graph": [
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter",
"@type": "S231P:Block",
"S231P:containsBlock": [
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue"
}
],
"S231P:hasInput": [
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.e"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.yMax"
}
],
"S231P:hasOutput": {
"@id": "http://example.org#FromModelica.CustomPWithLimiter.y"
},
"S231P:hasParameter": {
"@id": "http://example.org#FromModelica.CustomPWithLimiter.k"
},
"S231P:label": "CustomPWithLimiter"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.e",
"@type": "S231P:RealInput",
"S231P:accessSpecifier": "public",
"S231P:description": "Control error",
"S231P:graphics": "{\"Placement\":{\"transformation\":{\"extent\":[{\"x\":-140,\"y\":-60},{\"x\":-100,\"y\":-20}]}}}",
"S231P:isConnectedTo": {
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain.u"
},
"S231P:label": "e"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain",
"@type": "https://data.ashrae.org/S231P#Buildings.Controls.OBC.CDL.Reals.MultiplyByParameter",
"S231P:accessSpecifier": "public",
"S231P:description": "Constant gain",
"S231P:graphics": "{\"Placement\":{\"transformation\":{\"extent\":[{\"x\":-60,\"y\":-50},{\"x\":-40,\"y\":-30}]}}}",
"S231P:hasInstance": [
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain.k"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain.u"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain.y"
}
],
"S231P:label": "gain"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain.k",
"S231P:isFinal": true,
"S231P:value": "k"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.gain.y",
"S231P:isConnectedTo": {
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue.u2"
}
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.k",
"@type": "S231P:Parameter",
"S231P:accessSpecifier": "public",
"S231P:description": "Constant gain",
"S231P:isOfDataType": {
"@id": "S231P:Real"
},
"S231P:label": "k",
"S231P:value": 2
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue",
"@type": "https://data.ashrae.org/S231P#Buildings.Controls.OBC.CDL.Reals.Min",
"S231P:accessSpecifier": "public",
"S231P:description": "Outputs the minimum of its inputs",
"S231P:graphics": "{\"Placement\":{\"transformation\":{\"extent\":[{\"x\":20,\"y\":-10},{\"x\":40,\"y\":10}]}}}",
"S231P:hasInstance": [
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue.u1"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue.u2"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue.y"
}
],
"S231P:label": "minValue"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue.y",
"S231P:isConnectedTo": {
"@id": "http://example.org#FromModelica.CustomPWithLimiter.y"
}
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.y",
"@type": "S231P:RealOutput",
"S231P:accessSpecifier": "public",
"S231P:description": "Control signal",
"S231P:graphics": "{\"Placement\":{\"transformation\":{\"extent\":[{\"x\":100,\"y\":-10},{\"x\":120,\"y\":10}]}}}",
"S231P:label": "y"
},
{
"@id": "http://example.org#FromModelica.CustomPWithLimiter.yMax",
"@type": "S231P:RealInput",
"S231P:accessSpecifier": "public",
"S231P:description": "Maximum value of output signal",
"S231P:graphics": "{\"Placement\":{\"transformation\":{\"extent\":[{\"x\":-140,\"y\":20},{\"x\":-100,\"y\":60}]}}}",
"S231P:isConnectedTo": {
"@id": "http://example.org#FromModelica.CustomPWithLimiter.minValue.u1"
},
"S231P:label": "yMax"
}
]
}