OMCompiler/Compiler/Template/CodegenCppInit.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 | package CodegenCppInit | ||
| 37 | |||
| 38 | import interface SimCodeTV; | ||
| 39 | import interface SimCodeBackendTV; | ||
| 40 | import CodegenUtil.*; | ||
| 41 | import CodegenCppCommon; | ||
| 42 | import CodegenFMUCommon; | ||
| 43 | import CodegenFMU2; | ||
| 44 | import CodegenFMU1; | ||
| 45 | |||
| 46 | 50 | template modelInitXMLFile(SimCode simCode, String numRealVars, String numIntVars, String numBoolVars, String numStringVars, String FMUVersion, String FMUType, String FMUGuid, Boolean generateFMUModelDescription, String generatorComments, Text& complexStartExpressions, Text stateDerVectorName) | |
| 47 | "Generate a xml file that contains informations for initialization or for the FMU-structure" | ||
| 48 | ::= | ||
| 49 | match simCode | ||
| 50 | case SIMCODE(modelInfo = MODELINFO(__)) then | ||
| 51 | let variables = modelVariablesXML(simCode, modelInfo, varToArrayIndexMapping, '<%numRealVars%> - 1', '<%numIntVars%> - 1', '<%numBoolVars%> - 1', '<%numStringVars%> - 1', generateFMUModelDescription, complexStartExpressions, stateDerVectorName) | ||
| 52 | //let algLoops = (listAppend(allEquations,initialEquations) |> eq => algLoopXML(eq, simCode, varToArrayIndexMapping, '<%numRealVars%> - 1') ;separator="\n") | ||
| 53 | //let jacobianMatrices = jacobianMatricesXML(simCode.jacobianMatrices) | ||
| 54 | let descriptionTag = if generateFMUModelDescription then "fmiModelDescription" else "ModelDescription" | ||
| 55 | let fmiDescriptionAttributes = if generateFMUModelDescription then fmiDescriptionAttributes(simCode, FMUVersion, FMUType, FMUGuid) else 'modelName="<%dotPath(modelInfo.name)%>"' | ||
| 56 | let fmiTypeDefinitions = if generateFMUModelDescription then CodegenFMUCommon.fmiTypeDefinitions(simCode, FMUVersion) | ||
| 57 | let fmiDefaultExperiment = if generateFMUModelDescription then CodegenFMUCommon.DefaultExperiment(simulationSettingsOpt, FMUVersion) | ||
| 58 | << | ||
| 59 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 60 | <!--Generated with the modifications: <%generatorComments%> --> | ||
| 61 | <!--Take care about array indices, they are stored in column major layout.--> | ||
| 62 | <<%descriptionTag%> <%fmiDescriptionAttributes%>> | ||
| 63 | <%fmiTypeDefinitions%> | ||
| 64 | <%fmiDefaultExperiment%> | ||
| 65 | <ModelVariables> | ||
| 66 | <%variables%> | ||
| 67 | </ModelVariables> | ||
| 68 | </<%descriptionTag%>> | ||
| 69 | >> | ||
| 70 | /* | ||
| 71 | <%if boolNot(generateFMUModelDescription) then | ||
| 72 | << | ||
| 73 | <AlgLoops> | ||
| 74 | <%algLoops%> | ||
| 75 | </AlgLoops> | ||
| 76 | <Jacobian> | ||
| 77 | <%jacobianMatrices%> | ||
| 78 | </Jacobian> | ||
| 79 | >> | ||
| 80 | %> | ||
| 81 | */ | ||
| 82 | end modelInitXMLFile; | ||
| 83 | |||
| 84 | 1 | template fmiDescriptionAttributes(SimCode simCode, String FMUVersion, String FMUType, String FMUGuid) | |
| 85 | ::= | ||
| 86 | if isFMIVersion20(FMUVersion) then CodegenFMU2.fmiModelDescriptionAttributes(simCode,FMUGuid) | ||
| 87 | else fmiModelDescriptionAttributes(simCode,FMUGuid) | ||
| 88 | end fmiDescriptionAttributes; | ||
| 89 | |||
| 90 | 1 | template fmiModelDescriptionAttributes(SimCode simCode, String guid) | |
| 91 | "Generates code for ModelDescription file for FMU target." | ||
| 92 | ::= | ||
| 93 | match simCode | ||
| 94 | case SIMCODE(modelInfo = MODELINFO(varInfo = vi as VARINFO(__), vars = SIMVARS(stateVars = listStates))) then | ||
| 95 | let fmiVersion = '1.0' | ||
| 96 | let modelName = System.stringReplace(dotPath(modelInfo.name),"$", "_D_") | ||
| 97 | let modelIdentifier = System.stringReplace(fileNamePrefix,".", "_") | ||
| 98 | let description = '' | ||
| 99 | let author = '' | ||
| 100 | let version= '' | ||
| 101 | let generationTool= 'OpenModelica Compiler <%getVersionNr()%>' | ||
| 102 | let generationDateAndTime = CodegenFMUCommon.xsdateTime(Util.getCurrentDateTime()) | ||
| 103 | let variableNamingConvention = 'structured' | ||
| 104 | let numberOfContinuousStates = vi.numStateVars | ||
| 105 | let numberOfEventIndicators = CodegenFMUCommon.getNumberOfEventIndicators(simCode) | ||
| 106 | << | ||
| 107 | fmiVersion="<%fmiVersion%>" | ||
| 108 | modelName="<%modelName%>" | ||
| 109 | modelIdentifier="<%modelIdentifier%>" | ||
| 110 | guid="{<%guid%>}" | ||
| 111 | generationTool="<%generationTool%>" | ||
| 112 | generationDateAndTime="<%generationDateAndTime%>" | ||
| 113 | variableNamingConvention="<%variableNamingConvention%>" | ||
| 114 | numberOfContinuousStates="<%numberOfContinuousStates%>" | ||
| 115 | numberOfEventIndicators="<%numberOfEventIndicators%>" | ||
| 116 | >> | ||
| 117 | end fmiModelDescriptionAttributes; | ||
| 118 | |||
| 119 | 50 | template modelVariablesXML(SimCode simCode, ModelInfo modelInfo, HashTableCrIListArray.HashTable varToArrayIndexMapping, String indexForUndefinedReferencesReal, | |
| 120 | String indexForUndefinedReferencesInt, String indexForUndefinedReferencesBool, String indexForUndefinedReferencesString, | ||
| 121 | Boolean generateFMUModelDescription, Text& complexStartExpressions, Text stateDerVectorName) | ||
| 122 | "Generates the xml code for the variable defintions." | ||
| 123 | ::= | ||
| 124 | match modelInfo | ||
| 125 | case MODELINFO(vars=SIMVARS(__),varInfo=VARINFO(numAlgVars= numAlgVars, numDiscreteReal = numDiscreteReal, numOptimizeConstraints = numOptimizeConstraints)) then | ||
| 126 | << | ||
| 127 | <%vars.stateVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 128 | <%vars.derivativeVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 129 | <%vars.algVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 130 | <%vars.discreteAlgVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 131 | <%/*vars.realOptimizeConstraintsVars | ||
| 132 | |> var hasindex i0 => scalarVariableXML(simCode, var,varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty*/%> | ||
| 133 | <%/*vars.realOptimizeFinalConstraintsVars | ||
| 134 | |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty*/%> | ||
| 135 | <%vars.paramVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 136 | <%vars.aliasVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesReal, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 137 | |||
| 138 | <%vars.intAlgVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesInt, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 139 | <%vars.intParamVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesInt, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 140 | <%vars.intAliasVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesInt, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 141 | |||
| 142 | <%vars.boolAlgVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesBool, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 143 | <%vars.boolParamVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesBool, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 144 | <%vars.boolAliasVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesBool, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 145 | |||
| 146 | <%vars.stringAlgVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesString, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 147 | <%vars.stringParamVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesString, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 148 | <%vars.stringAliasVars |> var => scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferencesString, generateFMUModelDescription, complexStartExpressions, stateDerVectorName) ;separator="\n";empty%> | ||
| 149 | >> | ||
| 150 | end modelVariablesXML; | ||
| 151 | |||
| 152 | 11904 | template scalarVariableXML(SimCode simCode, SimVar simVar, HashTableCrIListArray.HashTable varToArrayIndexMapping, String indexForUndefinedReferences, Boolean generateFMUModelDescription, Text& complexStartExpressions, Text stateDerVectorName) | |
| 153 | "Generates code for ScalarVariable file for FMU target." | ||
| 154 | ::= | ||
| 155 | match simVar | ||
| 156 | case SIMVAR(type_ = T_ARRAY(), arrayCref = SOME(__)) then | ||
| 157 | let variableCode = if generateFMUModelDescription then CodegenFMUCommon.ScalarVariableType(simVar) else | ||
| 158 | ScalarVariableType(simCode, name, aliasvar, unit, displayUnit, minValue, maxValue, initialValue, nominalValue, isFixed, type_, complexStartExpressions, stateDerVectorName) | ||
| 159 | << | ||
| 160 | <ArrayVariable <%scalarVariableAttributeXML(simVar, simCode, indexForUndefinedReferences, generateFMUModelDescription)%>> | ||
| 161 | <%variableCode%> | ||
| 162 | <%simVar.numArrayElement |> dim => '<Dimension start="<%dim%>"/>'; separator="\n"%> | ||
| 163 | </ArrayVariable> | ||
| 164 | >> | ||
| 165 | case SIMVAR(type_ = T_ARRAY()) then | ||
| 166 | /* call ScalarVariableType for array to update complexStartExpressions */ | ||
| 167 | let _ = if not generateFMUModelDescription then | ||
| 168 | ScalarVariableType(simCode, name, aliasvar, unit, displayUnit, minValue, maxValue, initialValue, nominalValue, isFixed, Types.arrayElementType(type_), complexStartExpressions, stateDerVectorName) | ||
| 169 | /* roll out array as XML file only supports scalars */ | ||
| 170 | let &complexStartExpressionsForScalarsUnused = buffer "" | ||
| 171 | '<%getScalarElements(simVar) |> var => | ||
| 172 | scalarVariableXML(simCode, var, varToArrayIndexMapping, indexForUndefinedReferences, generateFMUModelDescription, complexStartExpressionsForScalarsUnused, stateDerVectorName) | ||
| 173 | ;separator="\n"%>' | ||
| 174 | case SIMVAR(__) then | ||
| 175 | let variableCode = if generateFMUModelDescription then CodegenFMUCommon.ScalarVariableType(simVar) else | ||
| 176 | ScalarVariableType(simCode, name, aliasvar, unit, displayUnit, minValue, maxValue, initialValue, nominalValue, isFixed, type_, complexStartExpressions, stateDerVectorName) | ||
| 177 | << | ||
| 178 | <ScalarVariable <%scalarVariableAttributeXML(simVar, simCode, indexForUndefinedReferences, generateFMUModelDescription)%>> | ||
| 179 | <%variableCode%> | ||
| 180 | </ScalarVariable> | ||
| 181 | >> | ||
| 182 | end scalarVariableXML; | ||
| 183 | |||
| 184 | 11870 | template scalarVariableAttributeXML(SimVar simVar, SimCode simCode, String indexForUndefinedReferences, Boolean generateFMUModelDescription) | |
| 185 | "Generates code for ScalarVariable Attribute file for FMU target." | ||
| 186 | ::= | ||
| 187 | match simVar | ||
| 188 | case SIMVAR(source = SOURCE(info = info)) then | ||
| 189 | let valueReference = SimCodeCodegenUtil.getValueReference(simVar, simCode, true) | ||
| 190 | let alias = getAliasAttribute(aliasvar) | ||
| 191 | let causalityAtt = CodegenFMUCommon.getCausality(causality) | ||
| 192 | let variability = getVariablity(varKind) | ||
| 193 | let description = if comment then 'description="<%Util.escapeModelicaStringToXmlString(comment)%>"' | ||
| 194 | let hr = match hideResult case SOME(bval) then '<%bval%>' | ||
| 195 | let additionalAttributes = if generateFMUModelDescription then '' else 'isProtected="<%isProtected%>" hideResult="<%hr%>" isDiscrete="<%isDiscrete%>" isValueChangeable="<%isValueChangeable%>"' | ||
| 196 | << | ||
| 197 | name="<%System.stringReplace(Util.escapeModelicaStringToXmlString(crefStrNoUnderscore(name)),"$", "_D_")%>" valueReference="<%valueReference%>" <%description%> variability="<%variability%>" causality="<%causalityAtt%>" alias="<%alias%>" <%additionalAttributes%> | ||
| 198 | >> | ||
| 199 | end scalarVariableAttributeXML; | ||
| 200 | |||
| 201 | 8041 | template getAliasAttribute(AliasVariable aliasvar) | |
| 202 | "Returns the alias Attribute of ScalarVariable." | ||
| 203 | ::= | ||
| 204 | match aliasvar | ||
| 205 | case NOALIAS(__) then "noAlias" | ||
| 206 | case ALIAS(__) then "alias" | ||
| 207 | case NEGATEDALIAS(__) then "negatedAlias" | ||
| 208 | else "undefinedAliasType" | ||
| 209 | end getAliasAttribute; | ||
| 210 | |||
| 211 | 11896 | template ScalarVariableType(SimCode simCode, DAE.ComponentRef simVarCref, AliasVariable simVarAlias, 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_, Text& complexStartExpressions, Text stateDerVectorName) | |
| 212 | "Generates code for ScalarVariable Type file for FMU target." | ||
| 213 | ::= | ||
| 214 | match Types.arrayElementType(type_) | ||
| 215 | case T_INTEGER(__) then | ||
| 216 | let start_ = ScalarVariableTypeStartAttribute(simCode, simVarCref, simVarAlias, startValue, "Int", complexStartExpressions, stateDerVectorName) | ||
| 217 | let fixed_ = ' fixed="<%isFixed%>"' | ||
| 218 | let min_ = attributeOptionString(minValue, "min") | ||
| 219 | let max_ = attributeOptionString(maxValue, "max") | ||
| 220 | let unit_ = unitString(unit, "unit") | ||
| 221 | let disp_ = unitString(displayUnit, "displayUnit") | ||
| 222 | '<Integer <%start_%><%fixed_%><%min_%><%max_%><%unit_%><%disp_%> />' | ||
| 223 | case T_REAL(__) then | ||
| 224 | let start_ = ScalarVariableTypeStartAttribute(simCode, simVarCref, simVarAlias, startValue, "Real", complexStartExpressions, stateDerVectorName) | ||
| 225 | let fixed_ = ' fixed="<%isFixed%>"' | ||
| 226 | let nom_ = ' useNominal="<%isSome(nominalValue)%>"<%attributeOptionString(nominalValue, "nominal")%>' | ||
| 227 | let min_ = attributeOptionString(minValue, "min") | ||
| 228 | let max_ = attributeOptionString(maxValue, "max") | ||
| 229 | let unit_ = unitString(unit, "unit") | ||
| 230 | let disp_ = unitString(displayUnit, "displayUnit") | ||
| 231 | '<Real <%start_%><%fixed_%><%nom_%><%min_%><%max_%><%unit_%><%disp_%> />' | ||
| 232 | case T_BOOL(__) then | ||
| 233 | let start_ = ScalarVariableTypeStartAttribute(simCode, simVarCref, simVarAlias, startValue, "Bool", complexStartExpressions, stateDerVectorName) | ||
| 234 | let fixed_ = ' fixed="<%isFixed%>"' | ||
| 235 | let unit_ = unitString(unit, "unit") | ||
| 236 | let disp_ = unitString(displayUnit, "displayUnit") | ||
| 237 | '<Boolean <%start_%><%fixed_%><%unit_%><%disp_%> />' | ||
| 238 | case T_STRING(__) then | ||
| 239 | let start_ = ScalarVariableTypeStartAttribute(simCode, simVarCref, simVarAlias, startValue, "String", complexStartExpressions, stateDerVectorName) | ||
| 240 | let fixed_ = ' fixed="<%isFixed%>"' | ||
| 241 | let unit_ = unitString(unit, "unit") | ||
| 242 | let disp_ = unitString(displayUnit, "displayUnit") | ||
| 243 | '<String <%start_%><%fixed_%><%unit_%><%disp_%> />' | ||
| 244 | case T_ENUMERATION(__) then | ||
| 245 | let start_ = ScalarVariableTypeStartAttribute(simCode, simVarCref, simVarAlias, startValue, "Int", complexStartExpressions, stateDerVectorName) | ||
| 246 | let fixed_ = ' fixed="<%isFixed%>"' | ||
| 247 | let unit_ = unitString(unit, "unit") | ||
| 248 | let disp_ = unitString(displayUnit, "displayUnit") | ||
| 249 | '<Integer <%start_%><%fixed_%><%unit_%><%disp_%> />' | ||
| 250 | case T_COMPLEX(complexClassType = ci as ClassInf.EXTERNAL_OBJ(__)) then | ||
| 251 | '<ExternalObject path="<%escapeModelicaStringToXmlString(dotPath(ci.path))%>" />' | ||
| 252 | else error(sourceInfo(), 'ScalarVariableType: <%unparseType(type_)%>') | ||
| 253 | end ScalarVariableType; | ||
| 254 | |||
| 255 | 8306 | template attributeString(DAE.Exp exp, String attr_name) | |
| 256 | ::= | ||
| 257 | match exp | ||
| 258 | case ICONST(__) | ||
| 259 | case RCONST(__) | ||
| 260 | case SCONST(__) | ||
| 261 | case BCONST(__) | ||
| 262 | case ENUM_LITERAL(__) then ' <%attr_name%>="<%initValXml(exp, '')%>"' | ||
| 263 | case ARRAY(__) then if Expression.isSimpleLiteralValue(exp, true) then ' <%attr_name%>="<%array |> elem => initValXml(elem, '"') ;separator=" "%>"' else '' | ||
| 264 | /* this is basically an each operator, just write one value and repeat it for the size when using it later */ | ||
| 265 | case REDUCTION() then if Expression.isSimpleLiteralValue(expr, true) then '<%attributeString(expr, attr_name)%>' else '' | ||
| 266 | else '' | ||
| 267 | end attributeString; | ||
| 268 | |||
| 269 | 5377 | template attributeOptionString(Option<DAE.Exp> exp_opt, String attr_name) | |
| 270 | "generates code for an attribute" | ||
| 271 | ::= | ||
| 272 | match exp_opt | ||
| 273 | case SOME(exp) then attributeString(exp, attr_name) | ||
| 274 | else '' | ||
| 275 | end attributeOptionString; | ||
| 276 | |||
| 277 | 8011 | template unitString(String unit, String attr_name) | |
| 278 | "generates code for unit attribute" | ||
| 279 | ::= | ||
| 280 | if unit then ' <%attr_name%>="<%Util.escapeModelicaStringToXmlString(unit)%>"' | ||
| 281 | end unitString; | ||
| 282 | |||
| 283 | 11896 | template ScalarVariableTypeStartAttribute(SimCode simCode, DAE.ComponentRef simVarCref, AliasVariable simVarAlias, Option<DAE.Exp> startValue, Text type, Text& complexStartExpressions, Text stateDerVectorName) | |
| 284 | "generates code for start attribute, | ||
| 285 | adds non-constant start values to complexStartExpressions" | ||
| 286 | ::= | ||
| 287 | match startValue | ||
| 288 | case SOME(exp) then | ||
| 289 | let startString = attributeString(exp, "start") | ||
| 290 | match startString | ||
| 291 | case "" then | ||
| 292 | let unsued = match simVarAlias | ||
| 293 | case NOALIAS(__) then | ||
| 294 | let &complexPreExpression = buffer "" | ||
| 295 | let &varDecls = buffer "" | ||
| 296 | let &extraFuncs = buffer "" | ||
| 297 | let &extraFuncsDecl = buffer "" | ||
| 298 | let crefStr = CodegenCppCommon.cref1(simVarCref, simCode , &extraFuncs, &extraFuncsDecl, "", contextOther, varDecls, stateDerVectorName, false) | ||
| 299 | let expression = CodegenCppCommon.daeExp(exp, contextOther, &complexPreExpression, &varDecls, simCode, &extraFuncs , &extraFuncsDecl, "", stateDerVectorName, false) | ||
| 300 | let &complexStartExpressions += '<%varDecls%><%complexPreExpression%>SystemDefaultImplementation::set<%type%>StartValue(<%crefStr%>,<%expression%>);<%\n%>' | ||
| 301 | '' | ||
| 302 | else '' | ||
| 303 | '' | ||
| 304 | else | ||
| 305 | '<%startString%>' | ||
| 306 | case NONE() then '' | ||
| 307 | end ScalarVariableTypeStartAttribute; | ||
| 308 | |||
| 309 | ✗ | template algLoopXML(SimEqSystem eqs, SimCode simCode, HashTableCrIListArray.HashTable varToArrayIndexMapping, String indexForUndefinedReferences) | |
| 310 | ::= | ||
| 311 | << | ||
| 312 | <% | ||
| 313 | match(eqs) | ||
| 314 | case(SES_LINEAR(lSystem = ls as LINEARSYSTEM(__))) then | ||
| 315 | << | ||
| 316 | <Linear eqIdx="<%ls.index%>" sparse="true" size="<%listLength(ls.vars)%>"> | ||
| 317 | <Vars> | ||
| 318 | <%ls.vars |> v as SIMVAR(__) => '<Var type="double" index="<%SimCodeCodegenUtil.getVarIndexListByMapping(varToArrayIndexMapping,v.name,true,indexForUndefinedReferences)%>" />' ;separator="\n"%> | ||
| 319 | </Vars> | ||
| 320 | </Linear> | ||
| 321 | >> | ||
| 322 | case(SES_NONLINEAR(nlSystem = nls as NONLINEARSYSTEM(__))) then | ||
| 323 | << | ||
| 324 | <NonLinear eqIdx="<%nls.index%>" size="<%listLength(nls.crefs)%>"> | ||
| 325 | <Vars> | ||
| 326 | <%nls.crefs |> name => '<Var type="double" index="<%SimCodeCodegenUtil.getVarIndexListByMapping(varToArrayIndexMapping,name,true,indexForUndefinedReferences)%>" />' ;separator="\n"%> | ||
| 327 | </Vars> | ||
| 328 | <NominalVars> | ||
| 329 | <!-- Maybe Expressions here --> | ||
| 330 | </NominalVars> | ||
| 331 | </NonLinear> | ||
| 332 | >> | ||
| 333 | else | ||
| 334 | '' | ||
| 335 | %> | ||
| 336 | >> | ||
| 337 | end algLoopXML; | ||
| 338 | |||
| 339 | ✗ | template jacobianMatricesXML(list<JacobianMatrix> JacobianMatrices) | |
| 340 | ::= | ||
| 341 | let jacMats = (JacobianMatrices |> JAC_MATRIX(columns=mat, seedVars=vars, matrixName=name, sparsity=sparsepattern, coloredCols=colorList, maxColorCols=maxColor, jacobianIndex=jacIndex) => | ||
| 342 | jacobianMatrixXML(jacIndex, mat, vars, name, sparsepattern, colorList, maxColor) | ||
| 343 | ;separator="\n";empty) | ||
| 344 | << | ||
| 345 | <%jacMats%> | ||
| 346 | >> | ||
| 347 | end jacobianMatricesXML; | ||
| 348 | |||
| 349 | ✗ | template jacobianMatrixXML(Integer indexJacobian, list<JacobianColumn> jacobianColumn, list<SimVar> seedVars, String matrixName, SparsityPattern sparsepattern, list<list<Integer>> colorList, Integer maxColor) | |
| 350 | ::= | ||
| 351 | let indexColumn = (jacobianColumn |> JAC_COLUMN(numberOfResultVars=nRows) => '<%nRows%>'; separator="\n") | ||
| 352 | let jacvals = (sparsepattern |> (index,indexes) hasindex index0 => | ||
| 353 | '<Column> | ||
| 354 | <%(indexes |> i_index hasindex index1 => | ||
| 355 | ( | ||
| 356 | match indexColumn case "1" then '<Entry indexX="<%index%>" indexY="0" valueIndex="0"/>' | ||
| 357 | else '<Entry indexX="<%index%>" indexY="<%i_index%>" valueIndex="<%i_index%>"/>' | ||
| 358 | );separator="\n" | ||
| 359 | )%> | ||
| 360 | </Column>' | ||
| 361 | ;separator="\n" | ||
| 362 | ) | ||
| 363 | << | ||
| 364 | <Matrix name="<%matrixName%>"> | ||
| 365 | <Column> | ||
| 366 | <%jacvals%> | ||
| 367 | </Column> | ||
| 368 | </Matrix> | ||
| 369 | >> | ||
| 370 | end jacobianMatrixXML; | ||
| 371 | |||
| 372 | annotation(__OpenModelica_Interface="codegen_cpp_common"); | ||
| 373 | end CodegenCppInit; | ||
| 374 |