shift_vect_converter_tests.cpp 2.63 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
/*
 * shift_vect_converter_tests.cpp
 *
 *  Created on: Feb 8, 2018
 *      Author: i-bird
 */

#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "Space/Shape/Box.hpp"

#include "Vector/map_vector.hpp"
#include "Decomposition/shift_vect_converter.hpp"

BOOST_AUTO_TEST_SUITE( shift_vect_converter_tests_suite )

BOOST_AUTO_TEST_CASE( shift_vect_converter_tests_use )
{
	{
	Box<3,double> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
	shift_vect_converter<3,double> svc;
	size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};

	openfpm::vector<Point<3,double>> sv;

	svc.generateShiftVectors(domain,bc,sv);

	BOOST_REQUIRE_EQUAL(sv.size(),27ul);

	// We test that the cominations generate the correct shift vectors
	comb<3> cmb1({-1,-1,1});
	comb<3> cmb2({-1,0,1});
	comb<3> cmb3({0,0,1});

	size_t i = svc.linId(cmb1);

	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[0],-1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[1],1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[2],1.0);

	i = svc.linId(cmb2);

	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[0],-1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[1],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[2],1.0);

	i = svc.linId(cmb3);

	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[0],-1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[1],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[2],0.0);

	}

	{
	openfpm::vector<Point<50,double>> sv;
	Box<50,double> domain;
	size_t bc[50];

	for (size_t i = 0 ; i < 50 ; i++)
	{
		domain.setLow(i,0.0);
		domain.setHigh(i,1.0);
		bc[i] = NON_PERIODIC;
	}

	bc[5] = PERIODIC;
	bc[17] = PERIODIC;
	bc[23] = PERIODIC;

	shift_vect_converter<50,double> svc;

	svc.generateShiftVectors(domain,bc,sv);

	BOOST_REQUIRE_EQUAL(sv.size(),27ul);

	// We test that the cominations generate the correct shift vectors
	comb<50> cmb1;
	comb<50> cmb2;
	comb<50> cmb3;

	cmb1.c[5] = 1;
	cmb1.c[17] = -1;
	cmb1.c[23] = -1;

	cmb2.c[5] = 1;
	cmb2.c[17] = 0;
	cmb2.c[23] = -1;

	cmb3.c[5] = 1;
	cmb3.c[17] = 0;
	cmb3.c[23] = 0;

	size_t i = svc.linId(cmb1);

	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[5],-1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[6],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[17],1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[23],1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[24],0.0);

	i = svc.linId(cmb2);

	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[5],-1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[6],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[17],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[23],1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[24],0.0);

	i = svc.linId(cmb3);

	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[5],-1.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[6],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[17],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[23],0.0);
	BOOST_REQUIRE_EQUAL(sv.get<0>(i)[24],0.0);

	}
}


BOOST_AUTO_TEST_SUITE_END()