5#ifndef OPENFPM_PDATA_BLOCKGEOMETRY_HPP
6#define OPENFPM_PDATA_BLOCKGEOMETRY_HPP
8#include <boost/mpl/size_t.hpp>
10#include <Grid/grid_sm.hpp>
11#include "SparseGridGpu/TemplateUtils/mathUtils.hpp"
18template<
unsigned int dim,
unsigned int blockEdgeSize,
typename indexT =
long int>
47 __host__ __device__
grid_smb(
const size_t (& sz)[dim])
49 for (
int d=0; d<dim; ++d)
52 blockSz[d] = sz[d] / blockEdgeSize + ((sz[d] % blockEdgeSize) != 0);
59 __host__ __device__
grid_smb(
const indexT (& sz)[dim])
61 for (
int d=0; d<dim; ++d)
64 blockSz[d] = sz[d] / blockEdgeSize + ((sz[d] % blockEdgeSize) != 0);
71 __host__ __device__
grid_smb(
const size_t domainBlockEdgeSize)
73 for (
int i = 0; i < dim; ++i)
75 blockSz[i] = (indexT)domainBlockEdgeSize;
76 sz[i] = (indexT)domainBlockEdgeSize * blockEdgeSize;
86 for (
int i = 0; i < dim; ++i)
88 blockSz[i] = blockGrid.
size(i);
89 sz[i] = blockGrid.
size(i) * blockEdgeSize;
96 static bool noPointers() {
return true;}
100 __host__ __device__
grid_smb(
const dim3 blockDimensions)
104 blockSz[i] = blockDimensions.x;
105 sz[i] = blockSz[i] * blockEdgeSize;
113 blockSz[i] = blockDimensions.y;
114 sz[i] = blockSz[i] * blockEdgeSize;
122 blockSz[i] = blockDimensions.z;
123 sz[i] = blockSz[i] * blockEdgeSize;
136 for (indexT i = 0 ; i < dim ; i++)
138 blockSz[i] = other.blockSz[i];
145 for (indexT i = 0 ; i < dim ; i++)
147 blockSz[i] = other.blockSz[i];
153 __host__ __device__
const indexT (& getSize()
const)[dim]
158 __host__ __device__
const indexT & size(
int i)
const
175 template<
typename indexT_>
179 indexT blockLinId = coord.
get(dim - 1) / blockEdgeSize;
180 indexT localLinId = coord.
get(dim - 1) % blockEdgeSize;
181 for (
int d = dim - 2; d >= 0; --d)
183 blockLinId *= blockSz[d];
184 localLinId *= blockEdgeSize;
185 blockLinId += coord.
get(d) / blockEdgeSize;
186 localLinId += coord.
get(d) % blockEdgeSize;
188 return blockLinId * blockSize + localLinId;
203 template<
typename indexT_>
207 blockLinId = coord.
get(dim - 1) / blockEdgeSize;
208 localLinId = coord.
get(dim - 1) % blockEdgeSize;
209 for (
int d = dim - 2; d >= 0; --d)
211 blockLinId *= blockSz[d];
212 localLinId *= blockEdgeSize;
213 blockLinId += coord.
get(d) / blockEdgeSize;
214 localLinId += coord.
get(d) % blockEdgeSize;
220 indexT blockLinId = linId / blockSize;
221 indexT localLinId = linId % blockSize;
222 return InvLinId(blockLinId, localLinId);
235 for (
int d = 0; d < dim; ++d)
237 auto c = localLinId % blockEdgeSize;
239 localLinId /= blockEdgeSize;
266 for (
int d = 0; d < dim; ++d)
268 auto c = blockLinId % blockSz[d];
270 c += localLinId % blockEdgeSize;
272 blockLinId /= blockSz[d];
273 localLinId /= blockEdgeSize;
279 template<
typename indexT_>
282 indexT blockLinId = blockCoord.
get(dim - 1);
283 if (blockLinId >= blockSz[dim-1])
286 for (
int d = dim - 2; d >= 0; --d)
288 blockLinId *= blockSz[d];
289 indexT cur = blockCoord.
get(d);
290 if (cur >= blockSz[d])
300 template<
typename indexT_>
305 for (
unsigned int i = 0 ; i < dim ; i++)
307 k.set_d(i,blockCoord.
get(i)*blockEdgeSize + offset%blockEdgeSize);
308 offset /= blockEdgeSize;
316 for (
int d = 0; d < dim; ++d)
318 auto c = blockLinId % blockSz[d];
319 blockCoord.
set_d(d, c);
320 blockLinId /= blockSz[d];
325 inline indexT size_blocks()
const
329 for (indexT i = 0 ; i < dim ; i++)
335 inline indexT size()
const
339 for (indexT i = 0 ; i < dim ; i++)
345 __host__ __device__
inline indexT getBlockEgdeSize()
const
347 return blockEdgeSize;
350 __host__ __device__
inline indexT getBlockSize()
const
357 indexT blockSz_tmp[dim];
360 for (indexT i = 0 ; i < dim ; i++)
362 blockSz_tmp[i] = blockSz[i];
363 blockSz[i] = other.blockSz[i];
364 other.blockSz[i] = blockSz_tmp[i];
368 other.sz[i] = sz_tmp[i];
This class represent an N-dimensional box.
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
grid_key_dx is the key to access any element in the grid
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
__device__ __host__ index_type get(index_type i) const
Get the i index.
__device__ __host__ size_t size() const
Return the size of the grid.
__host__ __device__ indexT LinId(const grid_key_dx< dim, indexT_ > coord) const
Linearize the coordinate index.
Box< dim, size_t > getBox() const
Return the box enclosing the grid.
Box< dim, size_t > box
Box enclosing the grid.
__host__ __device__ grid_key_dx< dim, int > LocalInvLinId(unsigned int localLinId) const
__host__ __device__ void LinId(const grid_key_dx< dim, indexT_ > coord, indexT &blockLinId, int &localLinId) const
Linearize the coordinate index.
__host__ __device__ grid_key_dx< dim, int > InvLinId(indexT blockLinId, indexT localLinId) const
Invert from the linearized block id + local id to the position of the point in coordinates.