CppNoddy  0.92
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
IVPLorenz.cpp File Reference

Integrate the Lorenz equations. More...

#include <IVP_bundle.h>

Go to the source code of this file.

Classes

class  CppNoddy::Example::Lorenz_equations
 Define the Lorenz equations by inheriting Equation base class. More...
 

Namespaces

namespace  CppNoddy
 A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechanics.
 
namespace  CppNoddy::Example
 

Functions

int main ()
 

Detailed Description

Integrate the Lorenz equations.

\[ \dot x = a( y - x )\,,\quad \dot y = x ( b - z ) - y\,, \quad \dot z = -c z + xy\,, \]

forward in time using an adaptive Runge-Kutta-Fehlberg routine. The parameters are chosen to be $ a=10 $, $ b = 7 $, $ c = 8/3 $. There is a fixed point solution $ (x,y,z) = (4,4,6) $, which is tested here.

Definition in file IVPLorenz.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 42 of file IVPLorenz.cpp.

43{
44 cout << "\n";
45 cout << "=== IVP: integrating the Lorenz system ==============\n";
46 cout << "\n";
47 cout << " Running shoot method - fixed step choice \n";
48
49 DenseVector<double> u( 3, 0.0 ), u_init( 3, 0.0 );
50 // initialise
51 u_init[ 0 ] = 1.0;
52 u_init[ 1 ] = 1.0;
53 u_init[ 2 ] = 1.0;
54 const int num_of_steps( 5000000 );
55 // set up the problem.
56 Example::Lorenz_equations problem;
57 problem.a = 10.0;
58 problem.b = 7.0;
59 problem.c = 8.0 / 3.0;
60
61 // Construct an ODE from the problem.
62 ODE_IVP<double> ode( &problem, 0.0, 200.0, num_of_steps );
63 ode.store_every() = 10;
64
65 const double tol = 1.e-7;
66#ifdef TIME
67 Timer timer;
68 timer.start();
69 do
70 {
71#endif
72 try
73 {
74 u = ode.shoot45( u_init, tol, 0.1 );
75 }
76 catch (const std::runtime_error &error )
77 {
78 cout << " \033[1;31;48m * FAILED THROUGH EXCEPTION BEING RAISED \033[0m\n";
79 return 1;
80 }
81
82#ifdef TIME
83 timer.counter()++;
84 }
85 while ( timer.get_time() < 5000.0 );
86 timer.stop();
87 timer.print();
88#endif
89
90 cout.precision( 12 );
91 if ( abs( u[ 0 ] - 4.0 ) > tol )
92 {
93 cout << " Difference = " << abs( u[ 0 ] - 4.0 ) << "\n";
94 cout << "\033[1;31;48m * FAILED \033[0m\n";
95 }
96 else
97 {
98 cout << "\033[1;32;48m * PASSED \033[0m\n";
99 }
100 ode.get_mesh().dump_gnu("./DATA/test.dat");
101}
An DenseVector class – a dense vector object.
Definition: DenseVector.h:34
A templated object for real/complex vector system of first-order ordinary differential equations.
Definition: ODE_IVP.h:20
A simple CPU-clock-tick timer for timing metods.
Definition: Timer.h:19
double get_time() const
Return the time.
Definition: Timer.cpp:34
void start()
Start the timer & reset stored time to zero.
Definition: Timer.cpp:12
int & counter()
Increment an internal discrete counter.
Definition: Timer.cpp:44
void print() const
Write a string to cout stating the time taken.
Definition: Timer.cpp:59
void stop()
Stop the clock & add the current time interval to the previously stored values ready for printing.
Definition: Timer.cpp:17

References CppNoddy::Example::Lorenz_equations::a, CppNoddy::Example::Lorenz_equations::b, CppNoddy::Example::Lorenz_equations::c, CppNoddy::Timer::counter(), CppNoddy::ODE_IVP< _Type >::get_mesh(), CppNoddy::Timer::get_time(), CppNoddy::Timer::print(), CppNoddy::ODE_IVP< _Type >::shoot45(), CppNoddy::Timer::start(), CppNoddy::Timer::stop(), CppNoddy::ODE_IVP< _Type >::store_every(), and u.

© 2012

R.E. Hewitt