@@ -1549,6 +1549,7 @@ algorithm
15491549 list<tuple<Integer,Integer>> equationSccMapping, eqBackendSimCodeMapping;
15501550 Integer highestSimEqIndex;
15511551 SimCode.BackendMapping backendMapping;
1552+ list<BackendDAE.Var> primaryParameters "already sorted";
15521553
15531554 case (dlow, class_, _, fileDir, _,_, _, _, _, _, _, _, _) equation
15541555 System.tmpTickReset(0);
@@ -1560,7 +1561,7 @@ algorithm
15601561 // fcall(Flags.FAILTRACE, print, "is that Cpp? : " + Dump.printBoolStr(ifcpp) + "\n");
15611562
15621563 // generate initDAE before replacing pre(alias)!
1563- (initDAE, useHomotopy, removedInitialEquationLst) = Initialization.solveInitialSystem(dlow);
1564+ (initDAE, useHomotopy, removedInitialEquationLst, primaryParameters ) = Initialization.solveInitialSystem(dlow);
15641565
15651566 if Flags.isSet(Flags.ITERATION_VARS) then
15661567 BackendDAEOptimize.listAllIterationVariables(dlow);
@@ -1606,7 +1607,7 @@ algorithm
16061607 ((uniqueEqIndex, minValueEquations)) = BackendDAEUtil.foldEqSystem(dlow, createMinValueEquations, (uniqueEqIndex, {}));
16071608 ((uniqueEqIndex, maxValueEquations)) = BackendDAEUtil.foldEqSystem(dlow, createMaxValueEquations, (uniqueEqIndex, {}));
16081609 ((uniqueEqIndex, parameterEquations)) = BackendDAEUtil.foldEqSystem(dlow, createVarNominalAssertFromVars, (uniqueEqIndex, {}));
1609- (uniqueEqIndex, parameterEquations) = createParameterEquations(shared, uniqueEqIndex, parameterEquations, useSymbolicInitialization);
1610+ (uniqueEqIndex, parameterEquations) = createParameterEquations(shared, uniqueEqIndex, parameterEquations, useSymbolicInitialization, primaryParameters );
16101611
16111612 ((uniqueEqIndex, algorithmAndEquationAsserts)) = BackendDAEUtil.foldEqSystem(dlow, createAlgorithmAndEquationAsserts, (uniqueEqIndex, {}));
16121613 discreteModelVars = BackendDAEUtil.foldEqSystem(dlow, extractDiscreteModelVars, {});
@@ -6613,13 +6614,31 @@ algorithm
66136614 end matchcontinue;
66146615end createMaxValueEquations;
66156616
6617+ protected function makeSolved_SES_SIMPLE_ASSIGN_fromStartValue
6618+ input BackendDAE.Var inVar;
6619+ input Integer inUniqueEqIndex;
6620+ output SimCode.SimEqSystem outSimEqn;
6621+ output Integer outUniqueEqIndex;
6622+ protected
6623+ DAE.Exp e;
6624+ DAE.ComponentRef cr;
6625+ DAE.ElementSource source;
6626+ algorithm
6627+ cr := BackendVariable.varCref(inVar);
6628+ e := BackendVariable.varBindExpStartValue(inVar);
6629+ source := BackendVariable.getVarSource(inVar);
6630+ outSimEqn := SimCode.SES_SIMPLE_ASSIGN(inUniqueEqIndex, cr, e, source);
6631+ outUniqueEqIndex := inUniqueEqIndex+1;
6632+ end makeSolved_SES_SIMPLE_ASSIGN_fromStartValue;
6633+
66166634protected function createParameterEquations
66176635 input BackendDAE.Shared inShared;
6618- input Integer iuniqueEqIndex ;
6636+ input Integer inUniqueEqIndex ;
66196637 input list<SimCode.SimEqSystem> acc;
6620- input Boolean initialSystemSolved;
6621- output Integer ouniqueEqIndex := iuniqueEqIndex;
6622- output list<SimCode.SimEqSystem> parameterEquations := {};
6638+ input Boolean inSymbolicInitialization;
6639+ input list<BackendDAE.Var> inPrimaryParameters "already sorted";
6640+ output Integer outUniqueEqIndex := inUniqueEqIndex;
6641+ output list<SimCode.SimEqSystem> outParameterEquations := {};
66236642protected
66246643 list<BackendDAE.Equation> parameterEquationsTmp;
66256644 BackendDAE.Variables knvars, extobj, v, kn;
@@ -6645,50 +6664,61 @@ protected
66456664 BackendDAE.EventInfo einfo;
66466665 BackendDAE.BackendDAEType btp;
66476666 BackendDAE.SymbolicJacobians symjacs;
6648- Integer uniqueEqIndex;
66496667 BackendDAE.ExtraInfo ei;
6668+ BackendDAE.Var p;
6669+ SimCode.SimEqSystem simEq;
66506670algorithm
66516671 try
66526672 BackendDAE.SHARED(knownVars=knvars, externalObjects=extobj, initialEqs=ie,
66536673 constraints=constrs, classAttrs=clsAttrs, cache=cache, graph=graph,
66546674 extObjClasses=extObjClasses, functionTree=funcs, info=ei) := inShared;
66556675
6656- // kvars params
6657- ((parameterEquationsTmp, lv, lkn, lv1, lv2, _)) := BackendVariable.traverseBackendDAEVars(knvars, createInitialParamAssignments, ({}, {}, {}, {}, {}, 1));
6658-
6659- // sort the equations
6660- emptyeqns := BackendEquation.emptyEqns();
6661- pe := BackendEquation.listEquation(parameterEquationsTmp);
6662- alisvars := BackendVariable.emptyVars();
6663- v := BackendVariable.listVar(lv);
6664- kn := BackendVariable.listVar(lkn);
6665- funcs := DAEUtil.avlTreeNew();
6666- syst := BackendDAE.EQSYSTEM(v, pe, NONE(), NONE(), BackendDAE.NO_MATCHING(), {}, BackendDAE.UNKNOWN_PARTITION());
6667- shared := BackendDAE.SHARED(kn, extobj, alisvars, emptyeqns, emptyeqns, constrs, clsAttrs, cache, graph, funcs, BackendDAE.EVENT_INFO({}, {}, {}, {}, {}, 0), extObjClasses, BackendDAE.PARAMETERSYSTEM(), {}, ei);
6668- (syst,_,_) := BackendDAEUtil.getIncidenceMatrixfromOption(syst, BackendDAE.NORMAL(), SOME(funcs));
6669- v1 := listArray(lv1);
6670- v2 := listArray(lv2);
6671- syst := BackendDAEUtil.setEqSystemMatching(syst, BackendDAE.MATCHING(v1, v2, {}));
6672- (syst, comps) := BackendDAETransform.strongComponents(syst, shared);
6673- paramdlow := BackendDAE.DAE({syst}, shared);
6674- if Flags.isSet(Flags.PARAM_DLOW_DUMP) then
6675- BackendDump.dumpEqnsSolved(paramdlow, "parameters: eqns in order");
6676- end if;
6677- (parameterEquations, _, uniqueEqIndex, _) := createEquations(false, false, true, false, syst, shared, comps, iuniqueEqIndex, {});
6676+ if inSymbolicInitialization then
6677+ if Flags.isSet(Flags.PARAM_DLOW_DUMP) then
6678+ BackendDump.dumpVarList(inPrimaryParameters, "parameters in order");
6679+ end if;
6680+
6681+ for p in inPrimaryParameters loop
6682+ (simEq, outUniqueEqIndex) := makeSolved_SES_SIMPLE_ASSIGN_fromStartValue(p, outUniqueEqIndex);
6683+ outParameterEquations := simEq::outParameterEquations;
6684+ end for;
6685+ outParameterEquations := listReverse(outParameterEquations);
6686+ else
6687+ // kvars params
6688+ ((parameterEquationsTmp, lv, lkn, lv1, lv2, _)) := BackendVariable.traverseBackendDAEVars(knvars, createInitialParamAssignments, ({}, {}, {}, {}, {}, 1));
6689+
6690+ // sort the equations
6691+ emptyeqns := BackendEquation.emptyEqns();
6692+ pe := BackendEquation.listEquation(parameterEquationsTmp);
6693+ alisvars := BackendVariable.emptyVars();
6694+ v := BackendVariable.listVar(lv);
6695+ kn := BackendVariable.listVar(lkn);
6696+ funcs := DAEUtil.avlTreeNew();
6697+ syst := BackendDAE.EQSYSTEM(v, pe, NONE(), NONE(), BackendDAE.NO_MATCHING(), {}, BackendDAE.UNKNOWN_PARTITION());
6698+ shared := BackendDAE.SHARED(kn, extobj, alisvars, emptyeqns, emptyeqns, constrs, clsAttrs, cache, graph, funcs, BackendDAE.EVENT_INFO({}, {}, {}, {}, {}, 0), extObjClasses, BackendDAE.PARAMETERSYSTEM(), {}, ei);
6699+ (syst,_,_) := BackendDAEUtil.getIncidenceMatrixfromOption(syst, BackendDAE.NORMAL(), SOME(funcs));
6700+ v1 := listArray(lv1);
6701+ v2 := listArray(lv2);
6702+ syst := BackendDAEUtil.setEqSystemMatching(syst, BackendDAE.MATCHING(v1, v2, {}));
6703+ (syst, comps) := BackendDAETransform.strongComponents(syst, shared);
6704+ paramdlow := BackendDAE.DAE({syst}, shared);
6705+ if Flags.isSet(Flags.PARAM_DLOW_DUMP) then
6706+ BackendDump.dumpEqnsSolved(paramdlow, "parameters: eqns in order");
6707+ end if;
6708+ (outParameterEquations, _, outUniqueEqIndex, _) := createEquations(false, false, true, false, syst, shared, comps, outUniqueEqIndex, {});
66786709
6679- if not initialSystemSolved then
6710+ // do not append the inital algorithms to the parameter equation if the system is solved symbolically
66806711 ialgs := BackendEquation.traverseEquationArray(ie, traverseAlgorithmFinder, {});
66816712 ialgs := listReverse(ialgs);
6682- (inalgs, uniqueEqIndex ) := List.mapFold(ialgs, dlowAlgToSimEqSystem, uniqueEqIndex );
6713+ (inalgs, outUniqueEqIndex ) := List.mapFold(ialgs, dlowAlgToSimEqSystem, outUniqueEqIndex );
66836714 end if;
66846715
66856716 // get minmax and nominal asserts
66866717 varasserts := BackendVariable.traverseBackendDAEVars(knvars, createVarAsserts, {});
6687- (simvarasserts, ouniqueEqIndex ) := List.mapFold(varasserts, dlowAlgToSimEqSystem, uniqueEqIndex );
6718+ (simvarasserts, outUniqueEqIndex ) := List.mapFold(varasserts, dlowAlgToSimEqSystem, outUniqueEqIndex );
66886719
6689- // do not append the inital algorithms to the parameter equation if the system is solved symbolically
6690- parameterEquations := listAppend(parameterEquations, listAppend(simvarasserts, inalgs));
6691- parameterEquations := listAppend(parameterEquations, acc);
6720+ outParameterEquations := listAppend(outParameterEquations, listAppend(simvarasserts, inalgs));
6721+ outParameterEquations := listAppend(outParameterEquations, acc);
66926722 else
66936723 Error.addMessage(Error.INTERNAL_ERROR, {"createParameterEquations failed"});
66946724 fail();
@@ -6699,16 +6729,17 @@ protected function traverseAlgorithmFinder "author: Frenkel TUD 2010-12
66996729 collect all used algorithms"
67006730 input BackendDAE.Equation inEq;
67016731 input list<DAE.Algorithm> inAlgs;
6702- output BackendDAE.Equation eqn;
6703- output list<DAE.Algorithm> algs;
6732+ output BackendDAE.Equation outEqn := inEq;
6733+ output list<DAE.Algorithm> outAlgs;
6734+ protected
6735+ DAE.Algorithm alg;
67046736algorithm
6705- (eqn,algs) := matchcontinue (inEq,inAlgs)
6706- local
6707- DAE.Algorithm alg;
6708- case (eqn as BackendDAE.ALGORITHM(alg=alg), algs)
6709- then (eqn, alg::algs);
6710- else (inEq,inAlgs);
6711- end matchcontinue;
6737+ outAlgs := match (inEq)
6738+ case BackendDAE.ALGORITHM(alg=alg)
6739+ then alg::inAlgs;
6740+
6741+ else inAlgs;
6742+ end match;
67126743end traverseAlgorithmFinder;
67136744
67146745protected function createInitialAssignmentsFromStart
0 commit comments