Click here to Skip to main content
15,896,154 members
Articles / Programming Languages / CUDA

odeint v2 - Solving ordinary differential equations in C++

Rate me:
Please Sign up or sign in to vote.
4.64/5 (18 votes)
19 Oct 2011CPOL19 min read 130.1K   2.8K   34  
odeint v2 - Solving ordinary differential equations in C++
/* Boost check_gmp.cpp test file

 Copyright 2009 Karsten Ahnert
 Copyright 2009 Mario Mulansky

 This file tests the odeint library with the gmp arbitrary precision types

 Distributed under the Boost Software License, Version 1.0.
 (See accompanying file LICENSE_1_0.txt or
 copy at http://www.boost.org/LICENSE_1_0.txt)
*/

#define BOOST_TEST_MODULE odeint_gmp

#include <gmpxx.h>

#include <boost/test/unit_test.hpp>
#include <boost/array.hpp>

#include <boost/numeric/odeint/stepper/runge_kutta4.hpp>

using namespace boost::unit_test;
using namespace boost::numeric::odeint;

const int precision = 1024;

typedef mpf_class value_type;
typedef boost::array< value_type , 1 > state_type;


void constant_system( state_type &x , state_type &dxdt , value_type t )
{
	dxdt[0] = value_type( 1.0 , precision );
}


BOOST_AUTO_TEST_CASE( gmp )
{
	/* We have to specify the desired precision in advance! */
	mpf_set_default_prec( precision );

	mpf_t eps_ , unity;
	mpf_init( eps_ ); mpf_init( unity );
	mpf_set_d( unity , 1.0 );
	mpf_div_2exp( eps_ , unity , precision-1 ); // 2^(-precision+1) : smallest number that can be represented with used precision
	value_type eps( eps_ );

	runge_kutta4< state_type , value_type > stepper;
	state_type x;
	x[0] = 0.0;

	stepper.do_step( constant_system , x , 0.0 , 0.1 );

	BOOST_MESSAGE( eps );
	BOOST_CHECK_MESSAGE( abs( x[0] - value_type( 0.1 , precision ) ) < eps , x[0] - 0.1 );
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions