MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::QFunctionAutoDiff< TFunctor, state_size, param_size > Class Template Reference

#include <admfem.hpp>

Public Types

typedef codi::RealForwardGen< real_tADFType
 
typedef TAutoDiffVector< ADFTypeADFVector
 
typedef TAutoDiffDenseMatrix< ADFTypeADFDenseMatrix
 
typedef codi::RealForwardGen< ADFTypeADSType
 
typedef TAutoDiffVector< ADSTypeADSVector
 
typedef TAutoDiffDenseMatrix< ADSTypeADSDenseMatrix
 
typedef codi::RealForwardGen< real_tADFType
 
typedef TAutoDiffVector< ADFTypeADFVector
 
typedef TAutoDiffDenseMatrix< ADFTypeADFDenseMatrix
 
typedef codi::RealReverseGen< ADFTypeADSType
 
typedef TAutoDiffVector< ADSTypeADSVector
 
typedef TAutoDiffDenseMatrix< ADSTypeADSDenseMatrix
 

Public Member Functions

real_t Eval (const mfem::Vector &vparam, mfem::Vector &uu)
 
void VectorFunc (const mfem::Vector &vparam, mfem::Vector &uu, mfem::Vector &rr)
 Provides the same functionality as Grad.
 
void Grad (const mfem::Vector &vparam, mfem::Vector &uu, mfem::Vector &rr)
 
void Jacobian (mfem::Vector &vparam, mfem::Vector &uu, mfem::DenseMatrix &jac)
 Provides same functionality as Hessian.
 
void Hessian (mfem::Vector &vparam, mfem::Vector &uu, mfem::DenseMatrix &jac)
 
real_t Eval (const Vector &vparam, Vector &uu)
 
void VectorFunc (const Vector &vparam, Vector &uu, Vector &rr)
 Provides the same functionality as Grad.
 
void Grad (const Vector &vparam, Vector &uu, Vector &rr)
 
void Jacobian (mfem::Vector &vparam, mfem::Vector &uu, mfem::DenseMatrix &jac)
 Provides same functionality as Hessian.
 
void Hessian (mfem::Vector &vparam, mfem::Vector &uu, mfem::DenseMatrix &jac)
 

Detailed Description

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
class mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >

The class provides an evaluation of the first derivatives and the Hessian of a templated scalar function provided as a functor TFunctor. Both the first and the second derivatives are evaluated with the help of automatic differentiation (AD). The template parameters specify the size of the input vector (state_size) and the size of the parameters supplied to the function. The TFunctor functor is a template class with parameters [Float data type], [Vector type for the additional parameters], [Vector type for the state vector and the return residual]. The integer template parameters are the same ones passed to QFunctionAutoDiff.

The class provides an evaluation of the first derivatives and the Hessian of a templated scalar function provided as a functor TFunctor. Both the first and the second derivatives are evaluated with the help of automatic differentiation (AD). The template parameters specify the size of the input vector (state_size) and the size of the parameters supplied to the function. The TFunctor functor is a template class with parameters [Float data type], [Vector type for the additional parameters], [Vector type for the state vector and the return residual]. The integer template parameters are the same ones passed to QFunctionAutoDiff. The class duplicates Grad and Hessian, i.e., VectorFunc calls Grad, and Jacobian calls Hessian. The main reason is to provide the same interface as the QVectorFuncAutoDiff class used to differentiate vector functions. Such compatibility allows users to start implementation of their problem based only on some energy or a weak form. The gradients, computed with Grad/VectorFunc, of the function will contribute to the FE residual. Computed with Hessian/Jacobian, the Hessian will contribute to the tangent matrix in Newton's iterations. Once the implementation is complete and tested, the users can start improving the performance by replacing Grad/VectorFunc with a hand-coded version. The gradient is a vector function and can be differentiated with the functionality implemented in QVectorFuncAutoDiff. Thus, the user can directly employ AD for computing the contributions to the global tangent matrix. The main code will not require changes as the names Grad/VectorFunc and Hessian/Jacobian are mirrored.

Definition at line 616 of file admfem.hpp.

Member Typedef Documentation

◆ ADFDenseMatrix [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffDenseMatrix<ADFType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADFDenseMatrix

Definition at line 325 of file admfem.hpp.

◆ ADFDenseMatrix [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffDenseMatrix<ADFType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADFDenseMatrix

Definition at line 334 of file admfem.hpp.

◆ ADFType [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef codi::RealForwardGen<real_t> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADFType

Definition at line 323 of file admfem.hpp.

◆ ADFType [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef codi::RealForwardGen<real_t> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADFType

Definition at line 332 of file admfem.hpp.

◆ ADFVector [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffVector<ADFType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADFVector

Definition at line 324 of file admfem.hpp.

◆ ADFVector [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffVector<ADFType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADFVector

Definition at line 333 of file admfem.hpp.

◆ ADSDenseMatrix [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffDenseMatrix<ADSType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADSDenseMatrix

Definition at line 329 of file admfem.hpp.

◆ ADSDenseMatrix [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffDenseMatrix<ADSType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADSDenseMatrix

Definition at line 338 of file admfem.hpp.

◆ ADSType [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef codi::RealForwardGen<ADFType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADSType

Definition at line 327 of file admfem.hpp.

◆ ADSType [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef codi::RealReverseGen<ADFType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADSType

Definition at line 336 of file admfem.hpp.

◆ ADSVector [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffVector<ADSType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADSVector

Definition at line 328 of file admfem.hpp.

◆ ADSVector [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
typedef TAutoDiffVector<ADSType> mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::ADSVector

Definition at line 337 of file admfem.hpp.

Member Function Documentation

◆ Eval() [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
real_t mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Eval ( const mfem::Vector & vparam,
mfem::Vector & uu )
inline

Evaluates a function for arguments vparam and uu. The evaluation is based on the operator() in the user provided functor TFunctor.

Definition at line 248 of file admfem.hpp.

◆ Eval() [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
real_t mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Eval ( const Vector & vparam,
Vector & uu )
inline

Evaluates a function for arguments vparam and uu. The evaluation is based on the operator() in the user provided functor TFunctor.

Definition at line 635 of file admfem.hpp.

◆ Grad() [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Grad ( const mfem::Vector & vparam,
mfem::Vector & uu,
mfem::Vector & rr )
inline

Returns the first derivative of TFunctor(...) with respect to the active arguments proved in vector uu. The length of rr is the same as for uu.

Definition at line 261 of file admfem.hpp.

◆ Grad() [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Grad ( const Vector & vparam,
Vector & uu,
Vector & rr )
inline

Returns the first derivative of TFunctor(...) with respect to the active arguments proved in vector uu. The length of rr is the same as for uu.

Definition at line 648 of file admfem.hpp.

◆ Hessian() [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Hessian ( mfem::Vector & vparam,
mfem::Vector & uu,
mfem::DenseMatrix & jac )
inline

Returns the Hessian of TFunctor(...) in the dense matrix jac. The dimensions of jac are state_size x state_size, where state_size is the length of vector uu.

Definition at line 345 of file admfem.hpp.

◆ Hessian() [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Hessian ( mfem::Vector & vparam,
mfem::Vector & uu,
mfem::DenseMatrix & jac )
inline

Returns the Hessian of TFunctor(...) in the dense matrix jac. The dimensions of jac are state_size x state_size, where state_size is the length of vector uu.

Definition at line 672 of file admfem.hpp.

◆ Jacobian() [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Jacobian ( mfem::Vector & vparam,
mfem::Vector & uu,
mfem::DenseMatrix & jac )
inline

Provides same functionality as Hessian.

Definition at line 316 of file admfem.hpp.

◆ Jacobian() [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::Jacobian ( mfem::Vector & vparam,
mfem::Vector & uu,
mfem::DenseMatrix & jac )
inline

Provides same functionality as Hessian.

Definition at line 664 of file admfem.hpp.

◆ VectorFunc() [1/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::VectorFunc ( const mfem::Vector & vparam,
mfem::Vector & uu,
mfem::Vector & rr )
inline

Provides the same functionality as Grad.

Definition at line 254 of file admfem.hpp.

◆ VectorFunc() [2/2]

template<template< typename, typename, typename, int, int > class TFunctor, int state_size = 1, int param_size = 0>
void mfem::QFunctionAutoDiff< TFunctor, state_size, param_size >::VectorFunc ( const Vector & vparam,
Vector & uu,
Vector & rr )
inline

Provides the same functionality as Grad.

Definition at line 641 of file admfem.hpp.


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