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

An equation object base class used in the PDE_double_IBVP class. More...

#include <Equation_3matrix.h>

Inheritance diagram for CppNoddy::Equation_3matrix< _Type, _Xtype >:
CppNoddy::Equation_2matrix< _Type, _Xtype > CppNoddy::Equation_1matrix< _Type, _Xtype > CppNoddy::Residual_with_coords< _Type, _Xtype > CppNoddy::Residual< _Type >

Public Member Functions

 Equation_3matrix (const unsigned &order)
 Constructor for equation class. More...
 
virtual ~Equation_3matrix ()
 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 > & matrix2 () const
 Return a handle to the matrix member data. More...
 
virtual void get_jacobian_of_matrix2_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::Equation_2matrix< _Type, _Xtype >
 Equation_2matrix (const unsigned &order)
 Constructor for equation class. More...
 
virtual ~Equation_2matrix ()
 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 > & matrix1 () const
 Return a handle to the matrix member data. More...
 
virtual void get_jacobian_of_matrix1_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::Equation_1matrix< _Type, _Xtype >
 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 matrix2 (const DenseVector< _Type > &state, DenseMatrix< _Type > &m) const
 Define the matrix for the current state vector. More...
 
- Protected Member Functions inherited from CppNoddy::Equation_2matrix< _Type, _Xtype >
virtual void matrix1 (const DenseVector< _Type > &state, DenseMatrix< _Type > &m) const
 Define the matrix in terms of the current state vector. More...
 
- Protected Member Functions inherited from CppNoddy::Equation_1matrix< _Type, _Xtype >
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_3matrix< _Type, _Xtype >

An equation object base class used in the PDE_double_IBVP class.

An equation object is essentially a ('square') residual object (although it doesn't currently inherit) with some independent variable data members and access methods. By 'square' we mean that it defines N residuals and N state variables. In this case the equation also defines 2 matrices (amongst other data). This inherits from the Equation_1matrix and adds the functionality for the additional matrix.

Definition at line 21 of file Equation_3matrix.h.

Constructor & Destructor Documentation

◆ Equation_3matrix()

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

Constructor for equation class.

Parameters
orderThe order of the system

Definition at line 12 of file Equation_3matrix.cpp.

12 :
13 Equation_2matrix<_Type, _Xtype>(order) {
14 // initialise the container for the extra matrix
15 MATRIX2_AT_LAST_STATE = DenseMatrix<_Type>(order, order, 0.0);
16 // add an extra coordinate to the vector stored in the residual_with_coords baseclass
17 Residual_with_coords<_Type,_Xtype>::coords.resize(3, 0.0);
18 }

◆ ~Equation_3matrix()

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

An empty destructor, virtual since we have virtual methods.

Definition at line 21 of file Equation_3matrix.cpp.

21 {
22 // timer reporting is done via the Equation (base) class
23 }

Member Function Documentation

◆ get_jacobian_of_matrix2_mult_vector()

template<typename _Type , typename _Xtype >
void CppNoddy::Equation_3matrix< _Type, _Xtype >::get_jacobian_of_matrix2_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

Reimplemented in CppNoddy::Example::diffusion_double, and CppNoddy::Example::nonlinear.

Definition at line 42 of file Equation_3matrix.cpp.

42 {
43 // we dont need state in the default implementation as its already been set by the update method. You do need it for the user
44 // to overload this method with an explicit analytical version however.
45 //
46 // copy some items for FD computation of Jacobian of mass matrix
47 DenseVector<_Type> copy_of_state(this -> LAST_STATE);
48 DenseMatrix<_Type> copy_of_matrix(MATRIX2_AT_LAST_STATE);
49 std::vector< DenseMatrix<_Type> > jacmatrix;
50 // update the Jacobian of the mass matrix
51 for(std::size_t i = 0; i < this -> ORDER_OF_SYSTEM; ++i) {
52 copy_of_state[ i ] += this -> DELTA;
53 matrix2(copy_of_state, copy_of_matrix);
54 copy_of_state[ i ] -= this -> DELTA;
55 copy_of_matrix.sub(MATRIX2_AT_LAST_STATE);
56 copy_of_matrix.scale(1. / this -> DELTA);
57 // the 3D object that represents the Jacobian of the mass matrix
58 jacmatrix.push_back(copy_of_matrix);
59 }
60 // evaluate the jacabian of mass contribution
61 for(unsigned i = 0; i < this -> ORDER_OF_SYSTEM; ++i) {
62 for(unsigned j = 0; j < this -> ORDER_OF_SYSTEM; ++j) {
63 h(i, j) = Utility::dot(jacmatrix[ j ][ i ], vec);
64 }
65 }
66 }
const DenseMatrix< _Type > & matrix2() const
Return a handle to the matrix member data.
_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
unsigned ORDER_OF_SYSTEM
The order of the system of equations.
Definition: Residual.h:90
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
Definition: Utility.h:314

◆ matrix2() [1/2]

template<typename _Type , typename _Xtype >
const DenseMatrix< _Type > & CppNoddy::Equation_3matrix< _Type, _Xtype >::matrix2
inline

Return a handle to the matrix member data.

Definition at line 69 of file Equation_3matrix.h.

69 {
70 return MATRIX2_AT_LAST_STATE;
71 }

◆ matrix2() [2/2]

template<typename _Type , typename _Xtype = double>
virtual void CppNoddy::Equation_3matrix< _Type, _Xtype >::matrix2 ( const DenseVector< _Type > &  state,
DenseMatrix< _Type > &  m 
) const
inlineprotectedvirtual

Define the matrix for the current state vector.

Parameters
stateThe current state vector.
mThe matrix.

Reimplemented in CppNoddy::Example::diffusion_double, CppNoddy::Example::nonlinear, and CppNoddy::Example::nonlinear.

Definition at line 53 of file Equation_3matrix.h.

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

◆ update()

template<typename _Type , typename _Xtype >
void CppNoddy::Equation_3matrix< _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 26 of file Equation_3matrix.cpp.

26 {
27 // call the base class's update method
29 // this has to go after the base class update - otherwise we'll be
30 // resuming the timer twice in a row
31#ifdef TIME
32 this -> T_UPDATER.start();
33#endif
34 // now deal with the additional matrix separately
35 matrix2(state, MATRIX2_AT_LAST_STATE);
36#ifdef TIME
37 this -> T_UPDATER.stop();
38#endif
39 }
void update(const DenseVector< _Type > &state)
Update the Equation object for the current set of state variables.

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

© 2012

R.E. Hewitt