Kernels_unit_tests.hpp 2.64 KB
Newer Older
Pietro Incardona's avatar
Pietro Incardona committed
1 2 3 4 5 6 7 8 9 10 11
/*
 * Kernels_unit_tests.hpp
 *
 *  Created on: Feb 17, 2016
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_PSE_KERNELS_UNIT_TESTS_HPP_
#define OPENFPM_NUMERICS_SRC_PSE_KERNELS_UNIT_TESTS_HPP_

#include "PSE/Kernels_test_util.hpp"
12
#ifdef HAVE_LIBQUADMATH
Pietro Incardona's avatar
Pietro Incardona committed
13
#include <boost/multiprecision/float128.hpp>
14
#endif
Pietro Incardona's avatar
Pietro Incardona committed
15 16 17 18 19

BOOST_AUTO_TEST_SUITE( pse_kernels_unit_tests )

BOOST_AUTO_TEST_CASE( pse_ker )
{
20
	Vcluster & v_cl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

	// This test is not made to run in parallel
	if (v_cl.getProcessingUnits() > 1)
		return;

	openfpm::vector<openfpm::vector<double>> y;
	openfpm::vector<openfpm::vector<double>> y_res;

	// Load the result of the test
	y_res.load("test_data/PSE_convergence");

	// Every time increase the number of particles by 2
	for (size_t i = 250 ; i <= 2097152000 ; i*=2)
	{
		y.add();

		PSEError err;

		/////// Order 2 //////////////

41
#ifdef HAVE_LIBQUADMATH
Pietro Incardona's avatar
Pietro Incardona committed
42 43 44 45 46
		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,2>>(i,2,err);
		y.last().add(err.linf_error);

		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,2>>(i,4,err);
		y.last().add(err.linf_error);
47
#endif
Pietro Incardona's avatar
Pietro Incardona committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

		PSE_test<double,Lap_PSE<1,double,2>>(i,2,err);
		y.last().add(err.linf_error);

		PSE_test<double,Lap_PSE<1,double,2>>(i,4,err);
		y.last().add(err.linf_error);

		PSE_test<float,Lap_PSE<1,float,2>>(i,2,err);
		y.last().add(err.linf_error);

		PSE_test<float,Lap_PSE<1,float,2>>(i,4,err);
		y.last().add(err.linf_error);

		//////// Order 4 /////////////

63
#ifdef HAVE_LIBQUADMATH
Pietro Incardona's avatar
Pietro Incardona committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,4>>(i,2,err);
		y.last().add(err.linf_error);

		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,4>>(i,4,err);
		y.last().add(err.linf_error);


		//////// Order 6 /////////////

		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,6>>(i,2,err);
		y.last().add(err.linf_error);

		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,6>>(i,4,err);
		y.last().add(err.linf_error);

		//////// Order 8 /////////////

		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,8>>(i,8,err);
		y.last().add(err.linf_error);

		PSE_test<boost::multiprecision::float128,Lap_PSE<1,boost::multiprecision::float128,8>>(i,16,err);
		y.last().add(err.linf_error);
86 87

#endif
Pietro Incardona's avatar
Pietro Incardona committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
	}

	// Check the result
	for (size_t i = 0 ; i < y.size(); i++)
	{
		for (size_t j = 0 ; j < y.get(i).size(); j++)
		{
			BOOST_REQUIRE_CLOSE(y.get(i).get(j),y_res.get(i).get(j),0.01);
		}
	}
}

BOOST_AUTO_TEST_SUITE_END()

#endif /* OPENFPM_NUMERICS_SRC_PSE_KERNELS_UNIT_TESTS_HPP_ */