Skip to content

Commit

Permalink
- Generate homotopy information for all systems. Until now, these inf…
Browse files Browse the repository at this point in the history
…ormation were only available for initialization and not for simulation.

- Mark each system locally if it contains a homotopy call. Until now, there was only a global marker that indicates if there is a homotopy call at all.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23297 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Nov 10, 2014
1 parent 5c27cbe commit ecd3174
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 74 deletions.
4 changes: 1 addition & 3 deletions Compiler/BackEnd/BackendDAETransform.mo
Expand Up @@ -1451,8 +1451,7 @@ algorithm
outWhenClauseLst := listReverse(outWhenClauseLst);
end traverseBackendDAEExpsWhenClauseLst;

public function traverseBackendDAEExpsEqnList<ArgT>
"author: Frenkel TUD 2010-11
public function traverseBackendDAEExpsEqnList<ArgT> "author: Frenkel TUD 2010-11
Traverse all expressions of a list of Equations. It is possible to change the equations
and the multidim equations and the algorithms."
input list<BackendDAE.Equation> inEquations;
Expand All @@ -1467,7 +1466,6 @@ public function traverseBackendDAEExpsEqnList<ArgT>
output DAE.Exp outExp;
output ArgT outArg;
end FuncExpType;
protected
algorithm
for eq in inEquations loop
(eq, outArg) := traverseBackendDAEExpsEqn(eq, func, outArg);
Expand Down
20 changes: 12 additions & 8 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -3146,13 +3146,14 @@ algorithm
list<tuple<Integer, Integer, SimCode.SimEqSystem>> simJac;
Option<SimCode.JacobianMatrix> jacobianMatrix;
list<DAE.ElementSource> sources;
case(SimCode.SES_NONLINEAR(eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing),_)
Boolean homotopySupport;
case(SimCode.SES_NONLINEAR(eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing,homotopySupport=homotopySupport),_)
equation
eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,assIn);
oldIdx = SimCodeUtil.eqIndex(simEqIn);
newIdx = arrayGet(assIn,oldIdx);
jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,assIn);
simEqSys = SimCode.SES_NONLINEAR(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing);
simEqSys = SimCode.SES_NONLINEAR(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing,homotopySupport);
then simEqSys;
case(SimCode.SES_LINEAR(partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem),ass)
equation
Expand Down Expand Up @@ -3191,12 +3192,13 @@ algorithm
list<tuple<Integer, Integer, SimCode.SimEqSystem>> simJac;
Option<SimCode.JacobianMatrix> jacobianMatrix;
list<DAE.ElementSource> sources;
case(SimCode.SES_NONLINEAR(index=oldIdx,eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing),(newIdx,ass))
Boolean homotopySupport;
case(SimCode.SES_NONLINEAR(index=oldIdx,eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing,homotopySupport=homotopySupport),(newIdx,ass))
equation
(eqs,(newIdx,ass)) = List.mapFold(eqs,TDS_replaceSimEqSysIndexWithUpdate,(newIdx,ass));
(jacobianMatrix,(newIdx,ass)) = TDS_replaceSimEqSysIdxInJacobianMatrixWithUpdate(jacobianMatrix,(newIdx,ass));
ass = arrayUpdate(ass,oldIdx,newIdx);
simEqSys = SimCode.SES_NONLINEAR(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing);
simEqSys = SimCode.SES_NONLINEAR(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing,homotopySupport);
then (simEqSys,(newIdx+1,ass));
case(SimCode.SES_LINEAR(index=oldIdx,partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem),(newIdx,ass))
equation
Expand Down Expand Up @@ -3784,15 +3786,16 @@ algorithm
list<DAE.ElementSource> sources;
list<tuple<Integer, Integer, SimCode.SimEqSystem>> simJac;
Option<SimCode.JacobianMatrix> jac;
Boolean homotopySupport;
case(SimCode.SES_LINEAR(index=idx,partOfMixed=pom,vars=simVars,beqs=expLst,sources=sources,simJac=simJac,residual=simEqSysLst,jacobianMatrix=jac),_)
equation
(lsIdx,nlsIdx,mIdx) = idcsIn;
simEqSys = SimCode.SES_LINEAR(idx,pom,simVars,expLst,simJac,simEqSysLst,jac,sources,lsIdx);
then (simEqSys,(lsIdx+1,nlsIdx,mIdx));
case(SimCode.SES_NONLINEAR(index=idx,eqs=simEqSysLst,crefs=crefs,jacobianMatrix=jac,linearTearing=lt),_)
case(SimCode.SES_NONLINEAR(index=idx,eqs=simEqSysLst,crefs=crefs,jacobianMatrix=jac,linearTearing=lt,homotopySupport=homotopySupport),_)
equation
(lsIdx,nlsIdx,mIdx) = idcsIn;
simEqSys = SimCode.SES_NONLINEAR(idx,simEqSysLst,crefs,nlsIdx,jac,lt);
simEqSys = SimCode.SES_NONLINEAR(idx,simEqSysLst,crefs,nlsIdx,jac,lt,homotopySupport);
then (simEqSys,(lsIdx,nlsIdx+1,mIdx));
case(SimCode.SES_MIXED(index=idx,cont=cont,discVars=simVars,discEqs=simEqSysLst),_)
equation
Expand Down Expand Up @@ -3841,6 +3844,7 @@ algorithm
list<tuple<DAE.Exp,list<SimCode.SimEqSystem>>> ifs;
list<SimCode.SimEqSystem> elsebranch;
Option<SimCode.JacobianMatrix> jac;
Boolean homotopySupport;
case(SimCode.SES_RESIDUAL(index=idx,exp=exp,source=source),_)
equation
(exp,changed) = BackendVarTransform.replaceExp(exp,replIn,NONE());
Expand Down Expand Up @@ -3884,15 +3888,15 @@ algorithm
simJac = List.map1(simJac,replaceInSimJac,replIn);
simEqSys = SimCode.SES_LINEAR(idx,pom,simVars,expLst,simJac,simEqSysLst,jac,sources,idxLS);
then (simEqSys,changed);
case(SimCode.SES_NONLINEAR(index=idx,eqs=simEqSysLst,crefs=crefs,indexNonLinearSystem=idxNLS,linearTearing=lt),_)
case(SimCode.SES_NONLINEAR(index=idx,eqs=simEqSysLst,crefs=crefs,indexNonLinearSystem=idxNLS,linearTearing=lt,homotopySupport=homotopySupport),_)
equation
expLst = List.map(crefs,Expression.crefExp);
(expLst,changed) = BackendVarTransform.replaceExpList(expLst,replIn,NONE(),{},false);
crefs = List.map(expLst,Expression.expCref);
(simEqSysLst,bLst) = List.map1_2(simEqSysLst,replaceExpsInSimEqSystem,replIn);
changed = changed or List.fold(bLst,boolOr,false);
print("implement Jacobian replacement for SES_NONLINEAR in HpcOmScheduler.replaceExpsInSimEqSystems!\n");
simEqSys = SimCode.SES_NONLINEAR(idx,simEqSysLst,crefs,idxNLS,NONE(),lt);
simEqSys = SimCode.SES_NONLINEAR(idx,simEqSysLst,crefs,idxNLS,NONE(),lt,homotopySupport);
then (simEqSys,changed);
case(SimCode.SES_MIXED(index=idx,cont=simEqSys,discVars=simVars,discEqs=simEqSysLst,indexMixedSystem=idxMS),_)
equation
Expand Down
32 changes: 20 additions & 12 deletions Compiler/BackEnd/Initialization.mo
Expand Up @@ -934,18 +934,26 @@ algorithm
(outExp,outUseHomotopy) := match (inExp,useHomotopy)
local
DAE.Exp e1, e2, e3, actual, simplified;
case (DAE.CALL(path = Absyn.IDENT(name="initial")), _) then (DAE.BCONST(true), useHomotopy);
case (DAE.CALL(path = Absyn.IDENT(name="sample")), _) then (DAE.BCONST(false), useHomotopy);
case (DAE.CALL(path = Absyn.IDENT(name="delay"), expLst = _::e1::_ ), _) then (e1, useHomotopy);
case (DAE.CALL(path = Absyn.IDENT(name="homotopy"), expLst = actual::simplified::_ ), _)
equation
e1 = Expression.makePureBuiltinCall("homotopyParameter", {}, DAE.T_REAL_DEFAULT);
e2 = DAE.BINARY(e1, DAE.MUL(DAE.T_REAL_DEFAULT), actual);
e3 = DAE.BINARY(DAE.RCONST(1.0), DAE.SUB(DAE.T_REAL_DEFAULT), e1);
e1 = DAE.BINARY(e3, DAE.MUL(DAE.T_REAL_DEFAULT), simplified);
e3 = DAE.BINARY(e2, DAE.ADD(DAE.T_REAL_DEFAULT), e1);
then (e3, true);
else (inExp,useHomotopy);

case (DAE.CALL(path = Absyn.IDENT(name="initial")), _)
then (DAE.BCONST(true), useHomotopy);

case (DAE.CALL(path = Absyn.IDENT(name="sample")), _)
then (DAE.BCONST(false), useHomotopy);

case (DAE.CALL(path = Absyn.IDENT(name="delay"), expLst = _::e1::_ ), _)
then (e1, useHomotopy);

case (DAE.CALL(path = Absyn.IDENT(name="homotopy"), expLst = actual::simplified::_ ), _) //equation
// e1 = Expression.makePureBuiltinCall("homotopyParameter", {}, DAE.T_REAL_DEFAULT);
// e2 = DAE.BINARY(e1, DAE.MUL(DAE.T_REAL_DEFAULT), actual);
// e3 = DAE.BINARY(DAE.RCONST(1.0), DAE.SUB(DAE.T_REAL_DEFAULT), e1);
// e1 = DAE.BINARY(e3, DAE.MUL(DAE.T_REAL_DEFAULT), simplified);
// e3 = DAE.BINARY(e2, DAE.ADD(DAE.T_REAL_DEFAULT), e1);
//then (e3, true);
then (inExp, true);

else (inExp, useHomotopy);
end match;
end simplifyInitialFunctionsExp;

Expand Down
1 change: 1 addition & 0 deletions Compiler/SimCode/SimCode.mo
Expand Up @@ -409,6 +409,7 @@ uniontype SimEqSystem
Integer indexNonLinearSystem;
Option<JacobianMatrix> jacobianMatrix;
Boolean linearTearing;
Boolean homotopySupport;
end SES_NONLINEAR;

record SES_MIXED
Expand Down

0 comments on commit ecd3174

Please sign in to comment.