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

#ifndef SRC_DECOMPOSITION_COMMON_HPP_
#define SRC_DECOMPOSITION_COMMON_HPP_

11
12
13
#define UNIQUE 1
#define MULTIPLE 2

incardon's avatar
incardon committed
14
15
#include "Vector/map_vector.hpp"

16
17
18
19
20
21
22
23
24
25
26
27
/*! \brief for each sub-domain box sub contain the real the sub-domain id
 *
 * When we apply boundary conditions real sub-domains are copied along the border
 * sub, contain the id of the real sub_domain
 *
 * \tparam dim Dimensionality of the box
 * \tparam T in witch space this box live
 *
 */
template<unsigned int dim, typename T>
struct Box_loc_sub
{
Pietro Incardona's avatar
Pietro Incardona committed
28
	//! Box defining the sub-domain (copied)
29
30
	Box<dim,T> bx;

Pietro Incardona's avatar
Pietro Incardona committed
31
	//! The id of the real domain
32
	size_t sub;
incardon's avatar
incardon committed
33

Pietro Incardona's avatar
Pietro Incardona committed
34
	//! in witch sector this sub-domain live
35
36
	comb<dim> cmb;

Pietro Incardona's avatar
Pietro Incardona committed
37
	//! Constructor
38
	Box_loc_sub()
Pietro Incardona's avatar
Pietro Incardona committed
39
	:sub(0)
40
41
42
43
	{
		cmb.zero();
	};

Pietro Incardona's avatar
Pietro Incardona committed
44
	//! Constructor from box, domain id and sector where it live
45
46
47
48
	Box_loc_sub(const Box<dim,T> & bx, size_t sub, const comb<dim> & cmb)
	:bx(bx),sub(sub),cmb(cmb)
	{};

Pietro Incardona's avatar
Pietro Incardona committed
49
	//! Set the sub-domain box coordinates
50
51
52
53
54
55
56
57
58
	Box_loc_sub operator=(const Box<dim,T> & box)
	{
		::Box<dim,T>::operator=(box);

		return *this;
	}


};
incardon's avatar
incardon committed
59

60
/*! It contain a box definition and from witch sub-domain it come from (in the local processor list)
Pietro Incardona's avatar
Pietro Incardona committed
61
 * and an unique if across adjacent processors (for communication)
incardon's avatar
incardon committed
62
63
64
 *
 * If the box come from the intersection of an expanded sub-domain and a sub-domain
 *
65
 * Assuming we are considering the near processors i (0 to getNNProcessors())
incardon's avatar
incardon committed
66
67
68
69
 *
 *
 */
template<unsigned int dim, typename T>
70
struct Box_sub
incardon's avatar
incardon committed
71
{
Pietro Incardona's avatar
Pietro Incardona committed
72
	//! Internal ghost box definition
73
74
	Box<dim,T> bx;

Pietro Incardona's avatar
Pietro Incardona committed
75
	//! Domain id
incardon's avatar
incardon committed
76
77
	size_t sub;

Pietro Incardona's avatar
Pietro Incardona committed
78
	//! see ebx_ibx_form in ie_ghost for the meaning
incardon's avatar
incardon committed
79
80
	size_t id;

81
82
83
	//! see getNearSubdomainsRealId in nn_prcs
	size_t r_sub;

Pietro Incardona's avatar
Pietro Incardona committed
84
85
	//! see ie_ghost follow sector explanation
	comb<dim> cmb;
incardon's avatar
incardon committed
86

incardon's avatar
incardon committed
87
	//! Constructor reset cmb
incardon's avatar
incardon committed
88
89
	Box_sub()
	{cmb.zero();}
incardon's avatar
incardon committed
90
91
92
93
};

//! Particular case for local internal ghost boxes
template<unsigned int dim, typename T>
94
struct Box_sub_k
incardon's avatar
incardon committed
95
{
Pietro Incardona's avatar
Pietro Incardona committed
96
	//! extension of this local internal ghost box
97
98
	Box<dim,T> bx;

Pietro Incardona's avatar
Pietro Incardona committed
99
	//! Domain id
incardon's avatar
incardon committed
100
101
	size_t sub;

Pietro Incardona's avatar
Pietro Incardona committed
102
	//! Where this sub_domain live
103
104
	comb<dim> cmb;

incardon's avatar
incardon committed
105
106
107
	//! k \see getLocalGhostIBoxE
	long int k;

108
	Box_sub_k()
Pietro Incardona's avatar
Pietro Incardona committed
109
	:sub(0),k(-1)
110
111
112
	{
		cmb.zero();
	}
incardon's avatar
incardon committed
113
114
};

115
116
117
template<unsigned int dim,typename T>
struct Box_map
{
incardon's avatar
incardon committed
118
	typedef boost::fusion::vector<Box<dim,T>,long int> type;
119

incardon's avatar
incardon committed
120
	type data;
incardon's avatar
incardon committed
121
122
123
124
125

	static bool noPointers()
	{
		return true;
	}
incardon's avatar
incardon committed
126
127

	static const unsigned int max_prop = 2;
128
129
};

incardon's avatar
incardon committed
130
131
132
133
//! Case for local ghost box
template<unsigned int dim, typename T>
struct lBox_dom
{
Pietro Incardona's avatar
Pietro Incardona committed
134
135
	//! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor
	//! sub-domains (External ghost)
incardon's avatar
incardon committed
136
	openfpm::vector_std< Box_sub_k<dim,T> > ebx;
incardon's avatar
incardon committed
137

Pietro Incardona's avatar
Pietro Incardona committed
138
139
	//! Intersection between the contiguous processor sub-domain enlarged by the ghost with the
	//! local sub-domain (Internal ghost)
incardon's avatar
incardon committed
140
141
142
	openfpm::vector_std< Box_sub_k<dim,T>> ibx;
};

Pietro Incardona's avatar
Pietro Incardona committed
143
//! Case for local external ghost box
144
145
146
template<unsigned int dim, typename T>
struct Box_proc
{
Pietro Incardona's avatar
Pietro Incardona committed
147
148
	//! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor
	//! sub-domains (External ghost)
149
150
	openfpm::vector<::Box<dim,T>> bx;

Pietro Incardona's avatar
Pietro Incardona committed
151
152
	//! Intersection between the contiguous processor sub-domain enlarged by the ghost with the
	//! local sub-domain (Internal ghost)
153
154
155
	openfpm::vector<::Box<dim,T>> nbx;


Pietro Incardona's avatar
Pietro Incardona committed
156
	//! processor
157
158
159
	size_t proc;
};

Pietro Incardona's avatar
Pietro Incardona committed
160
//! Case for external ghost box
161
162
163
template<unsigned int dim, typename T>
struct Box_dom
{
Pietro Incardona's avatar
Pietro Incardona committed
164
165
	//! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor
	//! sub-domains (External ghost)
166
167
	openfpm::vector_std< Box_sub<dim,T> > ebx;

Pietro Incardona's avatar
Pietro Incardona committed
168
169
	//! Intersection between the contiguous processor sub-domain enlarged by the ghost with the
	//! local sub-domain (Internal ghost)
170
171
172
	openfpm::vector_std< Box_sub<dim,T> > ibx;
};

Pietro Incardona's avatar
Pietro Incardona committed
173
// It store the sub-domain sent by the near processors
174
175
176
template<unsigned int dim, typename T>
struct N_box
{
Pietro Incardona's avatar
Pietro Incardona committed
177
	//! id of the processor in the nn_processor list (local processor id)
178
179
	size_t id;

Pietro Incardona's avatar
Pietro Incardona committed
180
	//! near processor sub-domains
181
	typename openfpm::vector<::Box<dim,T>> bx;
182

Pietro Incardona's avatar
Pietro Incardona committed
183
	//! near processor sector position (or where they live outside the domain)
184
185
	openfpm::vector<comb<dim>> pos;

Pietro Incardona's avatar
Pietro Incardona committed
186
	//! Number of real sub-domains or sub-domain in the central sector
187
188
	size_t n_real_sub;

Pietro Incardona's avatar
Pietro Incardona committed
189
190
191
	//! When a sub-domain is not in the central sector, it mean that has been created
	//! because of periodicity in a non central sector. Any sub-domain not in the central
	//! sector is linked to one sub-domain in the central sector
192
193
	openfpm::vector<size_t> r_sub;

194
	//! Default constructor
195
	N_box()
Pietro Incardona's avatar
Pietro Incardona committed
196
	:id((size_t)-1),n_real_sub(0)
197
	{};
198
199
200

	//! Copy constructor
	N_box(const N_box<dim,T> & b)
Pietro Incardona's avatar
Pietro Incardona committed
201
	:id((size_t)-1),n_real_sub(0)
202
203
204
205
206
207
	{
		this->operator=(b);
	}

	//! Copy constructor
	N_box(N_box<dim,T> && b)
Pietro Incardona's avatar
Pietro Incardona committed
208
	:id((size_t)-1),n_real_sub(0)
209
210
211
212
213
214
215
216
	{
		this->operator=(b);
	}

	/*! \brief Copy the element
	 *
	 * \param ele element to copy
	 *
Pietro Incardona's avatar
Pietro Incardona committed
217
218
	 * \return itself
	 *
219
220
221
222
223
	 */
	N_box<dim,T> & operator=(const N_box<dim,T> & ele)
	{
		id = ele.id;
		bx = ele.bx;
224
		pos = ele.pos;
225
226
		n_real_sub = ele.n_real_sub;
		r_sub = ele.r_sub;
227
228
229
230
231
232
233
234

		return * this;
	}

	/*! \brief Copy the element
	 *
	 * \param ele element to copy
	 *
Pietro Incardona's avatar
Pietro Incardona committed
235
236
	 * \return itself
	 *
237
238
239
240
241
	 */
	N_box<dim,T> & operator=(N_box<dim,T> && ele)
	{
		id = ele.id;
		bx.swap(ele.bx);
242
243
244
		pos.swap(ele.pos);
		n_real_sub = ele.n_real_sub;
		r_sub.swap(ele.r_sub);
245
246
247

		return * this;
	}
incardon's avatar
incardon committed
248
249

	/*! \brief Compare two N_box object
Pietro Incardona's avatar
Pietro Incardona committed
250
251
	 *
	 * \param ele element to compare with
incardon's avatar
incardon committed
252
253
254
255
256
257
258
259
260
	 *
	 * \return true if they match
	 *
	 */
	bool operator==(const N_box<dim,T> & ele) const
	{
		if (id != ele.id)
			return false;

261
262
263
		if (pos != ele.pos)
			return false;

264
265
266
267
268
269
		if (r_sub != ele.r_sub)
			return false;

		if (n_real_sub != ele.n_real_sub)
			return false;

incardon's avatar
incardon committed
270
271
272
273
		return bx == ele.bx;
	}

	/*! \brief Compare two N_box object
Pietro Incardona's avatar
Pietro Incardona committed
274
275
	 *
	 * \param ele element to compare with
incardon's avatar
incardon committed
276
277
278
279
280
281
282
283
	 *
	 * \return true if they match
	 *
	 */
	bool operator!=(const N_box<dim,T> & ele) const
	{
		return ! this->operator==(ele);
	}
284
285
};

Pietro Incardona's avatar
Pietro Incardona committed
286
//! It store all the boxes of the near processors in a linear array
incardon's avatar
incardon committed
287
288
289
290
291
292
293
294
template<unsigned int dim, typename T>
struct p_box
{
	//! Box that identify the intersection of the ghost of the near processor with the
	//! processor sub-domain
	::Box<dim,T> box;
	//! local processor id
	size_t lc_proc;
295
	//! processor rank
incardon's avatar
incardon committed
296
297
	size_t proc;

298
299
300
	//! shift vector id
	size_t shift_id;

incardon's avatar
incardon committed
301
302
303
304
	/*! \brief Check if two p_box are the same
	 *
	 * \param pb box to check
	 *
Pietro Incardona's avatar
Pietro Incardona committed
305
306
	 * \return true if they match
	 *
incardon's avatar
incardon committed
307
308
309
310
311
312
313
	 */
	bool operator==(const p_box & pb)
	{
		return pb.lc_proc == lc_proc;
	}
};

incardon's avatar
incardon committed
314
#endif /* SRC_DECOMPOSITION_COMMON_HPP_ */