Skip to content

Commit b86720d

Browse files
authored
some diffusion modernization (#3192)
remove the Elixir and use amrex::ParallelFor also if we are not using AMReX apply_op, then we can skip a FillPatch
1 parent 2449f5d commit b86720d

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

Source/diffusion/Castro_diffusion.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Castro::getTempDiffusionTerm (Real time, MultiFab& state_in, MultiFab& TempDiffT
121121
#pragma omp parallel
122122
#endif
123123
{
124-
FArrayBox coeff_cc;
124+
FArrayBox coeff_cc(The_Async_Arena());;
125125

126126
for (MFIter mfi(grown_state, TilingIfNotGPU()); mfi.isValid(); ++mfi)
127127
{
@@ -133,9 +133,8 @@ Castro::getTempDiffusionTerm (Real time, MultiFab& state_in, MultiFab& TempDiffT
133133

134134
const Box& obx = amrex::grow(bx, 1);
135135
coeff_cc.resize(obx, 1);
136-
Elixir elix_coeff_cc = coeff_cc.elixir();
137-
Array4<Real> const coeff_arr = coeff_cc.array();
138136

137+
Array4<Real> const coeff_arr = coeff_cc.array();
139138
Array4<Real const> const U_arr = grown_state.array(mfi);
140139

141140
fill_temp_cond(obx, U_arr, coeff_arr);
@@ -146,16 +145,16 @@ Castro::getTempDiffusionTerm (Real time, MultiFab& state_in, MultiFab& TempDiffT
146145

147146
Array4<Real> const edge_coeff_arr = (*coeffs[idir]).array(mfi);
148147

149-
AMREX_PARALLEL_FOR_3D(nbx, i, j, k,
148+
amrex::ParallelFor(nbx,
149+
[=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept
150150
{
151-
152-
if (idir == 0) {
153-
edge_coeff_arr(i,j,k) = 0.5_rt * (coeff_arr(i,j,k) + coeff_arr(i-1,j,k));
154-
} else if (idir == 1) {
155-
edge_coeff_arr(i,j,k) = 0.5_rt * (coeff_arr(i,j,k) + coeff_arr(i,j-1,k));
156-
} else {
157-
edge_coeff_arr(i,j,k) = 0.5_rt * (coeff_arr(i,j,k) + coeff_arr(i,j,k-1));
158-
}
151+
if (idir == 0) {
152+
edge_coeff_arr(i,j,k) = 0.5_rt * (coeff_arr(i,j,k) + coeff_arr(i-1,j,k));
153+
} else if (idir == 1) {
154+
edge_coeff_arr(i,j,k) = 0.5_rt * (coeff_arr(i,j,k) + coeff_arr(i,j-1,k));
155+
} else {
156+
edge_coeff_arr(i,j,k) = 0.5_rt * (coeff_arr(i,j,k) + coeff_arr(i,j,k-1));
157+
}
159158
});
160159
}
161160
}
@@ -165,17 +164,19 @@ Castro::getTempDiffusionTerm (Real time, MultiFab& state_in, MultiFab& TempDiffT
165164

166165
MultiFab CrseTemp;
167166

168-
if (level > 0) {
169-
// Fill temperature at next coarser level, if it exists.
170-
const BoxArray& crse_grids = getLevel(level-1).boxArray();
171-
const DistributionMapping& crse_dmap = getLevel(level-1).DistributionMap();
172-
CrseTemp.define(crse_grids,crse_dmap,1,1);
173-
FillPatch(getLevel(level-1),CrseTemp,1,time,State_Type,UTEMP,1);
174-
}
175-
176167
if (diffuse_use_amrex_mlmg) {
168+
169+
if (level > 0) {
170+
// Fill temperature at next coarser level, if it exists.
171+
const BoxArray& crse_grids = getLevel(level-1).boxArray();
172+
const DistributionMapping& crse_dmap = getLevel(level-1).DistributionMap();
173+
CrseTemp.define(crse_grids,crse_dmap,1,1);
174+
FillPatch(getLevel(level-1),CrseTemp,1,time,State_Type,UTEMP,1);
175+
}
176+
177177
// Evaluates ∇ ⋅(k_th ∇T) using AMReX
178178
diffusion->applyop(level, Temperature, CrseTemp, TempDiffTerm, coeffs);
179+
179180
} else {
180181
// Evaluates ∇ ⋅(k_th ∇T) without using AMReX
181182
#ifdef AMREX_USE_OMP

0 commit comments

Comments
 (0)