KASKADE 7 development version
Public Types | Public Member Functions | List of all members
Kaskade::DerivativeChecker< Functional, checkD1, SparseInt > Class Template Reference

Class that checks the derivatives of a functional at a linearization point. More...

#include <check_derivative.hh>

Detailed Description

template<class Functional, bool checkD1 = true, class SparseInt = int>
class Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >

Class that checks the derivatives of a functional at a linearization point.

The analytic derivatives are compared with a finite difference approximation. Note that this just gives you a hint (but a good one if you don't use stupid parameters for the tolerance and the increment) about the correctness of your analytically calculated derivatives. Keep in mind that it is a heuristic.

Parameters
checkD1enable/disable check of first derivative (i.e. disable it if d0() has not been implemented correctly in boundary or domain cache (optional, default=true(enabled))
SparseIntinteger type used for sparse matrix indices

Definition at line 407 of file check_derivative.hh.

Public Types

enum  { idOfFirstBlock = 0 , idOfLastBlock = boost::mpl::size<typename Functional::AnsatzVars::Variables>::type::value }
 
typedef Functional::Scalar Scalar
 

Public Member Functions

 DerivativeChecker (Assembler &assembler_, Functional const &f_, EvaluationPoint const &x_, VariableSet const &variableSet_, Scalar const tol=1.0e-6, Scalar const incr=1.0e-9)
 Constructor. More...
 
void checkFirstDerivative ()
 Check first derivative. More...
 
void checkSecondDerivative ()
 Check second derivative. More...
 
bool firstDerivativeOk () const
 
bool secondDerivativeOk () const
 
void setTolerance (Scalar const tol)
 Only errors below tolerance will be displayed. More...
 
void setIncrement (Scalar const incr)
 Set increment for finite differences. More...
 
void printD1Error () const
 print error in first derivative (only values below tolerance) More...
 
void printFullD1Error () const
 print error in first derivative More...
 
void printD2Error () const
 print error in second derivative (only values below tolerance) More...
 
void printFullD2Error () const
 print error in second derivative More...
 
void d2ToVTK ()
 write d2 to .vtu file More...
 
void d1ErrorToVTK (int const steps) const
 write error in first derivative to .vtu file More...
 
template<class Vector >
void vectorToVTK (Vector &vector, int const steps=0) const
 write Vector vector to .vtu file More...
 
void d2ErrorToVTK (int const steps) const
 write error in second derivative to .vtu-file More...
 
void matrixToVTK (MatrixAsTriplet< Scalar, SparseInt > const &matrix, int const steps=0) const
 write, possibly sparse, matrix in triplet format to .vtu-file More...
 

Member Typedef Documentation

◆ Scalar

template<class Functional , bool checkD1 = true, class SparseInt = int>
typedef Functional::Scalar Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::Scalar

Definition at line 416 of file check_derivative.hh.

Member Enumeration Documentation

◆ anonymous enum

template<class Functional , bool checkD1 = true, class SparseInt = int>
anonymous enum
Enumerator
idOfFirstBlock 
idOfLastBlock 

Definition at line 417 of file check_derivative.hh.

Constructor & Destructor Documentation

◆ DerivativeChecker()

template<class Functional , bool checkD1 = true, class SparseInt = int>
Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::DerivativeChecker ( Assembler assembler_,
Functional const &  f_,
EvaluationPoint const &  x_,
VariableSet const &  variableSet_,
Scalar const  tol = 1.0e-6,
Scalar const  incr = 1.0e-9 
)
inline

Constructor.

Parameters
functionalinstance of the Functional
x_linearization point
terror tolerance (point-wise, default=1.0e-6)
incrincrement for finite differences (default=1.0e-9)

Definition at line 427 of file check_derivative.hh.

Member Function Documentation

◆ checkFirstDerivative()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::checkFirstDerivative ( )
inline

Check first derivative.

This function is called by the constructor. You only need to call this function if you have changed the tolerance.

Definition at line 440 of file check_derivative.hh.

Referenced by Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::DerivativeChecker().

◆ checkSecondDerivative()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::checkSecondDerivative ( )
inline

Check second derivative.

This function is called by the constructor. You only need to call this function if you have changed the tolerance.

Definition at line 497 of file check_derivative.hh.

Referenced by Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::DerivativeChecker().

◆ d1ErrorToVTK()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::d1ErrorToVTK ( int const  steps) const
inline

write error in first derivative to .vtu file

Definition at line 629 of file check_derivative.hh.

◆ d2ErrorToVTK()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::d2ErrorToVTK ( int const  steps) const
inline

write error in second derivative to .vtu-file

Definition at line 710 of file check_derivative.hh.

◆ d2ToVTK()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::d2ToVTK ( )
inline

write d2 to .vtu file

Definition at line 620 of file check_derivative.hh.

◆ firstDerivativeOk()

template<class Functional , bool checkD1 = true, class SparseInt = int>
bool Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::firstDerivativeOk ( ) const
inline

Definition at line 553 of file check_derivative.hh.

◆ matrixToVTK()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::matrixToVTK ( MatrixAsTriplet< Scalar, SparseInt > const &  matrix,
int const  steps = 0 
) const
inline

write, possibly sparse, matrix in triplet format to .vtu-file

store index pairs

Definition at line 716 of file check_derivative.hh.

Referenced by Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::d2ErrorToVTK(), and Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::d2ToVTK().

◆ printD1Error()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::printD1Error ( ) const
inline

print error in first derivative (only values below tolerance)

Definition at line 591 of file check_derivative.hh.

◆ printD2Error()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::printD2Error ( ) const
inline

print error in second derivative (only values below tolerance)

Definition at line 606 of file check_derivative.hh.

◆ printFullD1Error()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::printFullD1Error ( ) const
inline

print error in first derivative

Definition at line 600 of file check_derivative.hh.

◆ printFullD2Error()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::printFullD2Error ( ) const
inline

print error in second derivative

Definition at line 613 of file check_derivative.hh.

◆ secondDerivativeOk()

template<class Functional , bool checkD1 = true, class SparseInt = int>
bool Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::secondDerivativeOk ( ) const
inline

Definition at line 555 of file check_derivative.hh.

◆ setIncrement()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::setIncrement ( Scalar const  incr)
inline

Set increment for finite differences.

Definition at line 588 of file check_derivative.hh.

◆ setTolerance()

template<class Functional , bool checkD1 = true, class SparseInt = int>
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::setTolerance ( Scalar const  tol)
inline

Only errors below tolerance will be displayed.

Definition at line 585 of file check_derivative.hh.

◆ vectorToVTK()

template<class Functional , bool checkD1 = true, class SparseInt = int>
template<class Vector >
void Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::vectorToVTK ( Vector &  vector,
int const  steps = 0 
) const
inline

write Vector vector to .vtu file

Vector must provide the function size() and operator[](size_type n)

Definition at line 639 of file check_derivative.hh.

Referenced by Kaskade::DerivativeChecker< Functional, checkD1, SparseInt >::d1ErrorToVTK().


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