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

An equation object base class used in the IBVP classes (and others). More...

#include <Equation_1matrix.h>

Inheritance diagram for CppNoddy::Equation_1matrix< _Type, _Xtype >:
CppNoddy::Residual_with_coords< _Type, _Xtype > CppNoddy::Residual< _Type > CppNoddy::Equation_2matrix< _Type, double > CppNoddy::Equation_2matrix< double > CppNoddy::Equation_2matrix< D_complex > CppNoddy::Equation_2matrix< double, double > CppNoddy::Equation_2matrix< _Type, _Xtype > CppNoddy::Example::Diff_equation CppNoddy::Example::Diffusion_equations CppNoddy::Example::Karman_equations CppNoddy::Example::Nlin_adv_equation CppNoddy::Example::harmonic_equation CppNoddy::Example::OS_evp_equation CppNoddy::Example::OS_evp_equation CppNoddy::Equation_3matrix< double > CppNoddy::Equation_3matrix< _Type, _Xtype >

Public Member Functions

 Equation_1matrix (const unsigned &order)
 Constructor for equation class. More...
 
virtual ~Equation_1matrix ()
 An empty destructor, virtual since we have virtual methods. More...
 
void update (const DenseVector< _Type > &state)
 Update the Equation object for the current set of state variables. More...
 
const DenseMatrix< _Type > & matrix0 () const
 Return a handle to the matrix. More...
 
virtual void get_jacobian_of_matrix0_mult_vector (const DenseVector< _Type > &state, const DenseVector< _Type > &vec, DenseMatrix< _Type > &h) const
 Return the product of the Jacobian-of-the-matrix and a vector 'vec' when the equation has a given 'state'. More...
 
- Public Member Functions inherited from CppNoddy::Residual_with_coords< _Type, _Xtype >
 Residual_with_coords (const unsigned &order, const unsigned &ncoords)
 Constructor for a 'square' residual object that is, N residuals for N unknowns. More...
 
 Residual_with_coords (const unsigned &order, const unsigned &nvars, const unsigned &ncoords)
 Constructor for a 'non-square' residual object that is, there are less residual constraints than unknowns. More...
 
virtual ~Residual_with_coords ()
 An empty destructor. More...
 
_Xtype & coord (const unsigned &i)
 General handle access to the coordinates. More...
 
const _Xtype & coord (const unsigned &i) const
 General handle access to the coordinates. More...
 
- Public Member Functions inherited from CppNoddy::Residual< _Type >
 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 matrix0 (const DenseVector< _Type > &x, DenseMatrix< _Type > &m) const
 Define the matrix in terms of the current state vector. More...
 
- Protected Member Functions inherited from CppNoddy::Residual< _Type >
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...
 

Additional Inherited Members

- Protected Attributes inherited from CppNoddy::Residual_with_coords< _Type, _Xtype >
std::vector< _Xtype > coords
 The coordinates stored for this residual. More...
 
- Protected Attributes inherited from CppNoddy::Residual< _Type >
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, typename _Xtype = double>
class CppNoddy::Equation_1matrix< _Type, _Xtype >

An equation object base class used in the IBVP classes (and others).

An equation object is essentially a ('square') residual object with an independent variable data member and access methods. By 'square' we mean that it defines N residuals and N state variables. The equation is defined using an NxN matrix that multiplies the derivative of unknowns and a residual RHS.

Definition at line 18 of file Equation_1matrix.h.

Constructor & Destructor Documentation

◆ Equation_1matrix()

template<typename _Type , typename _Xtype >
CppNoddy::Equation_1matrix< _Type, _Xtype >::Equation_1matrix ( const unsigned &  order)
explicit

Constructor for equation class.

Parameters
orderThe order of the system

Definition at line 12 of file Equation_1matrix.cpp.

12 :
13 Residual_with_coords<_Type, _Xtype>(order, 1) {
14 MATRIX0_AT_LAST_STATE = DenseMatrix<_Type>(this -> ORDER_OF_SYSTEM, this -> ORDER_OF_SYSTEM, 0.0);
15 }
unsigned ORDER_OF_SYSTEM
The order of the system of equations.
Definition: Residual.h:90

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

◆ ~Equation_1matrix()

template<typename _Type , typename _Xtype >
CppNoddy::Equation_1matrix< _Type, _Xtype >::~Equation_1matrix
virtual

An empty destructor, virtual since we have virtual methods.

Definition at line 18 of file Equation_1matrix.cpp.

18 {
19 // timer reporting is done via the Equation class this inherits from
20 }

Member Function Documentation

◆ get_jacobian_of_matrix0_mult_vector()

template<typename _Type , typename _Xtype >
void CppNoddy::Equation_1matrix< _Type, _Xtype >::get_jacobian_of_matrix0_mult_vector ( const DenseVector< _Type > &  state,
const DenseVector< _Type > &  vec,
DenseMatrix< _Type > &  h 
) const
virtual

Return the product of the Jacobian-of-the-matrix and a vector 'vec' when the equation has a given 'state'.

The user should overload this if concerned about performance of the solver. If not overloaded, the default is to finite difference the Jacobian-of-the-matrix.

Parameters
stateThe current state variables – used for clarity when overloaded by the user instead of expecting the user to access the member data.
vecThe vector that will be multiplied by the Jacobian-of-the-matrix
hThe resulting 2D matrix

Definition at line 23 of file Equation_1matrix.cpp.

23 {
24 // we dont need state in the default implementation as its already been set by the update method. You do need it for the user
25 // to overload this method with an explicit analytical version however.
26 //
27 // copy some items for FD computation of Jacobian of matrix
28 DenseVector<_Type> copy_of_state(this -> LAST_STATE);
29 DenseMatrix<_Type> copy_of_matrix(MATRIX0_AT_LAST_STATE);
30 std::vector< DenseMatrix<_Type> > jacmatrix;
31 // update the Jacobian of the mass matrix
32 for(std::size_t i = 0; i < this -> ORDER_OF_SYSTEM; ++i) {
33 copy_of_state[ i ] += this -> DELTA;
34 matrix0(copy_of_state, copy_of_matrix);
35 copy_of_state[ i ] -= this -> DELTA;
36 copy_of_matrix.sub(MATRIX0_AT_LAST_STATE);
37 copy_of_matrix.scale(1. / this -> DELTA);
38 // the 3D object that represents the Jacobian of the mass matrix
39 jacmatrix.push_back(copy_of_matrix);
40 }
41 // evaluate the jacabian of mass contribution
42 for(unsigned i = 0; i < this -> ORDER_OF_SYSTEM; ++i) {
43 for(unsigned j = 0; j < this -> ORDER_OF_SYSTEM; ++j) {
44 h(i, j) = Utility::dot(jacmatrix[ j ][ i ], vec);
45 }
46 }
47 }
const DenseMatrix< _Type > & matrix0() const
Return a handle to the matrix.
_Type DELTA
A default step for FD computation of the Jacobian.
Definition: Residual.h:88
DenseVector< _Type > LAST_STATE
The last state vector.
Definition: Residual.h:86
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
Definition: Utility.h:314

◆ matrix0() [1/2]

template<typename _Type , typename _Xtype >
const DenseMatrix< _Type > & CppNoddy::Equation_1matrix< _Type, _Xtype >::matrix0
inline

Return a handle to the matrix.

Definition at line 66 of file Equation_1matrix.h.

66 {
67 return MATRIX0_AT_LAST_STATE;
68 }

◆ matrix0() [2/2]

template<typename _Type , typename _Xtype = double>
virtual void CppNoddy::Equation_1matrix< _Type, _Xtype >::matrix0 ( const DenseVector< _Type > &  x,
DenseMatrix< _Type > &  m 
) const
inlineprotectedvirtual

Define the matrix in terms of the current state vector.

Parameters
xThe current state vector.
mThe matrix.

Reimplemented in CppNoddy::Example::Harmonic_equation< _Type, _Xtype >, CppNoddy::Example::Troesch_equation< _Type, _Xtype >, CppNoddy::Example::Nonidentity_equation< _Type, _Xtype >, CppNoddy::Example::Harmonic_equation< _Type, _Xtype >, CppNoddy::Example::OS_bvp_equation, CppNoddy::Example::OS_bvp_equation, CppNoddy::Example::Berman_equation, CppNoddy::Example::Blasius_equation, CppNoddy::Example::Karman_equations, CppNoddy::Example::Karman_equations, CppNoddy::Example::Karman_equations, CppNoddy::Example::Karman_equations, and CppNoddy::Example::Karman_equations.

Definition at line 51 of file Equation_1matrix.h.

51 {
52 std::string problem;
53 problem = "The equation::matrix0 method has not been implemented!\n";
54 problem += "You have to implement this method to define the equation.\n";
55 throw ExceptionRuntime(problem);
56 }

◆ update()

template<typename _Type , typename _Xtype >
void CppNoddy::Equation_1matrix< _Type, _Xtype >::update ( const DenseVector< _Type > &  state)

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

Parameters
stateThe state vector at which to set the equation object

Definition at line 50 of file Equation_1matrix.cpp.

50 {
51 // use the base class update to set LAST_STATE, FN_AT_LAST_STATE and JAC_AT_LAST_STATE
53 // this has TIME ifdef to go after the base class update - otherwise we'll be
54 // resuming the timer twice in a row
55#ifdef TIME
56 this -> T_UPDATER.start();
57#endif
58 // now we deal with the mass matrix separately to set MATRIX0_AT_LAST_STATE
59 // and JAC_OF_MATRIX
60 matrix0(state, MATRIX0_AT_LAST_STATE);
61#ifdef TIME
62 this -> T_UPDATER.stop();
63#endif
64 }
void update(const DenseVector< _Type > &state)
Update the Residual object for the current set of state variables.
Definition: Residual.h:100

References CppNoddy::Residual< _Type >::update().

Referenced by CppNoddy::Equation_2matrix< _Type, double >::Equation_2matrix().


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

© 2012

R.E. Hewitt