56 static_assert((NDim == 1) || (NDim == 2) || (NDim == 3),
"NDim must be 1, 2, or 3");
59 printf(
"WARNING: this function isn't usable since Cholla wasn't compiled with Dual Energy Formalism!\n");
63 int neighbor_ids[NDim * 2];
70 if constexpr (NDim == 1) {
71 n_cells = grid_shape.
x();
72 id = threadIdx.x + blockIdx.x * blockDim.x;
74 int nx = grid_shape.
x();
78 int imo = max(xid - 1, n_ghost);
79 neighbor_ids[0] = imo;
80 int ipo = min(xid + 1, nx - n_ghost - 1);
81 neighbor_ids[1] = ipo;
83 is_real_cell = (xid > n_ghost - 1 && xid < nx - n_ghost);
85 }
else if constexpr (NDim == 2) {
86 n_cells = grid_shape.
x() * grid_shape.y();
96 int blockId = blockIdx.x + blockIdx.y * gridDim.x;
97 id = threadIdx.x + blockId * blockDim.x;
99 int nx = grid_shape.
x();
100 int ny = grid_shape.y();
103 int xid =
id - yid * nx;
105 int imo = max(xid - 1, n_ghost);
106 neighbor_ids[0] = imo + yid * nx;
107 int ipo = min(xid + 1, nx - n_ghost - 1);
108 neighbor_ids[1] = ipo + yid * nx;
109 int jmo = max(yid - 1, n_ghost);
110 neighbor_ids[2] = xid + jmo * nx;
111 int jpo = min(yid + 1, ny - n_ghost - 1);
112 neighbor_ids[3] = xid + jpo * nx;
114 is_real_cell = (xid > n_ghost - 1 && xid < nx - n_ghost && yid > n_ghost - 1 && yid < ny - n_ghost);
117 n_cells = grid_shape.
x() * grid_shape.y() * grid_shape.z();
118 id = threadIdx.x + blockIdx.x * blockDim.x;
120 int nx = grid_shape.
x();
121 int ny = grid_shape.y();
122 int nz = grid_shape.z();
124 int zid =
id / (nx * ny);
125 int yid = (
id - zid * nx * ny) / nx;
126 int xid =
id - zid * nx * ny - yid * nx;
128 int imo = max(xid - 1, n_ghost);
129 neighbor_ids[0] = imo + yid * nx + zid * nx * ny;
130 int ipo = min(xid + 1, nx - n_ghost - 1);
131 neighbor_ids[1] = ipo + yid * nx + zid * nx * ny;
132 int jmo = max(yid - 1, n_ghost);
133 neighbor_ids[2] = xid + jmo * nx + zid * nx * ny;
134 int jpo = min(yid + 1, ny - n_ghost - 1);
135 neighbor_ids[3] = xid + jpo * nx + zid * nx * ny;
136 int kmo = max(zid - 1, n_ghost);
137 neighbor_ids[4] = xid + yid * nx + kmo * nx * ny;
138 int kpo = min(zid + 1, nz - n_ghost - 1);
139 neighbor_ids[5] = xid + yid * nx + kpo * nx * ny;
141 is_real_cell = (xid > n_ghost - 1 && xid < nx - n_ghost && yid > n_ghost - 1 && yid < ny - n_ghost &&
142 zid > n_ghost - 1 && zid < nz - n_ghost);
145 const Real eta_1 = DE_ETA_1;
146 const Real eta_2 = DE_ETA_2;
151 Real d = dev_conserved[id];
152 Real d_inv = 1.0 / d;
153 Real vx = dev_conserved[1 * n_cells + id] * d_inv;
154 Real vy = dev_conserved[2 * n_cells + id] * d_inv;
155 Real vz = dev_conserved[3 * n_cells + id] * d_inv;
156 Real E = dev_conserved[4 * n_cells + id];
157 Real U_advected = dev_conserved[(n_fields - 1) * n_cells +
id];
158 Real U_total = E - 0.5 * d * (vx * vx + vy * vy + vz * vz);
168 for (
int neighbor_id : neighbor_ids) {
169 Real neighbor_d = dev_conserved[grid_enum::density * n_cells + neighbor_id];
170 Real neighbor_E = dev_conserved[grid_enum::Energy * n_cells + neighbor_id];
171 Emax = fmax(Emax,
Cell_Is_Crashed(neighbor_d, neighbor_E) ? Emax : neighbor_E);
180 bool prefer_U_total = (U_total > E * eta_1) or (U_total > Emax * eta_2);
181 Real U = (prefer_U_total and (U_total > 0)) ? U_total : U_advected;
184 U = fmax(U, (Real)TINY_NUMBER);
189 dev_conserved[(n_fields - 1) * n_cells +
id] = U;
215 static_assert((NDim == 1) || (NDim == 2) || (NDim == 3),
"NDim must be 1, 2, or 3");
218 printf(
"WARNING: this function isn't usable since Cholla wasn't compiled with Dual Energy Formalism!\n");
227 if constexpr (NDim == 1) {
228 n_cells = grid_shape.
x();
231 id = threadIdx.x + blockIdx.x * blockDim.x;
233 is_real_cell = (xid > n_ghost - 1 && xid < grid_shape.
x() - n_ghost);
235 }
else if constexpr (NDim == 2) {
236 n_cells = grid_shape.
x() * grid_shape.y();
238 int nx = grid_shape.
x();
239 int ny = grid_shape.y();
242 int blockId = blockIdx.x + blockIdx.y * gridDim.x;
243 id = threadIdx.x + blockId * blockDim.x;
245 int xid =
id - yid * nx;
246 is_real_cell = (xid > n_ghost - 1 && xid < nx - n_ghost && yid > n_ghost - 1 && yid < ny - n_ghost);
249 n_cells = grid_shape.
x() * grid_shape.y() * grid_shape.z();
251 int nx = grid_shape.
x();
252 int ny = grid_shape.y();
253 int nz = grid_shape.z();
256 id = threadIdx.x + blockIdx.x * blockDim.x;
257 int zid =
id / (nx * ny);
258 int yid = (
id - zid * nx * ny) / nx;
259 int xid =
id - zid * nx * ny - yid * nx;
260 is_real_cell = (xid > n_ghost - 1 && xid < nx - n_ghost && yid > n_ghost - 1 && yid < ny - n_ghost &&
261 zid > n_ghost - 1 && zid < nz - n_ghost);
267 Real d = dev_conserved[grid_enum::density * n_cells + id];
268 Real d_inv = 1.0 / d;
269 Real vx = dev_conserved[grid_enum::momentum_x * n_cells + id] * d_inv;
270 Real vy = dev_conserved[grid_enum::momentum_y * n_cells + id] * d_inv;
271 Real vz = dev_conserved[grid_enum::momentum_z * n_cells + id] * d_inv;
272 Real U = dev_conserved[(n_fields - 1) * n_cells +
id];
275 dev_conserved[grid_enum::Energy * n_cells + id] = 0.5 * d * (vx * vx + vy * vy + vz * vz) + U;