Skip to content

Commit

Permalink
Solve for inputs (or a combination of inputs and outputs) of an algor…
Browse files Browse the repository at this point in the history
…ithm section if necessary

Therefore, the algorithm is treated as a nonlinear loop. This should be improved for discrete or hybrid systems (mixed continuous and discrete systems).
See #3081
TODO: Handle discrete algorithm outputs properly.
  • Loading branch information
lochel committed Jun 26, 2015
1 parent f2102e3 commit 639dcf9
Show file tree
Hide file tree
Showing 8 changed files with 766 additions and 690 deletions.
10 changes: 5 additions & 5 deletions Compiler/BackEnd/HpcOmScheduler.mo
Expand Up @@ -3549,22 +3549,22 @@ algorithm
case(SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(eqs=eqs,crefs=crefs,indexNonLinearSystem=indexNonLinearSystem,jacobianMatrix=jacobianMatrix,linearTearing=linearTearing,homotopySupport=homotopySupport,mixedSystem=mixedSystem)),_)
equation
eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,assIn);
oldIdx = SimCodeUtil.eqIndex(simEqIn);
oldIdx = SimCodeUtil.simEqSystemIndex(simEqIn);
newIdx = arrayGet(assIn,oldIdx);
jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,assIn);
simEqSys = SimCode.SES_NONLINEAR(SimCode.NONLINEARSYSTEM(newIdx,eqs,crefs,indexNonLinearSystem,jacobianMatrix,linearTearing,homotopySupport,mixedSystem), NONE());
then simEqSys;
case(SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(partOfMixed=partOfMixed,vars=vars,beqs=beqs,simJac=simJac,residual=eqs,jacobianMatrix=jacobianMatrix,sources=sources,indexLinearSystem=indexLinearSystem)),ass)
equation
eqs = List.map1(eqs,TDS_replaceSimEqSysIndex,ass);
oldIdx = SimCodeUtil.eqIndex(simEqIn);
oldIdx = SimCodeUtil.simEqSystemIndex(simEqIn);
newIdx = arrayGet(ass,oldIdx);
jacobianMatrix = TDS_replaceSimEqSysIdxInJacobianMatrix(jacobianMatrix,ass);
simEqSys = SimCode.SES_LINEAR(SimCode.LINEARSYSTEM(newIdx,partOfMixed,vars,beqs,simJac,eqs,jacobianMatrix,sources,indexLinearSystem), NONE());
then simEqSys;
case(_,ass)
equation
oldIdx = SimCodeUtil.eqIndex(simEqIn);
oldIdx = SimCodeUtil.simEqSystemIndex(simEqIn);
newIdx = arrayGet(ass,oldIdx);
simEqSys = SimCodeUtil.replaceSimEqSysIndex(simEqIn,newIdx);
then simEqSys;
Expand Down Expand Up @@ -3616,7 +3616,7 @@ algorithm
then (simEqSys,(newIdx+1,ass));
case(_,(newIdx,ass))
equation
oldIdx = SimCodeUtil.eqIndex(simEqIn);
oldIdx = SimCodeUtil.simEqSystemIndex(simEqIn);
ass = arrayUpdate(ass,oldIdx,newIdx);
simEqSys = SimCodeUtil.replaceSimEqSysIndex(simEqIn,newIdx);
then (simEqSys,(newIdx+1,ass));
Expand Down Expand Up @@ -4154,7 +4154,7 @@ algorithm
list<SimCode.SimEqSystem> eqSysLst;
case(_,_)
equation
_ = SimCodeUtil.eqIndex(eqSysIn);
_ = SimCodeUtil.simEqSystemIndex(eqSysIn);
pos = List.position1OnTrue(eqSysLstIn,SimCodeUtil.equationIndexEqual,eqSysIn);
eqSysLst = List.replaceAt(eqSysIn,pos,eqSysLstIn);
then eqSysLst;
Expand Down
779 changes: 391 additions & 388 deletions Compiler/SimCode/SerializeModelInfo.mo

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Compiler/SimCode/SimCode.mo
Expand Up @@ -390,6 +390,14 @@ uniontype SimEqSystem
list<DAE.Statement> statements;
end SES_ALGORITHM;

record SES_INVERSE_ALGORITHM
"this should only occure inside SES_NONLINEAR"
Integer index;
list<DAE.Statement> statements;
list<DAE.ComponentRef> outputCrefs "this are the output crefs of the original algorithm - not of the inverted one";
list<DAE.ComponentRef> knownOutputCrefs "this is a subset of outputCrefs that contain only those that are already known";
end SES_INVERSE_ALGORITHM;

record SES_LINEAR
LinearSystem lSystem;
Option<LinearSystem> alternativeTearing;
Expand Down
283 changes: 137 additions & 146 deletions Compiler/SimCode/SimCodeUtil.mo

Large diffs are not rendered by default.

0 comments on commit 639dcf9

Please sign in to comment.