DrawParticles_unit_tests.hpp 2.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * DrawParticles_unit_tests.hpp
 *
 *  Created on: Jan 3, 2017
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_UNIT_TESTS_HPP_
#define OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_UNIT_TESTS_HPP_

#include "PointIterator.hpp"
incardon's avatar
incardon committed
12 13
#include "PointIteratorSkin.hpp"
#include "DrawParticles.hpp"
14 15 16 17 18

BOOST_AUTO_TEST_SUITE( draw_particles )

BOOST_AUTO_TEST_CASE(point_iterator)
{
19 20
	//! [DrawBox_example]

incardon's avatar
incardon committed
21
	size_t sz[] = {23,27,20};
22

incardon's avatar
incardon committed
23 24 25 26 27
	Box<3,double> domain({-1.2,0.5,-0.6},{1.0,3.1,1.3});
	Box<3,double> sub_domain({-0.15,0.75,0.15},{1.05,1.15,1.05});
	Box<3,double> sub_real({-0.1,0.80,0.2},{1.0,1.1,1.0});

	size_t sz_sub[] = {12,4,9};
28 29 30 31 32 33 34 35 36

	// Boundary conditions
	size_t bc[3]={NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};

	// ghost, big enough to contain the interaction radius
	Ghost<3,float> ghost(0.01);

	vector_dist<3,double,aggregate<double>> vd(0,domain,bc,ghost);

incardon's avatar
incardon committed
37
	auto p = DrawParticles::DrawBox(vd,sz,domain,sub_domain);
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

	size_t cnt = 0;

	bool good = true;
	while (p.isNext())
	{
		vd.add();

		vd.getLastPos()[0] = p.get().get(0);
		vd.getLastPos()[1] = p.get().get(1);
		vd.getLastPos()[2] = p.get().get(2);

		good &= sub_domain.isInside(p.get());

		cnt++;

		++p;
	}

57 58
	//! [DrawBox_example]

incardon's avatar
incardon committed
59
	Vcluster<> & v_cl = create_vcluster();
60 61

	v_cl.sum(cnt);
incardon's avatar
incardon committed
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
	v_cl.execute();

	BOOST_REQUIRE_EQUAL(cnt,sz_sub[0]*sz_sub[1]*sz_sub[2]);
	BOOST_REQUIRE_EQUAL(good,true);

	Box<3,double> marg = p.getBoxMargins();

	BOOST_REQUIRE_CLOSE(marg.getLow(0), sub_real.getLow(0) ,0.0001);
	BOOST_REQUIRE_CLOSE(marg.getLow(1), sub_real.getLow(1) ,0.0001);
	BOOST_REQUIRE_CLOSE(marg.getLow(2), sub_real.getLow(2) ,0.0001);

	BOOST_REQUIRE_CLOSE(marg.getHigh(0), sub_real.getHigh(0) ,0.0001);
	BOOST_REQUIRE_CLOSE(marg.getHigh(1), sub_real.getHigh(1) ,0.0001);
	BOOST_REQUIRE_CLOSE(marg.getHigh(2), sub_real.getHigh(2) ,0.0001);
}

BOOST_AUTO_TEST_CASE(point_iterator_skin)
{
	size_t sz[] = {23,27,20};

	Box<3,double> domain({-1.2,0.5,-0.6},{1.0,3.1,1.3});
	Box<3,double> sub_domainA({-0.15,0.75,0.15},{1.05,1.15,1.05});
	Box<3,double> sub_domainB({-0.25,0.65,0.05},{0.95,1.05,1.05});

	// Boundary conditions
	size_t bc[3]={NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};

	// ghost, big enough to contain the interaction radius
	Ghost<3,float> ghost(0.01);

	vector_dist<3,double,aggregate<double>> vd(0,domain,bc,ghost);

	auto p = DrawParticles::DrawSkin(vd,sz,domain,sub_domainA, sub_domainB);

	size_t cnt = 0;

	bool good = true;
	while (p.isNext())
	{
		vd.add();

		vd.getLastPos()[0] = p.get().get(0);
		vd.getLastPos()[1] = p.get().get(1);
		vd.getLastPos()[2] = p.get().get(2);

		if (!((p.get().get(0) > -0.21 && p.get().get(0) < -0.19) || (p.get().get(1) > 0.69 && p.get().get(1) < 0.71) || (p.get().get(2) > 0.09 && p.get().get(2) < 0.11)) )
			good &= false;

		if (sub_domainA.isInside(p.get()))
			good &= false;

		cnt++;

		++p;
	}

incardon's avatar
incardon committed
118
	Vcluster<> & v_cl = create_vcluster();
incardon's avatar
incardon committed
119 120 121

	v_cl.sum(cnt);
	v_cl.execute();
122 123 124 125 126 127 128

	BOOST_REQUIRE_EQUAL(good,true);
}

BOOST_AUTO_TEST_SUITE_END()

#endif /* OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_UNIT_TESTS_HPP_ */