OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
staggered_dist_grid.hpp
1/*
2 * staggered_grid.hpp
3 *
4 * Created on: Aug 19, 2015
5 * Author: i-bird
6 */
7
8#ifndef SRC_GRID_STAGGERED_DIST_GRID_HPP_
9#define SRC_GRID_STAGGERED_DIST_GRID_HPP_
10
11#include "Grid/grid_dist_id.hpp"
12#include "staggered_dist_grid_util.hpp"
13#include "VTKWriter/VTKWriter.hpp"
14#include "staggered_dist_grid_copy.hpp"
15#include <boost/mpl/vector_c.hpp>
16
62template<unsigned int dim, typename St, typename T, typename Decomposition=CartDecomposition<dim,St>,typename Memory=HeapMemory , typename device_grid=grid_cpu<dim,T>>
63class staggered_grid_dist : public grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>
64{
66 openfpm::vector<comb<dim>> c_prp[T::max_prop_real];
67
68public:
69
71 typedef T value_type;
72
74
76 static const unsigned int dims = dim;
77
88 template<typename H> staggered_grid_dist(const grid_dist_id<dim,St,H,typename Decomposition::base_type,Memory,grid_cpu<dim,H>> & g,
89 const Ghost<dim,long int> & gh,
91 :grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(g,gh,ext)
92 {
93 }
94
103 staggered_grid_dist(const size_t (& g_sz)[dim],
104 const Box<dim,St> & domain,
105 const Ghost<dim,St> & ghost)
107 {}
108
117 staggered_grid_dist(const size_t (& g_sz)[dim],
118 const Box<dim,St> & domain,
121 {}
122
133 staggered_grid_dist(const size_t (& g_sz)[dim],const Box<dim,St> & domain,
134 const Ghost<dim,long int> & g, const periodicity<dim> & p)
135 :grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(g_sz,domain,g,p)
136 {
137 }
138
148 staggered_grid_dist(const Decomposition & dec, const size_t (& g_sz)[dim],
149 const Ghost<dim,long int> & g)
150 :grid_dist_id<dim,St,T,Decomposition,Memory,device_grid>(dec,g_sz,g)
151 {}
152
161 const size_t (& g_sz)[dim],
162 const Ghost<dim,St> & ghost)
164 {}
165
173 template<unsigned int p> void setStagPosition(openfpm::vector<comb<dim>> & cmb)
174 {
175#ifdef SE_CLASS1
176 if (extends< typename boost::mpl::at<typename T::type,boost::mpl::int_<p> >::type >::mul() > cmb.size())
177 std::cerr << __FILE__ << ":" << __LINE__ << " error properties has " << extends< typename boost::mpl::at<typename T::type,boost::mpl::int_<p> >::type >::mul() << " components, but " << cmb.size() << "has been defined \n";
178#endif
179 c_prp[p] = cmb;
180 }
181
186 {
187 // for each properties
188
190
191 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop_real> >(ssp);
192 }
193
206 template<typename Grid_dst ,unsigned int ... pos> bool to_normal(Grid_dst & g_dst, const Padding<dim> & pd, const long int (& start)[dim], const long int (& stop)[dim])
207 {
208 // interpolation points for each property
209 openfpm::vector<std::vector<comb<dim>>> interp_pos[sizeof...(pos)];
210
211 typedef boost::mpl::vector_c<unsigned int,pos ... > v_pos_type;
212
214 boost::mpl::for_each_ref<v_pos_type>(itp);
215
216 // shift the start and stop by the padding
217 grid_key_dx<dim> start_k = grid_key_dx<dim>(start);
218 grid_key_dx<dim> stop_k = grid_key_dx<dim>(stop);
219
220 // sub-grid iterator over the grid map
221 auto g_map_it = this->getSubDomainIterator(start_k,stop_k);
222
223 // Iterator over the destination grid
224 auto g_dst_it = g_dst.getDomainIterator();
225
226 // Check that the 2 iterator has the same size
227 checkIterator<Grid_dst,decltype(g_map_it),decltype(g_dst_it)>(g_map_it,g_dst_it);
228
229 while (g_map_it.isNext() == true)
230 {
231 typedef typename to_boost_vmpl<pos...>::type vid;
232 typedef boost::mpl::size<vid> v_size;
233
234 auto key_src = g_map_it.get();
235
236 // destination point
237 auto key_dst = g_dst_it.get();
238
239 // Transform this id into an id for the Eigen vector
240
241 interp_ele<vid,Grid_dst,typename std::remove_reference<decltype(*this)>::type,sizeof...(pos)> cp(key_dst,g_dst,*this,key_src,interp_pos);
242
243 // For each property in the target grid
244 boost::mpl::for_each_ref<boost::mpl::range_c<int,0,v_size::value>>(cp);
245
246 ++g_map_it;
247 ++g_dst_it;
248 }
249
250 return true;
251 }
252
259 const openfpm::vector<comb<dim>> (& getStagPositions()) [T::max_prop]
260 {
261 return c_prp;
262 }
263
269 void write(std::string str)
270 {
272
273 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(sgw);
274 }
275
283 bool is_staggered_prop(size_t prp)
284 {
285 return c_prp[prp].size() != 0;
286 }
287
293 bool is_staggered() const
294 {
295 return true;
296 }
297
298 friend class stag_create_and_add_grid<dim,staggered_grid_dist<dim,St,T,Decomposition,Memory,device_grid>,St>;
299};
300
301#endif /* SRC_GRID_STAGGERED_DIST_GRID_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
This class define the domain decomposition interface.
Class that contain Padding information on each direction positive and Negative direction.
Definition Ghost.hpp:127
This is a distributed grid.
Box< dim, St > domain
Domain.
Decomposition dec
Space Decomposition.
size_t g_sz[dim]
Size of the grid on each dimension.
grid_dist_iterator_sub< dim, device_grid > getSubDomainIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
It return an iterator that span the grid domain only in the specified part.
Ghost< dim, St > ghost
Ghost expansion.
Vcluster & getVC()
Get the Virtual Cluster machine.
grid_key_dx is the key to access any element in the grid
Definition grid_key.hpp:19
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
It create separated grid for each properties to write them into a file.
this class is a functor for "for_each" algorithm
Implementation of the staggered grid.
staggered_grid_dist(const Decomposition &dec, const size_t(&g_sz)[dim], const Ghost< dim, long int > &g)
bool to_normal(Grid_dst &g_dst, const Padding< dim > &pd, const long int(&start)[dim], const long int(&stop)[dim])
Copy the staggered grid into a normal one.
bool is_staggered() const
Return if the grid is staggered.
bool is_staggered_prop(size_t prp)
Return if the properties is a staggered property or not.
void setStagPosition(openfpm::vector< comb< dim > > &cmb)
set the staggered positions of the properties
void write(std::string str)
Write a vtk file with the information of the staggered grid.
static const unsigned int dims
Number of dimensions.
staggered_grid_dist(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, long int > &ghost)
Constructor.
openfpm::vector< comb< dim > > c_prp[T::max_prop_real]
position of the properties in the grid cell
staggered_grid_dist(const grid_dist_id< dim, St, H, typename Decomposition::base_type, Memory, grid_cpu< dim, H > > &g, const Ghost< dim, long int > &gh, Box< dim, size_t > ext)
This constructor is special, it construct an expanded grid that perfectly overlap with the previous.
T value_type
Properties for each grid point.
staggered_grid_dist(const Decomposition &dec, const size_t(&g_sz)[dim], const Ghost< dim, St > &ghost)
staggered_grid_dist(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, St > &ghost)
Constructor.
void setDefaultStagPosition()
It set all the properties defined to be staggered on the default location.
staggered_grid_dist(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, long int > &g, const periodicity< dim > &p)
Position of the element of dimension d in the hyper-cube of dimension dim.
Definition comb.hpp:35
Classes to get the number of components of the properties.
this class is a functor for "for_each" algorithm
this class is a functor for "for_each" algorithm
It model an expression expr1 * expr2.
Definition mul.hpp:120
Boundary conditions.
Definition common.hpp:22