Changeset 29797a1 in OpenModelica


Ignore:
Timestamp:
2021-04-08T11:44:41+02:00 (3 years ago)
Author:
Martin Sjölund <martin@…>
Children:
defe92d3
Parents:
7d6513e
Message:

Algebraic equations have index higher than dynamic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/SimCode/SimCodeUtil.mo

    r7d6513e r29797a1  
    867867    (_, _, equations, _, ouniqueEqIndex, clockedVars, oeqSccMapping, oeqBackendSimCodeMapping, oBackendMapping) :=
    868868        createEquationsForSystem(stateeqnsmark, zceqnsmarks, syst, inShared, comps, ouniqueEqIndex, {},
    869                                  sccOffset, oeqSccMapping, oeqBackendSimCodeMapping, oBackendMapping, true);
     869                                 sccOffset, oeqSccMapping, oeqBackendSimCodeMapping, oBackendMapping, OutputSystems.Both, true);
    870870    sccOffset := listLength(comps) + sccOffset;
    871871    //otempvars := listAppend(clockedVars, otempvars);
     
    14381438// =============================================================================
    14391439
     1440protected type OutputSystems = enumeration(States, NonStates, Both);
    14401441
    14411442protected type CreateEquationsForSystemsFold =
     
    14501451      SimCode.BackendMapping  /*backendSimCodeMapping*/,
    14511452      Integer  /*sccOffset*/>;
    1452 protected type CreateEquationsForSystemsArg = tuple<BackendDAE.Shared, list<BackendDAE.ZeroCrossing>, Boolean>;
     1453protected type CreateEquationsForSystemsArg = tuple<BackendDAE.Shared, list<BackendDAE.ZeroCrossing>, OutputSystems, Boolean>;
    14531454
    14541455protected function createEquationsForSystems "Some kind of comments would be very helpful!"
     
    14771478algorithm
    14781479  try
    1479     arg := (shared, inAllZeroCrossings, createAlgebraicEquations);
     1480    arg := (shared, inAllZeroCrossings, OutputSystems.States, createAlgebraicEquations);
    14801481    foldArg := (iuniqueEqIndex, {}, {}, {}, {}, itempvars, {}, {}, iBackendMapping, iSccOffset);
     1482    foldArg := List.fold1(inSysts, createEquationsForSystems1, arg, foldArg);
     1483    arg := (shared, inAllZeroCrossings, OutputSystems.NonStates, createAlgebraicEquations);
    14811484    foldArg := List.fold1(inSysts, createEquationsForSystems1, arg, foldArg);
    14821485    (ouniqueEqIndex, oodeEquations, oalgebraicEquations, oallEquations, oequationsForZeroCrossings, otempvars,
     
    14951498  input CreateEquationsForSystemsFold inFold;
    14961499  output CreateEquationsForSystemsFold outFold;
    1497 algorithm
     1500protected
     1501  BackendDAE.StrongComponents compsStates, compsNonStates, comps;
     1502  list<BackendDAE.ZeroCrossing> zeroCrossings;
     1503  BackendDAE.Shared shared;
     1504  Boolean createAlgebraicEquations;
     1505  OutputSystems outputSystemsKind;
     1506algorithm
     1507  (shared, zeroCrossings, outputSystemsKind, createAlgebraicEquations) := inArg;
    14981508  outFold := match inSyst.matching
    14991509    local
    15001510      list<SimCode.SimEqSystem> odeEquations1, algebraicEquations1, allEquations1;
    1501       BackendDAE.StrongComponents comps;
    15021511      BackendDAE.EqSystem syst;
    15031512      list<list<SimCode.SimEqSystem>> odeEquations, algebraicEquations;
     
    15111520      list<tuple<Integer,Integer>> eqSccMapping, eqBackendSimCodeMapping;
    15121521      SimCode.BackendMapping backendMapping;
    1513       list<BackendDAE.ZeroCrossing> zeroCrossings;
    1514       BackendDAE.Shared shared;
    1515       Boolean createAlgebraicEquations;
    15161522    case BackendDAE.MATCHING(ass1=ass1, comps=comps)
    15171523      equation
     
    15201526        end if;
    15211527
    1522         (shared, zeroCrossings, createAlgebraicEquations) = inArg;
    15231528        (uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsForZeroCrossings, tempvars,
    15241529         eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccOffset) = inFold;
     
    15361541            createEquationsForSystem(
    15371542                stateeqnsmark, zceqnsmarks, syst, shared, comps, uniqueEqIndex, tempvars,
    1538                 sccOffset, eqSccMapping, eqBackendSimCodeMapping, backendMapping, createAlgebraicEquations);
     1543                sccOffset, eqSccMapping, eqBackendSimCodeMapping, backendMapping, outputSystemsKind, createAlgebraicEquations);
    15391544        GC.free(stateeqnsmark);
    15401545        GC.free(zceqnsmarks);
     
    15651570protected type CreateEquationsForSystemArg =
    15661571tuple<array<Integer> /*stateeqnsmark*/, array<Integer> /*zceqnsmark*/,
    1567       BackendDAE.EqSystem /*syst*/, BackendDAE.Shared /*shared*/, Boolean>;
     1572      BackendDAE.EqSystem /*syst*/, BackendDAE.Shared /*shared*/, OutputSystems, Boolean>;
    15681573
    15691574protected function createEquationsForSystem
     
    15791584  input list<tuple<Integer,Integer>> ieqBackendSimCodeMapping;
    15801585  input SimCode.BackendMapping iBackendMapping;
     1586  input OutputSystems outputSystemsKind;
    15811587  input Boolean createAlgebraicEquations;
    15821588  output list<SimCode.SimEqSystem> outOdeEquations;
     
    15941600  list<list<SimCode.SimEqSystem>> odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings;
    15951601algorithm
    1596   arg := (stateeqnsmark, zceqnsmark, syst, shared, createAlgebraicEquations);
     1602  arg := (stateeqnsmark, zceqnsmark, syst, shared, outputSystemsKind, createAlgebraicEquations);
    15971603  foldArg := (iuniqueEqIndex, {}, {}, {}, {}, itempvars, ieqSccMapping, ieqBackendSimCodeMapping, iBackendMapping, iSccIndex);
    15981604  foldArg := List.fold2(comps, createEquationsForSystem1, arg, partitionKindToClockIndex(syst.partitionKind), foldArg);
     
    16491655  list<BackendDAE.Var> varlst;
    16501656  list<BackendDAE.Equation> eqnlst;
     1657  OutputSystems outputSystemsKind;
    16511658  Boolean createAlgebraicEquations, bdynamic, skip;
    1652   Boolean debug = false;
    1653 algorithm
    1654   (stateeqnsmark, zceqnsmark, syst, shared, createAlgebraicEquations) := inArg;
     1659  constant Boolean debug = false;
     1660algorithm
     1661  (stateeqnsmark, zceqnsmark, syst, shared, outputSystemsKind, createAlgebraicEquations) := inArg;
    16551662  (uniqueEqIndex, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings,
    16561663  tempvars, eqSccMapping, eqBackendSimCodeMapping, backendMapping, sccIndex) := inFold;
    1657   (varlst,varIdx,eqnlst,eqsIdx) := BackendDAEUtil.getStrongComponentVarsAndEquations(comp, syst.orderedVars, syst.orderedEqs);
     1664  (varlst, varIdx, eqnlst, eqsIdx) := BackendDAEUtil.getStrongComponentVarsAndEquations(comp, syst.orderedVars, syst.orderedEqs);
    16581665  bdynamic := BackendDAEUtil.blockIsDynamic(eqsIdx, stateeqnsmark);
     1666
     1667  if outputSystemsKind==OutputSystems.Both or (if outputSystemsKind==OutputSystems.States then bdynamic else not bdynamic) then
     1668    outFold := inFold;
     1669    return;
     1670  end if;
    16591671
    16601672  skip := false;
Note: See TracChangeset for help on using the changeset viewer.