Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 3 / 0 / 3
Functions: -% 0 / 0 / 0
Branches: -% 0 / 0 / 0

OMCompiler/Compiler/Template/CodegenFMU2.tpl
Line Branch Exec Source
1 /*
2 * This file is part of OpenModelica.
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC),
5 * c/o Linköpings universitet, Department of Computer and Information Science,
6 * SE-58183 Linköping, Sweden.
7 *
8 * All rights reserved.
9 *
10 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR
11 * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8.
12 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
13 * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL
14 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
15 *
16 * The OpenModelica software and the OSMC (Open Source Modelica Consortium)
17 * Public License (OSMC-PL) are obtained from OSMC, either from the above
18 * address, from the URLs:
19 * http://www.openmodelica.org or
20 * https://github.com/OpenModelica/ or
21 * http://www.ida.liu.se/projects/OpenModelica,
22 * and in the OpenModelica distribution.
23 *
24 * GNU AGPL version 3 is obtained from:
25 * https://www.gnu.org/licenses/licenses.html#GPL
26 *
27 * This program is distributed WITHOUT ANY WARRANTY; without
28 * even the implied warranty of MERCHANTABILITY or FITNESS
29 * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
30 * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
31 *
32 * See the full OSMC Public License conditions for more details.
33 *
34 */
35
36 // This file defines templates for transforming Modelica/MetaModelica code to FMU
37 // code. They are used in the code generator phase of the compiler to write
38 // target code.
39 //
40 // There are one root template intended to be called from the code generator:
41 // translateModel. These template do not return any
42 // result but instead write the result to files. All other templates return
43 // text and are used by the root templates (most of them indirectly).
44 //
45 // To future maintainers of this file:
46 //
47 // - A line like this
48 // # var = "" /*BUFD*/
49 // declares a text buffer that you can later append text to. It can also be
50 // passed to other templates that in turn can append text to it. In the new
51 // version of Susan it should be written like this instead:
52 // let &var = buffer ""
53 //
54 // - A line like this
55 // ..., Text var /*BUFP*/, ...
56 // declares that a template takes a text buffer as input parameter. In the
57 // new version of Susan it should be written like this instead:
58 // ..., Text &var, ...
59 //
60 // - A line like this:
61 // ..., var /*BUFC*/, ...
62 // passes a text buffer to a template. In the new version of Susan it should
63 // be written like this instead:
64 // ..., &var, ...
65 //
66 // - Style guidelines:
67 //
68 // - Try (hard) to limit each row to 80 characters
69 //
70 // - Code for a template should be indented with 2 spaces
71 //
72 // - Exception to this rule is if you have only a single case, then that
73 // single case can be written using no indentation
74 //
75 // This single case can be seen as a clarification of the input to the
76 // template
77 //
78 // - Code after a case should be indented with 2 spaces if not written on the
79 // same line
80
81 package CodegenFMU2
82
83 import interface SimCodeTV;
84 import interface SimCodeBackendTV;
85 import CodegenUtil.*;
86 import CodegenUtilSimulation.*;
87 import CodegenFMUCommon.*;
88
89 // Code for generating modelDescription.xml file for FMI 2.0 ModelExchange.
90 72 template fmiModelDescription(SimCode simCode, String guid, String FMUType, list<String> sourceFiles)
91 "Generates code for ModelDescription file for FMU target."
92 ::=
93 // <%UnitDefinitions(simCode)%>
94 // <%VendorAnnotations(simCode)%>
95 match simCode
96 case SIMCODE(__) then
97 <<
98 <fmiModelDescription
99 <%fmiModelDescriptionAttributes(simCode,guid)%>>
100 <%if isFMIMEType(FMUType) then ModelExchange(simCode, sourceFiles)%>
101 <%if isFMICSType(FMUType) then CoSimulation(simCode, sourceFiles)%>
102 <%UnitDefinitions(simCode)%>
103 <%fmiTypeDefinitions(simCode, "2.0")%>
104 <% if Flags.isSet(Flags.FMU_EXPERIMENTAL) then
105 <<
106 <LogCategories>
107 <Category name="logEvents" description="logEvents" />
108 <Category name="logSingularLinearSystems" description="logSingularLinearSystems" />
109 <Category name="logNonlinearSystems" description="logNonlinearSystems" />
110 <Category name="logDynamicStateSelection" description="logDynamicStateSelection" />
111 <Category name="logStatusWarning" description="logStatusWarning" />
112 <Category name="logStatusDiscard" description="logStatusDiscard" />
113 <Category name="logStatusError" description="logStatusError" />
114 <Category name="logStatusFatal" description="logStatusFatal" />
115 <Category name="logStatusPending" description="logStatusPending" />
116 <Category name="logAll" description="logAll" />
117 <Category name="logFmi2Call" description="logFmi2Call" />
118 </LogCategories>
119 >> else
120 <<
121 <LogCategories>
122 <Category name="logEvents" />
123 <Category name="logSingularLinearSystems" />
124 <Category name="logNonlinearSystems" />
125 <Category name="logDynamicStateSelection" />
126 <Category name="logStatusWarning" />
127 <Category name="logStatusDiscard" />
128 <Category name="logStatusError" />
129 <Category name="logStatusFatal" />
130 <Category name="logStatusPending" />
131 <Category name="logAll" />
132 <Category name="logFmi2Call" />
133 </LogCategories>
134 >> %>
135 <%DefaultExperiment(simulationSettingsOpt, "2.0")%>
136 <%fmiModelVariables(simCode, "2.0")%>
137 <%ModelStructure(modelStructure)%>
138 </fmiModelDescription>
139 >>
140 end fmiModelDescription;
141
142 72 template fmiModelDescriptionAttributes(SimCode simCode, String guid)
143 "Generates code for ModelDescription file for FMU target."
144 ::=
145 match simCode
146 case SIMCODE(modelInfo = MODELINFO(varInfo = vi as VARINFO(__), vars = SIMVARS(stateVars = listStates))) then
147 let fmiVersion = '2.0'
148 let modelName = dotPath(modelInfo.name)
149 let description = modelInfo.description
150 let author = modelInfo.author
151 let version = modelInfo.version
152 let copyright = modelInfo.copyright
153 let license = modelInfo.license
154 let generationTool= 'OpenModelica Compiler <%getVersionNr()%>'
155 let generationDateAndTime = xsdateTime(Util.getCurrentDateTime())
156 let variableNamingConvention = 'structured'
157 let numberOfEventIndicators = getNumberOfEventIndicators(simCode)
158 <<
159 fmiVersion="<%fmiVersion%>"
160 modelName="<%Util.escapeModelicaStringToXmlString(modelName)%>"
161 guid="{<%guid%>}"
162 description="<%Util.escapeModelicaStringToXmlString(description)%>"
163 version="<%Util.escapeModelicaStringToXmlString(version)%>"
164 <% if stringEq(author, "") then '' else 'author="<%Util.escapeModelicaStringToXmlString(author)%>"'%>
165 <% if stringEq(copyright, "") then '' else 'copyright="<%Util.escapeModelicaStringToXmlString(copyright)%>"'%>
166 <% if stringEq(license, "") then '' else 'license="<%Util.escapeModelicaStringToXmlString(license)%>"'%>
167 generationTool="<%Util.escapeModelicaStringToXmlString(generationTool)%>"
168 generationDateAndTime="<%Util.escapeModelicaStringToXmlString(generationDateAndTime)%>"
169 variableNamingConvention="<%variableNamingConvention%>"
170 numberOfEventIndicators="<%numberOfEventIndicators%>"
171 >>
172 end fmiModelDescriptionAttributes;
173
174 14 template CoSimulation(SimCode simCode, list<String> sourceFiles)
175 "Generates CoSimulation code for ModelDescription file for FMU target."
176 ::=
177 match simCode
178 case SIMCODE(__) then
179 let modelIdentifier = modelNamePrefix(simCode)
180 <<
181 <CoSimulation
182 modelIdentifier="<%Util.escapeModelicaStringToXmlString(modelIdentifier)%>"
183 needsExecutionTool="false"
184 canHandleVariableCommunicationStepSize="true"
185 canInterpolateInputs="true"
186 maxOutputDerivativeOrder="1"
187 canRunAsynchronuously="false"
188 canBeInstantiatedOnlyOncePerProcess="false"
189 canNotUseMemoryManagementFunctions="false"
190 canGetAndSetFMUstate="true"
191 canSerializeFMUstate="true"
192 <% if Flags.isSet(FMU_EXPERIMENTAL) then 'providesDirectionalDerivative="true"' else 'providesDirectionalDerivative="false"'%>>
193 <%SourceFiles(sourceFiles)%>
194 </CoSimulation>
195 >>
196 end CoSimulation;
197
198
199 annotation(__OpenModelica_Interface="codegen_fmu");
200 end CodegenFMU2;
201
202 // vim: filetype=susan sw=2 sts=2
203