1 #ifndef AMREX_PARTICLE_MOD_K_H_
2 #define AMREX_PARTICLE_MOD_K_H_
3 #include <AMReX_Config.H>
18 #if defined(__GNUC__) && !defined(__clang__)
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Warray-bounds"
23 #if (AMREX_SPACEDIM == 1)
24 amrex::Real lx = (p.pos(0) - plo[0]) * dxi[0] + Real(0.5);
26 int i =
static_cast<int>(amrex::Math::floor(lx));
28 amrex::Real xint = lx -
static_cast<Real
>(i);
30 amrex::Real sx[2] = {Real(1.0) - xint, xint};
32 for (
int ii = 0; ii <= 1; ++ii) {
36 for (
int comp=1; comp < nc; ++comp) {
37 for (
int ii = 0; ii <= 1; ++ii) {
39 static_cast<Real
>(sx[ii]*p.rdata(0)*p.rdata(comp)));
42 #elif (AMREX_SPACEDIM == 2)
43 amrex::Real lx = (p.pos(0) - plo[0]) * dxi[0] + Real(0.5);
44 amrex::Real ly = (p.pos(1) - plo[1]) * dxi[1] + Real(0.5);
46 int i =
static_cast<int>(amrex::Math::floor(lx));
47 int j =
static_cast<int>(amrex::Math::floor(ly));
49 amrex::Real xint = lx -
static_cast<Real
>(i);
50 amrex::Real yint = ly -
static_cast<Real
>(j);
52 amrex::Real sx[2] = {Real(1.0) - xint, xint};
53 amrex::Real sy[2] = {Real(1.0) - yint, yint};
55 for (
int jj = 0; jj <= 1; ++jj) {
56 for (
int ii = 0; ii <= 1; ++ii) {
58 static_cast<Real
>(sx[ii]*sy[jj]*p.rdata(0)));
62 for (
int comp=1; comp < nc; ++comp) {
63 for (
int jj = 0; jj <= 1; ++jj) {
64 for (
int ii = 0; ii <= 1; ++ii) {
66 static_cast<Real
>(sx[ii]*sy[jj]*p.rdata(0)*p.rdata(comp)));
71 #elif (AMREX_SPACEDIM == 3)
72 amrex::Real lx = (p.pos(0) - plo[0]) * dxi[0] + Real(0.5);
73 amrex::Real ly = (p.pos(1) - plo[1]) * dxi[1] + Real(0.5);
74 amrex::Real lz = (p.pos(2) - plo[2]) * dxi[2] + Real(0.5);
76 int i =
static_cast<int>(amrex::Math::floor(lx));
77 int j =
static_cast<int>(amrex::Math::floor(ly));
78 int k =
static_cast<int>(amrex::Math::floor(lz));
80 amrex::Real xint = lx -
static_cast<Real
>(i);
81 amrex::Real yint = ly -
static_cast<Real
>(j);
82 amrex::Real zint = lz -
static_cast<Real
>(k);
84 amrex::Real sx[] = {Real(1.0) - xint, xint};
85 amrex::Real sy[] = {Real(1.0) - yint, yint};
86 amrex::Real sz[] = {Real(1.0) - zint, zint};
88 for (
int kk = 0; kk <= 1; ++kk) {
89 for (
int jj = 0; jj <= 1; ++jj) {
90 for (
int ii = 0; ii <= 1; ++ii) {
92 static_cast<Real
>(sx[ii]*sy[jj]*sz[kk]*p.rdata(0)));
97 for (
int comp=1; comp < nc; ++comp) {
98 for (
int kk = 0; kk <= 1; ++kk) {
99 for (
int jj = 0; jj <= 1; ++jj) {
100 for (
int ii = 0; ii <= 1; ++ii) {
102 static_cast<Real
>(sx[ii]*sy[jj]*sz[kk]*p.rdata(0)*p.rdata(comp)));
111 #if defined(__GNUC__) && !defined(__clang__)
112 #pragma GCC diagnostic pop
116 template <
typename P>
124 #if defined(__GNUC__) && !defined(__clang__)
125 #pragma GCC diagnostic push
126 #pragma GCC diagnostic ignored "-Warray-bounds"
129 #if (AMREX_SPACEDIM == 1)
130 amrex::Real factor = (pdxi[0]/dxi[0]);
132 amrex::Real lx = (p.pos(0) - plo[0] - Real(0.5)/pdxi[0]) * dxi[0];
134 amrex::Real hx = (p.pos(0) - plo[0] + Real(0.5)/pdxi[0]) * dxi[0];
136 int lo_x =
static_cast<int>(amrex::Math::floor(lx));
138 int hi_x =
static_cast<int>(amrex::Math::floor(hx));
140 for (
int i = lo_x; i <= hi_x; ++i) {
141 if (i < rho.begin.x || i >= rho.
end.
x) {
continue; }
142 amrex::Real wx =
amrex::min(hx -
static_cast<Real
>(i), amrex::Real(1.0)) -
amrex::max(lx -
static_cast<Real
>(i), amrex::Real(0.0));
143 amrex::Real weight = wx*factor;
147 for (
int comp = 1; comp < nc; ++comp)
149 for (
int i = lo_x; i <= hi_x; ++i) {
150 if (i < rho.begin.x || i >= rho.
end.
x) {
continue; }
151 amrex::Real wx =
amrex::min(hx -
static_cast<Real
>(i), amrex::Real(1.0)) -
amrex::max(lx -
static_cast<Real
>(i), amrex::Real(0.0));
152 amrex::Real weight = wx*factor;
157 #elif (AMREX_SPACEDIM == 2)
158 amrex::Real factor = (pdxi[0]/dxi[0])*(pdxi[1]/dxi[1]);
160 amrex::Real lx = (p.pos(0) - plo[0] - Real(0.5)/pdxi[0]) * dxi[0];
161 amrex::Real ly = (p.pos(1) - plo[1] - Real(0.5)/pdxi[1]) * dxi[1];
163 amrex::Real hx = (p.pos(0) - plo[0] + Real(0.5)/pdxi[0]) * dxi[0];
164 amrex::Real hy = (p.pos(1) - plo[1] + Real(0.5)/pdxi[1]) * dxi[1];
166 int lo_x =
static_cast<int>(amrex::Math::floor(lx));
167 int lo_y =
static_cast<int>(amrex::Math::floor(ly));
169 int hi_x =
static_cast<int>(amrex::Math::floor(hx));
170 int hi_y =
static_cast<int>(amrex::Math::floor(hy));
172 for (
int j = lo_y; j <= hi_y; ++j) {
173 if (j < rho.begin.y || j >= rho.
end.
y) {
continue; }
174 amrex::Real wy =
amrex::min(hy -
static_cast<Real
>(j), amrex::Real(1.0)) -
amrex::max(ly -
static_cast<Real
>(j), amrex::Real(0.0));
175 for (
int i = lo_x; i <= hi_x; ++i) {
176 if (i < rho.begin.x || i >= rho.
end.
x) {
continue; }
177 amrex::Real wx =
amrex::min(hx -
static_cast<Real
>(i), amrex::Real(1.0)) -
amrex::max(lx -
static_cast<Real
>(i), amrex::Real(0.0));
178 amrex::Real weight = wx*wy*factor;
183 for (
int comp = 1; comp < nc; ++comp) {
184 for (
int j = lo_y; j <= hi_y; ++j) {
185 if (j < rho.begin.y || j >= rho.
end.
y) {
continue; }
186 amrex::Real wy =
amrex::min(hy -
static_cast<Real
>(j), amrex::Real(1.0)) -
amrex::max(ly -
static_cast<Real
>(j), amrex::Real(0.0));
187 for (
int i = lo_x; i <= hi_x; ++i) {
188 if (i < rho.begin.x || i >= rho.
end.
x) {
continue; }
189 amrex::Real wx =
amrex::min(hx -
static_cast<Real
>(i), amrex::Real(1.0)) -
amrex::max(lx -
static_cast<Real
>(i), amrex::Real(0.0));
190 amrex::Real weight = wx*wy*factor;
196 #elif (AMREX_SPACEDIM == 3)
197 amrex::Real factor = (pdxi[0]/dxi[0])*(pdxi[1]/dxi[1])*(pdxi[2]/dxi[2]);
199 amrex::Real lx = (p.pos(0) - plo[0] - Real(0.5)/pdxi[0]) * dxi[0];
200 amrex::Real ly = (p.pos(1) - plo[1] - Real(0.5)/pdxi[1]) * dxi[1];
201 amrex::Real lz = (p.pos(2) - plo[2] - Real(0.5)/pdxi[2]) * dxi[2];
203 amrex::Real hx = (p.pos(0) - plo[0] + Real(0.5)/pdxi[0]) * dxi[0];
204 amrex::Real hy = (p.pos(1) - plo[1] + Real(0.5)/pdxi[1]) * dxi[1];
205 amrex::Real hz = (p.pos(2) - plo[2] + Real(0.5)/pdxi[2]) * dxi[2];
207 int lo_x =
static_cast<int>(amrex::Math::floor(lx));
208 int lo_y =
static_cast<int>(amrex::Math::floor(ly));
209 int lo_z =
static_cast<int>(amrex::Math::floor(lz));
211 int hi_x =
static_cast<int>(amrex::Math::floor(hx));
212 int hi_y =
static_cast<int>(amrex::Math::floor(hy));
213 int hi_z =
static_cast<int>(amrex::Math::floor(hz));
215 for (
int k = lo_z; k <= hi_z; ++k) {
216 if (k < rho.begin.z || k >= rho.
end.
z) {
continue; }
217 amrex::Real wz =
amrex::min(hz -
static_cast<Real
>(k), amrex::Real(1.0)) -
amrex::max(lz -
static_cast<Real
>(k), amrex::Real(0.0));
218 for (
int j = lo_y; j <= hi_y; ++j) {
219 if (j < rho.begin.y || j >= rho.
end.
y) {
continue; }
220 amrex::Real wy =
amrex::min(hy -
static_cast<Real
>(j), amrex::Real(1.0)) -
amrex::max(ly -
static_cast<Real
>(j), amrex::Real(0.0));
221 for (
int i = lo_x; i <= hi_x; ++i) {
222 if (i < rho.begin.x || i >= rho.
end.
x) {
continue; }
223 amrex::Real wx =
amrex::min(hx -
static_cast<Real
>(i), amrex::Real(1.0)) -
amrex::max(lx -
static_cast<Real
>(i), amrex::Real(0.0));
224 amrex::Real weight = wx*wy*wz*factor;
230 for (
int comp = 1; comp < nc; ++comp) {
231 for (
int k = lo_z; k <= hi_z; ++k) {
232 if (k < rho.begin.z || k >= rho.
end.
z) {
continue; }
233 amrex::Real wz =
amrex::min(hz -
static_cast<Real
>(k), amrex::Real(1.0)) -
amrex::max(lz -
static_cast<Real
>(k), amrex::Real(0.0));
234 for (
int j = lo_y; j <= hi_y; ++j) {
235 if (j < rho.begin.y || j >= rho.
end.
y) {
continue; }
236 amrex::Real wy =
amrex::min(hy -
static_cast<Real
>(j), amrex::Real(1.0)) -
amrex::max(ly -
static_cast<Real
>(j), amrex::Real(0.0));
237 for (
int i = lo_x; i <= hi_x; ++i) {
238 if (i < rho.begin.x || i >= rho.
end.
x) {
continue; }
239 amrex::Real wx =
amrex::min(hx -
static_cast<Real
>(i), amrex::Real(1.0)) -
amrex::max(lx -
static_cast<Real
>(i), amrex::Real(0.0));
240 amrex::Real weight = wx*wy*wz*factor;
250 #if defined(__GNUC__) && !defined(__clang__)
251 #pragma GCC diagnostic pop
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void AddNoRet(T *sum, T value) noexcept
Definition: AMReX_GpuAtomic.H:281
static constexpr int P
Definition: AMReX_OpenBC.H:14
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_deposit_cic(P const &p, int nc, amrex::Array4< amrex::Real > const &rho, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &plo, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &dxi)
Definition: AMReX_Particle_mod_K.H:13
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void amrex_deposit_particle_dx_cic(P const &p, int nc, amrex::Array4< amrex::Real > const &rho, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &plo, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &dxi, amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > const &pdxi)
Definition: AMReX_Particle_mod_K.H:118
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
Definition: AMReX_Array4.H:61
Dim3 end
Definition: AMReX_Array4.H:67
int x
Definition: AMReX_Dim3.H:12
int z
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12
Definition: AMReX_Array.H:34