@@ -381,7 +381,7 @@ protected
381381algorithm
382382 name := Expression . reductionIterName(iter);
383383 cr := ComponentReference . makeCrefIdent(name,DAE . T_INTEGER_DEFAULT ,{});
384- backendVar := BackendDAE . VAR (cr, BackendDAE . VARIABLE (), DAE . BIDIR (), DAE . NON_PARALLEL (), DAE . T_INTEGER_DEFAULT , NONE (), {}, DAE . emptyElementSource, NONE (), NONE (), DAE . BCONST (false ), NONE (), DAE . NON_CONNECTOR (), DAE . NOT_INNER_OUTER (), false );
384+ backendVar := BackendDAE . VAR (cr, BackendDAE . VARIABLE (), DAE . BIDIR (), DAE . NON_PARALLEL (), DAE . T_INTEGER_DEFAULT , NONE (), NONE (), {}, DAE . emptyElementSource, NONE (), NONE (), DAE . BCONST (false ), NONE (), DAE . NON_CONNECTOR (), DAE . NOT_INNER_OUTER (), false );
385385end makeIterVariable;
386386
387387protected function checkEquationSize"author: Frenkel TUD 2010-12
@@ -6433,26 +6433,27 @@ algorithm
64336433 Boolean unreplaceable;
64346434 String name;
64356435 Option < BackendDAE . Var > v;
6436+ Option < DAE . Exp > tplExp;
64366437
64376438 case NONE ()
64386439 then (NONE (), inTypeA);
64396440
6440- case SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, SOME (e1), instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
6441+ case SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, SOME (e1), tplExp, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
64416442 (e1_, ext_arg_1) = func (e1, inTypeA);
64426443 (attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func , ext_arg_1);
64436444 if referenceEq(e1,e1_) and referenceEq(attr,attr_) then
64446445 v = inVar;
64456446 else
6446- v = SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, SOME (e1_), instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
6447+ v = SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, SOME (e1_), tplExp, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
64476448 end if ;
64486449 then (v, ext_arg_2);
64496450
6450- case SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, NONE (), instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
6451+ case SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, NONE (), tplExp, instdims, source, attr, ts, hideResult, comment, ct, io, unreplaceable)) equation
64516452 (attr_, ext_arg_2) = traverseBackendDAEVarAttr(attr, func , inTypeA);
64526453 if referenceEq(attr,attr_) then
64536454 v = inVar;
64546455 else
6455- v = SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, NONE (), instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
6456+ v = SOME (BackendDAE . VAR (cref, varKind, varDirection, varParallelism, varType, NONE (), tplExp, instdims, source, attr_, ts, hideResult, comment, ct, io, unreplaceable));
64566457 end if ;
64576458 then (v, ext_arg_2);
64586459
@@ -6862,8 +6863,6 @@ public function getSolvedSystem "Run the equation system pipeline."
68626863 output Boolean outUseHomotopy "true if homotopy(...) is used during initialization" ;
68636864 output Option < BackendDAE . BackendDAE > outInitDAE_lambda0;
68646865 output list< BackendDAE . Equation > outRemovedInitialEquationLst;
6865- output list< BackendDAE . Var > outPrimaryParameters "already sorted" ;
6866- output list< BackendDAE . Var > outAllPrimaryParameters "already sorted" ;
68676866protected
68686867 BackendDAE . BackendDAE dae, simDAE;
68696868 list< tuple< BackendDAEFunc . optimizationModule, String >> preOptModules;
@@ -6920,7 +6919,7 @@ algorithm
69206919 end if ;
69216920
69226921 // generate system for initialization
6923- (outInitDAE, outUseHomotopy, outInitDAE_lambda0, outRemovedInitialEquationLst, outPrimaryParameters, outAllPrimaryParameters, globalKnownVars) := Initialization . solveInitialSystem(dae);
6922+ (outInitDAE, outUseHomotopy, outInitDAE_lambda0, outRemovedInitialEquationLst, globalKnownVars) := Initialization . solveInitialSystem(dae);
69246923
69256924 // use function tree from initDAE further for simDAE
69266925 simDAE := BackendDAEUtil . setFunctionTree(dae, BackendDAEUtil . getFunctions(outInitDAE. shared ));
@@ -6937,6 +6936,9 @@ algorithm
69376936 // post-optimization phase
69386937 outSimDAE := postOptimizeDAE(simDAE, postOptModules, matchingAlgorithm, daeHandler);
69396938
6939+ // sort the globalKnownVars
6940+ outSimDAE := sortGlobalKnownVarsInDAE(outSimDAE);
6941+
69406942 if Flags . isSet(Flags . DUMP_INDX_DAE ) then
69416943 BackendDump . dumpBackendDAE(outSimDAE, "dumpindxdae" );
69426944 if Flags . isSet(Flags . ADDITIONAL_GRAPHVIZ_DUMP ) then
@@ -7304,6 +7306,58 @@ algorithm
73047306 // fcall2(Flags.DUMP_EQNINORDER, BackendDump.dumpEqnsSolved, outDAE, "system for jacobians");
73057307end getSolvedSystemforJacobians;
73067308
7309+ protected function sortGlobalKnownVarsInDAE "
7310+ author: ptaeuber
7311+ This function adds the external objects to globalKnownVars and sorts the globalKnownVars"
7312+ input output BackendDAE . BackendDAE backendDAE;
7313+ protected
7314+ BackendDAE . Variables globalKnownVars, globalKnownVars_sorted;
7315+ BackendDAE . EquationArray parameterEqns;
7316+ BackendDAE . EqSystem paramSystem;
7317+ BackendDAE . IncidenceMatrix m;
7318+ BackendDAE . Var var ;
7319+ array< Integer > ass1, ass2;
7320+ list< list< Integer >> comps;
7321+ list< Integer > flatComps;
7322+ algorithm
7323+ globalKnownVars := backendDAE. shared . globalKnownVars;
7324+ globalKnownVars := BackendVariable . addVariables(backendDAE. shared . externalObjects, globalKnownVars);
7325+ parameterEqns := BackendEquation . emptyEqns();
7326+ parameterEqns := BackendVariable . traverseBackendDAEVars(globalKnownVars, createParameterEquations, parameterEqns);
7327+
7328+ paramSystem := BackendDAEUtil . createEqSystem(globalKnownVars, parameterEqns);
7329+ (m, _) := BackendDAEUtil . incidenceMatrix(paramSystem, BackendDAE . NORMAL (), NONE ());
7330+ (ass1, ass2) := Matching . PerfectMatching (m);
7331+ comps := Sorting . Tarjan (m, ass1);
7332+ flatComps := list(Initialization . flattenParamComp(comp, globalKnownVars) for comp in comps);
7333+
7334+ globalKnownVars_sorted := BackendVariable . emptyVars();
7335+ for i in flatComps loop
7336+ var := BackendVariable . getVarAt(globalKnownVars, i);
7337+ globalKnownVars_sorted := BackendVariable . addVar(var , globalKnownVars_sorted);
7338+ end for ;
7339+
7340+ backendDAE := setDAEGlobalKnownVars(backendDAE, globalKnownVars_sorted);
7341+ end sortGlobalKnownVarsInDAE;
7342+
7343+ protected function createParameterEquations
7344+ input output BackendDAE . Var var ;
7345+ input output BackendDAE . EquationArray parameterEqns;
7346+ protected
7347+ DAE . Exp lhs, rhs;
7348+ BackendDAE . Equation eqn;
7349+ algorithm
7350+ lhs := BackendVariable . varExp(var );
7351+ try
7352+ rhs := BackendVariable . varBindExpStartValue(var );
7353+ else
7354+ rhs := DAE . RCONST (0 . 0 );
7355+ end try ;
7356+ eqn := BackendDAE . EQUATION (lhs, rhs, DAE . emptyElementSource, BackendDAE . EQ_ATTR_DEFAULT_BINDING );
7357+ parameterEqns := BackendEquation . addEquation(eqn, parameterEqns);
7358+ end createParameterEquations;
7359+
7360+
73077361/** ***********************************************
73087362 * index reduction method Selection
73097363 ************************************************/
0 commit comments