Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into masterMW
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Walther committed Jun 11, 2015
2 parents c885abd + 95d54df commit 82bcd94
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 17 deletions.
41 changes: 36 additions & 5 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) 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 @@ -573,18 +586,26 @@ algorithm
BackendDAE.Var v;
DAE.ComponentRef cr;
DAE.FunctionTree funcs;
BackendDAE.JacobianType jacType;
Boolean linear;


case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind),shared,(BackendDAE.EQUATIONSYSTEM(eqns=eindex,vars=vindx)))
case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind),shared,(BackendDAE.EQUATIONSYSTEM(eqns=eindex,vars=vindx, jacType=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))))
case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,stateSets=stateSets,partitionKind=partitionKind),shared,(BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(residualequations=eindex,tearingvars=vindx),linear=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 All @@ -602,6 +623,16 @@ algorithm

end removeLoopsWork;

protected function isConstOrlinear
input BackendDAE.JacobianType jacType;
output Boolean b;
algorithm
b := match jacType
case BackendDAE.JAC_CONSTANT() then true;
case BackendDAE.JAC_LINEAR() then true;
else false;
end match;
end isConstOrlinear;

protected function res2Con
"
Expand Down
30 changes: 19 additions & 11 deletions Compiler/Util/Flags.mo
Expand Up @@ -430,21 +430,19 @@ 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)."));

// This is a list of all debug flags, to keep track of which flags are used. A
Expand Down Expand Up @@ -584,7 +582,6 @@ constant list<DebugFlag> allDebugFlags = {
NO_PARTITIONING,
ADVANCE_TEARING,
CONSTJAC,
EXTENDS_DYN_OPT,
REDUCE_DYN_OPT,
VISUAL_XML,
ADD_SCALED_VARS,
Expand Down Expand Up @@ -1066,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 @@ -1140,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
2 changes: 1 addition & 1 deletion README.Linux.md
Expand Up @@ -155,4 +155,4 @@ Otherwise the testsuite will fail when generating simulation code.

- On some Linux systems when running simulate(Model, ...) the executable for the Model enters an infinite loop. To fix this, add -ffloat-store to CFLAGS

Last updated 2015-05-21. Much is still outdated.
Last updated 2015-06-10. Much is still outdated.

0 comments on commit 82bcd94

Please sign in to comment.