amr_base_unit_tests.cpp 3.53 KB
Newer Older
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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
/*
 * amr_base_unit_test.cpp
 *
 *  Created on: Oct 5, 2017
 *      Author: i-bird
 */
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include "Grid/grid_dist_id.hpp"
#include "Point_test.hpp"
#include "Grid/tests/grid_dist_id_util_tests.hpp"

BOOST_AUTO_TEST_SUITE( amr_grid_dist_id_test )


BOOST_AUTO_TEST_CASE( grid_dist_id_amr )
{
	// Domain
	Box<2,float> domain2({0.0,0.0},{1.0,1.0});

	size_t sz[2] = {100,100};

	// Ghost
	Ghost<2,long int> g(1);

	// periodicity
	periodicity<2> pr = {{PERIODIC,PERIODIC}};

	openfpm::vector<Box<2,long int>> C_draw;
	C_draw.add(Box<2,long int>({20,20},{50,24}));
	C_draw.add(Box<2,long int>({51,20},{60,24}));
	C_draw.add(Box<2,long int>({61,20},{70,24}));
	C_draw.add(Box<2,long int>({20,25},{24,66}));
	C_draw.add(Box<2,long int>({15,67},{49,85}));
	C_draw.add(Box<2,long int>({50,76},{70,81}));
	C_draw.add(Box<2,long int>({30,25},{34,37}));
	C_draw.add(Box<2,long int>({50,66},{70,70}));

	size_t volume_key = 0;
	for (size_t i = 0 ; i < C_draw.size() ; i++)
	{
		volume_key += Box<2,long int>(C_draw.get(i)).getVolumeKey();
	}

	// Distributed grid with id decomposition
	grid_dist_id<2,float,Point_test<float>> g_dist(sz,domain2,g,pr,C_draw);

	// fill with gkey

	auto git = g_dist.getDomainIterator();
	grid_sm<2,void> gs(sz);

	size_t count = 0;

	while (git.isNext())
	{
		auto key = git.get();
		auto gkey = git.getGKey(key);

		g_dist.template get<0>(key) = gs.LinId(gkey);

		count++;

		++git;
	}

	Vcluster<> & vcl = create_vcluster();

	vcl.sum(count);
	vcl.execute();

	BOOST_REQUIRE_EQUAL(count,volume_key);

	g_dist.ghost_get<0>();

	// Check it is correct

	bool check = true;
	size_t check_count = 0;

	auto git2 = g_dist.getDomainGhostIterator();
	while (git2.isNext())
	{
		auto key = git2.get();
		auto gkey = git2.getGKey(key);

		float value = g_dist.template get<0>(key);

		// check if the point is inside or outside the domain

		for (size_t k = 0; k < C_draw.size() ; k++)
		{
			if (Box<2,long int>(C_draw.get(k)).isInside(gkey.toPoint()) == true)
			{
				check &= value == gs.LinId(gkey);

				// get the gdb_ext
				auto & gdb_ext = g_dist.getLocalGridsInfo();

				for (size_t s = 0 ; s < gdb_ext.size() ; s++)
				{
					Box<2,long int> bx = gdb_ext.get(s).Dbox;
					bx += gdb_ext.get(s).origin;
					if (bx.isInside(gkey.toPoint()))
					{
						check_count++;
						break;
					}
				}
				break;
			}
		}

		++git2;
	}

	vcl.sum(check_count);
	vcl.execute();

	BOOST_REQUIRE_EQUAL(check,true);
	BOOST_REQUIRE(check_count >= volume_key);
}

BOOST_AUTO_TEST_CASE( amr_grid_dist_id_iterator_test_use_2D)
{
	// Domain
	Box<2,float> domain({0.0,0.0},{1.0,1.0});

#ifdef TEST_COVERAGE_MODE
	long int k = 256*256*create_vcluster().getProcessingUnits();
#else
	long int k = 1024*1024*create_vcluster().getProcessingUnits();
#endif
	k = std::pow(k, 1/2.);

	long int big_step = k / 30;
	big_step = (big_step == 0)?1:big_step;
	long int small_step = 21;

	print_test( "AMR Testing 2D full grid k<=",k);

	// 2D test
	for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
	{
		BOOST_TEST_CHECKPOINT( "AMR Testing 2D full grid k=" << k );

		//! [Create and access a distributed grid]

		// grid size
		size_t sz[2];
		sz[0] = k;
		sz[1] = k;

		// periodicity
		periodicity<2> pr = {{PERIODIC,PERIODIC}};

		// Ghost
		Ghost<2,long int> g(1);

		openfpm::vector<Box<2,long int>> bx_def;
		bx_def.add(Box<2,long int>({0,0},{k-1,k-1}));

		// Distributed grid with id decomposition
		grid_dist_id<2, float, aggregate<double>> g_dist(sz,domain,g,pr,bx_def);

		Test2D_core(g_dist,sz,k);
	}
}

BOOST_AUTO_TEST_SUITE_END()