Skip to content

Commit

Permalink
[NB] Fix symbolic Jacobian resultVars and tmpVars (#10457)
Browse files Browse the repository at this point in the history
* add correct filter function for Jacobians
  - ODE/DAE filter by state derivative / algebraic
  - LS/NLS filter by residual / inner

* Rename `JAC_DIFF_VAR` to `JAC_TMP_VAR`
* Common interface `checkVar`
---------

Co-authored-by: kabdelhak <karim.abdelhak@hsbi.de>
  • Loading branch information
phannebohm and kabdelhak committed Jun 23, 2023
1 parent b0c0a25 commit 89ecd3f
Show file tree
Hide file tree
Showing 30 changed files with 524 additions and 553 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAE.mo
Expand Up @@ -276,7 +276,7 @@ uniontype VarKind "variable kind"
record CONST end CONST;
record EXTOBJ Absyn.Path fullClassName; end EXTOBJ;
record JAC_VAR end JAC_VAR;
record JAC_DIFF_VAR end JAC_DIFF_VAR;
record JAC_TMP_VAR end JAC_TMP_VAR;
record SEED_VAR end SEED_VAR;
record OPT_CONSTR end OPT_CONSTR;
record OPT_FCONSTR end OPT_FCONSTR;
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Expand Up @@ -3687,7 +3687,7 @@ algorithm
case (BackendDAE.VAR(varKind = BackendDAE.DAE_RESIDUAL_VAR())::rest,i::irest,_,_)
guard not AvlSetInt.hasKey(vars, i)
then adjacencyRowExp1(rest,irest,AvlSetInt.add(vars, i),diffindex);
case (BackendDAE.VAR(varKind = BackendDAE.JAC_DIFF_VAR())::rest,i::irest,_,_)
case (BackendDAE.VAR(varKind = BackendDAE.JAC_TMP_VAR())::rest,i::irest,_,_)
guard not AvlSetInt.hasKey(vars, i)
then adjacencyRowExp1(rest,irest,AvlSetInt.add(vars, i),diffindex);
case (BackendDAE.VAR(varKind = BackendDAE.STATE())::rest,i::irest,_,_)
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/BackEnd/BackendDump.mo
Expand Up @@ -2562,9 +2562,9 @@ algorithm
case BackendDAE.CONST() then "CONST";
case BackendDAE.EXTOBJ(path) then "EXTOBJ: " + AbsynUtil.pathString(path);
case BackendDAE.JAC_VAR() then "JACOBIAN_VAR";
case BackendDAE.JAC_DIFF_VAR()then "JACOBIAN_DIFF_VAR";
case BackendDAE.JAC_TMP_VAR() then "JACOBIAN_TMP_VAR";
case BackendDAE.OPT_CONSTR() then "OPT_CONSTR";
case BackendDAE.OPT_FCONSTR() then "OPT_FCONSTR";
case BackendDAE.OPT_FCONSTR() then "OPT_FCONSTR";
case BackendDAE.OPT_INPUT_WITH_DER() then "OPT_INPUT_WITH_DER";
case BackendDAE.OPT_INPUT_DER() then "OPT_INPUT_DER";
case BackendDAE.OPT_TGRID() then "OPT_TGRID";
Expand Down
4 changes: 2 additions & 2 deletions OMCompiler/Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -1754,7 +1754,7 @@ algorithm
cr := varCref(inVar);
cr := ComponentReference.makeCrefQual(BackendDAE.partialDerivativeNamePrefix, DAE.T_REAL_DEFAULT, {}, cr);
outVar := copyVarNewName(cr,inVar);
outVar := setVarKind(outVar,BackendDAE.JAC_DIFF_VAR());
outVar := setVarKind(outVar,BackendDAE.JAC_TMP_VAR());
end createpDerVar;

public function createClockedState
Expand All @@ -1766,7 +1766,7 @@ protected
algorithm
cr := ComponentReference.makeCrefQual(DAE.previousNamePrefix, DAE.T_REAL_DEFAULT, {}, inVar.varName);
outVar := copyVarNewName(cr,inVar);
outVar := setVarKind(outVar,BackendDAE.JAC_DIFF_VAR());
outVar := setVarKind(outVar,BackendDAE.JAC_TMP_VAR());

// HACK hide previous(v) in results because it's not calculated right
outVar := setHideResult(outVar, SOME(DAE.BCONST(true)));
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NBackEnd/Classes/NBStrongComponent.mo
Expand Up @@ -805,7 +805,7 @@ protected
try
// replace non derivative dependencies with their previous dependencies (also remove self dependency)
// (be careful with algebraic loops. this here assumes that cyclic dependencies have already been resolved)
if jacType == NBJacobian.JacobianType.SIMULATION then
if jacType == NBJacobian.JacobianType.ODE then
for dep in listReverse(dependencies) loop
if BVariable.checkCref(dep, BVariable.isState) then
fixed_dependencies := dep :: fixed_dependencies;
Expand Down

0 comments on commit 89ecd3f

Please sign in to comment.