Skip to content

Commit

Permalink
- fixes for solve inital system
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13718 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Oct 30, 2012
1 parent 3d3c19e commit 98f66ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9327,14 +9327,14 @@ algorithm
case (_,_,_)
equation
true = intEq(nEqns,nVars);
pastOptModules = getPastOptModules(SOME({"constantLinearSystem","removeSimpleEquations","tearingSystem"}));
pastOptModules = getPastOptModules(SOME({"constantLinearSystem",/* here we need a special case and remove only alias and constant (no variables of the system) variables "removeSimpleEquations", */ "tearingSystem"}));
matchingAlgorithm = getMatchingAlgorithm(NONE());
daeHandler = getIndexReductionMethod(NONE());
daeHandler = getIndexReductionMethod(NONE());
// solve system
isyst = transformBackendDAE(inDAE,SOME((BackendDAE.NO_INDEX_REDUCTION(),BackendDAE.EXACT())),NONE(),NONE());
// simplify system
(isyst,Util.SUCCESS()) = pastoptimiseDAE(isyst,pastOptModules,matchingAlgorithm,daeHandler);
Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, print, "Solved Initial System");
Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, print, "Solved Initial System:\n");
Debug.fcall(Flags.DUMP_INITIAL_SYSTEM, BackendDump.dump, isyst);
then
isyst;
Expand Down
30 changes: 17 additions & 13 deletions Compiler/BackEnd/SimCodeUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,7 @@ algorithm

list<SimCode.JacobianMatrix> LinearMatrices;
SimCode.HashTableCrefToSimVar crefToSimVarHT;
Boolean ifcpp,hasDivStmts;
Boolean ifcpp,hasDivStmts,initialSystemSolved;
BackendDAE.EqSystems systs;
BackendDAE.Shared shared;
BackendDAE.EquationArray removedEqs;
Expand Down Expand Up @@ -1879,7 +1879,7 @@ algorithm
n_h = listLength(helpVarInfo);

// initialization stuff
(residuals, initialEquations, numberOfInitialEquations, uniqueEqIndex,tempvars) = createInitialResiduals(dlow2,uniqueEqIndex,{},helpVarInfo);
(residuals, initialEquations, numberOfInitialEquations, uniqueEqIndex,tempvars,initialSystemSolved) = createInitialResiduals(dlow2,uniqueEqIndex,{},helpVarInfo);
(jacG, uniqueEqIndex) = createInitialMatrices(dlow2, uniqueEqIndex);

// Add model info
Expand All @@ -1896,7 +1896,7 @@ algorithm
// create parameter equations
((uniqueEqIndex,startValueEquations)) = BackendDAEUtil.foldEqSystem(dlow2,createStartValueEquations,(uniqueEqIndex,{}));
((uniqueEqIndex,parameterEquations)) = BackendDAEUtil.foldEqSystem(dlow2,createVarNominalAssertFromVars,(uniqueEqIndex,{}));
(uniqueEqIndex,parameterEquations) = createParameterEquations(shared,uniqueEqIndex,parameterEquations);
(uniqueEqIndex,parameterEquations) = createParameterEquations(shared,uniqueEqIndex,parameterEquations,initialSystemSolved);
((uniqueEqIndex,removedEquations)) = BackendEquation.traverseBackendDAEEqns(removedEqs,traversedlowEqToSimEqSystem,(uniqueEqIndex,{}));

((uniqueEqIndex,algorithmAndEquationAsserts)) = BackendDAEUtil.foldEqSystem(dlow2,createAlgorithmAndEquationAsserts,(uniqueEqIndex,{}));
Expand Down Expand Up @@ -6293,9 +6293,10 @@ protected function createInitialResiduals "function: createInitialResiduals
output list<SimCode.SimEqSystem> outInitialEqns;
output Integer outNumberOfInitialEquations;
output Integer ouniqueEqIndex;
output list<SimCode.SimVar> otempvars;
output list<SimCode.SimVar> otempvars;
output Boolean initialSystemSolved;
algorithm
(outResiduals, outInitialEqns, outNumberOfInitialEquations, ouniqueEqIndex, otempvars) := matchcontinue(inDAE,iuniqueEqIndex,itempvars,helpVarInfo)
(outResiduals, outInitialEqns, outNumberOfInitialEquations, ouniqueEqIndex, otempvars, initialSystemSolved) := matchcontinue(inDAE,iuniqueEqIndex,itempvars,helpVarInfo)
local
BackendDAE.EqSystems eqs;
BackendDAE.EquationArray initialEqs,removedEqs;
Expand Down Expand Up @@ -6326,15 +6327,16 @@ algorithm
((uniqueEqIndex,aliasEquations)) = BackendVariable.traverseBackendDAEVars(aliasVars,traverseAliasVarsToSimEqSystem,(uniqueEqIndex,{}));
allEquations = listAppend(allEquations,aliasEquations);
then
({},allEquations,0,uniqueEqIndex,tempvars);
({},allEquations,0,uniqueEqIndex,tempvars,true);
case(BackendDAE.DAE(eqs=eqs, shared=BackendDAE.SHARED(initialEqs=initialEqs)),_,_,_)
equation
// initial_equation
//numberOfInitialEquations = BackendDAEUtil.equationSize(initialEqs);
numberOfInitialEquations = BackendDAEUtil.equationSize(initialEqs);
initialEqs_lst = BackendDAEUtil.equationList(initialEqs);
// remove algorithms, I have no clue what the reason is but is was done before also
initialEqs_lst = List.select(initialEqs_lst,BackendEquation.isNotAlgorithm);
numberOfInitialEquations = BackendEquation.equationLstSize(initialEqs_lst);
// do not remove the inital algorithms if the system is solved symbolically
initialEqs_lst = Debug.bcallret2(not Flags.isSet(Flags.SOLVE_INITIAL_SYSTEM),List.select,initialEqs_lst,BackendEquation.isNotAlgorithm,initialEqs_lst);
numberOfInitialEquations = Debug.bcallret1(not Flags.isSet(Flags.SOLVE_INITIAL_SYSTEM),BackendEquation.equationLstSize,initialEqs_lst,numberOfInitialEquations);
(residual_equations,uniqueEqIndex,tempvars) = createNonlinearResidualEquations(initialEqs_lst, iuniqueEqIndex, itempvars);

// [orderedVars] with start-values and fixed=true
Expand All @@ -6345,7 +6347,7 @@ algorithm
(residual_equations1, uniqueEqIndex) = List.mapFold(initialEqs_lst, dlowEqToSimEqSystem, uniqueEqIndex);
residual_equations = listAppend(residual_equations,residual_equations1);
then
(residual_equations,{},numberOfInitialEquations,uniqueEqIndex,tempvars);
(residual_equations,{},numberOfInitialEquations,uniqueEqIndex,tempvars,Flags.isSet(Flags.SOLVE_INITIAL_SYSTEM));

else equation
Error.addMessage(Error.INTERNAL_ERROR, {"./Compiler/BackEnd/SimCode.mo: createInitialResiduals failed"});
Expand Down Expand Up @@ -6549,10 +6551,11 @@ protected function createParameterEquations
input BackendDAE.Shared inShared;
input Integer iuniqueEqIndex;
input list<SimCode.SimEqSystem> acc;
input Boolean initialSystemSolved;
output Integer ouniqueEqIndex;
output list<SimCode.SimEqSystem> parameterEquations;
algorithm
(ouniqueEqIndex,parameterEquations) := matchcontinue (inShared,iuniqueEqIndex,acc)
(ouniqueEqIndex,parameterEquations) := matchcontinue (inShared,iuniqueEqIndex,acc,initialSystemSolved)
local
list<BackendDAE.Equation> parameterEquationsTmp;
BackendDAE.Variables knvars,extobj,v,kn;
Expand Down Expand Up @@ -6584,7 +6587,7 @@ algorithm

case (BackendDAE.SHARED(knownVars=knvars,externalObjects=extobj,aliasVars=aliasVars,
initialEqs=ie,removedEqs=remeqns,constraints=constrs,classAttrs=clsAttrs,cache=cache,env=env,
extObjClasses=extObjClasses,functionTree=funcs,eventInfo=einfo,backendDAEType=btp,symjacs=symjacs),_,_)
extObjClasses=extObjClasses,functionTree=funcs,eventInfo=einfo,backendDAEType=btp,symjacs=symjacs),_,_,_)
equation
// kvars params
((parameterEquationsTmp,lv,lkn,lv1,lv2,_)) = BackendVariable.traverseBackendDAEVars(knvars,createInitialParamAssignments,({},{},{},{},{},1));
Expand Down Expand Up @@ -6623,7 +6626,8 @@ algorithm
varasserts = BackendVariable.traverseBackendDAEVars(knvars,createVarAsserts,{});
(simvarasserts,uniqueEqIndex) = List.mapFold(varasserts,dlowAlgToSimEqSystem,uniqueEqIndex);

parameterEquations = listAppend(parameterEquations, inalgs);
// do not append the inital algorithms to the parameter equation if the system is solved symbolically
parameterEquations = Debug.bcallret2(not initialSystemSolved,listAppend,parameterEquations, inalgs, parameterEquations);
parameterEquations = listAppend(parameterEquations, simvarasserts);
parameterEquations = listAppend(parameterEquations, acc);
then
Expand Down

0 comments on commit 98f66ae

Please sign in to comment.