CppNoddy  0.92
Loading...
Searching...
No Matches
Residual.cpp
Go to the documentation of this file.
1/// \file Residual.cpp
2/// Implementation of the (double/complex) VECTOR residual class. To be
3/// inherited by anything that is to be passed to the Newton object.
4
5#include <Residual.h>
6
7namespace CppNoddy {
8 template <typename _Type>
9 Residual<_Type>::Residual(const unsigned& order) : 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;
16#ifdef TIME
17 // timer
18 T_UPDATER = Timer("Updating of the residual object:");
19#endif
20 }
21
22 template <typename _Type>
23 Residual<_Type>::Residual(const unsigned& order, const unsigned& nstate) : DELTA(1.e-8) {
24 // stet the order of the vector system and initialise the member data
25 ORDER_OF_SYSTEM = order;
30#ifdef TIME
31 // timer
32 T_UPDATER = Timer("Updating of the residual object:");
33#endif
34 }
35
36 template <typename _Type>
38#ifdef TIME
39 std::cout << "\n";
40 T_UPDATER.stop();
41 T_UPDATER.print();
42#endif
43 }
44
45 template <typename _Type>
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 }
58
59 // the templated versions we require are:
60 template class Residual<double>
61 ;
62 template class Residual<std::complex<double> >
63 ;
64
65} // end namespace
A specification of a (double/complex) VECTOR residual class.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
Definition: DenseMatrix.h:25
void set_col(const std::size_t &col, const DenseVector< _Type > &x)
Set a column of the matrix.
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A base class to be inherited by objects that define residuals.
Definition: Residual.h:15
const DenseMatrix< _Type > & jacobian() const
Retrun a handle to the Jacobian of the residual corresponding to the last update state.
Definition: Residual.h:118
virtual ~Residual()
An empty destructor, virtual since we have virtual methods.
Definition: Residual.cpp:37
DenseVector< _Type > FN_AT_LAST_STATE
Residual for the last state vector.
Definition: Residual.h:84
Residual(const unsigned &order)
Constructor for a 'square' residual object that is, N residuals for N unknowns.
Definition: Residual.cpp:9
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
A simple CPU-clock-tick timer for timing metods.
Definition: Timer.h:19
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...

© 2012

R.E. Hewitt