CppNoddy  0.92
Loading...
Searching...
No Matches
Equation_1matrix.cpp
Go to the documentation of this file.
1/// \file Equation_1matrix.cpp
2/// Implementation for an equations class that can be inherited from
3/// to allow instantiation of ODE objects using the resulting class.
4
5#include <Equation_1matrix.h>
7#include <Utility.h>
8
9namespace CppNoddy {
10
11 template <typename _Type, typename _Xtype>
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 }
16
17 template <typename _Type, typename _Xtype>
19 // timer reporting is done via the Equation class this inherits from
20 }
21
22 template <typename _Type, typename _Xtype>
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 }
48
49 template <typename _Type, typename _Xtype>
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 }
65
66 // the required templated versions are:
67 template class Equation_1matrix<double>
68 ;
70 ;
71 template class Equation_1matrix<std::complex<double>, std::complex<double> >
72 ;
73
74} // end namespace
A templated class for equations that can be inherited from to allow instantiation of PDE_IBVP objects...
A specification of a (double/complex) residual class that not only defines a vector residual of a vec...
A spec for a collection of utility functions.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
Definition: DenseMatrix.h:25
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
An equation object base class used in the IBVP classes (and others).
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 'st...
void update(const DenseVector< _Type > &state)
Update the Equation object for the current set of state variables.
Equation_1matrix(const unsigned &order)
Constructor for equation class.
virtual ~Equation_1matrix()
An empty destructor, virtual since we have virtual methods.
A base class to be inherited by objects that define residuals.
unsigned ORDER_OF_SYSTEM
The order of the system of equations.
Definition: Residual.h:90
void update(const DenseVector< _Type > &state)
Update the Residual object for the current set of state variables.
Definition: Residual.h:100
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
Definition: Utility.h:314
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt