sgrid_dist_id_unit_tests.cpp 4.19 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * sgrid_dist_id_unit_tests.cpp
 *
 *  Created on: Nov 18, 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"

incardon's avatar
incardon committed
14 15 16
////////////////////////////////////// THEESE TEST ARE BROKEN TO REMPOVE OR FIX ////


incardon's avatar
incardon committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
const int x = 0;
const int y = 1;
const int z = 2;

BOOST_AUTO_TEST_SUITE( sgrid_dist_id_test )

BOOST_AUTO_TEST_CASE( sgrid_dist_id_basic_test_2D)
{
	periodicity<2> bc = {NON_PERIODIC, NON_PERIODIC};

	// Domain
	Box<2,double> domain({-0.3,-0.3},{1.0,1.0});

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

	// Ghost
	Ghost<2,double> g(0.01);

	sgrid_dist_id<2,double,Point_test<float>> sg(sz,domain,g,bc);

incardon's avatar
incardon committed
40
	// create a grid iterator
incardon's avatar
incardon committed
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237

	auto it = sg.getGridIterator();

	while(it.isNext())
	{
		auto gkey = it.get();
		auto key = it.get_dist();


		long int sx = gkey.get(0) - 512;
		long int sy = gkey.get(1) - 512;

		if (sx*sx + sy*sy < 128*128)
		{
			sg.template insert<0>(key) = 1.0;
		}

		++it;
	}

	sg.write("sg_test_write");

	bool match = true;
	auto it2 = sg.getGridIterator();

	while(it2.isNext())
	{
		auto gkey = it2.get();
		auto key = it2.get_dist();

		long int sx = gkey.get(0) - 512;
		long int sy = gkey.get(1) - 512;

		if (sx*sx + sy*sy < 128*128)
		{
			match &= (sg.template get<0>(key) == 1.0);
		}

		++it2;
	}

	BOOST_REQUIRE_EQUAL(match,true);

	sg.ghost_get<0>();

	auto & gr = sg.getGridInfo();

	auto it3 = sg.getDomainIterator();

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

		sg.template insert<0>(key) = gr.LinId(gkey) * gr.LinId(gkey);

		++it3;
	}

	// now we check the stencil

	bool good = true;
	auto it4 = sg.getDomainIterator();

	while (it4.isNext())
	{
		auto key = it4.get();

		double lap;

		// Here we check that all point of the stencil are inside*/

/*		auto key_xm1 = it4.move(key,x,-1);
		auto gkey_xm1 = it4.getGkey(key,x,-1);
		auto key_xp1 = it4.move(key,x,1);
		auto key_ym1 = it4.move(key,y,-1);
		auto key_yp1 = it4.move(key,y,1);
		auto key_zm1 = it4.move(key,z,-1);
		auto key_zp1 = it4.move(key,z,1);


		size_t sx = key_xm1 - 512;
		size_t sy = gkey.get(1) - 512;*/

		lap = sg.template get<0>(key.move(x,1)) + sg.template get<0>(key.move(x,-1)) +
			  sg.template get<0>(key.move(y,1)) + sg.template get<0>(key.move(y,-1)) +
			  4.0*sg.template get<0>(key);

		good &= (lap == 4.0);

		++it4;
	}

	BOOST_REQUIRE_EQUAL(good,true);
}

BOOST_AUTO_TEST_CASE( sgrid_dist_id_basic_test)
{
	periodicity<3> bc = {NON_PERIODIC, NON_PERIODIC, NON_PERIODIC};

	// Domain
	Box<3,double> domain({-0.3,-0.3,-0.3},{1.0,1.0,1.0});

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

	// Ghost
	Ghost<3,double> g(0.01);

	sgrid_dist_id<3,double,Point_test<float>> sg(sz,domain,g,bc);

	// create a grid iterator over a bilion point

	auto it = sg.getGridIterator();

	while(it.isNext())
	{
		auto gkey = it.get();
		auto key = it.get_dist();

		size_t sx = gkey.get(0) - 512;
		size_t sy = gkey.get(1) - 512;
		size_t sz = gkey.get(2) - 512;

		if (sx*sx + sy*sy + sz*sz < 128*128)
		{
			sg.template insert<0>(key) = 1.0;
		}

		++it;
	}

	bool match = true;
	auto it2 = sg.getGridIterator();

	while(it2.isNext())
	{
		auto gkey = it2.get();
		auto key = it2.get_dist();

		size_t sx = gkey.get(0) - 512;
		size_t sy = gkey.get(1) - 512;
		size_t sz = gkey.get(2) - 512;

		if (sx*sx + sy*sy + sz*sz < 128*128)
		{
			match &= (sg.template get<0>(key) == 1.0);
		}

		++it2;
	}

	sg.ghost_get<0>();

	auto & gr = sg.getGridInfo();

	auto it3 = sg.getDomainIterator();

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

		sg.template insert<0>(key) = gr.LinId(gkey) * gr.LinId(gkey);

		++it3;
	}

	// now we check the stencil

	bool good = true;
	auto it4 = sg.getDomainIterator();

	while (it4.isNext())
	{
		auto key = it4.get();

		double lap;

		lap = sg.template get<0>(key.move(x,1)) + sg.template get<0>(key.move(x,-1)) +
			  sg.template get<0>(key.move(y,1)) + sg.template get<0>(key.move(y,-1)) +
			  sg.template get<0>(key.move(z,1)) + sg.template get<0>(key.move(z,-1)) +
			  6.0*sg.template get<0>(key);

		good &= (lap == 6.0);

		++it4;
	}

	BOOST_REQUIRE_EQUAL(match,true);
}


BOOST_AUTO_TEST_SUITE_END()