From baf78730bad2195b044f312e8bce66b070f00011 Mon Sep 17 00:00:00 2001
From: Pietro Incardona <i-bird@linux-2.fritz.box>
Date: Sun, 15 Nov 2015 22:17:11 -0500
Subject: [PATCH] Add pdata

---
 src/Decomposition/CartDecomposition.hpp       | 30 +++++---
 .../CartDecomposition_unit_test.hpp           |  8 +--
 src/Decomposition/ie_ghost.hpp                | 18 +++--
 src/Grid/grid_dist_id.hpp                     | 69 +++++++++++++------
 4 files changed, 82 insertions(+), 43 deletions(-)

diff --git a/src/Decomposition/CartDecomposition.hpp b/src/Decomposition/CartDecomposition.hpp
index 1390ea43..f205a31d 100644
--- a/src/Decomposition/CartDecomposition.hpp
+++ b/src/Decomposition/CartDecomposition.hpp
@@ -593,7 +593,7 @@ p1[0]<-----+         +----> p2[0]
 	 * \return a duplicated decomposition with different ghost boxes
 	 *
 	 */
-	CartDecomposition<dim,T,Memory,Domain> duplicate(Ghost<dim,T> & g)
+	CartDecomposition<dim,T,Memory,Domain> duplicate(const Ghost<dim,T> & g)
 	{
 		CartDecomposition<dim,T,Memory,Domain> cart(v_cl);
 
@@ -613,10 +613,10 @@ p1[0]<-----+         +----> p2[0]
 		cart.ss_box = ss_box;
 		cart.ghost = g;
 
-		nn_prcs<dim,T>::create(box_nn_processor, sub_domains);
+		cart.create(box_nn_processor, sub_domains);
 
-		calculateGhostBoxes();
-		Initialize_geo_cell_lists();
+		cart.Initialize_geo_cell_lists();
+		cart.calculateGhostBoxes();
 
 		return cart;
 	}
@@ -955,9 +955,14 @@ p1[0]<-----+         +----> p2[0]
 	 */
 	bool is_equal(CartDecomposition<dim,T,Memory,Domain> & cart)
 	{
-		static_cast<ie_loc_ghost<dim,T>*>(this)->is_equal(static_cast<ie_loc_ghost<dim,T>&>(cart));
-		static_cast<nn_prcs<dim,T>*>(this)->is_equal(static_cast<nn_prcs<dim,T>&>(cart));
-		static_cast<ie_ghost<dim,T>*>(this)->is_equal(static_cast<ie_ghost<dim,T>&>(cart));
+		if (static_cast<ie_loc_ghost<dim,T>*>(this)->is_equal(static_cast<ie_loc_ghost<dim,T>&>(cart)) == false)
+			return false;
+
+		if (static_cast<nn_prcs<dim,T>*>(this)->is_equal(static_cast<nn_prcs<dim,T>&>(cart)) == false)
+			return false;
+
+		if (static_cast<ie_ghost<dim,T>*>(this)->is_equal(static_cast<ie_ghost<dim,T>&>(cart)) == false)
+			return false;
 
 		if (sub_domains != cart.sub_domains)
 			return false;
@@ -994,9 +999,14 @@ p1[0]<-----+         +----> p2[0]
 	 */
 	bool is_equal_ng(CartDecomposition<dim,T,Memory,Domain> & cart)
 	{
-		static_cast<ie_loc_ghost<dim,T>*>(this)->is_equal_ng(static_cast<ie_loc_ghost<dim,T>&>(cart));
-		static_cast<nn_prcs<dim,T>*>(this)->is_equal(static_cast<nn_prcs<dim,T>&>(cart));
-		static_cast<ie_ghost<dim,T>*>(this)->is_equal(static_cast<ie_ghost<dim,T>&>(cart));
+		if (static_cast<ie_loc_ghost<dim,T>*>(this)->is_equal_ng(static_cast<ie_loc_ghost<dim,T>&>(cart)) == false)
+			return false;
+
+		if (static_cast<nn_prcs<dim,T>*>(this)->is_equal(static_cast<nn_prcs<dim,T>&>(cart)) == false)
+			return false;
+
+		if (static_cast<ie_ghost<dim,T>*>(this)->is_equal_ng(static_cast<ie_ghost<dim,T>&>(cart)) == false)
+			return false;
 
 		if (sub_domains != cart.sub_domains)
 			return false;
diff --git a/src/Decomposition/CartDecomposition_unit_test.hpp b/src/Decomposition/CartDecomposition_unit_test.hpp
index 661bc1de..4606a765 100644
--- a/src/Decomposition/CartDecomposition_unit_test.hpp
+++ b/src/Decomposition/CartDecomposition_unit_test.hpp
@@ -80,13 +80,12 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_use)
 	CartDecomposition<3,float> dec2 = dec.duplicate();
 	dec2.check_consistency();
 
+	// check that dec and dec2 contain the same information
 	bool ret = dec.is_equal(dec2);
 
 	// We check if the two decomposition are equal
 	BOOST_REQUIRE_EQUAL(ret,true);
 
-	// check that dec and dec2 contain the same information
-
 	// We duplicate the decomposition redefining the ghost
 
 	// Define ghost
@@ -98,10 +97,11 @@ BOOST_AUTO_TEST_CASE( CartDecomposition_test_use)
 	ret = dec3.check_consistency();
 	BOOST_REQUIRE_EQUAL(ret,true);
 
-	// Check that g3 is equal to dec2 with the exception of the ghost part
+	dec3.write("output_dec3_1.vtk");
+
+	// Check that dec3 is equal to dec2 with the exception of the ghost part
 	ret = dec3.is_equal_ng(dec2);
 	BOOST_REQUIRE_EQUAL(ret,true);
-
 }
 
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/Decomposition/ie_ghost.hpp b/src/Decomposition/ie_ghost.hpp
index 0d8b8314..99953ee3 100644
--- a/src/Decomposition/ie_ghost.hpp
+++ b/src/Decomposition/ie_ghost.hpp
@@ -626,6 +626,8 @@ public:
 					return false;
 			}
 		}
+
+		return true;
 	}
 
 	/*! \brief Check if the ie_loc_ghosts contain the same information with the exception of the ghost part
@@ -650,14 +652,14 @@ public:
 				return false;
 			for (size_t j = 0 ; j < getProcessorNIGhost(i) ; j++)
 			{
-				if (getProcessorIGhostBox(i,j).intersect(ig.getProcessorIGhostBox(i,j),bt) == false)
+				if (getProcessorIGhostBox(i,j).Intersect(ig.getProcessorIGhostBox(i,j),bt) == false)
 					return false;
-				if (getProcessorIGhostId(i,j).intersect(ig.getProcessorIGhostId(i,j),bt) == false)
+				if (getProcessorIGhostId(i,j) != ig.getProcessorIGhostId(i,j))
 					return false;
 				if (getProcessorIGhostSub(i,j) != ig.getProcessorIGhostSub(i,j))
 					return false;
 			}
-			if (getIGhostBox(i) != ig.getIGhostBox(i))
+			if (getIGhostBox(i).Intersect(ig.getIGhostBox(i),bt) == false)
 				return false;
 			if (getIGhostBoxProcessor(i) != ig.getIGhostBoxProcessor(i))
 				return false;
@@ -669,18 +671,20 @@ public:
 				return false;
 			for (size_t j = 0 ; j < getProcessorNEGhost(i) ; j++)
 			{
-				if (getProcessorEGhostBox(i,j).intersect(ig.getProcessorEGhostBox(i,j),bt) == false)
+				if (getProcessorEGhostBox(i,j).Intersect(ig.getProcessorEGhostBox(i,j),bt) == false)
 					return false;
-				if (getProcessorEGhostId(i,j),intersect(ig.getProcessorEGhostId(i,j),bt) == false)
+				if (getProcessorEGhostId(i,j) !=  ig.getProcessorEGhostId(i,j))
 					return false;
 				if (getProcessorEGhostSub(i,j) != ig.getProcessorEGhostSub(i,j))
 					return false;
 			}
-			if (getEGhostBox(i) != ig.getEGhostBox(i))
+			if (getEGhostBox(i).Intersect(ig.getEGhostBox(i),bt) == false)
 				return false;
-			if (getEGhostBoxProcessor(i).intersect(ig.getEGhostBoxProcessor(i),bt) == false)
+			if (getEGhostBoxProcessor(i) != ig.getEGhostBoxProcessor(i))
 				return false;
 		}
+
+		return true;
 	}
 };
 
diff --git a/src/Grid/grid_dist_id.hpp b/src/Grid/grid_dist_id.hpp
index 5c663df5..f6637d0c 100644
--- a/src/Grid/grid_dist_id.hpp
+++ b/src/Grid/grid_dist_id.hpp
@@ -487,9 +487,37 @@ public:
 	// Decomposition used
 	typedef Decomposition decomposition;
 
+	static inline Ghost<dim,float> convert_ghost(const Ghost<dim,long int> & gd,const CellDecomposer_sm<dim,St> & cd_sm)
+	{
+		Ghost<dim,float> gc;
+
+		// get the grid spacing
+		Box<dim,St> sp = cd_sm.getCellBox();
+
+		// enlarge 0.001 of the spacing
+		sp.magnify_fix_P1(1.1);
+
+		// set the ghost
+		for (size_t i = 0 ; i < dim ; i++)
+		{
+			gc.setLow(i,-sp.getHigh(i));
+			gc.setHigh(i,sp.getHigh(i));
+		}
+
+		return gc;
+	}
+
 
     //! constructor
     grid_dist_id(Decomposition & dec, const size_t (& g_sz)[dim], const Box<dim,St> & domain, const Ghost<dim,St> & ghost)
+    :domain(domain),ghost(ghost),dec(dec),v_cl(*global_v_cluster)
+	{
+		InitializeCellDecomposer(g_sz);
+		InitializeStructures(g_sz);
+	}
+
+    //! constructor
+    grid_dist_id(Decomposition && dec, const size_t (& g_sz)[dim], const Box<dim,St> & domain, const Ghost<dim,St> & ghost)
     :domain(domain),ghost(ghost),dec(dec),v_cl(*global_v_cluster)
 	{
 		InitializeCellDecomposer(g_sz);
@@ -523,18 +551,7 @@ public:
 	{
 		InitializeCellDecomposer(g_sz);
 
-		// get the grid spacing
-		Box<dim,St> sp = cd_sm.getCellBox();
-
-		// enlarge 0.001 of the spacing
-		sp.magnify_fix_P1(1.1);
-
-		// set the ghost
-		for (size_t i = 0 ; i < dim ; i++)
-		{
-			ghost.setLow(i,-sp.getHigh(i));
-			ghost.setHigh(i,sp.getHigh(i));
-		}
+		ghost = convert_ghost(g,cd_sm);
 
 		InitializeDecomposition(g_sz);
 		// Initialize structures
@@ -553,18 +570,26 @@ public:
 	{
 		InitializeCellDecomposer(g_sz);
 
-		// get the grid spacing
-		Box<dim,St> sp = cd_sm.getCellBox();
+		ghost = convert_ghost(g,cd_sm);
 
-		// enlarge 0.001 of the spacing
-		sp.magnify_fix_P1(1.1);
+		InitializeDecomposition(g_sz);
+		// Initialize structures
+		InitializeStructures(g_sz);
+	}
 
-		// set the ghost
-		for (size_t i = 0 ; i < dim ; i++)
-		{
-			ghost.setLow(i,-sp.getHigh(i));
-			ghost.setHigh(i,sp.getHigh(i));
-		}
+	/*! \brief Constrcuctor
+	 *
+	 * \param g_sz array with the grid size on each dimension
+	 * \param domain domain where this grid live
+	 * \param g Ghost given in grid units
+	 *
+	 */
+	grid_dist_id(Decomposition && dec, const size_t (& g_sz)[dim],const Box<dim,St> & domain, const Ghost<dim,long int> & g)
+	:domain(domain),dec(dec),v_cl(*global_v_cluster),ginfo(g_sz),ginfo_v(g_sz)
+	{
+		InitializeCellDecomposer(g_sz);
+
+		ghost = convert_ghost(g,cd_sm);
 
 		InitializeDecomposition(g_sz);
 		// Initialize structures
-- 
GitLab