8#ifndef DOMAIN_ICELLS_CART_HPP_
9#define DOMAIN_ICELLS_CART_HPP_
11#include "Vector/map_vector.hpp"
12#include "Space/Ghost.hpp"
13#include "NN/CellList/CellList.hpp"
14#include "NN/CellList/cuda/CellDecomposer_gpu_ker.cuh"
15#include "Vector/map_vector_sparse.hpp"
20template<
unsigned int dim,
typename vector_sparse_type,
typename CellDecomposer_type>
25 auto gk = grid_p<dim>::get_grid_point(cld.get_div_c());
27 unsigned int b = blockIdx.x + blockIdx.y * gridDim.x + blockIdx.z * gridDim.x * gridDim.y;
30 for (
unsigned int i = 0 ; i < dim ; i++)
32 gk.set_d(i,gk.get(i) + start.
get(i));
33 if (gk.get(i) > stop.
get(i))
39 auto id = cld.LinId(gk);
44 vs.flush_block_insert(b, threadIdx.x == 0 & threadIdx.y == 0 & threadIdx.z == 0 );
47template<
unsigned int dim,
typename vector_sparse_type,
typename CellDecomposer_type>
53 auto gk = grid_p<dim>::get_grid_point(cld.get_div_c());
55 unsigned int b = blockIdx.x + blockIdx.y * gridDim.x + blockIdx.z * gridDim.x * gridDim.y;
58 for (
unsigned int i = 0 ; i < dim ; i++)
60 gk.set_d(i,gk.get(i) + start.
get(i));
61 if (gk.get(i) > stop.
get(i))
67 auto id = cld.LinId(gk);
73 vs.flush_block_insert(b, threadIdx.x == 0 & threadIdx.y == 0 & threadIdx.z == 0 );
74 vsi.flush_block_remove(b, threadIdx.x == 0 & threadIdx.y == 0 & threadIdx.z == 0);
77template<
unsigned int dim,
typename T,
template<
typename>
class layout_base ,
typename Memory,
typename cnt_type,
typename ids_type,
bool is_gpu>
78struct CalculateInternalCells_impl
80 template<
typename VCluster_type>
81 static void CalculateInternalCells(VCluster_type & v_cl,
95template<
unsigned int dim,
typename T,
template<
typename>
class layout_base ,
typename Memory,
typename cnt_type,
typename ids_type>
96struct CalculateInternalCells_impl<dim,T,layout_base,Memory,cnt_type,ids_type,true>
98 template<
typename VCluster_type>
99 static void CalculateInternalCells(VCluster_type & v_cl,
116 cl_param_calculate(pbox, div, r_cut, enlarge);
122 for (
size_t i = 0 ; i < dim ; i++)
127 div_c[i] = div[i] + 2*off[i];
140 vs.template setBackground<0>(0);
144 for (
size_t i = 0 ; i < domain.size() ; i++)
148 auto pp2 = bx.
getP2();
150 for (
size_t j = 0 ; j < dim ; j++)
151 {pp2.get(j) = std::nextafter(pp2.get(j),pp2.get(j) -
static_cast<T
>(1.0));}
153 auto p1 = cld.getCell(bx.
getP1());
154 auto p2 = cld.getCell(pp2);
157 auto ite = g.getGPUIterator(p1,p2,256);
164 CUDA_LAUNCH((insert_icell<dim>),ite,vsi.
toKernel(),cld,ite.start,p2);
166 vsi.template flush<>(v_cl.getgpuContext(),flush_type::FLUSH_ON_DEVICE);
171 for (
size_t i = 0 ; i < ig_box.size() ; i++)
175 auto pp2 = bx.
getP2();
177 for (
size_t j = 0 ; j < dim ; j++)
178 {pp2.get(j) = std::nextafter(pp2.get(j),pp2.get(j) -
static_cast<T
>(1.0));}
180 auto p1 = cld.getCell(bx.
getP1());
181 auto p2 = cld.getCell(pp2);
183 auto ite = g.getGPUIterator(p1,p2,256);
191 CUDA_LAUNCH(insert_remove_icell<dim>,ite,vs.
toKernel(),vsi.
toKernel(),cld,ite.start,p2);
193 vs.template flush<>(v_cl.getgpuContext(),flush_type::FLUSH_ON_DEVICE);
194 vsi.
flush_remove(v_cl.getgpuContext(),flush_type::FLUSH_ON_DEVICE);
207template<
unsigned int dim,
typename T,
template<
typename>
class layout_base ,
typename Memory>
210 typedef unsigned int cnt_type;
212 typedef int ids_type;
217 CellDecomposer_sm<dim,T,shift<dim,T>> cd;
256 template<
typename VCluster_type>
265 CalculateInternalCells_impl<dim,T,layout_base,Memory,cnt_type,ids_type,std::is_same<Memory,CudaMemory>::value>
::CalculateInternalCells(v_cl,ig_box,domain,pbox,r_cut,enlarge,cd,icells,dcells);
299 for (
size_t i = 0 ; i < dim ; i++)
301 auto key = cd.getGrid().InvLinId(ci);
302 Point<dim,T> p1 = cd.getOrig().
get(i) - cd.getPadding(i)*cd.getCellBox().getHigh(i) ;
304 b.setLow(i,p1.
get(i) + key.get(i)*cd.getCellBox().getHigh(i));
305 b.setHigh(i,p1.
get(i) + ((key.get(i) + 1)*cd.getCellBox().getHigh(i)));
This class represent an N-dimensional box.
Point< dim, T > getP2() const
Get the point p2.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ T getHigh(int i) const
get the high interval of the box
Point< dim, T > getP1() const
Get the point p1.
This class implement an NxN (dense) matrix.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
This class represent an N-dimensional box.
openfpm::vector< aggregate< ids_type >, Memory, layout_base > & getIcells()
Return the list of the internal cells.
void CalculateInternalCells(VCluster_type &v_cl, openfpm::vector< Box< dim, T >, Memory, layout_base > &ig_box, openfpm::vector< SpaceBox< dim, T >, Memory, layout_base > &domain, Box< dim, T > &pbox, T r_cut, const Ghost< dim, T > &enlarge)
Calculate the subdomain that are in the skin part of the domain.
Box< dim, T > getBoxCell(unsigned int ci)
Given a cell index return the cell box.
openfpm::vector< aggregate< ids_type >, Memory, layout_base > & getDcells()
Return the list of the internal cells.
const grid_sm< dim, void > & getGrid()
Get the grid base information about this cell decomposition.
grid_key_dx is the key to access any element in the grid
__device__ __host__ index_type get(index_type i) const
Get the i index.
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
void flush_remove(gpu::ofp_context_t &context, flush_type opt=FLUSH_ON_HOST)
merge the added element to the main data array
void setGPURemoveBuffer(int nblock, int nslot)
set the gpu remove buffer for every block
vector_sparse_gpu_ker< T, Ti, layout_base > toKernel()
toKernel function transform this structure into one that can be used on GPU
void setGPUInsertBuffer(int nblock, int nslot)
set the gpu insert buffer for every block
void swapIndexVector(vector< aggregate< Ti >, Memory, layout_base, grow_p > &iv)
Implementation of 1-D std::vector like structure.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...