Skip to content

Commit 53019e1

Browse files
authored
more optimizations for normalize_species (#3183)
this uses Array4.cellData() to reducing some indexing and uses a constexpr_for
1 parent f07b68a commit 53019e1

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Source/driver/Castro.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,15 +3162,17 @@ Castro::normalize_species (MultiFab& S_new, int ng)
31623162
reduce_op.eval(bx, reduce_data,
31633163
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept -> ReduceTuple
31643164
{
3165+
3166+
auto U_cell = u.cellData(i, j, k);
31653167
Real rhoX_sum = 0.0_rt;
3166-
Real rho = u(i,j,k,URHO);
3168+
Real rho = U_cell[URHO];
31673169
Real rhoInv = 1.0_rt / rho;
31683170

31693171
int failed{};
31703172

31713173
for (int n = 0; n < NumSpec; ++n) {
31723174
// Abort if X is unphysically large.
3173-
Real X = u(i,j,k,UFS+n) * rhoInv;
3175+
Real X = U_cell[UFS+n] * rhoInv;
31743176

31753177
// Only do the abort check if the density is greater than a user-defined cutoff.
31763178
if (rho >= castro::abundance_failure_rho_cutoff) {
@@ -3187,15 +3189,15 @@ Castro::normalize_species (MultiFab& S_new, int ng)
31873189
}
31883190
}
31893191

3190-
u(i,j,k,UFS+n) = amrex::Clamp(u(i,j,k,UFS+n), lsmall_x * rho, rho);
3191-
rhoX_sum += u(i,j,k,UFS+n);
3192+
U_cell[UFS+n] = amrex::Clamp(U_cell[UFS+n], lsmall_x * rho, rho);
3193+
rhoX_sum += U_cell[UFS+n];
31923194
}
31933195

3194-
Real fac = u(i,j,k,URHO) / rhoX_sum;
3196+
Real fac = rho / rhoX_sum;
31953197

3196-
for (int n = 0; n < NumSpec; ++n) {
3197-
u(i,j,k,UFS+n) *= fac;
3198-
}
3198+
amrex::constexpr_for<0, NumSpec>([&] (auto n) {
3199+
U_cell[UFS+n] *= fac;
3200+
});
31993201

32003202
return {failed};
32013203
});

0 commit comments

Comments
 (0)