Skip to content

Commit

Permalink
change flag +d=extendsDynOpt in loop2con=all
Browse files Browse the repository at this point in the history
added option for loop2con: none, all, lin, noLin
  • Loading branch information
vruge authored and OpenModelica-Hudson committed Jun 10, 2015
1 parent 4344719 commit 95d54df
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
28 changes: 22 additions & 6 deletions Compiler/BackEnd/DynamicOptimization.mo
Expand Up @@ -501,7 +501,7 @@ public function removeLoops
input BackendDAE.BackendDAE inDAE;
output BackendDAE.BackendDAE outDAE;
algorithm
if Flags.isSet(Flags.EXTENDS_DYN_OPT) or Flags.isSet(Flags.LOOP2CON) then
if not Flags.getConfigString(Flags.LOOP2CON) == "none" then
//BackendDump.bltdump("***", inDAE);
(outDAE, _) := BackendDAEUtil.mapEqSystemAndFold(inDAE, findLoops, false);
//BackendDump.bltdump("###", outDAE);
Expand Down Expand Up @@ -540,10 +540,21 @@ protected
BackendDAE.StateSets stateSets;
BackendDAE.BaseClockPartitionKind partitionKind;
BackendDAE.EquationArray eqns;

Boolean l2p_all = Flags.getConfigString(Flags.LOOP2CON) == "all";
Boolean l2p_nl;
Boolean l2p_l;
algorithm

if l2p_all then
l2p_nl := true;
l2p_l := true;
else
l2p_nl := Flags.getConfigString(Flags.LOOP2CON) == "noLin";
l2p_l := not l2p_nl;
end if;

for comp in inComps loop
(osyst,oshared) := removeLoopsWork(osyst,oshared,comp);
(osyst,oshared) := removeLoopsWork(osyst,oshared,comp, l2p_all, l2p_l);
end for;

end findLoops1;
Expand All @@ -556,6 +567,8 @@ protected function removeLoopsWork
input BackendDAE.EqSystem isyst;
input BackendDAE.Shared ishared;
input BackendDAE.StrongComponent icomp;
input Boolean l2p_all;
input Boolean l2p_l;
output BackendDAE.EqSystem osyst;
output BackendDAE.Shared oshared;
algorithm
Expand All @@ -574,22 +587,25 @@ algorithm
DAE.ComponentRef cr;
DAE.FunctionTree funcs;
BackendDAE.JacobianType jacType;
Boolean linear, force_break = not Flags.isSet(Flags.LOOP2CON);
Boolean linear;


case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind),shared,(BackendDAE.EQUATIONSYSTEM(eqns=eindex,vars=vindx, jacType=jacType)))
guard force_break or not isConstOrlinear(jacType)
guard l2p_all or (if l2p_l then isConstOrlinear(jacType) else not isConstOrlinear(jacType))
equation
if l2p_l then
end if;
(eqns,vars,shared) = res2Con(eqns, vars, eindex, vindx,shared);
then (BackendDAE.EQSYSTEM(vars, eqns, NONE(), NONE(), BackendDAE.NO_MATCHING(), stateSets, partitionKind), shared);

case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind),shared,(BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=eindex,tearingvars=vindx),linear=linear)))
guard force_break or not linear
guard l2p_all or (if l2p_l then linear else not linear)
equation
(eqns,vars,shared) = res2Con(eqns, vars, eindex, vindx,shared);
then (BackendDAE.EQSYSTEM(vars, eqns, NONE(), NONE(), BackendDAE.NO_MATCHING(), stateSets, partitionKind), shared);

case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind),shared,BackendDAE.SINGLEEQUATION(eqn=eindex_,var=vindx_))
guard l2p_all or not l2p_l
equation
BackendDAE.EQUATION(exp=e1, scalar=e2) = BackendEquation.equationNth1(eqns, eindex_);
(v as BackendDAE.VAR(varName = cr)) = BackendVariable.getVarAt(vars, vindx_);
Expand Down
35 changes: 20 additions & 15 deletions Compiler/Util/Flags.mo
Expand Up @@ -430,24 +430,20 @@ constant DebugFlag ADVANCE_TEARING = DEBUG_FLAG(130, "advanceTearing", false,
Util.gettext("Using ExpressionSolve in adjacencyRowEnhanced"));
constant DebugFlag CONSTJAC = DEBUG_FLAG(131, "constjac", false,
Util.gettext("solves linear systems with const jacobian and variable b-Vector symbolically"));
constant DebugFlag EXTENDS_DYN_OPT = DEBUG_FLAG(132, "extendsDynOpt", false,
Util.gettext("generat extends NLP, move loops in the optimization problem as constraints. hint: using intial guess from file!"));
constant DebugFlag REDUCE_DYN_OPT = DEBUG_FLAG(133, "reduceDynOpt", false,
constant DebugFlag REDUCE_DYN_OPT = DEBUG_FLAG(132, "reduceDynOpt", false,
Util.gettext("remove eqs which not need for the calculations of cost and constraints"));
constant DebugFlag VISUAL_XML = DEBUG_FLAG(134, "visxml", false,
constant DebugFlag VISUAL_XML = DEBUG_FLAG(133, "visxml", false,
Util.gettext("Outputs a xml-file that contains information for visualization."));
constant DebugFlag ADD_SCALED_VARS = DEBUG_FLAG(135, "addScaledVars", false,
constant DebugFlag ADD_SCALED_VARS = DEBUG_FLAG(134, "addScaledVars", false,
Util.gettext("Adds an alias equation var_nrom = var/nominal where var is state"));
constant DebugFlag ADD_SCALED_VARS_INPUT = DEBUG_FLAG(136, "addScaledVarsInput", false,
constant DebugFlag ADD_SCALED_VARS_INPUT = DEBUG_FLAG(135, "addScaledVarsInput", false,
Util.gettext("Adds an alias equation var_nrom = var/nominal where var is input"));
constant DebugFlag VECTORIZE = DEBUG_FLAG(137, "vectorize", false,
constant DebugFlag VECTORIZE = DEBUG_FLAG(136, "vectorize", false,
Util.gettext("Activates vectorization in the backend."));
constant DebugFlag CHECK_EXT_LIBS = DEBUG_FLAG(138, "buildExternalLibs", true,
constant DebugFlag CHECK_EXT_LIBS = DEBUG_FLAG(137, "buildExternalLibs", true,
Util.gettext("Use the autotools project in the Resources folder of the library to build missing external libraries."));
constant DebugFlag RUNTIME_STATIC_LINKING = DEBUG_FLAG(139, "runtimeStaticLinking", false,
constant DebugFlag RUNTIME_STATIC_LINKING = DEBUG_FLAG(138, "runtimeStaticLinking", false,
Util.gettext("Use the static simulation runtime libraries (C++ simulation runtime)."));
constant DebugFlag LOOP2CON = DEBUG_FLAG(140, "loop2con", false,
Util.gettext("transform nonlinear loop in nonlinear constraint. hint: using intial guess from file!"));

// 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 @@ -586,15 +582,13 @@ constant list<DebugFlag> allDebugFlags = {
NO_PARTITIONING,
ADVANCE_TEARING,
CONSTJAC,
EXTENDS_DYN_OPT,
REDUCE_DYN_OPT,
VISUAL_XML,
ADD_SCALED_VARS,
ADD_SCALED_VARS_INPUT,
VECTORIZE,
CHECK_EXT_LIBS,
RUNTIME_STATIC_LINKING,
LOOP2CON
RUNTIME_STATIC_LINKING
};

public
Expand Down Expand Up @@ -1069,6 +1063,16 @@ constant ConfigFlag ADD_TIME_AS_STATE = CONFIG_FLAG(70,
"addTimeAsState", NONE(), INTERNAL(), BOOL_FLAG(false), NONE(),
Util.gettext("Experimental feature: this repaces each occurrence of variable time with a new introduced state $time with equation der($time) = 1.0"));

constant ConfigFlag LOOP2CON = CONFIG_FLAG(71, "loop2con",
NONE(), EXTERNAL(), STRING_FLAG("none"),
SOME(STRING_DESC_OPTION({
("none", Util.gettext("Disables module")),
("lin", Util.gettext("linear loops --> constraints.")),
("noLin", Util.gettext("no linear loops --> constraints.")),
("all", Util.gettext("loops --> constraints."))})),
Util.gettext("Specifies method that transform loops in constraints. hint: using intial guess from file!"));


protected
// This is a list of all configuration flags. A flag can not be used unless it's
// in this list, and the list is checked at initialization so that all flags are
Expand Down Expand Up @@ -1143,7 +1147,8 @@ constant list<ConfigFlag> allConfigFlags = {
REMOVE_SIMPLE_EQUATIONS,
DYNAMIC_TEARING,
SYM_EULER,
ADD_TIME_AS_STATE
ADD_TIME_AS_STATE,
LOOP2CON
};

public function new
Expand Down

0 comments on commit 95d54df

Please sign in to comment.