Skip to content

Commit

Permalink
Improve handling of deleted components (#7855)
Browse files Browse the repository at this point in the history
  • Loading branch information
perost committed Sep 2, 2021
1 parent c0fb919 commit 9949e99
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 45 deletions.
44 changes: 34 additions & 10 deletions OMCompiler/Compiler/NFFrontEnd/NFConnections.mo
Expand Up @@ -128,16 +128,7 @@ public
algorithm
lhs := ComponentRef.evaluateSubscripts(lhs);
rhs := ComponentRef.evaluateSubscripts(rhs);

if not (isDeleted(lhs) or isDeleted(rhs)) then
cl1 := makeConnectors(lhs, ty1, source);
cl2 := makeConnectors(rhs, ty2, source);

for c1 in cl1 loop
c2 :: cl2 := cl2;
conns := addConnection(Connection.CONNECTION(c1, c2), conns);
end for;
end if;
conns.connections := makeConnections(lhs, ty1, rhs, ty2, source, isDeleted, conns.connections);
then
eql;

Expand All @@ -150,6 +141,39 @@ public
end if;
end collect;

function makeConnections
input ComponentRef lhsCref;
input Type lhsType;
input ComponentRef rhsCref;
input Type rhsType;
input DAE.ElementSource source;
input IsDeleted isDeleted;
input output list<Connection> connections = {};

partial function IsDeleted
input ComponentRef cref;
output Boolean res;
end IsDeleted;
protected
list<Connector> cl1, cl2;
Connector c2;
algorithm
if isDeleted(lhsCref) or isDeleted(rhsCref) then
return;
end if;

cl1 := makeConnectors(lhsCref, lhsType, source);
cl2 := makeConnectors(rhsCref, rhsType, source);

for c1 in cl1 loop
c2 :: cl2 := cl2;

if not (isDeleted(c1.name) or isDeleted(c2.name)) then
connections := Connection.CONNECTION(c1, c2) :: connections;
end if;
end for;
end makeConnections;

function makeConnectors
input ComponentRef cref;
input Type ty;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFFlatten.mo
Expand Up @@ -1590,7 +1590,7 @@ algorithm
end if;
end if;

cr := ComponentRef.rest(cr);
cr := ComponentRef.stripSubscripts(ComponentRef.rest(cr));
end while;

res := false;
Expand Down
61 changes: 27 additions & 34 deletions OMCompiler/Compiler/NFFrontEnd/NFOCConnectionGraph.mo
Expand Up @@ -268,14 +268,11 @@ function generateEqualityConstraintEquation
output Boolean res;
end IsDeleted;
protected
ComponentRef lhs, rhs, cref, fcref_rhs, fcref_lhs, lhsArr, rhsArr;
list<Equation> eql = {};
list<Expression> lst;
ComponentRef lhs, rhs, fcref_rhs, fcref_lhs, lhsArr, rhsArr;
Type ty, ty1, ty2;
Integer priority;
list<Connection> conns;
Expression root, msg;
Connector c1, c2;
list<Connector> cl1, cl2;
Equation replaceEq;
Expression expLHS, expRHS;
InstNode fn_node_lhs, fn_node_rhs;
Expand All @@ -285,47 +282,43 @@ algorithm
return;
end if;

if not (isDeleted(clhs) or isDeleted(crhs)) then
cl1 := NFConnections.makeConnectors(clhs, lhs_ty, source);
cl2 := NFConnections.makeConnectors(crhs, rhs_ty, source);
conns := NFConnections.makeConnections(clhs, lhs_ty, crhs, rhs_ty, source, isDeleted);

for c1 in cl1 loop
c2 :: cl2 := cl2;
for c in conns loop
for conn in Connection.split(c) loop
lhs := Connector.name(conn.lhs);
rhs := Connector.name(conn.rhs);

for conn in Connection.split(Connection.CONNECTION(c1, c2)) loop
lhs := Connector.name(conn.lhs);
rhs := Connector.name(conn.rhs);
if isOverconstrainedCref(lhs) and isOverconstrainedCref(rhs) then
lhs := getOverconstrainedCref(lhs);
rhs := getOverconstrainedCref(rhs);
if isOverconstrainedCref(lhs) and isOverconstrainedCref(rhs) then
lhs := getOverconstrainedCref(lhs);
rhs := getOverconstrainedCref(rhs);

lhsArr := ComponentRef.stripSubscripts(lhs);
rhsArr := ComponentRef.stripSubscripts(rhs);
lhsArr := ComponentRef.stripSubscripts(lhs);
rhsArr := ComponentRef.stripSubscripts(rhs);

ty1 := ComponentRef.getComponentType(lhsArr);
ty2 := ComponentRef.getComponentType(rhsArr);
ty1 := ComponentRef.getComponentType(lhsArr);
ty2 := ComponentRef.getComponentType(rhsArr);

fcref_rhs := Function.lookupFunctionSimple("equalityConstraint", InstNode.classScope(ComponentRef.node(lhs)), context);
(fcref_rhs, fn_node_rhs, _) := Function.instFunctionRef(fcref_rhs, context, ElementSource.getInfo(source));
expRHS := Expression.CALL(Call.UNTYPED_CALL(fcref_rhs, {Expression.CREF(ty1, lhsArr), Expression.CREF(ty2, rhsArr)}, {}, fn_node_rhs));
fcref_rhs := Function.lookupFunctionSimple("equalityConstraint", InstNode.classScope(ComponentRef.node(lhs)), context);
(fcref_rhs, fn_node_rhs, _) := Function.instFunctionRef(fcref_rhs, context, ElementSource.getInfo(source));
expRHS := Expression.CALL(Call.UNTYPED_CALL(fcref_rhs, {Expression.CREF(ty1, lhsArr), Expression.CREF(ty2, rhsArr)}, {}, fn_node_rhs));

(expRHS, ty, var) := Typing.typeExp(expRHS, context, ElementSource.getInfo(source));
(expRHS, ty, var) := Typing.typeExp(expRHS, context, ElementSource.getInfo(source));

fcref_lhs := Function.lookupFunctionSimple("fill", InstNode.topScope(ComponentRef.node(clhs)), context);
(fcref_lhs, fn_node_lhs, _) := Function.instFunctionRef(fcref_lhs, context, ElementSource.getInfo(source));
expLHS := Expression.CALL(Call.UNTYPED_CALL(fcref_lhs, Expression.REAL(0.0)::List.map(Type.arrayDims(ty), Dimension.sizeExp), {}, fn_node_lhs));
fcref_lhs := Function.lookupFunctionSimple("fill", InstNode.topScope(ComponentRef.node(clhs)), context);
(fcref_lhs, fn_node_lhs, _) := Function.instFunctionRef(fcref_lhs, context, ElementSource.getInfo(source));
expLHS := Expression.CALL(Call.UNTYPED_CALL(fcref_lhs, Expression.REAL(0.0)::List.map(Type.arrayDims(ty), Dimension.sizeExp), {}, fn_node_lhs));

(expLHS, ty, var) := Typing.typeExp(expLHS, context, ElementSource.getInfo(source));
(expLHS, ty, var) := Typing.typeExp(expLHS, context, ElementSource.getInfo(source));

replaceEq := Equation.EQUALITY(expRHS, expLHS, ty, source);
replaceEq := Equation.EQUALITY(expRHS, expLHS, ty, source);

eqsEqualityConstraint := {replaceEq};
eqsEqualityConstraint := {replaceEq};

return;
end if;
end for;
return;
end if;
end for;
end if;
end for;
end generateEqualityConstraintEquation;

protected
Expand Down

0 comments on commit 9949e99

Please sign in to comment.