CppNoddy  0.92
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CppNoddy::Residual< _Type > Class Template Reference

A base class to be inherited by objects that define residuals. More...

#include <Residual.h>

Inheritance diagram for CppNoddy::Residual< _Type >:
CppNoddy::Residual_with_coords< _Type, double > CppNoddy::Residual_with_coords< double > CppNoddy::Residual_with_coords< double, double > CppNoddy::Residual_with_coords< D_complex, double > CppNoddy::Residual_with_coords< _Type, _Xtype > CppNoddy::Residual_with_coords< std::complex< double >, double > CppNoddy::Residual_with_coords< std::complex< double >, _Type > CppNoddy::Example::Harmonic_left_BC< _Type > CppNoddy::Example::Harmonic_right_BC< _Type > CppNoddy::Example::Nonidentity_left_BC< _Type > CppNoddy::Example::Nonidentity_right_BC< _Type > CppNoddy::Example::Troesch_left_BC< _Type > CppNoddy::Example::Troesch_right_BC< _Type > CppNoddy::Residual_with_coords< _Type, _Xtype >

Public Member Functions

 Residual (const unsigned &order)
 Constructor for a 'square' residual object that is, N residuals for N unknowns. More...
 
 Residual (const unsigned &order, const unsigned &nvars)
 Constructor for a 'non-square' residual object that is, there are less residual constraints than unknowns. More...
 
virtual ~Residual ()
 An empty destructor, virtual since we have virtual methods. More...
 
void update (const DenseVector< _Type > &state)
 Update the Residual object for the current set of state variables. More...
 
const DenseVector< _Type > & residual () const
 Return a handle to the residuals corresponding to the last update state. More...
 
const DenseMatrix< _Type > & jacobian () const
 Retrun a handle to the Jacobian of the residual corresponding to the last update state. More...
 
_Type & delta ()
 
const _Type & delta () const
 
unsigned get_order () const
 Get the order of the residual vector. More...
 
unsigned get_number_of_vars () const
 Get the number of variables that this residual condition is defined for. More...
 
virtual void residual_fn (const DenseVector< _Type > &state, DenseVector< _Type > &f) const
 A blank virtual residual function method. More...
 

Protected Member Functions

virtual void jacobian (const DenseVector< _Type > &state, DenseMatrix< _Type > &jac) const
 Because the residual evaluation at the current state is assumed to have already been done by the 'update' method, this routine is protected. More...
 

Protected Attributes

DenseMatrix< _Type > JAC_AT_LAST_STATE
 Jacobian for the last state vector. More...
 
DenseVector< _Type > FN_AT_LAST_STATE
 Residual for the last state vector. More...
 
DenseVector< _Type > LAST_STATE
 The last state vector. More...
 
_Type DELTA
 A default step for FD computation of the Jacobian. More...
 
unsigned ORDER_OF_SYSTEM
 The order of the system of equations. More...
 
unsigned NUMBER_OF_VARS
 The number of elements in the state vector. More...
 

Detailed Description

template<typename _Type>
class CppNoddy::Residual< _Type >

A base class to be inherited by objects that define residuals.

Definition at line 15 of file Residual.h.

Constructor & Destructor Documentation

◆ Residual() [1/2]

template<typename _Type >
CppNoddy::Residual< _Type >::Residual ( const unsigned &  order)

Constructor for a 'square' residual object that is, N residuals for N unknowns.

Parameters
orderThe order of the residual vector

Definition at line 9 of file Residual.cpp.

9 : DELTA(1.e-8) {
10 // set the order of the vector system and initialise the member data
11 ORDER_OF_SYSTEM = order;
12 NUMBER_OF_VARS = order;
13 LAST_STATE = DenseVector<_Type>(NUMBER_OF_VARS, 0.0);
14 FN_AT_LAST_STATE = DenseVector<_Type>(ORDER_OF_SYSTEM, 0.0);
15 JAC_AT_LAST_STATE = DenseMatrix<_Type>(ORDER_OF_SYSTEM, NUMBER_OF_VARS, 0.0);
16#ifdef TIME
17 // timer
18 T_UPDATER = Timer("Updating of the residual object:");
19#endif
20 }
_Type DELTA
A default step for FD computation of the Jacobian.
Definition: Residual.h:88
DenseVector< _Type > FN_AT_LAST_STATE
Residual for the last state vector.
Definition: Residual.h:84
unsigned NUMBER_OF_VARS
The number of elements in the state vector.
Definition: Residual.h:92
DenseVector< _Type > LAST_STATE
The last state vector.
Definition: Residual.h:86
DenseMatrix< _Type > JAC_AT_LAST_STATE
Jacobian for the last state vector.
Definition: Residual.h:82
unsigned ORDER_OF_SYSTEM
The order of the system of equations.
Definition: Residual.h:90

References CppNoddy::Residual< _Type >::FN_AT_LAST_STATE, CppNoddy::Residual< _Type >::JAC_AT_LAST_STATE, CppNoddy::Residual< _Type >::LAST_STATE, CppNoddy::Residual< _Type >::NUMBER_OF_VARS, and CppNoddy::Residual< _Type >::ORDER_OF_SYSTEM.

◆ Residual() [2/2]

template<typename _Type >
CppNoddy::Residual< _Type >::Residual ( const unsigned &  order,
const unsigned &  nvars 
)

Constructor for a 'non-square' residual object that is, there are less residual constraints than unknowns.

Parameters
orderThe number of residuals
nvarsThe number of unknowns/variables

Definition at line 23 of file Residual.cpp.

23 : DELTA(1.e-8) {
24 // stet the order of the vector system and initialise the member data
25 ORDER_OF_SYSTEM = order;
26 NUMBER_OF_VARS = nstate;
27 LAST_STATE = DenseVector<_Type>(NUMBER_OF_VARS, 0.0);
28 FN_AT_LAST_STATE = DenseVector<_Type>(ORDER_OF_SYSTEM, 0.0);
29 JAC_AT_LAST_STATE = DenseMatrix<_Type>(ORDER_OF_SYSTEM, NUMBER_OF_VARS, 0.0);
30#ifdef TIME
31 // timer
32 T_UPDATER = Timer("Updating of the residual object:");
33#endif
34 }

References CppNoddy::Residual< _Type >::ORDER_OF_SYSTEM.

◆ ~Residual()

template<typename _Type >
CppNoddy::Residual< _Type >::~Residual
virtual

An empty destructor, virtual since we have virtual methods.

Definition at line 37 of file Residual.cpp.

37 {
38#ifdef TIME
39 std::cout << "\n";
40 T_UPDATER.stop();
41 T_UPDATER.print();
42#endif
43 }

Member Function Documentation

◆ delta() [1/2]

template<typename _Type >
_Type & CppNoddy::Residual< _Type >::delta
inline
Returns
A handle to the step size used when finite-differencing the residual vector to obtain the Jacobian

Definition at line 133 of file Residual.h.

133 {
134 return DELTA;
135 }

◆ delta() [2/2]

template<typename _Type >
const _Type & CppNoddy::Residual< _Type >::delta
inline
Returns
A handle to the step size used when finite-differencing the residual vector to obtain the Jacobian

Definition at line 138 of file Residual.h.

138 {
139 return DELTA;
140 }

◆ get_number_of_vars()

template<typename _Type >
unsigned CppNoddy::Residual< _Type >::get_number_of_vars
inline

Get the number of variables that this residual condition is defined for.

Returns
The number of variables for the residual

Definition at line 128 of file Residual.h.

128 {
129 return NUMBER_OF_VARS;
130 }

◆ get_order()

template<typename _Type >
unsigned CppNoddy::Residual< _Type >::get_order
inline

Get the order of the residual vector.

Returns
The order/length of the residual vector

Definition at line 123 of file Residual.h.

123 {
124 return ORDER_OF_SYSTEM;
125 }

◆ jacobian() [1/2]

template<typename _Type >
const DenseMatrix< _Type > & CppNoddy::Residual< _Type >::jacobian
inline

Retrun a handle to the Jacobian of the residual corresponding to the last update state.

Definition at line 118 of file Residual.h.

118 {
119 return JAC_AT_LAST_STATE;
120 }

◆ jacobian() [2/2]

template<typename _Type >
void CppNoddy::Residual< _Type >::jacobian ( const DenseVector< _Type > &  state,
DenseMatrix< _Type > &  jac 
) const
protectedvirtual

Because the residual evaluation at the current state is assumed to have already been done by the 'update' method, this routine is protected.

This default uses a finite-differenced Jacobian. You can overload this to provide an analytic Jacobian if you wish

Parameters
stateDummy state vector ... this is only here to make overloading easier, the 'last_x' member data is assumed in the default FD method.
jacThe NxN matrix Jacobian where the equation_fn is a vector function of length N.

Definition at line 46 of file Residual.cpp.

46 {
47 DenseVector<_Type> new_state(state);
48 // evaluation of the function
49 DenseVector<_Type> f_at_new_state(ORDER_OF_SYSTEM, 0.0);
50 // default is to FD the Jacobian
51 for(std::size_t i = 0; i < NUMBER_OF_VARS; ++i) {
52 new_state[ i ] += DELTA;
53 residual_fn(new_state, f_at_new_state);
54 new_state[ i ] -= DELTA;
55 jac.set_col(i, (f_at_new_state - FN_AT_LAST_STATE) / DELTA);
56 }
57 }
virtual void residual_fn(const DenseVector< _Type > &state, DenseVector< _Type > &f) const
A blank virtual residual function method.
Definition: Residual.h:63

References CppNoddy::DenseMatrix< _Type >::set_col().

◆ residual()

template<typename _Type >
const DenseVector< _Type > & CppNoddy::Residual< _Type >::residual
inline

Return a handle to the residuals corresponding to the last update state.

Definition at line 113 of file Residual.h.

113 {
114 return FN_AT_LAST_STATE;
115 }

◆ residual_fn()

template<typename _Type >
virtual void CppNoddy::Residual< _Type >::residual_fn ( const DenseVector< _Type > &  state,
DenseVector< _Type > &  f 
) const
inlinevirtual

A blank virtual residual function method.

Parameters
stateThe unknown variable.
fThe residual function f(x).

Reimplemented in CppNoddy::Example::Harmonic_left_BC< _Type >, CppNoddy::Example::Harmonic_right_BC< _Type >, CppNoddy::Example::Nonidentity_left_BC< _Type >, CppNoddy::Example::Nonidentity_right_BC< _Type >, CppNoddy::Example::Troesch_left_BC< _Type >, CppNoddy::Example::Troesch_right_BC< _Type >, CppNoddy::Example::Harmonic_equation< _Type, _Xtype >, CppNoddy::Example::Nonidentity_equation< _Type, _Xtype >, CppNoddy::Example::Troesch_equation< _Type, _Xtype >, CppNoddy::Example::Biharmonic_residual, CppNoddy::Example::Harmonic_left_BC< _Type >, CppNoddy::Example::Harmonic_right_BC< _Type >, CppNoddy::Example::OS_evp_both_BC, CppNoddy::Example::OS_bvp_left_BC, CppNoddy::Example::OS_bvp_right_BC, CppNoddy::Example::OS_evp_both_BC, CppNoddy::Example::OS_bvp_left_BC, CppNoddy::Example::OS_bvp_right_BC, CppNoddy::Example::Cube_root_problem, CppNoddy::Example::Berman_residual, CppNoddy::Example::Blasius_residual, CppNoddy::Example::Berman_left_BC, CppNoddy::Example::Berman_right_BC, CppNoddy::Example::Blasius_left_BC, CppNoddy::Example::Blasius_right_BC, CppNoddy::Example::Karman_left_BC, CppNoddy::Example::Karman_right_BC, CppNoddy::Example::Karman_left_BC, CppNoddy::Example::Karman_right_BC, CppNoddy::Example::Karman_left_BC, CppNoddy::Example::Karman_right_BC, CppNoddy::Example::Karman_left_BC, CppNoddy::Example::Karman_right_BC, CppNoddy::Example::harmonic_both_BC, CppNoddy::Example::Karman_left_BC, CppNoddy::Example::Karman_right_BC, CppNoddy::Example::Arc_problem, CppNoddy::Example::Arc_problem, CppNoddy::Example::FS_residual, CppNoddy::Example::Arc_problem, CppNoddy::Example::Neutral_residual, and CppNoddy::Example::VCube_root_problem.

Definition at line 63 of file Residual.h.

63 {
64 std::string problem;
65 problem = "The Residual::residual_fn method has not been implemented.\n";
66 problem += "You have to implement this method to define the residual.\n";
67 throw ExceptionRuntime(problem);
68 }

◆ update()

template<typename _Type >
void CppNoddy::Residual< _Type >::update ( const DenseVector< _Type > &  state)
inline

Update the Residual object for the current set of state variables.

Parameters
stateThe state at which to set the residual object

Definition at line 100 of file Residual.h.

100 {
101#ifdef TIME
102 T_UPDATER.start();
103#endif
104 LAST_STATE = x;
107#ifdef TIME
108 T_UPDATER.stop();
109#endif
110 }
const DenseMatrix< _Type > & jacobian() const
Retrun a handle to the Jacobian of the residual corresponding to the last update state.
Definition: Residual.h:118

Referenced by CppNoddy::Equation_1matrix< _Type, _Xtype >::update().

Member Data Documentation

◆ DELTA

template<typename _Type >
_Type CppNoddy::Residual< _Type >::DELTA
protected

A default step for FD computation of the Jacobian.

Definition at line 88 of file Residual.h.

◆ FN_AT_LAST_STATE

template<typename _Type >
DenseVector<_Type> CppNoddy::Residual< _Type >::FN_AT_LAST_STATE
protected

Residual for the last state vector.

Definition at line 84 of file Residual.h.

Referenced by CppNoddy::Residual< _Type >::Residual().

◆ JAC_AT_LAST_STATE

template<typename _Type >
DenseMatrix<_Type> CppNoddy::Residual< _Type >::JAC_AT_LAST_STATE
protected

Jacobian for the last state vector.

Definition at line 82 of file Residual.h.

Referenced by CppNoddy::Residual< _Type >::Residual().

◆ LAST_STATE

template<typename _Type >
DenseVector<_Type> CppNoddy::Residual< _Type >::LAST_STATE
protected

The last state vector.

Definition at line 86 of file Residual.h.

Referenced by CppNoddy::Residual< _Type >::Residual().

◆ NUMBER_OF_VARS

template<typename _Type >
unsigned CppNoddy::Residual< _Type >::NUMBER_OF_VARS
protected

The number of elements in the state vector.

Definition at line 92 of file Residual.h.

Referenced by CppNoddy::Residual< _Type >::Residual().

◆ ORDER_OF_SYSTEM

template<typename _Type >
unsigned CppNoddy::Residual< _Type >::ORDER_OF_SYSTEM
protected

The order of the system of equations.

Definition at line 90 of file Residual.h.

Referenced by CppNoddy::Equation_1matrix< _Type, _Xtype >::Equation_1matrix(), and CppNoddy::Residual< _Type >::Residual().


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

© 2012

R.E. Hewitt