Skip to content

Commit

Permalink
Use VarKind JAC_VAR for Jacobian SimVars
Browse files Browse the repository at this point in the history
This further reduces erroneous guesses during Cpp code generation.
  • Loading branch information
rfranke committed Apr 3, 2016
1 parent 948feba commit a0ee81b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 31 deletions.
5 changes: 3 additions & 2 deletions Compiler/SimCode/SimCodeUtil.mo
Expand Up @@ -4157,7 +4157,7 @@ end collectAllJacobianEquations;

protected function collectAllJacobianVars
input list<SimCode.JacobianMatrix> inJacobianMatrix;
output list<SimCodeVar.SimVar> outEqn = {};
output list<SimCodeVar.SimVar> outVars = {};
protected
list<SimCode.JacobianColumn> column;
list<SimCodeVar.SimVar> tmp;
Expand All @@ -4166,9 +4166,10 @@ algorithm
(column, _, _, _, _, _, _) := m;
for c in column loop
(_,tmp,_) := c;
outEqn := listAppend(tmp, outEqn);
outVars := listAppend(tmp, outVars);
end for;
end for;
outVars := List.map1(outVars, setSimVarKind, BackendDAE.JAC_VAR());
end collectAllJacobianVars;

protected function collectAllSeedVars
Expand Down
36 changes: 7 additions & 29 deletions Compiler/Template/CodegenCppCommon.tpl
Expand Up @@ -220,13 +220,13 @@ template cref1(ComponentRef cr, SimCode simCode ,Text& extraFuncs,Text& extraFun
end cref1;

template representationCref(ComponentRef inCref, SimCode simCode ,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace, Context context, Text &varDecls, Text stateDerVectorName /*=__zDot*/, Boolean useFlatArrayNotation) ::=
cref2simvar(inCref, simCode) |> var as SIMVAR(__) =>
cref2simvar(inCref, simCode) |> var as SIMVAR(varKind=varKind, index=i) =>
match varKind
case STATE(__) then
representationCref1(inCref, var, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, context, useFlatArrayNotation)
case STATE_DER(__) then
representationCref2(inCref, var, simCode, &extraFuncs, &extraFuncsDecl, extraFuncsNamespace, context, stateDerVectorName)
case VARIABLE(__) then
case STATE() then
'__z[<%i%>]'
case STATE_DER() then
'__zDot[<%i%>]'
case VARIABLE() then
match var
case SIMVAR(index=-2) then
// unknown in cref2simvar, e.g. local in a function, iterator or time
Expand All @@ -241,7 +241,7 @@ template representationCref(ComponentRef inCref, SimCode simCode ,Text& extraFun
'_<%crefToCStr(inCref, false)%>'
else
cref(inCref, useFlatArrayNotation)
else
else
match context
case ALGLOOP_CONTEXT(genInitialisation = false) then
let &varDecls += '//_system-><%cref(inCref, useFlatArrayNotation)%>; definition of global variable<%\n%>'
Expand Down Expand Up @@ -319,28 +319,6 @@ template crefToCStr(ComponentRef cr, Boolean useFlatArrayNotation)
else "CREF_NOT_IDENT_OR_QUAL"
end crefToCStr;

template representationCref1(ComponentRef inCref, SimVar var, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Context context, Boolean useFlatArrayNotation)
::=
match var
case SIMVAR(index=i) then
match i
case -1 then
cref2(inCref, useFlatArrayNotation)
else
'__z[<%i%>]'
end representationCref1;

template representationCref2(ComponentRef inCref, SimVar var, SimCode simCode, Text& extraFuncs, Text& extraFuncsDecl, Text extraFuncsNamespace, Context context, Text stateDerVectorName /*=__zDot */)
::=
match var
case(SIMVAR(index=i)) then
match context
case JACOBIAN_CONTEXT() then
'_<%crefToCStr(inCref, false)%>'
else
'<%stateDerVectorName%>[<%i%>]'
end representationCref2;

template representationCrefDerVar(ComponentRef inCref, SimCode simCode ,Text& extraFuncs,Text& extraFuncsDecl,Text extraFuncsNamespace, Context context, Text stateDerVectorName /*=__zDot */) ::=
cref2simvar(inCref, simCode ) |> SIMVAR(__) =>'<%stateDerVectorName%>[<%index%>]'
end representationCrefDerVar;
Expand Down

0 comments on commit a0ee81b

Please sign in to comment.