CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
CppAD::cg::DummyDerivatives< Base > Class Template Reference
Inheritance diagram for CppAD::cg::DummyDerivatives< Base >:
Inheritance graph
Collaboration diagram for CppAD::cg::DummyDerivatives< Base >:
Collaboration graph

Public Member Functions

 DummyDerivatives (DaeStructuralIndexReduction< Base > &idxIdentify, const std::vector< Base > &x, const std::vector< Base > &normVar, const std::vector< Base > &normEq)
 
bool isAvoidConvertAlg2DifVars () const
 
void setAvoidConvertAlg2DifVars (bool avoid)
 
bool isGenerateSemiExplicitDae () const
 
void setGenerateSemiExplicitDae (bool generateSemiExplicitDae)
 
bool isReduceEquations () const
 
void setReduceEquations (bool reduceEquations)
 
bool isReorder () const
 
void setReorder (bool reorder)
 
void setAvoidVarsAsDummies (const std::set< std::string > &avoidAsDummy)
 
const std::set< std::string > & getAvoidVarsAsDummies () const
 
std::unique_ptr< ADFun< CG< Base > > > reduceIndex (std::vector< DaeVarInfo > &newVarInfo, std::vector< DaeEquationInfo > &newEqInfo) override
 
ADFun< CG< Base > > & getOriginalModel () const
 
std::ostream & log () const
 
void setLog (std::ostream &out)
 
void setVerbosity (Verbosity verbosity)
 
Verbosity getVerbosity () const
 

Protected Member Functions

virtual void addDummyDerivatives (const std::vector< DaeVarInfo > &varInfo, const std::vector< DaeEquationInfo > &eqInfo, std::vector< DaeVarInfo > &newVarInfo)
 
std::unique_ptr< ADFun< CGBase > > reduceEquations (const std::vector< DaeVarInfo > &reducedVarInfo, std::vector< DaeVarInfo > &newVarInfo, const std::vector< DaeEquationInfo > &reducedEqInfo, std::vector< DaeEquationInfo > &newEqInfo)
 
std::unique_ptr< ADFun< CGBase > > generateSemiExplicitDAE (ADFun< CG< Base > > &fun, const std::vector< DaeVarInfo > &varInfo, std::vector< DaeVarInfo > &newVarInfo, const std::vector< DaeEquationInfo > &eqInfo, std::vector< DaeEquationInfo > &newEqInfo)
 
void matchVars2Eqs4Elimination (std::vector< DaeVarInfo > &varInfo, std::vector< DaeEquationInfo > &eqInfo)
 
bool assignVar2Equation (Enode< Base > &i, std::vector< CGBase > &res0, Vnode< Base > &j, std::vector< CGBase > &indep0, CodeHandler< Base > &handler, std::vector< bool > &jacSparsity, const std::map< size_t, Vnode< Base > *> &tape2FreeVariables, std::vector< Enode< Base > *> &equations, std::vector< DaeVarInfo > &varInfo)
 
std::unique_ptr< ADFun< CGBase > > reorderModelEqNVars (ADFun< CG< Base > > &fun, const std::vector< DaeVarInfo > &varInfo, std::vector< DaeVarInfo > &newVarInfo, const std::vector< DaeEquationInfo > &eqInfo, std::vector< DaeEquationInfo > &newEqInfo)
 
ADFun< CGBase > * generateReorderedModel (CodeHandler< Base > &handler, const std::vector< CGBase > &res0, const std::vector< DaeVarInfo > &varInfo, const std::vector< DaeVarInfo > &newVarInfo, const std::vector< DaeEquationInfo > &eqInfo, const std::vector< DaeEquationInfo > &newEqInfo) const
 
void determineJacobian ()
 
void selectDummyDerivatives (const std::vector< Enode< Base > * > &eqs, const std::vector< Vnode< Base > * > &vars, MatrixB &work)
 

Static Protected Member Functions

static void printModel (std::ostream &out, CodeHandler< Base > &handler, const std::vector< CGBase > &res, const std::vector< DaeVarInfo > &varInfo, const std::set< size_t > &erasedVariables, const std::set< size_t > &erasedEquations)
 
static void printGraphSparsity (std::ostream &out, const std::vector< bool > &jacSparsity, const std::map< size_t, Vnode< Base > *> &tape2FreeVariables, const std::vector< Enode< Base > *> &equations, const size_t n)
 
template<class T >
static void deleteVectorValues (std::vector< T *> &v)
 

Protected Attributes

DaeStructuralIndexReduction< Base > *const idxIdentify_
 
std::vector< Base > x_
 
std::vector< Base > normVar_
 
std::vector< Base > normEq_
 
std::unique_ptr< ADFun< CGBase > > reducedFun_
 
std::vector< bool > jacSparsity_
 
size_t diffVarStart_
 
size_t diffEqStart_
 
Eigen::SparseMatrix< Base, Eigen::RowMajor > jacobian_
 
std::vector< Vnode< Base > * > dummyD_
 
bool reduceEquations_
 
bool generateSemiExplicitDae_
 
bool reorder_
 
bool avoidConvertAlg2DifVars_
 
std::set< std::string > avoidAsDummy_
 
ADFun< CG< Base > > *const fun_
 
Verbosity verbosity_
 
std::ostream * log_
 

Detailed Description

template<class Base>
class CppAD::cg::DummyDerivatives< Base >

Dummy derivatives DAE index reduction algorithm

Definition at line 34 of file dummy_deriv.hpp.

Constructor & Destructor Documentation

◆ DummyDerivatives()

template<class Base >
CppAD::cg::DummyDerivatives< Base >::DummyDerivatives ( DaeStructuralIndexReduction< Base > &  idxIdentify,
const std::vector< Base > &  x,
const std::vector< Base > &  normVar,
const std::vector< Base > &  normEq 
)
inline

Creates the DAE index reduction algorithm that implements the dummy derivatives method.

Parameters
idxIdentifyA structural index reduction method that identifies which variables and equations need to be differentiated
xtypical variable values (used to determine Jacobian values)
normVarvariable normalization values
normEqequation normalization values

Definition at line 114 of file dummy_deriv.hpp.

Member Function Documentation

◆ addDummyDerivatives()

template<class Base >
virtual void CppAD::cg::DummyDerivatives< Base >::addDummyDerivatives ( const std::vector< DaeVarInfo > &  varInfo,
const std::vector< DaeEquationInfo > &  eqInfo,
std::vector< DaeVarInfo > &  newVarInfo 
)
inlineprotectedvirtual

Consider all of the current equations that are differentiated versions of the original ones. Collect their predecessors and let them be the current equations.

Consider all current unknowns that are at least of order one. Collect their predecessors of one order less and let them be the current candidates for elimination.

Prepare the output information

Definition at line 299 of file dummy_deriv.hpp.

◆ assignVar2Equation()

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::assignVar2Equation ( Enode< Base > &  i,
std::vector< CGBase > &  res0,
Vnode< Base > &  j,
std::vector< CGBase > &  indep0,
CodeHandler< Base > &  handler,
std::vector< bool > &  jacSparsity,
const std::map< size_t, Vnode< Base > *> &  tape2FreeVariables,
std::vector< Enode< Base > *> &  equations,
std::vector< DaeVarInfo > &  varInfo 
)
inlineprotected

Implement the assignment in the model

Update the connections to the other equations affected by the substitution

Redetermine solvability for the affected equations

Implement changes in graph

Finalize model

Implement the assignment in the graph

Definition at line 961 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::matchVars2Eqs4Elimination().

◆ determineJacobian()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::determineJacobian ( )
inlineprotected

Determines the Jacobian relative to the differential variables (e.g. dxdt)

Definition at line 1312 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::addDummyDerivatives().

◆ generateReorderedModel()

template<class Base >
ADFun<CGBase>* CppAD::cg::DummyDerivatives< Base >::generateReorderedModel ( CodeHandler< Base > &  handler,
const std::vector< CGBase > &  res0,
const std::vector< DaeVarInfo > &  varInfo,
const std::vector< DaeVarInfo > &  newVarInfo,
const std::vector< DaeEquationInfo > &  eqInfo,
const std::vector< DaeEquationInfo > &  newEqInfo 
) const
inlineprotected

the model must be called with the handler order

removed variables using substitution are taken out from the list of independent variables in the handler

Definition at line 1242 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::reorderModelEqNVars().

◆ generateSemiExplicitDAE()

template<class Base >
std::unique_ptr<ADFun<CGBase> > CppAD::cg::DummyDerivatives< Base >::generateSemiExplicitDAE ( ADFun< CG< Base > > &  fun,
const std::vector< DaeVarInfo > &  varInfo,
std::vector< DaeVarInfo > &  newVarInfo,
const std::vector< DaeEquationInfo > &  eqInfo,
std::vector< DaeEquationInfo > &  newEqInfo 
)
inlineprotected

Attempts to generate a semi-explicit DAE.

Parameters
reorderplace all the differential equations and variables together
differentialEqs
Returns
The new semi-explicit DAE model with less variables (without the time derivative variables)
Exceptions
CGExceptionon failure

Generate an operation graph

Eliminate time derivatives from equations

Determine which equation to keep as differential

determine the variable indexes after the elimination of the time derivatives

Prepare the output information

Implement the reordering and derivative variable elimination in the model

Definition at line 610 of file dummy_deriv.hpp.

◆ getAvoidVarsAsDummies()

template<class Base >
const std::set<std::string>& CppAD::cg::DummyDerivatives< Base >::getAvoidVarsAsDummies ( ) const
inline

Which variables should not be selected as dummy derivatives (algebraic variables). These variables can still be selected as dummy derivatives when there is no other option.

Definition at line 235 of file dummy_deriv.hpp.

◆ getOriginalModel()

template<class Base >
ADFun<CG<Base> >& CppAD::cg::DaeIndexReduction< Base >::getOriginalModel ( ) const
inlineinherited

Provides the original model with a representation of an implicit DAE (potentially high index).

Definition at line 55 of file dae_index_reduction.hpp.

◆ isAvoidConvertAlg2DifVars()

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::isAvoidConvertAlg2DifVars ( ) const
inline

Whether or not to avoid converting algebraic variables to differential variables. When algebraic variables should not be converted to differential variables, derivatives for variables which where initially algebraic are selected first as dummy derivatives.

Definition at line 148 of file dummy_deriv.hpp.

◆ isGenerateSemiExplicitDae()

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::isGenerateSemiExplicitDae ( ) const
inline

Whether or not to attempt to generate a semi-explicit DAE by performing algebraic manipulations.

Definition at line 167 of file dummy_deriv.hpp.

◆ isReduceEquations()

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::isReduceEquations ( ) const
inline

Whether or not the total number of equations is to be reduced by performing variable substitutions.

Definition at line 186 of file dummy_deriv.hpp.

◆ isReorder()

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::isReorder ( ) const
inline

Whether or not variables and equations are to be reordered.

Definition at line 201 of file dummy_deriv.hpp.

◆ matchVars2Eqs4Elimination()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::matchVars2Eqs4Elimination ( std::vector< DaeVarInfo > &  varInfo,
std::vector< DaeEquationInfo > &  eqInfo 
)
inlineprotected

Create a new bipartite graph

Match equations to variables (derivatives and dummy derivatives only)

assign variables that can only be solved by a single equation

assign dummy derivatives that can only be solved by a single equation

assign equations that can only be used to solve for a single variable

All variables have at least two equations that can be used and all equations have at least two variables choose a tearing variable/equation

Assign algebraic variables (except dummy derivatives) This is only for information purposes!

save results

Definition at line 725 of file dummy_deriv.hpp.

◆ reduceEquations()

template<class Base >
std::unique_ptr<ADFun<CGBase> > CppAD::cg::DummyDerivatives< Base >::reduceEquations ( const std::vector< DaeVarInfo > &  reducedVarInfo,
std::vector< DaeVarInfo > &  newVarInfo,
const std::vector< DaeEquationInfo > &  reducedEqInfo,
std::vector< DaeEquationInfo > &  newEqInfo 
)
inlineprotected

Attempts to reduce the number of equations by variable substitution.

Parameters
newVarInfoVariable information of the resulting model
Returns
The new DAE reduced model with (possibly) less equations and variables

Generate an operation graph

maps the equations indexes of the reduced model to the new equation indexes in the model with less equations and variables (removed equations have negative indexes)

maps the variables indexes in the tape of the reduced model to the new tape indexes in the model with less equations and variables (removed variables have negative indexes)

attempt to eliminate dummy derivatives and the equation they are assigned to

Determine which equation to use to eliminate the dummy derivative

Prepare the output information

Implement the model after after the reduction of equations and variables by substitution

Definition at line 425 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::setReduceEquations().

◆ reduceIndex()

template<class Base >
std::unique_ptr<ADFun<CG<Base> > > CppAD::cg::DummyDerivatives< Base >::reduceIndex ( std::vector< DaeVarInfo > &  newVarInfo,
std::vector< DaeEquationInfo > &  equationInfo 
)
inlineoverridevirtual

Performs the DAE index reduction and creates a new reduced index model.

Parameters
newVarInfoVariable related information of the reduced index model
equationInfoEquation related information of the reduced index model
Returns
the reduced index model (null if there was no need for index reduction)

Variable information for the reduced

Equation information for the reduced model

Implements CppAD::cg::DaeIndexReduction< Base >.

Definition at line 239 of file dummy_deriv.hpp.

◆ reorderModelEqNVars()

template<class Base >
std::unique_ptr<ADFun<CGBase> > CppAD::cg::DummyDerivatives< Base >::reorderModelEqNVars ( ADFun< CG< Base > > &  fun,
const std::vector< DaeVarInfo > &  varInfo,
std::vector< DaeVarInfo > &  newVarInfo,
const std::vector< DaeEquationInfo > &  eqInfo,
std::vector< DaeEquationInfo > &  newEqInfo 
)
inlineprotected

Determine the variables that have derivatives in the model

sort variables

reorder variables

reorder equations

Generate an operation graph

Implement the reordering in the model

Definition at line 1116 of file dummy_deriv.hpp.

◆ selectDummyDerivatives()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::selectDummyDerivatives ( const std::vector< Enode< Base > * > &  eqs,
const std::vector< Vnode< Base > * > &  vars,
MatrixB &  work 
)
inlineprotected

Determine the columns/variables that must be removed

Definition at line 1382 of file dummy_deriv.hpp.

◆ setAvoidConvertAlg2DifVars()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::setAvoidConvertAlg2DifVars ( bool  avoid)
inline

Defines whether or not to avoid converting algebraic variables to differential variables. When algebraic variables should not be converted to differential variables, derivatives for variables which where initially algebraic are selected first as dummy derivatives

Definition at line 159 of file dummy_deriv.hpp.

◆ setAvoidVarsAsDummies()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::setAvoidVarsAsDummies ( const std::set< std::string > &  avoidAsDummy)
inline

Define a set of variables which should not be selected as dummy derivatives (algebraic variables). These variables can still be selected as dummy derivatives when there is no other option.

Parameters
avoidAsDummya set of variable names which should not be selected as dummy derivatives

Definition at line 225 of file dummy_deriv.hpp.

◆ setGenerateSemiExplicitDae()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::setGenerateSemiExplicitDae ( bool  generateSemiExplicitDae)
inline

Whether or not to attempt to generate a semi-explicit DAE by performing algebraic manipulations.

Warning
: The algebraic manipulations may fail to solve equations relative to the time derivatives.

Definition at line 178 of file dummy_deriv.hpp.

◆ setReduceEquations()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::setReduceEquations ( bool  reduceEquations)
inline

Whether or not to attempt to reduce the total number of equations by performing variable substitutions.

Definition at line 194 of file dummy_deriv.hpp.

◆ setReorder()

template<class Base >
void CppAD::cg::DummyDerivatives< Base >::setReorder ( bool  reorder)
inline

Whether or not to reorder variables and equations. If reordering is enabled, variables will sorted as: {differential vars, algebraic vars, derivative var, integrated var}. Equations are sorted as: {differential equations, algebraic equations}.

Definition at line 212 of file dummy_deriv.hpp.

Member Data Documentation

◆ avoidAsDummy_

template<class Base >
std::set<std::string> CppAD::cg::DummyDerivatives< Base >::avoidAsDummy_
protected

Avoid using these variables as dummy derivatives

Definition at line 100 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::getAvoidVarsAsDummies().

◆ dummyD_

template<class Base >
std::vector<Vnode<Base>*> CppAD::cg::DummyDerivatives< Base >::dummyD_
protected

Dummy derivatives

Definition at line 79 of file dummy_deriv.hpp.

◆ fun_

template<class Base >
ADFun<CG<Base> >* const CppAD::cg::DaeIndexReduction< Base >::fun_
protectedinherited

The original model representing an implicit DAE system

Definition at line 36 of file dae_index_reduction.hpp.

Referenced by CppAD::cg::DaeIndexReduction< Base >::getOriginalModel().

◆ generateSemiExplicitDae_

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::generateSemiExplicitDae_
protected

Attempt to generate a semi-explicit DAE by algebraic manipulations

Definition at line 88 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::isGenerateSemiExplicitDae().

◆ idxIdentify_

template<class Base >
DaeStructuralIndexReduction<Base>* const CppAD::cg::DummyDerivatives< Base >::idxIdentify_
protected

Method used to identify the structural index

Definition at line 44 of file dummy_deriv.hpp.

◆ jacobian_

template<class Base >
Eigen::SparseMatrix<Base, Eigen::RowMajor> CppAD::cg::DummyDerivatives< Base >::jacobian_
protected

Normalized Jacobian of the index one system's differentiated equations relative to the time derivatives (in the new variable order).

Definition at line 75 of file dummy_deriv.hpp.

◆ jacSparsity_

template<class Base >
std::vector<bool> CppAD::cg::DummyDerivatives< Base >::jacSparsity_
protected

Jacobian sparsity pattern of the reduced system (in the original variable order)

Definition at line 65 of file dummy_deriv.hpp.

◆ normEq_

template<class Base >
std::vector<Base> CppAD::cg::DummyDerivatives< Base >::normEq_
protected

normalization constants for the equations

Definition at line 56 of file dummy_deriv.hpp.

◆ normVar_

template<class Base >
std::vector<Base> CppAD::cg::DummyDerivatives< Base >::normVar_
protected

normalization constants for the variables (in the original order)

Definition at line 52 of file dummy_deriv.hpp.

◆ reducedFun_

template<class Base >
std::unique_ptr<ADFun<CGBase> > CppAD::cg::DummyDerivatives< Base >::reducedFun_
protected

new index reduced model

Definition at line 60 of file dummy_deriv.hpp.

◆ reduceEquations_

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::reduceEquations_
protected

Attempt to reduce the total number of equations by performing variable substitutions

Definition at line 84 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::isReduceEquations().

◆ reorder_

template<class Base >
bool CppAD::cg::DummyDerivatives< Base >::reorder_
protected

Reduce the total number of equations through variable substitutions

Definition at line 92 of file dummy_deriv.hpp.

Referenced by CppAD::cg::DummyDerivatives< Base >::isReorder().

◆ x_

template<class Base >
std::vector<Base> CppAD::cg::DummyDerivatives< Base >::x_
protected

typical values used to determine the Jacobian

Definition at line 48 of file dummy_deriv.hpp.


The documentation for this class was generated from the following file: