blob: c3e5b82e8ae9c2de9a0f03a2aa9510b637f16c6b [file] [log] [blame]
Brian Silverman7c33ab22018-08-04 17:14:51 -07001/*
2 * lorenz_mp.cpp
3 *
4 * This example demonstrates how odeint can be used with boost.multiprecision.
5 *
6 * Copyright 2011-2012 Karsten Ahnert
7 * Copyright 2013 Mario Mulansky
8 *
9 * Distributed under the Boost Software License, Version 1.0.
10 * (See accompanying file LICENSE_1_0.txt or
11 * copy at http://www.boost.org/LICENSE_1_0.txt)
12 */
13
14
15
16#include <iostream>
17
18//[ mp_lorenz_defs
19#include <boost/numeric/odeint.hpp>
20#include <boost/multiprecision/cpp_dec_float.hpp>
21
22using namespace std;
23using namespace boost::numeric::odeint;
24
25typedef boost::multiprecision::cpp_dec_float_50 value_type;
26
27typedef boost::array< value_type , 3 > state_type;
28//]
29
30//[ mp_lorenz_rhs
31struct lorenz
32{
33 void operator()( const state_type &x , state_type &dxdt , value_type t ) const
34 {
35 const value_type sigma( 10 );
36 const value_type R( 28 );
37 const value_type b( value_type( 8 ) / value_type( 3 ) );
38
39 dxdt[0] = sigma * ( x[1] - x[0] );
40 dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
41 dxdt[2] = -b * x[2] + x[0] * x[1];
42 }
43};
44//]
45
46
47
48
49struct streaming_observer
50{
51 std::ostream& m_out;
52
53 streaming_observer( std::ostream &out ) : m_out( out ) { }
54
55 template< class State , class Time >
56 void operator()( const State &x , Time t ) const
57 {
58 m_out << t;
59 for( size_t i=0 ; i<x.size() ; ++i ) m_out << "\t" << x[i] ;
60 m_out << "\n";
61 }
62};
63
64
65
66
67
68
69int main( int argc , char **argv )
70{
71 //[ mp_lorenz_int
72 state_type x = {{ value_type( 10.0 ) , value_type( 10.0 ) , value_type( 10.0 ) }};
73
74 cout.precision( 50 );
75 integrate_const( runge_kutta4< state_type , value_type >() ,
76 lorenz() , x , value_type( 0.0 ) , value_type( 10.0 ) , value_type( value_type( 1.0 ) / value_type( 10.0 ) ) ,
77 streaming_observer( cout ) );
78 //]
79
80 return 0;
81}