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

Public Member Functions

 BipartiteGraph (ADFun< CG< Base > > &fun, const std::vector< DaeVarInfo > &varInfo, const std::vector< std::string > &eqName, SimpleLogger &logger)
 
 BipartiteGraph (const BipartiteGraph &p)=delete
 
BipartiteGraphoperator= (const BipartiteGraph &p)=delete
 
std::vector< Vnode< Base > * > & variables ()
 
const std::vector< Vnode< Base > * > & variables () const
 
std::vector< Enode< Base > * > & equations ()
 
const std::vector< Enode< Base > * > & equations () const
 
const std::vector< DaeVarInfo > & getOriginalVariableInfo () const
 
size_t getOrigTimeDependentCount () const
 
void setPreserveNames (bool p)
 
bool isPreserveNames () const
 
size_t getStructuralIndex () const
 
void printResultInfo (const std::string &method)
 
void uncolorAll ()
 
Vnode< Base > * createDerivate (Vnode< Base > &j)
 
Enode< Base > * createDerivate (Enode< Base > &i, bool addOrigVars=true)
 
void remove (const Enode< Base > &i)
 
void dirtyDifferentiateEq (Enode< Base > &i, Enode< Base > &iDiff, bool addOrigVars=true)
 
std::unique_ptr< ADFun< CGBase > > generateNewModel (std::vector< DaeVarInfo > &newVarInfo, std::vector< DaeEquationInfo > &equationInfo, const std::vector< Base > &x)
 
std::vector< CppAD::AD< CG< Base > > > prepareTimeDependentVariables (const std::vector< ADCG > &indepOrig, const std::vector< DaeVarInfo > &newVarInfo, size_t timeTapeIndex) const
 
void printModel (std::ostream &out, ADFun< CG< Base > > *fun)
 
void printModel (std::ostream &out, ADFun< CG< Base > > &fun, const std::vector< DaeVarInfo > &varInfo, const std::vector< DaeEquationInfo > &eqInfo) const
 
void printModel (std::ostream &out, ADFun< CG< Base > > &fun, const std::vector< std::string > &indepNames, const std::vector< std::string > &depNames=std::vector< std::string >()) const
 
void printDot (std::ostream &out) const
 
template<class VectorCGB >
VectorCGB forward0 (ADFun< CGBase > &fun, const VectorCGB &indep0) const
 

Static Public Member Functions

static void forwardTimeDiff (ADFun< CGBase > &reducedFun, const std::vector< Enode< Base > *> &equations, std::vector< CG< Base > > &dep, size_t tapeTimeIndex)
 
static void reverseTimeDiff (ADFun< CGBase > &reducedFun, const std::vector< Enode< Base > *> &equations, std::vector< CG< Base > > &dep, size_t tapeTimeIndex)
 
static std::vector< int > determineVariableDiffOrder (const std::vector< DaeVarInfo > &varInfo)
 
static int determineVariableDiffOrder (const std::vector< DaeVarInfo > &varInfo, size_t index, size_t &j0)
 

Protected Types

using CGBase = CppAD::cg::CG< Base >
 
using ADCG = CppAD::AD< CGBase >
 

Protected Attributes

ADFun< CG< Base > > *const fun_
 
std::vector< DaeVarInfovarInfo_
 
std::vector< bool > sparsity_
 
std::vector< Vnode< Base > * > vnodes_
 
std::vector< Enode< Base > * > enodes_
 
int origMaxTimeDivOrder_
 
size_t origTimeDependentCount_
 
bool preserveNames_
 

Detailed Description

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

Bipartite graph which holds nodes to represent variables and equations in a DAE system.

Definition at line 30 of file bipartite_graph.hpp.

Constructor & Destructor Documentation

◆ BipartiteGraph()

template<class Base>
CppAD::cg::BipartiteGraph< Base >::BipartiteGraph ( ADFun< CG< Base > > &  fun,
const std::vector< DaeVarInfo > &  varInfo,
const std::vector< std::string > &  eqName,
SimpleLogger logger 
)
inline

Creates the bipartite graph.

Parameters
funThe DAE model
varInfoDAE model variable classification
eqNameEquation names (it can be an empty vector)

generate names for the variables

Definition at line 76 of file bipartite_graph.hpp.

Member Function Documentation

◆ dirtyDifferentiateEq()

template<class Base>
void CppAD::cg::BipartiteGraph< Base >::dirtyDifferentiateEq ( Enode< Base > &  i,
Enode< Base > &  iDiff,
bool  addOrigVars = true 
)
inline

Adds edges to a new equation resulting from the differentiation of another assuming the new equation differential contains all variables present in the original equation and their time derivatives (not exactly correct but it works because the potentially extra variables are removed later in the Pantelides method).

An example with incorrectly added variables would be the dirty differentiation of: x1 + x2 == 0 wich include the variables [x1, dx1dt, x2, dx2dt] although it should only be [dx1dt, dx2dt].

Parameters
iequation node to differentiate
Exceptions
CGException

Definition at line 498 of file bipartite_graph.hpp.

◆ generateNewModel()

template<class Base>
std::unique_ptr<ADFun<CGBase> > CppAD::cg::BipartiteGraph< Base >::generateNewModel ( std::vector< DaeVarInfo > &  newVarInfo,
std::vector< DaeEquationInfo > &  equationInfo,
const std::vector< Base > &  x 
)
inline

Creates a new tape for the index 1 model

Add the relationship between variables and derivatives

Prepare the output information

generate a new tape

generate the system of equations by repeatedly differentiating and adding equations to the DAE system

register operations from the other equations

register operations used to differentiate the equations

reconstruct the new system of equations

Definition at line 517 of file bipartite_graph.hpp.

◆ getStructuralIndex()

template<class Base>
size_t CppAD::cg::BipartiteGraph< Base >::getStructuralIndex ( ) const
inline

Provides the structural index after this graph has been reduced.

Returns
the DAE differentiation index.

Definition at line 314 of file bipartite_graph.hpp.

Referenced by CppAD::cg::DaeStructuralIndexReduction< Base >::getStructuralIndex().

◆ isPreserveNames()

template<class Base>
bool CppAD::cg::BipartiteGraph< Base >::isPreserveNames ( ) const
inline

Whether or not original names saved by using CppAD::PrintFor(0, "", val, name) should be kept by also adding PrintFor operations in the reduced model.

Definition at line 305 of file bipartite_graph.hpp.

Referenced by CppAD::cg::DaeStructuralIndexReduction< Base >::isPreserveNames().

◆ prepareTimeDependentVariables()

template<class Base>
std::vector<CppAD::AD<CG<Base> > > CppAD::cg::BipartiteGraph< Base >::prepareTimeDependentVariables ( const std::vector< ADCG > &  indepOrig,
const std::vector< DaeVarInfo > &  newVarInfo,
size_t  timeTapeIndex 
) const
inline

Introduces a dependency with respect to time in the provided variables.

Parameters
indepOrigThe variables without time dependency (in the original variable order).
Returns
The new variables with the time dependency (in the original variable order).

Definition at line 784 of file bipartite_graph.hpp.

Referenced by CppAD::cg::BipartiteGraph< Base >::generateNewModel().

◆ printModel() [1/2]

template<class Base>
void CppAD::cg::BipartiteGraph< Base >::printModel ( std::ostream &  out,
ADFun< CG< Base > > &  fun,
const std::vector< DaeVarInfo > &  varInfo,
const std::vector< DaeEquationInfo > &  eqInfo 
) const
inline

Prints out a DAE model to the standard output.

Parameters
funThe taped model

Definition at line 827 of file bipartite_graph.hpp.

◆ printModel() [2/2]

template<class Base>
void CppAD::cg::BipartiteGraph< Base >::printModel ( std::ostream &  out,
ADFun< CG< Base > > &  fun,
const std::vector< std::string > &  indepNames,
const std::vector< std::string > &  depNames = std::vector<std::string>() 
) const
inline

Prints out a DAE model to the standard output.

Parameters
funThe taped model
indepNamesThe independent variable names
depNamesThe dependent variable names

generate the source code

Definition at line 855 of file bipartite_graph.hpp.

◆ remove()

template<class Base>
void CppAD::cg::BipartiteGraph< Base >::remove ( const Enode< Base > &  i)
inline

Completely removes an equation and any variable that is only referenced by this equation from the graph. The equation cannot have a differentiated version of itself in the graph.

Warning
This equation node cannot be referenced after this call and neither can the variables which are also removed for not being present in any equation.

remove variable

Definition at line 427 of file bipartite_graph.hpp.

◆ setPreserveNames()

template<class Base>
void CppAD::cg::BipartiteGraph< Base >::setPreserveNames ( bool  p)
inline

Defines whether or not original names saved by using CppAD::PrintFor(0, "", val, name) should be kept by also adding PrintFor operations in the reduced model.

Definition at line 296 of file bipartite_graph.hpp.

Referenced by CppAD::cg::DaeStructuralIndexReduction< Base >::setPreserveNames().

Member Data Documentation

◆ fun_

template<class Base>
ADFun<CG<Base> >* const CppAD::cg::BipartiteGraph< Base >::fun_
protected

The original model

Definition at line 38 of file bipartite_graph.hpp.

◆ origMaxTimeDivOrder_

template<class Base>
int CppAD::cg::BipartiteGraph< Base >::origMaxTimeDivOrder_
protected

the maximum order of the time derivatives in the original model

Definition at line 53 of file bipartite_graph.hpp.

Referenced by CppAD::cg::BipartiteGraph< Base >::BipartiteGraph().

◆ origTimeDependentCount_

template<class Base>
size_t CppAD::cg::BipartiteGraph< Base >::origTimeDependentCount_
protected

◆ preserveNames_

template<class Base>
bool CppAD::cg::BipartiteGraph< Base >::preserveNames_
protected

Defines whether or not original names saved by using CppAD::PrintFor(0, "", val, name) should be kept by also adding PrintFor operations in the reduced model.

Definition at line 63 of file bipartite_graph.hpp.

Referenced by CppAD::cg::BipartiteGraph< Base >::isPreserveNames().

◆ sparsity_

template<class Base>
std::vector<bool> CppAD::cg::BipartiteGraph< Base >::sparsity_
protected

original sparsity pattern

Definition at line 46 of file bipartite_graph.hpp.

◆ varInfo_

template<class Base>
std::vector<DaeVarInfo> CppAD::cg::BipartiteGraph< Base >::varInfo_
protected

DAE variable information for the original system

Definition at line 42 of file bipartite_graph.hpp.

Referenced by CppAD::cg::BipartiteGraph< Base >::BipartiteGraph(), and CppAD::cg::BipartiteGraph< Base >::generateNewModel().


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