18 template <
typename _Type>
20 const double &x1,
const double &x2,
21 const std::size_t &num_of_points) :
24 H_INIT((x2 - x1) / num_of_points),
28 p_EQUATION -> coord(0) = X_INIT;
31 template <
typename _Type>
35 template <
typename _Type>
39 const double h = H_INIT;
40 const double hby2 =
h / 2.;
41 const double hby6 =
h / 6.;
42 const double hby3 =
h / 3.;
43 const int order =
u.size();
45 DenseVector<_Type> z(order, 0.0), k1(order, 0.0), k2(order, 0.0), k3(order, 0.0), k4(order, 0.0);
48 std::vector< DenseVector<_Type> > values;
53 for(
unsigned i = 0; i < N; i++) {
55 p_EQUATION -> coord(0) = x;
56 p_EQUATION -> residual_fn(
u, k1);
62 p_EQUATION -> coord(0) = x;
63 p_EQUATION -> residual_fn(z, k2);
67 p_EQUATION -> coord(0) = x;
68 p_EQUATION -> residual_fn(z, k3);
74 p_EQUATION -> coord(0) = x;
75 p_EQUATION -> residual_fn(z, k4);
76 u += k1 * hby6 + k2 * hby3 + k3 * hby3 + k4 * hby6;
78 if(i % STORE_EVERY == 0) {
87 for(
unsigned i = 0; i < coords.
size(); ++i) {
89 SOLN.set_nodes_vars(i, values[i]);
94 template <
typename _Type>
102 static const double X2 = 1. / 4.;
103 static const double X3 = 3. / 8.;
104 static const double X4 = 12. / 13.;
105 static const double X5 = 1.;
106 static const double X6 = 1. / 2.;
108 static const double W21 = 1. / 4.;
110 static const double W31 = 3. / 32.;
111 static const double W32 = 9. / 32.;
113 static const double W41 = 1932. / 2197.;
114 static const double W42 = -7200. / 2197.;
115 static const double W43 = 7296. / 2197.;
117 static const double W51 = 439. / 216.;
118 static const double W52 = -8.;
119 static const double W53 = 3680. / 513.;
120 static const double W54 = -845. / 4104;
122 static const double W61 = -8. / 27.;
123 static const double W62 = 2.;
124 static const double W63 = -3544. / 2565.;
125 static const double W64 = 1859. / 4104.;
126 static const double W65 = -11. / 40.;
128 static const double U1 = 25. / 216.;
129 static const double U3 = 1408. / 2565.;
130 static const double U4 = 2197. / 4104.;
131 static const double U5 = -1. / 5.;
133 static const double Z1 = 16. / 135.;
134 static const double Z3 = 6656. / 12825.;
135 static const double Z4 = 28561. / 56430.;
136 static const double Z5 = -9. / 50.;
137 static const double Z6 = 2. / 55.;
139 const unsigned order =
u.size();
142 k2(order, 0.0), k3(order, 0.0), k4(order, 0.0), k5(order, 0.0), k6(order, 0.0);
145 std::vector< DenseVector<_Type> > values;
153 p_EQUATION -> coord(0) = x;
154 p_EQUATION -> residual_fn(
u, k1);
159 p_EQUATION -> coord(0) = x + X2 *
h;
160 p_EQUATION -> residual_fn(z, k2);
162 z =
u + k1 * W31 + k2 * W32;
165 p_EQUATION -> coord(0) = x + X3 *
h;
166 p_EQUATION -> residual_fn(z, k3);
168 z =
u + k1 * W41 + k2 * W42 + k3 * W43;
171 p_EQUATION -> coord(0) = x + X4 *
h;
172 p_EQUATION -> residual_fn(z, k4);
174 z =
u + k1 * W51 + k2 * W52 + k3 * W53 + k4 * W54;
177 p_EQUATION -> coord(0) = x + X5 *
h;
178 p_EQUATION -> residual_fn(z, k5);
180 z =
u + k1 * W61 + k2 * W62 + k3 * W63 + k4 * W64 + k5 * W65;
183 p_EQUATION -> coord(0) = x + X6 *
h;
184 p_EQUATION -> residual_fn(z, k6);
187 e = k1 * U1 + k3 * U3 + k4 * U4 + k5 * U5;
188 z = k1 * Z1 + k3 * Z3 + k4 * Z4 + k5 * Z5 + k6 * Z6;
194 c = sqrt(sqrt(tol *
h / (2 * diff)));
198 if((step == 1) && (c < 1.0)) {
209 if(step % STORE_EVERY == 0) {
218 if(x +
h > X_FINAL) {
224 problem =
"The ODE.shoot45 method reached the maximum \n";
225 problem +=
"number of steps specified by the user. \n";
229 }
while(std::abs(x - X_FINAL) > tol);
233 for(
unsigned i = 0; i < coords.
size(); ++i) {
235 SOLN.set_nodes_vars(i, values[i]);
241 template <
typename _Type>
246 template <
typename _Type>
A templated class for equations that can be inherited from to allow instantiation of ODE/PDE objects ...
The collection of CppNoddy exceptions.
A specification for a class to solve initial value problems of the form.
A specification for a one dimensional mesh object.
A spec for a collection of utility functions.
An DenseVector class – a dense vector object.
void push_back(const _Type &fill)
A pass-thru definition of push_back.
std::size_t size() const
A pass-thru definition to get the size of the vector.
An equation object base class used in the BVP/IVP classes.
A generic runtime exception.
A templated object for real/complex vector system of first-order ordinary differential equations.
OneD_Node_Mesh< _Type > & get_mesh()
Return the history of the stepped solution.
unsigned & store_every()
Return a handle to the STORE_EVERY object.
ODE_IVP(Equation< _Type > *equation_ptr, const double &x_init, const double &x_final, const std::size_t &num_of_steps)
The class is defined by a vector function for the system.
DenseVector< _Type > shoot4(DenseVector< _Type > u)
A fixed step 4th order Runge-Kutta method.
DenseVector< _Type > shoot45(DenseVector< _Type > u, const double &tol, const double &h_init)
A Runge-Kutta-Fehlberg integrator.
A one dimensional mesh utility object.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...