Skip to content

Commit 2f52f79

Browse files
author
Jens Frenkel
committed
- add alias a = not b, not a = b, not a = not b, -a = -b
- fix write results for boolean alias, ToDo .mat git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13005 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent be020e1 commit 2f52f79

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

Compiler/BackEnd/BackendEquation.mo

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,6 +1908,11 @@ algorithm
19081908
equation
19091909
ne = Expression.negate(e2);
19101910
then (cr1,cr2,e1,ne,true);
1911+
// -a = -b;
1912+
case (BackendDAE.EQUATION(exp=DAE.UNARY(DAE.UMINUS(_),e1 as DAE.CREF(componentRef = cr1)),scalar=DAE.UNARY(DAE.UMINUS(_),e2 as DAE.CREF(componentRef = cr2))))
1913+
then (cr1,cr2,e1,e2,false);
1914+
case (BackendDAE.EQUATION(exp=DAE.UNARY(DAE.UMINUS_ARR(_),e1 as DAE.CREF(componentRef = cr1)),scalar=DAE.UNARY(DAE.UMINUS_ARR(_),e2 as DAE.CREF(componentRef = cr2))))
1915+
then (cr1,cr2,e1,e2,false);
19111916
// a + b = 0
19121917
case (BackendDAE.EQUATION(exp=DAE.BINARY(e1 as DAE.CREF(componentRef = cr1),DAE.ADD(ty=_),e2 as DAE.CREF(componentRef = cr2)),scalar=e))
19131918
equation
@@ -1996,6 +2001,20 @@ algorithm
19962001
true = Expression.isZero(e);
19972002
ne = Expression.negate(e2);
19982003
then (cr1,cr2,e1,ne,true);
2004+
// a = not b;
2005+
case (BackendDAE.EQUATION(exp=e1 as DAE.CREF(componentRef = cr1),scalar=e2 as DAE.LUNARY(DAE.NOT(_),DAE.CREF(componentRef = cr2))))
2006+
equation
2007+
ne = Expression.negate(e1);
2008+
then (cr1,cr2,ne,e2,true);
2009+
// not a = b;
2010+
case (BackendDAE.EQUATION(exp=e1 as DAE.LUNARY(DAE.NOT(_),DAE.CREF(componentRef = cr1)),scalar=e2 as DAE.CREF(componentRef = cr2)))
2011+
equation
2012+
ne = Expression.negate(e2);
2013+
then (cr1,cr2,e1,ne,true);
2014+
// not a = not b;
2015+
case (BackendDAE.EQUATION(exp=DAE.LUNARY(DAE.NOT(_),e1 as DAE.CREF(componentRef = cr1)),scalar=DAE.LUNARY(DAE.NOT(_),e2 as DAE.CREF(componentRef = cr2))))
2016+
then (cr1,cr2,e1,e2,false);
2017+
19992018
end match;
20002019
end aliasEquation;
20012020

Compiler/BackEnd/SimCodeUtil.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7829,6 +7829,7 @@ algorithm
78297829
case (DAE.CREF(componentRef=name),inVar) then SimCode.ALIAS(name);
78307830
case (DAE.UNARY(operator=DAE.UMINUS(_),exp=DAE.CREF(componentRef=name)),inVar) then SimCode.NEGATEDALIAS(name);
78317831
case (DAE.UNARY(operator=DAE.UMINUS_ARR(_),exp=DAE.CREF(componentRef=name)),inVar) then SimCode.NEGATEDALIAS(name);
7832+
case (DAE.LUNARY(operator=DAE.NOT(_),exp=DAE.CREF(componentRef=name)),inVar) then SimCode.NEGATEDALIAS(name);
78327833
case (DAE.CALL(path=fname, expLst={DAE.CREF(componentRef=name)}),inVar)
78337834
equation
78347835
Builtin.isDer(fname);

Compiler/FrontEnd/Expression.mo

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,9 @@ algorithm
523523
DAE.Exp e;
524524

525525
// to avoid unnessecary --e
526-
case(DAE.UNARY(DAE.UMINUS(t),e)) then e;
527-
case(DAE.UNARY(DAE.UMINUS_ARR(t),e)) then e;
526+
case(DAE.UNARY(DAE.UMINUS(_),e)) then e;
527+
case(DAE.UNARY(DAE.UMINUS_ARR(_),e)) then e;
528+
case(DAE.LUNARY(DAE.NOT(_),e)) then e;
528529

529530
case (DAE.ICONST(i))
530531
equation
@@ -545,6 +546,12 @@ algorithm
545546
true = isZero(e);
546547
then
547548
e;
549+
// not e
550+
case(e)
551+
equation
552+
(t as DAE.T_BOOL(source=_)) = typeof(e);
553+
then
554+
DAE.LUNARY(DAE.NOT(t),e);
548555

549556
case(e)
550557
equation

SimulationRuntime/c/simulation/results/simulation_result_csv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void simulation_result_csv::emit(DATA *data)
8282
}
8383
for (int i = 0; i < data->modelData.nAliasBoolean; i++) if (!data->modelData.booleanAlias[i].filterOutput){
8484
if (data->modelData.booleanAlias[i].negate)
85-
fprintf(fout, formatbool, -(data->localData[0])->booleanVars[data->modelData.booleanAlias[i].nameID]);
85+
fprintf(fout, formatbool, (data->localData[0])->booleanVars[data->modelData.booleanAlias[i].nameID]==1?0:1);
8686
else
8787
fprintf(fout, formatbool, (data->localData[0])->booleanVars[data->modelData.booleanAlias[i].nameID]);
8888
}

SimulationRuntime/c/simulation/results/simulation_result_plt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void simulation_result_plt::emit(DATA *data)
109109
maxPoints = (long)(1.4*maxPoints + (maxPoints-actualPoints) + 2000);
110110
/* cerr << "realloc simulationResultData to a size of " << maxPoints * dataSize * sizeof(double) << endl; */
111111
simulationResultData = (double*)realloc(simulationResultData, maxPoints * dataSize * sizeof(double));
112-
if (!simulationResultData)
112+
if (!simulationResultData)
113113
THROW1("Error allocating simulation result data of size %ld",maxPoints * dataSize);
114114
add_result(simulationResultData,&actualPoints,data);
115115
}
@@ -177,7 +177,7 @@ void simulation_result_plt::add_result(double *data, long *actualPoints, DATA *s
177177
if (!simData->modelData.booleanAlias[i].filterOutput) {
178178
ss << simData->modelData.booleanAlias[i].info.name << "\n";
179179
if (simData->modelData.booleanAlias[i].negate)
180-
ss << (data[currentPos++] = -simData->localData[0]->booleanVars[simData->modelData.booleanAlias[i].nameID]) << "\n";
180+
ss << (data[currentPos++] = simData->localData[0]->booleanVars[simData->modelData.booleanAlias[i].nameID]==1?0:1) << "\n";
181181
else
182182
ss << (data[currentPos++] = simData->localData[0]->booleanVars[simData->modelData.booleanAlias[i].nameID]) << "\n";
183183
}
@@ -229,12 +229,12 @@ void simulation_result_plt::add_result(double *data, long *actualPoints, DATA *s
229229
for (int i = 0; i < simData->modelData.nAliasBoolean; i++) {
230230
if (!simData->modelData.booleanAlias[i].filterOutput) {
231231
if (simData->modelData.booleanAlias[i].negate)
232-
data[currentPos++] = -simData->localData[0]->booleanVars[simData->modelData.booleanAlias[i].nameID];
232+
data[currentPos++] = simData->localData[0]->booleanVars[simData->modelData.booleanAlias[i].nameID]==1?0:1;
233233
else
234234
data[currentPos++] = simData->localData[0]->booleanVars[simData->modelData.booleanAlias[i].nameID];
235235
}
236236
}
237-
}
237+
}
238238

239239
/*cerr << " ... done" << endl; */
240240
(*actualPoints)++;

0 commit comments

Comments
 (0)