diff --git a/OMCompiler/Compiler/SimCode/ReduceDAE.mo b/OMCompiler/Compiler/SimCode/ReduceDAE.mo index 5c16d6991e6..33dc39a5925 100644 --- a/OMCompiler/Compiler/SimCode/ReduceDAE.mo +++ b/OMCompiler/Compiler/SimCode/ReduceDAE.mo @@ -328,22 +328,23 @@ protected function addLabelToEquations list s,t,inputs,outputs,expl,b; DAE.ComponentRef cr_1,cr; DAE.ElementSource source "origin of the equation"; - list sourcelist; + list sourcelist; SimCodeVar.SimVars vars,vars_1,vars_2,vars_3; list labels,labels2,labels3,labels4,labels5; tuple idx,idx2,idx3,idx4; Integer i,indexSys,idxLS,idxNLS,nUnknownsLS,nUnknownsNLS; list conditions; - Boolean partOfLinear,tornSystem,initialCall; - list whenStmtLst; + Boolean partOfLinear,tornSystem,initialCall; + list whenStmtLst; list> A,A2; list crefs,crefs_1; list varsLin,discVars; list statements,statements2; - list residual; - Option jacobianMatrix; + list residual; + Option jacobianMatrix; BackendDAE.EquationAttributes eqAttr; Boolean partOfJac; + Option clockIndex; // nothing case ({},vars,idx,_,_) then ({},vars,idx,{}); @@ -415,7 +416,7 @@ protected function addLabelToEquations (SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(i,partOfLinear,tornSystem,varsLin,b,A2,residual,jacobianMatrix,sourcelist,idxLS,nUnknownsLS, partOfJac),NONE(), eqAttr) :: es_1,vars_2,idx3,labels3); // non-linear systems - case (((eq as SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=i,eqs=nl,crefs=crefs,indexNonLinearSystem=idxNLS,nUnknowns=nUnknownsNLS,jacobianMatrix=jacobianMatrix),NONE(), eqAttr)) :: es),vars,idx,_,_) + case (((eq as SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=i,eqs=nl,crefs=crefs,indexNonLinearSystem=idxNLS,nUnknowns=nUnknownsNLS,jacobianMatrix=jacobianMatrix,clockIndex=clockIndex),NONE(), eqAttr)) :: es),vars,idx,_,_) equation if(Flags.isSet(Flags.REDUCE_DAE)) then @@ -427,7 +428,7 @@ protected function addLabelToEquations (es_1 ,vars_2,idx3,labels2)= addLabelToEquations(es,vars_1,idx2,reduceList,inVarRepl); labels3=listAppend(labels,labels2); then - (SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=i,eqs=nl_1,crefs=crefs,indexNonLinearSystem=idxNLS,nUnknowns=nUnknownsNLS,jacobianMatrix=jacobianMatrix,homotopySupport=false,mixedSystem=false,tornSystem=false),NONE(), eqAttr) :: es_1,vars_2,idx3,labels3); + (SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(index=i,eqs=nl_1,crefs=crefs,indexNonLinearSystem=idxNLS,nUnknowns=nUnknownsNLS,jacobianMatrix=jacobianMatrix,homotopySupport=false,mixedSystem=false,tornSystem=false,clockIndex=clockIndex),NONE(), eqAttr) :: es_1,vars_2,idx3,labels3); // mixed systems case (((eq as SimCode.SES_MIXED(i,cont,discVars,disc,indexSys, eqAttr)) :: es),vars,idx,_,_) equation diff --git a/OMCompiler/Compiler/SimCode/SimCode.mo b/OMCompiler/Compiler/SimCode/SimCode.mo index de0c069fd32..0bfd0612e1a 100644 --- a/OMCompiler/Compiler/SimCode/SimCode.mo +++ b/OMCompiler/Compiler/SimCode/SimCode.mo @@ -506,6 +506,7 @@ uniontype NonlinearSystem Boolean homotopySupport; Boolean mixedSystem; Boolean tornSystem; + Option clockIndex; end NONLINEARSYSTEM; end NonlinearSystem; diff --git a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo index 06c8e021383..a710a4b4e82 100644 --- a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo +++ b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo @@ -663,7 +663,7 @@ algorithm end if; // Set fullPathPrefix for FMUs - if isFMU then + if isFMU then if (Config.simCodeTarget()=="omsic") or (Config.simCodeTarget() == "omsicpp")then fullPathPrefix := filenamePrefix+".fmutmp"; else @@ -1581,7 +1581,7 @@ protected algorithm arg := (stateeqnsmark, zceqnsmark, syst, shared, createAlgebraicEquations); foldArg := (iuniqueEqIndex, {}, {}, {}, {}, itempvars, ieqSccMapping, ieqBackendSimCodeMapping, iBackendMapping, iSccIndex); - foldArg := List.fold1(comps, createEquationsForSystem1, arg, foldArg); + foldArg := List.fold2(comps, createEquationsForSystem1, arg, partitionKindToClockIndex(syst.partitionKind), foldArg); (ouniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, otempvars, oeqSccMapping, oeqBackendSimCodeMapping, oBackendMapping, _) := foldArg; outOdeEquations := List.flattenReverse(odeEquations); @@ -1618,6 +1618,7 @@ end addEquationsToLists; protected function createEquationsForSystem1 input BackendDAE.StrongComponent comp; input CreateEquationsForSystemArg inArg; + input Option clockIndex; input CreateEquationsForSystemFold inFold; output CreateEquationsForSystemFold outFold; protected @@ -1712,7 +1713,7 @@ algorithm equation (eqnlst, varlst, _) = BackendDAETransform.getEquationAndSolvedVar(comp, syst.orderedEqs, syst.orderedVars); varlst = List.map(varlst, BackendVariable.transformXToXd); - (equations1, uniqueEqIndex1) = createSingleAlgorithmCode(eqnlst, varlst, false, uniqueEqIndex); + (equations1, uniqueEqIndex1) = createSingleAlgorithmCode(eqnlst, varlst, false, uniqueEqIndex, clockIndex); eqSccMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, sccIndex, eqSccMapping); eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping); @@ -1730,7 +1731,7 @@ algorithm (eqnlst, varlst,_) = BackendDAETransform.getEquationAndSolvedVar(comp, syst.orderedEqs, syst.orderedVars); // States are solved for der(x) not x. varlst = List.map(varlst, BackendVariable.transformXToXd); - (equations1, uniqueEqIndex1, tempvars) = createSingleComplexEqnCode(listHead(eqnlst), varlst, uniqueEqIndex, tempvars, shared.info, true, shared.functionTree); + (equations1, uniqueEqIndex1, tempvars) = createSingleComplexEqnCode(listHead(eqnlst), varlst, uniqueEqIndex, tempvars, shared.info, true, shared.functionTree, clockIndex); eqSccMapping = appendSccIdx(uniqueEqIndex1-1, sccIndex, eqSccMapping); eqBackendSimCodeMapping = appendSccIdxRange(uniqueEqIndex, uniqueEqIndex1 - 1, e, eqBackendSimCodeMapping); @@ -1945,7 +1946,7 @@ algorithm equation (eqnlst, varlst, _) = BackendDAETransform.getEquationAndSolvedVar(comp, eqns, vars); varlst = List.map(varlst, BackendVariable.transformXToXd); - (equations1, uniqueEqIndex) = createSingleAlgorithmCode(eqnlst, varlst, skipDiscInAlgorithm, iuniqueEqIndex); + (equations1, uniqueEqIndex) = createSingleAlgorithmCode(eqnlst, varlst, skipDiscInAlgorithm, iuniqueEqIndex, partitionKindToClockIndex(syst.partitionKind)); then (equations1, equations1, uniqueEqIndex, itempvars); // A single complex equation @@ -1954,7 +1955,7 @@ algorithm (eqnlst, varlst,_) = BackendDAETransform.getEquationAndSolvedVar(comp, eqns, vars); // States are solved for der(x) not x. varlst = List.map(varlst, BackendVariable.transformXToXd); - (equations1, uniqueEqIndex, tempvars) = createSingleComplexEqnCode(listHead(eqnlst), varlst, iuniqueEqIndex, itempvars, ei, genDiscrete, shared.functionTree); + (equations1, uniqueEqIndex, tempvars) = createSingleComplexEqnCode(listHead(eqnlst), varlst, iuniqueEqIndex, itempvars, ei, genDiscrete, shared.functionTree, partitionKindToClockIndex(syst.partitionKind)); then (equations1, equations1, uniqueEqIndex, tempvars); // A single when equation @@ -2150,6 +2151,18 @@ algorithm end match; end addAssertEqn; +protected function partitionKindToClockIndex + input BackendDAE.BaseClockPartitionKind kind; + output Option clockIndex; +algorithm + clockIndex := match kind + local + Integer index; + case BackendDAE.CLOCKED_PARTITION(subPartIdx=index) then SOME(index); + else NONE(); + end match; +end partitionKindToClockIndex; + protected function createEquation input Integer eqNum; input Integer varNum; @@ -2167,8 +2180,9 @@ protected BackendDAE.EquationArray eqns; BackendDAE.Equation eqn; BackendDAE.Var v; + BackendDAE.BaseClockPartitionKind partitionKind; algorithm - BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns) := syst; + BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns, partitionKind=partitionKind) := syst; eqn := BackendEquation.get(eqns, eqNum); _ := match eqn case BackendDAE.WHEN_EQUATION() then (); @@ -2301,7 +2315,7 @@ algorithm (resEqs, uniqueEqIndex, tempvars) := createNonlinearResidualEquations({eqn}, iuniqueEqIndex, itempvars, shared.functionTree); cr := if BackendVariable.isStateVar(v) then ComponentReference.crefPrefixDer(cr) else cr; (_, homotopySupport) := BackendEquation.traverseExpsOfEquation(eqn, BackendDAEUtil.containsHomotopyCall, false); - eqSystlst := {SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, {cr}, 0, 1, NONE(), homotopySupport, false, false), NONE(), eqAttr)}; + eqSystlst := {SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, {cr}, 0, 1, NONE(), homotopySupport, false, false, partitionKindToClockIndex(partitionKind)), NONE(), eqAttr)}; uniqueEqIndex := uniqueEqIndex + 1; else b := false; @@ -2314,7 +2328,7 @@ algorithm (resEqs, uniqueEqIndex, tempvars) := createNonlinearResidualEquations({eqn}, iuniqueEqIndex, itempvars, shared.functionTree); cr := if BackendVariable.isStateVar(v) then ComponentReference.crefPrefixDer(cr) else cr; (_, homotopySupport) := BackendEquation.traverseExpsOfEquation(eqn, BackendDAEUtil.containsHomotopyCall, false); - eqSystlst := {SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, {cr}, 0, 1, NONE(), homotopySupport, false, false), NONE(), eqAttr)}; + eqSystlst := {SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, {cr}, 0, 1, NONE(), homotopySupport, false, false, partitionKindToClockIndex(partitionKind)), NONE(), eqAttr)}; uniqueEqIndex := uniqueEqIndex+1; end if; end if; @@ -3286,7 +3300,7 @@ algorithm vars_1 = BackendVariable.listVar1(var_lst_1); eqns_1 = BackendEquation.listEquation(eqn_lst); partOfJac = BackendDAEUtil.isJacobianDAE(ishared); - (equations_, uniqueEqIndex, tempvars) = createOdeSystem2(false, vars_1, globalKnownVars, eqns_1, jacobian, jac_tp, funcs, vars, iuniqueEqIndex, ei, mixedSystem, partOfJac, itempvars); + (equations_, uniqueEqIndex, tempvars) = createOdeSystem2(false, vars_1, globalKnownVars, eqns_1, jacobian, jac_tp, funcs, vars, iuniqueEqIndex, ei, mixedSystem, partOfJac, itempvars, partitionKindToClockIndex(isyst.partitionKind)); uniqueEqIndexMapping = uniqueEqIndex-1; //a system with this index is created that contains all the equations with the indeces from iuniqueEqIndex to uniqueEqIndex-2 //tmpEqSccMapping = appendSccIdxRange(iuniqueEqIndex, uniqueEqIndex - 1, isccIndex, ieqSccMapping); tmpEqSccMapping = appendSccIdxRange(uniqueEqIndexMapping, uniqueEqIndex - 1, isccIndex, ieqSccMapping); @@ -3327,6 +3341,7 @@ protected function createOdeSystem2 input Boolean mixedSystem; input Boolean partOfJac; input list itempvars; + input Option clockIndex; output list equations_; output Integer ouniqueEqIndex; output list otempvars; @@ -3400,7 +3415,7 @@ algorithm // create symbolic jacobian for simulation (jacobianMatrix, uniqueEqIndex, tempvars) = createSymbolicSimulationJacobian(inJacobian, uniqueEqIndex, tempvars); (_, homotopySupport) = BackendEquation.traverseExpsOfEquationList(eqn_lst, BackendDAEUtil.containsHomotopyCall, false); - then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, inVars.numberOfVars+listLength(tempvars)-listLength(itempvars), jacobianMatrix, homotopySupport, mixedSystem, false), NONE(), BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN)}, uniqueEqIndex+1, tempvars); + then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, inVars.numberOfVars+listLength(tempvars)-listLength(itempvars), jacobianMatrix, homotopySupport, mixedSystem, false, clockIndex), NONE(), BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN)}, uniqueEqIndex+1, tempvars); // No analytic jacobian available. Generate non-linear system. case (_, _) equation @@ -3411,7 +3426,7 @@ algorithm crefs = BackendVariable.getAllCrefFromVariables(inVars); (resEqs, uniqueEqIndex, tempvars) = createNonlinearResidualEquations(eqn_lst, iuniqueEqIndex, itempvars, inFuncs); (_, homotopySupport) = BackendEquation.traverseExpsOfEquationList(eqn_lst, BackendDAEUtil.containsHomotopyCall, false); - then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, inVars.numberOfVars+listLength(tempvars)-listLength(itempvars), NONE(), homotopySupport, mixedSystem, false), NONE(), BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN)}, uniqueEqIndex+1, tempvars); + then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, inVars.numberOfVars+listLength(tempvars)-listLength(itempvars), NONE(), homotopySupport, mixedSystem, false, clockIndex), NONE(), BackendDAE.EQ_ATTR_DEFAULT_UNKNOWN)}, uniqueEqIndex+1, tempvars); // failure else equation @@ -3506,6 +3521,7 @@ algorithm Option alternativeTearingNl; BackendDAE.BackendDAEType backendDAEType; Boolean partOfJac; + Option clockIndex; // CASE: linear case(true, BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns), BackendDAE.SHARED(globalKnownVars=globalKnownVars)) equation @@ -3582,7 +3598,9 @@ algorithm (_, homotopySupport) = BackendEquation.traverseExpsOfEquationList(reqns, BackendDAEUtil.containsHomotopyCall, false); end if; - nlSystem = SimCode.NONLINEARSYSTEM(uniqueEqIndex, simequations, tcrs, 0, listLength(tvars)+nInnerVars+listLength(tempvars)-listLength(itempvars), jacobianMatrix, homotopySupport, mixedSystem, true); + clockIndex = partitionKindToClockIndex(isyst.partitionKind); + + nlSystem = SimCode.NONLINEARSYSTEM(uniqueEqIndex, simequations, tcrs, 0, listLength(tvars)+nInnerVars+listLength(tempvars)-listLength(itempvars), jacobianMatrix, homotopySupport, mixedSystem, true, clockIndex); tempvars2 = tempvars; // Do if dynamic tearing is activated @@ -3607,7 +3625,7 @@ algorithm (_, homotopySupport) = BackendEquation.traverseExpsOfEquationList(reqns, BackendDAEUtil.containsHomotopyCall, false); end if; - alternativeTearingNl = SOME(SimCode.NONLINEARSYSTEM(uniqueEqIndex, simequations, tcrs, 0, listLength(tvars)+nInnerVars+listLength(tempvars2)-listLength(tempvars), jacobianMatrix, homotopySupport, mixedSystem, true)); + alternativeTearingNl = SOME(SimCode.NONLINEARSYSTEM(uniqueEqIndex, simequations, tcrs, 0, listLength(tvars)+nInnerVars+listLength(tempvars2)-listLength(tempvars), jacobianMatrix, homotopySupport, mixedSystem, true, clockIndex)); else alternativeTearingNl = NONE(); end if; @@ -3895,7 +3913,9 @@ protected Integer nAlgebraicSystems = 0; Integer index, nAllVars = 0; Boolean debug=false; + Option clockIndex; algorithm + clockIndex := partitionKindToClockIndex(constSyst.partitionKind); for component in components loop tmpEqns := {}; tmpInputVars := {}; tmpOutputVars := {}; tmpInnerVars := {}; @@ -3940,14 +3960,14 @@ algorithm (eqnlst, varlst,_) = BackendDAETransform.getEquationAndSolvedVar(component, constSyst.orderedEqs, constSyst.orderedVars); // States are solved for der(x) not x. varlst = List.map(varlst, BackendVariable.transformXToXd); - (tmpEqns, uniqueEqIndex, _) = createSingleComplexEqnCode(listHead(eqnlst), varlst, uniqueEqIndex, {}, shared.info, true, shared.functionTree); + (tmpEqns, uniqueEqIndex, _) = createSingleComplexEqnCode(listHead(eqnlst), varlst, uniqueEqIndex, {}, shared.info, true, shared.functionTree, clockIndex); then(); // case for single algorithm equation case BackendDAE.SINGLEALGORITHM() equation (eqnlst, varlst,_) = BackendDAETransform.getEquationAndSolvedVar(component, constSyst.orderedEqs, constSyst.orderedVars); varlst = List.map(varlst, BackendVariable.transformXToXd); - (tmpEqns, uniqueEqIndex) = createSingleAlgorithmCode(eqnlst, varlst, false, uniqueEqIndex); + (tmpEqns, uniqueEqIndex) = createSingleAlgorithmCode(eqnlst, varlst, false, uniqueEqIndex, clockIndex); then(); // case for single algorithm equation @@ -6034,6 +6054,7 @@ protected function createSingleComplexEqnCode input BackendDAE.ExtraInfo iextra; input Boolean genDiscrete; input DAE.FunctionTree funcTree; + input Option clockIndex; output list equations_; output Integer ouniqueEqIndex; output list otempvars; @@ -6073,7 +6094,7 @@ algorithm // Create nonlinear equation system from complex function (resEqs, uniqueEqIndex, tempvars, crefs) = createNonlinearResidualEquationsSingleComplex(e1, e2, source, eqAttr, iuniqueEqIndex, itempvars, crefs); (_, homotopySupport) = BackendEquation.traverseExpsOfEquation(inEquation, BackendDAEUtil.containsHomotopyCall, false); - then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, listLength(inVars)+listLength(tempvars)-listLength(itempvars), NONE(), homotopySupport, false, false), NONE(), eqAttr)}, uniqueEqIndex+1, tempvars); + then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, listLength(inVars)+listLength(tempvars)-listLength(itempvars), NONE(), homotopySupport, false, false, clockIndex), NONE(), eqAttr)}, uniqueEqIndex+1, tempvars); case (BackendDAE.COMPLEX_EQUATION(attr=eqAttr), _, _, _) equation crefs = List.map(inVars, BackendVariable.varCref); @@ -6088,7 +6109,7 @@ algorithm // considered yet there. (resEqs, uniqueEqIndex, tempvars) = createNonlinearResidualEquations({inEquation}, iuniqueEqIndex, itempvars, funcTree); (_, homotopySupport) = BackendEquation.traverseExpsOfEquation(inEquation, BackendDAEUtil.containsHomotopyCall, false); - then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, listLength(inVars)+listLength(tempvars)-listLength(itempvars), NONE(), homotopySupport, false, false), NONE(), eqAttr)}, uniqueEqIndex+1, tempvars); + then ({SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(uniqueEqIndex, resEqs, crefs, 0, listLength(inVars)+listLength(tempvars)-listLength(itempvars), NONE(), homotopySupport, false, false, clockIndex), NONE(), eqAttr)}, uniqueEqIndex+1, tempvars); // failure case (BackendDAE.COMPLEX_EQUATION(left=e1, right=e2), _, _, _) equation @@ -6510,6 +6531,7 @@ protected function createSingleAlgorithmCode input list vars; input Boolean skipDiscinAlgorithm; input Integer iuniqueEqIndex; + input Option clockIndex; output list equations_; output Integer ouniqueEqIndex; algorithm @@ -6590,7 +6612,7 @@ algorithm if not listEmpty(solvedVars) then result = {SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(iuniqueEqIndex+1, {SimCode.SES_INVERSE_ALGORITHM(iuniqueEqIndex, algStatements, knownOutputCrefs, true, eqAttr)}, - solvedVars, 0, listLength(vars), NONE(), false, false, false), NONE(), eqAttr)}; + solvedVars, 0, listLength(vars), NONE(), false, false, false, clockIndex), NONE(), eqAttr)}; ouniqueEqIndex = iuniqueEqIndex+2; else result = {SimCode.SES_INVERSE_ALGORITHM(iuniqueEqIndex, algStatements, knownOutputCrefs, false, eqAttr)}; @@ -13844,7 +13866,7 @@ algorithm getDefaultValueReference(inSimVar, inSimCode.modelInfo.varInfo); case (_, _, _) guard(stringEqual(Config.simCodeTarget(), "Cpp") or stringEqual(Config.simCodeTarget(), "omsic") - or stringEqual(Config.simCodeTarget(), "omsicpp")) + or stringEqual(Config.simCodeTarget(), "omsicpp")) algorithm // resolve aliases to get multi-dimensional arrays right // (this should possibly be done in getVarIndexByMapping?) diff --git a/OMCompiler/Compiler/Template/CodegenC.tpl b/OMCompiler/Compiler/Template/CodegenC.tpl index 72afb393dfb..a095aa69aa9 100644 --- a/OMCompiler/Compiler/Template/CodegenC.tpl +++ b/OMCompiler/Compiler/Template/CodegenC.tpl @@ -421,15 +421,15 @@ end updatePartition; template functionSystemsSynchronous(list subPartitions, String modelNamePrefix) ::= - let systs = subPartitions |> subPartition hasindex i => + let systs = subPartitions |> subPartition hasindex clockIndex => match subPartition case SUBPARTITION(__) then - functionEquationsSynchronous(i, vars, listAppend(equations, removedEquations), modelNamePrefix) + functionEquationsSynchronous(clockIndex, vars, listAppend(equations, removedEquations), modelNamePrefix) ; separator = "\n" - let cases = subPartitions |> subPartition hasindex i => - let name = 'functionEquationsSynchronous_system<%i%>' + let cases = subPartitions |> subPartition hasindex clockIndex => + let name = 'functionEquationsSynchronous_system<%clockIndex%>' << - case <%i%>: + case <%clockIndex%>: ret = <%symbolName(modelNamePrefix, name)%>(data, threadData); break; >>; separator = "\n" @@ -458,12 +458,12 @@ template functionSystemsSynchronous(list subPartitions, String mod end functionSystemsSynchronous; -template functionEquationsSynchronous(Integer i, list> vars, list equations, String modelNamePrefix) +template functionEquationsSynchronous(Integer clockIndex, list> vars, list equations, String modelNamePrefix) ::= << - <%equations |> eq => equation_impl(i, eq, contextOther, modelNamePrefix, false) ; separator="\n"%> + <%equations |> eq => equation_impl(clockIndex, eq, contextOther, modelNamePrefix, false) ; separator="\n"%> - int <%symbolName(modelNamePrefix, 'functionEquationsSynchronous_system<%i%>')%>(DATA *data, threadData_t *threadData) + int <%symbolName(modelNamePrefix, 'functionEquationsSynchronous_system<%clockIndex%>')%>(DATA *data, threadData_t *threadData) { TRACE_PUSH int i; @@ -2808,7 +2808,9 @@ match system DATA *data = (DATA*) ((void**)dataIn[0]); threadData_t *threadData = (threadData_t*) ((void**)dataIn[1]); const int equationIndexes[2] = {1,<%nls.index%>}; - int i; + int i;<% if clockIndex then << + const int clockIndex = <%clockIndex%>; + >> %> <%varDecls%> <% if profileAll() then 'SIM_PROF_TICK_EQ(<%nls.index%>);' %> <% if profileSome() then 'SIM_PROF_ADD_NCALL_EQ(modelInfoGetEquation(&data->modelData->modelDataXml,<%nls.index%>).profileBlockIndex,1);' %> diff --git a/OMCompiler/Compiler/Template/SimCodeTV.mo b/OMCompiler/Compiler/Template/SimCodeTV.mo index 442712de3b2..6a2fead49d6 100644 --- a/OMCompiler/Compiler/Template/SimCodeTV.mo +++ b/OMCompiler/Compiler/Template/SimCodeTV.mo @@ -668,6 +668,7 @@ package SimCode Boolean homotopySupport; Boolean mixedSystem; Boolean tornSystem; + Option clockIndex; end NONLINEARSYSTEM; end NonlinearSystem;