CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
codi::VectorAccessInterface< T_Real, T_Identifier > Struct Template Referenceabstract

Unified access to the adjoint vector and primal vector in a tape evaluation. More...

#include <vectorAccessInterface.hpp>

Inheritance diagram for codi::VectorAccessInterface< T_Real, T_Identifier >:

Public Types

using Identifier = CODI_DD(T_Identifier, int)
 See VectorAccessInterface.
 
using Real = CODI_DD(T_Real, double)
 See VectorAccessInterface.
 

Public Member Functions

virtual ~VectorAccessInterface ()
 Destructor.
 
Misc
virtual size_t getVectorSize () const =0
 Vector size in the current tape evaluation.
 
virtual bool isLhsZero ()=0
 True if the adjoint set with setLhsAdjoint is zero.
 
virtual VectorAccessInterfaceclone () const =0
 
Indirect adjoint access
virtual void setLhsAdjoint (Identifier const &index)=0
 
virtual void updateAdjointWithLhs (Identifier const &index, Real const &jacobian)=0
 
Indirect tangent access
virtual void setLhsTangent (Identifier const &index)=0
 
virtual void updateTangentWithLhs (Identifier const &index, Real const &jacobian)=0
 
Direct adjoint access
virtual void resetAdjoint (Identifier const &index, size_t dim)=0
 Set the adjoint component to zero.
 
virtual void resetAdjointVec (Identifier const &index)=0
 Set the adjoint entry to zero.
 
virtual Real getAdjoint (Identifier const &index, size_t dim)=0
 Get the adjoint component.
 
virtual void getAdjointVec (Identifier const &index, Real *const vec)=0
 Get the adjoint entry.
 
virtual Real const * getAdjointVec (Identifier const &index)=0
 Get the adjoint entry.
 
virtual void updateAdjoint (Identifier const &index, size_t dim, Real const &adjoint)=0
 Update the adjoint component.
 
virtual void updateAdjointVec (Identifier const &index, Real const *const vec)=0
 Update the adjoint entry.
 
Primal access
virtual void setPrimal (Identifier const &index, Real const &primal)=0
 Set the primal value.
 
virtual Real getPrimal (Identifier const &index)=0
 Get the primal value.
 
virtual bool hasPrimals ()=0
 True if the tape/vector interface has primal values.
 

Detailed Description

template<typename T_Real, typename T_Identifier>
struct codi::VectorAccessInterface< T_Real, T_Identifier >

Unified access to the adjoint vector and primal vector in a tape evaluation.

The interface abstracts the vector access such that custom vectors modes ( Example 11 - External function user data) can be handled in a generalized way for external functions. All definitions in this interface are based on the primal evaluation type of the tape. This means that also all vector definitions need to be evaluated with this type.

In general, this interface allows to evaluate the forward and reverse AD equations. All mathematical symbols in this documentation refer to the linked equations.

All identifiers in this interface are tape identifiers and can be obtained with codi::ActiveType::getIdentifier.

The interface provides different access types for the user which can be separated into five categories (all functions listed in their typical order of use):

  • Indirect adjoint access:
  • Indirect tangent access:
  • Direct adjoint vector access: The arrays need to have the size of getVectorSize()
  • Direct adjoint component access:
    • Same as the 'direct adjoint vector access' but all functions just work on one component.
    • Same function without the 'Vec' suffix.
  • Primal access: (Optional)
    • Only available if 'hasPrimals()' is true
    • setPrimal(): Set the primal value
    • getPrimal(): Get the primal value
    • This access is required for primal values tapes, which need to update or revert primal values during the tape evaluation.
Template Parameters
T_RealThe computation type of a tape, usually chosen as ActiveType::Real.
T_IdentifierThe adjoint/tangent identification of a tape, usually chosen as ActiveType::Identifier.

Member Function Documentation

◆ clone()

template<typename T_Real , typename T_Identifier >
virtual VectorAccessInterface * codi::VectorAccessInterface< T_Real, T_Identifier >::clone ( ) const
pure virtual

Obtain a heap-allocated copy of the vector access inter- face. The user is responsible for deleting the pointer.

Implemented in codi::AdjointVectorAccess< T_Real, T_Identifier, T_Gradient >, codi::AdjointVectorAccess< Real, Identifier, Gradient >, and codi::PrimalAdjointVectorAccess< T_Real, T_Identifier, T_Gradient >.

◆ getVectorSize()

template<typename T_Real , typename T_Identifier >
virtual size_t codi::VectorAccessInterface< T_Real, T_Identifier >::getVectorSize ( ) const
pure virtual

◆ hasPrimals()

template<typename T_Real , typename T_Identifier >
virtual bool codi::VectorAccessInterface< T_Real, T_Identifier >::hasPrimals ( )
pure virtual

◆ isLhsZero()

template<typename T_Real , typename T_Identifier >
virtual bool codi::VectorAccessInterface< T_Real, T_Identifier >::isLhsZero ( )
pure virtual

◆ setLhsAdjoint()

template<typename T_Real , typename T_Identifier >
virtual void codi::VectorAccessInterface< T_Real, T_Identifier >::setLhsAdjoint ( Identifier const &  index)
pure virtual

Identify the lhs variable $ w $. Create an internal copy of $ \bar w $ and set $ \bar w $ to zero.

◆ setLhsTangent()

template<typename T_Real , typename T_Identifier >
virtual void codi::VectorAccessInterface< T_Real, T_Identifier >::setLhsTangent ( Identifier const &  index)
pure virtual

Perform $ \dot w = \text{internalMem} $. Internal memory is reset afterwards.

◆ updateAdjointWithLhs()

template<typename T_Real , typename T_Identifier >
virtual void codi::VectorAccessInterface< T_Real, T_Identifier >::updateAdjointWithLhs ( Identifier const &  index,
Real const &  jacobian 
)
pure virtual

Perform $ \bar u_{\text{index}} \aeq
                  \text{jacobian} * \bar w $

◆ updateTangentWithLhs()

template<typename T_Real , typename T_Identifier >
virtual void codi::VectorAccessInterface< T_Real, T_Identifier >::updateTangentWithLhs ( Identifier const &  index,
Real const &  jacobian 
)
pure virtual

Perform $ \text{internalMem} \aeq jacobian *
                 < \dot
                  u_{\text{index}} $.


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