Skip to content

Commit

Permalink
- BackendDAE.mo: add Comment
Browse files Browse the repository at this point in the history
- extend Backend pipeline with functionalety to select matching algorithm
- Bugfix for DynamicStateSelection, in function BackendEquation.equationAddDAE do not throw incidenceMatrix away
- add function BackendVariable.daenumVariables, return the number of Variables in BackendDAE

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11707 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Apr 10, 2012
1 parent ce6c2eb commit bcb9f9b
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 169 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -273,8 +273,8 @@ end EqSystem;
uniontype Matching
record NO_MATCHING "matching has not yet been performed" end NO_MATCHING;
record MATCHING "not yet used"
array<Integer> ass1;
array<Integer> ass2;
array<Integer> ass1 "ass[varindx]=eqnindx";
array<Integer> ass2 "ass[eqnindx]=varindx";
StrongComponents comps;
end MATCHING;
end Matching;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendDAEOptimize.mo
Expand Up @@ -5018,7 +5018,7 @@ algorithm
dlow_1 = BackendDAE.DAE(BackendDAE.EQSYSTEM(vars_1,eqns_2,NONE(),NONE(),BackendDAE.NO_MATCHING())::{},shared);
dlow1_1 = BackendDAE.DAE(BackendDAE.EQSYSTEM(ordvars1,eqns1_1,NONE(),NONE(),BackendDAE.NO_MATCHING())::{},shared);
// try causalisation
(dlow_2 as BackendDAE.DAE(eqs=BackendDAE.EQSYSTEM(m=SOME(m_2),mT=SOME(mT_2),matching=BackendDAE.MATCHING(v1_1,v2_1,comps))::{})) = BackendDAEUtil.transformBackendDAE(dlow_1,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE());
(dlow_2 as BackendDAE.DAE(eqs=BackendDAE.EQSYSTEM(m=SOME(m_2),mT=SOME(mT_2),matching=BackendDAE.MATCHING(v1_1,v2_1,comps))::{})) = BackendDAEUtil.transformBackendDAE(dlow_1,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE(),NONE());
comps_1 = List.map(comps,getEqnIndxFromComp);
// check strongComponents and split it into two lists: len(comp)==1 and len(comp)>1
(morecomps,onecomp) = splitComps(comps_1);
Expand Down Expand Up @@ -5444,7 +5444,7 @@ algorithm

//Debug.fcall(Flags.EXEC_STAT,print, "*** analytical Jacobians -> removed simply equations: " +& realString(clock()) +& "\n" );
// figure out new matching and the strong components
(dlow as BackendDAE.DAE(eqs={BackendDAE.EQSYSTEM(matching=matching as BackendDAE.MATCHING(comps=comps1))})) = BackendDAEUtil.transformBackendDAE(dlow,functionTree,SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE());
(dlow as BackendDAE.DAE(eqs={BackendDAE.EQSYSTEM(matching=matching as BackendDAE.MATCHING(comps=comps1))})) = BackendDAEUtil.transformBackendDAE(dlow,functionTree,SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE(),NONE());
Debug.fcall(Flags.JAC_DUMP2, BackendDump.bltdump, ("jacdump2",dlow));
Debug.fcall(Flags.JAC_DUMP2, BackendDump.dumpFullMatching, matching);
//Debug.fcall(Flags.EXEC_STAT,print, "*** analytical Jacobians -> performed matching and sorting: " +& realString(clock()) +& "\n" );
Expand Down
101 changes: 59 additions & 42 deletions Compiler/BackEnd/BackendDAETransform.mo

Large diffs are not rendered by default.

239 changes: 144 additions & 95 deletions Compiler/BackEnd/BackendDAEUtil.mo

Large diffs are not rendered by default.

19 changes: 7 additions & 12 deletions Compiler/BackEnd/BackendEquation.mo
Expand Up @@ -1073,26 +1073,21 @@ end equationAdd;

public function equationAddDAE
"function: equationAddDAE
author: Frenkel TUD 2011-05
Incidence Matrix is lost"
author: Frenkel TUD 2011-05"
input BackendDAE.Equation inEquation;
input BackendDAE.EqSystem syst;
output BackendDAE.EqSystem osyst;
algorithm
osyst := match (inEquation,syst)
local
BackendDAE.Variables ordvars,knvars,exobj;
BackendDAE.AliasVariables aliasVars;
BackendDAE.EquationArray eqns,remeqns,inieqns,eqns1;
array<BackendDAE.MultiDimEquation> arreqns;
array<DAE.Algorithm> algorithms;
BackendDAE.EventInfo einfo;
BackendDAE.ExternalObjectClasses eoc;
BackendDAE.Shared shared;
case (inEquation,BackendDAE.EQSYSTEM(orderedVars=ordvars,orderedEqs=eqns))
BackendDAE.Variables ordvars;
BackendDAE.EquationArray eqns,eqns1;
Option<BackendDAE.IncidenceMatrix> m;
Option<BackendDAE.IncidenceMatrixT> mT;
case (inEquation,BackendDAE.EQSYSTEM(orderedVars=ordvars,orderedEqs=eqns,m=m,mT=mT))
equation
eqns1 = equationAdd(inEquation,eqns);
then BackendDAE.EQSYSTEM(ordvars,eqns1,NONE(),NONE(),BackendDAE.NO_MATCHING());
then BackendDAE.EQSYSTEM(ordvars,eqns1,m,mT,BackendDAE.NO_MATCHING());
end match;
end equationAddDAE;

Expand Down
10 changes: 10 additions & 0 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -1841,6 +1841,16 @@ end getNominalAssert;
* =======================================================
*/

public function daenumVariables
input BackendDAE.EqSystem syst;
output Integer n;
protected
BackendDAE.Variables vars;
algorithm
vars := daeVars(syst);
n := numVariables(vars);
end daenumVariables;

public function numVariables
input BackendDAE.Variables vars;
output Integer n;
Expand Down
16 changes: 7 additions & 9 deletions Compiler/BackEnd/SimCode.mo
Expand Up @@ -98,12 +98,10 @@ protected import ExpressionDump;
protected import ExpressionSimplify;
protected import ExpressionSolve;
protected import Flags;
protected import InnerOuter;
protected import List;
protected import Mod;
protected import PartFn;
protected import PriorityQueue;
protected import SCodeUtil;
protected import Settings;
protected import SimCodeDump;
protected import System;
Expand Down Expand Up @@ -1023,7 +1021,7 @@ algorithm
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae,funcs,true);
(dlow_1,funcs1) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
NONE(), NONE(), NONE());
NONE(), NONE(), NONE(), NONE());
Debug.fprintln(Flags.DYN_LOAD, "translateModel: Generating simulation code and functions.");
(indexed_dlow_1,libs,file_dir,timeBackend,timeSimCode,timeTemplates) =
generateModelCodeFMU(dlow_1,funcs1,p, dae, className, filenameprefix, inSimSettingsOpt);
Expand Down Expand Up @@ -1240,7 +1238,7 @@ algorithm
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae,funcs,true);
(dlow_1,funcs1) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,
NONE(), NONE(), NONE());
NONE(), NONE(), NONE(), NONE());
(indexed_dlow_1,libs,file_dir,timeBackend,timeSimCode,timeTemplates, timeJacobians) =
generateModelCode(dlow_1,funcs1,p, dae, className, filenameprefix, inSimSettingsOpt, args);
resultValues =
Expand Down Expand Up @@ -2587,7 +2585,7 @@ algorithm
equation
true = Flags.isSet(Flags.JACOBIAN) or Flags.isSet(Flags.LINEARIZATION);
dlow = BackendDAEOptimize.collapseIndependentBlocks(dlow,functions);
dlow = BackendDAEUtil.transformBackendDAE(dlow,functions,SOME((BackendDAE.NO_INDEX_REDUCTION(),BackendDAE.EXACT())),SOME("dummyDerivative"));
dlow = BackendDAEUtil.transformBackendDAE(dlow,functions,SOME((BackendDAE.NO_INDEX_REDUCTION(),BackendDAE.EXACT())),NONE(),SOME("dummyDerivative"));
// The jacobian code requires single systems;
// I did not rewrite it to take advantage of any parallelism in the code
res = createJacobianCC(functions,dlow);
Expand Down Expand Up @@ -2793,7 +2791,7 @@ BackendDAE.SHARED(knownVars = kv)))
newVars = BackendDAEUtil.emptyVars();
(newEqns, newVars) = splitoutEquationAndVars(blt_states,e,v,newEqns,newVars);
dlow = BackendDAE.DAE(BackendDAE.EQSYSTEM(newVars,newEqns,NONE(),NONE(),BackendDAE.NO_MATCHING())::{},shared);
dlow = BackendDAEUtil.transformBackendDAE(dlow,functions,SOME((BackendDAE.NO_INDEX_REDUCTION(),BackendDAE.EXACT())),SOME("dummyDerivative"));
dlow = BackendDAEUtil.transformBackendDAE(dlow,functions,SOME((BackendDAE.NO_INDEX_REDUCTION(),BackendDAE.EXACT())),NONE(),SOME("dummyDerivative"));

// Prepare all needed variables
varlst_tmp = BackendDAEUtil.varList(v);
Expand Down Expand Up @@ -4995,7 +4993,7 @@ algorithm
(m,mt) = BackendDAEUtil.incidenceMatrix(syst, shared, BackendDAE.ABSOLUTE());
syst = BackendDAE.EQSYSTEM(vars_1,eqns_1,SOME(m),SOME(mt),BackendDAE.NO_MATCHING());
subsystem_dae = BackendDAE.DAE({syst},shared);
(subsystem_dae_1 as BackendDAE.DAE(eqs={BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(v1,v2,comps))})) = BackendDAEUtil.transformBackendDAE(subsystem_dae,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE());
(subsystem_dae_1 as BackendDAE.DAE(eqs={BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(v1,v2,comps))})) = BackendDAEUtil.transformBackendDAE(subsystem_dae,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE(),NONE());
(subsystem_dae_2 as BackendDAE.DAE(eqs={BackendDAE.EQSYSTEM(m=SOME(m_3),mT=SOME(mT_3))}),v1_1,v2_1,comps_1,r,t) = BackendDAEOptimize.tearingSystem(subsystem_dae_1,v1,v2,comps);
true = listLength(r) > 0;
true = listLength(t) > 0;
Expand Down Expand Up @@ -5314,7 +5312,7 @@ algorithm
evars = BackendDAEUtil.emptyVars();
eeqns = BackendDAEUtil.listEquation({});
subsystem_dae = BackendDAE.DAE(BackendDAE.EQSYSTEM(v,eqn,NONE(),NONE(),BackendDAE.NO_MATCHING())::{},BackendDAE.SHARED(evars,evars,ave,eeqns,eeqns,ae,algorithms,complEqs,BackendDAE.EVENT_INFO({},{}),{},BackendDAE.ALGEQSYSTEM() ));
(subsystem_dae_1 as BackendDAE.DAE(eqs={BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(v1,v2,comps))})) = BackendDAEUtil.transformBackendDAE(subsystem_dae,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE());
(subsystem_dae_1 as BackendDAE.DAE(eqs={BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(v1,v2,comps))})) = BackendDAEUtil.transformBackendDAE(subsystem_dae,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.EXACT())),NONE(),NONE());
(subsystem_dae_2,v1_1,v2_1,comps_1,r,t) = BackendDAEOptimize.tearingSystem(subsystem_dae_1,v1,v2,comps);
true = listLength(r) > 0;
true = listLength(t) > 0;
Expand Down Expand Up @@ -6053,7 +6051,7 @@ algorithm
syst = BackendDAE.EQSYSTEM(vars,eqns_1,NONE(),NONE(),BackendDAE.NO_MATCHING());
shared = BackendDAE.SHARED(evars,evars,av,eeqns,eeqns,ae1,al,complEqs,BackendDAE.EVENT_INFO({},{}),{},BackendDAE.ARRAYSYSTEM());
subsystem_dae = BackendDAE.DAE({syst},shared);
(BackendDAE.DAE({syst as BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps))},shared)) = BackendDAEUtil.transformBackendDAE(subsystem_dae,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.ALLOW_UNDERCONSTRAINED())),NONE());
(BackendDAE.DAE({syst as BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps))},shared)) = BackendDAEUtil.transformBackendDAE(subsystem_dae,DAEUtil.avlTreeNew(),SOME((BackendDAE.NO_INDEX_REDUCTION(), BackendDAE.ALLOW_UNDERCONSTRAINED())),NONE(),NONE());
equations_ = createEquations(false, true, genDiscrete, false, false, syst, shared, offset, comps, helpVarInfo);
then
equations_;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/Uncertainties.mo
Expand Up @@ -143,7 +143,7 @@ algorithm
print("* Lower ok\n");


(dlow_1,funcs1) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,SOME({"removeFinalParameters", "removeEqualFunctionCalls","partitionIndependentBlocks", "expandDerOperator"}), NONE(), NONE());
(dlow_1,funcs1) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs,SOME({"removeFinalParameters", "removeEqualFunctionCalls","partitionIndependentBlocks", "expandDerOperator"}), NONE(), NONE(), NONE());
print("*** Lowered: \n");
BackendDump.dump(dlow_1);
print("*** end Lowered: \n");
Expand Down
5 changes: 2 additions & 3 deletions Compiler/BackEnd/XMLDump.mo
Expand Up @@ -92,7 +92,6 @@ protected import BackendDAETransform;
protected import ComponentReference;
protected import Config;
protected import DAEUtil;
protected import Debug;
protected import Dump;
protected import Error;
protected import Expression;
Expand Down Expand Up @@ -2748,7 +2747,7 @@ algorithm
case (false,false,_) then ();
case (true,true,dlow)
equation
(BackendDAE.DAE(eqs=BackendDAE.EQSYSTEM(m=SOME(m),mT=SOME(mT),matching=BackendDAE.MATCHING(v1,v2,comps))::{})) = BackendDAEUtil.transformBackendDAE(dlow,DAEUtil.avlTreeNew(),NONE(),NONE());
(BackendDAE.DAE(eqs=BackendDAE.EQSYSTEM(m=SOME(m),mT=SOME(mT),matching=BackendDAE.MATCHING(v1,v2,comps))::{})) = BackendDAEUtil.transformBackendDAE(dlow,DAEUtil.avlTreeNew(),NONE(),NONE(),NONE());
dumpStrOpenTag(ADDITIONAL_INFO);
dumpStrOpenTag(ORIGINAL_INCIDENCE_MATRIX);
dumpIncidenceMatrix(m);
Expand All @@ -2771,7 +2770,7 @@ algorithm
then ();
case (false,true,dlow)
equation
(BackendDAE.DAE(eqs=BackendDAE.EQSYSTEM(m=SOME(m),mT=SOME(mT),matching=BackendDAE.MATCHING(v1,v2,comps))::{})) = BackendDAEUtil.transformBackendDAE(dlow,DAEUtil.avlTreeNew(),NONE(),NONE());
(BackendDAE.DAE(eqs=BackendDAE.EQSYSTEM(m=SOME(m),mT=SOME(mT),matching=BackendDAE.MATCHING(v1,v2,comps))::{})) = BackendDAEUtil.transformBackendDAE(dlow,DAEUtil.avlTreeNew(),NONE(),NONE(),NONE());
dumpStrOpenTag(ADDITIONAL_INFO);
dumpStrOpenTag(SOLVING_INFO);
dumpMatching(v1);
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Main/Main.mo
Expand Up @@ -763,7 +763,7 @@ algorithm
true = runBackendQ();
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae,funcs,true);
(dlow_1,funcs_1) = BackendDAEUtil.getSolvedSystem(cache,env,dlow,funcs,NONE(),NONE(),NONE());
(dlow_1,funcs_1) = BackendDAEUtil.getSolvedSystem(cache,env,dlow,funcs,NONE(),NONE(),NONE(),NONE());
modpar(dlow_1);
Debug.execStat("Lowering Done",CevalScript.RT_CLOCK_EXECSTAT_MAIN);
simcodegen(dlow_1,funcs_1,classname,ap,dae);
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -3999,7 +3999,7 @@ algorithm
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae, funcs, true); //Verificare cosa fa
dlow_1 = BackendDAEUtil.preOptimiseBackendDAE(dlow,funcs,NONE());
dlow_1 = BackendDAEUtil.transformBackendDAE(dlow_1,funcs,NONE(),NONE());
dlow_1 = BackendDAEUtil.transformBackendDAE(dlow_1,funcs,NONE(),NONE(),NONE());
dlow_1 = BackendDAECreate.findZeroCrossings(dlow_1);
xml_filename = stringAppendList({filenameprefix,".xml"});
funcelems = DAEUtil.getFunctionList(Env.getFunctionTree(cache));
Expand All @@ -4025,7 +4025,7 @@ algorithm
dae = DAEUtil.transformationsBeforeBackend(cache,dae_1);
funcs = Env.getFunctionTree(cache);
dlow = BackendDAECreate.lower(dae, funcs, true);
(indexed_dlow,funcs1) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs, NONE(), NONE(), NONE());
(indexed_dlow,funcs1) = BackendDAEUtil.getSolvedSystem(cache, env, dlow, funcs, NONE(), NONE(), NONE(), NONE());
xml_filename = stringAppendList({filenameprefix,".xml"});
funcelems = DAEUtil.getFunctionList(funcs1);
Print.clearBuf();
Expand Down

0 comments on commit bcb9f9b

Please sign in to comment.