CartDecomposition.cpp 2.75 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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 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
/*
 * CartDecomposition.cpp
 *
 *  Created on: Aug 15, 2014
 *      Author: Pietro Incardona
 */

#include "CartDecomposition.hpp"



/*! \brief The the bulk part of the data set, or the data that does not depend
 *  from the ghosts layers
 *
 * The the bulk part of the data set, or the data that does not depend from the
 *  ghosts layers
 *
 */

/*template<typename T> T CartDecomposition<T>::getBulk(T data)
{
	// for each element in data

	for (size_t i = 0; i < data.size() ; i++)
	{
		if (localSpace.isInside())
	}

}

template<typename T> T CartDecomposition<T>::getInternal()
{

}*/

/*! \brief Check if is border or bulk
 *
 * \param neighboorhood define the neighboorhood of all the points
 * \return true if border, false if bulk
 *
 */

bool borderOrBulk(neighborhood & nb)
{
	device::grid<1,size_t> nbr = nb.next();

	// check the neighborhood

	// get neighborhood iterator

	grid_key_dx_iterator<dim> iterator_nbr = nbr.getIterator();

	while (iterator_nbr.hasNext())
	{
		grid_key_dx key_nbr = iterator_nbr.next();

		// check if the neighboorhood is internal

		if(subspace.isBound(data.template get<Point::x>(key_nbr)) == false)
		{
			// it is border

			return true;

			ret.bord.push_back(key);
			break;
		}
	}

	return false;
}

/*! \brief This function divide the data set into bulk, border, external and internal part
 *
 * \tparam dim dimensionality of the structure storing your data
 *         (example if they are in 3D grid, has to be 3)
 * \tparam T type of object we are dividing
 * \tparam device type of layout selected
 * \param data 1-dimensional grid of point
 * \param nb define the neighborhood of all the points
 * \return a structure with the set of objects divided
 *
 */

template<unsigned int dim, typename T, template<typename> class layout, typename Memory, template<unsigned int, typename> class Domain, template<typename, typename, typename> class data_s>
dataDiv<T> CartDecomposition<dim,T,layout>::divide(device::grid<1,Point<dim,T>> & data, neighborhood & nb)
{
	//! allocate the 3 subset

	dataDiv<T> ret;

	ret.bord = new boost::shared_ptr<T>(new T());
	ret.inte = new boost::shared_ptr<T>(new T());
	ret.ext = new boost::shared_ptr<T>(new T());

	//! get grid iterator

	grid_key_dx_iterator<dim> iterator = data.getIterator();

	//! we iterate trough all the set of objects

	while (iterator.hasNext())
	{
		grid_key_dx<dim> key = iterator.next();

		//! Check if the object is inside the subspace

		if (subspace.isBound(data.template get<Point<3,T>::x>(key)))
		{
			//! Check if the neighborhood is inside the subspace

			if (borderOrBulk(nb) == true)
			{
				// It is border

				ret.bord.push_back(key);
			}
			else
			{
				// It is bulk

				ret.bulk.push_back(key);
			}
		}
		else
		{
			//! it is external

			ret.ext.push_back(key);
		}
	}
}