Skip to content

Commit 4cea11d

Browse files
authored
Set aux vars to protected (#14726)
1 parent 5151d39 commit 4cea11d

File tree

6 files changed

+55
-36
lines changed

6 files changed

+55
-36
lines changed

OMCompiler/Compiler/BackEnd/SynchronousFeatures.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,7 @@ algorithm
23892389
varDirection = DAE.BIDIR(), varParallelism = DAE.NON_PARALLEL(),
23902390
varType = inType, bindExp = NONE(), tplExp = NONE(),
23912391
arryDim = {}, source = DAE.emptyElementSource,
2392-
values = NONE(), tearingSelectOption = SOME(BackendDAE.DEFAULT()),
2392+
values = DAEUtil.setProtectedAttr(DAEUtil.getEmptyVarAttr(inType), true), tearingSelectOption = SOME(BackendDAE.DEFAULT()),
23932393
hideResult = NONE(),
23942394
comment = NONE(), connectorType = DAE.NON_CONNECTOR(),
23952395
innerOuter = DAE.NOT_INNER_OUTER(), unreplaceable = false, initNonlinear = false, encrypted = false);

OMCompiler/Compiler/FrontEnd/DAE.mo

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,12 @@ uniontype VariableAttributes
556556
end VAR_ATTR_ENUMERATION;
557557
end VariableAttributes;
558558

559-
public constant VariableAttributes emptyVarAttrReal = VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
560-
public constant VariableAttributes emptyVarAttrBool = VAR_ATTR_BOOL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
559+
public constant VariableAttributes emptyVarAttrReal = VAR_ATTR_REAL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
560+
public constant VariableAttributes emptyVarAttrInt = VAR_ATTR_INT(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
561+
public constant VariableAttributes emptyVarAttrBool = VAR_ATTR_BOOL(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
562+
public constant VariableAttributes emptyVarAttrClock = VAR_ATTR_CLOCK(NONE(),NONE());
563+
public constant VariableAttributes emptyVarAttrString = VAR_ATTR_STRING(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
564+
public constant VariableAttributes emptyVarAttrEnum = VAR_ATTR_ENUMERATION(NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE(),NONE());
561565

562566
public uniontype StateSelect
563567
record NEVER end NEVER;

OMCompiler/Compiler/FrontEnd/DAEUtil.mo

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,21 @@ algorithm
370370
end match;
371371
end getClassList;
372372

373+
public function getEmptyVarAttr
374+
input DAE.Type ty;
375+
output Option<DAE.VariableAttributes> attr;
376+
algorithm
377+
attr := match Types.getBasicType(ty)
378+
case DAE.Type.T_REAL() then SOME(DAE.emptyVarAttrReal);
379+
case DAE.Type.T_INTEGER() then SOME(DAE.emptyVarAttrInt);
380+
case DAE.Type.T_BOOL() then SOME(DAE.emptyVarAttrBool);
381+
case DAE.Type.T_STRING() then SOME(DAE.emptyVarAttrString);
382+
case DAE.Type.T_ENUMERATION() then SOME(DAE.emptyVarAttrEnum);
383+
case DAE.Type.T_CLOCK() then SOME(DAE.emptyVarAttrClock);
384+
else NONE();
385+
end match;
386+
end getEmptyVarAttr;
387+
373388
public function getBoundStartEquation "
374389
Returned bound equation"
375390
input DAE.VariableAttributes attr;

OMCompiler/Compiler/SimCode/SimCodeUtil.mo

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,11 +5350,9 @@ algorithm
53505350
local
53515351
BackendDAE.Var v, v1;
53525352
SimCodeVar.SimVar simVar;
5353-
DAE.ComponentRef currVar, cref, derivedCref;
5353+
DAE.ComponentRef currVar, derivedCref;
53545354
list<BackendDAE.Var> restVar;
53555355
Option<DAE.VariableAttributes> dae_var_attr;
5356-
Boolean isProtected;
5357-
Boolean hideResult = false;
53585356
Integer resIndex=inResIndex, tmpIndex=inTmpIndex;
53595357
BackendDAE.VarKind varkind;
53605358

@@ -9508,10 +9506,10 @@ algorithm
95089506
str := "SubPartition Vars:\n"+UNDERLINE+"\n";
95099507
str := str + stringDelimitList(simVarStrings,"\n")+"\n";
95109508
str := str + "partition equations:\n"+UNDERLINE+"\n";
9511-
str := str + stringDelimitList(List.map(subPart.equations,simEqSystemString),"\n");
9509+
str := str + stringDelimitList(List.map(subPart.equations,simEqSystemString),"\n") + "\n";
95129510
str := str + "removedEquations equations:\n"+UNDERLINE+"\n";
95139511
str := str + stringDelimitList(List.map(subPart.removedEquations,simEqSystemString),"\n");
9514-
str := str + "SubClock:\n"+ BackendDump.subClockString(subPart.subClock);
9512+
str := str + "SubClock:\n"+ BackendDump.subClockString(subPart.subClock) + "\n";
95159513
str := str + "Hold Events: "+boolString(subPart.holdEvents);
95169514
end subPartitionString;
95179515

testsuite/openmodelica/cppruntime/testArrayEquations.mos

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ val(y4, 1.0);
129129
// x4[i]=(if firstTick() then 0.0 else $DER.x4[i]) * interval() + previous(x4[i])[Real]
130130
// end for;
131131
// 21: y4=sum(x4) [Real]
132-
// 22: y3=sum(x3) [Real]removedEquations equations:
132+
// 22: y3=sum(x3) [Real]
133+
// removedEquations equations:
133134
// ========================================
134135
// SubClock:
135-
// factor(1/1) shift(0/1) Hold Events: false
136+
// factor(1/1) shift(0/1)
137+
// Hold Events: false
136138
//
137139
// ========================================
138140
//

testsuite/simulation/modelica/synchronous/SynchronousFeatures.ControlledMass.mos

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
6565
//
6666
// Variables (3)
6767
// ========================================
68-
// 1: f:VARIABLE(unit = "N" ) "Force" type: Real
69-
// 2: v:STATE(1)(start = 0.0 unit = "m/s" fixed = true ) "Velocity" type: Real
70-
// 3: x:STATE(1)(start = 1.0 unit = "m" fixed = true ) "Position" type: Real
68+
// 1: f:VARIABLE(unit = "N" ) "Force" type: Real
69+
// 2: v:STATE(1)(start = 0.0 unit = "m/s" fixed = true ) "Velocity" type: Real
70+
// 3: x:STATE(1)(start = 1.0 unit = "m" fixed = true ) "Position" type: Real
7171
//
7272
//
7373
// Equations (3, 3)
@@ -85,8 +85,8 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
8585
//
8686
// Variables (2)
8787
// ========================================
88-
// 1: xdFast:DISCRETE() type: Real
89-
// 2: $var2:VARIABLE() type: Real
88+
// 1: xdFast:DISCRETE() type: Real
89+
// 2: $var2:VARIABLE(protected = true ) type: Real
9090
//
9191
//
9292
// Equations (2, 2)
@@ -103,9 +103,9 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
103103
//
104104
// Variables (3)
105105
// ========================================
106-
// 1: uInner:DISCRETE(start = 0.0 ) type: Real
107-
// 2: vref:DISCRETE() type: Real
108-
// 3: vd:DISCRETE() type: Real
106+
// 1: uInner:DISCRETE(start = 0.0 ) type: Real
107+
// 2: vref:DISCRETE() type: Real
108+
// 3: vd:DISCRETE() type: Real
109109
//
110110
//
111111
// Equations (3, 3)
@@ -123,10 +123,10 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
123123
//
124124
// Variables (4)
125125
// ========================================
126-
// 1: uOuter:DISCRETE(start = 0.0 ) type: Real
127-
// 2: intE:DISCRETE(start = 0.0 ) type: Real
128-
// 3: eOuter:DISCRETE() type: Real
129-
// 4: xd:DISCRETE() type: Real
126+
// 1: uOuter:DISCRETE(start = 0.0 ) type: Real
127+
// 2: intE:DISCRETE(start = 0.0 ) type: Real
128+
// 3: eOuter:DISCRETE() type: Real
129+
// 4: xd:DISCRETE() type: Real
130130
//
131131
//
132132
// Equations (4, 4)
@@ -145,7 +145,7 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
145145
//
146146
// Variables (1)
147147
// ========================================
148-
// 1: $var3:VARIABLE() type: Real
148+
// 1: $var3:VARIABLE(protected = true ) type: Real
149149
//
150150
//
151151
// Equations (1, 1)
@@ -182,9 +182,9 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
182182
//
183183
// Variables (3)
184184
// ========================================
185-
// 1: f:VARIABLE(unit = "N" ) "Force" type: Real
186-
// 2: v:STATE(1)(start = 0.0 unit = "m/s" fixed = true ) "Velocity" type: Real
187-
// 3: x:STATE(1,v)(start = 1.0 unit = "m" fixed = true ) "Position" type: Real
185+
// 1: f:VARIABLE(unit = "N" ) "Force" type: Real
186+
// 2: v:STATE(1)(start = 0.0 unit = "m/s" fixed = true ) "Velocity" type: Real
187+
// 3: x:STATE(1,v)(start = 1.0 unit = "m" fixed = true ) "Position" type: Real
188188
//
189189
//
190190
// Equations (3, 3)
@@ -214,8 +214,8 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
214214
//
215215
// Variables (2)
216216
// ========================================
217-
// 1: xdFast:CLOCKED_STATE(fixed = true ) type: Real
218-
// 2: $var2:VARIABLE() type: Real
217+
// 1: xdFast:CLOCKED_STATE(fixed = true ) type: Real
218+
// 2: $var2:VARIABLE(protected = true ) type: Real
219219
//
220220
//
221221
// Equations (2, 2)
@@ -232,9 +232,9 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
232232
//
233233
// Variables (3)
234234
// ========================================
235-
// 1: uInner:DISCRETE(start = 0.0 ) type: Real
236-
// 2: vref:DISCRETE() type: Real
237-
// 3: vd:DISCRETE() type: Real
235+
// 1: uInner:DISCRETE(start = 0.0 ) type: Real
236+
// 2: vref:DISCRETE() type: Real
237+
// 3: vd:DISCRETE() type: Real
238238
//
239239
//
240240
// Equations (3, 3)
@@ -252,10 +252,10 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
252252
//
253253
// Variables (4)
254254
// ========================================
255-
// 1: uOuter:DISCRETE(start = 0.0 ) type: Real
256-
// 2: intE:CLOCKED_STATE(start = 0.0 fixed = true ) type: Real
257-
// 3: eOuter:DISCRETE() type: Real
258-
// 4: xd:DISCRETE() type: Real
255+
// 1: uOuter:DISCRETE(start = 0.0 ) type: Real
256+
// 2: intE:CLOCKED_STATE(start = 0.0 fixed = true ) type: Real
257+
// 3: eOuter:DISCRETE() type: Real
258+
// 4: xd:DISCRETE() type: Real
259259
//
260260
//
261261
// Equations (4, 4)
@@ -274,7 +274,7 @@ translateModel(SynchronousFeatures.ControlledMass); getErrorString();
274274
//
275275
// Variables (1)
276276
// ========================================
277-
// 1: $var3:VARIABLE() type: Real
277+
// 1: $var3:VARIABLE(protected = true ) type: Real
278278
//
279279
//
280280
// Equations (1, 1)

0 commit comments

Comments
 (0)