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

#ifndef SRC_DECOMPOSITION_IE_GHOST_HPP_
#define SRC_DECOMPOSITION_IE_GHOST_HPP_

#include "common.hpp"
incardon's avatar
incardon committed
12 13
#include "nn_processor.hpp"

incardon's avatar
incardon committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*! \brief structure that store and compute the internal and external local ghost box
 *
 * \tparam dim is the dimensionality of the physical domain we are going to decompose.
 * \tparam T type of the space we decompose, Real, Integer, Complex ...
 *
 * \see CartDecomposition
 *
 */
template<unsigned int dim, typename T>
class ie_ghost
{
	//! for each sub-domain (first vector), contain the list (nested vector) of the neighborhood processors
	//! and for each processor contain the boxes calculated from the intersection
	//! of the sub-domains + ghost with the near-by processor sub-domain () and the other way around
	//! \see calculateGhostBoxes
	openfpm::vector< openfpm::vector< Box_proc<dim,T> > > box_nn_processor_int;

	//! It store the same information of box_nn_processor_int organized by processor id
	openfpm::vector< Box_dom<dim,T> > proc_int_box;

incardon's avatar
incardon committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
	// External ghost boxes for this processor, indicated with G8_0 G9_0 ...
	openfpm::vector<p_box<dim,T> > vb_ext;

	// Internal ghost boxes for this processor domain, indicated with B8_0 B9_0 ..... in the figure
	// below as a linear vector
	openfpm::vector<p_box<dim,T> > vb_int;

	//! Cell-list that store the geometrical information of the internal ghost boxes
	CellList<dim,T,FAST> geo_cell;

protected:

	/*! \brief Initialize the geo cell list structure
	 *
	 * The geo cell list structure exist to speed up the labelling the points if they fall on some
	 * internal ghost
	 *
	 */
	void Initialize_geo_cell(const Box<dim,T> & domain, const size_t (&div)[dim] ,const Point<dim,T> & orig)
	{
		// Initialize the geo_cell structure
		geo_cell.Initialize(domain,div,orig);
	}

incardon's avatar
incardon committed
58 59 60 61 62 63 64 65 66 67 68
	/*! \brief Create the box_nn_processor_int (bx part)  structure
	 *
	 * This structure store for each sub-domain of this processors enlarged by the ghost size the boxes that
	 *  come from the intersection with the near processors sub-domains (External ghost box)
	 *
	 * \param ghost margins
	 *
	 * \note Are the G8_0 G9_0 G9_1 G5_0 boxes in calculateGhostBoxes
	 * \see calculateGhostBoxes
	 *
	 */
incardon's avatar
incardon committed
69
	void create_box_nn_processor_ext(Vcluster & v_cl, Ghost<dim,T> & ghost, openfpm::vector<SpaceBox<dim,T>> & sub_domains, const openfpm::vector<openfpm::vector<long unsigned int> > & box_nn_processor, const nn_prcs<dim,T> & nn_p)
incardon's avatar
incardon committed
70
	{
incardon's avatar
incardon committed
71 72
		box_nn_processor_int.resize(sub_domains.size());
		proc_int_box.resize(nn_p.getNNProcessors());
incardon's avatar
incardon committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

		// For each sub-domain
		for (size_t i = 0 ; i < sub_domains.size() ; i++)
		{
			SpaceBox<dim,T> sub_with_ghost = sub_domains.get(i);

			// enlarge the sub-domain with the ghost
			sub_with_ghost.enlarge(ghost);

			// resize based on the number of adjacent processors
			box_nn_processor_int.get(i).resize(box_nn_processor.get(i).size());

			// For each processor adjacent to this sub-domain
			for (size_t j = 0 ; j < box_nn_processor.get(i).size() ; j++)
			{
				// Contiguous processor
				size_t p_id = box_nn_processor.get(i).get(j);

				// store the box in proc_int_box storing from which sub-domain they come from
incardon's avatar
incardon committed
92
				Box_dom<dim,T> & proc_int_box_g = proc_int_box.get(nn_p.ProctoID(p_id));
incardon's avatar
incardon committed
93 94

				// get the set of sub-domains of the adjacent processor p_id
incardon's avatar
incardon committed
95
				const openfpm::vector< ::Box<dim,T> > & nn_processor_subdomains_g = nn_p.getExternalAdjSubdomain(p_id).bx;
incardon's avatar
incardon committed
96 97 98 99 100 101 102 103 104 105 106 107 108

				// near processor sub-domain intersections
				openfpm::vector< ::Box<dim,T> > & box_nn_processor_int_gg = box_nn_processor_int.get(i).get(j).bx;

				// for each near processor sub-domain intersect with the enlarged local sub-domain and store it
				for (size_t b = 0 ; b < nn_processor_subdomains_g.size() ; b++)
				{
					::Box<dim,T> bi;

					bool intersect = sub_with_ghost.Intersect(::Box<dim,T>(nn_processor_subdomains_g.get(b)),bi);

					if (intersect == true)
					{
incardon's avatar
incardon committed
109
						struct p_box<dim,T> pb;
incardon's avatar
incardon committed
110 111 112

						pb.box = bi;
						pb.proc = p_id;
incardon's avatar
incardon committed
113
						pb.lc_proc = nn_p.ProctoID(p_id);
incardon's avatar
incardon committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

						//
						// Updating
						//
						// vb_ext
						// box_nn_processor_int
						// proc_int_box
						//
						// They all store the same information but organized in different ways
						// read the description of each for more information
						//
						vb_ext.add(pb);
						box_nn_processor_int_gg.add(bi);
						proc_int_box_g.ebx.add();
						proc_int_box_g.ebx.last() = bi;
						proc_int_box_g.ebx.last().sub = i;

						// Search for the correct id
						size_t k = 0;
incardon's avatar
incardon committed
133 134
						size_t p_idp = nn_p.ProctoID(p_id);
						for (k = 0 ; k < nn_p.getInternalAdjSubdomain(p_idp).size() ; k++)
incardon's avatar
incardon committed
135
						{
incardon's avatar
incardon committed
136
							if (nn_p.getInternalAdjSubdomain(p_idp).get(k) == i)
incardon's avatar
incardon committed
137 138
								break;
						}
incardon's avatar
incardon committed
139
						if (k == nn_p.getInternalAdjSubdomain(p_idp).size())
incardon's avatar
incardon committed
140 141 142 143 144 145
							std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " sub-domain not found\n";

						proc_int_box_g.ebx.last().id = (k * nn_processor_subdomains_g.size() + b) * v_cl.getProcessingUnits() + p_id;
					}
				}
			}
incardon's avatar
incardon committed
146
		}
incardon's avatar
incardon committed
147 148 149 150 151 152 153 154
	}

	/*! \brief Create the box_nn_processor_int (nbx part) structure, the geo_cell list and proc_int_box
	 *
	 * This structure store for each sub-domain of this processors the boxes that come from the intersection
	 * of the near processors sub-domains enlarged by the ghost size (Internal ghost box). These boxes
	 * fill a geometrical cell list. The proc_int_box store the same information ordered by near processors
	 *
incardon's avatar
incardon committed
155
	 * \param v_cl Virtual cluster
incardon's avatar
incardon committed
156
	 * \param ghost margins
incardon's avatar
incardon committed
157 158 159 160
	 * \param sub_domains
	 * \param box_nn_processors sub-domains of the adjacent processors
	 * \param nn_prcs structure that store the adjacent processor information
	 * \param geo_cell Cell list that store the subdomain information
incardon's avatar
incardon committed
161 162 163 164 165
	 *
	 * \note Are the B8_0 B9_0 B9_1 B5_0 boxes in calculateGhostBoxes
	 * \see calculateGhostBoxes
	 *
	 */
incardon's avatar
incardon committed
166
	void create_box_nn_processor_int(Vcluster & v_cl, Ghost<dim,T> & ghost, openfpm::vector<SpaceBox<dim,T>> & sub_domains, const openfpm::vector<openfpm::vector<long unsigned int> > & box_nn_processor, const nn_prcs<dim,T> & nn_p)
incardon's avatar
incardon committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180
	{
		box_nn_processor_int.resize(sub_domains.size());
		proc_int_box.resize(nn_p.getNNProcessors());

		// For each sub-domain
		for (size_t i = 0 ; i < sub_domains.size() ; i++)
		{
			// For each processor contiguous to this sub-domain
			for (size_t j = 0 ; j < box_nn_processor.get(i).size() ; j++)
			{
				// Contiguous processor
				size_t p_id = box_nn_processor.get(i).get(j);

				// get the set of sub-domains of the contiguous processor p_id
incardon's avatar
incardon committed
181
				const openfpm::vector< ::Box<dim,T> > & nn_p_box = nn_p.getExternalAdjSubdomain(p_id).bx;
incardon's avatar
incardon committed
182 183

				// get the local processor id
incardon's avatar
incardon committed
184
				size_t lc_proc = nn_p.getAdjacentProcessor(p_id);
incardon's avatar
incardon committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

				// For each near processor sub-domains enlarge and intersect with the local sub-domain and store the result
				for (size_t k = 0 ; k < nn_p_box.size() ; k++)
				{

					// enlarge the near-processor sub-domain
					::Box<dim,T> n_sub = nn_p_box.get(k);

					// local sub-domain
					::SpaceBox<dim,T> l_sub = sub_domains.get(i);

					// Create a margin of ghost size around the near processor sub-domain
					n_sub.enlarge(ghost);

					// Intersect with the local sub-domain
incardon's avatar
incardon committed
200
					p_box<dim,T> b_int;
incardon's avatar
incardon committed
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
					bool intersect = n_sub.Intersect(l_sub,b_int.box);

					// store if it intersect
					if (intersect == true)
					{
						// the box fill with the processor id
						b_int.proc = p_id;

						// fill the local processor id
						b_int.lc_proc = lc_proc;

						//
						// Updating
						//
						// vb_int
						// box_nn_processor_int
						// proc_int_box
						//
						// They all store the same information but organized in different ways
						// read the description of each for more information
						//

						// add the box to the near processor sub-domain intersections
						openfpm::vector< ::Box<dim,T> > & p_box_int = box_nn_processor_int.get(i).get(j).nbx;
						p_box_int.add(b_int.box);
						vb_int.add(b_int);

						// store the box in proc_int_box storing from which sub-domain they come from
incardon's avatar
incardon committed
229
						Box_dom<dim,T> & pr_box_int = proc_int_box.get(nn_p.ProctoID(p_id));
incardon's avatar
incardon committed
230 231 232 233 234 235
						Box_sub<dim,T> sb;
						sb = b_int.box;
						sb.sub = i;

						// Search for the correct id
						size_t s = 0;
incardon's avatar
incardon committed
236 237
						size_t p_idp = nn_p.ProctoID(p_id);
						for (s = 0 ; s < nn_p.getInternalAdjSubdomain(p_idp).size() ; s++)
incardon's avatar
incardon committed
238
						{
incardon's avatar
incardon committed
239
							if (nn_p.getInternalAdjSubdomain(p_idp).get(s) == i)
incardon's avatar
incardon committed
240 241
								break;
						}
incardon's avatar
incardon committed
242
						if (s == nn_p.getInternalAdjSubdomain(p_idp).size())
incardon's avatar
incardon committed
243 244
							std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " sub-domain not found\n";

incardon's avatar
incardon committed
245
						sb.id = (k * nn_p.getInternalAdjSubdomain(p_idp).size() + s) * v_cl.getProcessingUnits() + v_cl.getProcessUnitID();
incardon's avatar
incardon committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270

						pr_box_int.ibx.add(sb);

						// update the geo_cell list

						// get the cells this box span
						const grid_key_dx<dim> p1 = geo_cell.getCellGrid(b_int.box.getP1());
						const grid_key_dx<dim> p2 = geo_cell.getCellGrid(b_int.box.getP2());

						// Get the grid and the sub-iterator
						auto & gi = geo_cell.getGrid();
						grid_key_dx_iterator_sub<dim> g_sub(gi,p1,p2);

						// add the box-id to the cell list
						while (g_sub.isNext())
						{
							auto key = g_sub.get();
							geo_cell.addCell(gi.LinId(key),vb_int.size()-1);
							++g_sub;
						}
					}
				}
			}
		}
	}
incardon's avatar
incardon committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351

public:

	/*! \brief Get the number of Internal ghost boxes for one processor
	 *
	 * \param id near processor list id (the id go from 0 to getNNProcessor())
	 * \return the number of internal ghost
	 *
	 */
	inline size_t getProcessorNIGhost(size_t id) const
	{
		return proc_int_box.get(id).ibx.size();
	}

	/*! \brief Get the number of External ghost boxes for one processor id
	 *
	 * \param id near processor list id (the id go from 0 to getNNProcessor())
	 * \return the number of external ghost
	 *
	 */
	inline size_t getProcessorNEGhost(size_t id) const
	{
		return proc_int_box.get(id).ebx.size();
	}

	/*! \brief Get the j Internal ghost box for one processor
	 *
	 * \param id near processor list id (the id go from 0 to getNNProcessor())
	 * \param j box (each near processor can produce more than one internal ghost box)
	 * \return the box
	 *
	 */
	inline const ::Box<dim,T> & getProcessorIGhostBox(size_t id, size_t j) const
	{
		return proc_int_box.get(id).ibx.get(j);
	}

	/*! \brief Get the j External ghost box
	 *
	 * \param id near processor list id (the id go from 0 to getNNProcessor())
	 * \param j box (each near processor can produce more than one external ghost box)
	 * \return the box
	 *
	 */
	inline const ::Box<dim,T> & getProcessorEGhostBox(size_t id, size_t j) const
	{
		return proc_int_box.get(id).ebx.get(j);
	}

	/*! \brief Get the j Internal ghost box id
	 *
	 * \param id near processor list id (the id go from 0 to getNNProcessor())
	 * \param j box (each near processor can produce more than one internal ghost box)
	 * \return the box
	 *
	 */
	inline size_t getProcessorIGhostId(size_t id, size_t j) const
	{
		return proc_int_box.get(id).ibx.get(j).id;
	}

	/*! \brief Get the j External ghost box id
	 *
	 * \param id near processor list id (the id go from 0 to getNNProcessor())
	 * \param j box (each near processor can produce more than one external ghost box)
	 * \return the box
	 *
	 */
	inline size_t getProcessorEGhostId(size_t id, size_t j) const
	{
		return proc_int_box.get(id).ebx.get(j).id;
	}


	/*! \brief Get the local sub-domain at witch belong the internal ghost box
	 *
	 * \param id adjacent processor list id (the id go from 0 to getNNProcessor())
	 * \param j box (each near processor can produce more than one internal ghost box)
	 * \return sub-domain at which belong the internal ghost box
	 *
	 */
incardon's avatar
incardon committed
352
	inline size_t getProcessorIGhostSub(size_t id, size_t j) const
incardon's avatar
incardon committed
353 354 355 356 357 358 359 360 361 362 363
	{
		return proc_int_box.get(id).ibx.get(j).sub;
	}

	/*! \brief Get the local sub-domain at witch belong the external ghost box
	 *
	 * \param id near processor list id (the id go from 0 to getNNProcessor())
	 * \param j box (each near processor can produce more than one external ghost box)
	 * \return sub-domain at which belong the external ghost box
	 *
	 */
incardon's avatar
incardon committed
364
	inline size_t getProcessorEGhostSub(size_t id, size_t j) const
incardon's avatar
incardon committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
	{
		return proc_int_box.get(id).ebx.get(j).sub;
	}

	/*! \brief Return the total number of the calculated internal ghost boxes
	 *
	 * \return the number of internal ghost boxes
	 *
	 */
	inline size_t getNIGhostBox() const
	{
		return vb_int.size();
	}

	/*! \brief Given the internal ghost box id, it return the internal ghost box
	 *
	 * \return the internal ghost box
	 *
	 */
	inline ::Box<dim,T> getIGhostBox(size_t b_id) const
	{
		return vb_int.get(b_id).box;
	}

	/*! \brief Given the internal ghost box id, it return the near processor at witch belong
	 *         or the near processor that produced this internal ghost box
	 *
	 * \return the processor id of the ghost box
	 *
	 */
	inline size_t getIGhostBoxProcessor(size_t b_id) const
	{
		return vb_int.get(b_id).proc;
	}

	/*! \brief Get the number of the calculated external ghost boxes
	 *
	 * \return the number of external ghost boxes
	 *
	 */
	inline size_t getNEGhostBox() const
	{
		return vb_ext.size();
	}

	/*! \brief Given the external ghost box id, it return the external ghost box
	 *
	 * \return the external ghost box
	 *
	 */
	inline ::Box<dim,T> getEGhostBox(size_t b_id) const
	{
		return vb_ext.get(b_id).box;
	}

	/*! \brief Given the external ghost box id, it return the near processor at witch belong
	 *         or the near processor that produced this external ghost box
	 *
	 * \return the processor id of the external ghost box
	 *
	 */
	inline size_t getEGhostBoxProcessor(size_t b_id) const
	{
		return vb_ext.get(b_id).proc;
	}

	/*! /brief Given a point it return the set of boxes in which the point fall
	 *
	 * \param p Point to check
	 * \return An iterator with the id's of the internal boxes in which the point fall
	 *
	 */
	auto getInternalIDBoxes(Point<dim,T> & p) -> decltype(geo_cell.getIterator(geo_cell.getCell(p)))
	{
		return geo_cell.getIterator(geo_cell.getCell(p));
	}

	/*! \brief if the point fall into the ghost of some near processor it return the processors id's in which
	 *  it fall
	 *
	 * \param p Point
	 * \return iterator of the processors id's
	 *
	 */
	inline auto labelPoint(Point<dim,T> & p) -> decltype(geo_cell.getIterator(geo_cell.getCell(p)))
	{
		return geo_cell.getIterator(geo_cell.getCell(p));
	}

	openfpm::vector<size_t> ids;

	/*! \brief Given a position it return if the position belong to any neighborhood processor ghost
	 * (Internal ghost)
	 *
	 * \tparam id type of if to get box_id processor_id lc_processor_id
	 * \param p Particle position
	 * \param opt intersection boxes of the same processor can overlap, so in general the function
	 *        can produce more entry with the same processor, the UNIQUE option eliminate double entries
	 *        (UNIQUE) is for particle data (MULTIPLE) is for grid data [default MULTIPLE]
	 *
	 * \param return the processor ids
	 *
	 */
	template <typename id> inline const openfpm::vector<size_t> ghost_processorID(Point<dim,T> & p, const int opt = MULTIPLE)
	{
		ids.clear();

		// Check with geo-cell if a particle is inside one Cell containing boxes

		auto cell_it = geo_cell.getIterator(geo_cell.getCell(p));

		// For each element in the cell, check if the point is inside the box
		// if it is, store the processor id
		while (cell_it.isNext())
		{
			size_t bid = cell_it.get();

			if (vb_int.get(bid).box.isInside(p) == true)
			{
				ids.add(id::id(vb_int.get(bid),bid));
			}

			++cell_it;
		}

		// Make the id unique
		if (opt == UNIQUE)
			ids.unique();

		return ids;
	}

	/*! \brief Given a position it return if the position belong to any neighborhood processor ghost
	 * (Internal ghost)
	 *
	 * \tparam id type of if to get box_id processor_id lc_processor_id
	 * \param p Particle position
	 *
	 * \param return the processor ids
	 *
	 */
	template<typename id, typename Mem> inline const openfpm::vector<size_t> ghost_processorID(const encapc<1,Point<dim,T>,Mem> & p, const int opt = MULTIPLE)
	{
		ids.clear();

		// Check with geo-cell if a particle is inside one Cell containing boxes

		auto cell_it = geo_cell.getIterator(geo_cell.getCell(p));

		// For each element in the cell, check if the point is inside the box
		// if it is, store the processor id
		while (cell_it.isNext())
		{
			size_t bid = cell_it.get();

			if (vb_int.get(bid).box.isInside(p) == true)
			{
				ids.add(id::id(vb_int.get(bid),bid));
			}

			++cell_it;
		}

		// Make the id unique
		if (opt == UNIQUE)
			ids.unique();

		return ids;
	}

	/*! \brief write the information about the ghost in vtk format
	 *
	 * 1) internal_ghost_X.vtk Internal ghost boxes for the local processor (X)
	 * 2) external_ghost_X.vtk External ghost boxes for the local processor (X)
	 *
	 * \param output directory
	 * \param p_id processor rank
	 *
	 */
	bool write(std::string output, size_t p_id) const
	{
		//! internal_ghost_X.vtk Internal ghost boxes for the local processor (X)
		VTKWriter<openfpm::vector<::Box<dim,T>>,VECTOR_BOX> vtk_box3;
		for (size_t p = 0 ; p < box_nn_processor_int.size() ; p++)
		{
			for (size_t s = 0 ; s < box_nn_processor_int.get(p).size() ; s++)
			{
				vtk_box3.add(box_nn_processor_int.get(p).get(s).nbx);
			}
		}
		vtk_box3.write(output + std::string("internal_ghost_") + std::to_string(p_id) + std::string(".vtk"));

		//! external_ghost_X.vtk External ghost boxes for the local processor (X)
		VTKWriter<openfpm::vector<::Box<dim,T>>,VECTOR_BOX> vtk_box4;
		for (size_t p = 0 ; p < box_nn_processor_int.size() ; p++)
		{
			for (size_t s = 0 ; s < box_nn_processor_int.get(p).size() ; s++)
			{
				vtk_box4.add(box_nn_processor_int.get(p).get(s).bx);
			}
		}
		vtk_box4.write(output + std::string("external_ghost_") + std::to_string(p_id) + std::string(".vtk"));

		return true;
	}
incardon's avatar
incardon committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584

	/*! \brief Check if the ie_loc_ghosts contain the same information
	 *
	 * \param ele Element to check
	 *
	 */
	bool is_equal(ie_ghost<dim,T> & ig)
	{
		if (getNEGhostBox() != ig.getNEGhostBox())
			return false;

		if (getNIGhostBox() != ig.getNIGhostBox())
			return false;

		for (size_t i = 0 ; i < getNIGhostBox() ; i++)
incardon's avatar
incardon committed
585 586 587 588 589 590 591 592
		{
			if (getIGhostBox(i) != ig.getIGhostBox(i))
				return false;
			if (getIGhostBoxProcessor(i) != ig.getIGhostBoxProcessor(i))
				return false;
		}

		for (size_t i = 0 ; i < proc_int_box.size() ; i++)
incardon's avatar
incardon committed
593 594 595 596 597 598 599 600 601 602 603 604
		{
			if (getProcessorNIGhost(i) != ig.getProcessorNIGhost(i))
				return false;
			for (size_t j = 0 ; j < getProcessorNIGhost(i) ; j++)
			{
				if (getProcessorIGhostBox(i,j) != ig.getProcessorIGhostBox(i,j))
					return false;
				if (getProcessorIGhostId(i,j) != ig.getProcessorIGhostId(i,j))
					return false;
				if (getProcessorIGhostSub(i,j) != ig.getProcessorIGhostSub(i,j))
					return false;
			}
incardon's avatar
incardon committed
605 606 607 608 609
		}

		for (size_t i = 0 ; i < getNEGhostBox() ; i++)
		{
			if (getEGhostBox(i) != ig.getEGhostBox(i))
incardon's avatar
incardon committed
610
				return false;
incardon's avatar
incardon committed
611
			if (getEGhostBoxProcessor(i) != ig.getEGhostBoxProcessor(i))
incardon's avatar
incardon committed
612 613 614
				return false;
		}

incardon's avatar
incardon committed
615
		for (size_t i = 0 ; i < proc_int_box.size() ; i++)
incardon's avatar
incardon committed
616 617 618 619 620 621 622 623 624 625 626 627 628
		{
			if (getProcessorNEGhost(i) != ig.getProcessorNEGhost(i))
				return false;
			for (size_t j = 0 ; j < getProcessorNEGhost(i) ; j++)
			{
				if (getProcessorEGhostBox(i,j) != ig.getProcessorEGhostBox(i,j))
					return false;
				if (getProcessorEGhostId(i,j) != ig.getProcessorEGhostId(i,j))
					return false;
				if (getProcessorEGhostSub(i,j) != ig.getProcessorEGhostSub(i,j))
					return false;
			}
		}
Pietro Incardona's avatar
Pietro Incardona committed
629 630

		return true;
incardon's avatar
incardon committed
631
	}
incardon's avatar
incardon committed
632 633 634 635 636 637 638 639 640

	/*! \brief Check if the ie_loc_ghosts contain the same information with the exception of the ghost part
	 * It is anyway required that the ghost come from the same sub-domains decomposition
	 *
	 * \param ele Element to check
	 *
	 */
	bool is_equal_ng(ie_ghost<dim,T> & ig)
	{
incardon's avatar
incardon committed
641
		Box<dim,T> bt;
incardon's avatar
incardon committed
642 643 644 645 646 647 648 649 650 651 652 653 654

		if (getNEGhostBox() != ig.getNEGhostBox())
			return false;

		if (getNIGhostBox() != ig.getNIGhostBox())
			return false;

		for (size_t i = 0 ; i < getNIGhostBox() ; i++)
		{
			if (getProcessorNIGhost(i) != ig.getProcessorNIGhost(i))
				return false;
			for (size_t j = 0 ; j < getProcessorNIGhost(i) ; j++)
			{
Pietro Incardona's avatar
Pietro Incardona committed
655
				if (getProcessorIGhostBox(i,j).Intersect(ig.getProcessorIGhostBox(i,j),bt) == false)
incardon's avatar
incardon committed
656
					return false;
Pietro Incardona's avatar
Pietro Incardona committed
657
				if (getProcessorIGhostId(i,j) != ig.getProcessorIGhostId(i,j))
incardon's avatar
incardon committed
658 659 660 661
					return false;
				if (getProcessorIGhostSub(i,j) != ig.getProcessorIGhostSub(i,j))
					return false;
			}
Pietro Incardona's avatar
Pietro Incardona committed
662
			if (getIGhostBox(i).Intersect(ig.getIGhostBox(i),bt) == false)
incardon's avatar
incardon committed
663 664 665 666 667 668 669 670 671 672 673
				return false;
			if (getIGhostBoxProcessor(i) != ig.getIGhostBoxProcessor(i))
				return false;
		}

		for (size_t i = 0 ; i < getNEGhostBox() ; i++)
		{
			if (getProcessorNEGhost(i) != ig.getProcessorNEGhost(i))
				return false;
			for (size_t j = 0 ; j < getProcessorNEGhost(i) ; j++)
			{
Pietro Incardona's avatar
Pietro Incardona committed
674
				if (getProcessorEGhostBox(i,j).Intersect(ig.getProcessorEGhostBox(i,j),bt) == false)
incardon's avatar
incardon committed
675
					return false;
Pietro Incardona's avatar
Pietro Incardona committed
676
				if (getProcessorEGhostId(i,j) !=  ig.getProcessorEGhostId(i,j))
incardon's avatar
incardon committed
677 678 679 680
					return false;
				if (getProcessorEGhostSub(i,j) != ig.getProcessorEGhostSub(i,j))
					return false;
			}
Pietro Incardona's avatar
Pietro Incardona committed
681
			if (getEGhostBox(i).Intersect(ig.getEGhostBox(i),bt) == false)
incardon's avatar
incardon committed
682
				return false;
Pietro Incardona's avatar
Pietro Incardona committed
683
			if (getEGhostBoxProcessor(i) != ig.getEGhostBoxProcessor(i))
incardon's avatar
incardon committed
684 685
				return false;
		}
Pietro Incardona's avatar
Pietro Incardona committed
686 687

		return true;
incardon's avatar
incardon committed
688
	}
incardon's avatar
incardon committed
689 690 691 692
};


#endif /* SRC_DECOMPOSITION_IE_GHOST_HPP_ */