OMCompiler/Compiler/Template/CodegenFMU.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 CodegenFMU | ||
| 82 | |||
| 83 | import interface SimCodeTV; | ||
| 84 | import interface SimCodeBackendTV; | ||
| 85 | import CodegenUtil.*; | ||
| 86 | import CodegenUtilSimulation.*; | ||
| 87 | import CodegenC.*; //unqualified import, no need the CodegenC is optional when calling a template; or mandatory when the same named template exists in this package (name hiding) | ||
| 88 | import CodegenCFunctions.*; | ||
| 89 | import CodegenFMUCommon.*; | ||
| 90 | import CodegenFMUModelDescription.*; | ||
| 91 | import CodegenFMU1; | ||
| 92 | import CodegenFMU2; | ||
| 93 | import CodegenFMU3; | ||
| 94 | |||
| 95 | |||
| 96 | 82 | template translateModel(SimCode simCode, String FMUVersion, String FMUType, list<String> sourceFiles) | |
| 97 | "Generates C code and Makefile for compiling a FMU of a | ||
| 98 | Modelica model." | ||
| 99 | ::= | ||
| 100 | match simCode | ||
| 101 | case sc as SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then | ||
| 102 | let guid = getUUIDStr() | ||
| 103 | let target = simulationCodeTarget() | ||
| 104 | let fileNamePrefixHash = Util.hashFileNamePrefix(fileNamePrefix) | ||
| 105 | let fileNamePrefixTmpDir = '<%fileNamePrefixHash%>.fmutmp/sources/<%fileNamePrefix%>' | ||
| 106 | let()= textFile(simulationLiteralsFile(fileNamePrefix, literals), '<%fileNamePrefixTmpDir%>_literals.h') | ||
| 107 | let()= textFile(simulationFunctionsHeaderFile(fileNamePrefix, modelInfo.functions, recordDecls, sc.generic_loop_calls), '<%fileNamePrefixTmpDir%>_functions.h') | ||
| 108 | let()= textFile(simulationFunctionsFile(fileNamePrefix, modelInfo.functions, generic_loop_calls), '<%fileNamePrefixTmpDir%>_functions.c') | ||
| 109 | let()= textFile(externalFunctionIncludes(sc.externalFunctionIncludes), '<%fileNamePrefixTmpDir%>_includes.h') | ||
| 110 | let()= textFile(recordsFile(fileNamePrefix, recordDecls, true /*isSimulation*/), '<%fileNamePrefixTmpDir%>_records.c') | ||
| 111 | let()= textFile(simulationHeaderFile(simCode), '<%fileNamePrefixTmpDir%>_model.h') | ||
| 112 | |||
| 113 | let _ = generateSimulationFiles(simCode,guid,fileNamePrefixTmpDir,FMUVersion) | ||
| 114 | |||
| 115 | let()= textFile(simulationInitFunction(simCode,guid), '<%fileNamePrefixTmpDir%>_init_fmu.c') | ||
| 116 | let()= textFile(fmumodel_identifierHeaderFile(simCode,guid,FMUVersion,FMUType), '<%fileNamePrefixTmpDir%>_FMU.h') | ||
| 117 | let()= textFile(fmumodel_identifierFile(simCode,guid,FMUVersion,FMUType), '<%fileNamePrefixTmpDir%>_FMU.c') | ||
| 118 | |||
| 119 | /* Doesn't seem to work properly | ||
| 120 | let &fmuModelDescription = buffer "" | ||
| 121 | let &fmuModelDescription += redirectToFile('<%fileNamePrefix%>.fmutmp/modelDescription.xml') | ||
| 122 | let &fmuModelDescription += fmuModelDescriptionFile(simCode,guid,FMUVersion,FMUType) | ||
| 123 | let &fmuModelDescription += closeFile() | ||
| 124 | */ | ||
| 125 | |||
| 126 | let()= textFile(fmuModelDescriptionFile(simCode, guid, FMUVersion, FMUType, sourceFiles), '<%fileNamePrefixHash%>.fmutmp/modelDescription.xml') | ||
| 127 | |||
| 128 | // Generate optional terminalsAndIcons/terminalsAndIcons.xml (FMI 3.0 Terminals) | ||
| 129 | let _ = if stringEq(FMUVersion, "3.0") then CodegenFMU3.fmiTerminalsAndIconsFile(simCode, fileNamePrefixHash) | ||
| 130 | |||
| 131 | // Generate sources/buildDescription.xml (FMI 3.0 source-FMU build instructions) | ||
| 132 | let _ = if stringEq(FMUVersion, "3.0") then CodegenFMU3.fmiBuildDescriptionFile(simCode, sourceFiles, fileNamePrefixHash) | ||
| 133 | |||
| 134 | // Generate optional <fmiPrefix>_flags.json | ||
| 135 | let _ = match sc.fmiSimulationFlags | ||
| 136 | case SOME(fmiSimFlags as FMI_SIMULATION_FLAGS(__)) then | ||
| 137 | let() = textFile(fmuSimulationFlagsFile(fmiSimFlags), '<%fileNamePrefixHash%>.fmutmp/resources/<%fileNamePrefix%>_flags.json') | ||
| 138 | "" | ||
| 139 | else | ||
| 140 | "" | ||
| 141 | end match | ||
| 142 | |||
| 143 | let()= textFile(fmudeffile(simCode,FMUVersion), '<%fileNamePrefixHash%>.fmutmp/sources/<%fileNamePrefix%>.def') | ||
| 144 | let()= textFile(fmuSourceMakefile(simCode,FMUVersion,fileNamePrefixHash), '<%fileNamePrefix%>_FMU.makefile') | ||
| 145 | "" // Return empty result since result written to files directly | ||
| 146 | end translateModel; | ||
| 147 | |||
| 148 | /* public */ template generateSimulationFiles(SimCode simCode, String guid, String modelNamePrefix, String fmuVersion) | ||
| 149 | "Generates code in different C files for the simulation target. | ||
| 150 | To make the compilation faster we split the simulation files into several | ||
| 151 | used in Compiler/Template/CodegenFMU.tpl" | ||
| 152 | ::= | ||
| 153 | match simCode | ||
| 154 | case simCode as SIMCODE(__) then | ||
| 155 | // external objects | ||
| 156 | let()=tmpTickResetIndex(0, 0) | ||
| 157 | let()=tmpTickResetIndex(0, 1) | ||
| 158 | let()= textFileConvertLines(simulationFile_exo(simCode), '<%modelNamePrefix%>_01exo.c') | ||
| 159 | // non-linear systems | ||
| 160 | let()=tmpTickResetIndex(0, 0) | ||
| 161 | let()=tmpTickResetIndex(0, 1) | ||
| 162 | let()= textFileConvertLines(simulationFile_nls(simCode), '<%modelNamePrefix%>_02nls.c') | ||
| 163 | // linear systems | ||
| 164 | let()=tmpTickResetIndex(0, 0) | ||
| 165 | let()=tmpTickResetIndex(0, 1) | ||
| 166 | let()= textFileConvertLines(simulationFile_lsy(simCode), '<%modelNamePrefix%>_03lsy.c') | ||
| 167 | // state set | ||
| 168 | let()=tmpTickResetIndex(0, 0) | ||
| 169 | let()=tmpTickResetIndex(0, 1) | ||
| 170 | let()= textFileConvertLines(simulationFile_set(simCode), '<%modelNamePrefix%>_04set.c') | ||
| 171 | // events: sample, zero crossings, relations | ||
| 172 | let()=tmpTickResetIndex(0, 0) | ||
| 173 | let()=tmpTickResetIndex(0, 1) | ||
| 174 | let()= textFileConvertLines(simulationFile_evt(simCode), '<%modelNamePrefix%>_05evt.c') | ||
| 175 | // initialization | ||
| 176 | let()=tmpTickResetIndex(0, 0) | ||
| 177 | let()=tmpTickResetIndex(0, 1) | ||
| 178 | let()= textFileConvertLines(simulationFile_inz(simCode), '<%modelNamePrefix%>_06inz.c') | ||
| 179 | // delay | ||
| 180 | let()= textFileConvertLines(simulationFile_dly(simCode), '<%modelNamePrefix%>_07dly.c') | ||
| 181 | // update bound start values, update bound parameters | ||
| 182 | let()=tmpTickResetIndex(0, 0) | ||
| 183 | let()=tmpTickResetIndex(0, 1) | ||
| 184 | let()= textFileConvertLines(simulationFile_bnd(simCode), '<%modelNamePrefix%>_08bnd.c') | ||
| 185 | // algebraic | ||
| 186 | let()=tmpTickResetIndex(0, 0) | ||
| 187 | let()=tmpTickResetIndex(0, 1) | ||
| 188 | let()= textFileConvertLines(simulationFile_alg(simCode), '<%modelNamePrefix%>_09alg.c') | ||
| 189 | // asserts | ||
| 190 | let()=tmpTickResetIndex(0, 0) | ||
| 191 | let()=tmpTickResetIndex(0, 1) | ||
| 192 | let()= textFileConvertLines(simulationFile_asr(simCode), '<%modelNamePrefix%>_10asr.c') | ||
| 193 | // mixed systems | ||
| 194 | let()=tmpTickResetIndex(0, 0) | ||
| 195 | let()=tmpTickResetIndex(0, 1) | ||
| 196 | let &mixheader = buffer "" | ||
| 197 | let()= textFileConvertLines(simulationFile_mix(simCode,&mixheader), '<%modelNamePrefix%>_11mix.c') | ||
| 198 | let()= textFile(&mixheader, '<%modelNamePrefix%>_11mix.h') | ||
| 199 | // jacobians | ||
| 200 | let()=tmpTickResetIndex(0, 0) | ||
| 201 | let()=tmpTickResetIndex(0, 1) | ||
| 202 | let()= textFileConvertLines(simulationFile_jac(simCode), '<%modelNamePrefix%>_12jac.c') | ||
| 203 | let()= textFile(simulationFile_jac_header(simCode), '<%modelNamePrefix%>_12jac.h') | ||
| 204 | // optimization | ||
| 205 | let()=tmpTickResetIndex(0, 0) | ||
| 206 | let()=tmpTickResetIndex(0, 1) | ||
| 207 | let()= textFileConvertLines(simulationFile_opt(simCode), '<%modelNamePrefix%>_13opt.c') | ||
| 208 | let()= textFile(simulationFile_opt_header(simCode), '<%modelNamePrefix%>_13opt.h') | ||
| 209 | // linearization | ||
| 210 | let()=tmpTickResetIndex(0, 0) | ||
| 211 | let()=tmpTickResetIndex(0, 1) | ||
| 212 | let()= textFileConvertLines(simulationFile_lnz(simCode), '<%modelNamePrefix%>_14lnz.c') | ||
| 213 | // synchronous | ||
| 214 | let()=tmpTickResetIndex(0, 0) | ||
| 215 | let()=tmpTickResetIndex(0, 1) | ||
| 216 | let()= textFileConvertLines(simulationFile_syn(simCode), '<%modelNamePrefix%>_15syn.c') | ||
| 217 | // residuals | ||
| 218 | let()=tmpTickResetIndex(0, 0) | ||
| 219 | let()=tmpTickResetIndex(0, 1) | ||
| 220 | let()= textFileConvertLines(simulationFile_dae(simCode), '<%modelNamePrefix%>_16dae.c') | ||
| 221 | // inline solver | ||
| 222 | let()=tmpTickResetIndex(0, 0) | ||
| 223 | let()=tmpTickResetIndex(0, 1) | ||
| 224 | let()= textFileConvertLines(simulationFile_inl(simCode), '<%modelNamePrefix%>_17inl.c') | ||
| 225 | // main file | ||
| 226 | let()=tmpTickResetIndex(0, 0) | ||
| 227 | let()=tmpTickResetIndex(0, 1) | ||
| 228 | let()= textFileConvertLines(simulationFile_spd(simCode), '<%modelNamePrefix%>_18spd.c') | ||
| 229 | // update bound start values, update bound parameters | ||
| 230 | let()=tmpTickResetIndex(0, 0) | ||
| 231 | let()=tmpTickResetIndex(0, 1) | ||
| 232 | let()= textFileConvertLines(simulationFile(simCode,guid,fmuVersion), '<%modelNamePrefix%>.c') | ||
| 233 | |||
| 234 | "" | ||
| 235 | end match | ||
| 236 | end generateSimulationFiles; | ||
| 237 | |||
| 238 | ✗ | template VendorAnnotations(SimCode simCode) | |
| 239 | "Generates code for VendorAnnotations file for FMU target." | ||
| 240 | ::= | ||
| 241 | match simCode | ||
| 242 | case SIMCODE(__) then | ||
| 243 | << | ||
| 244 | <VendorAnnotations> | ||
| 245 | </VendorAnnotations> | ||
| 246 | >> | ||
| 247 | end VendorAnnotations; | ||
| 248 | |||
| 249 | |||
| 250 | 82 | template fmumodel_identifierHeaderFile(SimCode simCode, String guid, String FMUVersion, String FMUType) | |
| 251 | "Generates code for model defines." | ||
| 252 | ::= | ||
| 253 | match simCode | ||
| 254 | case SIMCODE(__) then | ||
| 255 | << | ||
| 256 | #ifndef <%modelNamePrefix(simCode)%>_FMU_H | ||
| 257 | #define <%modelNamePrefix(simCode)%>_FMU_H | ||
| 258 | |||
| 259 | #include "simulation_data.h" | ||
| 260 | |||
| 261 | // define class name and unique id | ||
| 262 | #define MODEL_IDENTIFIER <%modelNamePrefix(simCode)%> | ||
| 263 | #define MODEL_GUID "{<%guid%>}" | ||
| 264 | |||
| 265 | <%ModelDefineData(simCode, modelInfo)%> | ||
| 266 | |||
| 267 | #ifdef __cplusplus | ||
| 268 | extern "C" { | ||
| 269 | #endif | ||
| 270 | |||
| 271 | extern void <%symbolName(modelNamePrefix(simCode),"setupDataStruc")%>(DATA *data, threadData_t *threadData); | ||
| 272 | <%if isFMIVersion30(FMUVersion) then | ||
| 273 | << | ||
| 274 | #define fmu3_model_interface_setupDataStruc <%symbolName(modelNamePrefix(simCode),"setupDataStruc")%> | ||
| 275 | #include "fmi-export/fmu3_model_interface.h" | ||
| 276 | >> | ||
| 277 | else if isFMIVersion20(FMUVersion) then | ||
| 278 | << | ||
| 279 | #define fmu2_model_interface_setupDataStruc <%symbolName(modelNamePrefix(simCode),"setupDataStruc")%> | ||
| 280 | #include "fmi-export/fmu2_model_interface.h" | ||
| 281 | #include "fmi-export/fmu_read_flags.h" | ||
| 282 | >> | ||
| 283 | else | ||
| 284 | << | ||
| 285 | // fmu1_model_interface.h pulls in fmiModelFunctions.h (the FMI 1.0 types) and defines the | ||
| 286 | // ModelInstance struct used by the declarations below and by fmu1_model_interface.c.inc. | ||
| 287 | // The FMI 2.0 fmi2Functions.h header is not needed for FMI 1.0. The implementation | ||
| 288 | // (fmu1_model_interface.c.inc) is inlined further down, after the forward declarations | ||
| 289 | // that it calls (setStartValues, getReal, ...). See #15838. | ||
| 290 | #include "fmi-export/fmu1_model_interface.h" | ||
| 291 | #define fmu1_model_interface_setupDataStruc <%symbolName(modelNamePrefix(simCode),"setupDataStruc")%> | ||
| 292 | >> | ||
| 293 | %> | ||
| 294 | |||
| 295 | <%if isFMIVersion30(FMUVersion) then | ||
| 296 | << | ||
| 297 | // FMI 3.0 export. fmu3_model_interface.c is self-contained (its own model | ||
| 298 | // engine) and is built independently of the FMI 2.0 files. The generated | ||
| 299 | // per-base-type get/set helper functions below (getReal/setReal/...) are | ||
| 300 | // shared model code. FMI 3.0 requires globally unique value references, so the | ||
| 301 | // per-base-type value references are shifted by the offsets below to recover | ||
| 302 | // the per-type index used by the engine. fmi2Functions.h is included only for | ||
| 303 | // the FMI 2.0 scalar/utility types used by the engine and the generated helpers. | ||
| 304 | #define FMI2_FUNCTION_PREFIX <%modelNamePrefix(simCode)%>_ | ||
| 305 | #include "fmi2Functions.h" | ||
| 306 | #define FMI3_FUNCTION_PREFIX <%modelNamePrefix(simCode)%>_ | ||
| 307 | #include "fmi3Functions.h" | ||
| 308 | |||
| 309 | #define FMI3_REAL_VR_OFFSET 0 | ||
| 310 | #define FMI3_INTEGER_VR_OFFSET (NUMBER_OF_REALS) | ||
| 311 | #define FMI3_BOOLEAN_VR_OFFSET (NUMBER_OF_REALS + NUMBER_OF_INTEGERS) | ||
| 312 | #define FMI3_STRING_VR_OFFSET (NUMBER_OF_REALS + NUMBER_OF_INTEGERS + NUMBER_OF_BOOLEANS) | ||
| 313 | // external objects are exported as FMI 3.0 Binary, then the model clocks, after the string block | ||
| 314 | #define FMI3_BINARY_VR_OFFSET (NUMBER_OF_REALS + NUMBER_OF_INTEGERS + NUMBER_OF_BOOLEANS + NUMBER_OF_STRINGS) | ||
| 315 | #define FMI3_CLOCK_VR_OFFSET (NUMBER_OF_REALS + NUMBER_OF_INTEGERS + NUMBER_OF_BOOLEANS + NUMBER_OF_STRINGS + NUMBER_OF_EXTERNALOBJECTS) | ||
| 316 | #define FMI3_TIME_VR (NUMBER_OF_REALS + NUMBER_OF_INTEGERS + NUMBER_OF_BOOLEANS + NUMBER_OF_STRINGS + NUMBER_OF_EXTERNALOBJECTS + NUMBER_OF_CLOCKS) | ||
| 317 | #define FMI3_EVENT_INDICATOR_VR_START (FMI3_TIME_VR + 1) | ||
| 318 | <%SimCodeCodegenUtil.fmi3ArrayDefines(simCode)%> | ||
| 319 | >> | ||
| 320 | else if isFMIVersion20(FMUVersion) then | ||
| 321 | << | ||
| 322 | #define FMI2_FUNCTION_PREFIX <%modelNamePrefix(simCode)%>_ | ||
| 323 | #include "fmi2Functions.h" | ||
| 324 | #include "fmi-export/fmu2_model_interface.h" | ||
| 325 | #include "fmi-export/fmu_read_flags.h" | ||
| 326 | >> | ||
| 327 | %> | ||
| 328 | |||
| 329 | void setStartValues(ModelInstance *comp); | ||
| 330 | void setDefaultStartValues(ModelInstance *comp); | ||
| 331 | <%if boolOr(isFMIVersion20(FMUVersion), isFMIVersion30(FMUVersion)) then | ||
| 332 | << | ||
| 333 | void eventUpdate(ModelInstance* comp, fmi2EventInfo* eventInfo); | ||
| 334 | fmi2Real getReal(ModelInstance* comp, const fmi2ValueReference vr); | ||
| 335 | fmi2Status setReal(ModelInstance* comp, const fmi2ValueReference vr, const fmi2Real value); | ||
| 336 | fmi2Integer getInteger(ModelInstance* comp, const fmi2ValueReference vr); | ||
| 337 | fmi2Status setInteger(ModelInstance* comp, const fmi2ValueReference vr, const fmi2Integer value); | ||
| 338 | fmi2Boolean getBoolean(ModelInstance* comp, const fmi2ValueReference vr); | ||
| 339 | fmi2Status setBoolean(ModelInstance* comp, const fmi2ValueReference vr, const fmi2Boolean value); | ||
| 340 | fmi2String getString(ModelInstance* comp, const fmi2ValueReference vr); | ||
| 341 | fmi2Status setString(ModelInstance* comp, const fmi2ValueReference vr, fmi2String value); | ||
| 342 | fmi2Status setExternalFunction(ModelInstance* c, const fmi2ValueReference vr, const void* value); | ||
| 343 | fmi2ValueReference mapInputReference2InputNumber(const fmi2ValueReference vr); | ||
| 344 | fmi2ValueReference mapOutputReference2OutputNumber(const fmi2ValueReference vr); | ||
| 345 | fmi2ValueReference mapOutputReference2RealOutputDerivatives(const fmi2ValueReference vr); | ||
| 346 | fmi2ValueReference mapInitialUnknownsdependentIndex(const fmi2ValueReference vr); | ||
| 347 | fmi2ValueReference mapInitialUnknownsIndependentIndex(const fmi2ValueReference vr); | ||
| 348 | >> | ||
| 349 | else | ||
| 350 | << | ||
| 351 | void eventUpdate(ModelInstance* comp, fmiEventInfo* eventInfo); | ||
| 352 | fmiReal getReal(ModelInstance* comp, const fmiValueReference vr); | ||
| 353 | fmiStatus setReal(ModelInstance* comp, const fmiValueReference vr, const fmiReal value); | ||
| 354 | fmiInteger getInteger(ModelInstance* comp, const fmiValueReference vr); | ||
| 355 | fmiStatus setInteger(ModelInstance* comp, const fmiValueReference vr, const fmiInteger value); | ||
| 356 | fmiBoolean getBoolean(ModelInstance* comp, const fmiValueReference vr); | ||
| 357 | fmiStatus setBoolean(ModelInstance* comp, const fmiValueReference vr, const fmiBoolean value); | ||
| 358 | fmiString getString(ModelInstance* comp, const fmiValueReference vr); | ||
| 359 | fmiStatus setString(ModelInstance* comp, const fmiValueReference vr, fmiString value); | ||
| 360 | fmiStatus setExternalFunction(ModelInstance* c, const fmiValueReference vr, const void* value); | ||
| 361 | >> | ||
| 362 | %> | ||
| 363 | |||
| 364 | <%if isFMIVersion10(FMUVersion) then | ||
| 365 | << | ||
| 366 | // FMI 1.0 inlines the model interface implementation here, after the forward declarations | ||
| 367 | // above (setStartValues, setDefaultStartValues, getReal, ...) that it calls. See #15838. | ||
| 368 | #if !defined(OMC_RUST_SIMULATION_RUNTIME) | ||
| 369 | #include "fmi-export/fmu1_model_interface.c.inc" | ||
| 370 | #endif | ||
| 371 | >> | ||
| 372 | else "" | ||
| 373 | %> | ||
| 374 | |||
| 375 | #ifdef __cplusplus | ||
| 376 | } | ||
| 377 | #endif | ||
| 378 | |||
| 379 | #endif /* <%modelNamePrefix(simCode)%>_FMU_H */ | ||
| 380 | >> | ||
| 381 | end fmumodel_identifierHeaderFile; | ||
| 382 | |||
| 383 | 82 | template fmumodel_identifierFile(SimCode simCode, String guid, String FMUVersion, String FMUType) | |
| 384 | "Generates code for ModelDescription file for FMU target." | ||
| 385 | ::= | ||
| 386 | match simCode | ||
| 387 | case SIMCODE(__) then | ||
| 388 | << | ||
| 389 | #include "<%modelNamePrefix(simCode)%>_FMU.h" | ||
| 390 | |||
| 391 | // include fmu header files, typedefs and macros | ||
| 392 | #include <stdio.h> | ||
| 393 | #include <string.h> | ||
| 394 | #include <assert.h> | ||
| 395 | #include "openmodelica.h" | ||
| 396 | #include "openmodelica_func.h" | ||
| 397 | #include "util/omc_error.h" | ||
| 398 | #include "<%fileNamePrefix%>_functions.h" | ||
| 399 | |||
| 400 | #include "simulation/solver/events.h" | ||
| 401 | |||
| 402 | <%setDefaultStartValues(modelInfo)%> | ||
| 403 | <%setStartValues(modelInfo)%> | ||
| 404 | const size_t omc_fmu_threadDataSize = sizeof(threadData_t); | ||
| 405 | <%if isFMIVersion30(FMUVersion) then | ||
| 406 | << | ||
| 407 | const int omc_fmu3_nArrays = FMI3_NUMBER_OF_ARRAYS; | ||
| 408 | #if FMI3_NUMBER_OF_ARRAYS > 0 | ||
| 409 | const unsigned int omc_fmu3_arrayVrs[] = FMI3_ARRAY_VRS; | ||
| 410 | const unsigned int omc_fmu3_arrayLengths[] = FMI3_ARRAY_LENGTHS; | ||
| 411 | #else | ||
| 412 | const unsigned int omc_fmu3_arrayVrs[1] = {0}; | ||
| 413 | const unsigned int omc_fmu3_arrayLengths[1] = {0}; | ||
| 414 | #endif | ||
| 415 | >> | ||
| 416 | else | ||
| 417 | << | ||
| 418 | const int omc_fmu3_nArrays = 0; | ||
| 419 | const unsigned int omc_fmu3_arrayVrs[1] = {0}; | ||
| 420 | const unsigned int omc_fmu3_arrayLengths[1] = {0}; | ||
| 421 | >> | ||
| 422 | %> | ||
| 423 | void omc_fmu_setupDataStruc(DATA *data, threadData_t *threadData) { | ||
| 424 | <%symbolName(modelNamePrefix(simCode),"setupDataStruc")%>(data, threadData); | ||
| 425 | } | ||
| 426 | #if defined(OMC_RUST_SIMULATION_RUNTIME) | ||
| 427 | #include "fmi-export/fmu<%if isFMIVersion30(FMUVersion) then "3" else if isFMIVersion20(FMUVersion) then "2" else "1"%>_rust_interface.c.inc" | ||
| 428 | #endif | ||
| 429 | |||
| 430 | // implementation of the Model Exchange functions | ||
| 431 | <%if boolOr(isFMIVersion20(FMUVersion), isFMIVersion30(FMUVersion)) then | ||
| 432 | << | ||
| 433 | <%eventUpdateFunction2(simCode)%> | ||
| 434 | <%getRealFunction2(simCode, modelInfo)%> | ||
| 435 | <%setRealFunction2(simCode, modelInfo)%> | ||
| 436 | <%getIntegerFunction2(simCode, modelInfo)%> | ||
| 437 | <%setIntegerFunction2(simCode, modelInfo)%> | ||
| 438 | <%getBooleanFunction2(simCode, modelInfo)%> | ||
| 439 | <%setBooleanFunction2(simCode, modelInfo)%> | ||
| 440 | <%getStringFunction2(simCode, modelInfo)%> | ||
| 441 | <%setStringFunction2(simCode, modelInfo)%> | ||
| 442 | <%setExternalFunction2(modelInfo)%> | ||
| 443 | <%mapInputAndOutputs(simCode)%> | ||
| 444 | <%mapRealOutputDerivatives(simCode, FMUType)%> | ||
| 445 | <%mapInitialUnknownsdependentCrefs(simCode)%> | ||
| 446 | <%mapInitialUnknownsIndependentCrefs(simCode)%> | ||
| 447 | >> | ||
| 448 | else | ||
| 449 | << | ||
| 450 | <%eventUpdateFunction(simCode)%> | ||
| 451 | <%getRealFunction(simCode, modelInfo)%> | ||
| 452 | <%setRealFunction(simCode, modelInfo)%> | ||
| 453 | <%getIntegerFunction(simCode, modelInfo)%> | ||
| 454 | <%setIntegerFunction(simCode, modelInfo)%> | ||
| 455 | <%getBooleanFunction(simCode, modelInfo)%> | ||
| 456 | <%setBooleanFunction(simCode, modelInfo)%> | ||
| 457 | <%getStringFunction(simCode, modelInfo)%> | ||
| 458 | <%setStringFunction(simCode, modelInfo)%> | ||
| 459 | <%setExternalFunction(modelInfo)%> | ||
| 460 | >> | ||
| 461 | %> | ||
| 462 | |||
| 463 | >> | ||
| 464 | end fmumodel_identifierFile; | ||
| 465 | |||
| 466 | 82 | template ModelDefineData(SimCode simCode, ModelInfo modelInfo) | |
| 467 | "Generates global data in simulation file." | ||
| 468 | ::= | ||
| 469 | match modelInfo | ||
| 470 | case MODELINFO(varInfo=VARINFO(__), vars=SIMVARS(stateVars = listStates), nClocks=numberOfClocks) then | ||
| 471 | // Per-scalar sizes (sum getNumElems): equals the per-variable varInfo counts for | ||
| 472 | // scalarized variables, but counts each element for non-scalarized arrays. | ||
| 473 | // (numScalarElems is inlined because a Susan `let` binds a Text, not an Integer.) | ||
| 474 | let numberOfReals = intAdd(intMul(SimCodeCodegenUtil.numScalarElems(vars.stateVars),2),intAdd(SimCodeCodegenUtil.numScalarElems(vars.discreteAlgVars), intAdd(SimCodeCodegenUtil.numScalarElems(vars.algVars),intAdd(SimCodeCodegenUtil.numScalarElems(vars.paramVars),SimCodeCodegenUtil.numScalarElems(vars.aliasVars))))) | ||
| 475 | let numberOfIntegers = intAdd(SimCodeCodegenUtil.numScalarElems(vars.intAlgVars),intAdd(SimCodeCodegenUtil.numScalarElems(vars.intParamVars),SimCodeCodegenUtil.numScalarElems(vars.intAliasVars))) | ||
| 476 | let numberOfStrings = intAdd(SimCodeCodegenUtil.numScalarElems(vars.stringAlgVars),intAdd(SimCodeCodegenUtil.numScalarElems(vars.stringParamVars),SimCodeCodegenUtil.numScalarElems(vars.stringAliasVars))) | ||
| 477 | let numberOfBooleans = intAdd(SimCodeCodegenUtil.numScalarElems(vars.boolAlgVars),intAdd(SimCodeCodegenUtil.numScalarElems(vars.boolParamVars),SimCodeCodegenUtil.numScalarElems(vars.boolAliasVars))) | ||
| 478 | let numberOfRealInputs = varInfo.numRealInputVars | ||
| 479 | << | ||
| 480 | // define model size | ||
| 481 | #define NUMBER_OF_STATES <%if intEq(SimCodeCodegenUtil.numScalarElems(vars.stateVars),1) then statesnumwithDummy(listStates) else SimCodeCodegenUtil.numScalarElems(vars.stateVars)%> | ||
| 482 | #define NUMBER_OF_EVENT_INDICATORS <%varInfo.numZeroCrossings%> | ||
| 483 | #define NUMBER_OF_REALS <%numberOfReals%> | ||
| 484 | #define NUMBER_OF_REAL_INPUTS <%numberOfRealInputs%> | ||
| 485 | #define NUMBER_OF_INTEGERS <%numberOfIntegers%> | ||
| 486 | #define NUMBER_OF_STRINGS <%numberOfStrings%> | ||
| 487 | #define NUMBER_OF_BOOLEANS <%numberOfBooleans%> | ||
| 488 | #define NUMBER_OF_EXTERNALOBJECTS <%listLength(vars.extObjVars)%> | ||
| 489 | #define NUMBER_OF_CLOCKS <%numberOfClocks%> | ||
| 490 | #define NUMBER_OF_EXTERNALFUNCTIONS <%countDynamicExternalFunctions(functions)%> | ||
| 491 | |||
| 492 | // define initial state vector as vector of value references (arrays expanded to | ||
| 493 | // their scalar element value references) | ||
| 494 | #define STATES { <%vars.stateVars |> simvar as SIMVAR(__) => if stringEq(CodegenUtil.crefStr(name),"$dummy") then '' else SimCodeCodegenUtil.getFMIScalarVRs(simvar, simCode) ;separator=", "%> } | ||
| 495 | #define STATESDERIVATIVES { <%vars.derivativeVars |> simvar as SIMVAR(__) => if stringEq(CodegenUtil.crefStr(name),"der($dummy)") then '' else SimCodeCodegenUtil.getFMIScalarVRs(simvar, simCode) ;separator=", "%> } | ||
| 496 | |||
| 497 | <%System.tmpTickReset(0)%> | ||
| 498 | <%(functions |> fn => defineExternalFunction(fn) ; separator="\n")%> | ||
| 499 | >> | ||
| 500 | end ModelDefineData; | ||
| 501 | |||
| 502 | ✗ | template dervativeNameCStyle(ComponentRef cr) | |
| 503 | "Generates the name of a derivative in c style, replaces ( with _" | ||
| 504 | ::= | ||
| 505 | match cr | ||
| 506 | case CREF_QUAL(ident = "$DER") then 'der_<%CodegenUtil.crefStr(componentRef)%>_' | ||
| 507 | end dervativeNameCStyle; | ||
| 508 | |||
| 509 | ✗ | template defineExternalFunction(SimCodeFunction.Function fn) | |
| 510 | "Generates external function definitions." | ||
| 511 | ::= | ||
| 512 | match fn | ||
| 513 | case EXTERNAL_FUNCTION(dynamicLoad=true) then | ||
| 514 | let fname = extFunctionName(extName, language) | ||
| 515 | << | ||
| 516 | #define $P<%fname%> <%System.tmpTick()%> | ||
| 517 | >> | ||
| 518 | end defineExternalFunction; | ||
| 519 | |||
| 520 | |||
| 521 | 82 | template setDefaultStartValues(ModelInfo modelInfo) | |
| 522 | "Generates code in c file for function setStartValues() which will set start values for all variables." | ||
| 523 | ::= | ||
| 524 | match modelInfo | ||
| 525 | case MODELINFO(varInfo=VARINFO(numStateVars=numStateVars, numAlgVars= numAlgVars),vars=SIMVARS(__)) then | ||
| 526 | << | ||
| 527 | // Set values for all variables that define a start value | ||
| 528 | OMC_DISABLE_OPT | ||
| 529 | void omc_fmu_setDefaultStartValues(DATA *fmuData) { | ||
| 530 | <%vars.stateVars |> var => initValsDefault(var,"realVars") ;separator="\n"%> | ||
| 531 | <%vars.derivativeVars |> var => initValsDefault(var,"realVars") ;separator="\n"%> | ||
| 532 | <%vars.algVars |> var => initValsDefault(var,"realVars") ;separator="\n"%> | ||
| 533 | <%vars.discreteAlgVars |> var => initValsDefault(var, "realVars") ;separator="\n"%> | ||
| 534 | <%vars.intAlgVars |> var => initValsDefault(var,"integerVars") ;separator="\n"%> | ||
| 535 | <%vars.boolAlgVars |> var => initValsDefault(var,"booleanVars") ;separator="\n"%> | ||
| 536 | <%vars.stringAlgVars |> var => initValsDefault(var,"stringVars") ;separator="\n"%> | ||
| 537 | <%vars.paramVars |> var => initParamsDefault(var,"realParameter") ;separator="\n"%> | ||
| 538 | <%vars.intParamVars |> var => initParamsDefault(var,"integerParameter") ;separator="\n"%> | ||
| 539 | <%vars.boolParamVars |> var => initParamsDefault(var,"booleanParameter") ;separator="\n"%> | ||
| 540 | <%vars.stringParamVars |> var => initParamsDefault(var,"stringParameter") ;separator="\n"%> | ||
| 541 | } | ||
| 542 | |||
| 543 | void setDefaultStartValues(ModelInstance *comp) { | ||
| 544 | omc_fmu_setDefaultStartValues(comp->fmuData); | ||
| 545 | } | ||
| 546 | >> | ||
| 547 | end setDefaultStartValues; | ||
| 548 | |||
| 549 | 82 | template setStartValues(ModelInfo modelInfo) | |
| 550 | "Generates code in c file for function setStartValues() which will set start values for all variables." | ||
| 551 | ::= | ||
| 552 | match modelInfo | ||
| 553 | case MODELINFO(varInfo=VARINFO(numStateVars=numStateVars, numAlgVars= numAlgVars),vars=SIMVARS(__)) then | ||
| 554 | << | ||
| 555 | // Set values for all variables that define a start value | ||
| 556 | OMC_DISABLE_OPT | ||
| 557 | void setStartValues(ModelInstance *comp) { | ||
| 558 | <%vars.stateVars |> var => initVals(var,"realVars") ;separator="\n"%> | ||
| 559 | <%vars.derivativeVars |> var => initVals(var,"realVars") ;separator="\n"%> | ||
| 560 | <%vars.algVars |> var => initVals(var,"realVars") ;separator="\n"%> | ||
| 561 | <%vars.discreteAlgVars |> var => initVals(var, "realVars") ;separator="\n"%> | ||
| 562 | <%vars.intAlgVars |> var => initVals(var,"integerVars") ;separator="\n"%> | ||
| 563 | <%vars.boolAlgVars |> var => initVals(var,"booleanVars") ;separator="\n"%> | ||
| 564 | <%vars.stringAlgVars |> var => initVals(var,"stringVars") ;separator="\n"%> | ||
| 565 | <%vars.paramVars |> var => initParams(var,"realParameter") ;separator="\n"%> | ||
| 566 | <%vars.intParamVars |> var => initParams(var,"integerParameter") ;separator="\n"%> | ||
| 567 | <%vars.boolParamVars |> var => initParams(var,"booleanParameter") ;separator="\n"%> | ||
| 568 | <%vars.stringParamVars |> var => initParams(var,"stringParameter") ;separator="\n"%> | ||
| 569 | } | ||
| 570 | |||
| 571 | >> | ||
| 572 | end setStartValues; | ||
| 573 | |||
| 574 | ✗ | template initializeFunction(list<SimEqSystem> allEquations) | |
| 575 | "Generates initialize function for c file." | ||
| 576 | ::= | ||
| 577 | let &sub = buffer "" | ||
| 578 | let &varDecls = buffer "" /*BUFD*/ | ||
| 579 | let &varFrees = buffer "" | ||
| 580 | let eqPart = ""/* (allEquations |> eq as SES_SIMPLE_ASSIGN(__) => | ||
| 581 | equation_(eq, contextOther, &varDecls, &varFrees) | ||
| 582 | ;separator="\n") */ | ||
| 583 | << | ||
| 584 | // Used to set the first time event, if any. | ||
| 585 | void initialize(ModelInstance* comp, fmiEventInfo* eventInfo) { | ||
| 586 | |||
| 587 | <%varDecls%> | ||
| 588 | |||
| 589 | <%eqPart%> | ||
| 590 | <%allEquations |> SES_SIMPLE_ASSIGN(__) => | ||
| 591 | 'if (sim_verbose) { printf("Setting variable start value: %s(start=%f)\n", "<%escapeModelicaStringToCString(crefStrNoUnderscore(cref))%>", <%cref(cref, &sub)%>); }' | ||
| 592 | ;separator="\n"%> | ||
| 593 | |||
| 594 | } | ||
| 595 | >> | ||
| 596 | end initializeFunction; | ||
| 597 | |||
| 598 | |||
| 599 | 4271 | template initVals(SimVar var, String arrayName) ::= | |
| 600 | match var | ||
| 601 | case var as SIMVAR(type_=type_) then | ||
| 602 | if stringEq(CodegenUtil.crefStr(name),"$dummy") then | ||
| 603 | '' | ||
| 604 | else if stringEq(CodegenUtil.crefStr(name),"der($dummy)") then | ||
| 605 | '' | ||
| 606 | else | ||
| 607 | // For a non-scalarized array the start attribute is a single | ||
| 608 | // (broadcast) scalar element, so it is set like a scalar. | ||
| 609 | << | ||
| 610 | put_<%expTypeShort(type_)%>_element(comp->fmuData->localData[0]-><%arrayName%>[<%var.index%>], 0, &comp->fmuData->modelData-><%arrayName%>Data[<%var.index%>].attribute.start); | ||
| 611 | >> | ||
| 612 | end initVals; | ||
| 613 | |||
| 614 | 2563 | template initParams(SimVar var, String arrayName) ::= | |
| 615 | match var | ||
| 616 | case SIMVAR(index=index, type_=type_) then | ||
| 617 | << | ||
| 618 | put_<%expTypeShort(type_)%>_element(comp->fmuData->simulationInfo-><%arrayName%>[<%index%>], 0, &comp->fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start); | ||
| 619 | >> | ||
| 620 | end initParams; | ||
| 621 | |||
| 622 | 4081 | template initValsDefault(SimVar var, String arrayName) ::= | |
| 623 | match var | ||
| 624 | // a non-scalarized real array's start attribute is a single broadcast scalar. | ||
| 625 | case SIMVAR(index=index, type_=T_REAL()) | ||
| 626 | case SIMVAR(index=index, type_=T_ARRAY(ty=T_REAL())) then | ||
| 627 | << | ||
| 628 | put_real_element(<%initValDefault(var)%>, 0, &fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start); | ||
| 629 | >> | ||
| 630 | case SIMVAR(index=index, type_=T_STRING()) | ||
| 631 | case SIMVAR(index=index, type_=T_ARRAY(ty=T_STRING())) then | ||
| 632 | << | ||
| 633 | omc_string_move((modelica_string*) fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start.data, <%initValDefault(var)%>); | ||
| 634 | >> | ||
| 635 | case SIMVAR(index=index, type_=type_) then | ||
| 636 | << | ||
| 637 | put_<%expTypeShort(type_)%>_element(<%initValDefault(var)%>, 0, &fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start); | ||
| 638 | >> | ||
| 639 | end initValsDefault; | ||
| 640 | |||
| 641 | 2078 | template initParamsDefault(SimVar var, String arrayName) ::= | |
| 642 | match var | ||
| 643 | case SIMVAR(index=index, type_=T_REAL()) then | ||
| 644 | << | ||
| 645 | put_real_element(<%initValDefault(var)%>, 0, &fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start); | ||
| 646 | >> | ||
| 647 | case SIMVAR(index=index, type_=T_STRING()) then | ||
| 648 | << | ||
| 649 | omc_string_move((modelica_string*) fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start.data, <%initValDefault(var)%>); | ||
| 650 | >> | ||
| 651 | case SIMVAR(index=index, type_=type_) then | ||
| 652 | << | ||
| 653 | put_<%expTypeShort(type_)%>_element(<%initValDefault(var)%>, 0, &fmuData->modelData-><%arrayName%>Data[<%index%>].attribute.start); | ||
| 654 | >> | ||
| 655 | end initParamsDefault; | ||
| 656 | |||
| 657 | 6834 | template initValDefault(SimVar var) ::= | |
| 658 | match var | ||
| 659 | case var as SIMVAR(__) then | ||
| 660 | match var.initialValue | ||
| 661 | case SOME(v as SCONST(__)) then 'omc_string_new(<%initVal(v)%>)' | ||
| 662 | case SOME(v as ICONST(__)) | ||
| 663 | case SOME(v as RCONST(__)) | ||
| 664 | case SOME(v as BCONST(__)) | ||
| 665 | case SOME(v as ENUM_LITERAL(__)) | ||
| 666 | // non-scalarized array start (broadcast scalar) given as an array | ||
| 667 | // constructor / reduction: | ||
| 668 | case SOME(v as ARRAY(__)) | ||
| 669 | case SOME(v as REDUCTION(__)) then initVal(v) | ||
| 670 | else | ||
| 671 | match var.type_ | ||
| 672 | case T_INTEGER(__) | ||
| 673 | case T_REAL(__) | ||
| 674 | case T_ENUMERATION(__) | ||
| 675 | case T_BOOL(__) | ||
| 676 | case T_ARRAY(ty=T_INTEGER()) | ||
| 677 | case T_ARRAY(ty=T_REAL()) | ||
| 678 | case T_ARRAY(ty=T_ENUMERATION()) | ||
| 679 | case T_ARRAY(ty=T_BOOL()) then '0' | ||
| 680 | case T_STRING(__) | ||
| 681 | case T_ARRAY(ty=T_STRING()) then 'omc_string_new("")' | ||
| 682 | else error(sourceInfo(), 'Unknown type for initValDefault: <%unparseType(var.type_)%>') | ||
| 683 | end initValDefault; | ||
| 684 | |||
| 685 | 4008 | template initVal(Exp initialValue) | |
| 686 | ::= | ||
| 687 | match initialValue | ||
| 688 | case ICONST(__) then integer | ||
| 689 | case RCONST(__) then real | ||
| 690 | case SCONST(__) then '"<%Util.escapeModelicaStringToXmlString(string)%>"' | ||
| 691 | case BCONST(__) then if bool then "1" else "0" | ||
| 692 | case ENUM_LITERAL(__) then '<%index%>' | ||
| 693 | // non-scalarized array start (broadcast scalar): extract the element value. | ||
| 694 | case ARRAY(array = first :: _) then initVal(first) | ||
| 695 | case REDUCTION(expr = first) then initVal(first) | ||
| 696 | else error(sourceInfo(), 'initial value of unknown type: <%printExpStr(initialValue)%>') | ||
| 697 | end initVal; | ||
| 698 | |||
| 699 | 2 | template eventUpdateFunction(SimCode simCode) | |
| 700 | "Generates event update function for c file." | ||
| 701 | ::= | ||
| 702 | match simCode | ||
| 703 | case SIMCODE(__) then | ||
| 704 | << | ||
| 705 | // Used to set the next time event, if any. | ||
| 706 | void eventUpdate(ModelInstance* comp, fmiEventInfo* eventInfo) { | ||
| 707 | } | ||
| 708 | |||
| 709 | >> | ||
| 710 | end eventUpdateFunction; | ||
| 711 | |||
| 712 | 2 | template getRealFunction(SimCode simCode, ModelInfo modelInfo) | |
| 713 | "Generates getReal function for c file." | ||
| 714 | ::= | ||
| 715 | match modelInfo | ||
| 716 | case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numStateVars=numStateVars, numAlgVars= numAlgVars)) then | ||
| 717 | << | ||
| 718 | fmiReal getReal(ModelInstance* comp, const fmiValueReference vr) { | ||
| 719 | switch (vr) { | ||
| 720 | <%vars.stateVars |> var => SwitchVars(simCode, var, "realVars") ;separator="\n"%> | ||
| 721 | <%vars.derivativeVars |> var => SwitchVars(simCode, var, "realVars") ;separator="\n"%> | ||
| 722 | <%vars.algVars |> var => SwitchVars(simCode, var, "realVars") ;separator="\n"%> | ||
| 723 | <%vars.discreteAlgVars |> var => SwitchVars(simCode, var, "realVars") ;separator="\n"%> | ||
| 724 | <%vars.paramVars |> var => SwitchParameters(simCode, var, "realParameter") ;separator="\n"%> | ||
| 725 | <%vars.aliasVars |> var => SwitchAliasVars(simCode, var, "Real","-") ;separator="\n"%> | ||
| 726 | default: | ||
| 727 | return 0; | ||
| 728 | } | ||
| 729 | } | ||
| 730 | |||
| 731 | >> | ||
| 732 | end getRealFunction; | ||
| 733 | |||
| 734 | 2 | template setRealFunction(SimCode simCode, ModelInfo modelInfo) | |
| 735 | "Generates setReal function for c file." | ||
| 736 | ::= | ||
| 737 | match modelInfo | ||
| 738 | case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numStateVars=numStateVars, numAlgVars= numAlgVars)) then | ||
| 739 | << | ||
| 740 | fmiStatus setReal(ModelInstance* comp, const fmiValueReference vr, const fmiReal value) { | ||
| 741 | switch (vr) { | ||
| 742 | <%vars.stateVars |> var => SwitchVarsSet(simCode, var, "realVars") ;separator="\n"%> | ||
| 743 | <%vars.derivativeVars |> var => SwitchVarsSet(simCode, var, "realVars") ;separator="\n"%> | ||
| 744 | <%vars.algVars |> var => SwitchVarsSet(simCode, var, "realVars") ;separator="\n"%> | ||
| 745 | <%vars.discreteAlgVars |> var => SwitchVarsSet(simCode, var, "realVars") ;separator="\n"%> | ||
| 746 | <%vars.paramVars |> var => SwitchParametersSet(simCode, var, "realParameter") ;separator="\n"%> | ||
| 747 | <%vars.aliasVars |> var => SwitchAliasVarsSet(simCode, var, "Real", "-") ;separator="\n"%> | ||
| 748 | default: | ||
| 749 | return fmiError; | ||
| 750 | } | ||
| 751 | return fmiOK; | ||
| 752 | } | ||
| 753 | |||
| 754 | >> | ||
| 755 | end setRealFunction; | ||
| 756 | |||
| 757 | 2 | template getIntegerFunction(SimCode simCode, ModelInfo modelInfo) | |
| 758 | "Generates getInteger function for c file." | ||
| 759 | ::= | ||
| 760 | match modelInfo | ||
| 761 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 762 | << | ||
| 763 | fmiInteger getInteger(ModelInstance* comp, const fmiValueReference vr) { | ||
| 764 | switch (vr) { | ||
| 765 | <%vars.intAlgVars |> var => SwitchVars(simCode, var, "integerVars") ;separator="\n"%> | ||
| 766 | <%vars.intParamVars |> var => SwitchParameters(simCode, var, "integerParameter") ;separator="\n"%> | ||
| 767 | <%vars.intAliasVars |> var => SwitchAliasVars(simCode, var, "Integer", "-") ;separator="\n"%> | ||
| 768 | default: | ||
| 769 | return 0; | ||
| 770 | } | ||
| 771 | } | ||
| 772 | >> | ||
| 773 | end getIntegerFunction; | ||
| 774 | |||
| 775 | 2 | template setIntegerFunction(SimCode simCode, ModelInfo modelInfo) | |
| 776 | "Generates setInteger function for c file." | ||
| 777 | ::= | ||
| 778 | match modelInfo | ||
| 779 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 780 | << | ||
| 781 | fmiStatus setInteger(ModelInstance* comp, const fmiValueReference vr, const fmiInteger value) { | ||
| 782 | switch (vr) { | ||
| 783 | <%vars.intAlgVars |> var => SwitchVarsSet(simCode, var, "integerVars") ;separator="\n"%> | ||
| 784 | <%vars.intParamVars |> var => SwitchParametersSet(simCode, var, "integerParameter") ;separator="\n"%> | ||
| 785 | <%vars.intAliasVars |> var => SwitchAliasVarsSet(simCode, var, "Integer", "-") ;separator="\n"%> | ||
| 786 | default: | ||
| 787 | return fmiError; | ||
| 788 | } | ||
| 789 | return fmiOK; | ||
| 790 | } | ||
| 791 | >> | ||
| 792 | end setIntegerFunction; | ||
| 793 | |||
| 794 | 2 | template getBooleanFunction(SimCode simCode, ModelInfo modelInfo) | |
| 795 | "Generates getBoolean function for c file." | ||
| 796 | ::= | ||
| 797 | match modelInfo | ||
| 798 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 799 | << | ||
| 800 | fmiBoolean getBoolean(ModelInstance* comp, const fmiValueReference vr) { | ||
| 801 | switch (vr) { | ||
| 802 | <%vars.boolAlgVars |> var => SwitchVars(simCode, var, "booleanVars") ;separator="\n"%> | ||
| 803 | <%vars.boolParamVars |> var => SwitchParameters(simCode, var, "booleanParameter") ;separator="\n"%> | ||
| 804 | <%vars.boolAliasVars |> var => SwitchAliasVars(simCode, var, "Boolean", "!") ;separator="\n"%> | ||
| 805 | default: | ||
| 806 | return fmiFalse; | ||
| 807 | } | ||
| 808 | } | ||
| 809 | |||
| 810 | >> | ||
| 811 | end getBooleanFunction; | ||
| 812 | |||
| 813 | 2 | template setBooleanFunction(SimCode simCode, ModelInfo modelInfo) | |
| 814 | "Generates setBoolean function for c file." | ||
| 815 | ::= | ||
| 816 | match modelInfo | ||
| 817 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 818 | << | ||
| 819 | fmiStatus setBoolean(ModelInstance* comp, const fmiValueReference vr, const fmiBoolean value) { | ||
| 820 | switch (vr) { | ||
| 821 | <%vars.boolAlgVars |> var => SwitchVarsSet(simCode, var, "booleanVars") ;separator="\n"%> | ||
| 822 | <%vars.boolParamVars |> var => SwitchParametersSet(simCode, var, "booleanParameter") ;separator="\n"%> | ||
| 823 | <%vars.boolAliasVars |> var => SwitchAliasVarsSet(simCode, var, "Boolean", "!") ;separator="\n"%> | ||
| 824 | default: | ||
| 825 | return fmiError; | ||
| 826 | } | ||
| 827 | return fmiOK; | ||
| 828 | } | ||
| 829 | |||
| 830 | >> | ||
| 831 | end setBooleanFunction; | ||
| 832 | |||
| 833 | 2 | template getStringFunction(SimCode simCode, ModelInfo modelInfo) | |
| 834 | "Generates getString function for c file." | ||
| 835 | ::= | ||
| 836 | match modelInfo | ||
| 837 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 838 | << | ||
| 839 | fmiString getString(ModelInstance* comp, const fmiValueReference vr) { | ||
| 840 | switch (vr) { | ||
| 841 | <%vars.stringAlgVars |> var => SwitchVars(simCode, var, "stringVars") ;separator="\n"%> | ||
| 842 | <%vars.stringParamVars |> var => SwitchParameters(simCode, var, "stringParameter") ;separator="\n"%> | ||
| 843 | <%vars.stringAliasVars |> var => SwitchAliasVars(simCode, var, "String", "") ;separator="\n"%> | ||
| 844 | default: | ||
| 845 | return ""; | ||
| 846 | } | ||
| 847 | } | ||
| 848 | |||
| 849 | >> | ||
| 850 | end getStringFunction; | ||
| 851 | |||
| 852 | 2 | template setStringFunction(SimCode simCode, ModelInfo modelInfo) | |
| 853 | "Generates setString function for c file." | ||
| 854 | ::= | ||
| 855 | match modelInfo | ||
| 856 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 857 | << | ||
| 858 | fmiStatus setString(ModelInstance* comp, const fmiValueReference vr, fmiString value) { | ||
| 859 | switch (vr) { | ||
| 860 | <%vars.stringAlgVars |> var => SwitchVarsSet(simCode, var, "stringVars") ;separator="\n"%> | ||
| 861 | <%vars.stringParamVars |> var => SwitchParametersSet(simCode, var, "stringParameter") ;separator="\n"%> | ||
| 862 | <%vars.stringAliasVars |> var => SwitchAliasVarsSet(simCode, var, "String", "") ;separator="\n"%> | ||
| 863 | default: | ||
| 864 | return fmiError; | ||
| 865 | } | ||
| 866 | return fmiOK; | ||
| 867 | } | ||
| 868 | |||
| 869 | >> | ||
| 870 | end setStringFunction; | ||
| 871 | |||
| 872 | 2 | template setExternalFunction(ModelInfo modelInfo) | |
| 873 | "Generates setExternal function for c file." | ||
| 874 | ::= | ||
| 875 | match modelInfo | ||
| 876 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 877 | let externalFuncs = setExternalFunctionsSwitch(functions) | ||
| 878 | << | ||
| 879 | fmiStatus setExternalFunction(ModelInstance* c, const fmiValueReference vr, const void* value){ | ||
| 880 | switch (vr) { | ||
| 881 | <%externalFuncs%> | ||
| 882 | default: | ||
| 883 | return fmiError; | ||
| 884 | } | ||
| 885 | return fmiOK; | ||
| 886 | } | ||
| 887 | |||
| 888 | >> | ||
| 889 | end setExternalFunction; | ||
| 890 | |||
| 891 | 80 | template eventUpdateFunction2(SimCode simCode) | |
| 892 | "Generates event update function for c file." | ||
| 893 | ::= | ||
| 894 | match simCode | ||
| 895 | case SIMCODE(__) then | ||
| 896 | << | ||
| 897 | // Used to set the next time event, if any. | ||
| 898 | void eventUpdate(ModelInstance* comp, fmi2EventInfo* eventInfo) { | ||
| 899 | } | ||
| 900 | |||
| 901 | >> | ||
| 902 | end eventUpdateFunction2; | ||
| 903 | |||
| 904 | 80 | template getRealFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 905 | "Generates getReal function for c file." | ||
| 906 | ::= | ||
| 907 | match modelInfo | ||
| 908 | case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numAlgAliasVars=numAlgAliasVars, numParams=numParams, numStateVars=numStateVars, numAlgVars= numAlgVars, numDiscreteReal=numDiscreteReal)) then | ||
| 909 | // per-scalar block boundaries (sum getNumElems), so non-scalarized array | ||
| 910 | // variables index the correct contiguous realVars range. (numScalarElems is | ||
| 911 | // inlined because a Susan `let` binds a Text, not an Integer.) | ||
| 912 | let ixFirstParam = intAdd(intMul(2,SimCodeCodegenUtil.numScalarElems(vars.stateVars)),intAdd(SimCodeCodegenUtil.numScalarElems(vars.algVars),SimCodeCodegenUtil.numScalarElems(vars.discreteAlgVars))) | ||
| 913 | let ixFirstAlias = intAdd(SimCodeCodegenUtil.numScalarElems(vars.paramVars), intAdd(intMul(2,SimCodeCodegenUtil.numScalarElems(vars.stateVars)),intAdd(SimCodeCodegenUtil.numScalarElems(vars.algVars),SimCodeCodegenUtil.numScalarElems(vars.discreteAlgVars)))) | ||
| 914 | let ixEnd = intAdd(numAlgAliasVars,intAdd(SimCodeCodegenUtil.numScalarElems(vars.paramVars), intAdd(intMul(2,SimCodeCodegenUtil.numScalarElems(vars.stateVars)),intAdd(SimCodeCodegenUtil.numScalarElems(vars.algVars),SimCodeCodegenUtil.numScalarElems(vars.discreteAlgVars))))) | ||
| 915 | << | ||
| 916 | fmi2Real getReal(ModelInstance* comp, const fmi2ValueReference vr) { | ||
| 917 | if (vr < <%ixFirstParam%>) { | ||
| 918 | return comp->fmuData->localData[0]->realVars[vr]; | ||
| 919 | } | ||
| 920 | if (vr < <%ixFirstAlias%>) { | ||
| 921 | return comp->fmuData->simulationInfo->realParameter[vr-<%ixFirstParam%>]; | ||
| 922 | } | ||
| 923 | <%if numAlgAliasVars then | ||
| 924 | << | ||
| 925 | if (vr < <%ixEnd%>) { | ||
| 926 | int ix = comp->fmuData->callback->fmiRealAliasIndexes[vr-<%ixFirstAlias%>]; | ||
| 927 | return ix>=0 ? getReal(comp, ix) : -getReal(comp, -(ix+1)); | ||
| 928 | } | ||
| 929 | >> | ||
| 930 | %> | ||
| 931 | return NAN; | ||
| 932 | } | ||
| 933 | |||
| 934 | >> | ||
| 935 | end getRealFunction2; | ||
| 936 | |||
| 937 | 80 | template setRealFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 938 | "Generates setReal function for c file." | ||
| 939 | ::= | ||
| 940 | match modelInfo | ||
| 941 | case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numAlgAliasVars=numAlgAliasVars, numParams=numParams, numStateVars=numStateVars, numAlgVars= numAlgVars, numDiscreteReal=numDiscreteReal)) then | ||
| 942 | // per-scalar block boundaries (sum getNumElems) for non-scalarized arrays. | ||
| 943 | let ixFirstParam = intAdd(intMul(2,SimCodeCodegenUtil.numScalarElems(vars.stateVars)),intAdd(SimCodeCodegenUtil.numScalarElems(vars.algVars),SimCodeCodegenUtil.numScalarElems(vars.discreteAlgVars))) | ||
| 944 | let ixFirstAlias = intAdd(SimCodeCodegenUtil.numScalarElems(vars.paramVars), intAdd(intMul(2,SimCodeCodegenUtil.numScalarElems(vars.stateVars)),intAdd(SimCodeCodegenUtil.numScalarElems(vars.algVars),SimCodeCodegenUtil.numScalarElems(vars.discreteAlgVars)))) | ||
| 945 | let ixEnd = intAdd(numAlgAliasVars,intAdd(SimCodeCodegenUtil.numScalarElems(vars.paramVars), intAdd(intMul(2,SimCodeCodegenUtil.numScalarElems(vars.stateVars)),intAdd(SimCodeCodegenUtil.numScalarElems(vars.algVars),SimCodeCodegenUtil.numScalarElems(vars.discreteAlgVars))))) | ||
| 946 | << | ||
| 947 | fmi2Status setReal(ModelInstance* comp, const fmi2ValueReference vr, const fmi2Real value) { | ||
| 948 | // set start value attribute for all variable that has start value, till initialization mode | ||
| 949 | if (vr < <%ixFirstParam%> && (comp->state == model_state_instantiated || comp->state == model_state_initialization_mode)) { | ||
| 950 | put_real_element(value, 0, &comp->fmuData->modelData->realVarsData[vr].attribute.start); | ||
| 951 | } | ||
| 952 | if (vr < <%ixFirstParam%>) { | ||
| 953 | comp->fmuData->localData[0]->realVars[vr] = value; | ||
| 954 | return fmi2OK; | ||
| 955 | } | ||
| 956 | if (vr < <%ixFirstAlias%>) { | ||
| 957 | comp->fmuData->simulationInfo->realParameter[vr-<%ixFirstParam%>] = value; | ||
| 958 | return fmi2OK; | ||
| 959 | } | ||
| 960 | <%if numAlgAliasVars then | ||
| 961 | << | ||
| 962 | if (vr < <%ixEnd%>) { | ||
| 963 | int ix = comp->fmuData->callback->fmiRealAliasIndexes[vr-<%ixFirstAlias%>]; | ||
| 964 | return ix >= 0 ? setReal(comp, ix, value) : setReal(comp, -(ix+1), -value); | ||
| 965 | } | ||
| 966 | >> | ||
| 967 | %> | ||
| 968 | return fmi2Error; | ||
| 969 | } | ||
| 970 | |||
| 971 | >> | ||
| 972 | end setRealFunction2; | ||
| 973 | |||
| 974 | 80 | template getIntegerFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 975 | "Generates setInteger function for c file." | ||
| 976 | ::= | ||
| 977 | match modelInfo | ||
| 978 | case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numIntAliasVars=numAliasVars, numIntParams=numParams, numIntAlgVars=numAlgVars)) then | ||
| 979 | let ixFirstParam = numAlgVars | ||
| 980 | let ixFirstAlias = intAdd(numParams, numAlgVars) | ||
| 981 | let ixEnd = intAdd(numAliasVars,intAdd(numParams, numAlgVars)) | ||
| 982 | << | ||
| 983 | fmi2Integer getInteger(ModelInstance* comp, const fmi2ValueReference vr) { | ||
| 984 | if (vr < <%ixFirstParam%>) { | ||
| 985 | return comp->fmuData->localData[0]->integerVars[vr]; | ||
| 986 | } | ||
| 987 | if (vr < <%ixFirstAlias%>) { | ||
| 988 | return comp->fmuData->simulationInfo->integerParameter[vr-<%ixFirstParam%>]; | ||
| 989 | } | ||
| 990 | <% if numAliasVars then | ||
| 991 | << | ||
| 992 | if (vr < <%ixEnd%>) { | ||
| 993 | int ix = comp->fmuData->callback->fmiIntegerAliasIndexes[vr-<%ixFirstAlias%>]; | ||
| 994 | return ix>=0 ? getInteger(comp, ix) : -getInteger(comp, -(ix+1)); | ||
| 995 | } | ||
| 996 | >> | ||
| 997 | %> | ||
| 998 | return 0; | ||
| 999 | } | ||
| 1000 | |||
| 1001 | >> | ||
| 1002 | end getIntegerFunction2; | ||
| 1003 | |||
| 1004 | 80 | template setIntegerFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 1005 | "Generates getInteger function for c file." | ||
| 1006 | ::= | ||
| 1007 | match modelInfo | ||
| 1008 | case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numIntAliasVars=numAliasVars, numIntParams=numParams, numIntAlgVars=numAlgVars)) then | ||
| 1009 | let ixFirstParam = numAlgVars | ||
| 1010 | let ixFirstAlias = intAdd(numParams, numAlgVars) | ||
| 1011 | let ixEnd = intAdd(numAliasVars,intAdd(numParams, numAlgVars)) | ||
| 1012 | << | ||
| 1013 | fmi2Status setInteger(ModelInstance* comp, const fmi2ValueReference vr, const fmi2Integer value) { | ||
| 1014 | // set start value attribute for all variable that has start value, till initialization mode | ||
| 1015 | if (vr < <%ixFirstParam%> && (comp->state == model_state_instantiated || comp->state == model_state_initialization_mode)) { | ||
| 1016 | put_integer_element(value, 0, &comp->fmuData->modelData->integerVarsData[vr].attribute.start); | ||
| 1017 | } | ||
| 1018 | if (vr < <%ixFirstParam%>) { | ||
| 1019 | comp->fmuData->localData[0]->integerVars[vr] = value; | ||
| 1020 | return fmi2OK; | ||
| 1021 | } | ||
| 1022 | if (vr < <%ixFirstAlias%>) { | ||
| 1023 | comp->fmuData->simulationInfo->integerParameter[vr-<%ixFirstParam%>] = value; | ||
| 1024 | return fmi2OK; | ||
| 1025 | } | ||
| 1026 | <% if numAliasVars then | ||
| 1027 | << | ||
| 1028 | if (vr < <%ixEnd%>) { | ||
| 1029 | int ix = comp->fmuData->callback->fmiIntegerAliasIndexes[vr-<%ixFirstAlias%>]; | ||
| 1030 | return ix >= 0 ? setInteger(comp, ix, value) : setInteger(comp, -(ix+1), -value); | ||
| 1031 | } | ||
| 1032 | >> | ||
| 1033 | %> | ||
| 1034 | return fmi2Error; | ||
| 1035 | } | ||
| 1036 | >> | ||
| 1037 | end setIntegerFunction2; | ||
| 1038 | |||
| 1039 | 80 | template getBooleanFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 1040 | "Generates setBoolean function for c file." | ||
| 1041 | ::= | ||
| 1042 | match modelInfo | ||
| 1043 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 1044 | << | ||
| 1045 | fmi2Boolean getBoolean(ModelInstance* comp, const fmi2ValueReference vr) { | ||
| 1046 | switch (vr) { | ||
| 1047 | <%vars.boolAlgVars |> var => SwitchVars(simCode, var, "booleanVars") ;separator="\n"%> | ||
| 1048 | <%vars.boolParamVars |> var => SwitchParameters(simCode, var, "booleanParameter") ;separator="\n"%> | ||
| 1049 | <%vars.boolAliasVars |> var => SwitchAliasVars(simCode, var, "Boolean", "!") ;separator="\n"%> | ||
| 1050 | default: | ||
| 1051 | return fmi2False; | ||
| 1052 | } | ||
| 1053 | } | ||
| 1054 | |||
| 1055 | >> | ||
| 1056 | end getBooleanFunction2; | ||
| 1057 | |||
| 1058 | 80 | template setBooleanFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 1059 | "Generates getBoolean function for c file." | ||
| 1060 | ::= | ||
| 1061 | match modelInfo | ||
| 1062 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 1063 | << | ||
| 1064 | fmi2Status setBoolean(ModelInstance* comp, const fmi2ValueReference vr, const fmi2Boolean value) { | ||
| 1065 | switch (vr) { | ||
| 1066 | <%vars.boolAlgVars |> var => SwitchVarsSet(simCode, var, "booleanVars") ;separator="\n"%> | ||
| 1067 | <%vars.boolParamVars |> var => SwitchParametersSet(simCode, var, "booleanParameter") ;separator="\n"%> | ||
| 1068 | <%vars.boolAliasVars |> var => SwitchAliasVarsSet(simCode, var, "Boolean", "!") ;separator="\n"%> | ||
| 1069 | default: | ||
| 1070 | return fmi2Error; | ||
| 1071 | } | ||
| 1072 | return fmi2OK; | ||
| 1073 | } | ||
| 1074 | |||
| 1075 | >> | ||
| 1076 | end setBooleanFunction2; | ||
| 1077 | |||
| 1078 | 80 | template getStringFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 1079 | "Generates getString function for c file." | ||
| 1080 | ::= | ||
| 1081 | match modelInfo | ||
| 1082 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 1083 | << | ||
| 1084 | fmi2String getString(ModelInstance* comp, const fmi2ValueReference vr) { | ||
| 1085 | switch (vr) { | ||
| 1086 | <%vars.stringAlgVars |> var => SwitchVars(simCode, var, "stringVars") ;separator="\n"%> | ||
| 1087 | <%vars.stringParamVars |> var => SwitchParameters(simCode, var, "stringParameter") ;separator="\n"%> | ||
| 1088 | <%vars.stringAliasVars |> var => SwitchAliasVars(simCode, var, "String", "") ;separator="\n"%> | ||
| 1089 | default: | ||
| 1090 | return ""; | ||
| 1091 | } | ||
| 1092 | } | ||
| 1093 | |||
| 1094 | >> | ||
| 1095 | end getStringFunction2; | ||
| 1096 | |||
| 1097 | 80 | template setStringFunction2(SimCode simCode, ModelInfo modelInfo) | |
| 1098 | "Generates setString function for c file." | ||
| 1099 | ::= | ||
| 1100 | match modelInfo | ||
| 1101 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 1102 | << | ||
| 1103 | fmi2Status setString(ModelInstance* comp, const fmi2ValueReference vr, fmi2String value) { | ||
| 1104 | switch (vr) { | ||
| 1105 | <%vars.stringAlgVars |> var => SwitchVarsSet(simCode, var, "stringVars") ;separator="\n"%> | ||
| 1106 | <%vars.stringParamVars |> var => SwitchParametersSet(simCode, var, "stringParameter") ;separator="\n"%> | ||
| 1107 | <%vars.stringAliasVars |> var => SwitchAliasVarsSet(simCode, var, "String", "") ;separator="\n"%> | ||
| 1108 | default: | ||
| 1109 | return fmi2Error; | ||
| 1110 | } | ||
| 1111 | return fmi2OK; | ||
| 1112 | } | ||
| 1113 | |||
| 1114 | >> | ||
| 1115 | end setStringFunction2; | ||
| 1116 | |||
| 1117 | 80 | template setExternalFunction2(ModelInfo modelInfo) | |
| 1118 | "Generates setExternal function for c file." | ||
| 1119 | ::= | ||
| 1120 | match modelInfo | ||
| 1121 | case MODELINFO(vars=SIMVARS(__)) then | ||
| 1122 | let externalFuncs = setExternalFunctionsSwitch(functions) | ||
| 1123 | << | ||
| 1124 | fmi2Status setExternalFunction(ModelInstance* c, const fmi2ValueReference vr, const void* value){ | ||
| 1125 | switch (vr) { | ||
| 1126 | <%externalFuncs%> | ||
| 1127 | default: | ||
| 1128 | return fmi2Error; | ||
| 1129 | } | ||
| 1130 | return fmi2OK; | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | >> | ||
| 1134 | end setExternalFunction2; | ||
| 1135 | |||
| 1136 | 82 | template setExternalFunctionsSwitch(list<SimCodeFunction.Function> functions) | |
| 1137 | "Generates external function definitions." | ||
| 1138 | ::= | ||
| 1139 | (functions |> fn => setExternalFunctionSwitch(fn) ; separator="\n") | ||
| 1140 | end setExternalFunctionsSwitch; | ||
| 1141 | |||
| 1142 | ✗ | template setExternalFunctionSwitch(SimCodeFunction.Function fn) | |
| 1143 | "Generates external function definitions." | ||
| 1144 | ::= | ||
| 1145 | match fn | ||
| 1146 | case EXTERNAL_FUNCTION(dynamicLoad=true) then | ||
| 1147 | let fname = extFunctionName(extName, language) | ||
| 1148 | << | ||
| 1149 | case $P<%fname%> : ptr_<%fname%>=(ptrT_<%fname%>)value; break; | ||
| 1150 | >> | ||
| 1151 | end setExternalFunctionSwitch; | ||
| 1152 | |||
| 1153 | 21 | template SwitchVars(SimCode simCode, SimVar simVar, String arrayName) | |
| 1154 | "Generates code for defining variables in c file for FMU target. " | ||
| 1155 | ::= | ||
| 1156 | match simVar | ||
| 1157 | case SIMVAR(__) then | ||
| 1158 | let description = if comment then '// "<%comment%>"' | ||
| 1159 | if stringEq(CodegenUtil.crefStr(name),"$dummy") then | ||
| 1160 | <<>> | ||
| 1161 | else if stringEq(CodegenUtil.crefStr(name),"der($dummy)") then | ||
| 1162 | <<>> | ||
| 1163 | else | ||
| 1164 | if stringEq(arrayName, "stringVars") | ||
| 1165 | then | ||
| 1166 | << | ||
| 1167 | case <%lookupVR(name,simCode)%> : return omc_string_data(comp->fmuData->localData[0]-><%arrayName%>[<%index%>]); break; | ||
| 1168 | >> | ||
| 1169 | else | ||
| 1170 | << | ||
| 1171 | case <%lookupVR(name,simCode)%> : return comp->fmuData->localData[0]-><%arrayName%>[<%index%>]; break; | ||
| 1172 | >> | ||
| 1173 | end SwitchVars; | ||
| 1174 | |||
| 1175 | 321 | template SwitchParameters(SimCode simCode, SimVar simVar, String arrayName) | |
| 1176 | "Generates code for defining variables in c file for FMU target. " | ||
| 1177 | ::= | ||
| 1178 | match simVar | ||
| 1179 | case SIMVAR(__) then | ||
| 1180 | let description = if comment then '// "<%comment%>"' | ||
| 1181 | if stringEq(arrayName, "stringParameter") | ||
| 1182 | then | ||
| 1183 | << | ||
| 1184 | case <%lookupVR(name,simCode)%> : return omc_string_data(comp->fmuData->simulationInfo-><%arrayName%>[<%index%>]); break; | ||
| 1185 | >> | ||
| 1186 | else | ||
| 1187 | << | ||
| 1188 | case <%lookupVR(name,simCode)%> : return comp->fmuData->simulationInfo-><%arrayName%>[<%index%>]; break; | ||
| 1189 | >> | ||
| 1190 | end SwitchParameters; | ||
| 1191 | |||
| 1192 | |||
| 1193 | ✗ | template SwitchAliasVars(SimCode simCode, SimVar simVar, String arrayName, String negate) | |
| 1194 | "Generates code for defining variables in c file for FMU target. " | ||
| 1195 | ::= | ||
| 1196 | match simVar | ||
| 1197 | case SIMVAR(__) then | ||
| 1198 | let description = if comment then '// "<%comment%>"' | ||
| 1199 | let crefName = lookupVR(name,simCode) | ||
| 1200 | match aliasvar | ||
| 1201 | case ALIAS(__) then | ||
| 1202 | if stringEq(CodegenUtil.crefStr(varName),"time") then | ||
| 1203 | << | ||
| 1204 | case <%crefName%> : return comp->fmuData->localData[0]->timeValue; break; | ||
| 1205 | >> | ||
| 1206 | else | ||
| 1207 | << | ||
| 1208 | case <%crefName%> : return get<%arrayName%>(comp, <%lookupVR(varName,simCode)%>); break; | ||
| 1209 | >> | ||
| 1210 | case NEGATEDALIAS(__) then | ||
| 1211 | if stringEq(CodegenUtil.crefStr(varName),"time") then | ||
| 1212 | << | ||
| 1213 | case <%crefName%> : return comp->fmuData->localData[0]->timeValue; break; | ||
| 1214 | >> | ||
| 1215 | else | ||
| 1216 | << | ||
| 1217 | case <%crefName%> : return (<%negate%> get<%arrayName%>(comp, <%lookupVR(varName,simCode)%>)); break; | ||
| 1218 | >> | ||
| 1219 | end match | ||
| 1220 | end SwitchAliasVars; | ||
| 1221 | |||
| 1222 | |||
| 1223 | 21 | template SwitchVarsSet(SimCode simCode, SimVar simVar, String arrayName) | |
| 1224 | "Generates code for defining variables in c file for FMU target. " | ||
| 1225 | ::= | ||
| 1226 | match simVar | ||
| 1227 | case SIMVAR(__) then | ||
| 1228 | let description = if comment then '// "<%comment%>"' | ||
| 1229 | if stringEq(CodegenUtil.crefStr(name),"$dummy") then | ||
| 1230 | <<>> | ||
| 1231 | else if stringEq(CodegenUtil.crefStr(name),"der($dummy)") then | ||
| 1232 | <<>> | ||
| 1233 | else | ||
| 1234 | if stringEq(arrayName, "stringVars") | ||
| 1235 | then | ||
| 1236 | << | ||
| 1237 | case <%lookupVR(name,simCode)%> : omc_string_move(&comp->fmuData->localData[0]-><%arrayName%>[<%index%>], omc_string_new(value)); break; | ||
| 1238 | >> | ||
| 1239 | else | ||
| 1240 | << | ||
| 1241 | case <%lookupVR(name,simCode)%> : comp->fmuData->localData[0]-><%arrayName%>[<%index%>] = value; break; | ||
| 1242 | >> | ||
| 1243 | end SwitchVarsSet; | ||
| 1244 | |||
| 1245 | 321 | template SwitchParametersSet(SimCode simCode, SimVar simVar, String arrayName) | |
| 1246 | "Generates code for defining variables in c file for FMU target. " | ||
| 1247 | ::= | ||
| 1248 | match simVar | ||
| 1249 | case SIMVAR(__) then | ||
| 1250 | let description = if comment then '// "<%comment%>"' | ||
| 1251 | if stringEq(arrayName, "stringParameter") | ||
| 1252 | then | ||
| 1253 | << | ||
| 1254 | case <%lookupVR(name,simCode)%> : omc_string_move(&comp->fmuData->simulationInfo-><%arrayName%>[<%index%>], omc_string_new(value)); break; | ||
| 1255 | >> | ||
| 1256 | else | ||
| 1257 | << | ||
| 1258 | case <%lookupVR(name,simCode)%> : comp->fmuData->simulationInfo-><%arrayName%>[<%index%>] = value; break; | ||
| 1259 | >> | ||
| 1260 | end SwitchParametersSet; | ||
| 1261 | |||
| 1262 | |||
| 1263 | ✗ | template SwitchAliasVarsSet(SimCode simCode, SimVar simVar, String arrayName, String negate) | |
| 1264 | "Generates code for defining variables in c file for FMU target. " | ||
| 1265 | ::= | ||
| 1266 | match simVar | ||
| 1267 | case SIMVAR(__) then | ||
| 1268 | let description = if comment then '// "<%comment%>"' | ||
| 1269 | let crefName = lookupVR(name,simCode) | ||
| 1270 | match aliasvar | ||
| 1271 | case ALIAS(__) then | ||
| 1272 | if stringEq(CodegenUtil.crefStr(varName),"time") then | ||
| 1273 | << | ||
| 1274 | >> | ||
| 1275 | else | ||
| 1276 | << | ||
| 1277 | case <%crefName%> : return set<%arrayName%>(comp, <%lookupVR(varName,simCode)%>, value); break; | ||
| 1278 | >> | ||
| 1279 | case NEGATEDALIAS(__) then | ||
| 1280 | if stringEq(CodegenUtil.crefStr(varName),"time") then | ||
| 1281 | << | ||
| 1282 | >> | ||
| 1283 | else | ||
| 1284 | << | ||
| 1285 | case <%crefName%> : return set<%arrayName%>(comp, <%lookupVR(varName,simCode)%>, (<%negate%> value)); break; | ||
| 1286 | >> | ||
| 1287 | end match | ||
| 1288 | end SwitchAliasVarsSet; | ||
| 1289 | |||
| 1290 | 80 | template mapInputAndOutputs(SimCode simCode) | |
| 1291 | "" | ||
| 1292 | ::= | ||
| 1293 | match simCode | ||
| 1294 | case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(inputVars=inputVars, outputVars=outputVars))) then | ||
| 1295 | << | ||
| 1296 | /* function maps input references to a input index used in partialDerivatives */ | ||
| 1297 | fmi2ValueReference mapInputReference2InputNumber(const fmi2ValueReference vr) { | ||
| 1298 | switch (vr) { | ||
| 1299 | <%inputVars |> var hasindex index0 => match var case SIMVAR(name=name, type_=T_REAL()) then | ||
| 1300 | 'case <%lookupVR(name, simCode)%>: return <%index0%>; break;' ;separator="\n"%> | ||
| 1301 | default: | ||
| 1302 | return -1; | ||
| 1303 | } | ||
| 1304 | } | ||
| 1305 | /* function maps output references to a input index used in partialDerivatives */ | ||
| 1306 | fmi2ValueReference mapOutputReference2OutputNumber(const fmi2ValueReference vr) { | ||
| 1307 | switch (vr) { | ||
| 1308 | <%outputVars |> var hasindex index0 => match var case SIMVAR(name=name, type_=T_REAL()) then | ||
| 1309 | 'case <%lookupVR(name, simCode)%>: return <%index0%>; break;' ;separator="\n"%> | ||
| 1310 | default: | ||
| 1311 | return -1; | ||
| 1312 | } | ||
| 1313 | } | ||
| 1314 | >> | ||
| 1315 | end match | ||
| 1316 | end mapInputAndOutputs; | ||
| 1317 | |||
| 1318 | 80 | template mapRealOutputDerivatives(SimCode simCode, String FMUType) | |
| 1319 | "" | ||
| 1320 | ::= | ||
| 1321 | match simCode | ||
| 1322 | case SIMCODE(modelInfo=MODELINFO(vars=SIMVARS(outputVars=outputVars))) then | ||
| 1323 | << | ||
| 1324 | /* function maps output references to an internal output Real derivatives */ | ||
| 1325 | fmi2ValueReference mapOutputReference2RealOutputDerivatives(const fmi2ValueReference vr) { | ||
| 1326 | switch (vr) { | ||
| 1327 | <%outputVars |> var => match var case SIMVAR(name=name, type_=T_REAL()) then | ||
| 1328 | 'case <%lookupVR(name, simCode)%>: return <%lookupVRForRealOutputDerivative(name, simCode, FMUType)%>; break;' ;separator="\n"%> | ||
| 1329 | default: | ||
| 1330 | return -1; | ||
| 1331 | } | ||
| 1332 | } | ||
| 1333 | >> | ||
| 1334 | end match | ||
| 1335 | end mapRealOutputDerivatives; | ||
| 1336 | |||
| 1337 | 80 | template mapInitialUnknownsdependentCrefs(SimCode simCode) | |
| 1338 | "" | ||
| 1339 | ::= | ||
| 1340 | match simCode | ||
| 1341 | case SIMCODE(modelStructure=SOME(FMIMODELSTRUCTURE(fmiInitialUnknowns=FMIINITIALUNKNOWNS(sortedUnknownCrefs=sortedUnknownCrefs)))) then | ||
| 1342 | << | ||
| 1343 | /* function maps initialUnknowns UnknownVars ValueReferences to an internal partial derivatives index */ | ||
| 1344 | fmi2ValueReference mapInitialUnknownsdependentIndex(const fmi2ValueReference vr) { | ||
| 1345 | switch (vr) { | ||
| 1346 | <%sortedUnknownCrefs |> (index, cref) => | ||
| 1347 | 'case <%lookupVR(cref, simCode)%>: return <%index%>; break;' ;separator="\n"%> | ||
| 1348 | default: | ||
| 1349 | return -1; | ||
| 1350 | } | ||
| 1351 | } | ||
| 1352 | >> | ||
| 1353 | else | ||
| 1354 | << | ||
| 1355 | /* no model structure / initial unknowns available */ | ||
| 1356 | fmi2ValueReference mapInitialUnknownsdependentIndex(const fmi2ValueReference vr) { | ||
| 1357 | return -1; | ||
| 1358 | } | ||
| 1359 | >> | ||
| 1360 | end match | ||
| 1361 | end mapInitialUnknownsdependentCrefs; | ||
| 1362 | |||
| 1363 | 80 | template mapInitialUnknownsIndependentCrefs(SimCode simCode) | |
| 1364 | "" | ||
| 1365 | ::= | ||
| 1366 | match simCode | ||
| 1367 | case SIMCODE(modelStructure=SOME(FMIMODELSTRUCTURE(fmiInitialUnknowns=FMIINITIALUNKNOWNS(sortedknownCrefs=sortedknownCrefs)))) then | ||
| 1368 | << | ||
| 1369 | /* function maps initialUnknowns knownVars ValueReferences to an internal partial derivatives index */ | ||
| 1370 | fmi2ValueReference mapInitialUnknownsIndependentIndex(const fmi2ValueReference vr) { | ||
| 1371 | switch (vr) { | ||
| 1372 | <%sortedknownCrefs |> (index, cref) => | ||
| 1373 | 'case <%lookupVR(cref, simCode)%>: return <%index%>; break;' ;separator="\n"%> | ||
| 1374 | default: | ||
| 1375 | return -1; | ||
| 1376 | } | ||
| 1377 | } | ||
| 1378 | >> | ||
| 1379 | else | ||
| 1380 | << | ||
| 1381 | /* no model structure / initial unknowns available */ | ||
| 1382 | fmi2ValueReference mapInitialUnknownsIndependentIndex(const fmi2ValueReference vr) { | ||
| 1383 | return -1; | ||
| 1384 | } | ||
| 1385 | >> | ||
| 1386 | end match | ||
| 1387 | end mapInitialUnknownsIndependentCrefs; | ||
| 1388 | |||
| 1389 | 82 | template settingsfile(SimCode simCode) | |
| 1390 | "Generates content of omc_simulation_settings.h" | ||
| 1391 | ::= | ||
| 1392 | match simCode | ||
| 1393 | case SIMCODE(modelInfo=MODELINFO(varInfo=varInfo as VARINFO(__)), delayedExps=DELAYED_EXPRESSIONS(maxDelayedIndex=maxDelayedIndex), fmiSimulationFlags=fmiSimulationFlags) then | ||
| 1394 | << | ||
| 1395 | #if !defined(OMC_SIM_SETTINGS_CMDLINE) | ||
| 1396 | #define OMC_SIM_SETTINGS_CMDLINE | ||
| 1397 | #define OMC_NUM_LINEAR_SYSTEMS <%varInfo.numLinearSystems%> | ||
| 1398 | #define OMC_NUM_NONLINEAR_SYSTEMS <%varInfo.numNonLinearSystems%> | ||
| 1399 | #define OMC_NUM_MIXED_SYSTEMS <%varInfo.numMixedSystems%> | ||
| 1400 | #define OMC_NDELAY_EXPRESSIONS <%maxDelayedIndex%> | ||
| 1401 | #define OMC_NVAR_STRING <%varInfo.numStringAlgVars%> | ||
| 1402 | <% if Flags.isSet(Flags.FMU_EXPERIMENTAL) then '#define FMU_EXPERIMENTAL 1'%> | ||
| 1403 | #define OMC_MODEL_PREFIX "<%modelNamePrefix(simCode)%>" | ||
| 1404 | #define OMC_MINIMAL_RUNTIME 1 | ||
| 1405 | #define OMC_FMI_RUNTIME 1 | ||
| 1406 | #endif | ||
| 1407 | >> | ||
| 1408 | end settingsfile; | ||
| 1409 | |||
| 1410 | 82 | template fmuSourceMakefile(SimCode simCode, String FMUVersion, String fileNamePrefixHash) | |
| 1411 | "Generates the contents of the makefile for the simulation case. Copy libexpat & correct linux fmu" | ||
| 1412 | ::= | ||
| 1413 | match simCode | ||
| 1414 | case SIMCODE(modelInfo=modelInfo as MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simulationSettingsOpt = sopt) then | ||
| 1415 | let includedir = '<%fileNamePrefixHash%>.fmutmp/sources/' | ||
| 1416 | let mkdir = match makefileParams.platform case "win32" case "win64" then '"mkdir.exe"' else 'mkdir' | ||
| 1417 | let omhome = makefileParams.omhome | ||
| 1418 | let prefix = fileNamePrefix | ||
| 1419 | << | ||
| 1420 | # FIXME: before you push into master... | ||
| 1421 | RUNTIMEDIR=<%makefileParams.omhome%>/include/omc/c/ | ||
| 1422 | #COPY_RUNTIMEFILES=$(FMI_ME_OBJS:%= && (OMCFILE=% && cp $(RUNTIMEDIR)/$$OMCFILE.c $$OMCFILE.c)) | ||
| 1423 | |||
| 1424 | fmu: | ||
| 1425 | <%match getGeneralTarget(Config.simulationCodeTarget()) | ||
| 1426 | case "msvc" then | ||
| 1427 | // nmake runs these in cmd; cmake comes with the Visual Studio environment. | ||
| 1428 | << | ||
| 1429 | <%\t%>cmake -E rm -f <%fileNamePrefixHash%>.fmutmp/sources/<%prefix%>_init.xml | ||
| 1430 | <%\t%>cmake -E copy_directory "<%omhome%>/share/omc/runtime/c/fmi/buildproject" <%fileNamePrefixHash%>.fmutmp/sources | ||
| 1431 | <%\t%>cmake -E copy <%prefix%>_FMU.libs <%fileNamePrefixHash%>.fmutmp/sources/ | ||
| 1432 | >> | ||
| 1433 | else | ||
| 1434 | << | ||
| 1435 | <%\t%>rm -f <%fileNamePrefixHash%>.fmutmp/sources/<%prefix%>_init.xml<%/*Already translated to .c*/%> | ||
| 1436 | <%\t%>cp -a "<%omhome%>/share/omc/runtime/c/fmi/buildproject/"* <%fileNamePrefixHash%>.fmutmp/sources | ||
| 1437 | <%\t%>cp -a <%prefix%>_FMU.libs <%fileNamePrefixHash%>.fmutmp/sources/ | ||
| 1438 | >> | ||
| 1439 | %> | ||
| 1440 | <%\n%> | ||
| 1441 | >> | ||
| 1442 | end fmuSourceMakefile; | ||
| 1443 | |||
| 1444 | ✗ | template importFMUModelDescription(FmiImport fmi) | |
| 1445 | "Generates Modelica code for FMU model description" | ||
| 1446 | ::= | ||
| 1447 | match fmi | ||
| 1448 | case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)) then | ||
| 1449 | /* FMI 1.0 and 2.0 share the records and are both dumped by the "1.0" case; FMI 3.0 | ||
| 1450 | has records of its own. */ | ||
| 1451 | let mdVersion = if isFMIVersion30(fmiInfo.fmiVersion) then "3.0" else "1.0" | ||
| 1452 | << | ||
| 1453 | model <%fmiInfo.fmiModelIdentifier%>_Input_Output_FMU<%if stringEq(fmiInfo.fmiDescription, "") then "" else " \""+fmiInfo.fmiDescription+"\""%> | ||
| 1454 | <%dumpFMITypeDefinitions(fmiTypeDefinitionsList)%> | ||
| 1455 | <%dumpFMUModelDescriptionVariablesList(mdVersion, fmiModelVariablesList, fmiTypeDefinitionsList, generateInputConnectors, generateOutputConnectors)%> | ||
| 1456 | end <%fmiInfo.fmiModelIdentifier%>_Input_Output_FMU; | ||
| 1457 | >> | ||
| 1458 | end importFMUModelDescription; | ||
| 1459 | |||
| 1460 | ✗ | template dumpFMUModelDescriptionVariablesList(String FMUVersion, list<ModelVariables> fmiModelVariablesList, list<TypeDefinitions> fmiTypeDefinitionsList, Boolean generateInputConnectors, Boolean generateOutputConnectors) | |
| 1461 | "Generates the Model Variables code." | ||
| 1462 | ::= | ||
| 1463 | << | ||
| 1464 | <%fmiModelVariablesList |> fmiModelVariable => dumpFMUModelDescriptionVariable(FMUVersion, fmiModelVariable, fmiTypeDefinitionsList, generateInputConnectors, generateOutputConnectors) ;separator="\n"%> | ||
| 1465 | >> | ||
| 1466 | end dumpFMUModelDescriptionVariablesList; | ||
| 1467 | |||
| 1468 | ✗ | template dumpFMUModelDescriptionVariable(String FMUVersion, ModelVariables fmiModelVariable, list<TypeDefinitions> fmiTypeDefinitionsList, Boolean generateInputConnectors, Boolean generateOutputConnectors) | |
| 1469 | ::= | ||
| 1470 | match FMUVersion | ||
| 1471 | case "1.0" then | ||
| 1472 | match fmiModelVariable | ||
| 1473 | case REALVARIABLE(__) then | ||
| 1474 | let isInputOrOutput = if boolOr(stringEq(causality, "input"), stringEq(causality, "output")) then true | ||
| 1475 | if isInputOrOutput then | ||
| 1476 | << | ||
| 1477 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1478 | >> | ||
| 1479 | case INTEGERVARIABLE(__) then | ||
| 1480 | let isInputOrOutput = if boolOr(stringEq(causality, "input"), stringEq(causality, "output")) then true | ||
| 1481 | if isInputOrOutput then | ||
| 1482 | << | ||
| 1483 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1484 | >> | ||
| 1485 | case BOOLEANVARIABLE(__) then | ||
| 1486 | let isInputOrOutput = if boolOr(stringEq(causality, "input"), stringEq(causality, "output")) then true | ||
| 1487 | if isInputOrOutput then | ||
| 1488 | << | ||
| 1489 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1490 | >> | ||
| 1491 | case STRINGVARIABLE(__) then | ||
| 1492 | let isInputOrOutput = if boolOr(stringEq(causality, "input"), stringEq(causality, "output")) then true | ||
| 1493 | if isInputOrOutput then | ||
| 1494 | << | ||
| 1495 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1496 | >> | ||
| 1497 | case ENUMERATIONVARIABLE(__) then | ||
| 1498 | let isInputOrOutput = if boolOr(stringEq(causality, "input"), stringEq(causality, "output")) then true | ||
| 1499 | if isInputOrOutput then | ||
| 1500 | << | ||
| 1501 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1502 | >> | ||
| 1503 | end match | ||
| 1504 | case "3.0" then | ||
| 1505 | /* The FMI 3.0 records, which carry the same baseType as the older ones -- Real for | ||
| 1506 | both float types, Integer for all eight integer types -- so the connector a | ||
| 1507 | variable becomes is chosen exactly as above. Binary and Clock have no Modelica | ||
| 1508 | type and are left out, as are arrays, which a connector cannot carry. */ | ||
| 1509 | match fmiModelVariable | ||
| 1510 | case FMI3REALVARIABLE(__) then | ||
| 1511 | let emitConnector = if boolAnd(boolOr(stringEq(causality, "input"), stringEq(causality, "output")), listEmpty(dimensions)) then true | ||
| 1512 | if emitConnector then | ||
| 1513 | << | ||
| 1514 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1515 | >> | ||
| 1516 | case FMI3INTEGERVARIABLE(__) then | ||
| 1517 | let emitConnector = if boolAnd(boolOr(stringEq(causality, "input"), stringEq(causality, "output")), listEmpty(dimensions)) then true | ||
| 1518 | if emitConnector then | ||
| 1519 | << | ||
| 1520 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1521 | >> | ||
| 1522 | case FMI3BOOLEANVARIABLE(__) then | ||
| 1523 | let emitConnector = if boolAnd(boolOr(stringEq(causality, "input"), stringEq(causality, "output")), listEmpty(dimensions)) then true | ||
| 1524 | if emitConnector then | ||
| 1525 | << | ||
| 1526 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1527 | >> | ||
| 1528 | case FMI3STRINGVARIABLE(__) then | ||
| 1529 | let emitConnector = if boolAnd(boolOr(stringEq(causality, "input"), stringEq(causality, "output")), listEmpty(dimensions)) then true | ||
| 1530 | if emitConnector then | ||
| 1531 | << | ||
| 1532 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1533 | >> | ||
| 1534 | case FMI3ENUMERATIONVARIABLE(__) then | ||
| 1535 | let emitConnector = if boolAnd(boolOr(stringEq(causality, "input"), stringEq(causality, "output")), listEmpty(dimensions)) then true | ||
| 1536 | if emitConnector then | ||
| 1537 | << | ||
| 1538 | <%dumpFMUModelDescriptionInputOutputVariable(name, causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 1539 | >> | ||
| 1540 | end match | ||
| 1541 | end dumpFMUModelDescriptionVariable; | ||
| 1542 | |||
| 1543 | ✗ | template dumpFMUModelDescriptionInputOutputVariable(String name, String causality, String baseType, Boolean generateInputConnectors, Boolean generateOutputConnectors) | |
| 1544 | ::= | ||
| 1545 | if boolAnd(generateInputConnectors, boolAnd(stringEq(causality, "input"),stringEq(baseType, "Real"))) then "Modelica.Blocks.Interfaces.RealInput "+name+"" | ||
| 1546 | else if boolAnd(generateInputConnectors, boolAnd(stringEq(causality, "input"),stringEq(baseType, "Integer"))) then "Modelica.Blocks.Interfaces.IntegerInput "+name+"" | ||
| 1547 | else if boolAnd(generateInputConnectors, boolAnd(stringEq(causality, "input"),stringEq(baseType, "Boolean"))) then "Modelica.Blocks.Interfaces.BooleanInput "+name+"" | ||
| 1548 | else if boolAnd(generateOutputConnectors, boolAnd(stringEq(causality, "output"),stringEq(baseType, "Real"))) then "Modelica.Blocks.Interfaces.RealOutput "+name+"" | ||
| 1549 | else if boolAnd(generateOutputConnectors, boolAnd(stringEq(causality, "output"),stringEq(baseType, "Integer"))) then "Modelica.Blocks.Interfaces.IntegerOutput "+name+"" | ||
| 1550 | else if boolAnd(generateOutputConnectors, boolAnd(stringEq(causality, "output"),stringEq(baseType, "Boolean"))) then "Modelica.Blocks.Interfaces.BooleanOutput "+name+"" | ||
| 1551 | end dumpFMUModelDescriptionInputOutputVariable; | ||
| 1552 | |||
| 1553 | 18 | template importFMUModelica(FmiImport fmi, String name) | |
| 1554 | "Generates the Modelica code depending on the FMU type." | ||
| 1555 | ::= | ||
| 1556 | match fmi | ||
| 1557 | case FMIIMPORT(__) then | ||
| 1558 | match fmiInfo | ||
| 1559 | case (INFO(fmiVersion = "1.0", fmiType = 0)) then | ||
| 1560 | importFMU1ModelExchange(fmi, name) | ||
| 1561 | case (INFO(fmiVersion = "1.0", fmiType = 1)) then | ||
| 1562 | importFMU1CoSimulationStandAlone(fmi, name) | ||
| 1563 | case (INFO(fmiVersion = "2.0", fmiType = 1)) then | ||
| 1564 | importFMU2ModelExchange(fmi, name) | ||
| 1565 | /* FMI 3.0 numbers its interface types as flags, so Model Exchange is 2 here and | ||
| 1566 | not the 1 of FMI 2.0; see fmi3_fmu_kind_enu_t. */ | ||
| 1567 | case (INFO(fmiVersion = "3.0", fmiType = 2)) then | ||
| 1568 | importFMU3ModelExchange(fmi, name) | ||
| 1569 | end importFMUModelica; | ||
| 1570 | |||
| 1571 | 2 | template importFMU1ModelExchange(FmiImport fmi, String name) | |
| 1572 | "Generates Modelica code for FMI Model Exchange version 1.0" | ||
| 1573 | ::= | ||
| 1574 | match fmi | ||
| 1575 | case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)) then | ||
| 1576 | /* Get Real parameters and their value references */ | ||
| 1577 | let realParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 1, "1.0") | ||
| 1578 | let realParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 2, "1.0") | ||
| 1579 | /* Get Integer parameters and their value references */ | ||
| 1580 | let integerParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 1, "1.0") | ||
| 1581 | let integerParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 2, "1.0") | ||
| 1582 | /* Get Boolean parameters and their value references */ | ||
| 1583 | let booleanParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 1, "1.0") | ||
| 1584 | let booleanParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 2, "1.0") | ||
| 1585 | /* Get String parameters and their value references */ | ||
| 1586 | let stringParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 1, "1.0") | ||
| 1587 | let stringParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 2, "1.0") | ||
| 1588 | /* Get dependent Real parameters and their value references */ | ||
| 1589 | let realDependentParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 1, "1.0") | ||
| 1590 | let realDependentParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 2, "1.0") | ||
| 1591 | /* Get dependent Integer parameters and their value references */ | ||
| 1592 | let integerDependentParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 1, "1.0") | ||
| 1593 | let integerDependentParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 2, "1.0") | ||
| 1594 | /* Get dependent Boolean parameters and their value references */ | ||
| 1595 | let booleanDependentParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 1, "1.0") | ||
| 1596 | let booleanDependentParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 2, "1.0") | ||
| 1597 | /* Get dependent String parameters and their value references */ | ||
| 1598 | let stringDependentParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 1, "1.0") | ||
| 1599 | let stringDependentParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 2, "1.0") | ||
| 1600 | /* Get input Real varibales and their value references */ | ||
| 1601 | let realInputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "input", false, 1, "1.0") | ||
| 1602 | let realInputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 2, "1.0") | ||
| 1603 | let realInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 3, "1.0") | ||
| 1604 | /* Get input Integer varibales and their value references */ | ||
| 1605 | let integerInputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "input", false, 1, "1.0") | ||
| 1606 | let integerInputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 2, "1.0") | ||
| 1607 | let integerInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 3, "1.0") | ||
| 1608 | /* Get input Boolean varibales and their value references */ | ||
| 1609 | let booleanInputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 1, "1.0") | ||
| 1610 | let booleanInputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 2, "1.0") | ||
| 1611 | let booleanInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 3, "1.0") | ||
| 1612 | /* Get input String varibales and their value references */ | ||
| 1613 | let stringInputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "input", false, 1, "1.0") | ||
| 1614 | let stringStartVariablesNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 2, "1.0") | ||
| 1615 | let stringInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 3, "1.0") | ||
| 1616 | /* Get output Real varibales and their value references */ | ||
| 1617 | let realOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "output", false, 1, "1.0") | ||
| 1618 | let realOutputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "output", false, 2, "1.0") | ||
| 1619 | /* Get output Integer varibales and their value references */ | ||
| 1620 | let integerOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "output", false, 1, "1.0") | ||
| 1621 | let integerOutputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "output", false, 2, "1.0") | ||
| 1622 | /* Get output Boolean varibales and their value references */ | ||
| 1623 | let booleanOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 1, "1.0") | ||
| 1624 | let booleanOutputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 2, "1.0") | ||
| 1625 | /* Get output String varibales and their value references */ | ||
| 1626 | let stringOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "output", false, 1, "1.0") | ||
| 1627 | let stringOutputVariablesNames = dumpVariables(fmiModelVariablesList, "string", "output", false, 2, "1.0") | ||
| 1628 | << | ||
| 1629 | model <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%><%if stringEq(fmiInfo.fmiDescription, "") then "" else " \""+fmiInfo.fmiDescription+"\""%> | ||
| 1630 | <%dumpFMITypeDefinitions(fmiTypeDefinitionsList)%> | ||
| 1631 | constant String fmuWorkingDir = "<%fmuWorkingDirectory%>"; | ||
| 1632 | parameter Integer logLevel = <%fmiLogLevel%> "log level used during the loading of FMU" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 1633 | parameter Boolean debugLogging = <%fmiDebugOutput%> "enables the FMU simulation logging" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 1634 | <%dumpFMIModelVariablesList("1.0", fmiModelVariablesList, fmiTypeDefinitionsList, generateInputConnectors, generateOutputConnectors)%> | ||
| 1635 | protected | ||
| 1636 | FMI1ModelExchange fmi1me = FMI1ModelExchange(logLevel, fmuWorkingDir, "<%fmiInfo.fmiModelIdentifier%>", debugLogging); | ||
| 1637 | constant Integer numberOfContinuousStates = <%listLength(fmiInfo.fmiNumberOfContinuousStates)%>; | ||
| 1638 | Real fmi_x[numberOfContinuousStates] "States"; | ||
| 1639 | Real fmi_x_new[numberOfContinuousStates](each fixed = true) "New States"; | ||
| 1640 | constant Integer numberOfEventIndicators = <%listLength(fmiInfo.fmiNumberOfEventIndicators)%>; | ||
| 1641 | Real fmi_z[numberOfEventIndicators] "Events Indicators"; | ||
| 1642 | Boolean fmi_z_positive[numberOfEventIndicators](each fixed = true); | ||
| 1643 | parameter Real flowStartTime(fixed=false); | ||
| 1644 | Real flowTime; | ||
| 1645 | parameter Real flowInitialized(fixed=false); | ||
| 1646 | parameter Real flowParamsStart(fixed=false); | ||
| 1647 | parameter Real flowInitInputs(fixed=false); | ||
| 1648 | Real flowStatesInputs; | ||
| 1649 | <%if not stringEq(realInputVariablesVRs, "") then "Real "+realInputVariablesReturnNames+";"%> | ||
| 1650 | <%if not stringEq(integerInputVariablesVRs, "") then "Integer "+integerInputVariablesReturnNames+";"%> | ||
| 1651 | <%if not stringEq(booleanInputVariablesVRs, "") then "Boolean "+booleanInputVariablesReturnNames+";"%> | ||
| 1652 | <%if not stringEq(stringInputVariablesVRs, "") then "String "+stringInputVariablesReturnNames+";"%> | ||
| 1653 | Boolean callEventUpdate; | ||
| 1654 | constant Boolean intermediateResults = false; | ||
| 1655 | Boolean newStatesAvailable(fixed = true); | ||
| 1656 | Real triggerDSSEvent; | ||
| 1657 | Real nextEventTime; | ||
| 1658 | initial equation | ||
| 1659 | <%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then | ||
| 1660 | << | ||
| 1661 | fmi_x = fmi1Functions.fmi1GetContinuousStates(fmi1me, numberOfContinuousStates, flowParamsStart+flowInitialized); | ||
| 1662 | >> | ||
| 1663 | %> | ||
| 1664 | initial algorithm | ||
| 1665 | flowParamsStart := 1; | ||
| 1666 | flowInitInputs := 1; | ||
| 1667 | flowStartTime := fmi1Functions.fmi1SetTime(fmi1me, time, 1); | ||
| 1668 | /* the parameters must be set before the FMU is initialized, | ||
| 1669 | otherwise the FMU computes its calculated parameters from the default values */ | ||
| 1670 | <%if not stringEq(realParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetRealParameter(fmi1me, {"+realParametersVRs+"}, {"+realParametersNames+"});"%> | ||
| 1671 | <%if not stringEq(integerParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetIntegerParameter(fmi1me, {"+integerParametersVRs+"}, {"+integerParametersNames+"});"%> | ||
| 1672 | <%if not stringEq(booleanParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetBooleanParameter(fmi1me, {"+booleanParametersVRs+"}, {"+booleanParametersNames+"});"%> | ||
| 1673 | <%if not stringEq(stringParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetStringParameter(fmi1me, {"+stringParametersVRs+"}, {"+stringParametersNames+"});"%> | ||
| 1674 | flowInitialized := fmi1Functions.fmi1Initialize(fmi1me, flowParamsStart+flowInitInputs+flowStartTime); | ||
| 1675 | initial equation | ||
| 1676 | <%if not stringEq(realDependentParametersVRs, "") then "{"+realDependentParametersNames+"} = fmi1Functions.fmi1GetReal(fmi1me, {"+realDependentParametersVRs+"}, flowInitialized);"%> | ||
| 1677 | <%if not stringEq(integerDependentParametersVRs, "") then "{"+integerDependentParametersNames+"} = fmi1Functions.fmi1GetInteger(fmi1me, {"+integerDependentParametersVRs+"}, flowInitialized);"%> | ||
| 1678 | <%if not stringEq(booleanDependentParametersVRs, "") then "{"+booleanDependentParametersNames+"} = fmi1Functions.fmi1GetBoolean(fmi1me, {"+booleanDependentParametersVRs+"}, flowInitialized);"%> | ||
| 1679 | <%if not stringEq(stringDependentParametersVRs, "") then "{"+stringDependentParametersNames+"} = fmi1Functions.fmi1GetString(fmi1me, {"+stringDependentParametersVRs+"}, flowInitialized);"%> | ||
| 1680 | equation | ||
| 1681 | flowTime = fmi1Functions.fmi1SetTime(fmi1me, time, flowInitialized); | ||
| 1682 | <%if not stringEq(realInputVariablesVRs, "") then "{"+realInputVariablesReturnNames+"} = fmi1Functions.fmi1SetReal(fmi1me, {"+realInputVariablesVRs+"}, {"+realInputVariablesNames+"});"%> | ||
| 1683 | <%if not stringEq(integerInputVariablesVRs, "") then "{"+integerInputVariablesReturnNames+"} = fmi1Functions.fmi1SetInteger(fmi1me, {"+integerInputVariablesVRs+"}, {"+integerInputVariablesNames+"});"%> | ||
| 1684 | <%if not stringEq(booleanInputVariablesVRs, "") then "{"+booleanInputVariablesReturnNames+"} = fmi1Functions.fmi1SetBoolean(fmi1me, {"+booleanInputVariablesVRs+"}, {"+booleanInputVariablesNames+"});"%> | ||
| 1685 | <%if not stringEq(stringInputVariablesVRs, "") then "{"+stringInputVariablesReturnNames+"} = fmi1Functions.fmi1SetString(fmi1me, {"+stringInputVariablesVRs+"}, {"+stringStartVariablesNames+"});"%> | ||
| 1686 | flowStatesInputs = fmi1Functions.fmi1SetContinuousStates(fmi1me, fmi_x, flowParamsStart + flowTime); | ||
| 1687 | der(fmi_x) = fmi1Functions.fmi1GetDerivatives(fmi1me, numberOfContinuousStates, flowStatesInputs); | ||
| 1688 | fmi_z = fmi1Functions.fmi1GetEventIndicators(fmi1me, numberOfEventIndicators, flowStatesInputs); | ||
| 1689 | for i in 1:size(fmi_z,1) loop | ||
| 1690 | fmi_z_positive[i] = if not terminal() then fmi_z[i] > 0 else pre(fmi_z_positive[i]); | ||
| 1691 | end for; | ||
| 1692 | callEventUpdate = fmi1Functions.fmi1CompletedIntegratorStep(fmi1me, flowStatesInputs); | ||
| 1693 | triggerDSSEvent = noEvent(if callEventUpdate then flowStatesInputs+1.0 else flowStatesInputs-1.0); | ||
| 1694 | nextEventTime = fmi1Functions.fmi1nextEventTime(fmi1me, flowStatesInputs); | ||
| 1695 | <%if not boolAnd(stringEq(realOutputVariablesNames, ""), stringEq(realOutputVariablesVRs, "")) then "{"+realOutputVariablesNames+"} = fmi1Functions.fmi1GetReal(fmi1me, {"+realOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 1696 | <%if not boolAnd(stringEq(integerOutputVariablesNames, ""), stringEq(integerOutputVariablesVRs, "")) then "{"+integerOutputVariablesNames+"} = fmi1Functions.fmi1GetInteger(fmi1me, {"+integerOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 1697 | <%if not boolAnd(stringEq(booleanOutputVariablesNames, ""), stringEq(booleanOutputVariablesVRs, "")) then "{"+booleanOutputVariablesNames+"} = fmi1Functions.fmi1GetBoolean(fmi1me, {"+booleanOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 1698 | <%if not boolAnd(stringEq(stringOutputVariablesNames, ""), stringEq(stringOutputVariablesVRs, "")) then "{"+stringOutputVariablesNames+"} = fmi1Functions.fmi1GetString(fmi1me, {"+stringOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 1699 | <%dumpOutputGetEnumerationVariables(fmiModelVariablesList, fmiTypeDefinitionsList, "fmi1Functions.fmi1GetInteger", "fmi1me")%> | ||
| 1700 | algorithm | ||
| 1701 | <%if intGt(listLength(fmiInfo.fmiNumberOfEventIndicators), 0) then | ||
| 1702 | << | ||
| 1703 | when {<%fmiInfo.fmiNumberOfEventIndicators |> eventIndicator => "change(fmi_z_positive["+eventIndicator+"])" ;separator=" or "%>, triggerDSSEvent > flowStatesInputs, nextEventTime < time, terminal()} then | ||
| 1704 | >> | ||
| 1705 | else | ||
| 1706 | << | ||
| 1707 | when {triggerDSSEvent > flowStatesInputs, nextEventTime < time, terminal()} then | ||
| 1708 | >> | ||
| 1709 | %> | ||
| 1710 | newStatesAvailable := fmi1Functions.fmi1EventUpdate(fmi1me, intermediateResults); | ||
| 1711 | <%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then | ||
| 1712 | << | ||
| 1713 | if newStatesAvailable then | ||
| 1714 | fmi_x_new := fmi1Functions.fmi1GetContinuousStates(fmi1me, numberOfContinuousStates, flowStatesInputs); | ||
| 1715 | <%fmiInfo.fmiNumberOfContinuousStates |> continuousStates => "reinit(fmi_x["+continuousStates+"], fmi_x_new["+continuousStates+"]);" ;separator="\n"%> | ||
| 1716 | end if; | ||
| 1717 | >> | ||
| 1718 | %> | ||
| 1719 | end when; | ||
| 1720 | annotation(experiment(StartTime=<%fmiExperimentAnnotation.fmiExperimentStartTime%>, StopTime=<%fmiExperimentAnnotation.fmiExperimentStopTime%>, Tolerance=<%fmiExperimentAnnotation.fmiExperimentTolerance%>)); | ||
| 1721 | annotation (Icon(graphics={ | ||
| 1722 | Rectangle( | ||
| 1723 | extent={{-100,100},{100,-100}}, | ||
| 1724 | lineColor={0,0,0}, | ||
| 1725 | fillColor={240,240,240}, | ||
| 1726 | fillPattern=FillPattern.Solid, | ||
| 1727 | lineThickness=0.5), | ||
| 1728 | Text( | ||
| 1729 | extent={{-100,40},{100,0}}, | ||
| 1730 | lineColor={0,0,0}, | ||
| 1731 | textString="%name"), | ||
| 1732 | Text( | ||
| 1733 | extent={{-100,-50},{100,-90}}, | ||
| 1734 | lineColor={0,0,0}, | ||
| 1735 | textString="V1.0")})); | ||
| 1736 | protected | ||
| 1737 | class FMI1ModelExchange | ||
| 1738 | extends ExternalObject; | ||
| 1739 | function constructor | ||
| 1740 | input Integer logLevel; | ||
| 1741 | input String workingDirectory; | ||
| 1742 | input String instanceName; | ||
| 1743 | input Boolean debugLogging; | ||
| 1744 | output FMI1ModelExchange fmi1me; | ||
| 1745 | external "C" fmi1me = FMI1ModelExchangeConstructor_OMC(logLevel, workingDirectory, instanceName, debugLogging) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1746 | end constructor; | ||
| 1747 | |||
| 1748 | function destructor | ||
| 1749 | input FMI1ModelExchange fmi1me; | ||
| 1750 | external "C" FMI1ModelExchangeDestructor_OMC(fmi1me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1751 | end destructor; | ||
| 1752 | end FMI1ModelExchange; | ||
| 1753 | |||
| 1754 | <%dumpFMITypeDefinitionsMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 1755 | |||
| 1756 | <%dumpFMITypeDefinitionsArrayMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 1757 | |||
| 1758 | package fmi1Functions | ||
| 1759 | function fmi1Initialize | ||
| 1760 | input FMI1ModelExchange fmi1me; | ||
| 1761 | input Real preInitialized; | ||
| 1762 | output Real postInitialized=preInitialized; | ||
| 1763 | external "C" fmi1Initialize_OMC(fmi1me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1764 | end fmi1Initialize; | ||
| 1765 | |||
| 1766 | function fmi1SetTime | ||
| 1767 | input FMI1ModelExchange fmi1me; | ||
| 1768 | input Real inTime; | ||
| 1769 | input Real inFlow; | ||
| 1770 | output Real outFlow = inFlow; | ||
| 1771 | external "C" fmi1SetTime_OMC(fmi1me, inTime) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1772 | end fmi1SetTime; | ||
| 1773 | |||
| 1774 | function fmi1GetContinuousStates | ||
| 1775 | input FMI1ModelExchange fmi1me; | ||
| 1776 | input Integer numberOfContinuousStates; | ||
| 1777 | input Real inFlowParams; | ||
| 1778 | output Real fmi_x[numberOfContinuousStates]; | ||
| 1779 | external "C" fmi1GetContinuousStates_OMC(fmi1me, numberOfContinuousStates, inFlowParams, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1780 | end fmi1GetContinuousStates; | ||
| 1781 | |||
| 1782 | function fmi1SetContinuousStates | ||
| 1783 | input FMI1ModelExchange fmi1me; | ||
| 1784 | input Real fmi_x[:]; | ||
| 1785 | input Real inFlowParams; | ||
| 1786 | output Real outFlowStates; | ||
| 1787 | external "C" outFlowStates = fmi1SetContinuousStates_OMC(fmi1me, size(fmi_x, 1), inFlowParams, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1788 | end fmi1SetContinuousStates; | ||
| 1789 | |||
| 1790 | function fmi1GetDerivatives | ||
| 1791 | input FMI1ModelExchange fmi1me; | ||
| 1792 | input Integer numberOfContinuousStates; | ||
| 1793 | input Real inFlowStates; | ||
| 1794 | output Real fmi_x[numberOfContinuousStates]; | ||
| 1795 | external "C" fmi1GetDerivatives_OMC(fmi1me, numberOfContinuousStates, inFlowStates, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1796 | end fmi1GetDerivatives; | ||
| 1797 | |||
| 1798 | function fmi1GetEventIndicators | ||
| 1799 | input FMI1ModelExchange fmi1me; | ||
| 1800 | input Integer numberOfEventIndicators; | ||
| 1801 | input Real inFlowStates; | ||
| 1802 | output Real fmi_z[numberOfEventIndicators]; | ||
| 1803 | external "C" fmi1GetEventIndicators_OMC(fmi1me, numberOfEventIndicators, inFlowStates, fmi_z) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1804 | end fmi1GetEventIndicators; | ||
| 1805 | |||
| 1806 | function fmi1GetReal | ||
| 1807 | input FMI1ModelExchange fmi1me; | ||
| 1808 | input Real realValuesReferences[:]; | ||
| 1809 | input Real inFlowStatesInput; | ||
| 1810 | output Real realValues[size(realValuesReferences, 1)]; | ||
| 1811 | external "C" fmi1GetReal_OMC(fmi1me, size(realValuesReferences, 1), realValuesReferences, inFlowStatesInput, realValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1812 | end fmi1GetReal; | ||
| 1813 | |||
| 1814 | function fmi1SetReal | ||
| 1815 | input FMI1ModelExchange fmi1me; | ||
| 1816 | input Real realValueReferences[:]; | ||
| 1817 | input Real realValues[size(realValueReferences, 1)]; | ||
| 1818 | output Real outValues[size(realValueReferences, 1)] = realValues; | ||
| 1819 | external "C" fmi1SetReal_OMC(fmi1me, size(realValueReferences, 1), realValueReferences, realValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1820 | end fmi1SetReal; | ||
| 1821 | |||
| 1822 | function fmi1SetRealParameter | ||
| 1823 | input FMI1ModelExchange fmi1me; | ||
| 1824 | input Real realValueReferences[:]; | ||
| 1825 | input Real realValues[size(realValueReferences, 1)]; | ||
| 1826 | output Real out_Value = 1; | ||
| 1827 | external "C" fmi1SetReal_OMC(fmi1me, size(realValueReferences, 1), realValueReferences, realValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1828 | end fmi1SetRealParameter; | ||
| 1829 | |||
| 1830 | function fmi1GetInteger | ||
| 1831 | input FMI1ModelExchange fmi1me; | ||
| 1832 | input Real integerValueReferences[:]; | ||
| 1833 | input Real inFlowStatesInput; | ||
| 1834 | output Integer integerValues[size(integerValueReferences, 1)]; | ||
| 1835 | external "C" fmi1GetInteger_OMC(fmi1me, size(integerValueReferences, 1), integerValueReferences, inFlowStatesInput, integerValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1836 | end fmi1GetInteger; | ||
| 1837 | |||
| 1838 | function fmi1SetInteger | ||
| 1839 | input FMI1ModelExchange fmi1me; | ||
| 1840 | input Real integerValuesReferences[:]; | ||
| 1841 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 1842 | output Integer outValues[size(integerValuesReferences, 1)] = integerValues; | ||
| 1843 | external "C" fmi1SetInteger_OMC(fmi1me, size(integerValuesReferences, 1), integerValuesReferences, integerValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1844 | end fmi1SetInteger; | ||
| 1845 | |||
| 1846 | function fmi1SetIntegerParameter | ||
| 1847 | input FMI1ModelExchange fmi1me; | ||
| 1848 | input Real integerValuesReferences[:]; | ||
| 1849 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 1850 | output Real out_Value = 1; | ||
| 1851 | external "C" fmi1SetInteger_OMC(fmi1me, size(integerValuesReferences, 1), integerValuesReferences, integerValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1852 | end fmi1SetIntegerParameter; | ||
| 1853 | |||
| 1854 | function fmi1GetBoolean | ||
| 1855 | input FMI1ModelExchange fmi1me; | ||
| 1856 | input Real booleanValuesReferences[:]; | ||
| 1857 | input Real inFlowStatesInput; | ||
| 1858 | output Boolean booleanValues[size(booleanValuesReferences, 1)]; | ||
| 1859 | external "C" fmi1GetBoolean_OMC(fmi1me, size(booleanValuesReferences, 1), booleanValuesReferences, inFlowStatesInput, booleanValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1860 | end fmi1GetBoolean; | ||
| 1861 | |||
| 1862 | function fmi1SetBoolean | ||
| 1863 | input FMI1ModelExchange fmi1me; | ||
| 1864 | input Real booleanValueReferences[:]; | ||
| 1865 | input Boolean booleanValues[size(booleanValueReferences, 1)]; | ||
| 1866 | output Boolean outValues[size(booleanValueReferences, 1)] = booleanValues; | ||
| 1867 | external "C" fmi1SetBoolean_OMC(fmi1me, size(booleanValueReferences, 1), booleanValueReferences, booleanValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1868 | end fmi1SetBoolean; | ||
| 1869 | |||
| 1870 | function fmi1SetBooleanParameter | ||
| 1871 | input FMI1ModelExchange fmi1me; | ||
| 1872 | input Real booleanValueReferences[:]; | ||
| 1873 | input Boolean booleanValues[size(booleanValueReferences, 1)]; | ||
| 1874 | output Real out_Value = 1; | ||
| 1875 | external "C" fmi1SetBoolean_OMC(fmi1me, size(booleanValueReferences, 1), booleanValueReferences, booleanValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1876 | end fmi1SetBooleanParameter; | ||
| 1877 | |||
| 1878 | function fmi1GetString | ||
| 1879 | input FMI1ModelExchange fmi1me; | ||
| 1880 | input Real stringValuesReferences[:]; | ||
| 1881 | input Real inFlowStatesInput; | ||
| 1882 | output String stringValues[size(stringValuesReferences, 1)]; | ||
| 1883 | external "C" fmi1GetString_OMC(fmi1me, size(stringValuesReferences, 1), stringValuesReferences, inFlowStatesInput, stringValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1884 | end fmi1GetString; | ||
| 1885 | |||
| 1886 | function fmi1SetString | ||
| 1887 | input FMI1ModelExchange fmi1me; | ||
| 1888 | input Real stringValueReferences[:]; | ||
| 1889 | input String stringValues[size(stringValueReferences, 1)]; | ||
| 1890 | output String outValues[size(stringValueReferences, 1)] = stringValues; | ||
| 1891 | external "C" fmi1SetString_OMC(fmi1me, size(stringValueReferences, 1), stringValueReferences, stringValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1892 | end fmi1SetString; | ||
| 1893 | |||
| 1894 | function fmi1SetStringParameter | ||
| 1895 | input FMI1ModelExchange fmi1me; | ||
| 1896 | input Real stringValueReferences[:]; | ||
| 1897 | input String stringValues[size(stringValueReferences, 1)]; | ||
| 1898 | output Real out_Value = 1; | ||
| 1899 | external "C" fmi1SetString_OMC(fmi1me, size(stringValueReferences, 1), stringValueReferences, stringValues, 1) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1900 | end fmi1SetStringParameter; | ||
| 1901 | |||
| 1902 | function fmi1EventUpdate | ||
| 1903 | input FMI1ModelExchange fmi1me; | ||
| 1904 | input Boolean intermediateResults; | ||
| 1905 | output Boolean outNewStatesAvailable; | ||
| 1906 | external "C" outNewStatesAvailable = fmi1EventUpdate_OMC(fmi1me, intermediateResults) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1907 | end fmi1EventUpdate; | ||
| 1908 | |||
| 1909 | function fmi1nextEventTime | ||
| 1910 | input FMI1ModelExchange fmi1me; | ||
| 1911 | input Real inFlowStates; | ||
| 1912 | output Real outNewnextTime; | ||
| 1913 | external "C" outNewnextTime = fmi1nextEventTime_OMC(fmi1me, inFlowStates) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1914 | end fmi1nextEventTime; | ||
| 1915 | |||
| 1916 | function fmi1CompletedIntegratorStep | ||
| 1917 | input FMI1ModelExchange fmi1me; | ||
| 1918 | input Real inFlowStates; | ||
| 1919 | output Boolean outCallEventUpdate; | ||
| 1920 | external "C" outCallEventUpdate = fmi1CompletedIntegratorStep_OMC(fmi1me, inFlowStates) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 1921 | end fmi1CompletedIntegratorStep; | ||
| 1922 | end fmi1Functions; | ||
| 1923 | end <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%>; | ||
| 1924 | >> | ||
| 1925 | end importFMU1ModelExchange; | ||
| 1926 | |||
| 1927 | 14 | template importFMU2ModelExchange(FmiImport fmi, String name) | |
| 1928 | "Generates Modelica code for FMI Model Exchange version 2.0" | ||
| 1929 | ::= | ||
| 1930 | match fmi | ||
| 1931 | case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)) then | ||
| 1932 | /* Get Real parameters and their value references */ | ||
| 1933 | let realParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 1, "2.0") | ||
| 1934 | let realParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 2, "2.0") | ||
| 1935 | /* Get Integer parameters and their value references */ | ||
| 1936 | let integerParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 1, "2.0") | ||
| 1937 | let integerParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 2, "2.0") | ||
| 1938 | /* Get Boolean parameters and their value references */ | ||
| 1939 | let booleanParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 1, "2.0") | ||
| 1940 | let booleanParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 2, "2.0") | ||
| 1941 | /* Get String parameters and their value references */ | ||
| 1942 | let stringParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 1, "2.0") | ||
| 1943 | let stringParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 2, "2.0") | ||
| 1944 | /* Get dependent Real parameters and their value references */ | ||
| 1945 | let realDependentParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 1, "2.0") | ||
| 1946 | let realDependentParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 2, "2.0") | ||
| 1947 | /* Get dependent Integer parameters and their value references */ | ||
| 1948 | let integerDependentParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 1, "2.0") | ||
| 1949 | let integerDependentParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 2, "2.0") | ||
| 1950 | /* Get dependent Boolean parameters and their value references */ | ||
| 1951 | let booleanDependentParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 1, "2.0") | ||
| 1952 | let booleanDependentParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 2, "2.0") | ||
| 1953 | /* Get dependent String parameters and their value references */ | ||
| 1954 | let stringDependentParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 1, "2.0") | ||
| 1955 | let stringDependentParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 2, "2.0") | ||
| 1956 | /* Get input Real varibales and their value references */ | ||
| 1957 | let nRealInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "real", "input")) | ||
| 1958 | let realInputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "input", false, 1, "2.0") | ||
| 1959 | let realInputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 2, "2.0") | ||
| 1960 | let realInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 3, "2.0") | ||
| 1961 | /* Get input Integer varibales and their value references */ | ||
| 1962 | let nIntegerInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "integer", "input")) | ||
| 1963 | let integerInputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "input", false, 1, "2.0") | ||
| 1964 | let integerInputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 2, "2.0") | ||
| 1965 | let integerInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 3, "2.0") | ||
| 1966 | /* Get input Boolean varibales and their value references */ | ||
| 1967 | let nBooleanInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "boolean", "input")) | ||
| 1968 | let booleanInputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 1, "2.0") | ||
| 1969 | let booleanInputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 2, "2.0") | ||
| 1970 | let booleanInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 3, "2.0") | ||
| 1971 | /* Get input String varibales and their value references */ | ||
| 1972 | let nStringInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "string", "input")) | ||
| 1973 | let stringInputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "input", false, 1, "2.0") | ||
| 1974 | let stringStartVariablesNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 2, "2.0") | ||
| 1975 | let stringInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 3, "2.0") | ||
| 1976 | /* Get event input Real varibales and their value references */ | ||
| 1977 | let nRealEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "real", "input")) | ||
| 1978 | let realEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "input", false, 1, "2.0") | ||
| 1979 | let realEventInputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 2, "2.0") | ||
| 1980 | let realEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 3, "2.0") | ||
| 1981 | /* Get event input Integer varibales and their value references */ | ||
| 1982 | let nIntegerEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "integer", "input")) | ||
| 1983 | let integerEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "input", false, 1, "2.0") | ||
| 1984 | let integerEventInputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 2, "2.0") | ||
| 1985 | let integerEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 3, "2.0") | ||
| 1986 | /* Get event input Boolean varibales and their value references */ | ||
| 1987 | let nBooleanEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "boolean", "input")) | ||
| 1988 | let booleanEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 1, "2.0") | ||
| 1989 | let booleanEventInputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 2, "2.0") | ||
| 1990 | let booleanEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 3, "2.0") | ||
| 1991 | /* Get event input String varibales and their value references */ | ||
| 1992 | let nStringEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "string", "input")) | ||
| 1993 | let stringEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "input", false, 1, "2.0") | ||
| 1994 | let stringEventStartVariablesNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 2, "2.0") | ||
| 1995 | let stringEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 3, "2.0") | ||
| 1996 | /* Get output Real varibales and their value references */ | ||
| 1997 | let realOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "output", false, 1, "2.0") | ||
| 1998 | let realOutputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "output", false, 2, "2.0") | ||
| 1999 | /* Get output Integer varibales and their value references */ | ||
| 2000 | let integerOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "output", false, 1, "2.0") | ||
| 2001 | let integerOutputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "output", false, 2, "2.0") | ||
| 2002 | /* Get output Boolean varibales and their value references */ | ||
| 2003 | let booleanOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 1, "2.0") | ||
| 2004 | let booleanOutputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 2, "2.0") | ||
| 2005 | /* Get output String varibales and their value references */ | ||
| 2006 | let stringOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "output", false, 1, "2.0") | ||
| 2007 | let stringOutputVariablesNames = dumpVariables(fmiModelVariablesList, "string", "output", false, 2, "2.0") | ||
| 2008 | << | ||
| 2009 | model <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%><%if stringEq(fmiInfo.fmiDescription, "") then "" else " \""+fmiInfo.fmiDescription+"\""%> | ||
| 2010 | <%dumpFMITypeDefinitions(fmiTypeDefinitionsList)%> | ||
| 2011 | constant String fmuWorkingDir = "<%fmuWorkingDirectory%>"; | ||
| 2012 | parameter Integer logLevel = <%fmiLogLevel%> "log level used during the loading of FMU" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 2013 | parameter Boolean debugLogging = <%fmiDebugOutput%> "enables the FMU simulation logging" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 2014 | <%dumpFMIModelVariablesList("2.0", fmiModelVariablesList, fmiTypeDefinitionsList, generateInputConnectors, generateOutputConnectors)%> | ||
| 2015 | protected | ||
| 2016 | FMI2ModelExchange fmi2me = FMI2ModelExchange(logLevel, fmuWorkingDir, "<%fmiInfo.fmiModelIdentifier%>", debugLogging); | ||
| 2017 | constant Integer numberOfContinuousStates = <%listLength(fmiInfo.fmiNumberOfContinuousStates)%>; | ||
| 2018 | Real fmi_x[numberOfContinuousStates] "States"; | ||
| 2019 | Real fmi_x_new[numberOfContinuousStates](each fixed=true) "New States"; | ||
| 2020 | constant Integer numberOfEventIndicators = <%listLength(fmiInfo.fmiNumberOfEventIndicators)%>; | ||
| 2021 | Real fmi_z[numberOfEventIndicators] "Events Indicators"; | ||
| 2022 | Boolean fmi_z_positive[numberOfEventIndicators](each fixed=true); | ||
| 2023 | parameter Real flowStartTime(fixed=false); | ||
| 2024 | Real flowTime; | ||
| 2025 | parameter Real flowEnterInitialization(fixed=false); | ||
| 2026 | parameter Real flowInitialized(fixed=false); | ||
| 2027 | parameter Real flowParamsStart(fixed=false); | ||
| 2028 | parameter Real flowInitInputs(fixed=false); | ||
| 2029 | Real flowStatesInputs; | ||
| 2030 | <%if not stringEq(realInputVariablesVRs, "") then "Real realInputVariables["+nRealInputVariables+"];"%> | ||
| 2031 | <%if not stringEq(realInputVariablesVRs, "") then "Real "+realInputVariablesReturnNames+";"%> | ||
| 2032 | <%if not stringEq(integerInputVariablesVRs, "") then "Integer integerInputVariables["+nIntegerInputVariables+"];"%> | ||
| 2033 | <%if not stringEq(integerInputVariablesVRs, "") then "Integer "+integerInputVariablesReturnNames+";"%> | ||
| 2034 | <%if not stringEq(booleanInputVariablesVRs, "") then "Boolean booleanInputVariables["+nBooleanInputVariables+"];"%> | ||
| 2035 | <%if not stringEq(booleanInputVariablesVRs, "") then "Boolean "+booleanInputVariablesReturnNames+";"%> | ||
| 2036 | <%if not stringEq(stringInputVariablesVRs, "") then "String stringInputVariables["+nStringInputVariables+"];"%> | ||
| 2037 | <%if not stringEq(stringInputVariablesVRs, "") then "String "+stringInputVariablesReturnNames+";"%> | ||
| 2038 | <%if not stringEq(realEventInputVariablesVRs, "") then "Real realEventInputVariables["+nRealEventInputVariables+"](each fixed=true);"%> | ||
| 2039 | <%if not stringEq(integerEventInputVariablesVRs, "") then "Integer integerEventInputVariables["+nIntegerEventInputVariables+"](each fixed=true);"%> | ||
| 2040 | <%if not stringEq(booleanEventInputVariablesVRs, "") then "Boolean booleanEventInputVariables["+nBooleanEventInputVariables+"](each fixed=true);"%> | ||
| 2041 | <%if not stringEq(stringEventInputVariablesVRs, "") then "String stringEventInputVariables["+nStringEventInputVariables+"](each fixed=true);"%> | ||
| 2042 | Boolean callEventUpdate; | ||
| 2043 | Boolean newStatesAvailable(fixed = true); | ||
| 2044 | Real triggerDSSEvent; | ||
| 2045 | Real nextEventTime(fixed = true); | ||
| 2046 | initial equation | ||
| 2047 | <%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then | ||
| 2048 | << | ||
| 2049 | fmi_x = fmi2Functions.fmi2GetContinuousStates(fmi2me, numberOfContinuousStates, flowParamsStart+flowInitialized); | ||
| 2050 | >> | ||
| 2051 | %> | ||
| 2052 | initial algorithm | ||
| 2053 | flowParamsStart := 1; | ||
| 2054 | flowInitInputs := 1; | ||
| 2055 | flowStartTime := fmi2Functions.fmi2SetupExperiment(fmi2me, false, 0.0, time, false, 0.0, flowParamsStart+flowInitInputs); | ||
| 2056 | flowEnterInitialization := fmi2Functions.fmi2EnterInitialization(fmi2me, flowParamsStart+flowInitInputs+flowStartTime); | ||
| 2057 | /* the parameters must be set while the FMU is still in Initialization Mode, | ||
| 2058 | otherwise the FMU computes its calculated parameters from the default values */ | ||
| 2059 | <%if not stringEq(realParametersVRs, "") then "flowParamsStart := fmi2Functions.fmi2SetRealParameter(fmi2me, {"+realParametersVRs+"}, {"+realParametersNames+"});"%> | ||
| 2060 | <%if not stringEq(integerParametersVRs, "") then "flowParamsStart := fmi2Functions.fmi2SetIntegerParameter(fmi2me, {"+integerParametersVRs+"}, {"+integerParametersNames+"});"%> | ||
| 2061 | <%if not stringEq(booleanParametersVRs, "") then "flowParamsStart := fmi2Functions.fmi2SetBooleanParameter(fmi2me, {"+booleanParametersVRs+"}, {"+booleanParametersNames+"});"%> | ||
| 2062 | <%if not stringEq(stringParametersVRs, "") then "flowParamsStart := fmi2Functions.fmi2SetStringParameter(fmi2me, {"+stringParametersVRs+"}, {"+stringParametersNames+"});"%> | ||
| 2063 | flowInitialized := fmi2Functions.fmi2ExitInitialization(fmi2me, flowParamsStart+flowInitInputs+flowStartTime+flowEnterInitialization); | ||
| 2064 | initial equation | ||
| 2065 | <%if not stringEq(realDependentParametersVRs, "") then "{"+realDependentParametersNames+"} = fmi2Functions.fmi2GetReal(fmi2me, {"+realDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2066 | <%if not stringEq(integerDependentParametersVRs, "") then "{"+integerDependentParametersNames+"} = fmi2Functions.fmi2GetInteger(fmi2me, {"+integerDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2067 | <%if not stringEq(booleanDependentParametersVRs, "") then "{"+booleanDependentParametersNames+"} = fmi2Functions.fmi2GetBoolean(fmi2me, {"+booleanDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2068 | <%if not stringEq(stringDependentParametersVRs, "") then "{"+stringDependentParametersNames+"} = fmi2Functions.fmi2GetString(fmi2me, {"+stringDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2069 | algorithm | ||
| 2070 | flowTime := if not initial() then fmi2Functions.fmi2SetTime(fmi2me, time, flowInitialized) else time; | ||
| 2071 | /* algorithm section ensures that inputs to fmi (if any) are set directly after the new time is set */ | ||
| 2072 | <%if not stringEq(realInputVariablesVRs, "") then "realInputVariables := fmi2Functions.fmi2SetReal(fmi2me, {"+realInputVariablesVRs+"}, {"+realInputVariablesNames+"});"%> | ||
| 2073 | <%if not stringEq(integerInputVariablesVRs, "") then "integerInputVariables := fmi2Functions.fmi2SetInteger(fmi2me, {"+integerInputVariablesVRs+"}, {"+integerInputVariablesNames+"});"%> | ||
| 2074 | <%if not stringEq(booleanInputVariablesVRs, "") then "booleanInputVariables := fmi2Functions.fmi2SetBoolean(fmi2me, {"+booleanInputVariablesVRs+"}, {"+booleanInputVariablesNames+"});"%> | ||
| 2075 | <%if not stringEq(stringInputVariablesVRs, "") then "stringInputVariables := fmi2Functions.fmi2SetString(fmi2me, {"+stringInputVariablesVRs+"}, {"+stringStartVariablesNames+"});"%> | ||
| 2076 | equation | ||
| 2077 | <%if not stringEq(realInputVariablesVRs, "") then "{"+realInputVariablesReturnNames+"} = realInputVariables;"%> | ||
| 2078 | <%if not stringEq(integerInputVariablesVRs, "") then "{"+integerInputVariablesReturnNames+"} = integerInputVariables;"%> | ||
| 2079 | <%if not stringEq(booleanInputVariablesVRs, "") then "{"+booleanInputVariablesReturnNames+"} = booleanInputVariables;"%> | ||
| 2080 | <%if not stringEq(stringInputVariablesVRs, "") then "{"+stringInputVariablesReturnNames+"} = stringInputVariables;"%> | ||
| 2081 | flowStatesInputs = fmi2Functions.fmi2SetContinuousStates(fmi2me, fmi_x, flowParamsStart + flowTime); | ||
| 2082 | der(fmi_x) = fmi2Functions.fmi2GetDerivatives(fmi2me, numberOfContinuousStates, flowStatesInputs); | ||
| 2083 | fmi_z = fmi2Functions.fmi2GetEventIndicators(fmi2me, numberOfEventIndicators, flowStatesInputs); | ||
| 2084 | for i in 1:size(fmi_z,1) loop | ||
| 2085 | fmi_z_positive[i] = if not terminal() then fmi_z[i] > 0 else pre(fmi_z_positive[i]); | ||
| 2086 | end for; | ||
| 2087 | |||
| 2088 | triggerDSSEvent = noEvent(if callEventUpdate then flowStatesInputs+1.0 else flowStatesInputs-1.0); | ||
| 2089 | |||
| 2090 | <%if not boolAnd(stringEq(realOutputVariablesNames, ""), stringEq(realOutputVariablesVRs, "")) then "{"+realOutputVariablesNames+"} = fmi2Functions.fmi2GetReal(fmi2me, {"+realOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2091 | <%if not boolAnd(stringEq(integerOutputVariablesNames, ""), stringEq(integerOutputVariablesVRs, "")) then "{"+integerOutputVariablesNames+"} = fmi2Functions.fmi2GetInteger(fmi2me, {"+integerOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2092 | <%if not boolAnd(stringEq(booleanOutputVariablesNames, ""), stringEq(booleanOutputVariablesVRs, "")) then "{"+booleanOutputVariablesNames+"} = fmi2Functions.fmi2GetBoolean(fmi2me, {"+booleanOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2093 | <%if not boolAnd(stringEq(stringOutputVariablesNames, ""), stringEq(stringOutputVariablesVRs, "")) then "{"+stringOutputVariablesNames+"} = fmi2Functions.fmi2GetString(fmi2me, {"+stringOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2094 | <%dumpOutputGetEnumerationVariables(fmiModelVariablesList, fmiTypeDefinitionsList, "fmi2Functions.fmi2GetInteger", "fmi2me")%> | ||
| 2095 | callEventUpdate = fmi2Functions.fmi2CompletedIntegratorStep(fmi2me, flowStatesInputs+flowTime); | ||
| 2096 | algorithm | ||
| 2097 | <%if intGt(listLength(fmiInfo.fmiNumberOfEventIndicators), 0) then | ||
| 2098 | << | ||
| 2099 | when {<%fmiInfo.fmiNumberOfEventIndicators |> eventIndicator => "change(fmi_z_positive["+eventIndicator+"])" ;separator=" or "%>, triggerDSSEvent > flowStatesInputs, pre(nextEventTime) < time, terminal()} then | ||
| 2100 | >> | ||
| 2101 | else | ||
| 2102 | << | ||
| 2103 | when {triggerDSSEvent > flowStatesInputs, pre(nextEventTime) < time, terminal()} then | ||
| 2104 | >> | ||
| 2105 | %> | ||
| 2106 | fmi2Functions.fmi2StartEventUpdate(fmi2me); | ||
| 2107 | <%if not stringEq(realEventInputVariablesVRs, "") then "realEventInputVariables := fmi2Functions.fmi2SetReal(fmi2me, {"+realEventInputVariablesVRs+"}, {"+realEventInputVariablesNames+"});"%> | ||
| 2108 | <%if not stringEq(integerEventInputVariablesVRs, "") then "integerEventInputVariables := fmi2Functions.fmi2SetInteger(fmi2me, {"+integerEventInputVariablesVRs+"}, {"+integerEventInputVariablesNames+"});"%> | ||
| 2109 | <%if not stringEq(booleanEventInputVariablesVRs, "") then "booleanEventInputVariables := fmi2Functions.fmi2SetBoolean(fmi2me, {"+booleanEventInputVariablesVRs+"}, {"+booleanEventInputVariablesNames+"});"%> | ||
| 2110 | <%if not stringEq(stringEventInputVariablesVRs, "") then "stringEventInputVariables := fmi2Functions.fmi2SetString(fmi2me, {"+stringEventInputVariablesVRs+"}, {"+stringEventStartVariablesNames+"});"%> | ||
| 2111 | newStatesAvailable := fmi2Functions.fmi2EndEventUpdate(fmi2me); | ||
| 2112 | nextEventTime := fmi2Functions.fmi2nextEventTime(fmi2me, flowStatesInputs); | ||
| 2113 | <%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then | ||
| 2114 | << | ||
| 2115 | if newStatesAvailable then | ||
| 2116 | fmi_x_new := fmi2Functions.fmi2GetContinuousStates(fmi2me, numberOfContinuousStates, flowStatesInputs); | ||
| 2117 | <%fmiInfo.fmiNumberOfContinuousStates |> continuousStates => "reinit(fmi_x["+continuousStates+"], fmi_x_new["+continuousStates+"]);" ;separator="\n"%> | ||
| 2118 | end if; | ||
| 2119 | >> | ||
| 2120 | %> | ||
| 2121 | end when; | ||
| 2122 | annotation(experiment(StartTime=<%fmiExperimentAnnotation.fmiExperimentStartTime%>, StopTime=<%fmiExperimentAnnotation.fmiExperimentStopTime%>, Tolerance=<%fmiExperimentAnnotation.fmiExperimentTolerance%>)); | ||
| 2123 | annotation (Icon(graphics={ | ||
| 2124 | Rectangle( | ||
| 2125 | extent={{-100,100},{100,-100}}, | ||
| 2126 | lineColor={0,0,0}, | ||
| 2127 | fillColor={240,240,240}, | ||
| 2128 | fillPattern=FillPattern.Solid, | ||
| 2129 | lineThickness=0.5), | ||
| 2130 | Text( | ||
| 2131 | extent={{-100,40},{100,0}}, | ||
| 2132 | lineColor={0,0,0}, | ||
| 2133 | textString="%name"), | ||
| 2134 | Text( | ||
| 2135 | extent={{-100,-50},{100,-90}}, | ||
| 2136 | lineColor={0,0,0}, | ||
| 2137 | textString="V2.0")})); | ||
| 2138 | protected | ||
| 2139 | class FMI2ModelExchange | ||
| 2140 | extends ExternalObject; | ||
| 2141 | function constructor | ||
| 2142 | input Integer logLevel; | ||
| 2143 | input String workingDirectory; | ||
| 2144 | input String instanceName; | ||
| 2145 | input Boolean debugLogging; | ||
| 2146 | output FMI2ModelExchange fmi2me; | ||
| 2147 | external "C" fmi2me = FMI2ModelExchangeConstructor_OMC(logLevel, workingDirectory, instanceName, debugLogging) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2148 | end constructor; | ||
| 2149 | |||
| 2150 | function destructor | ||
| 2151 | input FMI2ModelExchange fmi2me; | ||
| 2152 | external "C" FMI2ModelExchangeDestructor_OMC(fmi2me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2153 | end destructor; | ||
| 2154 | end FMI2ModelExchange; | ||
| 2155 | |||
| 2156 | <%dumpFMITypeDefinitionsMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 2157 | |||
| 2158 | <%dumpFMITypeDefinitionsArrayMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 2159 | |||
| 2160 | package fmi2Functions | ||
| 2161 | function fmi2SetupExperiment | ||
| 2162 | input FMI2ModelExchange fmi2me; | ||
| 2163 | input Boolean inToleranceDefined; | ||
| 2164 | input Real inTolerance; | ||
| 2165 | input Real inStartTime; | ||
| 2166 | input Boolean inStopTimeDefined; | ||
| 2167 | input Real inStopTime; | ||
| 2168 | input Real inFlow; | ||
| 2169 | output Real outFlow = inFlow; | ||
| 2170 | external "C" fmi2SetupExperiment_OMC(fmi2me, inToleranceDefined, inTolerance, inStartTime, inStopTimeDefined, inStopTime) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2171 | end fmi2SetupExperiment; | ||
| 2172 | |||
| 2173 | function fmi2SetTime | ||
| 2174 | input FMI2ModelExchange fmi2me; | ||
| 2175 | input Real inTime; | ||
| 2176 | input Real inFlow; | ||
| 2177 | output Real outFlow = inFlow; | ||
| 2178 | external "C" fmi2SetTime_OMC(fmi2me, inTime) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2179 | end fmi2SetTime; | ||
| 2180 | |||
| 2181 | function fmi2EnterInitialization | ||
| 2182 | input FMI2ModelExchange fmi2me; | ||
| 2183 | input Real inFlowVariable; | ||
| 2184 | output Real outFlowVariable = inFlowVariable; | ||
| 2185 | external "C" fmi2EnterInitializationModel_OMC(fmi2me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2186 | end fmi2EnterInitialization; | ||
| 2187 | |||
| 2188 | function fmi2ExitInitialization | ||
| 2189 | input FMI2ModelExchange fmi2me; | ||
| 2190 | input Real inFlowVariable; | ||
| 2191 | output Real outFlowVariable = inFlowVariable; | ||
| 2192 | external "C" fmi2ExitInitializationModel_OMC(fmi2me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2193 | end fmi2ExitInitialization; | ||
| 2194 | |||
| 2195 | function fmi2GetContinuousStates | ||
| 2196 | input FMI2ModelExchange fmi2me; | ||
| 2197 | input Integer numberOfContinuousStates; | ||
| 2198 | input Real inFlowParams; | ||
| 2199 | output Real fmi_x[numberOfContinuousStates]; | ||
| 2200 | external "C" fmi2GetContinuousStates_OMC(fmi2me, numberOfContinuousStates, inFlowParams, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2201 | end fmi2GetContinuousStates; | ||
| 2202 | |||
| 2203 | function fmi2SetContinuousStates | ||
| 2204 | input FMI2ModelExchange fmi2me; | ||
| 2205 | input Real fmi_x[:]; | ||
| 2206 | input Real inFlowParams; | ||
| 2207 | output Real outFlowStates; | ||
| 2208 | external "C" outFlowStates = fmi2SetContinuousStates_OMC(fmi2me, size(fmi_x, 1), inFlowParams, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2209 | end fmi2SetContinuousStates; | ||
| 2210 | |||
| 2211 | function fmi2GetDerivatives | ||
| 2212 | input FMI2ModelExchange fmi2me; | ||
| 2213 | input Integer numberOfContinuousStates; | ||
| 2214 | input Real inFlowStates; | ||
| 2215 | output Real fmi_x[numberOfContinuousStates]; | ||
| 2216 | external "C" fmi2GetDerivatives_OMC(fmi2me, numberOfContinuousStates, inFlowStates, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2217 | end fmi2GetDerivatives; | ||
| 2218 | |||
| 2219 | function fmi2GetEventIndicators | ||
| 2220 | input FMI2ModelExchange fmi2me; | ||
| 2221 | input Integer numberOfEventIndicators; | ||
| 2222 | input Real inFlowStates; | ||
| 2223 | output Real fmi_z[numberOfEventIndicators]; | ||
| 2224 | external "C" fmi2GetEventIndicators_OMC(fmi2me, numberOfEventIndicators, inFlowStates, fmi_z) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2225 | end fmi2GetEventIndicators; | ||
| 2226 | |||
| 2227 | function fmi2GetReal | ||
| 2228 | input FMI2ModelExchange fmi2me; | ||
| 2229 | input Real realValuesReferences[:]; | ||
| 2230 | input Real inFlowStatesInput; | ||
| 2231 | output Real realValues[size(realValuesReferences, 1)]; | ||
| 2232 | external "C" fmi2GetReal_OMC(fmi2me, size(realValuesReferences, 1), realValuesReferences, inFlowStatesInput, realValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2233 | end fmi2GetReal; | ||
| 2234 | |||
| 2235 | function fmi2SetReal | ||
| 2236 | input FMI2ModelExchange fmi2me; | ||
| 2237 | input Real realValueReferences[:]; | ||
| 2238 | input Real realValues[size(realValueReferences, 1)]; | ||
| 2239 | output Real outValues[size(realValueReferences, 1)] = realValues; | ||
| 2240 | external "C" fmi2SetReal_OMC(fmi2me, size(realValueReferences, 1), realValueReferences, realValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2241 | end fmi2SetReal; | ||
| 2242 | |||
| 2243 | function fmi2SetRealParameter | ||
| 2244 | input FMI2ModelExchange fmi2me; | ||
| 2245 | input Real realValueReferences[:]; | ||
| 2246 | input Real realValues[size(realValueReferences, 1)]; | ||
| 2247 | output Real out_Value = 1; | ||
| 2248 | external "C" fmi2SetReal_OMC(fmi2me, size(realValueReferences, 1), realValueReferences, realValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2249 | end fmi2SetRealParameter; | ||
| 2250 | |||
| 2251 | function fmi2GetInteger | ||
| 2252 | input FMI2ModelExchange fmi2me; | ||
| 2253 | input Real integerValueReferences[:]; | ||
| 2254 | input Real inFlowStatesInput; | ||
| 2255 | output Integer integerValues[size(integerValueReferences, 1)]; | ||
| 2256 | external "C" fmi2GetInteger_OMC(fmi2me, size(integerValueReferences, 1), integerValueReferences, inFlowStatesInput, integerValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2257 | end fmi2GetInteger; | ||
| 2258 | |||
| 2259 | function fmi2SetInteger | ||
| 2260 | input FMI2ModelExchange fmi2me; | ||
| 2261 | input Real integerValuesReferences[:]; | ||
| 2262 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 2263 | output Integer outValues[size(integerValuesReferences, 1)] = integerValues; | ||
| 2264 | external "C" fmi2SetInteger_OMC(fmi2me, size(integerValuesReferences, 1), integerValuesReferences, integerValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2265 | end fmi2SetInteger; | ||
| 2266 | |||
| 2267 | function fmi2SetIntegerParameter | ||
| 2268 | input FMI2ModelExchange fmi2me; | ||
| 2269 | input Real integerValuesReferences[:]; | ||
| 2270 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 2271 | output Real out_Value = 1; | ||
| 2272 | external "C" fmi2SetInteger_OMC(fmi2me, size(integerValuesReferences, 1), integerValuesReferences, integerValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2273 | end fmi2SetIntegerParameter; | ||
| 2274 | |||
| 2275 | function fmi2GetBoolean | ||
| 2276 | input FMI2ModelExchange fmi2me; | ||
| 2277 | input Real booleanValuesReferences[:]; | ||
| 2278 | input Real inFlowStatesInput; | ||
| 2279 | output Boolean booleanValues[size(booleanValuesReferences, 1)]; | ||
| 2280 | external "C" fmi2GetBoolean_OMC(fmi2me, size(booleanValuesReferences, 1), booleanValuesReferences, inFlowStatesInput, booleanValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2281 | end fmi2GetBoolean; | ||
| 2282 | |||
| 2283 | function fmi2SetBoolean | ||
| 2284 | input FMI2ModelExchange fmi2me; | ||
| 2285 | input Real booleanValueReferences[:]; | ||
| 2286 | input Boolean booleanValues[size(booleanValueReferences, 1)]; | ||
| 2287 | output Boolean outValues[size(booleanValueReferences, 1)] = booleanValues; | ||
| 2288 | external "C" fmi2SetBoolean_OMC(fmi2me, size(booleanValueReferences, 1), booleanValueReferences, booleanValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2289 | end fmi2SetBoolean; | ||
| 2290 | |||
| 2291 | function fmi2SetBooleanParameter | ||
| 2292 | input FMI2ModelExchange fmi2me; | ||
| 2293 | input Real booleanValueReferences[:]; | ||
| 2294 | input Boolean booleanValues[size(booleanValueReferences, 1)]; | ||
| 2295 | output Real out_Value = 1; | ||
| 2296 | external "C" fmi2SetBoolean_OMC(fmi2me, size(booleanValueReferences, 1), booleanValueReferences, booleanValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2297 | end fmi2SetBooleanParameter; | ||
| 2298 | |||
| 2299 | function fmi2GetString | ||
| 2300 | input FMI2ModelExchange fmi2me; | ||
| 2301 | input Real stringValuesReferences[:]; | ||
| 2302 | input Real inFlowStatesInput; | ||
| 2303 | output String stringValues[size(stringValuesReferences, 1)]; | ||
| 2304 | external "C" fmi2GetString_OMC(fmi2me, size(stringValuesReferences, 1), stringValuesReferences, inFlowStatesInput, stringValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2305 | end fmi2GetString; | ||
| 2306 | |||
| 2307 | function fmi2SetString | ||
| 2308 | input FMI2ModelExchange fmi2me; | ||
| 2309 | input Real stringValueReferences[:]; | ||
| 2310 | input String stringValues[size(stringValueReferences, 1)]; | ||
| 2311 | output String outValues[size(stringValueReferences, 1)] = stringValues; | ||
| 2312 | external "C" fmi2SetString_OMC(fmi2me, size(stringValueReferences, 1), stringValueReferences, stringValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2313 | end fmi2SetString; | ||
| 2314 | |||
| 2315 | function fmi2SetStringParameter | ||
| 2316 | input FMI2ModelExchange fmi2me; | ||
| 2317 | input Real stringValueReferences[:]; | ||
| 2318 | input String stringValues[size(stringValueReferences, 1)]; | ||
| 2319 | output Real out_Value = 1; | ||
| 2320 | external "C" fmi2SetString_OMC(fmi2me, size(stringValueReferences, 1), stringValueReferences, stringValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2321 | end fmi2SetStringParameter; | ||
| 2322 | |||
| 2323 | function fmi2StartEventUpdate | ||
| 2324 | input FMI2ModelExchange fmi2me; | ||
| 2325 | external "C" fmi2StartEventUpdate_OMC(fmi2me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2326 | end fmi2StartEventUpdate; | ||
| 2327 | |||
| 2328 | function fmi2EndEventUpdate | ||
| 2329 | input FMI2ModelExchange fmi2me; | ||
| 2330 | output Boolean outNewStatesAvailable; | ||
| 2331 | external "C" outNewStatesAvailable = fmi2EndEventUpdate_OMC(fmi2me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2332 | end fmi2EndEventUpdate; | ||
| 2333 | |||
| 2334 | function fmi2nextEventTime | ||
| 2335 | input FMI2ModelExchange fmi2me; | ||
| 2336 | input Real inFlowStates; | ||
| 2337 | output Real outNewnextTime; | ||
| 2338 | external "C" outNewnextTime = fmi2nextEventTime_OMC(fmi2me, inFlowStates) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2339 | end fmi2nextEventTime; | ||
| 2340 | |||
| 2341 | function fmi2CompletedIntegratorStep | ||
| 2342 | input FMI2ModelExchange fmi2me; | ||
| 2343 | input Real inFlowStates; | ||
| 2344 | output Boolean outCallEventUpdate; | ||
| 2345 | external "C" outCallEventUpdate = fmi2CompletedIntegratorStep_OMC(fmi2me, inFlowStates) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2346 | end fmi2CompletedIntegratorStep; | ||
| 2347 | end fmi2Functions; | ||
| 2348 | end <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%>; | ||
| 2349 | >> | ||
| 2350 | end importFMU2ModelExchange; | ||
| 2351 | |||
| 2352 | 1 | template importFMU3ModelExchange(FmiImport fmi, String name) | |
| 2353 | "Generates Modelica code for FMI Model Exchange version 3.0" | ||
| 2354 | ::= | ||
| 2355 | match fmi | ||
| 2356 | case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)) then | ||
| 2357 | /* Get Real parameters and their value references */ | ||
| 2358 | let realParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 1, "3.0") | ||
| 2359 | let realParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 2, "3.0") | ||
| 2360 | /* Get Integer parameters and their value references */ | ||
| 2361 | let integerParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 1, "3.0") | ||
| 2362 | let integerParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 2, "3.0") | ||
| 2363 | /* Get Boolean parameters and their value references */ | ||
| 2364 | let booleanParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 1, "3.0") | ||
| 2365 | let booleanParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 2, "3.0") | ||
| 2366 | /* Get String parameters and their value references */ | ||
| 2367 | let stringParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 1, "3.0") | ||
| 2368 | let stringParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 2, "3.0") | ||
| 2369 | /* Get dependent Real parameters and their value references */ | ||
| 2370 | let realDependentParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 1, "3.0") | ||
| 2371 | let realDependentParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 2, "3.0") | ||
| 2372 | /* Get dependent Integer parameters and their value references */ | ||
| 2373 | let integerDependentParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 1, "3.0") | ||
| 2374 | let integerDependentParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 2, "3.0") | ||
| 2375 | /* Get dependent Boolean parameters and their value references */ | ||
| 2376 | let booleanDependentParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 1, "3.0") | ||
| 2377 | let booleanDependentParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 2, "3.0") | ||
| 2378 | /* Get dependent String parameters and their value references */ | ||
| 2379 | let stringDependentParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 1, "3.0") | ||
| 2380 | let stringDependentParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 2, "3.0") | ||
| 2381 | /* Get input Real varibales and their value references */ | ||
| 2382 | let nRealInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "real", "input")) | ||
| 2383 | let realInputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "input", false, 1, "3.0") | ||
| 2384 | let realInputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 2, "3.0") | ||
| 2385 | let realInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 3, "3.0") | ||
| 2386 | /* Get input Integer varibales and their value references */ | ||
| 2387 | let nIntegerInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "integer", "input")) | ||
| 2388 | let integerInputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "input", false, 1, "3.0") | ||
| 2389 | let integerInputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 2, "3.0") | ||
| 2390 | let integerInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 3, "3.0") | ||
| 2391 | /* Get input Boolean varibales and their value references */ | ||
| 2392 | let nBooleanInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "boolean", "input")) | ||
| 2393 | let booleanInputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 1, "3.0") | ||
| 2394 | let booleanInputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 2, "3.0") | ||
| 2395 | let booleanInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 3, "3.0") | ||
| 2396 | /* Get input String varibales and their value references */ | ||
| 2397 | let nStringInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "string", "input")) | ||
| 2398 | let stringInputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "input", false, 1, "3.0") | ||
| 2399 | let stringStartVariablesNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 2, "3.0") | ||
| 2400 | let stringInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 3, "3.0") | ||
| 2401 | /* Get event input Real varibales and their value references */ | ||
| 2402 | let nRealEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "real", "input")) | ||
| 2403 | let realEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "input", false, 1, "3.0") | ||
| 2404 | let realEventInputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 2, "3.0") | ||
| 2405 | let realEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 3, "3.0") | ||
| 2406 | /* Get event input Integer varibales and their value references */ | ||
| 2407 | let nIntegerEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "integer", "input")) | ||
| 2408 | let integerEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "input", false, 1, "3.0") | ||
| 2409 | let integerEventInputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 2, "3.0") | ||
| 2410 | let integerEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 3, "3.0") | ||
| 2411 | /* Get event input Boolean varibales and their value references */ | ||
| 2412 | let nBooleanEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "boolean", "input")) | ||
| 2413 | let booleanEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 1, "3.0") | ||
| 2414 | let booleanEventInputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 2, "3.0") | ||
| 2415 | let booleanEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 3, "3.0") | ||
| 2416 | /* Get event input String varibales and their value references */ | ||
| 2417 | let nStringEventInputVariables = listLength(filterModelVariables(fmiModelVariablesList, "string", "input")) | ||
| 2418 | let stringEventInputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "input", false, 1, "3.0") | ||
| 2419 | let stringEventStartVariablesNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 2, "3.0") | ||
| 2420 | let stringEventInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 3, "3.0") | ||
| 2421 | /* Get output Real varibales and their value references */ | ||
| 2422 | let realOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "output", false, 1, "3.0") | ||
| 2423 | let realOutputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "output", false, 2, "3.0") | ||
| 2424 | /* Get output Integer varibales and their value references */ | ||
| 2425 | let integerOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "output", false, 1, "3.0") | ||
| 2426 | let integerOutputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "output", false, 2, "3.0") | ||
| 2427 | /* Get output Boolean varibales and their value references */ | ||
| 2428 | let booleanOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 1, "3.0") | ||
| 2429 | let booleanOutputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 2, "3.0") | ||
| 2430 | /* Get output String varibales and their value references */ | ||
| 2431 | let stringOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "output", false, 1, "3.0") | ||
| 2432 | let stringOutputVariablesNames = dumpVariables(fmiModelVariablesList, "string", "output", false, 2, "3.0") | ||
| 2433 | << | ||
| 2434 | model <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%><%if stringEq(fmiInfo.fmiDescription, "") then "" else " \""+fmiInfo.fmiDescription+"\""%> | ||
| 2435 | <%dumpFMITypeDefinitions(fmiTypeDefinitionsList)%> | ||
| 2436 | constant String fmuWorkingDir = "<%fmuWorkingDirectory%>"; | ||
| 2437 | parameter Integer logLevel = <%fmiLogLevel%> "log level used during the loading of FMU" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 2438 | parameter Boolean debugLogging = <%fmiDebugOutput%> "enables the FMU simulation logging" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 2439 | <%dumpFMIModelVariablesList("3.0", fmiModelVariablesList, fmiTypeDefinitionsList, generateInputConnectors, generateOutputConnectors)%> | ||
| 2440 | protected | ||
| 2441 | FMI3ModelExchange fmi3me = FMI3ModelExchange(logLevel, fmuWorkingDir, "<%fmiInfo.fmiModelIdentifier%>", debugLogging); | ||
| 2442 | constant Integer numberOfContinuousStates = <%listLength(fmiInfo.fmiNumberOfContinuousStates)%>; | ||
| 2443 | Real fmi_x[numberOfContinuousStates] "States"; | ||
| 2444 | Real fmi_x_new[numberOfContinuousStates](each fixed=true) "New States"; | ||
| 2445 | constant Integer numberOfEventIndicators = <%listLength(fmiInfo.fmiNumberOfEventIndicators)%>; | ||
| 2446 | Real fmi_z[numberOfEventIndicators] "Events Indicators"; | ||
| 2447 | Boolean fmi_z_positive[numberOfEventIndicators](each fixed=true); | ||
| 2448 | parameter Real flowStartTime(fixed=false); | ||
| 2449 | Real flowTime; | ||
| 2450 | parameter Real flowEnterInitialization(fixed=false); | ||
| 2451 | parameter Real flowInitialized(fixed=false); | ||
| 2452 | parameter Real flowParamsStart(fixed=false); | ||
| 2453 | parameter Real flowInitInputs(fixed=false); | ||
| 2454 | Real flowStatesInputs; | ||
| 2455 | <%if not stringEq(realInputVariablesVRs, "") then "Real realInputVariables["+nRealInputVariables+"];"%> | ||
| 2456 | <%if not stringEq(realInputVariablesVRs, "") then "Real "+realInputVariablesReturnNames+";"%> | ||
| 2457 | <%if not stringEq(integerInputVariablesVRs, "") then "Integer integerInputVariables["+nIntegerInputVariables+"];"%> | ||
| 2458 | <%if not stringEq(integerInputVariablesVRs, "") then "Integer "+integerInputVariablesReturnNames+";"%> | ||
| 2459 | <%if not stringEq(booleanInputVariablesVRs, "") then "Boolean booleanInputVariables["+nBooleanInputVariables+"];"%> | ||
| 2460 | <%if not stringEq(booleanInputVariablesVRs, "") then "Boolean "+booleanInputVariablesReturnNames+";"%> | ||
| 2461 | <%if not stringEq(stringInputVariablesVRs, "") then "String stringInputVariables["+nStringInputVariables+"];"%> | ||
| 2462 | <%if not stringEq(stringInputVariablesVRs, "") then "String "+stringInputVariablesReturnNames+";"%> | ||
| 2463 | <%if not stringEq(realEventInputVariablesVRs, "") then "Real realEventInputVariables["+nRealEventInputVariables+"](each fixed=true);"%> | ||
| 2464 | <%if not stringEq(integerEventInputVariablesVRs, "") then "Integer integerEventInputVariables["+nIntegerEventInputVariables+"](each fixed=true);"%> | ||
| 2465 | <%if not stringEq(booleanEventInputVariablesVRs, "") then "Boolean booleanEventInputVariables["+nBooleanEventInputVariables+"](each fixed=true);"%> | ||
| 2466 | <%if not stringEq(stringEventInputVariablesVRs, "") then "String stringEventInputVariables["+nStringEventInputVariables+"](each fixed=true);"%> | ||
| 2467 | Boolean callEventUpdate; | ||
| 2468 | Boolean newStatesAvailable(fixed = true); | ||
| 2469 | Real triggerDSSEvent; | ||
| 2470 | Real nextEventTime(fixed = true); | ||
| 2471 | initial equation | ||
| 2472 | <%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then | ||
| 2473 | << | ||
| 2474 | fmi_x = fmi3Functions.fmi3GetContinuousStates(fmi3me, numberOfContinuousStates, flowParamsStart+flowInitialized); | ||
| 2475 | >> | ||
| 2476 | %> | ||
| 2477 | initial algorithm | ||
| 2478 | flowParamsStart := 1; | ||
| 2479 | flowInitInputs := 1; | ||
| 2480 | flowStartTime := flowParamsStart+flowInitInputs; | ||
| 2481 | flowEnterInitialization := fmi3Functions.fmi3EnterInitialization(fmi3me, false, 0.0, time, false, 0.0, flowParamsStart+flowInitInputs); | ||
| 2482 | /* the parameters must be set while the FMU is still in Initialization Mode, | ||
| 2483 | otherwise the FMU computes its calculated parameters from the default values */ | ||
| 2484 | <%if not stringEq(realParametersVRs, "") then "flowParamsStart := fmi3Functions.fmi3SetRealParameter(fmi3me, {"+realParametersVRs+"}, {"+realParametersNames+"});"%> | ||
| 2485 | <%if not stringEq(integerParametersVRs, "") then "flowParamsStart := fmi3Functions.fmi3SetIntegerParameter(fmi3me, {"+integerParametersVRs+"}, {"+integerParametersNames+"});"%> | ||
| 2486 | <%if not stringEq(booleanParametersVRs, "") then "flowParamsStart := fmi3Functions.fmi3SetBooleanParameter(fmi3me, {"+booleanParametersVRs+"}, {"+booleanParametersNames+"});"%> | ||
| 2487 | <%if not stringEq(stringParametersVRs, "") then "flowParamsStart := fmi3Functions.fmi3SetStringParameter(fmi3me, {"+stringParametersVRs+"}, {"+stringParametersNames+"});"%> | ||
| 2488 | flowInitialized := fmi3Functions.fmi3ExitInitialization(fmi3me, flowParamsStart+flowInitInputs+flowStartTime+flowEnterInitialization); | ||
| 2489 | initial equation | ||
| 2490 | <%if not stringEq(realDependentParametersVRs, "") then "{"+realDependentParametersNames+"} = fmi3Functions.fmi3GetReal(fmi3me, {"+realDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2491 | <%if not stringEq(integerDependentParametersVRs, "") then "{"+integerDependentParametersNames+"} = fmi3Functions.fmi3GetInteger(fmi3me, {"+integerDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2492 | <%if not stringEq(booleanDependentParametersVRs, "") then "{"+booleanDependentParametersNames+"} = fmi3Functions.fmi3GetBoolean(fmi3me, {"+booleanDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2493 | <%if not stringEq(stringDependentParametersVRs, "") then "{"+stringDependentParametersNames+"} = fmi3Functions.fmi3GetString(fmi3me, {"+stringDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2494 | algorithm | ||
| 2495 | flowTime := if not initial() then fmi3Functions.fmi3SetTime(fmi3me, time, flowInitialized) else time; | ||
| 2496 | /* algorithm section ensures that inputs to fmi (if any) are set directly after the new time is set */ | ||
| 2497 | <%if not stringEq(realInputVariablesVRs, "") then "realInputVariables := fmi3Functions.fmi3SetReal(fmi3me, {"+realInputVariablesVRs+"}, {"+realInputVariablesNames+"});"%> | ||
| 2498 | <%if not stringEq(integerInputVariablesVRs, "") then "integerInputVariables := fmi3Functions.fmi3SetInteger(fmi3me, {"+integerInputVariablesVRs+"}, {"+integerInputVariablesNames+"});"%> | ||
| 2499 | <%if not stringEq(booleanInputVariablesVRs, "") then "booleanInputVariables := fmi3Functions.fmi3SetBoolean(fmi3me, {"+booleanInputVariablesVRs+"}, {"+booleanInputVariablesNames+"});"%> | ||
| 2500 | <%if not stringEq(stringInputVariablesVRs, "") then "stringInputVariables := fmi3Functions.fmi3SetString(fmi3me, {"+stringInputVariablesVRs+"}, {"+stringStartVariablesNames+"});"%> | ||
| 2501 | equation | ||
| 2502 | <%if not stringEq(realInputVariablesVRs, "") then "{"+realInputVariablesReturnNames+"} = realInputVariables;"%> | ||
| 2503 | <%if not stringEq(integerInputVariablesVRs, "") then "{"+integerInputVariablesReturnNames+"} = integerInputVariables;"%> | ||
| 2504 | <%if not stringEq(booleanInputVariablesVRs, "") then "{"+booleanInputVariablesReturnNames+"} = booleanInputVariables;"%> | ||
| 2505 | <%if not stringEq(stringInputVariablesVRs, "") then "{"+stringInputVariablesReturnNames+"} = stringInputVariables;"%> | ||
| 2506 | flowStatesInputs = fmi3Functions.fmi3SetContinuousStates(fmi3me, fmi_x, flowParamsStart + flowTime); | ||
| 2507 | der(fmi_x) = fmi3Functions.fmi3GetDerivatives(fmi3me, numberOfContinuousStates, flowStatesInputs); | ||
| 2508 | fmi_z = fmi3Functions.fmi3GetEventIndicators(fmi3me, numberOfEventIndicators, flowStatesInputs); | ||
| 2509 | for i in 1:size(fmi_z,1) loop | ||
| 2510 | fmi_z_positive[i] = if not terminal() then fmi_z[i] > 0 else pre(fmi_z_positive[i]); | ||
| 2511 | end for; | ||
| 2512 | |||
| 2513 | triggerDSSEvent = noEvent(if callEventUpdate then flowStatesInputs+1.0 else flowStatesInputs-1.0); | ||
| 2514 | |||
| 2515 | <%if not boolAnd(stringEq(realOutputVariablesNames, ""), stringEq(realOutputVariablesVRs, "")) then "{"+realOutputVariablesNames+"} = fmi3Functions.fmi3GetReal(fmi3me, {"+realOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2516 | <%if not boolAnd(stringEq(integerOutputVariablesNames, ""), stringEq(integerOutputVariablesVRs, "")) then "{"+integerOutputVariablesNames+"} = fmi3Functions.fmi3GetInteger(fmi3me, {"+integerOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2517 | <%if not boolAnd(stringEq(booleanOutputVariablesNames, ""), stringEq(booleanOutputVariablesVRs, "")) then "{"+booleanOutputVariablesNames+"} = fmi3Functions.fmi3GetBoolean(fmi3me, {"+booleanOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2518 | <%if not boolAnd(stringEq(stringOutputVariablesNames, ""), stringEq(stringOutputVariablesVRs, "")) then "{"+stringOutputVariablesNames+"} = fmi3Functions.fmi3GetString(fmi3me, {"+stringOutputVariablesVRs+"}, flowStatesInputs);"%> | ||
| 2519 | <%dumpOutputGetEnumerationVariables(fmiModelVariablesList, fmiTypeDefinitionsList, "fmi3Functions.fmi3GetInteger", "fmi3me")%> | ||
| 2520 | callEventUpdate = fmi3Functions.fmi3CompletedIntegratorStep(fmi3me, flowStatesInputs+flowTime); | ||
| 2521 | algorithm | ||
| 2522 | <%if intGt(listLength(fmiInfo.fmiNumberOfEventIndicators), 0) then | ||
| 2523 | << | ||
| 2524 | when {<%fmiInfo.fmiNumberOfEventIndicators |> eventIndicator => "change(fmi_z_positive["+eventIndicator+"])" ;separator=" or "%>, triggerDSSEvent > flowStatesInputs, pre(nextEventTime) < time, terminal()} then | ||
| 2525 | >> | ||
| 2526 | else | ||
| 2527 | << | ||
| 2528 | when {triggerDSSEvent > flowStatesInputs, pre(nextEventTime) < time, terminal()} then | ||
| 2529 | >> | ||
| 2530 | %> | ||
| 2531 | fmi3Functions.fmi3StartEventUpdate(fmi3me); | ||
| 2532 | <%if not stringEq(realEventInputVariablesVRs, "") then "realEventInputVariables := fmi3Functions.fmi3SetReal(fmi3me, {"+realEventInputVariablesVRs+"}, {"+realEventInputVariablesNames+"});"%> | ||
| 2533 | <%if not stringEq(integerEventInputVariablesVRs, "") then "integerEventInputVariables := fmi3Functions.fmi3SetInteger(fmi3me, {"+integerEventInputVariablesVRs+"}, {"+integerEventInputVariablesNames+"});"%> | ||
| 2534 | <%if not stringEq(booleanEventInputVariablesVRs, "") then "booleanEventInputVariables := fmi3Functions.fmi3SetBoolean(fmi3me, {"+booleanEventInputVariablesVRs+"}, {"+booleanEventInputVariablesNames+"});"%> | ||
| 2535 | <%if not stringEq(stringEventInputVariablesVRs, "") then "stringEventInputVariables := fmi3Functions.fmi3SetString(fmi3me, {"+stringEventInputVariablesVRs+"}, {"+stringEventStartVariablesNames+"});"%> | ||
| 2536 | newStatesAvailable := fmi3Functions.fmi3EndEventUpdate(fmi3me); | ||
| 2537 | nextEventTime := fmi3Functions.fmi3nextEventTime(fmi3me, flowStatesInputs); | ||
| 2538 | <%if intGt(listLength(fmiInfo.fmiNumberOfContinuousStates), 0) then | ||
| 2539 | << | ||
| 2540 | if newStatesAvailable then | ||
| 2541 | fmi_x_new := fmi3Functions.fmi3GetContinuousStates(fmi3me, numberOfContinuousStates, flowStatesInputs); | ||
| 2542 | <%fmiInfo.fmiNumberOfContinuousStates |> continuousStates => "reinit(fmi_x["+continuousStates+"], fmi_x_new["+continuousStates+"]);" ;separator="\n"%> | ||
| 2543 | end if; | ||
| 2544 | >> | ||
| 2545 | %> | ||
| 2546 | end when; | ||
| 2547 | annotation(experiment(StartTime=<%fmiExperimentAnnotation.fmiExperimentStartTime%>, StopTime=<%fmiExperimentAnnotation.fmiExperimentStopTime%>, Tolerance=<%fmiExperimentAnnotation.fmiExperimentTolerance%>)); | ||
| 2548 | annotation (Icon(graphics={ | ||
| 2549 | Rectangle( | ||
| 2550 | extent={{-100,100},{100,-100}}, | ||
| 2551 | lineColor={0,0,0}, | ||
| 2552 | fillColor={240,240,240}, | ||
| 2553 | fillPattern=FillPattern.Solid, | ||
| 2554 | lineThickness=0.5), | ||
| 2555 | Text( | ||
| 2556 | extent={{-100,40},{100,0}}, | ||
| 2557 | lineColor={0,0,0}, | ||
| 2558 | textString="%name"), | ||
| 2559 | Text( | ||
| 2560 | extent={{-100,-50},{100,-90}}, | ||
| 2561 | lineColor={0,0,0}, | ||
| 2562 | textString="V3.0")})); | ||
| 2563 | protected | ||
| 2564 | class FMI3ModelExchange | ||
| 2565 | extends ExternalObject; | ||
| 2566 | function constructor | ||
| 2567 | input Integer logLevel; | ||
| 2568 | input String workingDirectory; | ||
| 2569 | input String instanceName; | ||
| 2570 | input Boolean debugLogging; | ||
| 2571 | output FMI3ModelExchange fmi3me; | ||
| 2572 | external "C" fmi3me = FMI3ModelExchangeConstructor_OMC(logLevel, workingDirectory, instanceName, debugLogging) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2573 | end constructor; | ||
| 2574 | |||
| 2575 | function destructor | ||
| 2576 | input FMI3ModelExchange fmi3me; | ||
| 2577 | external "C" FMI3ModelExchangeDestructor_OMC(fmi3me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2578 | end destructor; | ||
| 2579 | end FMI3ModelExchange; | ||
| 2580 | |||
| 2581 | <%dumpFMITypeDefinitionsMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 2582 | |||
| 2583 | <%dumpFMITypeDefinitionsArrayMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 2584 | |||
| 2585 | package fmi3Functions | ||
| 2586 | function fmi3SetTime | ||
| 2587 | input FMI3ModelExchange fmi3me; | ||
| 2588 | input Real inTime; | ||
| 2589 | input Real inFlow; | ||
| 2590 | output Real outFlow = inFlow; | ||
| 2591 | external "C" fmi3SetTime_OMC(fmi3me, inTime) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2592 | end fmi3SetTime; | ||
| 2593 | |||
| 2594 | function fmi3EnterInitialization | ||
| 2595 | "FMI 3.0 folded what fmi2SetupExperiment carried into fmi3EnterInitializationMode." | ||
| 2596 | input FMI3ModelExchange fmi3me; | ||
| 2597 | input Boolean inToleranceDefined; | ||
| 2598 | input Real inTolerance; | ||
| 2599 | input Real inStartTime; | ||
| 2600 | input Boolean inStopTimeDefined; | ||
| 2601 | input Real inStopTime; | ||
| 2602 | input Real inFlowVariable; | ||
| 2603 | output Real outFlowVariable = inFlowVariable; | ||
| 2604 | external "C" fmi3EnterInitializationModel_OMC(fmi3me, inToleranceDefined, inTolerance, inStartTime, inStopTimeDefined, inStopTime) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2605 | end fmi3EnterInitialization; | ||
| 2606 | |||
| 2607 | function fmi3ExitInitialization | ||
| 2608 | input FMI3ModelExchange fmi3me; | ||
| 2609 | input Real inFlowVariable; | ||
| 2610 | output Real outFlowVariable = inFlowVariable; | ||
| 2611 | external "C" fmi3ExitInitializationModel_OMC(fmi3me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2612 | end fmi3ExitInitialization; | ||
| 2613 | |||
| 2614 | function fmi3GetContinuousStates | ||
| 2615 | input FMI3ModelExchange fmi3me; | ||
| 2616 | input Integer numberOfContinuousStates; | ||
| 2617 | input Real inFlowParams; | ||
| 2618 | output Real fmi_x[numberOfContinuousStates]; | ||
| 2619 | external "C" fmi3GetContinuousStates_OMC(fmi3me, numberOfContinuousStates, inFlowParams, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2620 | end fmi3GetContinuousStates; | ||
| 2621 | |||
| 2622 | function fmi3SetContinuousStates | ||
| 2623 | input FMI3ModelExchange fmi3me; | ||
| 2624 | input Real fmi_x[:]; | ||
| 2625 | input Real inFlowParams; | ||
| 2626 | output Real outFlowStates; | ||
| 2627 | external "C" outFlowStates = fmi3SetContinuousStates_OMC(fmi3me, size(fmi_x, 1), inFlowParams, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2628 | end fmi3SetContinuousStates; | ||
| 2629 | |||
| 2630 | function fmi3GetDerivatives | ||
| 2631 | input FMI3ModelExchange fmi3me; | ||
| 2632 | input Integer numberOfContinuousStates; | ||
| 2633 | input Real inFlowStates; | ||
| 2634 | output Real fmi_x[numberOfContinuousStates]; | ||
| 2635 | external "C" fmi3GetDerivatives_OMC(fmi3me, numberOfContinuousStates, inFlowStates, fmi_x) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2636 | end fmi3GetDerivatives; | ||
| 2637 | |||
| 2638 | function fmi3GetEventIndicators | ||
| 2639 | input FMI3ModelExchange fmi3me; | ||
| 2640 | input Integer numberOfEventIndicators; | ||
| 2641 | input Real inFlowStates; | ||
| 2642 | output Real fmi_z[numberOfEventIndicators]; | ||
| 2643 | external "C" fmi3GetEventIndicators_OMC(fmi3me, numberOfEventIndicators, inFlowStates, fmi_z) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2644 | end fmi3GetEventIndicators; | ||
| 2645 | |||
| 2646 | function fmi3GetReal | ||
| 2647 | input FMI3ModelExchange fmi3me; | ||
| 2648 | input Real realValuesReferences[:]; | ||
| 2649 | input Real inFlowStatesInput; | ||
| 2650 | output Real realValues[size(realValuesReferences, 1)]; | ||
| 2651 | external "C" fmi3GetReal_OMC(fmi3me, size(realValuesReferences, 1), realValuesReferences, inFlowStatesInput, realValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2652 | end fmi3GetReal; | ||
| 2653 | |||
| 2654 | function fmi3SetReal | ||
| 2655 | input FMI3ModelExchange fmi3me; | ||
| 2656 | input Real realValueReferences[:]; | ||
| 2657 | input Real realValues[size(realValueReferences, 1)]; | ||
| 2658 | output Real outValues[size(realValueReferences, 1)] = realValues; | ||
| 2659 | external "C" fmi3SetReal_OMC(fmi3me, size(realValueReferences, 1), realValueReferences, realValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2660 | end fmi3SetReal; | ||
| 2661 | |||
| 2662 | function fmi3SetRealParameter | ||
| 2663 | input FMI3ModelExchange fmi3me; | ||
| 2664 | input Real realValueReferences[:]; | ||
| 2665 | input Real realValues[size(realValueReferences, 1)]; | ||
| 2666 | output Real out_Value = 1; | ||
| 2667 | external "C" fmi3SetReal_OMC(fmi3me, size(realValueReferences, 1), realValueReferences, realValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2668 | end fmi3SetRealParameter; | ||
| 2669 | |||
| 2670 | function fmi3GetInteger | ||
| 2671 | input FMI3ModelExchange fmi3me; | ||
| 2672 | input Real integerValueReferences[:]; | ||
| 2673 | input Real inFlowStatesInput; | ||
| 2674 | output Integer integerValues[size(integerValueReferences, 1)]; | ||
| 2675 | external "C" fmi3GetInteger_OMC(fmi3me, size(integerValueReferences, 1), integerValueReferences, inFlowStatesInput, integerValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2676 | end fmi3GetInteger; | ||
| 2677 | |||
| 2678 | function fmi3SetInteger | ||
| 2679 | input FMI3ModelExchange fmi3me; | ||
| 2680 | input Real integerValuesReferences[:]; | ||
| 2681 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 2682 | output Integer outValues[size(integerValuesReferences, 1)] = integerValues; | ||
| 2683 | external "C" fmi3SetInteger_OMC(fmi3me, size(integerValuesReferences, 1), integerValuesReferences, integerValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2684 | end fmi3SetInteger; | ||
| 2685 | |||
| 2686 | function fmi3SetIntegerParameter | ||
| 2687 | input FMI3ModelExchange fmi3me; | ||
| 2688 | input Real integerValuesReferences[:]; | ||
| 2689 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 2690 | output Real out_Value = 1; | ||
| 2691 | external "C" fmi3SetInteger_OMC(fmi3me, size(integerValuesReferences, 1), integerValuesReferences, integerValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2692 | end fmi3SetIntegerParameter; | ||
| 2693 | |||
| 2694 | function fmi3GetBoolean | ||
| 2695 | input FMI3ModelExchange fmi3me; | ||
| 2696 | input Real booleanValuesReferences[:]; | ||
| 2697 | input Real inFlowStatesInput; | ||
| 2698 | output Boolean booleanValues[size(booleanValuesReferences, 1)]; | ||
| 2699 | external "C" fmi3GetBoolean_OMC(fmi3me, size(booleanValuesReferences, 1), booleanValuesReferences, inFlowStatesInput, booleanValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2700 | end fmi3GetBoolean; | ||
| 2701 | |||
| 2702 | function fmi3SetBoolean | ||
| 2703 | input FMI3ModelExchange fmi3me; | ||
| 2704 | input Real booleanValueReferences[:]; | ||
| 2705 | input Boolean booleanValues[size(booleanValueReferences, 1)]; | ||
| 2706 | output Boolean outValues[size(booleanValueReferences, 1)] = booleanValues; | ||
| 2707 | external "C" fmi3SetBoolean_OMC(fmi3me, size(booleanValueReferences, 1), booleanValueReferences, booleanValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2708 | end fmi3SetBoolean; | ||
| 2709 | |||
| 2710 | function fmi3SetBooleanParameter | ||
| 2711 | input FMI3ModelExchange fmi3me; | ||
| 2712 | input Real booleanValueReferences[:]; | ||
| 2713 | input Boolean booleanValues[size(booleanValueReferences, 1)]; | ||
| 2714 | output Real out_Value = 1; | ||
| 2715 | external "C" fmi3SetBoolean_OMC(fmi3me, size(booleanValueReferences, 1), booleanValueReferences, booleanValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2716 | end fmi3SetBooleanParameter; | ||
| 2717 | |||
| 2718 | function fmi3GetString | ||
| 2719 | input FMI3ModelExchange fmi3me; | ||
| 2720 | input Real stringValuesReferences[:]; | ||
| 2721 | input Real inFlowStatesInput; | ||
| 2722 | output String stringValues[size(stringValuesReferences, 1)]; | ||
| 2723 | external "C" fmi3GetString_OMC(fmi3me, size(stringValuesReferences, 1), stringValuesReferences, inFlowStatesInput, stringValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2724 | end fmi3GetString; | ||
| 2725 | |||
| 2726 | function fmi3SetString | ||
| 2727 | input FMI3ModelExchange fmi3me; | ||
| 2728 | input Real stringValueReferences[:]; | ||
| 2729 | input String stringValues[size(stringValueReferences, 1)]; | ||
| 2730 | output String outValues[size(stringValueReferences, 1)] = stringValues; | ||
| 2731 | external "C" fmi3SetString_OMC(fmi3me, size(stringValueReferences, 1), stringValueReferences, stringValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2732 | end fmi3SetString; | ||
| 2733 | |||
| 2734 | function fmi3SetStringParameter | ||
| 2735 | input FMI3ModelExchange fmi3me; | ||
| 2736 | input Real stringValueReferences[:]; | ||
| 2737 | input String stringValues[size(stringValueReferences, 1)]; | ||
| 2738 | output Real out_Value = 1; | ||
| 2739 | external "C" fmi3SetString_OMC(fmi3me, size(stringValueReferences, 1), stringValueReferences, stringValues) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2740 | end fmi3SetStringParameter; | ||
| 2741 | |||
| 2742 | function fmi3StartEventUpdate | ||
| 2743 | input FMI3ModelExchange fmi3me; | ||
| 2744 | external "C" fmi3StartEventUpdate_OMC(fmi3me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2745 | end fmi3StartEventUpdate; | ||
| 2746 | |||
| 2747 | function fmi3EndEventUpdate | ||
| 2748 | input FMI3ModelExchange fmi3me; | ||
| 2749 | output Boolean outNewStatesAvailable; | ||
| 2750 | external "C" outNewStatesAvailable = fmi3EndEventUpdate_OMC(fmi3me) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2751 | end fmi3EndEventUpdate; | ||
| 2752 | |||
| 2753 | function fmi3nextEventTime | ||
| 2754 | input FMI3ModelExchange fmi3me; | ||
| 2755 | input Real inFlowStates; | ||
| 2756 | output Real outNewnextTime; | ||
| 2757 | external "C" outNewnextTime = fmi3nextEventTime_OMC(fmi3me, inFlowStates) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2758 | end fmi3nextEventTime; | ||
| 2759 | |||
| 2760 | function fmi3CompletedIntegratorStep | ||
| 2761 | input FMI3ModelExchange fmi3me; | ||
| 2762 | input Real inFlowStates; | ||
| 2763 | output Boolean outCallEventUpdate; | ||
| 2764 | external "C" outCallEventUpdate = fmi3CompletedIntegratorStep_OMC(fmi3me, inFlowStates) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2765 | end fmi3CompletedIntegratorStep; | ||
| 2766 | end fmi3Functions; | ||
| 2767 | end <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%>; | ||
| 2768 | >> | ||
| 2769 | end importFMU3ModelExchange; | ||
| 2770 | |||
| 2771 | 1 | template importFMU1CoSimulationStandAlone(FmiImport fmi, String name) | |
| 2772 | "Generates Modelica code for FMI Co-simulation stand alone version 1.0" | ||
| 2773 | ::= | ||
| 2774 | match fmi | ||
| 2775 | case FMIIMPORT(fmiInfo=INFO(__),fmiExperimentAnnotation=EXPERIMENTANNOTATION(__)) then | ||
| 2776 | /* Get Real parameters and their value references */ | ||
| 2777 | let realParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 1, "1.0") | ||
| 2778 | let realParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", false, 2, "1.0") | ||
| 2779 | /* Get Integer parameters and their value references */ | ||
| 2780 | let integerParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 1, "1.0") | ||
| 2781 | let integerParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", false, 2, "1.0") | ||
| 2782 | /* Get Boolean parameters and their value references */ | ||
| 2783 | let booleanParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 1, "1.0") | ||
| 2784 | let booleanParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", false, 2, "1.0") | ||
| 2785 | /* Get String parameters and their value references */ | ||
| 2786 | let stringParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 1, "1.0") | ||
| 2787 | let stringParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", false, 2, "1.0") | ||
| 2788 | /* Get dependent Real parameters and their value references */ | ||
| 2789 | let realDependentParametersVRs = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 1, "1.0") | ||
| 2790 | let realDependentParametersNames = dumpVariables(fmiModelVariablesList, "real", "parameter", true, 2, "1.0") | ||
| 2791 | /* Get dependent Integer parameters and their value references */ | ||
| 2792 | let integerDependentParametersVRs = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 1, "1.0") | ||
| 2793 | let integerDependentParametersNames = dumpVariables(fmiModelVariablesList, "integer", "parameter", true, 2, "1.0") | ||
| 2794 | /* Get dependent Boolean parameters and their value references */ | ||
| 2795 | let booleanDependentParametersVRs = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 1, "1.0") | ||
| 2796 | let booleanDependentParametersNames = dumpVariables(fmiModelVariablesList, "boolean", "parameter", true, 2, "1.0") | ||
| 2797 | /* Get dependent String parameters and their value references */ | ||
| 2798 | let stringDependentParametersVRs = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 1, "1.0") | ||
| 2799 | let stringDependentParametersNames = dumpVariables(fmiModelVariablesList, "string", "parameter", true, 2, "1.0") | ||
| 2800 | /* Get input Real varibales and their value references */ | ||
| 2801 | let realInputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "input", false, 1, "1.0") | ||
| 2802 | let realInputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 2, "1.0") | ||
| 2803 | let realInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "real", "input", false, 3, "1.0") | ||
| 2804 | /* Get input Integer varibales and their value references */ | ||
| 2805 | let integerInputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "input", false, 1, "1.0") | ||
| 2806 | let integerInputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 2, "1.0") | ||
| 2807 | let integerInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "integer", "input", false, 3, "1.0") | ||
| 2808 | /* Get input Boolean varibales and their value references */ | ||
| 2809 | let booleanInputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 1, "1.0") | ||
| 2810 | let booleanInputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 2, "1.0") | ||
| 2811 | let booleanInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "boolean", "input", false, 3, "1.0") | ||
| 2812 | /* Get input String varibales and their value references */ | ||
| 2813 | let stringInputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "input", false, 1, "1.0") | ||
| 2814 | let stringStartVariablesNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 2, "1.0") | ||
| 2815 | let stringInputVariablesReturnNames = dumpVariables(fmiModelVariablesList, "string", "input", false, 3, "1.0") | ||
| 2816 | /* Get output Real varibales and their value references */ | ||
| 2817 | let realOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "real", "output", false, 1, "1.0") | ||
| 2818 | let realOutputVariablesNames = dumpVariables(fmiModelVariablesList, "real", "output", false, 2, "1.0") | ||
| 2819 | /* Get output Integer varibales and their value references */ | ||
| 2820 | let integerOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "integer", "output", false, 1, "1.0") | ||
| 2821 | let integerOutputVariablesNames = dumpVariables(fmiModelVariablesList, "integer", "output", false, 2, "1.0") | ||
| 2822 | /* Get output Boolean varibales and their value references */ | ||
| 2823 | let booleanOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 1, "1.0") | ||
| 2824 | let booleanOutputVariablesNames = dumpVariables(fmiModelVariablesList, "boolean", "output", false, 2, "1.0") | ||
| 2825 | /* Get output String varibales and their value references */ | ||
| 2826 | let stringOutputVariablesVRs = dumpVariables(fmiModelVariablesList, "string", "output", false, 1, "1.0") | ||
| 2827 | let stringOutputVariablesNames = dumpVariables(fmiModelVariablesList, "string", "output", false, 2, "1.0") | ||
| 2828 | << | ||
| 2829 | model <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%><%if stringEq(fmiInfo.fmiDescription, "") then "" else " \""+fmiInfo.fmiDescription+"\""%> | ||
| 2830 | <%dumpFMITypeDefinitions(fmiTypeDefinitionsList)%> | ||
| 2831 | constant String fmuLocation = "file://<%fmuWorkingDirectory%>/resources"; | ||
| 2832 | constant String fmuWorkingDir = "<%fmuWorkingDirectory%>"; | ||
| 2833 | parameter Integer logLevel = <%fmiLogLevel%> "log level used during the loading of FMU" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 2834 | parameter Boolean debugLogging = <%fmiDebugOutput%> "enables the FMU simulation logging" annotation (Dialog(tab="FMI", group="Enable logging")); | ||
| 2835 | constant String mimeType = ""; | ||
| 2836 | constant Real timeout = 0.0; | ||
| 2837 | constant Boolean visible = false; | ||
| 2838 | constant Boolean interactive = false; | ||
| 2839 | parameter Real startTime = <%fmiExperimentAnnotation.fmiExperimentStartTime%> "start time used to initialize the slave" annotation (Dialog(tab="FMI", group="Step time")); | ||
| 2840 | parameter Real stopTime = <%fmiExperimentAnnotation.fmiExperimentStopTime%> "stop time used to initialize the slave" annotation (Dialog(tab="FMI", group="Step time")); | ||
| 2841 | parameter Real numberOfSteps = 500 annotation (Dialog(tab="FMI", group="Step time")); | ||
| 2842 | parameter Real communicationStepSize = (stopTime-startTime)/numberOfSteps "step size used by fmiDoStep" annotation (Dialog(tab="FMI", group="Step time")); | ||
| 2843 | constant Boolean stopTimeDefined = true; | ||
| 2844 | <%dumpFMIModelVariablesList("1.0", fmiModelVariablesList, fmiTypeDefinitionsList, generateInputConnectors, generateOutputConnectors)%> | ||
| 2845 | protected | ||
| 2846 | FMI1CoSimulation fmi1cs = FMI1CoSimulation(logLevel, fmuWorkingDir, "<%fmiInfo.fmiModelIdentifier%>", debugLogging, fmuLocation, mimeType, timeout, visible, interactive, startTime, stopTimeDefined, stopTime); | ||
| 2847 | parameter Real flowParamsStart(fixed=false); | ||
| 2848 | parameter Real flowInitialized(fixed=false); | ||
| 2849 | Real flowStep; | ||
| 2850 | <%if not stringEq(realInputVariablesVRs, "") then "Real "+realInputVariablesReturnNames+";"%> | ||
| 2851 | <%if not stringEq(integerInputVariablesVRs, "") then "Integer "+integerInputVariablesReturnNames+";"%> | ||
| 2852 | <%if not stringEq(booleanInputVariablesVRs, "") then "Boolean "+booleanInputVariablesReturnNames+";"%> | ||
| 2853 | <%if not stringEq(stringInputVariablesVRs, "") then "String "+stringInputVariablesReturnNames+";"%> | ||
| 2854 | initial algorithm | ||
| 2855 | flowParamsStart := 1; | ||
| 2856 | /* the parameters must be set before the slave is initialized, | ||
| 2857 | otherwise the FMU computes its calculated parameters from the default values */ | ||
| 2858 | <%if not stringEq(realParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetRealParameter(fmi1cs, {"+realParametersVRs+"}, {"+realParametersNames+"});"%> | ||
| 2859 | <%if not stringEq(integerParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetIntegerParameter(fmi1cs, {"+integerParametersVRs+"}, {"+integerParametersNames+"});"%> | ||
| 2860 | <%if not stringEq(booleanParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetBooleanParameter(fmi1cs, {"+booleanParametersVRs+"}, {"+booleanParametersNames+"});"%> | ||
| 2861 | <%if not stringEq(stringParametersVRs, "") then "flowParamsStart := fmi1Functions.fmi1SetStringParameter(fmi1cs, {"+stringParametersVRs+"}, {"+stringParametersNames+"});"%> | ||
| 2862 | flowInitialized := fmi1Functions.fmi1InitializeSlave(fmi1cs, flowParamsStart); | ||
| 2863 | initial equation | ||
| 2864 | <%if not stringEq(realDependentParametersVRs, "") then "{"+realDependentParametersNames+"} = fmi1Functions.fmi1GetReal(fmi1cs, {"+realDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2865 | <%if not stringEq(integerDependentParametersVRs, "") then "{"+integerDependentParametersNames+"} = fmi1Functions.fmi1GetInteger(fmi1cs, {"+integerDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2866 | <%if not stringEq(booleanDependentParametersVRs, "") then "{"+booleanDependentParametersNames+"} = fmi1Functions.fmi1GetBoolean(fmi1cs, {"+booleanDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2867 | <%if not stringEq(stringDependentParametersVRs, "") then "{"+stringDependentParametersNames+"} = fmi1Functions.fmi1GetString(fmi1cs, {"+stringDependentParametersVRs+"}, flowInitialized);"%> | ||
| 2868 | equation | ||
| 2869 | <%if not boolAnd(stringEq(realOutputVariablesNames, ""), stringEq(realOutputVariablesVRs, "")) then "{"+realOutputVariablesNames+"} = fmi1Functions.fmi1GetReal(fmi1cs, {"+realOutputVariablesVRs+"}, flowInitialized);"%> | ||
| 2870 | <%if not boolAnd(stringEq(integerOutputVariablesNames, ""), stringEq(integerOutputVariablesVRs, "")) then "{"+integerOutputVariablesNames+"} = fmi1Functions.fmi1GetInteger(fmi1cs, {"+integerOutputVariablesVRs+"}, flowInitialized);"%> | ||
| 2871 | <%if not boolAnd(stringEq(booleanOutputVariablesNames, ""), stringEq(booleanOutputVariablesVRs, "")) then "{"+booleanOutputVariablesNames+"} = fmi1Functions.fmi1GetBoolean(fmi1cs, {"+booleanOutputVariablesVRs+"}, flowInitialized);"%> | ||
| 2872 | <%if not boolAnd(stringEq(stringOutputVariablesNames, ""), stringEq(stringOutputVariablesVRs, "")) then "{"+stringOutputVariablesNames+"} = fmi1Functions.fmi1GetString(fmi1cs, {"+stringOutputVariablesVRs+"}, flowInitialized);"%> | ||
| 2873 | <%if not stringEq(realInputVariablesVRs, "") then "{"+realInputVariablesReturnNames+"} = fmi1Functions.fmi1SetReal(fmi1cs, {"+realInputVariablesVRs+"}, {"+realInputVariablesNames+"});"%> | ||
| 2874 | <%if not stringEq(integerInputVariablesVRs, "") then "{"+integerInputVariablesReturnNames+"} = fmi1Functions.fmi1SetInteger(fmi1cs, {"+integerInputVariablesVRs+"}, {"+integerInputVariablesNames+"});"%> | ||
| 2875 | <%if not stringEq(booleanInputVariablesVRs, "") then "{"+booleanInputVariablesReturnNames+"} = fmi1Functions.fmi1SetBoolean(fmi1cs, {"+booleanInputVariablesVRs+"}, {"+booleanInputVariablesNames+"});"%> | ||
| 2876 | <%if not stringEq(stringInputVariablesVRs, "") then "{"+stringInputVariablesReturnNames+"} = fmi1Functions.fmi1SetString(fmi1cs, {"+stringInputVariablesVRs+"}, {"+stringStartVariablesNames+"});"%> | ||
| 2877 | flowStep = fmi1Functions.fmi1DoStep(fmi1cs, time, communicationStepSize, true, flowInitialized); | ||
| 2878 | annotation(experiment(StartTime=<%fmiExperimentAnnotation.fmiExperimentStartTime%>, StopTime=<%fmiExperimentAnnotation.fmiExperimentStopTime%>, Tolerance=<%fmiExperimentAnnotation.fmiExperimentTolerance%>)); | ||
| 2879 | annotation (Icon(graphics={ | ||
| 2880 | Rectangle( | ||
| 2881 | extent={{-100,100},{100,-100}}, | ||
| 2882 | lineColor={0,0,0}, | ||
| 2883 | fillColor={240,240,240}, | ||
| 2884 | fillPattern=FillPattern.Solid, | ||
| 2885 | lineThickness=0.5), | ||
| 2886 | Text( | ||
| 2887 | extent={{-100,40},{100,0}}, | ||
| 2888 | lineColor={0,0,0}, | ||
| 2889 | textString="%name"), | ||
| 2890 | Text( | ||
| 2891 | extent={{-100,-50},{100,-90}}, | ||
| 2892 | lineColor={0,0,0}, | ||
| 2893 | textString="V1.0")})); | ||
| 2894 | protected | ||
| 2895 | class FMI1CoSimulation | ||
| 2896 | extends ExternalObject; | ||
| 2897 | function constructor | ||
| 2898 | input Integer fmiLogLevel; | ||
| 2899 | input String workingDirectory; | ||
| 2900 | input String instanceName; | ||
| 2901 | input Boolean debugLogging; | ||
| 2902 | input String fmuLocation; | ||
| 2903 | input String mimeType; | ||
| 2904 | input Real timeOut; | ||
| 2905 | input Boolean visible; | ||
| 2906 | input Boolean interactive; | ||
| 2907 | input Real tStart; | ||
| 2908 | input Boolean stopTimeDefined; | ||
| 2909 | input Real tStop; | ||
| 2910 | output FMI1CoSimulation fmi1cs; | ||
| 2911 | external "C" fmi1cs = FMI1CoSimulationConstructor_OMC(fmiLogLevel, workingDirectory, instanceName, debugLogging, fmuLocation, mimeType, timeOut, visible, interactive, tStart, stopTimeDefined, tStop) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2912 | end constructor; | ||
| 2913 | |||
| 2914 | function destructor | ||
| 2915 | input FMI1CoSimulation fmi1cs; | ||
| 2916 | external "C" FMI1CoSimulationDestructor_OMC(fmi1cs) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2917 | end destructor; | ||
| 2918 | end FMI1CoSimulation; | ||
| 2919 | |||
| 2920 | <%dumpFMITypeDefinitionsMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 2921 | |||
| 2922 | <%dumpFMITypeDefinitionsArrayMappingFunctions(fmiTypeDefinitionsList)%> | ||
| 2923 | |||
| 2924 | package fmi1Functions | ||
| 2925 | function fmi1InitializeSlave | ||
| 2926 | input FMI1CoSimulation fmi1cs; | ||
| 2927 | input Real preInitialized; | ||
| 2928 | output Real postInitialized=preInitialized; | ||
| 2929 | external "C" fmi1InitializeSlave_OMC(fmi1cs) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2930 | end fmi1InitializeSlave; | ||
| 2931 | |||
| 2932 | function fmi1DoStep | ||
| 2933 | input FMI1CoSimulation fmi1cs; | ||
| 2934 | input Real currentCommunicationPoint; | ||
| 2935 | input Real communicationStepSize; | ||
| 2936 | input Boolean newStep; | ||
| 2937 | input Real preInitialized; | ||
| 2938 | output Real postInitialized=preInitialized; | ||
| 2939 | external "C" fmi1DoStep_OMC(fmi1cs, currentCommunicationPoint, communicationStepSize, newStep) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2940 | end fmi1DoStep; | ||
| 2941 | |||
| 2942 | function fmi1GetReal | ||
| 2943 | input FMI1CoSimulation fmi1cs; | ||
| 2944 | input Real realValuesReferences[:]; | ||
| 2945 | input Real inFlowStatesInput; | ||
| 2946 | output Real realValues[size(realValuesReferences, 1)]; | ||
| 2947 | external "C" fmi1GetReal_OMC(fmi1cs, size(realValuesReferences, 1), realValuesReferences, inFlowStatesInput, realValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2948 | end fmi1GetReal; | ||
| 2949 | |||
| 2950 | function fmi1SetReal | ||
| 2951 | input FMI1CoSimulation fmi1cs; | ||
| 2952 | input Real realValuesReferences[:]; | ||
| 2953 | input Real realValues[size(realValuesReferences, 1)]; | ||
| 2954 | output Real out_Values[size(realValuesReferences, 1)] = realValues; | ||
| 2955 | external "C" fmi1SetReal_OMC(fmi1cs, size(realValuesReferences, 1), realValuesReferences, realValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2956 | end fmi1SetReal; | ||
| 2957 | |||
| 2958 | function fmi1SetRealParameter | ||
| 2959 | input FMI1CoSimulation fmi1cs; | ||
| 2960 | input Real realValuesReferences[:]; | ||
| 2961 | input Real realValues[size(realValuesReferences, 1)]; | ||
| 2962 | output Real out_Value = 1; | ||
| 2963 | external "C" fmi1SetReal_OMC(fmi1cs, size(realValuesReferences, 1), realValuesReferences, realValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2964 | end fmi1SetRealParameter; | ||
| 2965 | |||
| 2966 | function fmi1GetInteger | ||
| 2967 | input FMI1CoSimulation fmi1cs; | ||
| 2968 | input Real integerValuesReferences[:]; | ||
| 2969 | input Real inFlowStatesInput; | ||
| 2970 | output Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 2971 | external "C" fmi1GetInteger_OMC(fmi1cs, size(integerValuesReferences, 1), integerValuesReferences, inFlowStatesInput, integerValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2972 | end fmi1GetInteger; | ||
| 2973 | |||
| 2974 | function fmi1SetInteger | ||
| 2975 | input FMI1CoSimulation fmi1cs; | ||
| 2976 | input Real integerValuesReferences[:]; | ||
| 2977 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 2978 | output Integer out_Values[size(integerValuesReferences, 1)] = integerValues; | ||
| 2979 | external "C" fmi1SetInteger_OMC(fmi1cs, size(integerValuesReferences, 1), integerValuesReferences, integerValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2980 | end fmi1SetInteger; | ||
| 2981 | |||
| 2982 | function fmi1SetIntegerParameter | ||
| 2983 | input FMI1CoSimulation fmi1cs; | ||
| 2984 | input Real integerValuesReferences[:]; | ||
| 2985 | input Integer integerValues[size(integerValuesReferences, 1)]; | ||
| 2986 | output Real out_Value = 1; | ||
| 2987 | external "C" fmi1SetInteger_OMC(fmi1cs, size(integerValuesReferences, 1), integerValuesReferences, integerValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2988 | end fmi1SetIntegerParameter; | ||
| 2989 | |||
| 2990 | function fmi1GetBoolean | ||
| 2991 | input FMI1CoSimulation fmi1cs; | ||
| 2992 | input Real booleanValuesReferences[:]; | ||
| 2993 | input Real inFlowStatesInput; | ||
| 2994 | output Boolean booleanValues[size(booleanValuesReferences, 1)]; | ||
| 2995 | external "C" fmi1GetBoolean_OMC(fmi1cs, size(booleanValuesReferences, 1), booleanValuesReferences, inFlowStatesInput, booleanValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 2996 | end fmi1GetBoolean; | ||
| 2997 | |||
| 2998 | function fmi1SetBoolean | ||
| 2999 | input FMI1CoSimulation fmi1cs; | ||
| 3000 | input Real booleanValuesReferences[:]; | ||
| 3001 | input Boolean booleanValues[size(booleanValuesReferences, 1)]; | ||
| 3002 | output Boolean out_Values[size(booleanValuesReferences, 1)] = booleanValues; | ||
| 3003 | external "C" fmi1SetBoolean_OMC(fmi1cs, size(booleanValuesReferences, 1), booleanValuesReferences, booleanValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 3004 | end fmi1SetBoolean; | ||
| 3005 | |||
| 3006 | function fmi1SetBooleanParameter | ||
| 3007 | input FMI1CoSimulation fmi1cs; | ||
| 3008 | input Real booleanValuesReferences[:]; | ||
| 3009 | input Boolean booleanValues[size(booleanValuesReferences, 1)]; | ||
| 3010 | output Real out_Value = 1; | ||
| 3011 | external "C" fmi1SetBoolean_OMC(fmi1cs, size(booleanValuesReferences, 1), booleanValuesReferences, booleanValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 3012 | end fmi1SetBooleanParameter; | ||
| 3013 | |||
| 3014 | function fmi1GetString | ||
| 3015 | input FMI1CoSimulation fmi1cs; | ||
| 3016 | input Real stringValuesReferences[:]; | ||
| 3017 | input Real inFlowStatesInput; | ||
| 3018 | output String stringValues[size(stringValuesReferences, 1)]; | ||
| 3019 | external "C" fmi1GetString_OMC(fmi1cs, size(stringValuesReferences, 1), stringValuesReferences, inFlowStatesInput, stringValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 3020 | end fmi1GetString; | ||
| 3021 | |||
| 3022 | function fmi1SetString | ||
| 3023 | input FMI1CoSimulation fmi1cs; | ||
| 3024 | input Real stringValuesReferences[:]; | ||
| 3025 | input String stringValues[size(stringValuesReferences, 1)]; | ||
| 3026 | output String out_Values[size(stringValuesReferences, 1)] = stringValues; | ||
| 3027 | external "C" fmi1SetString_OMC(fmi1cs, size(stringValuesReferences, 1), stringValuesReferences, stringValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 3028 | end fmi1SetString; | ||
| 3029 | |||
| 3030 | function fmi1SetStringParameter | ||
| 3031 | input FMI1CoSimulation fmi1cs; | ||
| 3032 | input Real stringValuesReferences[:]; | ||
| 3033 | input String stringValues[size(stringValuesReferences, 1)]; | ||
| 3034 | output Real out_Value = 1; | ||
| 3035 | external "C" fmi1SetString_OMC(fmi1cs, size(stringValuesReferences, 1), stringValuesReferences, stringValues, 2) annotation(Library = {"OpenModelicaFMIRuntimeC", "fmilib"}); | ||
| 3036 | end fmi1SetStringParameter; | ||
| 3037 | end fmi1Functions; | ||
| 3038 | end <%if stringEq(name, "") then fmiInfo.fmiModelIdentifier+"_"+getFMIType(fmiInfo)+"_FMU" else name%>; | ||
| 3039 | >> | ||
| 3040 | end importFMU1CoSimulationStandAlone; | ||
| 3041 | |||
| 3042 | 18 | template dumpFMITypeDefinitions(list<TypeDefinitions> fmiTypeDefinitionsList) | |
| 3043 | "Generates the Type Definitions code." | ||
| 3044 | ::= | ||
| 3045 | << | ||
| 3046 | <%fmiTypeDefinitionsList |> fmiTypeDefinition => dumpFMITypeDefinition(fmiTypeDefinition) ;separator="\n"%> | ||
| 3047 | >> | ||
| 3048 | end dumpFMITypeDefinitions; | ||
| 3049 | |||
| 3050 | 6 | template dumpFMITypeDefinition(TypeDefinitions fmiTypeDefinition) | |
| 3051 | "Generates the Type code." | ||
| 3052 | ::= | ||
| 3053 | match fmiTypeDefinition | ||
| 3054 | case ENUMERATIONTYPE(__) then | ||
| 3055 | << | ||
| 3056 | type <%name%> = enumeration( | ||
| 3057 | <%dumpFMITypeDefinitionsItems(items)%>); | ||
| 3058 | >> | ||
| 3059 | end dumpFMITypeDefinition; | ||
| 3060 | |||
| 3061 | 6 | template dumpFMITypeDefinitionsItems(list<EnumerationItem> items) | |
| 3062 | "Generates the Enumeration Type items code." | ||
| 3063 | ::= | ||
| 3064 | << | ||
| 3065 | <%items |> item => dumpFMITypeDefinitionsItem(item) ;separator=",\n"%> | ||
| 3066 | >> | ||
| 3067 | end dumpFMITypeDefinitionsItems; | ||
| 3068 | |||
| 3069 | 23 | template dumpFMITypeDefinitionsItem(EnumerationItem item) | |
| 3070 | "Generates the Enumeration Type item name." | ||
| 3071 | ::= | ||
| 3072 | match item | ||
| 3073 | case ENUMERATIONITEM(__) then | ||
| 3074 | << | ||
| 3075 | <%name%> | ||
| 3076 | >> | ||
| 3077 | end dumpFMITypeDefinitionsItem; | ||
| 3078 | |||
| 3079 | 18 | template dumpFMITypeDefinitionsMappingFunctions(list<TypeDefinitions> fmiTypeDefinitionsList) | |
| 3080 | "Generates the mapping functions for all enumeration types." | ||
| 3081 | ::= | ||
| 3082 | << | ||
| 3083 | <%fmiTypeDefinitionsList |> fmiTypeDefinition => dumpFMITypeDefinitionMappingFunction(fmiTypeDefinition) ;separator="\n"%> | ||
| 3084 | >> | ||
| 3085 | end dumpFMITypeDefinitionsMappingFunctions; | ||
| 3086 | |||
| 3087 | 6 | template dumpFMITypeDefinitionMappingFunction(TypeDefinitions fmiTypeDefinition) | |
| 3088 | "Generates the mapping function from integer to enumeration type." | ||
| 3089 | ::= | ||
| 3090 | match fmiTypeDefinition | ||
| 3091 | case ENUMERATIONTYPE(__) then | ||
| 3092 | << | ||
| 3093 | function map_<%name%>_from_integer | ||
| 3094 | input Integer i; | ||
| 3095 | output <%name%> outType; | ||
| 3096 | algorithm | ||
| 3097 | <%items |> item hasindex i0 fromindex 1 => dumpFMITypeDefinitionMappingFunctionItems(item, name, i0) ;separator="\n"%> | ||
| 3098 | <%if intGt(listLength(items), 1) then "end if;"%> | ||
| 3099 | end map_<%name%>_from_integer; | ||
| 3100 | >> | ||
| 3101 | end dumpFMITypeDefinitionMappingFunction; | ||
| 3102 | |||
| 3103 | 23 | template dumpFMITypeDefinitionMappingFunctionItems(EnumerationItem item, String typeName, Integer i) | |
| 3104 | "Dumps the mapping function conditions. This is closely related to dumpFMITypeDefinitionMappingFunction." | ||
| 3105 | ::= | ||
| 3106 | match item | ||
| 3107 | case ENUMERATIONITEM(__) then | ||
| 3108 | if intEq(i, 1) then | ||
| 3109 | << | ||
| 3110 | if i == <%i%> then outType := <%typeName%>.<%name%>; | ||
| 3111 | >> | ||
| 3112 | else | ||
| 3113 | << | ||
| 3114 | elseif i == <%i%> then outType := <%typeName%>.<%name%>; | ||
| 3115 | >> | ||
| 3116 | end dumpFMITypeDefinitionMappingFunctionItems; | ||
| 3117 | |||
| 3118 | 18 | template dumpFMITypeDefinitionsArrayMappingFunctions(list<TypeDefinitions> fmiTypeDefinitionsList) | |
| 3119 | "Generates the array mapping functions for all enumeration types." | ||
| 3120 | ::= | ||
| 3121 | << | ||
| 3122 | <%fmiTypeDefinitionsList |> fmiTypeDefinition => dumpFMITypeDefinitionsArrayMappingFunction(fmiTypeDefinition) ;separator="\n"%> | ||
| 3123 | >> | ||
| 3124 | end dumpFMITypeDefinitionsArrayMappingFunctions; | ||
| 3125 | |||
| 3126 | 6 | template dumpFMITypeDefinitionsArrayMappingFunction(TypeDefinitions fmiTypeDefinition) | |
| 3127 | "Generates the mapping function from integer to enumeration type." | ||
| 3128 | ::= | ||
| 3129 | match fmiTypeDefinition | ||
| 3130 | case ENUMERATIONTYPE(__) then | ||
| 3131 | << | ||
| 3132 | function map_<%name%>_from_integers | ||
| 3133 | input Integer fromInt[size(fromInt, 1)]; | ||
| 3134 | output <%name%> toEnum[size(fromInt, 1)]; | ||
| 3135 | protected | ||
| 3136 | Integer n = size(fromInt, 1); | ||
| 3137 | algorithm | ||
| 3138 | for i in 1:n loop | ||
| 3139 | toEnum[i] := map_<%name%>_from_integer(fromInt[i]); | ||
| 3140 | end for; | ||
| 3141 | end map_<%name%>_from_integers; | ||
| 3142 | >> | ||
| 3143 | end dumpFMITypeDefinitionsArrayMappingFunction; | ||
| 3144 | |||
| 3145 | 18 | template dumpFMIModelVariablesList(String FMUVersion, list<ModelVariables> fmiModelVariablesList, list<TypeDefinitions> fmiTypeDefinitionsList, Boolean generateInputConnectors, Boolean generateOutputConnectors) | |
| 3146 | "Generates the Model Variables code." | ||
| 3147 | ::= | ||
| 3148 | << | ||
| 3149 | <%fmiModelVariablesList |> fmiModelVariable => dumpFMIModelVariable(FMUVersion, fmiModelVariable, fmiTypeDefinitionsList, generateInputConnectors, generateOutputConnectors) ;separator="\n"%> | ||
| 3150 | >> | ||
| 3151 | end dumpFMIModelVariablesList; | ||
| 3152 | |||
| 3153 | 616 | template dumpFMIModelVariable(String FMUVersion, ModelVariables fmiModelVariable, list<TypeDefinitions> fmiTypeDefinitionsList, Boolean generateInputConnectors, Boolean generateOutputConnectors) | |
| 3154 | ::= | ||
| 3155 | match FMUVersion | ||
| 3156 | case "1.0" then | ||
| 3157 | match fmiModelVariable | ||
| 3158 | case REALVARIABLE(__) then | ||
| 3159 | << | ||
| 3160 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIRealModelVariableStartValue(FMUVersion, variability, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3161 | >> | ||
| 3162 | case INTEGERVARIABLE(__) then | ||
| 3163 | << | ||
| 3164 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIIntegerModelVariableStartValue(FMUVersion, variability, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3165 | >> | ||
| 3166 | case BOOLEANVARIABLE(__) then | ||
| 3167 | << | ||
| 3168 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIBooleanModelVariableStartValue(FMUVersion, variability, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3169 | >> | ||
| 3170 | case STRINGVARIABLE(__) then | ||
| 3171 | << | ||
| 3172 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIStringModelVariableStartValue(FMUVersion, variability, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3173 | >> | ||
| 3174 | case ENUMERATIONVARIABLE(__) then | ||
| 3175 | << | ||
| 3176 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIEnumerationModelVariableStartValue(fmiTypeDefinitionsList, baseType, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3177 | >> | ||
| 3178 | end match | ||
| 3179 | case "2.0" then | ||
| 3180 | match fmiModelVariable | ||
| 3181 | case REALVARIABLE(__) then | ||
| 3182 | << | ||
| 3183 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIRealModelVariableStartValue(FMUVersion, causality, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3184 | >> | ||
| 3185 | case INTEGERVARIABLE(__) then | ||
| 3186 | << | ||
| 3187 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIIntegerModelVariableStartValue(FMUVersion, causality, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3188 | >> | ||
| 3189 | case BOOLEANVARIABLE(__) then | ||
| 3190 | << | ||
| 3191 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIBooleanModelVariableStartValue(FMUVersion, causality, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3192 | >> | ||
| 3193 | case STRINGVARIABLE(__) then | ||
| 3194 | << | ||
| 3195 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIStringModelVariableStartValue(FMUVersion, causality, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3196 | >> | ||
| 3197 | case ENUMERATIONVARIABLE(__) then | ||
| 3198 | << | ||
| 3199 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIEnumerationModelVariableStartValue(fmiTypeDefinitionsList, baseType, hasStartValue, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3200 | >> | ||
| 3201 | end match | ||
| 3202 | case "3.0" then | ||
| 3203 | /* Arrays, Binary and Clock are skipped: no Modelica declaration fits them yet, and | ||
| 3204 | so is the independent variable, which is Modelica's own time. */ | ||
| 3205 | match fmiModelVariable | ||
| 3206 | case FMI3REALVARIABLE(causality="independent") then "" | ||
| 3207 | case FMI3REALVARIABLE(__) then | ||
| 3208 | << | ||
| 3209 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMI3RealModelVariableStartValue(causality, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3210 | >> | ||
| 3211 | case FMI3INTEGERVARIABLE(__) then | ||
| 3212 | << | ||
| 3213 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMI3IntegerModelVariableStartValue(causality, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3214 | >> | ||
| 3215 | case FMI3BOOLEANVARIABLE(__) then | ||
| 3216 | << | ||
| 3217 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMI3BooleanModelVariableStartValue(causality, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3218 | >> | ||
| 3219 | case FMI3STRINGVARIABLE(__) then | ||
| 3220 | << | ||
| 3221 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMI3StringModelVariableStartValue(causality, startValue, isFixed)%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3222 | >> | ||
| 3223 | case FMI3ENUMERATIONVARIABLE(__) then | ||
| 3224 | << | ||
| 3225 | <%dumpFMIModelVariableVariability(variability)%><%dumpFMIModelVariableCausalityAndBaseType(causality, baseType, generateInputConnectors, generateOutputConnectors)%> <%name%><%dumpFMIModelVariableDescription(description)%><%dumpFMIModelVariablePlacementAnnotation(x1Placement, x2Placement, y1Placement, y2Placement, generateInputConnectors, generateOutputConnectors, causality)%>; | ||
| 3226 | >> | ||
| 3227 | end match | ||
| 3228 | end dumpFMIModelVariable; | ||
| 3229 | |||
| 3230 | 640 | template dumpFMIModelVariableVariability(String variability) | |
| 3231 | ::= | ||
| 3232 | << | ||
| 3233 | <%if stringEq(variability, "") then "" else variability+" "%> | ||
| 3234 | >> | ||
| 3235 | end dumpFMIModelVariableVariability; | ||
| 3236 | |||
| 3237 | 640 | template dumpFMIModelVariableCausalityAndBaseType(String causality, String baseType, Boolean generateInputConnectors, Boolean generateOutputConnectors) | |
| 3238 | ::= | ||
| 3239 | if boolAnd(generateInputConnectors, boolAnd(stringEq(causality, "input"),stringEq(baseType, "Real"))) then "Modelica.Blocks.Interfaces.RealInput" | ||
| 3240 | else if boolAnd(generateInputConnectors, boolAnd(stringEq(causality, "input"),stringEq(baseType, "Integer"))) then "Modelica.Blocks.Interfaces.IntegerInput" | ||
| 3241 | else if boolAnd(generateInputConnectors, boolAnd(stringEq(causality, "input"),stringEq(baseType, "Boolean"))) then "Modelica.Blocks.Interfaces.BooleanInput" | ||
| 3242 | else if boolAnd(generateOutputConnectors, boolAnd(stringEq(causality, "output"),stringEq(baseType, "Real"))) then "Modelica.Blocks.Interfaces.RealOutput" | ||
| 3243 | else if boolAnd(generateOutputConnectors, boolAnd(stringEq(causality, "output"),stringEq(baseType, "Integer"))) then "Modelica.Blocks.Interfaces.IntegerOutput" | ||
| 3244 | else if boolAnd(generateOutputConnectors, boolAnd(stringEq(causality, "output"),stringEq(baseType, "Boolean"))) then "Modelica.Blocks.Interfaces.BooleanOutput" | ||
| 3245 | else if stringEq(causality, "") then baseType else causality+" "+baseType | ||
| 3246 | end dumpFMIModelVariableCausalityAndBaseType; | ||
| 3247 | |||
| 3248 | ✗ | template dumpFMIModelVariableCausality(String causality) | |
| 3249 | ::= | ||
| 3250 | << | ||
| 3251 | <%if stringEq(causality, "") then "" else causality+" "%> | ||
| 3252 | >> | ||
| 3253 | end dumpFMIModelVariableCausality; | ||
| 3254 | |||
| 3255 | 5 | template dumpFMI3RealModelVariableStartValue(String causality, list<Real> startValue, Boolean isFixed) | |
| 3256 | "The start value part of an FMI 3.0 Real variable declaration. | ||
| 3257 | |||
| 3258 | The record holds a list because an FMI 3.0 variable can be an array; only scalars | ||
| 3259 | are imported, so the list has at most one element and an empty one means the FMU | ||
| 3260 | gave no start value." | ||
| 3261 | ::= | ||
| 3262 | match startValue | ||
| 3263 | case {} then | ||
| 3264 | match causality | ||
| 3265 | case "parameter" then | ||
| 3266 | if isFixed then "(fixed=true)" else "(fixed=false)" | ||
| 3267 | else "" | ||
| 3268 | case startVal :: _ then | ||
| 3269 | match causality | ||
| 3270 | case "parameter" then | ||
| 3271 | if isFixed then " = "+startVal | ||
| 3272 | else "(start="+startVal+",fixed=false)" | ||
| 3273 | else | ||
| 3274 | if boolNot(isFixed) then "(start="+startVal+",fixed=false)" | ||
| 3275 | end dumpFMI3RealModelVariableStartValue; | ||
| 3276 | |||
| 3277 | ✗ | template dumpFMI3IntegerModelVariableStartValue(String causality, list<Integer> startValue, Boolean isFixed) | |
| 3278 | "The start value part of an FMI 3.0 Integer variable declaration. | ||
| 3279 | |||
| 3280 | The record holds a list because an FMI 3.0 variable can be an array; only scalars | ||
| 3281 | are imported, so the list has at most one element and an empty one means the FMU | ||
| 3282 | gave no start value." | ||
| 3283 | ::= | ||
| 3284 | match startValue | ||
| 3285 | case {} then | ||
| 3286 | match causality | ||
| 3287 | case "parameter" then | ||
| 3288 | if isFixed then "(fixed=true)" else "(fixed=false)" | ||
| 3289 | else "" | ||
| 3290 | case startVal :: _ then | ||
| 3291 | match causality | ||
| 3292 | case "parameter" then | ||
| 3293 | if isFixed then " = "+startVal | ||
| 3294 | else "(start="+startVal+",fixed=false)" | ||
| 3295 | else | ||
| 3296 | if boolNot(isFixed) then "(start="+startVal+",fixed=false)" | ||
| 3297 | end dumpFMI3IntegerModelVariableStartValue; | ||
| 3298 | |||
| 3299 | ✗ | template dumpFMI3BooleanModelVariableStartValue(String causality, list<Boolean> startValue, Boolean isFixed) | |
| 3300 | "The start value part of an FMI 3.0 Boolean variable declaration. | ||
| 3301 | |||
| 3302 | The record holds a list because an FMI 3.0 variable can be an array; only scalars | ||
| 3303 | are imported, so the list has at most one element and an empty one means the FMU | ||
| 3304 | gave no start value." | ||
| 3305 | ::= | ||
| 3306 | match startValue | ||
| 3307 | case {} then | ||
| 3308 | match causality | ||
| 3309 | case "parameter" then | ||
| 3310 | if isFixed then "(fixed=true)" else "(fixed=false)" | ||
| 3311 | else "" | ||
| 3312 | case startVal :: _ then | ||
| 3313 | match causality | ||
| 3314 | case "parameter" then | ||
| 3315 | if isFixed then " = "+startVal | ||
| 3316 | else "(start="+startVal+",fixed=false)" | ||
| 3317 | else | ||
| 3318 | if boolNot(isFixed) then "(start="+startVal+",fixed=false)" | ||
| 3319 | end dumpFMI3BooleanModelVariableStartValue; | ||
| 3320 | |||
| 3321 | ✗ | template dumpFMI3StringModelVariableStartValue(String causality, list<String> startValue, Boolean isFixed) | |
| 3322 | "The start value part of an FMI 3.0 String variable declaration. | ||
| 3323 | |||
| 3324 | The record holds a list because an FMI 3.0 variable can be an array; only scalars | ||
| 3325 | are imported, so the list has at most one element and an empty one means the FMU | ||
| 3326 | gave no start value." | ||
| 3327 | ::= | ||
| 3328 | match startValue | ||
| 3329 | case {} then | ||
| 3330 | match causality | ||
| 3331 | case "parameter" then | ||
| 3332 | if isFixed then "(fixed=true)" else "(fixed=false)" | ||
| 3333 | else "" | ||
| 3334 | case startVal :: _ then | ||
| 3335 | match causality | ||
| 3336 | case "parameter" then | ||
| 3337 | if isFixed then " = \""+startVal+"\"" | ||
| 3338 | else "(start=\""+startVal+"\",fixed=false)" | ||
| 3339 | else | ||
| 3340 | if boolNot(isFixed) then "(start=\""+startVal+"\",fixed=false)" | ||
| 3341 | end dumpFMI3StringModelVariableStartValue; | ||
| 3342 | |||
| 3343 | 516 | template dumpFMIRealModelVariableStartValue(String FMUVersion, String variabilityCausality, Boolean hasStartValue, Real startValue, Boolean isFixed) | |
| 3344 | ::= | ||
| 3345 | match FMUVersion | ||
| 3346 | case "1.0" then | ||
| 3347 | match variabilityCausality | ||
| 3348 | case "parameter" then | ||
| 3349 | if boolAnd(hasStartValue,isFixed) then " = "+startValue | ||
| 3350 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3351 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3352 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3353 | case "" then | ||
| 3354 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3355 | end match | ||
| 3356 | case "2.0" then | ||
| 3357 | match variabilityCausality | ||
| 3358 | case "parameter" then | ||
| 3359 | if boolAnd(hasStartValue,isFixed) then " = "+startValue | ||
| 3360 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3361 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3362 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3363 | else | ||
| 3364 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3365 | end dumpFMIRealModelVariableStartValue; | ||
| 3366 | |||
| 3367 | 45 | template dumpFMIIntegerModelVariableStartValue(String FMUVersion, String variabilityCausality, Boolean hasStartValue, Integer startValue, Boolean isFixed) | |
| 3368 | ::= | ||
| 3369 | match FMUVersion | ||
| 3370 | case "1.0" then | ||
| 3371 | match variabilityCausality | ||
| 3372 | case "parameter" then | ||
| 3373 | if boolAnd(hasStartValue,isFixed) then " = "+startValue | ||
| 3374 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3375 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3376 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3377 | case "" then | ||
| 3378 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3379 | end match | ||
| 3380 | case "2.0" then | ||
| 3381 | match variabilityCausality | ||
| 3382 | case "parameter" then | ||
| 3383 | if boolAnd(hasStartValue,isFixed) then " = "+startValue | ||
| 3384 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3385 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3386 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3387 | else | ||
| 3388 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3389 | end dumpFMIIntegerModelVariableStartValue; | ||
| 3390 | |||
| 3391 | 38 | template dumpFMIBooleanModelVariableStartValue(String FMUVersion, String variabilityCausality, Boolean hasStartValue, Boolean startValue, Boolean isFixed) | |
| 3392 | ::= | ||
| 3393 | match FMUVersion | ||
| 3394 | case "1.0" then | ||
| 3395 | match variabilityCausality | ||
| 3396 | case "parameter" then | ||
| 3397 | if boolAnd(hasStartValue,isFixed) then " = "+startValue | ||
| 3398 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3399 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3400 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3401 | case "" then | ||
| 3402 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3403 | end match | ||
| 3404 | case "2.0" then | ||
| 3405 | match variabilityCausality | ||
| 3406 | case "parameter" then | ||
| 3407 | if boolAnd(hasStartValue,isFixed) then " = "+startValue | ||
| 3408 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3409 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3410 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3411 | else | ||
| 3412 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start="+startValue+",fixed=false)" | ||
| 3413 | end dumpFMIBooleanModelVariableStartValue; | ||
| 3414 | |||
| 3415 | 5 | template dumpFMIStringModelVariableStartValue(String FMUVersion, String variabilityCausality, Boolean hasStartValue, String startValue, Boolean isFixed) | |
| 3416 | ::= | ||
| 3417 | match FMUVersion | ||
| 3418 | case "1.0" then | ||
| 3419 | match variabilityCausality | ||
| 3420 | case "parameter" then | ||
| 3421 | if boolAnd(hasStartValue,isFixed) then " = \""+startValue+"\"" | ||
| 3422 | /* If we set fixed=false, we generate bad code; let make OM handle the bad values */ | ||
| 3423 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start=\""+startValue+"\")" | ||
| 3424 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3425 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3426 | case "" then | ||
| 3427 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start=\""+startValue+"\",fixed=false)" | ||
| 3428 | end match | ||
| 3429 | case "2.0" then | ||
| 3430 | match variabilityCausality | ||
| 3431 | case "parameter" then | ||
| 3432 | if boolAnd(hasStartValue,isFixed) then " = \""+startValue+"\"" | ||
| 3433 | else if boolAnd(hasStartValue,boolNot(isFixed)) then "(start=\""+startValue+"\",fixed=false)" | ||
| 3434 | else if boolAnd(boolNot(hasStartValue),isFixed) then "(fixed=true)" | ||
| 3435 | else if boolAnd(boolNot(hasStartValue),boolNot(isFixed)) then "(fixed=false)" | ||
| 3436 | else | ||
| 3437 | if boolAnd(hasStartValue,boolNot(isFixed)) then "(start=\""+startValue+"\",fixed=false)" | ||
| 3438 | end dumpFMIStringModelVariableStartValue; | ||
| 3439 | |||
| 3440 | 12 | template dumpFMIEnumerationModelVariableStartValue(list<TypeDefinitions> fmiTypeDefinitionsList, String baseType, Boolean hasStartValue, Integer startValue, Boolean isFixed) | |
| 3441 | ::= | ||
| 3442 | << | ||
| 3443 | <%if hasStartValue then " = map_" + getEnumerationTypeFromTypes(fmiTypeDefinitionsList, baseType) + "_from_integer(" + startValue + ")"%> | ||
| 3444 | >> | ||
| 3445 | end dumpFMIEnumerationModelVariableStartValue; | ||
| 3446 | |||
| 3447 | 640 | template dumpFMIModelVariableDescription(String description) | |
| 3448 | ::= | ||
| 3449 | << | ||
| 3450 | <%if stringEq(description, "") then "" else " \""+description+"\""%> | ||
| 3451 | >> | ||
| 3452 | end dumpFMIModelVariableDescription; | ||
| 3453 | |||
| 3454 | 640 | template dumpFMIModelVariablePlacementAnnotation(Integer x1Placement, Integer x2Placement, Integer y1Placement, Integer y2Placement, Boolean generateInputConnectors, Boolean generateOutputConnectors, String causality) | |
| 3455 | ::= | ||
| 3456 | if boolAnd(generateInputConnectors, stringEq(causality, "input")) then " annotation(Placement(transformation(extent={{"+x1Placement+","+y1Placement+"},{"+x2Placement+","+y2Placement+"}})))" | ||
| 3457 | else if boolAnd(generateOutputConnectors, stringEq(causality, "output")) then " annotation(Placement(transformation(extent={{"+x1Placement+","+y1Placement+"},{"+x2Placement+","+y2Placement+"}})))" | ||
| 3458 | end dumpFMIModelVariablePlacementAnnotation; | ||
| 3459 | |||
| 3460 | 828 | template dumpVariables(list<ModelVariables> fmiModelVariablesList, String type, String variabilityCausality, Boolean dependent, Integer what, String fmiVersion) | |
| 3461 | ::= | ||
| 3462 | << | ||
| 3463 | <%fmiModelVariablesList |> fmiModelVariable => dumpVariable(fmiModelVariable, type, variabilityCausality, dependent, what, fmiVersion) ;separator=", "%> | ||
| 3464 | >> | ||
| 3465 | end dumpVariables; | ||
| 3466 | |||
| 3467 | 30540 | template dumpVariable(ModelVariables fmiModelVariable, String type, String variabilityCausality, Boolean dependent, Integer what, String fmiVersion) | |
| 3468 | ::= | ||
| 3469 | if boolAnd(stringEq(type, "real"), (boolAnd(stringEq(variabilityCausality, "parameter"), boolNot(dependent)))) then | ||
| 3470 | << | ||
| 3471 | <% | ||
| 3472 | if stringEq(fmiVersion,"1.0") then | ||
| 3473 | match fmiModelVariable | ||
| 3474 | case REALVARIABLE(variability="parameter", hasStartValue=true) then | ||
| 3475 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3476 | end match | ||
| 3477 | else if stringEq(fmiVersion,"2.0") then | ||
| 3478 | match fmiModelVariable | ||
| 3479 | case REALVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3480 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3481 | end match | ||
| 3482 | else if stringEq(fmiVersion,"3.0") then | ||
| 3483 | match fmiModelVariable | ||
| 3484 | case FMI3REALVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3485 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3486 | %> | ||
| 3487 | >> | ||
| 3488 | else if boolAnd(stringEq(type, "integer"), (boolAnd(stringEq(variabilityCausality, "parameter"), boolNot(dependent)))) then | ||
| 3489 | << | ||
| 3490 | <% | ||
| 3491 | if stringEq(fmiVersion,"1.0") then | ||
| 3492 | match fmiModelVariable | ||
| 3493 | case INTEGERVARIABLE(variability="parameter", hasStartValue=true) then | ||
| 3494 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3495 | end match | ||
| 3496 | else if stringEq(fmiVersion,"2.0") then | ||
| 3497 | match fmiModelVariable | ||
| 3498 | case INTEGERVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3499 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3500 | end match | ||
| 3501 | else if stringEq(fmiVersion,"3.0") then | ||
| 3502 | match fmiModelVariable | ||
| 3503 | case FMI3INTEGERVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3504 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3505 | %> | ||
| 3506 | >> | ||
| 3507 | else if boolAnd(stringEq(type, "boolean"), (boolAnd(stringEq(variabilityCausality, "parameter"), boolNot(dependent)))) then | ||
| 3508 | << | ||
| 3509 | <% | ||
| 3510 | if stringEq(fmiVersion,"1.0") then | ||
| 3511 | match fmiModelVariable | ||
| 3512 | case BOOLEANVARIABLE(variability="parameter", hasStartValue=true) then | ||
| 3513 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3514 | end match | ||
| 3515 | else if stringEq(fmiVersion,"2.0") then | ||
| 3516 | match fmiModelVariable | ||
| 3517 | case BOOLEANVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3518 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3519 | end match | ||
| 3520 | else if stringEq(fmiVersion,"3.0") then | ||
| 3521 | match fmiModelVariable | ||
| 3522 | case FMI3BOOLEANVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3523 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3524 | %> | ||
| 3525 | >> | ||
| 3526 | else if boolAnd(stringEq(type, "string"), (boolAnd(stringEq(variabilityCausality, "parameter"), boolNot(dependent)))) then | ||
| 3527 | << | ||
| 3528 | <% | ||
| 3529 | if stringEq(fmiVersion,"1.0") then | ||
| 3530 | match fmiModelVariable | ||
| 3531 | case STRINGVARIABLE(variability="parameter", hasStartValue=true) then | ||
| 3532 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3533 | end match | ||
| 3534 | else if stringEq(fmiVersion,"2.0") then | ||
| 3535 | match fmiModelVariable | ||
| 3536 | case STRINGVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3537 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3538 | end match | ||
| 3539 | else if stringEq(fmiVersion,"3.0") then | ||
| 3540 | match fmiModelVariable | ||
| 3541 | case FMI3STRINGVARIABLE(causality="parameter", hasStartValue=true) then | ||
| 3542 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3543 | %> | ||
| 3544 | >> | ||
| 3545 | else if boolAnd(stringEq(type, "real"), (boolAnd(stringEq(variabilityCausality, "parameter"), dependent))) then | ||
| 3546 | << | ||
| 3547 | <% | ||
| 3548 | if stringEq(fmiVersion,"1.0") then | ||
| 3549 | match fmiModelVariable | ||
| 3550 | case REALVARIABLE(variability="parameter", hasStartValue=false, isFixed=false) then | ||
| 3551 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3552 | end match | ||
| 3553 | else if stringEq(fmiVersion,"2.0") then | ||
| 3554 | match fmiModelVariable | ||
| 3555 | case REALVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3556 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3557 | end match | ||
| 3558 | else if stringEq(fmiVersion,"3.0") then | ||
| 3559 | match fmiModelVariable | ||
| 3560 | case FMI3REALVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3561 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3562 | %> | ||
| 3563 | >> | ||
| 3564 | else if boolAnd(stringEq(type, "integer"), (boolAnd(stringEq(variabilityCausality, "parameter"), dependent))) then | ||
| 3565 | << | ||
| 3566 | <% | ||
| 3567 | if stringEq(fmiVersion,"1.0") then | ||
| 3568 | match fmiModelVariable | ||
| 3569 | case INTEGERVARIABLE(variability="parameter", hasStartValue=false, isFixed=false) then | ||
| 3570 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3571 | end match | ||
| 3572 | else if stringEq(fmiVersion,"2.0") then | ||
| 3573 | match fmiModelVariable | ||
| 3574 | case INTEGERVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3575 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3576 | end match | ||
| 3577 | else if stringEq(fmiVersion,"3.0") then | ||
| 3578 | match fmiModelVariable | ||
| 3579 | case FMI3INTEGERVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3580 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3581 | %> | ||
| 3582 | >> | ||
| 3583 | else if boolAnd(stringEq(type, "boolean"), (boolAnd(stringEq(variabilityCausality, "parameter"), dependent))) then | ||
| 3584 | << | ||
| 3585 | <% | ||
| 3586 | if stringEq(fmiVersion,"1.0") then | ||
| 3587 | match fmiModelVariable | ||
| 3588 | case BOOLEANVARIABLE(variability="parameter", hasStartValue=false, isFixed=false) then | ||
| 3589 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3590 | end match | ||
| 3591 | else if stringEq(fmiVersion,"2.0") then | ||
| 3592 | match fmiModelVariable | ||
| 3593 | case BOOLEANVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3594 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3595 | end match | ||
| 3596 | else if stringEq(fmiVersion,"3.0") then | ||
| 3597 | match fmiModelVariable | ||
| 3598 | case FMI3BOOLEANVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3599 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3600 | %> | ||
| 3601 | >> | ||
| 3602 | else if boolAnd(stringEq(type, "string"), (boolAnd(stringEq(variabilityCausality, "parameter"), dependent))) then | ||
| 3603 | << | ||
| 3604 | <% | ||
| 3605 | if stringEq(fmiVersion,"1.0") then | ||
| 3606 | match fmiModelVariable | ||
| 3607 | case STRINGVARIABLE(variability="parameter", hasStartValue=false, isFixed=false) then | ||
| 3608 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3609 | end match | ||
| 3610 | else if stringEq(fmiVersion,"2.0") then | ||
| 3611 | match fmiModelVariable | ||
| 3612 | case STRINGVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3613 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3614 | end match | ||
| 3615 | else if stringEq(fmiVersion,"3.0") then | ||
| 3616 | match fmiModelVariable | ||
| 3617 | case FMI3STRINGVARIABLE(causality="parameter", hasStartValue=false, isFixed=false) then | ||
| 3618 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3619 | %> | ||
| 3620 | >> | ||
| 3621 | else if boolAnd(stringEq(type, "real"), stringEq(variabilityCausality, "input")) then | ||
| 3622 | << | ||
| 3623 | <% | ||
| 3624 | match fmiModelVariable | ||
| 3625 | case REALVARIABLE(causality="input") then | ||
| 3626 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3627 | case FMI3REALVARIABLE(causality="input") then | ||
| 3628 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3629 | %> | ||
| 3630 | >> | ||
| 3631 | else if boolAnd(stringEq(type, "integer"), stringEq(variabilityCausality, "input")) then | ||
| 3632 | << | ||
| 3633 | <% | ||
| 3634 | match fmiModelVariable | ||
| 3635 | case INTEGERVARIABLE(causality="input") then | ||
| 3636 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3637 | case FMI3INTEGERVARIABLE(causality="input") then | ||
| 3638 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3639 | %> | ||
| 3640 | >> | ||
| 3641 | else if boolAnd(stringEq(type, "boolean"), stringEq(variabilityCausality, "input")) then | ||
| 3642 | << | ||
| 3643 | <% | ||
| 3644 | match fmiModelVariable | ||
| 3645 | case BOOLEANVARIABLE(causality="input") then | ||
| 3646 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3647 | case FMI3BOOLEANVARIABLE(causality="input") then | ||
| 3648 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3649 | %> | ||
| 3650 | >> | ||
| 3651 | else if boolAnd(stringEq(type, "string"), stringEq(variabilityCausality, "input")) then | ||
| 3652 | << | ||
| 3653 | <% | ||
| 3654 | match fmiModelVariable | ||
| 3655 | case STRINGVARIABLE(causality="input") then | ||
| 3656 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3657 | case FMI3STRINGVARIABLE(causality="input") then | ||
| 3658 | if intEq(what,1) then valueReference else if intEq(what,2) then name else if intEq(what,3) then "fmi_input_"+name | ||
| 3659 | %> | ||
| 3660 | >> | ||
| 3661 | else if boolAnd(stringEq(type, "real"), stringEq(variabilityCausality, "output")) then | ||
| 3662 | << | ||
| 3663 | <% | ||
| 3664 | match fmiModelVariable | ||
| 3665 | case REALVARIABLE(variability = "",causality="") then | ||
| 3666 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3667 | case FMI3REALVARIABLE(variability = "",causality="") then | ||
| 3668 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3669 | case REALVARIABLE(variability = "",causality="output") then | ||
| 3670 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3671 | case FMI3REALVARIABLE(variability = "",causality="output") then | ||
| 3672 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3673 | %> | ||
| 3674 | >> | ||
| 3675 | else if boolAnd(stringEq(type, "integer"), stringEq(variabilityCausality, "output")) then | ||
| 3676 | << | ||
| 3677 | <% | ||
| 3678 | match fmiModelVariable | ||
| 3679 | case INTEGERVARIABLE(variability = "",causality="") then | ||
| 3680 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3681 | case FMI3INTEGERVARIABLE(variability = "",causality="") then | ||
| 3682 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3683 | case INTEGERVARIABLE(variability = "",causality="output") then | ||
| 3684 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3685 | case FMI3INTEGERVARIABLE(variability = "",causality="output") then | ||
| 3686 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3687 | %> | ||
| 3688 | >> | ||
| 3689 | else if boolAnd(stringEq(type, "boolean"), stringEq(variabilityCausality, "output")) then | ||
| 3690 | << | ||
| 3691 | <% | ||
| 3692 | match fmiModelVariable | ||
| 3693 | case BOOLEANVARIABLE(variability = "",causality="") then | ||
| 3694 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3695 | case FMI3BOOLEANVARIABLE(variability = "",causality="") then | ||
| 3696 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3697 | case BOOLEANVARIABLE(variability = "",causality="output") then | ||
| 3698 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3699 | case FMI3BOOLEANVARIABLE(variability = "",causality="output") then | ||
| 3700 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3701 | %> | ||
| 3702 | >> | ||
| 3703 | else if boolAnd(stringEq(type, "string"), stringEq(variabilityCausality, "output")) then | ||
| 3704 | << | ||
| 3705 | <% | ||
| 3706 | match fmiModelVariable | ||
| 3707 | case STRINGVARIABLE(variability = "",causality="") then | ||
| 3708 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3709 | case FMI3STRINGVARIABLE(variability = "",causality="") then | ||
| 3710 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3711 | case STRINGVARIABLE(variability = "",causality="output") then | ||
| 3712 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3713 | case FMI3STRINGVARIABLE(variability = "",causality="output") then | ||
| 3714 | if intEq(what,1) then valueReference else if intEq(what,2) then name | ||
| 3715 | %> | ||
| 3716 | >> | ||
| 3717 | end dumpVariable; | ||
| 3718 | |||
| 3719 | 17 | template dumpOutputGetEnumerationVariables(list<ModelVariables> fmiModelVariablesList, list<TypeDefinitions> fmiTypeDefinitionsList, String fmiGetFunction, String fmiInstance) | |
| 3720 | ::= | ||
| 3721 | << | ||
| 3722 | <%fmiModelVariablesList |> fmiModelVariable => dumpOutputGetEnumerationVariable(fmiModelVariable, fmiTypeDefinitionsList, fmiGetFunction, fmiInstance)%> | ||
| 3723 | >> | ||
| 3724 | end dumpOutputGetEnumerationVariables; | ||
| 3725 | |||
| 3726 | 10 | template dumpOutputGetEnumerationVariable(ModelVariables fmiModelVariable, list<TypeDefinitions> fmiTypeDefinitionsList, String fmiGetFunction, String fmiInstance) | |
| 3727 | ::= | ||
| 3728 | match fmiModelVariable | ||
| 3729 | case ENUMERATIONVARIABLE(variability = "",causality="") then | ||
| 3730 | << | ||
| 3731 | {<%name%>} = map_<%getEnumerationTypeFromTypes(fmiTypeDefinitionsList, baseType)%>_from_integers(<%fmiGetFunction%>(<%fmiInstance%>, {<%valueReference%>}, flowStatesInputs));<%\n%> | ||
| 3732 | >> | ||
| 3733 | case ENUMERATIONVARIABLE(variability = "",causality="output") then | ||
| 3734 | << | ||
| 3735 | {<%name%>} = map_<%getEnumerationTypeFromTypes(fmiTypeDefinitionsList, baseType)%>_from_integers(<%fmiGetFunction%>(<%fmiInstance%>, {<%valueReference%>}, flowStatesInputs));<%\n%> | ||
| 3736 | >> | ||
| 3737 | case FMI3ENUMERATIONVARIABLE(variability = "",causality="") then | ||
| 3738 | << | ||
| 3739 | {<%name%>} = map_<%getEnumerationTypeFromTypes(fmiTypeDefinitionsList, baseType)%>_from_integers(<%fmiGetFunction%>(<%fmiInstance%>, {<%valueReference%>}, flowStatesInputs));<%\n%> | ||
| 3740 | >> | ||
| 3741 | case FMI3ENUMERATIONVARIABLE(variability = "",causality="output") then | ||
| 3742 | << | ||
| 3743 | {<%name%>} = map_<%getEnumerationTypeFromTypes(fmiTypeDefinitionsList, baseType)%>_from_integers(<%fmiGetFunction%>(<%fmiInstance%>, {<%valueReference%>}, flowStatesInputs));<%\n%> | ||
| 3744 | >> | ||
| 3745 | end dumpOutputGetEnumerationVariable; | ||
| 3746 | |||
| 3747 | /* public */ template simulationInitFunction(SimCode simCode, String guid) | ||
| 3748 | "Generates the contents of the makefile for the simulation case. | ||
| 3749 | used in Compiler/Template/CodegenFMU.tpl" | ||
| 3750 | ::= | ||
| 3751 | match simCode | ||
| 3752 | case SIMCODE(modelInfo = MODELINFO(functions = functions, varInfo = vi as VARINFO(__), vars = vars as SIMVARS(__)), | ||
| 3753 | simulationSettingsOpt = SOME(s as SIMULATION_SETTINGS(__)), makefileParams = makefileParams as MAKEFILE_PARAMS(__)) | ||
| 3754 | then | ||
| 3755 | << | ||
| 3756 | #include "simulation_data.h" | ||
| 3757 | #include "util/real_array.h" | ||
| 3758 | #include "util/integer_array.h" | ||
| 3759 | #include "util/boolean_array.h" | ||
| 3760 | #include "util/string_array.h" | ||
| 3761 | |||
| 3762 | OMC_DISABLE_OPT<%/* This function is very simple and doesn't need to be optimized. GCC/clang spend way too much time looking at it. */%> | ||
| 3763 | |||
| 3764 | void <%symbolName(modelNamePrefix(simCode),"read_simulation_info")%>(SIMULATION_INFO* simulationInfo) | ||
| 3765 | { | ||
| 3766 | simulationInfo->startTime = <%s.startTime%>; | ||
| 3767 | simulationInfo->stopTime = <%s.stopTime%>; | ||
| 3768 | simulationInfo->stepSize = <%s.stepSize%>; | ||
| 3769 | simulationInfo->tolerance = <%s.tolerance%>; | ||
| 3770 | /* Freed in deInitializeDataStruc, like the ones read from the init XML. */ | ||
| 3771 | simulationInfo->solverMethod = GC_strdup("<%s.method%>"); | ||
| 3772 | simulationInfo->outputFormat = GC_strdup("<%s.outputFormat%>"); | ||
| 3773 | simulationInfo->variableFilter = GC_strdup("<%s.variableFilter%>"); | ||
| 3774 | simulationInfo->OPENMODELICAHOME = GC_strdup("<%makefileParams.omhome%>"); | ||
| 3775 | } | ||
| 3776 | |||
| 3777 | void <%symbolName(modelNamePrefix(simCode),"read_input_fmu")%>(MODEL_DATA* modelData) | ||
| 3778 | { | ||
| 3779 | <%System.tmpTickReset(1000)%> | ||
| 3780 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3781 | <%vars.stateVars |> var => ScalarVariableFMU(var,"realVarsData") ;separator="\n";empty%> | ||
| 3782 | <%vars.derivativeVars |> var => ScalarVariableFMU(var,"realVarsData") ;separator="\n";empty%> | ||
| 3783 | <%vars.algVars |> var => ScalarVariableFMU(var,"realVarsData") ;separator="\n";empty%> | ||
| 3784 | <%vars.discreteAlgVars |> var => ScalarVariableFMU(var,"realVarsData") ;separator="\n";empty%> | ||
| 3785 | <%vars.realOptimizeConstraintsVars | ||
| 3786 | |> var => ScalarVariableFMU(var,"realVarsData") ;separator="\n";empty%> | ||
| 3787 | <%vars.realOptimizeFinalConstraintsVars | ||
| 3788 | |> var => ScalarVariableFMU(var,"realVarsData") ;separator="\n";empty%> | ||
| 3789 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3790 | <%vars.paramVars |> var => ScalarVariableFMU(var,"realParameterData") ;separator="\n";empty%> | ||
| 3791 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3792 | <%vars.intAlgVars |> var => ScalarVariableFMU(var,"integerVarsData") ;separator="\n";empty%> | ||
| 3793 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3794 | <%vars.intParamVars |> var => ScalarVariableFMU(var,"integerParameterData") ;separator="\n";empty%> | ||
| 3795 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3796 | <%vars.boolAlgVars |> var => ScalarVariableFMU(var,"booleanVarsData") ;separator="\n";empty%> | ||
| 3797 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3798 | <%vars.boolParamVars |> var => ScalarVariableFMU(var,"booleanParameterData") ;separator="\n";empty%> | ||
| 3799 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3800 | <%vars.stringAlgVars |> var => ScalarVariableFMU(var,"stringVarsData") ;separator="\n";empty%> | ||
| 3801 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3802 | <%vars.stringParamVars |> var => ScalarVariableFMU(var,"stringParameterData") ;separator="\n";empty%> | ||
| 3803 | <%System.tmpTickResetIndex(0,2)%> | ||
| 3804 | } | ||
| 3805 | >> | ||
| 3806 | end simulationInitFunction; | ||
| 3807 | |||
| 3808 | 6834 | template getInfoArgsFMU(String str, builtin.SourceInfo info) | |
| 3809 | ::= | ||
| 3810 | match info | ||
| 3811 | case SOURCEINFO(__) then | ||
| 3812 | << | ||
| 3813 | <%str%>.filename = "<%Util.escapeModelicaStringToCString(fileName)%>"; | ||
| 3814 | <%str%>.lineStart = <%lineNumberStart%>; | ||
| 3815 | <%str%>.colStart = <%columnNumberStart%>; | ||
| 3816 | <%str%>.lineEnd = <%lineNumberEnd%>; | ||
| 3817 | <%str%>.colEnd = <%columnNumberEnd%>; | ||
| 3818 | <%str%>.readonly = <%if isReadOnly then 1 else 0%>; | ||
| 3819 | >> | ||
| 3820 | end getInfoArgsFMU; | ||
| 3821 | |||
| 3822 | 6834 | template ScalarVariableFMU(SimVar simVar, String classType) | |
| 3823 | "Generates code for ScalarVariable file for FMU target." | ||
| 3824 | ::= | ||
| 3825 | match simVar | ||
| 3826 | case SIMVAR(source = SOURCE(info = info)) then | ||
| 3827 | let valueReference = System.tmpTick() | ||
| 3828 | let ci = System.tmpTickIndex(2) | ||
| 3829 | let description = if comment then Util.escapeModelicaStringToCString(comment) | ||
| 3830 | let infostr = 'modelData-><%classType%>[<%ci%>].info' | ||
| 3831 | let attrstr = 'modelData-><%classType%>[<%ci%>].attribute' | ||
| 3832 | << | ||
| 3833 | <%infostr%>.id = <%valueReference%>; | ||
| 3834 | <%infostr%>.name = "<%Util.escapeModelicaStringToCString(crefStrNoUnderscore(name))%>"; | ||
| 3835 | <%infostr%>.comment = "<%description%>"; | ||
| 3836 | <%getInfoArgsFMU(infostr+".info", info)%> | ||
| 3837 | <%DimensionsFMU(simVar, classType, ci)%> | ||
| 3838 | <%ScalarVariableTypeFMU(attrstr, unit, displayUnit, minValue, maxValue, initialValue, nominalValue, isFixed, type_)%> | ||
| 3839 | >> | ||
| 3840 | end ScalarVariableFMU; | ||
| 3841 | |||
| 3842 | 8 | template DimensionsFMU(SimVar simVar, String classType, String ci) | |
| 3843 | "Sets the runtime array dimensions of a non-scalarized array variable so that | ||
| 3844 | calculateAllScalarLength / computeVarIndices size the value vectors correctly. | ||
| 3845 | Emits nothing for scalars (numberOfDimensions defaults to 0). Only genuine | ||
| 3846 | array variables (type_ = T_ARRAY) are dimensioned: a scalarized array element | ||
| 3847 | still carries the parent numArrayElement but is a scalar and must keep | ||
| 3848 | numberOfDimensions 0, otherwise the start/min/max/nominal bound-attribute | ||
| 3849 | update treats it as an array." | ||
| 3850 | ::= | ||
| 3851 | match simVar | ||
| 3852 | case SIMVAR(type_ = T_ARRAY(), numArrayElement = dims) then | ||
| 3853 | if listEmpty(dims) then '' else | ||
| 3854 | << | ||
| 3855 | modelData-><%classType%>[<%ci%>].dimension.numberOfDimensions = <%listLength(dims)%>; | ||
| 3856 | modelData-><%classType%>[<%ci%>].dimension.dimensions = (DIMENSION_ATTRIBUTE*)calloc(<%listLength(dims)%>, sizeof(DIMENSION_ATTRIBUTE)); | ||
| 3857 | <%dims |> d hasindex k0 => | ||
| 3858 | 'modelData-><%classType%>[<%ci%>].dimension.dimensions[<%k0%>].start = <%d%>;<%\n%>modelData-><%classType%>[<%ci%>].dimension.dimensions[<%k0%>].valueReference = -1;<%\n%>modelData-><%classType%>[<%ci%>].dimension.dimensions[<%k0%>].type = DIMENSION_BY_START;' | ||
| 3859 | ;separator="\n"%> | ||
| 3860 | >> | ||
| 3861 | end DimensionsFMU; | ||
| 3862 | |||
| 3863 | 4550 | template scalarValFMU(Exp e, String default) | |
| 3864 | "Returns a C literal for a scalar constant expression. For a non-scalarized | ||
| 3865 | array start (a uniform array constructor / reduction) the single broadcast | ||
| 3866 | element value is extracted." | ||
| 3867 | ::= | ||
| 3868 | match e | ||
| 3869 | case ICONST(__) then integer | ||
| 3870 | case RCONST(__) then real | ||
| 3871 | case SCONST(__) then 'omc_string_new("<%Util.escapeModelicaStringToCString(string)%>")' | ||
| 3872 | case BCONST(__) then if bool then 1 else 0 | ||
| 3873 | case ENUM_LITERAL(__) then '<%index%>' | ||
| 3874 | case ARRAY(array = first :: _) then scalarValFMU(first, default) | ||
| 3875 | case REDUCTION(expr = first) then scalarValFMU(first, default) | ||
| 3876 | else default // error(sourceInfo(), 'initial value of unknown type: <%printExpStr(e)%>') | ||
| 3877 | end scalarValFMU; | ||
| 3878 | |||
| 3879 | 18963 | template optInitValFMU(Option<Exp> exp, String default) | |
| 3880 | ::= | ||
| 3881 | match exp | ||
| 3882 | case SOME(e) then scalarValFMU(e, default) | ||
| 3883 | else default | ||
| 3884 | end optInitValFMU; | ||
| 3885 | |||
| 3886 | 6842 | template ScalarVariableTypeFMU(String attrstr, String unit, String displayUnit, Option<DAE.Exp> minValue, Option<DAE.Exp> maxValue, Option<DAE.Exp> startValue, Option<DAE.Exp> nominalValue, Boolean isFixed, DAE.Type type_) | |
| 3887 | "Generates code for ScalarVariable Type file for FMU target." | ||
| 3888 | ::= | ||
| 3889 | match type_ | ||
| 3890 | case T_REAL(__) then | ||
| 3891 | << | ||
| 3892 | omc_string_move(&<%attrstr%>.unit, omc_string_new("<%Util.escapeModelicaStringToCString(unit)%>")); | ||
| 3893 | omc_string_move(&<%attrstr%>.displayUnit, omc_string_new("<%Util.escapeModelicaStringToCString(displayUnit)%>")); | ||
| 3894 | put_real_element(<%optInitValFMU(minValue,"-DBL_MAX")%>, 0, &<%attrstr%>.min); | ||
| 3895 | put_real_element(<%optInitValFMU(maxValue,"DBL_MAX")%>, 0, &<%attrstr%>.max); | ||
| 3896 | <%attrstr%>.fixed = <%if isFixed then 1 else 0%>; | ||
| 3897 | <%attrstr%>.useNominal = <%if nominalValue then 1 else 0%>; | ||
| 3898 | put_real_element(<%optInitValFMU(nominalValue,"1.0")%>, 0, &<%attrstr%>.nominal); | ||
| 3899 | put_real_element(<%optInitValFMU(startValue,"0.0")%>, 0, &<%attrstr%>.start); | ||
| 3900 | >> | ||
| 3901 | case T_INTEGER(__) then | ||
| 3902 | << | ||
| 3903 | put_integer_element(<%optInitValFMU(minValue,"-LONG_MAX")%>, 0, &<%attrstr%>.min); | ||
| 3904 | put_integer_element(<%optInitValFMU(maxValue,"LONG_MAX")%>, 0, &<%attrstr%>.max); | ||
| 3905 | <%attrstr%>.fixed = <%if isFixed then 1 else 0%>; | ||
| 3906 | put_integer_element(<%optInitValFMU(startValue,"0")%>, 0, &<%attrstr%>.start); | ||
| 3907 | >> | ||
| 3908 | case T_BOOL(__) then | ||
| 3909 | << | ||
| 3910 | <%attrstr%>.fixed = <%if isFixed then 1 else 0%>; | ||
| 3911 | put_boolean_element(<%optInitValFMU(startValue,"0")%>, 0, &<%attrstr%>.start); | ||
| 3912 | >> | ||
| 3913 | case T_STRING(__) then | ||
| 3914 | << | ||
| 3915 | omc_string_move((modelica_string*) <%attrstr%>.start.data, <%optInitValFMU(startValue,"omc_string_new(\"\")")%>); | ||
| 3916 | >> | ||
| 3917 | case T_ENUMERATION(__) then | ||
| 3918 | << | ||
| 3919 | put_integer_element(<%optInitValFMU(minValue,"1")%>, 0, &<%attrstr%>.min); | ||
| 3920 | put_integer_element(<%optInitValFMU(maxValue,listLength(names))%>, 0, &<%attrstr%>.max); | ||
| 3921 | <%attrstr%>.fixed = <%if isFixed then 1 else 0%>; | ||
| 3922 | put_integer_element(<%optInitValFMU(startValue,"0")%>, 0, &<%attrstr%>.start); | ||
| 3923 | >> | ||
| 3924 | case T_ARRAY(ty=ty) then | ||
| 3925 | // non-scalarized array variable: emit the attributes using the element type | ||
| 3926 | ScalarVariableTypeFMU(attrstr, unit, displayUnit, minValue, maxValue, startValue, nominalValue, isFixed, ty) | ||
| 3927 | else error(sourceInfo(), 'ScalarVariableTypeFMU: <%unparseType(type_)%>') | ||
| 3928 | end ScalarVariableTypeFMU; | ||
| 3929 | |||
| 3930 | annotation(__OpenModelica_Interface="codegen_fmu_c"); | ||
| 3931 | end CodegenFMU; | ||
| 3932 | |||
| 3933 | // vim: filetype=susan sw=2 sts=2 | ||
| 3934 |