Brian Silverman | 7c33ab2 | 2018-08-04 17:14:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * lorenz_gmpxx.cpp |
| 3 | * |
| 4 | * This example demonstrates how odeint can be used with arbitrary precision types. |
| 5 | * |
| 6 | * Copyright 2011-2012 Karsten Ahnert |
| 7 | * Copyright 2011-2012 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 | #include <boost/array.hpp> |
| 18 | |
| 19 | #include <gmpxx.h> |
| 20 | |
| 21 | #include <boost/numeric/odeint.hpp> |
| 22 | |
| 23 | using namespace std; |
| 24 | using namespace boost::numeric::odeint; |
| 25 | |
| 26 | //[ gmpxx_lorenz |
| 27 | typedef mpf_class value_type; |
| 28 | typedef boost::array< value_type , 3 > state_type; |
| 29 | |
| 30 | struct lorenz |
| 31 | { |
| 32 | void operator()( const state_type &x , state_type &dxdt , value_type t ) const |
| 33 | { |
| 34 | const value_type sigma( 10.0 ); |
| 35 | const value_type R( 28.0 ); |
| 36 | const value_type b( value_type( 8.0 ) / value_type( 3.0 ) ); |
| 37 | |
| 38 | dxdt[0] = sigma * ( x[1] - x[0] ); |
| 39 | dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; |
| 40 | dxdt[2] = -b * x[2] + x[0] * x[1]; |
| 41 | } |
| 42 | }; |
| 43 | //] |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | struct streaming_observer |
| 49 | { |
| 50 | std::ostream& m_out; |
| 51 | |
| 52 | streaming_observer( std::ostream &out ) : m_out( out ) { } |
| 53 | |
| 54 | template< class State , class Time > |
| 55 | void operator()( const State &x , Time t ) const |
| 56 | { |
| 57 | m_out << t; |
| 58 | for( size_t i=0 ; i<x.size() ; ++i ) m_out << "\t" << x[i] ; |
| 59 | m_out << "\n"; |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | int main( int argc , char **argv ) |
| 69 | { |
| 70 | //[ gmpxx_integration |
| 71 | const int precision = 1024; |
| 72 | mpf_set_default_prec( precision ); |
| 73 | |
| 74 | state_type x = {{ value_type( 10.0 ) , value_type( 10.0 ) , value_type( 10.0 ) }}; |
| 75 | |
| 76 | cout.precision( 1000 ); |
| 77 | integrate_const( runge_kutta4< state_type , value_type >() , |
| 78 | lorenz() , x , value_type( 0.0 ) , value_type( 10.0 ) , value_type( value_type( 1.0 ) / value_type( 10.0 ) ) , |
| 79 | streaming_observer( cout ) ); |
| 80 | //] |
| 81 | |
| 82 | return 0; |
| 83 | } |