Skip to content

Commit

Permalink
[NB] remove useless function (#11958)
Browse files Browse the repository at this point in the history
- remove function Equation.fromLHSandRHS because Equation.makeAssignment does the same but better
 - also creates correct sizes
  • Loading branch information
kabdelhak committed Feb 6, 2024
1 parent 2ab36e8 commit ef124e4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 38 deletions.
36 changes: 2 additions & 34 deletions OMCompiler/Compiler/NBackEnd/Classes/NBEquation.mo
Expand Up @@ -1228,31 +1228,6 @@ public
end match;
end setRHS;

function fromLHSandRHS
input Expression lhs;
input Expression rhs;
input Pointer<Integer> idx;
input String context;
input EquationAttributes attr = EquationAttributes.default(EquationKind.UNKNOWN, false);
input DAE.ElementSource src = DAE.emptyElementSource;
output Pointer<Equation> eqn_ptr;
protected
Type ty;
Equation eqn;
Option<Integer> opt_rec_size;
Integer rec_size;
algorithm
ty := Expression.typeOf(lhs);
opt_rec_size := Type.complexSize(ty);
eqn := match (ty, opt_rec_size)
case (Type.ARRAY(), _) then ARRAY_EQUATION(ty, lhs, rhs, src, attr, opt_rec_size);
case (Type.COMPLEX(), SOME(rec_size)) then RECORD_EQUATION(ty, lhs, rhs, src, attr, rec_size);
else SCALAR_EQUATION(ty, lhs, rhs, src, attr);
end match;
eqn_ptr := Pointer.create(eqn);
Equation.createName(eqn_ptr, idx, context);
end fromLHSandRHS;

function updateLHSandRHS
input output Equation eqn;
input Expression lhs;
Expand Down Expand Up @@ -1767,20 +1742,13 @@ public

if Iterator.isEmpty(iter) then
lhs := Expression.fromCref(var.name);
eqn := Equation.fromLHSandRHS(lhs, rhs, idx, context, eqnAttr);
eqn := Equation.makeAssignment(lhs, rhs, idx, context, Iterator.EMPTY(), eqnAttr);
else
rhs := Expression.map(rhs, Expression.repairOperator);
(sub_crefs, _) := Iterator.getFrames(iter);
subs := list(Subscript.fromTypedExp(Expression.fromCref(cref)) for cref in sub_crefs);
lhs := Expression.fromCref(ComponentRef.mergeSubscripts(subs, var.name, true, true));
eqn := Equation.fromLHSandRHS(lhs, rhs, idx, context, eqnAttr);
eqn := Pointer.create(Equation.FOR_EQUATION(
size = ComponentRef.size(var.name),
iter = iter,
body = {Pointer.access(eqn)},
source = DAE.emptyElementSource,
attr = eqnAttr));
Equation.createName(eqn, idx, context);
eqn := Equation.makeAssignment(lhs, rhs, idx, context, iter, eqnAttr);
// this could lead to non existing variables, should not be a problem though
Equation.renameIterators(eqn, "$i");
end if;
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBDetectStates.mo
Expand Up @@ -58,7 +58,7 @@ protected
import BEquation = NBEquation;
import BVariable = NBVariable;
import Differentiate = NBDifferentiate;
import NBEquation.{Equation, EquationPointers, EqData, WhenEquationBody, WhenStatement, IfEquationBody};
import NBEquation.{Equation, EquationPointers, EqData, EquationAttributes, EquationKind, Iterator, WhenEquationBody, WhenStatement, IfEquationBody};
import NBVariable.{VariablePointers, VarData};

// Util
Expand Down Expand Up @@ -265,7 +265,7 @@ protected
if Expression.fold(arg, checkAlgebraic, 0) > 1 then
// more than one algebraic variable > create auxiliary state
(state_var, state_cref, der_var, der_cref) := BVariable.makeAuxStateVar(Pointer.access(uniqueIndex), SOME(arg));
aux_equation := Equation.fromLHSandRHS(Expression.fromCref(state_cref), arg, uniqueIndex, NBVariable.AUXILIARY_STR);
aux_equation := Equation.makeAssignment(Expression.fromCref(state_cref), arg, uniqueIndex, NBVariable.AUXILIARY_STR, Iterator.EMPTY(), EquationAttributes.default(EquationKind.CONTINUOUS, false));
returnExp := Expression.fromCref(der_cref);

Pointer.update(acc_states, state_var :: Pointer.access(acc_states));
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/NBackEnd/Modules/2_Pre/NBEvents.mo
Expand Up @@ -211,7 +211,7 @@ public
for tpl in cev_lst loop
(cond, cev) := tpl;
if not BVariable.isDummyVariable(cev.auxiliary) then
aux_eqn := Equation.fromLHSandRHS(Expression.fromCref(BVariable.getVarName(cev.auxiliary)), cond.exp, idx, context, EquationAttributes.default(EquationKind.DISCRETE, false));
aux_eqn := Equation.makeAssignment(Expression.fromCref(BVariable.getVarName(cev.auxiliary)), cond.exp, idx, context, Iterator.EMPTY(), EquationAttributes.default(EquationKind.DISCRETE, false));
auxiliary_vars := cev.auxiliary :: auxiliary_vars;
auxiliary_eqns := aux_eqn :: auxiliary_eqns;
end if;
Expand Down Expand Up @@ -413,7 +413,7 @@ public
guard(Operator.getMathClassification(exp.operator) == NFOperator.MathClassification.RELATION)
algorithm
// create auxiliary equation and solve for TIME
tmpEqn := Pointer.access(Equation.fromLHSandRHS(exp.exp1, exp.exp2, Pointer.create(0), "TMP"));
tmpEqn := Pointer.access(Equation.makeAssignment(exp.exp1, exp.exp2, Pointer.create(0), "TMP", Iterator.EMPTY(), EquationAttributes.default(EquationKind.UNKNOWN, false)));
_ := Equation.map(tmpEqn, function containsTimeTraverseExp(b = containsTime), SOME(function containsTimeTraverseCref(b = containsTime)));
if Pointer.access(containsTime) then
(tmpEqn, _, status, invert) := Solve.solveBody(tmpEqn, NFBuiltin.TIME_CREF, funcTree);
Expand Down

0 comments on commit ef124e4

Please sign in to comment.