12#ifndef CABANA_CARTESIANGRID_HPP
13#define CABANA_CARTESIANGRID_HPP
15#include <Kokkos_Core.hpp>
26template <
class Real,
typename std::enable_if<
27 std::is_floating_point<Real>::value,
int>::type = 0>
31 using real_type = Real;
51 CartesianGrid(
const Real min_x,
const Real min_y,
const Real min_z,
52 const Real max_x,
const Real max_y,
const Real max_z,
53 const Real delta_x,
const Real delta_y,
const Real delta_z )
61 _nx = cellsBetween( max_x, min_x, 1.0 / delta_x );
62 _ny = cellsBetween( max_y, min_y, 1.0 / delta_y );
63 _nz = cellsBetween( max_z, min_z, 1.0 / delta_z );
65 _dx = ( max_x - min_x ) / _nx;
66 _dy = ( max_y - min_y ) / _ny;
67 _dz = ( max_z - min_z ) / _nz;
75 KOKKOS_INLINE_FUNCTION
76 std::size_t totalNumCells()
const {
return _nx * _ny * _nz; }
79 KOKKOS_INLINE_FUNCTION
80 void numCells(
int& num_x,
int& num_y,
int& num_z )
88 KOKKOS_INLINE_FUNCTION
89 int numBin(
const int dim )
const
102 KOKKOS_INLINE_FUNCTION
103 void locatePoint(
const Real xp,
const Real yp,
const Real zp,
int& ic,
104 int& jc,
int& kc )
const
108 ic = cellsBetween( xp, _min_x, _rdx );
109 ic = ( ic == _nx ) ? ic - 1 : ic;
110 jc = cellsBetween( yp, _min_y, _rdy );
111 jc = ( jc == _ny ) ? jc - 1 : jc;
112 kc = cellsBetween( zp, _min_z, _rdz );
113 kc = ( kc == _nz ) ? kc - 1 : kc;
119 KOKKOS_INLINE_FUNCTION
120 Real minDistanceToPoint(
const Real xp,
const Real yp,
const Real zp,
121 const int ic,
const int jc,
const int kc )
const
123 Real xc = _min_x + ( ic + 0.5 ) * _dx;
124 Real yc = _min_y + ( jc + 0.5 ) * _dy;
125 Real zc = _min_z + ( kc + 0.5 ) * _dz;
127 Real rx = fabs( xp - xc ) - 0.5 * _dx;
128 Real ry = fabs( yp - yc ) - 0.5 * _dy;
129 Real rz = fabs( zp - zc ) - 0.5 * _dz;
131 rx = ( rx > 0.0 ) ? rx : 0.0;
132 ry = ( ry > 0.0 ) ? ry : 0.0;
133 rz = ( rz > 0.0 ) ? rz : 0.0;
135 return rx * rx + ry * ry + rz * rz;
139 KOKKOS_INLINE_FUNCTION
140 int cardinalCellIndex(
const int i,
const int j,
const int k )
const
142 return ( i * _ny + j ) * _nz + k;
145 KOKKOS_INLINE_FUNCTION
146 void ijkBinIndex(
const int cardinal,
int& i,
int& j,
int& k )
const
148 i = cardinal / ( _ny * _nz );
149 j = ( cardinal / _nz ) % _ny;
154 KOKKOS_INLINE_FUNCTION
155 int cellsBetween(
const Real max,
const Real min,
const Real rdelta )
const
157 return Kokkos::floor( ( max - min ) * rdelta );
Core: particle data structures and algorithms.
Definition Cabana_AoSoA.hpp:36