Skip to content

Commit

Permalink
activated solveSimpleEquations
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24150 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Vitalij Ruge committed Jan 22, 2015
1 parent 8dfdb42 commit 75100a4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
11 changes: 9 additions & 2 deletions Compiler/BackEnd/ExpressionSolve.mo
Expand Up @@ -155,8 +155,11 @@ algorithm
BackendDAE.StrongComponent comp;
BackendDAE.StrongComponents comps;
array<Integer> ass1, ass2;
Option<BackendDAE.IncidenceMatrix> m;
Option<BackendDAE.IncidenceMatrixT> mT;

case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,matching=matching,stateSets=stateSets,partitionKind=partitionKind),shared,BackendDAE.SINGLEEQUATION(eqn=eindex,var=vindx))

case (BackendDAE.EQSYSTEM(orderedVars=vars,orderedEqs=eqns,matching=matching,stateSets=stateSets,partitionKind=partitionKind, m=m,mT=mT),shared,BackendDAE.SINGLEEQUATION(eqn=eindex,var=vindx))
algorithm
(eqn_ as BackendDAE.EQUATION(exp=e1, scalar=e2, source=source,attr=attr)) := BackendEquation.equationNth1(eqns, eindex);
(var_ as BackendDAE.VAR(varName = cr)) := BackendVariable.getVarAt(vars, vindx);
Expand All @@ -181,19 +184,23 @@ algorithm
end if;
else
try
// ExpressionSolve fail!
// try simplify equation
fail(); //TODO: ./simulation/libraries/msl32/Modelica.Electrical.Analog.Examples.ThyristorBehaviourTest.mos
(varexp, e, solveEqns, solveCr, _) := preprocessingSolve(e1, e2, varexp, NONE(), NONE(), 0);
true := List.isEmpty(solveEqns);
eqn_ := BackendDAE.EQUATION(varexp, e, source, attr);
else
eqn_ := eqn_;
end try;
// ExressionSolve can't solve eqn -> make equastion system
comp := BackendDAE.EQUATIONSYSTEM({eindex}, {vindx}, BackendDAE.EMPTY_JACOBIAN() ,BackendDAE.JAC_NONLINEAR(), false);
BackendDAE.MATCHING(comps = comps, ass1 = ass1, ass2 = ass2) := matching;
comps := List.replaceAt(comp, iter, comps);
matching := BackendDAE.MATCHING(ass1, ass2, comps);
end try;
eqns_ := BackendEquation.setAtIndex(eqns,eindex,eqn_);
syst := BackendDAE.EQSYSTEM(vars,eqns_,NONE(),NONE(),matching,stateSets,partitionKind);
syst := BackendDAE.EQSYSTEM(vars,eqns_,m,mT,matching,stateSets,partitionKind);

then(syst,shared,tmpvars);

Expand Down
31 changes: 31 additions & 0 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -2539,6 +2539,37 @@ algorithm
then
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, uniqueEqIndex, tempvars, tmpEqSccMapping, tmpEqBackendSimCodeMapping, tmpBackendMapping);

// EQUATIONSYSTEM size 1 -> single equation
case (_, _, BackendDAE.EQSYSTEM(orderedVars=vars, orderedEqs=eqns), _, (BackendDAE.EQUATIONSYSTEM(eqns={index}, vars={vindex})), _, _, _, _, _, _, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings)
equation
eqn = BackendEquation.equationNth1(eqns, index);
// ignore when equations if we should not generate them
bwhen = BackendEquation.isWhenEquation(eqn);
// ignore discrete if we should not generate them
v = BackendVariable.getVarAt(vars, index);
_ = BackendVariable.isVarDiscrete(v);
// block is dynamic, belong in dynamic section
bdynamic = BackendDAEUtil.blockIsDynamic({index}, stateeqnsmark);
// block need to evaluate zeroCrossings
bzceqns = BackendDAEUtil.blockIsDynamic({index}, zceqnsmark);
(equations1, uniqueEqIndex, tempvars) = createEquation(index, vindex, syst, shared, false, iuniqueEqIndex, itempvars);

firstSES = List.first(equations1); // check if the all equations occure with this index in the c file
isEqSys = isSimEqSys(firstSES);
firstEqIndex = if isEqSys then uniqueEqIndex-1 else iuniqueEqIndex;
//tmpEqSccMapping = List.fold1(List.intRange2(iuniqueEqIndex, uniqueEqIndex - 1), appendSccIdx, isccIndex, ieqSccMapping);

tmpEqSccMapping = List.fold1(List.intRange2(firstEqIndex, uniqueEqIndex - 1), appendSccIdx, isccIndex, ieqSccMapping);
tmpEqBackendSimCodeMapping = List.fold1(List.intRange2(firstEqIndex, uniqueEqIndex - 1), appendSccIdx, index, ieqBackendSimCodeMapping);
tmpBackendMapping = setEqMapping(List.intRange2(firstEqIndex, uniqueEqIndex - 1),{index}, iBackendMapping);

odeEquations = if bdynamic and (not bwhen) then equations1::odeEquations else odeEquations;
algebraicEquations = if (not bdynamic) and (not bwhen) then equations1::algebraicEquations else algebraicEquations;
equationsforZeroCrossings = if bzceqns and (not bwhen) then equations1::equationsforZeroCrossings else equationsforZeroCrossings;
allEquations = equations1::allEquations;
then
(odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings, uniqueEqIndex, tempvars, tmpEqSccMapping, tmpEqBackendSimCodeMapping, tmpBackendMapping);

// a system of equations
case (_, _, _, _, _, _, _, _, _, _, _, odeEquations, algebraicEquations, allEquations, equationsforZeroCrossings)
equation
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Util/Flags.mo
Expand Up @@ -705,7 +705,6 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
"inlineArrayEqn",
"constantLinearSystem",
"simplifysemiLinear",
//"solveSimpleEquations", // can change matching, some issues with HeatingSystem
//"solveLinearSystem",
"removeSimpleEquations",
"encapsulateWhenConditions", // must called after remove simple equations
Expand All @@ -720,7 +719,8 @@ constant ConfigFlag POST_OPT_MODULES = CONFIG_FLAG(16, "postOptModules",
"generateSymbolicJacobian",
"generateSymbolicLinearization",
"removeUnusedFunctions",
"removeConstants"
"removeConstants",
"solveSimpleEquations"
// "partitionIndependentBlocks",
// "addInitialStmtsToAlgorithms"
}),
Expand Down

0 comments on commit 75100a4

Please sign in to comment.