OMCompiler/Compiler/Template/CodegenFMUCommon.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 CodegenFMUCommon | ||
| 82 | |||
| 83 | import interface SimCodeTV; | ||
| 84 | import interface SimCodeBackendTV; | ||
| 85 | import CodegenUtil.*; | ||
| 86 | import CodegenUtilSimulation.*; | ||
| 87 | |||
| 88 | 66 | template ModelExchange(SimCode simCode, list<String> sourceFiles) | |
| 89 | "Generates ModelExchange code for ModelDescription file for FMU target." | ||
| 90 | ::= | ||
| 91 | match simCode | ||
| 92 | case SIMCODE(__) then | ||
| 93 | let modelIdentifier = modelNamePrefix(simCode) | ||
| 94 | << | ||
| 95 | <ModelExchange | ||
| 96 | modelIdentifier="<%modelIdentifier%>" | ||
| 97 | needsExecutionTool="false" | ||
| 98 | completedIntegratorStepNotNeeded="false" | ||
| 99 | canBeInstantiatedOnlyOncePerProcess="false" | ||
| 100 | canNotUseMemoryManagementFunctions="false" | ||
| 101 | canGetAndSetFMUstate="true" | ||
| 102 | canSerializeFMUstate="true" | ||
| 103 | <% if providesDirectionalDerivative(simCode) then 'providesDirectionalDerivative="true"' else 'providesDirectionalDerivative="false"'%>> | ||
| 104 | <%SourceFiles(sourceFiles)%> | ||
| 105 | </ModelExchange> | ||
| 106 | >> | ||
| 107 | end ModelExchange; | ||
| 108 | |||
| 109 | 4 | template SourceFiles(list<String> sourceFiles) | |
| 110 | ::= | ||
| 111 | if sourceFiles then | ||
| 112 | << | ||
| 113 | <SourceFiles> | ||
| 114 | <% sourceFiles |> file => '<File name="<%file%>" />' ; separator="\n" %> | ||
| 115 | </SourceFiles> | ||
| 116 | >> | ||
| 117 | end SourceFiles; | ||
| 118 | |||
| 119 | 74 | template fmiModelVariables(SimCode simCode, String FMUVersion) | |
| 120 | "Generates code for ModelVariables file for FMU target." | ||
| 121 | ::= | ||
| 122 | match simCode | ||
| 123 | case SIMCODE(modelInfo=modelInfo) then | ||
| 124 | match modelInfo | ||
| 125 | case MODELINFO(vars=SIMVARS(stateVars=stateVars)) then | ||
| 126 | << | ||
| 127 | <ModelVariables> | ||
| 128 | <%System.tmpTickReset(0)%> | ||
| 129 | <%vars.stateVars |> var => | ||
| 130 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 131 | ;separator="\n"%> | ||
| 132 | <%vars.derivativeVars |> var => | ||
| 133 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 134 | ;separator="\n"%> | ||
| 135 | <%vars.algVars |> var => | ||
| 136 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 137 | ;separator="\n"%> | ||
| 138 | <%vars.discreteAlgVars |> var => | ||
| 139 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 140 | ;separator="\n"%> | ||
| 141 | <%vars.paramVars |> var => | ||
| 142 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 143 | ;separator="\n"%> | ||
| 144 | <%vars.aliasVars |> var => | ||
| 145 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 146 | ;separator="\n"%> | ||
| 147 | <%System.tmpTickReset(0)%> | ||
| 148 | <%vars.intAlgVars |> var => | ||
| 149 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 150 | ;separator="\n"%> | ||
| 151 | <%vars.intParamVars |> var => | ||
| 152 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 153 | ;separator="\n"%> | ||
| 154 | <%vars.intAliasVars |> var => | ||
| 155 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 156 | ;separator="\n"%> | ||
| 157 | <%System.tmpTickReset(0)%> | ||
| 158 | <%vars.boolAlgVars |> var => | ||
| 159 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 160 | ;separator="\n"%> | ||
| 161 | <%vars.boolParamVars |> var => | ||
| 162 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 163 | ;separator="\n"%> | ||
| 164 | <%vars.boolAliasVars |> var => | ||
| 165 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 166 | ;separator="\n"%> | ||
| 167 | <%System.tmpTickReset(0)%> | ||
| 168 | <%vars.stringAlgVars |> var => | ||
| 169 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 170 | ;separator="\n"%> | ||
| 171 | <%vars.stringParamVars |> var => | ||
| 172 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 173 | ;separator="\n"%> | ||
| 174 | <%vars.stringAliasVars |> var => | ||
| 175 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 176 | ;separator="\n"%> | ||
| 177 | <%System.tmpTickReset(0)%> | ||
| 178 | <%externalFunctions(modelInfo)%> | ||
| 179 | </ModelVariables> | ||
| 180 | >> | ||
| 181 | end fmiModelVariables; | ||
| 182 | |||
| 183 | 6251 | template ScalarVariable(SimVar simVar, SimCode simCode, list<SimVar> stateVars, String FMUVersion) | |
| 184 | "Generates code for ScalarVariable file for FMU target." | ||
| 185 | ::= | ||
| 186 | match simVar | ||
| 187 | case SIMVAR(type_ = T_ARRAY()) then | ||
| 188 | /* roll out array as XML file only supports scalars */ | ||
| 189 | '<%getScalarElements(simVar) |> var => | ||
| 190 | ScalarVariable(var, simCode, stateVars, FMUVersion) | ||
| 191 | ;separator="\n"%>' | ||
| 192 | case SIMVAR(__) then | ||
| 193 | if stringEq(CodegenUtil.crefStr(name),"$dummy") then | ||
| 194 | <<>> | ||
| 195 | else if stringEq(CodegenUtil.crefStr(name),"der($dummy)") then | ||
| 196 | <<>> | ||
| 197 | else if isFMIVersion20(FMUVersion) then | ||
| 198 | if isSome(exportVar) then | ||
| 199 | << | ||
| 200 | <!-- Index of variable = "<%getVariableFMIIndex(simVar)%>" --> | ||
| 201 | <ScalarVariable | ||
| 202 | <%ScalarVariableAttribute2(simVar, simCode)%>> | ||
| 203 | <%ScalarVariableType2(simVar, stateVars)%> | ||
| 204 | </ScalarVariable> | ||
| 205 | >> | ||
| 206 | else | ||
| 207 | '' | ||
| 208 | else | ||
| 209 | << | ||
| 210 | <ScalarVariable | ||
| 211 | <%ScalarVariableAttribute(simVar)%>> | ||
| 212 | <%ScalarVariableType(simVar)%> | ||
| 213 | </ScalarVariable> | ||
| 214 | >> | ||
| 215 | end ScalarVariable; | ||
| 216 | |||
| 217 | 8 | template ScalarVariableAttribute(SimVar simVar) | |
| 218 | "Generates code for ScalarVariable Attribute file for FMU target." | ||
| 219 | ::= | ||
| 220 | match simVar | ||
| 221 | case SIMVAR(__) then | ||
| 222 | let valueReference = '<%System.tmpTick()%>' | ||
| 223 | let variability_ = getVariabilityFMI1(variability, type_) | ||
| 224 | let description = if comment then 'description="<%Util.escapeModelicaStringToXmlString(comment)%>"' | ||
| 225 | let alias = getAliasVar(aliasvar) | ||
| 226 | let caus = getCausality(causality) | ||
| 227 | << | ||
| 228 | name="<%System.stringReplace(crefStrNoUnderscore(name),"$", "_D_")%>" | ||
| 229 | valueReference="<%valueReference%>" | ||
| 230 | <%description%> | ||
| 231 | variability="<%variability_%>" | ||
| 232 | causality="<%caus%>" | ||
| 233 | alias="<%alias%>" | ||
| 234 | >> | ||
| 235 | end ScalarVariableAttribute; | ||
| 236 | |||
| 237 | 11723 | template getCausality(Option<Causality> c) | |
| 238 | "Returns the Causality Attribute of ScalarVariable." | ||
| 239 | ::= | ||
| 240 | match c | ||
| 241 | case SOME(NONECAUS(__)) then "none" | ||
| 242 | case SOME(OUTPUT(__)) then "output" | ||
| 243 | case SOME(INPUT(__)) then "input" | ||
| 244 | else "internal" // needed to support for FMI 1.0 since causality= PARAMETER, CALCULATED__PARAMETER and LOCAL are not handled | ||
| 245 | end getCausality; | ||
| 246 | |||
| 247 | 4 | template getVariability(Option<SimCodeVar.Variability> variability_) | |
| 248 | "Returns the variability Attribute of ScalarVariable." | ||
| 249 | ::= | ||
| 250 | match variability_ | ||
| 251 | case SOME(DISCRETE(__)) then "discrete" | ||
| 252 | case SOME(FIXED(__)) then "parameter" // FMI 1.0 do not have fixed | ||
| 253 | case SOME(CONSTANT(__)) then "constant" | ||
| 254 | case SOME(CONTINUOUS(__)) then "continuous" | ||
| 255 | else "continuous" | ||
| 256 | end getVariability; | ||
| 257 | |||
| 258 | 8 | template getVariabilityFMI1(Option<SimCodeVar.Variability> variability_, DAE.Type type_) | |
| 259 | "getVariability of an FMI 1.0 ScalarVariable: continuous is for Real only, as | ||
| 260 | in FMI 2.0 (see getVariabilityFMI2)." | ||
| 261 | ::= | ||
| 262 | match type_ | ||
| 263 | case T_REAL(__) then getVariability(variability_) | ||
| 264 | else | ||
| 265 | match variability_ | ||
| 266 | case SOME(CONTINUOUS(__)) then "discrete" | ||
| 267 | case NONE() then "discrete" | ||
| 268 | else getVariability(variability_) | ||
| 269 | end getVariabilityFMI1; | ||
| 270 | |||
| 271 | 8 | template getAliasVar(AliasVariable aliasvar) | |
| 272 | "Returns the alias Attribute of ScalarVariable." | ||
| 273 | ::= | ||
| 274 | match aliasvar | ||
| 275 | case NOALIAS(__) then "noAlias" | ||
| 276 | /* We don't handle the alias and negatedAlias properly. If a variable is alias it must get the valueReference of the aliased variable. */ | ||
| 277 | /*case ALIAS(__) then "alias" | ||
| 278 | case NEGATEDALIAS(__) then "negatedAlias" | ||
| 279 | */ | ||
| 280 | else "noAlias" | ||
| 281 | end getAliasVar; | ||
| 282 | |||
| 283 | 16 | template ScalarVariableType(SimVar simvar) | |
| 284 | "Generates code for ScalarVariable Type file for FMU target." | ||
| 285 | ::= | ||
| 286 | match simvar | ||
| 287 | case SIMVAR(__) then | ||
| 288 | match type_ | ||
| 289 | case T_INTEGER(__) then '<Integer<%StartString(simvar)%>/>' | ||
| 290 | /* Don't generate the units for now since it is wrong. If you generate a unit attribute here then we must add the UnitDefinitions tag section also. */ | ||
| 291 | case T_REAL(__) then '<Real<%StartString(simvar)/*%><%ScalarVariableTypeRealAttribute(unit,displayUnit)*/%>/>' | ||
| 292 | case T_BOOL(__) then '<Boolean<%StartString(simvar)%>/>' | ||
| 293 | case T_STRING(__) then '<String<%StartString(simvar)%>/>' | ||
| 294 | case T_ENUMERATION(__) then '<Enumeration declaredType="<%AbsynUtil.pathString(path, ".", false, false)%>"<%StartString(simvar)%>/>' | ||
| 295 | else 'UNKOWN_TYPE' | ||
| 296 | end ScalarVariableType; | ||
| 297 | |||
| 298 | 16 | template StartString(SimVar simvar) | |
| 299 | ::= | ||
| 300 | match simvar | ||
| 301 | case SIMVAR(initialValue = initialValue, causality = causality, type_ = type_) then | ||
| 302 | match initialValue | ||
| 303 | case SOME(e as ICONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 304 | case SOME(e as RCONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 305 | case SOME(e as SCONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 306 | case SOME(e as BCONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 307 | case SOME(e as ENUM_LITERAL(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 308 | else | ||
| 309 | match causality | ||
| 310 | case SOME(INPUT(__)) then ' start="<%initDefaultValXml(type_)%>"' | ||
| 311 | else '' | ||
| 312 | end StartString; | ||
| 313 | |||
| 314 | ✗ | template ScalarVariableTypeRealAttribute(String unit, String displayUnit) | |
| 315 | "Generates code for ScalarVariable Type Real file for FMU target." | ||
| 316 | ::= | ||
| 317 | let unit_ = if unit then 'unit="<%Util.escapeModelicaStringToXmlString(unit)%>"' | ||
| 318 | let displayUnit_ = if displayUnit then 'displayUnit="<%Util.escapeModelicaStringToXmlString(displayUnit)%>"' | ||
| 319 | << | ||
| 320 | <%unit_%> <%displayUnit_%> | ||
| 321 | >> | ||
| 322 | end ScalarVariableTypeRealAttribute; | ||
| 323 | |||
| 324 | 74 | template externalFunctions(ModelInfo modelInfo) | |
| 325 | "Generates external function definitions." | ||
| 326 | ::= | ||
| 327 | match modelInfo | ||
| 328 | case MODELINFO(__) then | ||
| 329 | (functions |> fn => externalFunction(fn) ; separator="\n") | ||
| 330 | end externalFunctions; | ||
| 331 | |||
| 332 | ✗ | template externalFunction(SimCodeFunction.Function fn) | |
| 333 | "Generates external function definitions." | ||
| 334 | ::= | ||
| 335 | match fn | ||
| 336 | case EXTERNAL_FUNCTION(dynamicLoad=true) then | ||
| 337 | let fname = extFunctionName(extName, language) | ||
| 338 | << | ||
| 339 | <ExternalFunction | ||
| 340 | name="<%fname%>" | ||
| 341 | valueReference="<%System.tmpTick()%>"/> | ||
| 342 | >> | ||
| 343 | end externalFunction; | ||
| 344 | |||
| 345 | ✗ | template Implementation() | |
| 346 | "Generate Co-simulation Implementation section" | ||
| 347 | ::= | ||
| 348 | << | ||
| 349 | <Implementation> | ||
| 350 | <CoSimulation_StandAlone> | ||
| 351 | <Capabilities | ||
| 352 | canHandleVariableCommunicationStepSize="true" | ||
| 353 | canHandleEvents="true" | ||
| 354 | canBeInstantiatedOnlyOncePerProcess="false" | ||
| 355 | canInterpolateInputs="true" | ||
| 356 | maxOutputDerivativeOrder="0"/> | ||
| 357 | </CoSimulation_StandAlone> | ||
| 358 | </Implementation> | ||
| 359 | >> | ||
| 360 | end Implementation; | ||
| 361 | |||
| 362 | 72 | template ModelStructure(Option<FmiModelStructure> fmiModelStructure) | |
| 363 | "Generates ModelStructure" | ||
| 364 | ::= | ||
| 365 | match fmiModelStructure | ||
| 366 | case SOME(fmistruct as FMIMODELSTRUCTURE(__)) then | ||
| 367 | << | ||
| 368 | <ModelStructure> | ||
| 369 | <%ModelStructureOutputs(fmistruct.fmiOutputs)%> | ||
| 370 | <%ModelStructureDerivatives(fmistruct.fmiDerivatives)%> | ||
| 371 | <% if Flags.getConfigBool(Flags.EXPORT_CLOCKS_IN_MODELDESCRIPTION) then ModelStructureDiscreteStates(fmistruct.fmiDiscreteStates) else "" %> | ||
| 372 | <%ModelStructureInitialUnknowns(fmistruct.fmiInitialUnknowns)%> | ||
| 373 | </ModelStructure> | ||
| 374 | >> | ||
| 375 | else | ||
| 376 | << | ||
| 377 | <ModelStructure> | ||
| 378 | </ModelStructure> | ||
| 379 | >> | ||
| 380 | end ModelStructure; | ||
| 381 | |||
| 382 | 5 | template TypeDefinitionsClocks(SimCode simCode) | |
| 383 | "Generates TypeDefinitions Clocks" | ||
| 384 | ::= | ||
| 385 | match simCode | ||
| 386 | case SIMCODE(modelInfo = MODELINFO(__)) then | ||
| 387 | let clocks = (clockedPartitions |> partition => | ||
| 388 | match partition | ||
| 389 | case CLOCKED_PARTITION(baseClock=baseClock, subPartitions=subPartitions) then | ||
| 390 | match baseClock | ||
| 391 | case REAL_CLOCK(interval=baseInterval as RCONST(real=bi)) then | ||
| 392 | (subPartitions |> subPartition => | ||
| 393 | match subPartition | ||
| 394 | case SUBPARTITION(subClock=SUBCLOCK(factor=RATIONAL(nom=fsub, denom=fsuper), shift=RATIONAL(nom=snom, denom=sres))) then | ||
| 395 | << | ||
| 396 | <Clock><Inferred | ||
| 397 | interval="<%realMul(bi, realDiv(intReal(fsub), intReal(fsuper)))%>" | ||
| 398 | <%if intGt(snom, 0) then 'shiftCounter="'+snom+'"'%> | ||
| 399 | <%if intGt(sres, 1) then 'resolution="'+sres+'"'%> | ||
| 400 | /></Clock> | ||
| 401 | >> | ||
| 402 | ; separator="\n") | ||
| 403 | case RATIONAL_CLOCK(intervalCounter=ic as ICONST(integer=bic), resolution=res as ICONST(integer=resi)) then | ||
| 404 | (subPartitions |> subPartition => | ||
| 405 | match subPartition | ||
| 406 | case SUBPARTITION(subClock=SUBCLOCK(factor=RATIONAL(nom=fsub, denom=fsuper), shift=RATIONAL(nom=snom, denom=sres))) then | ||
| 407 | << | ||
| 408 | <Clock><Inferred | ||
| 409 | intervalCounter="<%intMul(intMul(bic, fsub), sres)%>" | ||
| 410 | <%if intGt(snom, 0) then 'shiftCounter="'+intMul(intMul(snom, resi), fsuper)+'"'%> | ||
| 411 | resolution="<%intMul(intMul(resi, sres), fsuper)%>" | ||
| 412 | /></Clock> | ||
| 413 | >> | ||
| 414 | ; separator="\n") | ||
| 415 | case REAL_CLOCK() | ||
| 416 | case RATIONAL_CLOCK() | ||
| 417 | case INFERRED_CLOCK() then | ||
| 418 | << | ||
| 419 | <Clock><Inferred/></Clock> | ||
| 420 | >> | ||
| 421 | else | ||
| 422 | << | ||
| 423 | <Clock><Triggered/></Clock> | ||
| 424 | >> | ||
| 425 | ;separator="\n") | ||
| 426 | match clocks | ||
| 427 | case "" then | ||
| 428 | <<>> | ||
| 429 | else | ||
| 430 | << | ||
| 431 | <Clocks> | ||
| 432 | <%clocks%> | ||
| 433 | </Clocks> | ||
| 434 | >> | ||
| 435 | end TypeDefinitionsClocks; | ||
| 436 | |||
| 437 | 38 | template ModelStructureOutputs(FmiOutputs fmiOutputs) | |
| 438 | "Generates Model Structure Outputs." | ||
| 439 | ::= | ||
| 440 | match fmiOutputs | ||
| 441 | case FMIOUTPUTS(fmiUnknownsList={}) then "" | ||
| 442 | case FMIOUTPUTS(__) then | ||
| 443 | << | ||
| 444 | <Outputs> | ||
| 445 | <%ModelStructureUnknowns(fmiUnknownsList)%> | ||
| 446 | </Outputs> | ||
| 447 | >> | ||
| 448 | end ModelStructureOutputs; | ||
| 449 | |||
| 450 | 52 | template ModelStructureDerivatives(FmiDerivatives fmiDerivatives) | |
| 451 | "Generates Model Structure Derivatives." | ||
| 452 | ::= | ||
| 453 | match fmiDerivatives | ||
| 454 | case FMIDERIVATIVES(fmiUnknownsList={}) then "" | ||
| 455 | case FMIDERIVATIVES(__) then | ||
| 456 | << | ||
| 457 | <Derivatives> | ||
| 458 | <%ModelStructureUnknowns(fmiUnknownsList)%> | ||
| 459 | </Derivatives> | ||
| 460 | >> | ||
| 461 | end ModelStructureDerivatives; | ||
| 462 | |||
| 463 | 4 | template ModelStructureDiscreteStates(FmiDiscreteStates fmiDiscreteStates) | |
| 464 | "Generates Model Structure DiscreteStates." | ||
| 465 | ::= | ||
| 466 | match fmiDiscreteStates | ||
| 467 | // don't generate if model has no discrete states for FMI 2.0 compatibility | ||
| 468 | case FMIDISCRETESTATES(fmiUnknownsList={}) then "" | ||
| 469 | case FMIDISCRETESTATES(__) then | ||
| 470 | << | ||
| 471 | <DiscreteStates> | ||
| 472 | <%ModelStructureUnknowns(fmiUnknownsList)%> | ||
| 473 | </DiscreteStates> | ||
| 474 | >> | ||
| 475 | end ModelStructureDiscreteStates; | ||
| 476 | |||
| 477 | 66 | template ModelStructureInitialUnknowns(FmiInitialUnknowns fmiInitialUnknowns) | |
| 478 | "Generates Model Structure InitialUnknowns." | ||
| 479 | ::= | ||
| 480 | match fmiInitialUnknowns | ||
| 481 | case FMIINITIALUNKNOWNS(fmiUnknownsList={}) then "" | ||
| 482 | case FMIINITIALUNKNOWNS(__) then | ||
| 483 | << | ||
| 484 | <InitialUnknowns> | ||
| 485 | <%ModelStructureUnknowns(fmiUnknownsList)%> | ||
| 486 | </InitialUnknowns> | ||
| 487 | >> | ||
| 488 | end match | ||
| 489 | end ModelStructureInitialUnknowns; | ||
| 490 | |||
| 491 | 160 | template ModelStructureUnknowns(list<FmiUnknown> fmiUnknownsList) | |
| 492 | "Generates Model Structure Unknowns" | ||
| 493 | ::= | ||
| 494 | << | ||
| 495 | <%fmiUnknownsList |> fmiUnknown => FmiUnknownAttributes(fmiUnknown) ;separator="\n"%> | ||
| 496 | >> | ||
| 497 | end ModelStructureUnknowns; | ||
| 498 | |||
| 499 | 821 | template FmiUnknownAttributes(FmiUnknown fmiUnknown) | |
| 500 | "Generates Model Structure Unknown attributes" | ||
| 501 | ::= | ||
| 502 | match fmiUnknown | ||
| 503 | case FMIUNKNOWN(__) then | ||
| 504 | << | ||
| 505 | <Unknown index="<%index%>"<%FmiUnknownDependencies(dependencies)%><%FmiUnknownDependenciesKind(dependenciesKind)%> /> | ||
| 506 | >> | ||
| 507 | end FmiUnknownAttributes; | ||
| 508 | |||
| 509 | 821 | template FmiUnknownDependencies(list<Integer> dependencies) | |
| 510 | ::= | ||
| 511 | // Note: dependencies="" means no dependencies; | ||
| 512 | // missing dependencies means dependent on all knowns (see FMI 2.0 spec). | ||
| 513 | << | ||
| 514 | dependencies="<%SimCodeCodegenUtil.fmiDependenciesString(dependencies)%>" | ||
| 515 | >> | ||
| 516 | end FmiUnknownDependencies; | ||
| 517 | |||
| 518 | 821 | template FmiUnknownDependenciesKind(list<String> dependenciesKind) | |
| 519 | ::= | ||
| 520 | << | ||
| 521 | dependenciesKind="<%SimCodeCodegenUtil.fmiDependenciesKindString(dependenciesKind)%>" | ||
| 522 | >> | ||
| 523 | end FmiUnknownDependenciesKind; | ||
| 524 | |||
| 525 | 2286 | template ScalarVariableAttribute2(SimVar simVar, SimCode simCode) | |
| 526 | "Generates code for ScalarVariable Attribute file for FMU 2.0 target." | ||
| 527 | ::= | ||
| 528 | match simVar | ||
| 529 | case SIMVAR(__) then | ||
| 530 | let name = Util.escapeModelicaStringToXmlString(System.stringReplace(crefStrNoUnderscore(Util.getOption(exportVar)),"$", "_D_")) | ||
| 531 | let defaultValueReference = '<%System.tmpTick()%>' | ||
| 532 | let valueReference = getValueReference(simVar, simCode, false) | ||
| 533 | let description = if comment then 'description="<%Util.escapeModelicaStringToXmlString(comment)%>"' | ||
| 534 | let variability_ = if getClockIndex(simVar, simCode) then "discrete" else getVariabilityFMI2(variability, type_) | ||
| 535 | let clockIndex = getClockIndex(simVar, simCode) | ||
| 536 | let previous = match varKind case CLOCKED_STATE(__) then '<%getVariableFMIIndex(cref2simvar(previousName, simCode))%>' | ||
| 537 | let caus = getCausality2(causality) | ||
| 538 | let initial = getFmiInitialAttributeStr(simVar) | ||
| 539 | << | ||
| 540 | name="<%name%>" | ||
| 541 | valueReference="<%valueReference%>" | ||
| 542 | <%description%> | ||
| 543 | <%if boolNot(stringEq(variability_, "")) then 'variability="'+variability_+'"' %> | ||
| 544 | <%if boolNot(stringEq(caus, "")) then 'causality="'+caus+'"' %> | ||
| 545 | <%if boolAnd(boolNot(stringEq(clockIndex, "")), Flags.getConfigBool(Flags.EXPORT_CLOCKS_IN_MODELDESCRIPTION)) then 'clockIndex="'+clockIndex+'"' %> | ||
| 546 | <%if boolAnd(boolNot(stringEq(previous, "")), Flags.getConfigBool(Flags.EXPORT_CLOCKS_IN_MODELDESCRIPTION)) then 'previous="'+previous+'"' %> | ||
| 547 | <%if boolNot(stringEq(initial, "")) then 'initial="'+initial+'"' %> | ||
| 548 | >> | ||
| 549 | end ScalarVariableAttribute2; | ||
| 550 | |||
| 551 | 1785 | template getVariability2(Option<SimCodeVar.Variability> variability) | |
| 552 | "Returns the variability Attribute of ScalarVariable." | ||
| 553 | ::= | ||
| 554 | match variability | ||
| 555 | case SOME(DISCRETE(__)) then "discrete" | ||
| 556 | case SOME(FIXED(__)) then "fixed" | ||
| 557 | case SOME(CONSTANT(__)) then "constant" | ||
| 558 | case SOME(CONTINUOUS(__)) then if Flags.isSet(Flags.DUMP_FORCE_FMI_ATTRIBUTES) then "continuous" else "" // default | ||
| 559 | case SOME(TUNABLE(__)) then "tunable" | ||
| 560 | else "" | ||
| 561 | end getVariability2; | ||
| 562 | |||
| 563 | 2240 | template getVariabilityFMI2(Option<SimCodeVar.Variability> variability, DAE.Type type_) | |
| 564 | "Returns the variability Attribute of an FMI 2.0 ScalarVariable. | ||
| 565 | |||
| 566 | FMI 2.0 allows variability='continuous' only for Real (FMI 2.0 specification, | ||
| 567 | section 2.2.7), and the attribute defaults to 'continuous' when it is left out. | ||
| 568 | A non-Real variable that is continuous in Modelica, or that carries no | ||
| 569 | variability of its own, therefore has to be written out as discrete -- leaving | ||
| 570 | it to the default would produce an invalid modelDescription.xml. | ||
| 571 | |||
| 572 | FMI 3.0 does not need this: there the default is 'discrete' for every type | ||
| 573 | other than Float32/Float64, so getVariability2 is used as is." | ||
| 574 | ::= | ||
| 575 | match type_ | ||
| 576 | case T_REAL(__) then getVariability2(variability) | ||
| 577 | else | ||
| 578 | match variability | ||
| 579 | case SOME(CONTINUOUS(__)) then "discrete" | ||
| 580 | case NONE() then "discrete" | ||
| 581 | else getVariability2(variability) | ||
| 582 | end getVariabilityFMI2; | ||
| 583 | |||
| 584 | 1925 | template getCausality2(Option<Causality> c) | |
| 585 | "Returns the Causality Attribute of ScalarVariable." | ||
| 586 | ::= | ||
| 587 | match c | ||
| 588 | case SOME(NONECAUS(__)) then "none" | ||
| 589 | case SOME(OUTPUT(__)) then "output" | ||
| 590 | case SOME(INPUT(__)) then "input" | ||
| 591 | case SOME(LOCAL(__)) then if Flags.isSet(Flags.DUMP_FORCE_FMI_ATTRIBUTES) then "local" else "" // same as INTERNAL() see FMI-2.0 specification | ||
| 592 | case SOME(PARAMETER(__)) then "parameter" | ||
| 593 | case SOME(CALCULATED_PARAMETER(__)) then "calculatedParameter" | ||
| 594 | else "" | ||
| 595 | /*TODO! Handle "independent" causality.*/ | ||
| 596 | end getCausality2; | ||
| 597 | |||
| 598 | 132 | template getNumberOfEventIndicators(SimCode simCode) | |
| 599 | "Get the number of event indicators, which depends on the selected code target (c or cpp)." | ||
| 600 | ::= | ||
| 601 | match simCode | ||
| 602 | case SIMCODE(zeroCrossings = zeroCrossings, modelInfo = MODELINFO(varInfo = vi as VARINFO(__))) then | ||
| 603 | match Config.simCodeTarget() | ||
| 604 | case "Cpp" | ||
| 605 | then listLength(zeroCrossings) | ||
| 606 | else vi.numZeroCrossings | ||
| 607 | end match | ||
| 608 | else "" | ||
| 609 | end getNumberOfEventIndicators; | ||
| 610 | |||
| 611 | 2286 | template ScalarVariableType2(SimVar simvar, list<SimVar> stateVars) | |
| 612 | "Generates code for ScalarVariable Type file for FMU 2.0 target." | ||
| 613 | ::= | ||
| 614 | match simvar | ||
| 615 | case SIMVAR(__) then | ||
| 616 | match type_ | ||
| 617 | case T_REAL(__) then '<Real<%ScalarVariableTypeCommonAttribute2(simvar, stateVars)%>/>' | ||
| 618 | case T_INTEGER(__) then '<Integer<%ScalarVariableTypeCommonAttribute2(simvar, stateVars)%>/>' | ||
| 619 | case T_BOOL(__) then '<Boolean<%ScalarVariableTypeCommonAttribute2(simvar, stateVars)%>/>' | ||
| 620 | case T_STRING(__) then '<String<%ScalarVariableTypeCommonAttribute2(simvar, stateVars)%>/>' | ||
| 621 | case T_ENUMERATION(__) then '<Enumeration declaredType="<%AbsynUtil.pathString(path, ".", false, false)%>"<%ScalarVariableTypeCommonAttribute2(simvar, stateVars)%>/>' | ||
| 622 | else 'UNKOWN_TYPE' | ||
| 623 | end ScalarVariableType2; | ||
| 624 | |||
| 625 | 2286 | template ScalarVariableTypeCommonAttribute2(SimVar simvar, list<SimVar> stateVars) | |
| 626 | "Generates code for ScalarVariable Type file for FMU 2.0 target." | ||
| 627 | ::= | ||
| 628 | match simvar | ||
| 629 | case SIMVAR(__) then | ||
| 630 | let startString = StartString2(simvar) | ||
| 631 | let extraAttributes = '<%DerivativeVarIndex(simvar,stateVars)%><%MinString2(simvar)%><%MaxString2(simvar)%><%NominalString2(simvar)%><%UnitString2(simvar)%><%relativeQuantity(simvar)%>' | ||
| 632 | << | ||
| 633 | <%startString%><%extraAttributes%> | ||
| 634 | >> | ||
| 635 | end ScalarVariableTypeCommonAttribute2; | ||
| 636 | |||
| 637 | 2286 | template DerivativeVarIndex(SimVar simvar, list<SimVar> stateVars) | |
| 638 | ::= | ||
| 639 | match simvar | ||
| 640 | case SIMVAR(varKind = varKind, index = index) then | ||
| 641 | match varKind | ||
| 642 | case STATE_DER(__) then ' derivative="<%getStateSimVarIndexFromIndex(stateVars, index)%>"' | ||
| 643 | else '' | ||
| 644 | end DerivativeVarIndex; | ||
| 645 | |||
| 646 | // template StartString2(SimVar simvar) | ||
| 647 | // ::= | ||
| 648 | // match simvar | ||
| 649 | // case SIMVAR(aliasvar = SimCodeVar.ALIAS(__)) then '' | ||
| 650 | // case SIMVAR(initialValue = initialValue) then | ||
| 651 | // match initialValue | ||
| 652 | // case SOME(initialValue) then ' start="<%initValXml(initialValue)%>"' | ||
| 653 | // else '' | ||
| 654 | // end StartString2; | ||
| 655 | |||
| 656 | 2037 | template StartString2(SimVar simvar) | |
| 657 | ::= | ||
| 658 | match simvar | ||
| 659 | case SIMVAR(aliasvar = SimCodeVar.ALIAS(__)) then '' | ||
| 660 | case SIMVAR(initialValue = NONE()) then '' | ||
| 661 | case SIMVAR(causality = SOME(SimCodeVar.INPUT())) then '<%startString3(simvar)%>' | ||
| 662 | case SIMVAR(initial_ = initial_) then | ||
| 663 | match initial_ | ||
| 664 | case SOME(SimCodeVar.EXACT()) then '<%startString3(simvar)%>' | ||
| 665 | case SOME(SimCodeVar.APPROX()) then '<%startString3(simvar)%>' | ||
| 666 | else '' | ||
| 667 | end StartString2; | ||
| 668 | |||
| 669 | // make a more general check on the expression types and generate start value only for these types | ||
| 670 | 989 | template startString3(SimVar simvar) | |
| 671 | ::= | ||
| 672 | match simvar | ||
| 673 | case SIMVAR(initialValue = initialValue) then | ||
| 674 | match initialValue | ||
| 675 | case SOME(e as ICONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 676 | case SOME(e as RCONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 677 | case SOME(e as SCONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 678 | case SOME(e as BCONST(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 679 | case SOME(e as ENUM_LITERAL(__)) then ' start="<%initValXml(e, "")%>"' | ||
| 680 | else '' | ||
| 681 | end startString3; | ||
| 682 | |||
| 683 | ✗ | template startString2Helper(Option<Exp> exp, DAE.Type type_) | |
| 684 | ::= | ||
| 685 | match exp | ||
| 686 | case SOME((e as exp)) then '<%initValXml(e, "")%>' | ||
| 687 | // if start expression is none then assigne defaultvalues for start attribute based on Type | ||
| 688 | else '<%initDefaultValXml(type_)%>' | ||
| 689 | end startString2Helper; | ||
| 690 | |||
| 691 | 3392 | template MinString2(SimVar simvar) | |
| 692 | ::= | ||
| 693 | match simvar | ||
| 694 | case SIMVAR(minValue = minValue) then | ||
| 695 | match minValue | ||
| 696 | case SOME(e as ICONST(__)) then ' min="<%initValXml(e, "")%>"' | ||
| 697 | case SOME(e as RCONST(__)) then ' min="<%initValXml(e, "")%>"' | ||
| 698 | case SOME(e as SCONST(__)) then ' min="<%initValXml(e, "")%>"' | ||
| 699 | case SOME(e as BCONST(__)) then ' min="<%initValXml(e, "")%>"' | ||
| 700 | case SOME(e as ENUM_LITERAL(__)) then ' min="<%initValXml(e, "")%>"' | ||
| 701 | else '' | ||
| 702 | end MinString2; | ||
| 703 | |||
| 704 | 3392 | template MaxString2(SimVar simvar) | |
| 705 | ::= | ||
| 706 | match simvar | ||
| 707 | case SIMVAR(maxValue = maxValue) then | ||
| 708 | match maxValue | ||
| 709 | case SOME(e as ICONST(__)) then ' max="<%initValXml(e, "")%>"' | ||
| 710 | case SOME(e as RCONST(__)) then ' max="<%initValXml(e, "")%>"' | ||
| 711 | case SOME(e as SCONST(__)) then ' max="<%initValXml(e, "")%>"' | ||
| 712 | case SOME(e as BCONST(__)) then ' max="<%initValXml(e, "")%>"' | ||
| 713 | case SOME(e as ENUM_LITERAL(__)) then ' max="<%initValXml(e, "")%>"' | ||
| 714 | else '' | ||
| 715 | end MaxString2; | ||
| 716 | |||
| 717 | 3310 | template NominalString2(SimVar simvar) | |
| 718 | ::= | ||
| 719 | match simvar | ||
| 720 | case SIMVAR(nominalValue = nominalValue) then | ||
| 721 | match nominalValue | ||
| 722 | case SOME(e as RCONST(__)) then ' nominal="<%initValXml(e, "")%>"' | ||
| 723 | else '' | ||
| 724 | end NominalString2; | ||
| 725 | |||
| 726 | 2286 | template UnitString2(SimVar simvar) | |
| 727 | ::= | ||
| 728 | match simvar | ||
| 729 | case SIMVAR(unit = unit, displayUnit = displayUnit) then | ||
| 730 | let unitString = if unit then ' unit="<%Util.escapeModelicaStringToXmlString(unit)%>"' | ||
| 731 | let displayUnitString = if displayUnit then ' displayUnit="<%Util.escapeModelicaStringToXmlString(displayUnit)%>"' | ||
| 732 | //'<%unitString%><%displayUnitString%>' skip displayUnit because FMI2XML fails for e.g. bar | ||
| 733 | '<%unitString%>' | ||
| 734 | end UnitString2; | ||
| 735 | |||
| 736 | 1024 | template UnitString3(SimVar simvar, SimCode simCode) | |
| 737 | "UnitString2 with the display unit, which FMI 3.0 may name now that the unit | ||
| 738 | definitions declare it. Left off where it resolved to no <DisplayUnit>, which a | ||
| 739 | variable may not name." | ||
| 740 | ::= | ||
| 741 | match simvar | ||
| 742 | case SIMVAR(unit = unit, displayUnit = displayUnit) then | ||
| 743 | let unitString = if unit then ' unit="<%Util.escapeModelicaStringToXmlString(unit)%>"' | ||
| 744 | let displayUnitString = if declaredDisplayUnit(unit, displayUnit, simCode) then | ||
| 745 | ' displayUnit="<%Util.escapeModelicaStringToXmlString(displayUnit)%>"' | ||
| 746 | '<%unitString%><%displayUnitString%>' | ||
| 747 | end UnitString3; | ||
| 748 | |||
| 749 | 1024 | template declaredDisplayUnit(String unit, String displayUnit, SimCode simCode) | |
| 750 | "Non-empty when `displayUnit` is another unit of `unit`\'s dimensions, which is exactly | ||
| 751 | when UnitDefinitions nested it as a <DisplayUnit> of it." | ||
| 752 | ::= | ||
| 753 | match simCode | ||
| 754 | case SIMCODE(modelInfo=MODELINFO(unitDefinitions=unitDefinitions)) then | ||
| 755 | let dims = (unitDefinitions |> u => unitDimensionsNamed(u, unit)) | ||
| 756 | let displayDims = (unitDefinitions |> u => unitDimensionsNamed(u, displayUnit)) | ||
| 757 | if boolAnd(boolNot(stringEq(dims, "")), | ||
| 758 | boolAnd(stringEq(dims, displayDims), boolNot(stringEq(unit, displayUnit)))) then "declared" | ||
| 759 | end declaredDisplayUnit; | ||
| 760 | |||
| 761 | 32702 | template unitDimensionsNamed(UnitDefinition unitDefinition, String wanted) | |
| 762 | "This unit\'s dimensions when it is the one named, so a fold over the list picks it out. | ||
| 763 | `wanted` may not be called `name`: a record field of that name shadows the parameter." | ||
| 764 | ::= | ||
| 765 | match unitDefinition | ||
| 766 | case UNITDEFINITION(name=unitName, baseUnit=baseUnit) then | ||
| 767 | if stringEq(unitName, wanted) then baseUnitDimensions(baseUnit) | ||
| 768 | end unitDimensionsNamed; | ||
| 769 | |||
| 770 | 3310 | template relativeQuantity(SimVar simvar) | |
| 771 | ::= | ||
| 772 | match simvar | ||
| 773 | case SIMVAR(relativeQuantity = relativeQuantity) then | ||
| 774 | match relativeQuantity | ||
| 775 | case true then ' relativeQuantity="true"' | ||
| 776 | else '' | ||
| 777 | end relativeQuantity; | ||
| 778 | |||
| 779 | 36 | template statesnumwithDummy(list<SimVar> vars) | |
| 780 | " return number of states without dummy vars" | ||
| 781 | ::= | ||
| 782 | (vars |> var => match var case SIMVAR(__) then if stringEq(CodegenUtil.crefStr(name),"$dummy") then '0' else '1' ;separator="\n") | ||
| 783 | end statesnumwithDummy; | ||
| 784 | |||
| 785 | 91 | template xsdateTime(DateTime dt) | |
| 786 | "YYYY-MM-DDThh:mm:ssZ" | ||
| 787 | ::= | ||
| 788 | match dt | ||
| 789 | case DATETIME(__) then '<%year%>-<%twodigit(mon)%>-<%twodigit(mday)%>T<%twodigit(hour)%>:<%twodigit(min)%>:<%twodigit(sec)%>Z' | ||
| 790 | end xsdateTime; | ||
| 791 | |||
| 792 | 88 | template UnitDefinitions(SimCode simCode) | |
| 793 | "Generates code for UnitDefinitions file for FMU target." | ||
| 794 | ::= | ||
| 795 | match simCode | ||
| 796 | case SIMCODE(modelInfo=modelInfo) then | ||
| 797 | match modelInfo | ||
| 798 | case MODELINFO(unitDefinitions = unitDefinitions) then | ||
| 799 | << | ||
| 800 | <%UnitDefinitionsHelper(unitDefinitions)%> | ||
| 801 | >> | ||
| 802 | end UnitDefinitions; | ||
| 803 | |||
| 804 | 19 | template UnitDefinitionsHelper(list<UnitDefinition> unitDefinitions) | |
| 805 | "Generates code for UnitDefinition for FMU target." | ||
| 806 | ::= | ||
| 807 | if unitDefinitions then | ||
| 808 | << | ||
| 809 | <UnitDefinitions> | ||
| 810 | <%unitDefinitions |> unitDefinition => UnitDefinitionsHelper1(unitDefinition, unitDefinitions) ;separator="\n"%> | ||
| 811 | </UnitDefinitions> | ||
| 812 | >> | ||
| 813 | end UnitDefinitionsHelper; | ||
| 814 | |||
| 815 | 215 | template UnitDefinitionsHelper1(UnitDefinition unitDefinition, list<UnitDefinition> allUnits) | |
| 816 | "helper function to generates code for UnitDefinition for FMU target." | ||
| 817 | ::= | ||
| 818 | match unitDefinition | ||
| 819 | case UNITDEFINITION(name=name, baseUnit=baseUnit) then | ||
| 820 | << | ||
| 821 | <Unit <%unitDefinitionAttribute(name)%>> | ||
| 822 | <%baseUnitAttributes(baseUnit)%><%displayUnits(name, baseUnit, allUnits)%> | ||
| 823 | </Unit> | ||
| 824 | >> | ||
| 825 | end UnitDefinitionsHelper1; | ||
| 826 | |||
| 827 | 215 | template displayUnits(String unitName, BaseUnit baseUnit, list<UnitDefinition> allUnits) | |
| 828 | "Every other unit of the same dimensions, nested as a <DisplayUnit> of this one: | ||
| 829 | FMI lets a variable name a display unit only among its own unit\'s children. | ||
| 830 | Fields are bound by name; Susan will not pass on the ones `__` brings into scope." | ||
| 831 | ::= | ||
| 832 | match baseUnit | ||
| 833 | case BASEUNIT(factor=unitFactor, offset=unitOffset) then | ||
| 834 | let dims = baseUnitDimensions(baseUnit) | ||
| 835 | (allUnits |> other => displayUnit(unitName, dims, unitFactor, unitOffset, other)) | ||
| 836 | end displayUnits; | ||
| 837 | |||
| 838 | 3313 | template displayUnit(String unitName, String dims, Real unitFactor, Real unitOffset, UnitDefinition other) | |
| 839 | "`other` as a <DisplayUnit> of the unit whose SI pair is (unitFactor, unitOffset), when | ||
| 840 | it is a different unit of the same dimensions. Both carry the pair taking them to SI, | ||
| 841 | so the display value is | ||
| 842 | value_display = (unitFactor/displayFactor)*value + (unitOffset - displayOffset)/displayFactor." | ||
| 843 | ::= | ||
| 844 | match other | ||
| 845 | case UNITDEFINITION(name=otherName, baseUnit=(otherBase as BASEUNIT(factor=displayFactor, offset=displayOffset))) then | ||
| 846 | if boolAnd(stringEq(dims, baseUnitDimensions(otherBase)), boolNot(stringEq(unitName, otherName))) then | ||
| 847 | '<%\n%><DisplayUnit name="<%Util.escapeModelicaStringToXmlString(otherName)%>" factor="<%realDiv(unitFactor, displayFactor)%>" offset="<%realDiv(realSub(unitOffset, displayOffset), displayFactor)%>"/>' | ||
| 848 | end displayUnit; | ||
| 849 | |||
| 850 | 4407 | template baseUnitDimensions(BaseUnit baseUnit) | |
| 851 | "The seven exponents as a key, so two units are compared as one string. Empty where | ||
| 852 | there is no base unit to compare." | ||
| 853 | ::= | ||
| 854 | match baseUnit | ||
| 855 | case BASEUNIT(__) then '<%s%>.<%m%>.<%kg%>.<%A%>.<%K%>.<%mol%>.<%cd%>' | ||
| 856 | end baseUnitDimensions; | ||
| 857 | |||
| 858 | 215 | template unitDefinitionAttribute(String unitName) | |
| 859 | "Generates code for UnitDefinition Attribute for FMU target." | ||
| 860 | ::= | ||
| 861 | let unitString = if unitName then 'name="<%unitName%>"' | ||
| 862 | << | ||
| 863 | <%unitString%> | ||
| 864 | >> | ||
| 865 | end unitDefinitionAttribute; | ||
| 866 | |||
| 867 | 215 | template baseUnitAttributes(BaseUnit baseUnit) | |
| 868 | "Generates code for BaseUnit for FMU target." | ||
| 869 | ::= | ||
| 870 | match baseUnit | ||
| 871 | case (BASEUNIT(__)) then | ||
| 872 | let s_Value = if not intEq(s, 0) then 's="<% s %>" ' else "" | ||
| 873 | let m_Value = if not intEq(m, 0) then 'm="<% m %>" ' else "" | ||
| 874 | let kg_Value = if not intEq(kg, 0) then 'kg="<% kg %>" ' else "" | ||
| 875 | let A_Value = if not intEq(A, 0) then 'A="<% A %>" ' else "" | ||
| 876 | let K_Value = if not intEq(K, 0) then 'K="<% K %>" ' else "" | ||
| 877 | let mol_Value = if not intEq(mol, 0) then 'mol="<% mol %>" ' else "" | ||
| 878 | let cd_Value = if not intEq(cd, 0) then 'cd="<% cd %>" ' else "" | ||
| 879 | let factor_Value = if not realAlmostEq(factor, 1.0, 1e-6) then 'factor="<% factor %>" ' else "" | ||
| 880 | let offset_Value = if not realAlmostEq(offset, 0.0, 1e-6) then 'offset="<% offset %>" ' else "" | ||
| 881 | << | ||
| 882 | <BaseUnit <%mol_Value%><%cd_Value%><%m_Value%><%s_Value%><%A_Value%><%K_Value%><%kg_Value%><%factor_Value%><%offset_Value%>/> | ||
| 883 | >> | ||
| 884 | case (NOBASEUNIT()) then "" | ||
| 885 | end baseUnitAttributes; | ||
| 886 | |||
| 887 | 75 | template fmiTypeDefinitions(SimCode simCode, String FMUVersion) | |
| 888 | "Generates code for TypeDefinitions for FMU target." | ||
| 889 | ::= | ||
| 890 | match simCode | ||
| 891 | case SIMCODE(modelInfo=modelInfo) then | ||
| 892 | match modelInfo | ||
| 893 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 894 | << | ||
| 895 | <%TypeDefinitionsHelper(simCode, SimCodeCodegenUtil.getEnumerationTypes(vars), FMUVersion)%> | ||
| 896 | >> | ||
| 897 | end fmiTypeDefinitions; | ||
| 898 | |||
| 899 | 75 | template TypeDefinitionsHelper(SimCode simCode, list<SimCodeVar.SimVar> vars, String FMUVersion) | |
| 900 | "Generates code for TypeDefinitions for FMU target." | ||
| 901 | ::= | ||
| 902 | let clocks = if isFMIVersion10(FMUVersion) then "" else if Flags.getConfigBool(Flags.EXPORT_CLOCKS_IN_MODELDESCRIPTION) then TypeDefinitionsClocks(simCode) else "" | ||
| 903 | if boolOr(intGt(listLength(vars), 0), boolNot(stringEq(clocks, ""))) then | ||
| 904 | << | ||
| 905 | <TypeDefinitions> | ||
| 906 | <%vars |> var => TypeDefinition(var,FMUVersion) ;separator="\n"%> | ||
| 907 | <%clocks%> | ||
| 908 | </TypeDefinitions> | ||
| 909 | >> | ||
| 910 | end TypeDefinitionsHelper; | ||
| 911 | |||
| 912 | 23 | template TypeDefinition(SimVar simVar, String FMUVersion) | |
| 913 | ::= | ||
| 914 | match simVar | ||
| 915 | case SIMVAR(__) then | ||
| 916 | << | ||
| 917 | <%TypeDefinitionType(type_,FMUVersion)%> | ||
| 918 | >> | ||
| 919 | end TypeDefinition; | ||
| 920 | |||
| 921 | 23 | template TypeDefinitionType(DAE.Type type_, String FMUVersion) | |
| 922 | "Generates code for TypeDefinitions Type file for FMU target." | ||
| 923 | ::= | ||
| 924 | match type_ | ||
| 925 | case T_ENUMERATION(__) then | ||
| 926 | if isFMIVersion20(FMUVersion) then | ||
| 927 | << | ||
| 928 | <SimpleType name="<%AbsynUtil.pathString(path, ".", false, false)%>"> | ||
| 929 | <Enumeration> | ||
| 930 | <%names |> name hasindex i0 fromindex 1 => '<Item name="<%name%>" value="<%i0%>"/>' ;separator="\n"%> | ||
| 931 | </Enumeration> | ||
| 932 | </SimpleType> | ||
| 933 | >> | ||
| 934 | else | ||
| 935 | << | ||
| 936 | <Type name="<%AbsynUtil.pathString(path, ".", false, false)%>"> | ||
| 937 | <EnumerationType> | ||
| 938 | <%names |> name => '<Item name="<%name%>"/>' ;separator="\n"%> | ||
| 939 | </EnumerationType> | ||
| 940 | </Type> | ||
| 941 | >> | ||
| 942 | end TypeDefinitionType; | ||
| 943 | |||
| 944 | 75 | template DefaultExperiment(Option<SimulationSettings> simulationSettingsOpt, String FMUVersion) | |
| 945 | "Generates code for DefaultExperiment file for FMU target." | ||
| 946 | ::= | ||
| 947 | match simulationSettingsOpt | ||
| 948 | case SOME(v) then | ||
| 949 | << | ||
| 950 | <DefaultExperiment <%DefaultExperimentAttribute(v, FMUVersion)%>/> | ||
| 951 | >> | ||
| 952 | end DefaultExperiment; | ||
| 953 | |||
| 954 | 75 | template DefaultExperimentAttribute(SimulationSettings simulationSettings, String FMUVersion) | |
| 955 | "Generates code for DefaultExperiment Attribute file for FMU target." | ||
| 956 | ::= | ||
| 957 | match simulationSettings | ||
| 958 | case SIMULATION_SETTINGS(__) then | ||
| 959 | if isFMIVersion20(FMUVersion) then | ||
| 960 | << | ||
| 961 | startTime="<%startTime%>" stopTime="<%stopTime%>" tolerance="<%tolerance%>" stepSize="<%stepSize%>" | ||
| 962 | >> | ||
| 963 | else | ||
| 964 | << | ||
| 965 | startTime="<%startTime%>" stopTime="<%stopTime%>" tolerance="<%tolerance%>" | ||
| 966 | >> | ||
| 967 | end DefaultExperimentAttribute; | ||
| 968 | |||
| 969 | 5 | template fmuSimulationFlagsFile(FmiSimulationFlags fmiSimulationFlags) | |
| 970 | "Generates <fmiPrefix>_flags.json file for FMUs with custom simulation flags. | ||
| 971 | Lives in the codegen_fmu tier: the wasm export ships the same file and reads | ||
| 972 | its solver back out of it, so it must not depend on the C target." | ||
| 973 | ::= | ||
| 974 | match fmiSimulationFlags | ||
| 975 | case flags as FMI_SIMULATION_FLAGS(__) then | ||
| 976 | let fileContent = (flags.nameValueTuples |> (name, value) => | ||
| 977 | '"<%name%>" : "<%value%>"' | ||
| 978 | ;separator=",\n") | ||
| 979 | << | ||
| 980 | { | ||
| 981 | <%fileContent%> | ||
| 982 | } | ||
| 983 | >> | ||
| 984 | end fmuSimulationFlagsFile; | ||
| 985 | |||
| 986 | ✗ | template getPlatformString2(String modelNamePrefix, String platform, String fileNamePrefix, String fmuTargetName, String dirExtra, String libsPos1, String libsPos2, String omhome, String FMUVersion) | |
| 987 | "returns compilation commands for the platform. " | ||
| 988 | ::= | ||
| 989 | let fmudirname = '<%Util.hashFileNamePrefix(fileNamePrefix)%>.fmutmp' | ||
| 990 | match platform | ||
| 991 | case "win32" | ||
| 992 | case "win64" then | ||
| 993 | << | ||
| 994 | <%fileNamePrefix%>_FMU: nozip | ||
| 995 | <%\t%>cd .. && rm -f ../<%fileNamePrefix%>.fmu && zip -r ../<%fmuTargetName%>.fmu * | ||
| 996 | nozip: <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES) $(FMISUNDIALSFILES) | ||
| 997 | <%\t%>$(CXX) -shared -I. -o <%modelNamePrefix%>$(DLLEXT) $(RUNTIMEFILES) $(FMISUNDIALSFILES) $(OFILES) $(CPPFLAGS) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(CFLAGS) $(LDFLAGS) -llis -Wl,--kill-at | ||
| 998 | <%\t%>mkdir.exe -p ../binaries/<%platform%> | ||
| 999 | <%\t%>dlltool -d <%fileNamePrefix%>.def --dllname <%fileNamePrefix%>$(DLLEXT) --output-lib <%fileNamePrefix%>.lib --kill-at | ||
| 1000 | <%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fileNamePrefix%>.lib <%fileNamePrefix%>_FMU.libs ../binaries/<%platform%>/ | ||
| 1001 | <%\t%>rm -f *.o <%fileNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES) $(FMISUNDIALSFILES) | ||
| 1002 | <%\t%>cd .. && rm -f ../<%fileNamePrefix%>.fmu && zip -r ../<%fmuTargetName%>.fmu * | ||
| 1003 | |||
| 1004 | >> | ||
| 1005 | else | ||
| 1006 | << | ||
| 1007 | <%fileNamePrefix%>_FMU: nozip | ||
| 1008 | <%\t%>cd .. && rm -f ../<%fileNamePrefix%>.fmu && zip -r ../<%fmuTargetName%>.fmu * | ||
| 1009 | nozip: <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES) $(FMISUNDIALSFILES) | ||
| 1010 | <%\t%>mkdir -p ../binaries/$(FMIPLATFORM) | ||
| 1011 | ifeq (@LIBTYPE_DYNAMIC@,1) | ||
| 1012 | <%\t%>$(LD) -o <%modelNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES) $(FMISUNDIALSFILES) <%dirExtra%> <%libsPos1%> <%libsPos2%> @BDYNAMIC@ $(LDFLAGS) | ||
| 1013 | <%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fileNamePrefix%>_FMU.libs ../binaries/$(FMIPLATFORM)/ | ||
| 1014 | endif | ||
| 1015 | <%if intLt(Flags.getConfigEnum(Flags.FMI_FILTER), 4) then | ||
| 1016 | '<%\t%>head -n20 Makefile > ../resources/$(FMIPLATFORM).summary' | ||
| 1017 | %> | ||
| 1018 | ifeq (@LIBTYPE_STATIC@,1) | ||
| 1019 | <%\t%>rm -f <%modelNamePrefix%>.a | ||
| 1020 | <%\t%>$(AR) -rsu <%modelNamePrefix%>.a $(OFILES) $(RUNTIMEFILES) $(FMISUNDIALSFILES) | ||
| 1021 | <%\t%>cp <%fileNamePrefix%>.a <%fileNamePrefix%>_FMU.libs ../binaries/$(FMIPLATFORM)/ | ||
| 1022 | endif | ||
| 1023 | <% if not Flags.isSet(Flags.GEN_DEBUG_SYMBOLS) then "\t$(MAKE) distclean" %> | ||
| 1024 | distclean: clean | ||
| 1025 | <%\t%>rm -f Makefile config.status config.log | ||
| 1026 | clean: | ||
| 1027 | <%\t%>rm -f <%fileNamePrefix%>.def <%fileNamePrefix%>.o <%fileNamePrefix%>.a <%fileNamePrefix%>$(DLLEXT) $(MAINOBJ) $(OFILES) $(RUNTIMEFILES) $(FMISUNDIALSFILES) | ||
| 1028 | >> | ||
| 1029 | end getPlatformString2; | ||
| 1030 | |||
| 1031 | 91 | template fmudeffile(SimCode simCode, String FMUVersion) | |
| 1032 | "Generates the def file of the fmu." | ||
| 1033 | ::= | ||
| 1034 | match simCode | ||
| 1035 | case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simulationSettingsOpt = sopt) then | ||
| 1036 | if isFMIVersion30(FMUVersion) then | ||
| 1037 | << | ||
| 1038 | EXPORTS | ||
| 1039 | ;*************************************************** | ||
| 1040 | ;Common Functions | ||
| 1041 | ;**************************************************** | ||
| 1042 | <%fileNamePrefix%>_fmi3GetVersion | ||
| 1043 | <%fileNamePrefix%>_fmi3SetDebugLogging | ||
| 1044 | <%fileNamePrefix%>_fmi3InstantiateModelExchange | ||
| 1045 | <%fileNamePrefix%>_fmi3InstantiateCoSimulation | ||
| 1046 | <%fileNamePrefix%>_fmi3InstantiateScheduledExecution | ||
| 1047 | <%fileNamePrefix%>_fmi3FreeInstance | ||
| 1048 | <%fileNamePrefix%>_fmi3EnterInitializationMode | ||
| 1049 | <%fileNamePrefix%>_fmi3ExitInitializationMode | ||
| 1050 | <%fileNamePrefix%>_fmi3EnterEventMode | ||
| 1051 | <%fileNamePrefix%>_fmi3Terminate | ||
| 1052 | <%fileNamePrefix%>_fmi3Reset | ||
| 1053 | <%fileNamePrefix%>_fmi3GetFloat32 | ||
| 1054 | <%fileNamePrefix%>_fmi3GetFloat64 | ||
| 1055 | <%fileNamePrefix%>_fmi3GetInt8 | ||
| 1056 | <%fileNamePrefix%>_fmi3GetUInt8 | ||
| 1057 | <%fileNamePrefix%>_fmi3GetInt16 | ||
| 1058 | <%fileNamePrefix%>_fmi3GetUInt16 | ||
| 1059 | <%fileNamePrefix%>_fmi3GetInt32 | ||
| 1060 | <%fileNamePrefix%>_fmi3GetUInt32 | ||
| 1061 | <%fileNamePrefix%>_fmi3GetInt64 | ||
| 1062 | <%fileNamePrefix%>_fmi3GetUInt64 | ||
| 1063 | <%fileNamePrefix%>_fmi3GetBoolean | ||
| 1064 | <%fileNamePrefix%>_fmi3GetString | ||
| 1065 | <%fileNamePrefix%>_fmi3GetBinary | ||
| 1066 | <%fileNamePrefix%>_fmi3GetClock | ||
| 1067 | <%fileNamePrefix%>_fmi3SetFloat32 | ||
| 1068 | <%fileNamePrefix%>_fmi3SetFloat64 | ||
| 1069 | <%fileNamePrefix%>_fmi3SetInt8 | ||
| 1070 | <%fileNamePrefix%>_fmi3SetUInt8 | ||
| 1071 | <%fileNamePrefix%>_fmi3SetInt16 | ||
| 1072 | <%fileNamePrefix%>_fmi3SetUInt16 | ||
| 1073 | <%fileNamePrefix%>_fmi3SetInt32 | ||
| 1074 | <%fileNamePrefix%>_fmi3SetUInt32 | ||
| 1075 | <%fileNamePrefix%>_fmi3SetInt64 | ||
| 1076 | <%fileNamePrefix%>_fmi3SetUInt64 | ||
| 1077 | <%fileNamePrefix%>_fmi3SetBoolean | ||
| 1078 | <%fileNamePrefix%>_fmi3SetString | ||
| 1079 | <%fileNamePrefix%>_fmi3SetBinary | ||
| 1080 | <%fileNamePrefix%>_fmi3SetClock | ||
| 1081 | <%fileNamePrefix%>_fmi3GetNumberOfVariableDependencies | ||
| 1082 | <%fileNamePrefix%>_fmi3GetVariableDependencies | ||
| 1083 | <%fileNamePrefix%>_fmi3GetFMUState | ||
| 1084 | <%fileNamePrefix%>_fmi3SetFMUState | ||
| 1085 | <%fileNamePrefix%>_fmi3FreeFMUState | ||
| 1086 | <%fileNamePrefix%>_fmi3SerializedFMUStateSize | ||
| 1087 | <%fileNamePrefix%>_fmi3SerializeFMUState | ||
| 1088 | <%fileNamePrefix%>_fmi3DeserializeFMUState | ||
| 1089 | <%fileNamePrefix%>_fmi3GetDirectionalDerivative | ||
| 1090 | <%fileNamePrefix%>_fmi3GetAdjointDerivative | ||
| 1091 | <%fileNamePrefix%>_fmi3EnterConfigurationMode | ||
| 1092 | <%fileNamePrefix%>_fmi3ExitConfigurationMode | ||
| 1093 | <%fileNamePrefix%>_fmi3GetIntervalDecimal | ||
| 1094 | <%fileNamePrefix%>_fmi3GetIntervalFraction | ||
| 1095 | <%fileNamePrefix%>_fmi3GetShiftDecimal | ||
| 1096 | <%fileNamePrefix%>_fmi3GetShiftFraction | ||
| 1097 | <%fileNamePrefix%>_fmi3SetIntervalDecimal | ||
| 1098 | <%fileNamePrefix%>_fmi3SetIntervalFraction | ||
| 1099 | <%fileNamePrefix%>_fmi3SetShiftDecimal | ||
| 1100 | <%fileNamePrefix%>_fmi3SetShiftFraction | ||
| 1101 | <%fileNamePrefix%>_fmi3EvaluateDiscreteStates | ||
| 1102 | <%fileNamePrefix%>_fmi3UpdateDiscreteStates | ||
| 1103 | ;*************************************************** | ||
| 1104 | ;Functions for Model Exchange | ||
| 1105 | ;**************************************************** | ||
| 1106 | <%fileNamePrefix%>_fmi3EnterContinuousTimeMode | ||
| 1107 | <%fileNamePrefix%>_fmi3CompletedIntegratorStep | ||
| 1108 | <%fileNamePrefix%>_fmi3SetTime | ||
| 1109 | <%fileNamePrefix%>_fmi3SetContinuousStates | ||
| 1110 | <%fileNamePrefix%>_fmi3GetContinuousStateDerivatives | ||
| 1111 | <%fileNamePrefix%>_fmi3GetEventIndicators | ||
| 1112 | <%fileNamePrefix%>_fmi3GetContinuousStates | ||
| 1113 | <%fileNamePrefix%>_fmi3GetNominalsOfContinuousStates | ||
| 1114 | <%fileNamePrefix%>_fmi3GetNumberOfEventIndicators | ||
| 1115 | <%fileNamePrefix%>_fmi3GetNumberOfContinuousStates | ||
| 1116 | ;*************************************************** | ||
| 1117 | ;Functions for Co-Simulation | ||
| 1118 | ;**************************************************** | ||
| 1119 | <%fileNamePrefix%>_fmi3EnterStepMode | ||
| 1120 | <%fileNamePrefix%>_fmi3GetOutputDerivatives | ||
| 1121 | <%fileNamePrefix%>_fmi3DoStep | ||
| 1122 | ;*************************************************** | ||
| 1123 | ;Functions for Scheduled Execution | ||
| 1124 | ;**************************************************** | ||
| 1125 | <%fileNamePrefix%>_fmi3ActivateModelPartition | ||
| 1126 | >> | ||
| 1127 | else if isFMIVersion20(FMUVersion) then | ||
| 1128 | << | ||
| 1129 | EXPORTS | ||
| 1130 | ;*************************************************** | ||
| 1131 | ;Common Functions | ||
| 1132 | ;**************************************************** | ||
| 1133 | <%fileNamePrefix%>_fmiGetTypesPlatform @1 | ||
| 1134 | <%fileNamePrefix%>_fmiGetVersion @2 | ||
| 1135 | <%fileNamePrefix%>_fmiSetDebugLogging @3 | ||
| 1136 | <%fileNamePrefix%>_fmiInstantiate @4 | ||
| 1137 | <%fileNamePrefix%>_fmiFreeInstance @5 | ||
| 1138 | <%fileNamePrefix%>_fmiSetupExperiment @6 | ||
| 1139 | <%fileNamePrefix%>_fmiEnterInitializationMode @7 | ||
| 1140 | <%fileNamePrefix%>_fmiExitInitializationMode @8 | ||
| 1141 | <%fileNamePrefix%>_fmiTerminate @9 | ||
| 1142 | <%fileNamePrefix%>_fmiReset @10 | ||
| 1143 | <%fileNamePrefix%>_fmiGetReal @11 | ||
| 1144 | <%fileNamePrefix%>_fmiGetInteger @12 | ||
| 1145 | <%fileNamePrefix%>_fmiGetBoolean @13 | ||
| 1146 | <%fileNamePrefix%>_fmiGetString @14 | ||
| 1147 | <%fileNamePrefix%>_fmiSetReal @15 | ||
| 1148 | <%fileNamePrefix%>_fmiSetInteger @16 | ||
| 1149 | <%fileNamePrefix%>_fmiSetBoolean @17 | ||
| 1150 | <%fileNamePrefix%>_fmiSetString @18 | ||
| 1151 | <%fileNamePrefix%>_fmiGetFMUstate @19 | ||
| 1152 | <%fileNamePrefix%>_fmiSetFMUstate @20 | ||
| 1153 | <%fileNamePrefix%>_fmiFreeFMUstate @21 | ||
| 1154 | <%fileNamePrefix%>_fmiSerializedFMUstateSize @22 | ||
| 1155 | <%fileNamePrefix%>_fmiSerializeFMUstate @23 | ||
| 1156 | <%fileNamePrefix%>_fmiDeSerializeFMUstate @24 | ||
| 1157 | <%fileNamePrefix%>_fmiGetDirectionalDerivative @25 | ||
| 1158 | ;*************************************************** | ||
| 1159 | ;Functions for FMI for Model Exchange | ||
| 1160 | ;**************************************************** | ||
| 1161 | <%fileNamePrefix%>_fmiEnterEventMode @26 | ||
| 1162 | <%fileNamePrefix%>_fmiNewDiscreteStates @27 | ||
| 1163 | <%fileNamePrefix%>_fmiEnterContinuousTimeMode @28 | ||
| 1164 | <%fileNamePrefix%>_fmiCompletedIntegratorStep @29 | ||
| 1165 | <%fileNamePrefix%>_fmiSetTime @30 | ||
| 1166 | <%fileNamePrefix%>_fmiSetContinuousStates @31 | ||
| 1167 | <%fileNamePrefix%>_fmiGetDerivatives @32 | ||
| 1168 | <%fileNamePrefix%>_fmiGetEventIndicators @33 | ||
| 1169 | <%fileNamePrefix%>_fmiGetContinuousStates @34 | ||
| 1170 | <%fileNamePrefix%>_fmiGetNominalsOfContinuousStates @35 | ||
| 1171 | ;*************************************************** | ||
| 1172 | ;Functions for FMI for Co-Simulation | ||
| 1173 | ;**************************************************** | ||
| 1174 | <%fileNamePrefix%>_fmiSetRealInputDerivatives @36 | ||
| 1175 | <%fileNamePrefix%>_fmiGetRealOutputDerivatives @37 | ||
| 1176 | <%fileNamePrefix%>_fmiDoStep @38 | ||
| 1177 | <%fileNamePrefix%>_fmiCancelStep @39 | ||
| 1178 | <%fileNamePrefix%>_fmiGetStatus @40 | ||
| 1179 | <%fileNamePrefix%>_fmiGetRealStatus @41 | ||
| 1180 | <%fileNamePrefix%>_fmiGetIntegerStatus @42 | ||
| 1181 | <%fileNamePrefix%>_fmiGetBooleanStatus @43 | ||
| 1182 | <%fileNamePrefix%>_fmiGetStringStatus @44 | ||
| 1183 | <% if Flags.isSet(Flags.FMU_EXPERIMENTAL) then | ||
| 1184 | << | ||
| 1185 | ;*************************************************** | ||
| 1186 | ; Experimetnal function for FMI for ModelExchange | ||
| 1187 | ;**************************************************** | ||
| 1188 | <%fileNamePrefix%>_fmiGetSpecificDerivatives @45 | ||
| 1189 | >> %> | ||
| 1190 | >> | ||
| 1191 | else | ||
| 1192 | << | ||
| 1193 | EXPORTS | ||
| 1194 | <%fileNamePrefix%>_fmiCompletedIntegratorStep @1 | ||
| 1195 | <%fileNamePrefix%>_fmiEventUpdate @2 | ||
| 1196 | <%fileNamePrefix%>_fmiFreeModelInstance @3 | ||
| 1197 | <%fileNamePrefix%>_fmiGetBoolean @4 | ||
| 1198 | <%fileNamePrefix%>_fmiGetContinuousStates @5 | ||
| 1199 | <%fileNamePrefix%>_fmiGetDerivatives @6 | ||
| 1200 | <%fileNamePrefix%>_fmiGetEventIndicators @7 | ||
| 1201 | <%fileNamePrefix%>_fmiGetInteger @8 | ||
| 1202 | <%fileNamePrefix%>_fmiGetModelTypesPlatform @9 | ||
| 1203 | <%fileNamePrefix%>_fmiGetNominalContinuousStates @10 | ||
| 1204 | <%fileNamePrefix%>_fmiGetReal @11 | ||
| 1205 | <%fileNamePrefix%>_fmiGetStateValueReferences @12 | ||
| 1206 | <%fileNamePrefix%>_fmiGetString @13 | ||
| 1207 | <%fileNamePrefix%>_fmiGetVersion @14 | ||
| 1208 | <%fileNamePrefix%>_fmiInitialize @15 | ||
| 1209 | <%fileNamePrefix%>_fmiInstantiateModel @16 | ||
| 1210 | <%fileNamePrefix%>_fmiSetBoolean @17 | ||
| 1211 | <%fileNamePrefix%>_fmiSetContinuousStates @18 | ||
| 1212 | <%fileNamePrefix%>_fmiSetDebugLogging @19 | ||
| 1213 | <%fileNamePrefix%>_fmiSetExternalFunction @20 | ||
| 1214 | <%fileNamePrefix%>_fmiSetInteger @21 | ||
| 1215 | <%fileNamePrefix%>_fmiSetReal @22 | ||
| 1216 | <%fileNamePrefix%>_fmiSetString @23 | ||
| 1217 | <%fileNamePrefix%>_fmiSetTime @24 | ||
| 1218 | <%fileNamePrefix%>_fmiTerminate @25 | ||
| 1219 | >> | ||
| 1220 | end fmudeffile; | ||
| 1221 | |||
| 1222 | annotation(__OpenModelica_Interface="codegen_fmu"); | ||
| 1223 | end CodegenFMUCommon; | ||
| 1224 | |||
| 1225 | // vim: filetype=susan sw=2 sts=2 | ||
| 1226 |