DrawParticles.hpp 4.77 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 * DrawParticles.hpp
 *
 *  Created on: Jan 5, 2017
 *      Author: i-bird
 */

#ifndef OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_HPP_
#define OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_HPP_

#include "PointIterator.hpp"
#include "PointIteratorSkin.hpp"
#include "Vector/vector_dist.hpp"

15 16 17 18 19 20 21
/*! \brief A class to draw/create particles based on simple shaped
 *
 * ## Draw box example
 *
 * \snippet Draw/DrawParticles_unit_tests.hpp DrawBox_example
 *
 */
incardon's avatar
incardon committed
22 23 24 25
class DrawParticles
{
public:

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
	/*! \brief Draw particles in a box B excluding the area of a second box A (B - A)
	 *
	 * The function return an iterator over particles defined on a virtual grid in the simulation domain.
	 *
	 * \param vd particles where we are creating the particles
	 * \param sz indicate the grid size of the virtual grid.
	 * \param domain Domain where the virtual grid is defined (Must match the domain of vd)
	 * \param sub_B box contained in domain that define where the particle iterator must iterate,
	 *            particles are placed strictly inside this box
	 * \param sub_A box contained in the domain that define where the particle iterator should not
	 *              iterate (excluding area)
	 *
	 * \note Suppose to have a simulation domain of 1.5 on x and we use sz = 16. Consider now
	 * to have particles with spacing 0.1 on x. if we define a sub_A that on extend from 0.65
	 *  to 0.95 the first fluid particle
	 * is at 0.70 and the last is at 0.90
	 *
	 * \return an iterator to the selected particles
	 *
	 */
incardon's avatar
incardon committed
46 47 48
	template<unsigned int dim, typename T, typename vd_type>
	static PointIteratorSkin<dim,T,typename vd_type::Decomposition_type>
	DrawSkin(vd_type & vd,
incardon's avatar
incardon committed
49 50 51 52 53 54 55 56 57 58
			 size_t (& sz)[dim],
			 Box<dim,T> & domain,
			 Box<dim,T> & sub_A,
			 Box<dim,T> & sub_B)
	{
		size_t bc[dim];

		for (size_t i = 0 ; i < dim ; i++)
			bc[i] = NON_PERIODIC;

incardon's avatar
incardon committed
59
		return PointIteratorSkin<dim,T,typename vd_type::Decomposition_type>(vd.getDecomposition(),sz,vd.getDecomposition().getDomain(),sub_A, sub_B, bc);
incardon's avatar
incardon committed
60 61
	}

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

	/*! \brief Draw particles in a box B excluding the areas of an array of boxes A_n
	 *
	 * The function return an iterator over particles defined on a virtual grid in the simulation domain.
	 *
	 * \param vd particles where we are creating the particles
	 * \param sz indicate the grid size of the virtual grid.
	 * \param domain Domain where the virtual grid is defined (Must match the domain of vd)
	 * \param sub_B box contained in domain that define where the particle iterator must iterate,
	 *            particles are placed strictly inside this box
	 * \param sub_A array of boxes contained in the domain that define where the particle iterator should not
	 *              iterate (excluding areas)
	 *
	 * \note Suppose to have a simulation domain of 1.5 on x and we use sz = 16. Consider now
	 * to have particles with spacing 0.1 on x. if we define a sub_A that on extend from 0.65
	 *  to 0.95 the first fluid particle
	 * is at 0.70 and the last is at 0.90
	 *
	 * \return an iterator to the selected particles
	 *
	 */
incardon's avatar
incardon committed
83 84 85
	template<unsigned int dim, typename T, typename vd_type>
	static PointIteratorSkin<dim,T,typename vd_type::Decomposition_type>
	DrawSkin(vd_type & vd,
incardon's avatar
incardon committed
86 87 88 89 90 91 92 93 94 95
			 size_t (& sz)[dim],
			 Box<dim,T> & domain,
			 openfpm::vector<Box<dim,T>> & sub_A,
			 Box<dim,T> & sub_B)
	{
		size_t bc[dim];

		for (size_t i = 0 ; i < dim ; i++)
			bc[i] = NON_PERIODIC;

incardon's avatar
incardon committed
96
		PointIteratorSkin<dim,T,typename vd_type::Decomposition_type> it(vd.getDecomposition(),sz,vd.getDecomposition().getDomain(),sub_A.get(0), sub_B, bc);
incardon's avatar
incardon committed
97 98 99 100 101 102 103

		for (size_t i = 1 ; i < sub_A.size() ; i++)
			it.addBoxA(Box<dim,T>(sub_A.get(i)));

		return it;
	}

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
	/*! \brief Draw particles in a box
	 *
	 * The function return an iterator over particles defined on a virtual grid in the simulation domain.
	 *
	 * \param vd particles where we are creating the particles
	 * \param sz indicate the grid size of the virtual grid.
	 * \param domain Domain where the virtual grid is defined (Must match the domain of vd)
	 * \param sub box contained in domain that define where the particle iterator must iterate,
	 *            particles are placed strictly inside this box
	 *
	 * \note Suppose to have a simulation domain of 1.5 on x and we use sz = 16. Consider now
	 * to have particles with spacing 0.1 on x. if we define a sub box that on extend from 0.65
	 *  to 0.95 the first fluid particle
	 * is at 0.70 and the last is at 0.90
	 *
	 * \return an iterator to the selected particles
	 *
	 */
incardon's avatar
incardon committed
122 123
	template<unsigned int dim, typename T, typename vd_type> static PointIterator<dim,T,typename vd_type::Decomposition_type>
	DrawBox(vd_type & vd,
incardon's avatar
incardon committed
124 125 126 127
			 size_t (& sz)[dim],
			 Box<dim,T> & domain,
			 Box<dim,T> & sub)
	{
incardon's avatar
incardon committed
128
		return PointIterator<dim,T,typename vd_type::Decomposition_type>(vd.getDecomposition(),sz,vd.getDecomposition().getDomain(),sub);
incardon's avatar
incardon committed
129 130 131 132 133 134
	}

};


#endif /* OPENFPM_NUMERICS_SRC_DRAW_DRAWPARTICLES_HPP_ */