Skip to content

Commit

Permalink
remove interpolation of fields in fgb region
Browse files Browse the repository at this point in the history
  • Loading branch information
RevathiJambunathan committed Aug 10, 2024
1 parent ee8d9bd commit 74cbd90
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 267 deletions.
22 changes: 0 additions & 22 deletions Source/Particles/PhysicalParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -320,28 +320,6 @@ public:
amrex::FArrayBox const * & ez_ptr, amrex::FArrayBox const * & bx_ptr,
amrex::FArrayBox const * & by_ptr, amrex::FArrayBox const * & bz_ptr);

void InterpolateFieldsInGatherBuffer (const amrex::Box& box,
amrex::FArrayBox& bufferEx, amrex::FArrayBox& bufferEy, amrex::FArrayBox& bufferEz,
amrex::FArrayBox& bufferBx, amrex::FArrayBox& bufferBy, amrex::FArrayBox& bufferBz,
amrex::Elixir& buf_exeli, amrex::Elixir& buf_eyeli, amrex::Elixir& buf_ezeli,
amrex::Elixir& buf_bxeli, amrex::Elixir& buf_byeli, amrex::Elixir& buf_bzeli,
amrex::FArrayBox const *& ex_ptr, amrex::FArrayBox const *& ey_ptr, amrex::FArrayBox const* & ez_ptr,
amrex::FArrayBox const *& bx_ptr, amrex::FArrayBox const *& by_ptr, amrex::FArrayBox const* & bz_ptr,
amrex::FArrayBox const *& cex_ptr, amrex::FArrayBox const *& cey_ptr, amrex::FArrayBox const* & cez_ptr,
amrex::FArrayBox const *& cbx_ptr, amrex::FArrayBox const *& cby_ptr, amrex::FArrayBox const* & cbz_ptr,
const amrex::IArrayBox& gather_mask, const amrex::FArrayBox& weight_gbuffer,
const amrex::IntVect ref_ratio);

void WeightedSumInGatherBuffer (const amrex::Box& tmp_xbox, const amrex::Box& tmp_ybox, const amrex::Box& tmp_zbox,
amrex::Array4<amrex::Real> const & xbuf_field_arr, amrex::Array4<amrex::Real> const& ybuf_field_arr,
amrex::Array4<amrex::Real> const & zbuf_field_arr,
amrex::Array4<const amrex::Real> cfx_arr, amrex::Array4<const amrex::Real> cfy_arr,
amrex::Array4<const amrex::Real> cfz_arr,
amrex::Array4<const amrex::Real> fx_arr, amrex::Array4<const amrex::Real> fy_arr,
amrex::Array4<const amrex::Real> fz_arr,
amrex::Array4<const int > gm_arr, amrex::Array4<const amrex::Real> wt_arr,
const amrex::IntVect ref_ratio);

/**
* \brief This function determines if resampling should be done for the current species, and
* if so, performs the resampling.
Expand Down
107 changes: 0 additions & 107 deletions Source/Particles/PhysicalParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,113 +2349,6 @@ PhysicalParticleContainer::applyNCIFilter (
#endif
}

void
PhysicalParticleContainer::InterpolateFieldsInGatherBuffer (const Box& box,
amrex::FArrayBox& bufferEx, amrex::FArrayBox& bufferEy, amrex::FArrayBox& bufferEz,
amrex::FArrayBox& bufferBx, amrex::FArrayBox& bufferBy, amrex::FArrayBox& bufferBz,
Elixir& buf_exeli, Elixir& buf_eyeli, Elixir& buf_ezeli,
Elixir& buf_bxeli, Elixir& buf_byeli, Elixir& buf_bzeli,
FArrayBox const *& ex_ptr, FArrayBox const *& ey_ptr, FArrayBox const* & ez_ptr,
FArrayBox const *& bx_ptr, FArrayBox const *& by_ptr, FArrayBox const* & bz_ptr,
FArrayBox const *& cex_ptr, FArrayBox const *& cey_ptr, FArrayBox const* & cez_ptr,
FArrayBox const *& cbx_ptr, FArrayBox const *& cby_ptr, FArrayBox const* & cbz_ptr,
const IArrayBox& gather_mask, const FArrayBox& weight_gbuffer,
const amrex::IntVect ref_ratio)
{
amrex::Box tmp_exbox = amrex::convert(box,ex_ptr->box().ixType());
amrex::Box tmp_eybox = amrex::convert(box,ey_ptr->box().ixType());
amrex::Box tmp_ezbox = amrex::convert(box,ez_ptr->box().ixType());

bufferEx.resize(tmp_exbox);
buf_exeli = bufferEx.elixir();
bufferEy.resize(tmp_eybox);
buf_eyeli = bufferEy.elixir();
bufferEz.resize(tmp_ezbox);
buf_ezeli = bufferEz.elixir();
WeightedSumInGatherBuffer(tmp_exbox, tmp_eybox, tmp_ezbox,
bufferEx.array(), bufferEy.array(), bufferEz.array(),
cex_ptr->array(), cey_ptr->array(), cez_ptr->array(),
ex_ptr->array(), ey_ptr->array(), ez_ptr->array(),
gather_mask.array(), weight_gbuffer.array(), ref_ratio);

amrex::Box tmp_bxbox = amrex::convert(box,bx_ptr->box().ixType());
amrex::Box tmp_bybox = amrex::convert(box,by_ptr->box().ixType());
amrex::Box tmp_bzbox = amrex::convert(box,bz_ptr->box().ixType());
bufferBx.resize(tmp_bxbox);
buf_bxeli = bufferBx.elixir();
bufferBy.resize(tmp_bybox);
buf_byeli = bufferBy.elixir();
bufferBz.resize(tmp_bzbox);
buf_bzeli = bufferBz.elixir();

WeightedSumInGatherBuffer(tmp_bxbox, tmp_bybox, tmp_bzbox,
bufferBx.array(), bufferBy.array(), bufferBz.array(),
cbx_ptr->array(), cby_ptr->array(), cbz_ptr->array(),
bx_ptr->array(), by_ptr->array(), bz_ptr->array(),
gather_mask.array(), weight_gbuffer.array(), ref_ratio);
}

void
PhysicalParticleContainer::WeightedSumInGatherBuffer (
const amrex::Box& tmp_xbox, const amrex::Box& tmp_ybox, const amrex::Box& tmp_zbox,
amrex::Array4<amrex::Real> const & xbuf_field_arr, amrex::Array4<amrex::Real> const& ybuf_field_arr,
amrex::Array4<amrex::Real> const & zbuf_field_arr,
amrex::Array4<const amrex::Real> cfx_arr, amrex::Array4<const amrex::Real> cfy_arr,
amrex::Array4<const amrex::Real> cfz_arr,
amrex::Array4<const amrex::Real> fx_arr, amrex::Array4<const amrex::Real> fy_arr,
amrex::Array4<const amrex::Real> fz_arr,
amrex::Array4<const int > gm_arr, amrex::Array4<const amrex::Real> wt_arr,
const amrex::IntVect ref_ratio)
{
amrex::ParallelFor( tmp_xbox, tmp_ybox, tmp_zbox,
[=] AMREX_GPU_DEVICE (int i, int j, int k) {
int ii = amrex::coarsen(i,ref_ratio[0]);
int jj = j;
int kk = k;
#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
jj = amrex::coarsen(j,ref_ratio[1]);
#elif defined(WARPX_DIM_3D)
kk = amrex::coarsen(k,ref_ratio[2]);
#endif
if (gm_arr(i,j,k) == 0) {
xbuf_field_arr(i,j,k) = wt_arr(i,j,k)*fx_arr(i,j,k) + (1._rt-wt_arr(i,j,k))*cfx_arr(ii,jj,kk);
} else {
xbuf_field_arr(i,j,k) = fx_arr(i,j,k);
}
},
[=] AMREX_GPU_DEVICE (int i, int j, int k) {
int ii = amrex::coarsen(i,ref_ratio[0]);
int jj = j;
int kk = k;
#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
jj = amrex::coarsen(j,ref_ratio[1]);
#elif defined(WARPX_DIM_3D)
kk = amrex::coarsen(k,ref_ratio[2]);
#endif
if (gm_arr(i,j,k) == 0) {
ybuf_field_arr(i,j,k) = wt_arr(i,j,k)*fy_arr(i,j,k) + (1._rt-wt_arr(i,j,k))*cfy_arr(ii,jj,kk);
} else {
ybuf_field_arr(i,j,k) = fy_arr(i,j,k);
}
},
[=] AMREX_GPU_DEVICE (int i, int j, int k) {
int ii = amrex::coarsen(i,ref_ratio[0]);
int jj = j;
int kk = k;
#if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
jj = amrex::coarsen(j,ref_ratio[1]);
#elif defined(WARPX_DIM_3D)
kk = amrex::coarsen(k,ref_ratio[2]);
#endif
if (gm_arr(i,j,k) == 0) {
zbuf_field_arr(i,j,k) = wt_arr(i,j,k)*fz_arr(i,j,k) + (1._rt-wt_arr(i,j,k))*cfz_arr(ii,jj,kk);
} else {
zbuf_field_arr(i,j,k) = fz_arr(i,j,k);
}
}
);
}

// Loop over all particles in the particle container and
// split particles tagged with p.id()=DoSplitParticleID
void
Expand Down
28 changes: 0 additions & 28 deletions Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -363,31 +363,6 @@ public:
static int n_field_gather_buffer;
static amrex::IntVect n_field_gather_buffer_each_dir;

/**
* If true, particles located inside refinement patch but within
* #n_field_gather_buffer cells of the patch edge will gather fields
* that are a weighted sum of the fields from lower refinement
* level and the refinement patch. By default, no interpolation will be done,
* and the fields will be gathered only from the lower refinement level.
* The option can be used to allow for a smooth transition from the fine
* and coarse solutions with a tanh profile, such that, the value
* of the gather fields is close to the solution on the refinement patch
* near the gather buffer edge, and close to the solution on the lower
* refinement level close to the edge of the patch.
* #tanh_midpoint_gather_buffer can be used to set the tanh profile
*/
static bool do_fieldinterp_gather_buffer;

/**
* With mesh-refinement, finite number of gather buffer cells, and
* do_fieldinterp_gather_buffer, the particles on the fine patch
* gather a weighted sum of fields from fine patch and coarse patch.
* A tanh profile is used to set the smoothing kernel
* #tanh_midpoint_gather_buffer must be a fraction of the buffer width
* measured from coarsefine interface, where the tanh profile is 0.5
* The default value is 0.5
*/
static amrex::Real tanh_midpoint_gather_buffer;
//! With mesh refinement, particles located inside a refinement patch, but within
//! #n_current_deposition_buffer cells of the edge of the patch, will deposit their charge
//! and current onto the lower refinement level instead of the refinement patch itself
Expand Down Expand Up @@ -1130,9 +1105,6 @@ public:
void BuildBufferMasksInBox ( amrex::Box tbx, amrex::IArrayBox &buffer_mask,
const amrex::IArrayBox &guard_mask, const amrex::IntVect ng );

void SetWeightsInGatherBuffer(const amrex::Box tbx, amrex::Array4<amrex::Real> wtmsk,
const amrex::Array4<int const> gmsk, const amrex::Array4<int const> bmsk,
const int ngbuffer, const bool do_interpolate,amrex::Real tanh_midpoint);
#ifdef AMREX_USE_EB
amrex::EBFArrayBoxFactory const& fieldEBFactory (int lev) const noexcept {
return static_cast<amrex::EBFArrayBoxFactory const&>(*m_field_factory[lev]);
Expand Down
110 changes: 0 additions & 110 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ amrex::IntVect WarpX::n_field_gather_buffer_each_dir(-1);
amrex::IntVect WarpX::n_current_deposition_buffer_each_dir(-1);
int WarpX::n_field_gather_buffer = -1;
int WarpX::n_current_deposition_buffer = -1;
bool WarpX::do_fieldinterp_gather_buffer = false;
amrex::Real WarpX::tanh_midpoint_gather_buffer = 0.5;

short WarpX::grid_type;
amrex::IntVect m_rho_nodal_flag;
Expand Down Expand Up @@ -930,11 +928,6 @@ WarpX::ReadParameters ()
n_current_deposition_buffer_each_dir[i] = ncurrentdepositionbuffer_eachdir[i];
}

utils::parser::queryWithParser(
pp_warpx, "do_fieldinterp_gather_buffer", do_fieldinterp_gather_buffer);
utils::parser::queryWithParser(
pp_warpx, "tanh_midpoint_gather_buffer", tanh_midpoint_gather_buffer);

amrex::Real quantum_xi_tmp;
const auto quantum_xi_is_specified =
utils::parser::queryWithParser(pp_warpx, "quantum_xi", quantum_xi_tmp);
Expand Down Expand Up @@ -3132,8 +3125,6 @@ WarpX::getLoadBalanceEfficiency (const int lev)
void
WarpX::BuildBufferMasks ()
{
bool do_interpolate = WarpX::do_fieldinterp_gather_buffer;
amrex::Real tanh_midpoint = WarpX::tanh_midpoint_gather_buffer;
for (int lev = 1; lev <= maxLevel(); ++lev)
{
for (int ipass = 0; ipass < 2; ++ipass)
Expand Down Expand Up @@ -3161,112 +3152,11 @@ WarpX::BuildBufferMasks ()
const Box tbx = mfi.growntilebox();
BuildBufferMasksInBox( tbx, (*bmasks)[mfi], tmp[mfi], ngbuffer );
}
//if (ipass==0) continue;
//amrex::MultiFab* weight_gbuffer = interp_weight_gbuffer[lev].get();
//// Using tmp to also set weights in the interp_weight_gbuffer multifab
//for (MFIter mfi(*weight_gbuffer, true); mfi.isValid(); ++mfi)
//{
// const Box& tbx = mfi.tilebox(IntVect::TheNodeVector(),weight_gbuffer->nGrowVect());
// auto const& gmsk = tmp[mfi].const_array();
// auto const& bmsk = (*bmasks)[mfi].array();
// auto const& wtmsk = (*weight_gbuffer)[mfi].array();
// SetWeightsInGatherBuffer(tbx, wtmsk, gmsk, bmsk, ngbuffer, do_interpolate, tanh_midpoint);
// //amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
// // wtmsk(i,j,k) = 0._rt;
// // if (bmsk(i,j,k) == 0 && do_interpolate) {
// // if(gmsk(i,j,k)==0) {
// // wtmsk(i,j,k) = 0.;
// // return;
// // }
// // for (int ii = i-1; ii >= i-ngbuffer; --ii) {
// // if (gmsk(ii,j,k)==0) {
// // amrex::Real arg = (static_cast<amrex::Real>(i-ii)-ngbuffer*tanh_midpoint)
// // / ((1.-tanh_midpoint)*(ngbuffer/3.));
// // wtmsk(i,j,k) = std::tanh(arg)*0.5 + 0.5;
// // amrex::Print() << " i edge wt is " << wtmsk(i,j,k) << "\n";
// // return;
// // }
// // }
// // for (int ii = i+1; ii <= i+ngbuffer; ++ii) {
// // if (gmsk(ii,j,k)==0) {
// // amrex::Real arg = (static_cast<amrex::Real>(ii-i)-ngbuffer*tanh_midpoint)
// // / ((1.-tanh_midpoint)*(ngbuffer/3.));
// // wtmsk(i,j,k) = std::tanh(arg)*0.5+0.5;
// // amrex::Print() << " wt is " << wtmsk(i,j,k) << "\n";
// // return;
// // }
// // }
// // //for (int jj = j-1; jj >= j-ngbuffer; --jj) {
// // // if (gmsk(i,jj,k)==0) {
// // // amrex::Real arg = (static_cast<amrex::Real>(j-jj)-ngbuffer*tanh_midpoint)
// // // / ((1.-tanh_midpoint)*(ngbuffer/3.));
// // // wtmsk(i,j,k) = std::tanh(arg)*0.5 + 0.5;
// // // return;
// // // }
// // //}
// // //for (int jj = j+1; jj <= j+ngbuffer; ++jj) {
// // // if (gmsk(i,jj,k)==0) {
// // // amrex::Real arg = (static_cast<amrex::Real>(jj - j)-ngbuffer*tanh_midpoint)
// // // / ((1.-tanh_midpoint)*(ngbuffer/3.));
// // // wtmsk(i,j,k) = std::tanh(arg)*0.5+0.5;
// // // return;
// // // }
// // //}
// // //for (int kk = k-1; kk >= k-ngbuffer; --kk) {
// // // if (gmsk(i,j,kk)==0) {
// // // amrex::Real arg = (static_cast<amrex::Real>(k-kk)-ngbuffer*tanh_midpoint)
// // // / ((1.-tanh_midpoint)*(ngbuffer/3.));
// // // wtmsk(i,j,k) = std::tanh(arg)*0.5+0.5;
// // // return;
// // // }
// // //}
// // //for (int kk = k+1; kk <= k+ngbuffer; ++kk) {
// // // if (gmsk(i,j,kk)==0) {
// // // amrex::Real arg = (static_cast<amrex::Real>(kk-k)-ngbuffer*tanh_midpoint)
// // // / ((1.-tanh_midpoint)*(ngbuffer/3.));
// // // wtmsk(i,j,k) = std::tanh(arg)*0.5+0.5;
// // // return;
// // // }
// // //}
// // }
// //});
//}
}
}
}
}

void
WarpX::SetWeightsInGatherBuffer(const amrex::Box tbx, amrex::Array4<amrex::Real> wtmsk,
const amrex::Array4<int const> gmsk, const amrex::Array4<int const> bmsk, const int ngbuffer, const bool do_interpolate, amrex::Real tanh_midpoint)
{
amrex::ParallelFor(tbx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
wtmsk(i,j,k) = 0._rt;
if (bmsk(i,j,k) == 0 && do_interpolate) {
if(gmsk(i,j,k)==0) {
wtmsk(i,j,k) = 0.;
return;
}
for (int ii = i-1; ii >= i-ngbuffer; --ii) {
if (gmsk(ii,j,k)==0) {
amrex::Real arg = (static_cast<amrex::Real>(i-ii)-ngbuffer*tanh_midpoint)
/ ((1.-tanh_midpoint)*(ngbuffer/3.));
wtmsk(i,j,k) = std::tanh(arg)*0.5 + 0.5;
return;
}
}
for (int ii = i+1; ii <= i+ngbuffer; ++ii) {
if (gmsk(ii,j,k)==0) {
amrex::Real arg = (static_cast<amrex::Real>(ii-i)-ngbuffer*tanh_midpoint)
/ ((1.-tanh_midpoint)*(ngbuffer/3.));
wtmsk(i,j,k) = std::tanh(arg)*0.5+0.5;
return;
}
}
}
});
}

/**
* \brief Build buffer mask within given FArrayBox
*
Expand Down

0 comments on commit 74cbd90

Please sign in to comment.