Skip to content

Commit

Permalink
skip Jacobian::get* code if there are no equations
Browse files Browse the repository at this point in the history
This reduces the generated code if symbolic Jacobians are deactivated,
e.g. with Flags.DIS_SYMJAC_FMI20.
  • Loading branch information
rfranke committed Nov 13, 2015
1 parent 3107627 commit f20146e
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -13083,15 +13083,13 @@ case {} then
<<
void <%classname%>Jacobian::calc<%matrixName%>JacobianColumn()
{
throw ModelicaSimulationError(MATH_FUNCTION,"Symbolic jacobians not is activated");
throw ModelicaSimulationError(MATH_FUNCTION, "Symbolic jacobians not is activated");

}

// const matrix_t& <%classname%>Jacobian::get<%matrixName%>Jacobian()
const <%matrixreturntype%>& <%classname%>Jacobian::get<%matrixName%>Jacobian()
{
throw ModelicaSimulationError(MATH_FUNCTION,"Symbolic jacobians not is activated");

throw ModelicaSimulationError(MATH_FUNCTION, "Symbolic jacobians not is activated");
}
>>
case _ then
Expand All @@ -13100,34 +13098,41 @@ case _ then
<<
void <%classname%>Jacobian::calc<%matrixName%>JacobianColumn()
{
throw ModelicaSimulationError(MATH_FUNCTION,"Symbolic jacobians not is activated");
throw ModelicaSimulationError(MATH_FUNCTION, "Symbolic jacobians not is activated");
}
//const matrix_t& <%classname%>Jacobian::get<%matrixName%>Jacobian()

const <%matrixreturntype%>& <%classname%>Jacobian::get<%matrixName%>Jacobian()
{
throw ModelicaSimulationError(MATH_FUNCTION,"Symbolic jacobians not is activated");
throw ModelicaSimulationError(MATH_FUNCTION, "Symbolic jacobians not is activated");
}
>>
case _ then
case _ then
let jacMats = (jacobianColumn |> (eqs,vars,indxColumn) =>
functionJac(eqs, vars, indxColumn, matrixName, indexJacobian,simCode , &extraFuncs , &extraFuncsDecl, extraFuncsNamespace, stateDerVectorName, useFlatArrayNotation)
;separator="\n")
let indexColumn = (jacobianColumn |> (eqs,vars,indxColumn) =>
indxColumn
;separator="\n")
let jacvals = ( sparsepattern |> (index,indexes) hasindex index0 =>
let jaccol = ( indexes |> i_index hasindex index1 =>
let eqsCount = (jacobianColumn |> (eqs,vars,indxColumn) =>
listLength(eqs)
;separator="+")
let jacvals = if stringEq(eqsCount, "0") then '' else
(sparsepattern |> (index,indexes) hasindex index0 =>
let jaccol = ( indexes |> i_index hasindex index1 =>
(match indexColumn case "1" then '_<%matrixName%>jacobian(0,<%index%>) = _<%matrixName%>jac_y(0);/*test1<%index0%>,<%index1%>*/'
else '_<%matrixName%>jacobian(<%i_index%>,<%index%>) = _<%matrixName%>jac_y(<%i_index%>);/*test2<%index0%>,<%index1%>*/'
)
;separator="\n" )
'_<%matrixName%>jac_x(<%index0%>) = 1;
calc<%matrixName%>JacobianColumn();
_<%matrixName%>jac_x.clear();
<%jaccol%>'
;separator="\n")
;separator="\n")
<<
_<%matrixName%>jac_x(<%index0%>) = 1;
calc<%matrixName%>JacobianColumn();
_<%matrixName%>jac_x.clear();
<%jaccol%>
>>
;separator="\n")
<<
<%jacMats%>

const <%matrixreturntype%>& <%classname%>Jacobian::get<%matrixName%>Jacobian()
{
/*Index <%indexJacobian%>*/
Expand Down

0 comments on commit f20146e

Please sign in to comment.