Skip to content

Commit

Permalink
[NF] fixes to overconstrained connection graph (OCG)
Browse files Browse the repository at this point in the history
- strip subscripts from the overconstrained components when used in the graph or the equalityConstraint function
- lookup "fill" in top
- add flag (no)nfScalarize to be able to disable scalarization in NF

Belonging to [master]:
  - OpenModelica/OMCompiler#2580
  - OpenModelica/OpenModelica-testsuite#1002
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Jul 29, 2018
1 parent b28062c commit a9fc037
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
5 changes: 4 additions & 1 deletion Compiler/NFFrontEnd/NFInst.mo
Expand Up @@ -152,7 +152,10 @@ algorithm
flat_model := Package.collectConstants(flat_model, funcs);

// Scalarize array components in the flat model.
flat_model := Scalarize.scalarize(flat_model, name);
if Flags.isSet(Flags.NF_SCALARIZE) then
flat_model := Scalarize.scalarize(flat_model, name);
end if;

// Convert the flat model to a DAE.
(dae, daeFuncs) := ConvertDAE.convert(flat_model, funcs, name, InstNode.info(inst_cls));

Expand Down
31 changes: 19 additions & 12 deletions Compiler/NFFrontEnd/NFOCConnectionGraph.mo
Expand Up @@ -192,6 +192,10 @@ algorithm
if isOverconstrainedCref(lhs) and isOverconstrainedCref(rhs) then
lhs := getOverconstrainedCref(lhs);
rhs := getOverconstrainedCref(rhs);

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

graph := addConnection(graph, lhs, rhs, eqlBroken);
added := true;
break;
Expand Down Expand Up @@ -270,11 +274,11 @@ function generateEqualityConstraintEquation
input DAE.ElementSource source;
output list<Equation> eqsEqualityConstraint = {};
protected
ComponentRef lhs, rhs, cref, fcref_rhs, fcref_lhs;
ComponentRef lhs, rhs, cref, fcref_rhs, fcref_lhs, lhsArr, rhsArr;
list<Equation> eql = {};
list<Expression> lst;
Type ty, ty1, ty2;
ComponentRef lhs, rhs;
ComponentRef clhs, crhs;
Integer priority;
Expression root, msg;
Connector c1, c2, cc1, cc2;
Expand All @@ -288,12 +292,12 @@ algorithm
return;
end if;

Expression.CREF(ty = ty1, cref = lhs) := elhs;
Expression.CREF(ty = ty2, cref = rhs) := erhs;
if not (ComponentRef.isDeleted(lhs) or ComponentRef.isDeleted(rhs))
Expression.CREF(ty = ty1, cref = clhs) := elhs;
Expression.CREF(ty = ty2, cref = crhs) := erhs;
if not (ComponentRef.isDeleted(clhs) or ComponentRef.isDeleted(crhs))
then
cl1 := NFConnections.makeConnectors(lhs, ty1, source);
cl2 := NFConnections.makeConnectors(rhs, ty2, source);
cl1 := NFConnections.makeConnectors(clhs, ty1, source);
cl2 := NFConnections.makeConnectors(crhs, ty2, source);

for c1 in cl1 loop
c2 :: cl2 := cl2;
Expand All @@ -310,16 +314,19 @@ algorithm
lhs := getOverconstrainedCref(lhs);
rhs := getOverconstrainedCref(rhs);

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

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

fcref_rhs := Function.lookupFunctionSimple("equalityConstraint", ComponentRef.node(lhs));
fcref_rhs := Function.lookupFunctionSimple("equalityConstraint", InstNode.classScope(ComponentRef.node(lhs)));
(fcref_rhs, fn_node_rhs, _) := Function.instFunctionRef(fcref_rhs, ElementSource.getInfo(source));
expRHS := Expression.CALL(Call.UNTYPED_CALL(fcref_rhs, {Expression.CREF(ty1, lhs), Expression.CREF(ty2, rhs)}, {}, fn_node_rhs));
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, origin, ElementSource.getInfo(source), true);

fcref_lhs := Function.lookupFunctionSimple("fill", ComponentRef.node(lhs));
fcref_lhs := Function.lookupFunctionSimple("fill", InstNode.topScope(ComponentRef.node(clhs)));
(fcref_lhs, fn_node_lhs, _) := Function.instFunctionRef(fcref_lhs, 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));

Expand Down
5 changes: 4 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -530,6 +530,8 @@ constant DebugFlag EXEC_STAT_EXTRA_GC = DEBUG_FLAG(177, "execstatGCcollect", fal
Util.gettext("When running execstat, also perform an extra full garbage collection."));
constant DebugFlag DEBUG_DAEMODE = DEBUG_FLAG(178, "debugDAEmode", false,
Util.gettext("Dump debug output for the DAEmode."));
constant DebugFlag NF_SCALARIZE = DEBUG_FLAG(179, "nfScalarize", true,
Util.gettext("Run scalarization in NF, default true."));

// This is a list of all debug flags, to keep track of which flags are used. A
// flag can not be used unless it's in this list, and the list is checked at
Expand Down Expand Up @@ -714,7 +716,8 @@ constant list<DebugFlag> allDebugFlags = {
SUSAN_MATCHCONTINUE_DEBUG,
OLD_FE_UNITCHECK,
EXEC_STAT_EXTRA_GC,
DEBUG_DAEMODE
DEBUG_DAEMODE,
NF_SCALARIZE
};

public
Expand Down

0 comments on commit a9fc037

Please sign in to comment.