AdaptiveCellList_test.hpp 3.64 KB
Newer Older
incardon's avatar
incardon committed
1
2
3
4
5
6
7
8
9
10
/*
 * AdaptiveCellList_test.hpp
 *
 *  Created on: May 4, 2015
 *      Author: i-bird
 */

#ifndef ADAPTIVECELLLIST_TEST_HPP_
#define ADAPTIVECELLLIST_TEST_HPP_

11
12
#include "AdaptiveCellList.hpp"
#include "Grid/grid_sm.hpp"
incardon's avatar
incardon committed
13
14


15
16
template<unsigned int dim>
Point<dim+1,double> giveRadius(Point<dim,double> const & p)
incardon's avatar
incardon committed
17
{
18
19
20
21
22
  Point<dim+1, double> p_;
  for(unsigned int i=0; i<dim; ++i) p_.get(i) = p.get(i);
  p_[dim] = 0.5;
  return p_;
}
incardon's avatar
incardon committed
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
/*! \brief Test cell structure
 *
 * \tparam CellS
 *
 */
template<unsigned int dim, typename T, typename CellS> void Test_ar_cell_s()
{
	//Space where is living the Cell list
	SpaceBox<dim,T> box({0.0f,0.0f,0.0f},{1.0f,1.0f,1.0f});

	// Subdivisions
	size_t div[dim] = {16,16,16};

	// grid info
	grid_sm<dim,void> g_info(div);

	// Origin
	Point<dim,T> org({0.0,0.0,0.0});

	// id Cell list
	CellS cl1(box,div,org);

	// Create a grid iterator
	grid_key_dx_iterator<dim> g_it(g_info);

	// Iterate through each element
	// Add 1 element for each cell
	
	// Usefull definition of points
	Point<dim,T> end = box.getP2();
	Point<dim,T> middle = end / div / 2.0;
	Point<dim,T> spacing = end / div;

	Point<dim,T> offset[dim] = {middle,middle,middle};

	// Create offset shift vectors
	for (int i = 0 ; i < dim ; i++)
	{
		offset[i].get(i) += (1.0 / div[i]) / 8.0;
	}

	size_t id = 0;

	while (g_it.isNext())
	{
		// Add 2 particles on each cell

		// particle one
		Point<dim,T> key = g_it.get();
		key = key * spacing + offset[0];

		cl1.add(giveRadius(key),id);
		++id;

		// particle two
		key = g_it.get();
		key = key * spacing + offset[1];

		cl1.add(giveRadius(key),id);
		++id;

		++g_it;
	}

	// check the cells are correctly filled

	// reset iterator
	g_it.reset();

	while (g_it.isNext())
	{
		// Add 2 particles on each cell

		Point<dim,T> key = g_it.get();
		key = key * spacing + offset[2];

		size_t cell = cl1.getCell(key);
		size_t n_ele = cl1.getNelements(cell);
incardon's avatar
incardon committed
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
		BOOST_REQUIRE_EQUAL(n_ele,2);
		BOOST_REQUIRE_EQUAL(cl1.get(cell,1) - cl1.get(cell,0),1);

		++g_it;
	}

	// reset itarator
	g_it.reset();

	// remove one particle from each cell

	while (g_it.isNext())
	{
		// remove 1 particle on each cell

		Point<dim,T> key = g_it.get();
		key = key * spacing + offset[0];

		auto cell = cl1.getCell(key);

		// Remove the first particle in the cell
		cl1.remove(cell,0);
		++g_it;
	}

	// Check we have 1 object per cell
	g_it.reset();

	while (g_it.isNext())
	{
		// remove 1 particle on each cell

		Point<dim,T> key = g_it.get();
		key = key * spacing + offset[0];

		auto cell = cl1.getCell(key);
		size_t n_ele = cl1.getNelements(cell);

		BOOST_REQUIRE_EQUAL(n_ele,1);
		++g_it;
	}


	// Check the neighborhood iterator on the internal grid (They do not wotk on external grid)

	// Check we have 1 object per cell

	// Create a grid iterator
	grid_key_dx<dim> p1(1,1,1);
	grid_key_dx<dim> p2(div[0]-2,div[1]-2,div[2]-2);
	grid_key_dx_iterator_sub<dim> g_it_s(g_info,p1,p2);

	while (g_it_s.isNext())
	{
		// remove 1 particle on each cell

		Point<dim,T> key = g_it_s.get();
		key = key * spacing + offset[0];

		auto NN = cl1.template getNNIterator<NO_CHECK>(cl1.getCell(key));
		size_t total = 0;

		while(NN.isNext())
		{
			// total

			total++;

			++NN;
		}

		BOOST_REQUIRE_EQUAL(total,openfpm::math::pow(3,dim));
		++g_it_s;
	}
}

BOOST_AUTO_TEST_SUITE( AdaptiveCellList_test )

BOOST_AUTO_TEST_CASE( AdaptiveCellList_use)
{
	std::cout << "Now testing the AR-List..." << std::endl;
	Test_ar_cell_s<3, double, AdaptiveCellList<3, double>>();
	std::cout << "Done testing the AR-List." << std::endl;
incardon's avatar
incardon committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
}

BOOST_AUTO_TEST_CASE( AdaptiveCellList_another_test)
{
	// Test case for your class

	//

}

BOOST_AUTO_TEST_SUITE_END()


#endif /* ADAPTIVECELLLIST_TEST_HPP_ */