CppNoddy  0.92
Loading...
Searching...
No Matches
ODE_BVP.h
Go to the documentation of this file.
1/// \file ODE_BVP.h
2/// A specification of a class for an \f$ n^{th} \f$-order ODE BVP defined by
3/// \f[ {\underline f}^\prime (y) = {\underline R}( {\underline f}(y), y )\,, \f]
4/// subject to \f$ n \f$ Dirichlet conditions defined at \f$ y = y_{left} \f$ or
5/// \f$ y_{right} \f$ for some components of \f$ {\underline f}(y) \f$. The system
6/// is solved by applying Newton iteration, with the intermediate problem:
7/// \f[ {\underline g}^\prime (y) - \frac{\partial {\underline R}}{\partial \underline f} \Big \vert_{\underline F} \,\,{\underline g}(y) = {\underline R}( {\underline F}(y), y) - {\underline F}^\prime (y) \,, \f]
8/// for the corrections \f$ \underline g(y) \f$ to the current approximation
9/// to the solution \f$ {\underline F}(y) \f$. The numerical scheme can be
10/// run for any given distribution of nodes and can adapt the nodal
11/// positions based on residual evaluations (including both refinement and unrefinement).
12
13#ifndef ODE_BVP_H
14#define ODE_BVP_H
15
16#include <DenseVector.h>
17#include <DenseMatrix.h>
18#include <Equation_1matrix.h>
19#include <OneD_Node_Mesh.h>
20#include <Uncopyable.h>
21#include <Residual.h>
22#include <Timer.h>
23#include <ArcLength_base.h>
24#include <BandedLinearSystem.h>
25#include <Utility.h>
28
29namespace CppNoddy {
30
31 /// A templated object for real/complex vector system
32 /// of first-order ordinary differential equations. The
33 /// class is double templated, with the first type associated
34 /// with real/complex data, and second (real/complex) type associated with
35 /// a problem on the real line or line in the complex plane.
36 template < typename _Type, typename _Xtype = double >
37 class ODE_BVP : public ArcLength_base<_Type> {
38 public:
39
40 // we want access to the base class init_arc method even though it
41 // is hidden by the derived class' init_arc.
42 using ArcLength_base<_Type>::init_arc;
43
44 /// The class is defined by a vector function for the system.
45 /// \param ptr_to_equation A pointer to an Equation_1matrix object.
46 /// \param nodes A vector that defines the nodal positions.
47 /// \param ptr_to_left_residual A pointer to a residual object that defines the LHS boundary conditions.
48 /// \param ptr_to_right_residual A pointer to a residual object that defines the RHS boundary conditions.
50 const DenseVector<_Xtype> &nodes,
51 Residual<_Type>* ptr_to_left_residual,
52 Residual<_Type>* ptr_to_right_residual);
53
54 /// Destructor
55 virtual ~ODE_BVP();
56
57 /// A virtual method that is called prior to the linear solve
58 /// stage of the solve2() method. This is called prior to any
59 /// linear solve to allow the user to manually tune the matrix
60 /// problem directly.
61 /// \param a The Jacbian matrix to be passed to the linear solver
62 /// \param b The residual vector to be passed to the linear solver
64 {}
65
66 /// Formulate and solve the ODE using Newton iteration and
67 /// a second-order finite difference scheme. The solution is
68 /// stored in the publicly accessible 'solution' member data.
69 void solve2();
70
71 /// Adapt the computational mesh ONCE. We step through each interior
72 /// node and evaluate the residual at that node. If the residual
73 /// is less than the convergence tolerance, the node is removed.
74 /// If the residual is greater than the adapt_tol parameter, then
75 /// the mesh is adapted with an addition node place either side
76 /// of the evaluation node.
77 /// \param adapt_tol The residual tolerance at a nodal point that
78 /// will lead to the mesh adaptation.
79 /// \return A pair of values indicating the number of refinements
80 /// and unrefinements.
81 std::pair< unsigned, unsigned > adapt(const double& adapt_tol);
82
83 /// Adaptively solve the system until no refinements or unrefinements
84 /// are applied.
85 /// \param adapt_tol The residual tolerance at a nodal point that
86 /// will lead to the mesh adaptation.
87 void adapt_until(const double& adapt_tol);
88
89 /// Set the flag that determines if the determinant will be monitored
90 /// The default is to monitor.
91 /// \param flag The boolean value that the flag will be set to
92 void set_monitor_det(bool flag);
93
94 /// Initialise the class ready for arc length continuation. The base
95 /// class requires a vector, so we wrap the base class method here
96 /// so that the vector can be extracted from the mesh member data.
97 /// \param p The pointer to the parameter
98 /// \param length The initial arc length step to be taken (all in the
99 /// parameter.
100 /// \param max_length The maximum arc length step to be allowed.
101 void init_arc(_Type* p, const double& length, const double& max_length);
102
103 /// Arc-length solve the system. Before this can be called the
104 /// arc_init method should have been called in order to ensure
105 /// we know a solution and have derivatives w.r.t. the arc-length
106 /// parameter.
107 double arclength_solve(const double& step);
108
109 /// \return A handle to the solution mesh
111
112 /// Access method to the tolerance
113 /// \return A handle to the private member data TOLERANCE
114 double& tolerance() {
115 return TOL;
116 }
117
118 /// Access method to the maximum number of iterations
119 /// \return A handle to the private member data MAX_ITERATIONS
120 int& max_itns() {
121 return MAX_ITERATIONS;
122 }
123
124 private:
125
126 /// Solve the system for an initial guess by Newton iteration, this
127 /// method is inherited from the ArcLength_base class and this is a
128 /// wrapper that points to the 2nd-order finite-difference solution
129 /// method. Because the arclength base class is for general vector
130 /// systems, we pre/post convert the solution mesh to a vector.
131 /// \param state An initial guess vector, the solution overwrites it.
132 void solve(DenseVector<_Type>& state);
133
134 /// Assemble the Jacobian matrix and residual vector for the
135 /// BVP using the equation object and boundary condition residuals
136 /// for this instance. This routine is separated into a separate
137 /// method because it is used in both the solve2() and the
138 /// arclength_solve() routines.
139 /// \param a The matrix to be filled with the banded Jacobian. It must
140 /// be sized appropriately on entry.
141 /// \param b The vector to be filled with the residuals at each nodal
142 /// point in the mesh.
143 void assemble_matrix_problem(BandedMatrix<_Type>& a, DenseVector<_Type>& b);
144
145 /// The solution mesh
147 /// maximum number of iterations to be taken
148 int MAX_ITERATIONS;
149 /// tolerance for convergence
150 double TOL;
151 /// The sign of the determinant of the Jacobian matrix for the last
152 /// converged solution.
153 int LAST_DET_SIGN;
154 /// The equation object associated with this instance.
156 /// Pointer to the residual defining the LHS BC
157 Residual<_Type > *p_LEFT_RESIDUAL;
158 /// Pointer to the residual defining the RHS BC
159 Residual<_Type > *p_RIGHT_RESIDUAL;
160 /// boolean flag to decide if we should monitor the determinant
161 bool MONITOR_DET;
162
163#ifdef TIME
164 /// Timers for debug use
165 Timer T_ASSEMBLE;
166 Timer T_SOLVE;
167 Timer T_REFINE;
168#endif
169
170 }
171 ; // end class
172
173 template <typename _Type, typename _Xtype>
175 MONITOR_DET = flag;
176 }
177
178 template <typename _Type, typename _Xtype>
180 const double& length,
181 const double& max_length) {
182 DenseVector<_Type> state(SOLUTION.vars_as_vector());
183 this -> init_arc(state, p, length, max_length);
184 }
185
186 template <typename _Type, typename _Xtype>
188 return SOLUTION;
189 }
190
191} // end namespace
192
193#endif
A base class for arclength-capable solvers.
Specification of the linear system class.
Specification of the dense linear eigensystem class.
A matrix class that constructs a DENSE matrix as an STL Vector of DenseVectors.
Specification for a templated DenseVector class – a dense, dynamic, vector object.
A templated class for equations that can be inherited from to allow instantiation of PDE_IBVP objects...
Specification of the linear eigensystem base class.
A specification for a one dimensional mesh object.
A specification of a (double/complex) VECTOR residual class.
A spec for the CppNoddy Timer object.
A spec for a collection of utility functions.
A matrix class that constructs a BANDED matrix.
Definition: BandedMatrix.h:16
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
An equation object base class used in the IBVP classes (and others).
A templated object for real/complex vector system of first-order ordinary differential equations.
Definition: ODE_BVP.h:37
double arclength_solve(const double &step)
Arc-length solve the system.
Definition: ODE_BVP.cpp:164
void adapt_until(const double &adapt_tol)
Adaptively solve the system until no refinements or unrefinements are applied.
Definition: ODE_BVP.cpp:471
void set_monitor_det(bool flag)
Set the flag that determines if the determinant will be monitored The default is to monitor.
Definition: ODE_BVP.h:174
double & tolerance()
Access method to the tolerance.
Definition: ODE_BVP.h:114
virtual void actions_before_linear_solve(BandedMatrix< _Type > &a, DenseVector< _Type > &b)
A virtual method that is called prior to the linear solve stage of the solve2() method.
Definition: ODE_BVP.h:63
virtual ~ODE_BVP()
Destructor.
Definition: ODE_BVP.cpp:69
OneD_Node_Mesh< _Type, _Xtype > & solution()
Definition: ODE_BVP.h:187
int & max_itns()
Access method to the maximum number of iterations.
Definition: ODE_BVP.h:120
std::pair< unsigned, unsigned > adapt(const double &adapt_tol)
Adapt the computational mesh ONCE.
Definition: ODE_BVP.cpp:481
void solve2()
Formulate and solve the ODE using Newton iteration and a second-order finite difference scheme.
Definition: ODE_BVP.cpp:83
void init_arc(_Type *p, const double &length, const double &max_length)
Initialise the class ready for arc length continuation.
Definition: ODE_BVP.h:179
A one dimensional mesh utility object.
A base class to be inherited by objects that define residuals.
Definition: Residual.h:15
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