Skip to content

Commit

Permalink
clear up $cse variables for FMI modelDescription.xml (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 committed Feb 13, 2020
1 parent 7195011 commit bde36e3
Show file tree
Hide file tree
Showing 12 changed files with 616 additions and 1,667 deletions.
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/SimCode/ReduceDAE.mo
Expand Up @@ -2191,14 +2191,14 @@ algorithm
//create simVar for label_1

simVar_1 = SimCodeVar.SIMVAR(DAE.CREF_IDENT(name1,DAE.T_REAL_DEFAULT,{}),BackendDAE.PARAM(),"","","",p,NONE(),NONE(),SOME(DAE.RCONST(1.0)),NONE(),
true,DAE.T_REAL_DEFAULT,false,NONE(),SimCodeVar.NOALIAS(),DAE.emptyElementSource,SOME(SimCodeVar.LOCAL()),NONE(),{},false,false,false,NONE(),NONE(),NONE(),NONE());
true,DAE.T_REAL_DEFAULT,false,NONE(),SimCodeVar.NOALIAS(),DAE.emptyElementSource,SOME(SimCodeVar.LOCAL()),NONE(),NONE(),{},false,false,false,NONE(),NONE(),NONE(),NONE(),false);
param=listReverse(param);
//add simVar_1 to parameter list
param_1=simVar_1::param;
p=p+1;
//create simVar_2 to parameter list
simVar_2 = SimCodeVar.SIMVAR(DAE.CREF_IDENT(name2,DAE.T_REAL_DEFAULT,{}),BackendDAE.PARAM(),"","","",p,NONE(),NONE(),SOME(DAE.RCONST(0.0)),NONE(),
true,DAE.T_REAL_DEFAULT,false,NONE(),SimCodeVar.NOALIAS(),DAE.emptyElementSource,SOME(SimCodeVar.LOCAL()),NONE(),{},false,false,false,NONE(),NONE(),NONE(),NONE());
true,DAE.T_REAL_DEFAULT,false,NONE(),SimCodeVar.NOALIAS(),DAE.emptyElementSource,SOME(SimCodeVar.LOCAL()),NONE(),NONE(),{},false,false,false,NONE(),NONE(),NONE(),NONE(),false);
//add simVar_2 to parameter list
param_2=simVar_2::param_1;
param_2=listReverse(param_2);
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/SimCode/SimCodeMain.mo
Expand Up @@ -1300,15 +1300,15 @@ algorithm
((_, resVars)) := BackendVariable.traverseBackendDAEVars(daeVars, BackendVariable.collectVarKindVarinVariables, (BackendVariable.isDAEmodeResVar, BackendVariable.emptyVars()));
((residualVars, _)) := BackendVariable.traverseBackendDAEVars(resVars, SimCodeUtil.traversingdlowvarToSimvar, ({}, BackendVariable.emptyVars()));
residualVars := SimCodeUtil.rewriteIndex(residualVars, 0);
(residualVars, _) := SimCodeUtil.setVariableIndexHelper(residualVars, 0);
(residualVars, _) := SimCodeUtil.setVariableIndexHelper(residualVars, 0, 0);
crefToSimVarHT:= List.fold(residualVars,HashTableCrefSimVar.addSimVarToHashTable,crefToSimVarHT);

// create auxiliary variables, set index and push them SimCode Hash Table
((_, auxVars)) := BackendVariable.traverseBackendDAEVars(daeVars, BackendVariable.collectVarKindVarinVariables, (BackendVariable.isDAEmodeAuxVar, BackendVariable.emptyVars()));
((auxiliaryVars, _)) := BackendVariable.traverseBackendDAEVars(auxVars, SimCodeUtil.traversingdlowvarToSimvar, ({}, BackendVariable.emptyVars()));
auxiliaryVars := List.sort(auxiliaryVars, SimCodeUtil.simVarCompareByCrefSubsAtEndlLexical);
auxiliaryVars := SimCodeUtil.rewriteIndex(auxiliaryVars, 0);
(auxiliaryVars, _) := SimCodeUtil.setVariableIndexHelper(auxiliaryVars, 0);
(auxiliaryVars, _) := SimCodeUtil.setVariableIndexHelper(auxiliaryVars, 0, 0);
crefToSimVarHT:= List.fold(auxiliaryVars,HashTableCrefSimVar.addSimVarToHashTable,crefToSimVarHT);

// create SimCodeVars for algebraic states
Expand Down
126 changes: 83 additions & 43 deletions OMCompiler/Compiler/SimCode/SimCodeUtil.mo

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion OMCompiler/Compiler/SimCode/SimCodeVar.mo
Expand Up @@ -95,7 +95,8 @@ public uniontype SimVar "Information about a variable in a Modelica model."
AliasVariable aliasvar;
DAE.ElementSource source;
Option<Causality> causality;
Option<Integer> variable_index;
Option<Integer> variable_index "valueReference";
Option<Integer> fmi_index "index of variable in modelDescription.xml";
list<String> numArrayElement;
Boolean isValueChangeable;
Boolean isProtected;
Expand All @@ -104,6 +105,7 @@ public uniontype SimVar "Information about a variable in a Modelica model."
Option<String> matrixName "if the varibale is a jacobian var, this is the corresponding matrix";
Option<Variability> variability "FMI-2.0 variabilty attribute";
Option<Initial> initial_ "FMI-2.0 initial attribute";
Boolean exportVar "variables will only be exported to the modelDescription.xml if this attribute is true";
end SIMVAR;
end SimVar;

Expand Down
17 changes: 10 additions & 7 deletions OMCompiler/Compiler/Template/CodegenFMUCommon.tpl
Expand Up @@ -171,13 +171,16 @@ case SIMVAR(__) then
else if stringEq(crefStr(name),"der($dummy)") then
<<>>
else if isFMIVersion20(FMUVersion) then
<<
<!-- Index of variable = "<%getVariableIndex(simVar)%>" -->
<ScalarVariable
<%ScalarVariableAttribute2(simVar, simCode)%>>
<%ScalarVariableType2(simVar, stateVars)%>
</ScalarVariable>
>>
if exportVar then
<<
<!-- Index of variable = "<%getVariableFMIIndex(simVar)%>" -->
<ScalarVariable
<%ScalarVariableAttribute2(simVar, simCode)%>>
<%ScalarVariableType2(simVar, stateVars)%>
</ScalarVariable>
>>
else
''
else
<<
<ScalarVariable
Expand Down
13 changes: 10 additions & 3 deletions OMCompiler/Compiler/Template/SimCodeTV.mo
Expand Up @@ -261,14 +261,16 @@ package SimCodeVar
AliasVariable aliasvar;
DAE.ElementSource source;
Option<Causality> causality;
Option<Integer> variable_index;
Option<Integer> variable_index "valueReference";
Option<Integer> fmi_index "index of variable in modelDescription.xml";
list<String> numArrayElement;
Boolean isValueChangeable;
Boolean isProtected;
Boolean hideResult;
Option<String> matrixName;
Option<Variability> variability; // variabilty attribute of a variable needed for FMI-2.0
Option<Initial> initial_; // initial attribute of a variable needed for FMI-2.0
Option<Variability> variability "FMI-2.0 variabilty attribute";
Option<Initial> initial_ "FMI-2.0 initial attribute";
Boolean exportVar "true for internal variables that are introduced in the symbolic transformation process";
end SIMVAR;
end SimVar;

Expand Down Expand Up @@ -1054,6 +1056,11 @@ package SimCodeUtil
output Integer outVariableIndex;
end getVariableIndex;

function getVariableFMIIndex
input SimCodeVar.SimVar inVar;
output Integer outIndex;
end getVariableFMIIndex;

function getMaxSimEqSystemIndex
input SimCode.SimCode simCode;
output Integer idxOut;
Expand Down
2 changes: 2 additions & 0 deletions OMCompiler/Compiler/Util/Flags.mo
Expand Up @@ -553,6 +553,8 @@ constant DebugFlag NF_DUMP_FLAT = DEBUG_FLAG(192, "nfDumpFlat", false,
Gettext.gettext("Dumps the flat model structure before generating the DAE."));
constant DebugFlag DUMP_FORCE_FMI_ATTRIBUTES = DEBUG_FLAG(193, "force-fmi-attributes", false,
Gettext.gettext("Force to export all fmi attributes to the modelDescription.xml, including those which have default values"));
constant DebugFlag DUMP_FORCE_FMI_INTERNAL_VARIABLES = DEBUG_FLAG(194, "force-fmi-internal-variables", false,
Gettext.gettext("Force to export all internal variables (eg: $CSE) to the modelDescription.xml"));

public
// CONFIGURATION FLAGS
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/Util/FlagsUtil.mo
Expand Up @@ -249,7 +249,8 @@ constant list<Flags.DebugFlag> allDebugFlags = {
Flags.DUMP_ASSC,
Flags.SPLIT_CONSTANT_PARTS_SYMJAC,
Flags.NF_DUMP_FLAT,
Flags.DUMP_FORCE_FMI_ATTRIBUTES
Flags.DUMP_FORCE_FMI_ATTRIBUTES,
Flags.DUMP_FORCE_FMI_INTERNAL_VARIABLES
};

protected
Expand Down

0 comments on commit bde36e3

Please sign in to comment.