common.hpp 6.13 KB
Newer Older
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

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
{
28
	//! Box defining the sub-domain (copied)
29 30
	Box<dim,T> bx;

31
	//! The id of the real domain
32
	size_t sub;
33

34
	//! in witch sector this sub-domain live
35 36
	comb<dim> cmb;

37
	//! Constructor
38
	Box_loc_sub()
39
	:sub(0)
40 41 42 43
	{
		cmb.zero();
	};

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)
	{};

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;
	}


};
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)
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())
66 67 68 69
 *
 *
 */
template<unsigned int dim, typename T>
70
struct Box_sub
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
76 77
	size_t sub;

Pietro Incardona's avatar
Pietro Incardona committed
78
	//! see ebx_ibx_form in ie_ghost for the meaning
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;
86 87 88 89
};

//! Particular case for local internal ghost boxes
template<unsigned int dim, typename T>
90
struct Box_sub_k
91
{
92
	//! extension of this local internal ghost box
93 94
	Box<dim,T> bx;

95
	//! Domain id
96 97
	size_t sub;

98
	//! Where this sub_domain live
99 100
	comb<dim> cmb;

101 102 103
	//! k \see getLocalGhostIBoxE
	long int k;

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

//! Case for local ghost box
template<unsigned int dim, typename T>
struct lBox_dom
{
115 116
	//! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor
	//! sub-domains (External ghost)
incardon's avatar
incardon committed
117
	openfpm::vector_std< Box_sub_k<dim,T> > ebx;
118

119 120
	//! Intersection between the contiguous processor sub-domain enlarged by the ghost with the
	//! local sub-domain (Internal ghost)
121 122 123
	openfpm::vector_std< Box_sub_k<dim,T>> ibx;
};

124
//! Case for local external ghost box
125 126 127
template<unsigned int dim, typename T>
struct Box_proc
{
128 129
	//! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor
	//! sub-domains (External ghost)
130 131
	openfpm::vector<::Box<dim,T>> bx;

132 133
	//! Intersection between the contiguous processor sub-domain enlarged by the ghost with the
	//! local sub-domain (Internal ghost)
134 135 136
	openfpm::vector<::Box<dim,T>> nbx;


137
	//! processor
138 139 140
	size_t proc;
};

141
//! Case for external ghost box
142 143 144
template<unsigned int dim, typename T>
struct Box_dom
{
145 146
	//! Intersection between the local sub-domain enlarged by the ghost and the contiguous processor
	//! sub-domains (External ghost)
147 148
	openfpm::vector_std< Box_sub<dim,T> > ebx;

149 150
	//! Intersection between the contiguous processor sub-domain enlarged by the ghost with the
	//! local sub-domain (Internal ghost)
151 152 153
	openfpm::vector_std< Box_sub<dim,T> > ibx;
};

154
// It store the sub-domain sent by the near processors
155 156 157
template<unsigned int dim, typename T>
struct N_box
{
158
	//! id of the processor in the nn_processor list (local processor id)
159 160
	size_t id;

161
	//! near processor sub-domains
162
	typename openfpm::vector<::Box<dim,T>> bx;
163

164
	//! near processor sector position (or where they live outside the domain)
165 166
	openfpm::vector<comb<dim>> pos;

167
	//! Number of real sub-domains or sub-domain in the central sector
168 169
	size_t n_real_sub;

170 171 172
	//! 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
173 174
	openfpm::vector<size_t> r_sub;

175
	//! Default constructor
176
	N_box()
Pietro Incardona's avatar
Pietro Incardona committed
177
	:id((size_t)-1),n_real_sub(0)
178
	{};
179 180 181

	//! Copy constructor
	N_box(const N_box<dim,T> & b)
182
	:id((size_t)-1),n_real_sub(0)
183 184 185 186 187 188
	{
		this->operator=(b);
	}

	//! Copy constructor
	N_box(N_box<dim,T> && b)
189
	:id((size_t)-1),n_real_sub(0)
190 191 192 193 194 195 196 197
	{
		this->operator=(b);
	}

	/*! \brief Copy the element
	 *
	 * \param ele element to copy
	 *
198 199
	 * \return itself
	 *
200 201 202 203 204
	 */
	N_box<dim,T> & operator=(const N_box<dim,T> & ele)
	{
		id = ele.id;
		bx = ele.bx;
205
		pos = ele.pos;
206 207
		n_real_sub = ele.n_real_sub;
		r_sub = ele.r_sub;
208 209 210 211 212 213 214 215

		return * this;
	}

	/*! \brief Copy the element
	 *
	 * \param ele element to copy
	 *
216 217
	 * \return itself
	 *
218 219 220 221 222
	 */
	N_box<dim,T> & operator=(N_box<dim,T> && ele)
	{
		id = ele.id;
		bx.swap(ele.bx);
223 224 225
		pos.swap(ele.pos);
		n_real_sub = ele.n_real_sub;
		r_sub.swap(ele.r_sub);
226 227 228

		return * this;
	}
229 230

	/*! \brief Compare two N_box object
231 232
	 *
	 * \param ele element to compare with
233 234 235 236 237 238 239 240 241
	 *
	 * \return true if they match
	 *
	 */
	bool operator==(const N_box<dim,T> & ele) const
	{
		if (id != ele.id)
			return false;

242 243 244
		if (pos != ele.pos)
			return false;

245 246 247 248 249 250
		if (r_sub != ele.r_sub)
			return false;

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

251 252 253 254
		return bx == ele.bx;
	}

	/*! \brief Compare two N_box object
255 256
	 *
	 * \param ele element to compare with
257 258 259 260 261 262 263 264
	 *
	 * \return true if they match
	 *
	 */
	bool operator!=(const N_box<dim,T> & ele) const
	{
		return ! this->operator==(ele);
	}
265 266
};

267
//! It store all the boxes of the near processors in a linear array
incardon's avatar
incardon committed
268 269 270 271 272 273 274 275
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;
276
	//! processor rank
incardon's avatar
incardon committed
277 278
	size_t proc;

279 280 281
	//! shift vector id
	size_t shift_id;

incardon's avatar
incardon committed
282 283 284 285
	/*! \brief Check if two p_box are the same
	 *
	 * \param pb box to check
	 *
286 287
	 * \return true if they match
	 *
incardon's avatar
incardon committed
288 289 290 291 292 293 294
	 */
	bool operator==(const p_box & pb)
	{
		return pb.lc_proc == lc_proc;
	}
};

295
#endif /* SRC_DECOMPOSITION_COMMON_HPP_ */