Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WarpX class: move AllocateCenteringCoefficients to anonymous namespace in WarpX.cpp #5666

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -1239,26 +1239,6 @@ private:
return gather_buffer_masks[lev].get();
}

/**
* \brief Allocates and initializes the stencil coefficients used for the finite-order centering
* of fields and currents, and stores them in the given device vectors.
*
* \param[in,out] device_centering_stencil_coeffs_x device vector where the stencil coefficients along x will be stored
* \param[in,out] device_centering_stencil_coeffs_y device vector where the stencil coefficients along y will be stored
* \param[in,out] device_centering_stencil_coeffs_z device vector where the stencil coefficients along z will be stored
* \param[in] centering_nox order of the finite-order centering along x
* \param[in] centering_noy order of the finite-order centering along y
* \param[in] centering_noz order of the finite-order centering along z
* \param[in] a_grid_type type of grid (collocated or not)
*/
void AllocateCenteringCoefficients (amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_x,
amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_y,
amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_z,
int centering_nox,
int centering_noy,
int centering_noz,
ablastr::utils::enums::GridType a_grid_type);

void AllocLevelMFs (int lev, const amrex::BoxArray& ba, const amrex::DistributionMapping& dm,
const amrex::IntVect& ngEB, amrex::IntVect& ngJ,
const amrex::IntVect& ngRho, const amrex::IntVect& ngF,
Expand Down
132 changes: 62 additions & 70 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ WarpX* WarpX::m_instance = nullptr;

namespace
{

[[nodiscard]] bool
isAnyBoundaryPML(
const amrex::Array<FieldBoundaryType,AMREX_SPACEDIM>& field_boundary_lo,
Expand All @@ -201,6 +200,66 @@ namespace
return is_any_pml;
}

/**
* \brief Allocates and initializes the stencil coefficients used for the finite-order centering
* of fields and currents, and stores them in the given device vectors.
*
* \param[in,out] device_centering_stencil_coeffs_x device vector where the stencil coefficients along x will be stored
* \param[in,out] device_centering_stencil_coeffs_y device vector where the stencil coefficients along y will be stored
* \param[in,out] device_centering_stencil_coeffs_z device vector where the stencil coefficients along z will be stored
* \param[in] centering_nox order of the finite-order centering along x
* \param[in] centering_noy order of the finite-order centering along y
* \param[in] centering_noz order of the finite-order centering along z
* \param[in] a_grid_type type of grid (collocated or not)
*/
void AllocateCenteringCoefficients (amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_x,
amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_y,
amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_z,
int centering_nox,
int centering_noy,
int centering_noz,
ablastr::utils::enums::GridType a_grid_type)
{
// Vectors of Fornberg stencil coefficients
const auto Fornberg_stencil_coeffs_x = ablastr::math::getFornbergStencilCoefficients(centering_nox, a_grid_type);
const auto Fornberg_stencil_coeffs_y = ablastr::math::getFornbergStencilCoefficients(centering_noy, a_grid_type);
const auto Fornberg_stencil_coeffs_z = ablastr::math::getFornbergStencilCoefficients(centering_noz, a_grid_type);

// Host vectors of stencil coefficients used for finite-order centering
auto host_centering_stencil_coeffs_x = amrex::Vector<amrex::Real>(centering_nox);
auto host_centering_stencil_coeffs_y = amrex::Vector<amrex::Real>(centering_noy);
auto host_centering_stencil_coeffs_z = amrex::Vector<amrex::Real>(centering_noz);

// Re-order Fornberg stencil coefficients:
// example for order 6: (c_0,c_1,c_2) becomes (c_2,c_1,c_0,c_0,c_1,c_2)
ablastr::math::ReorderFornbergCoefficients(
host_centering_stencil_coeffs_x,
Fornberg_stencil_coeffs_x,
centering_nox);

ablastr::math::ReorderFornbergCoefficients(
host_centering_stencil_coeffs_y,
Fornberg_stencil_coeffs_y,
centering_noy);

ablastr::math::ReorderFornbergCoefficients(
host_centering_stencil_coeffs_z,
Fornberg_stencil_coeffs_z,
centering_noz);

// Device vectors of stencil coefficients used for finite-order centering
const auto copy_to_device = [](const auto& src, auto& dst){
dst.resize(src.size());
amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice, src.begin(), src.end(), dst.begin());
};

copy_to_device(host_centering_stencil_coeffs_x, device_centering_stencil_coeffs_x);
copy_to_device(host_centering_stencil_coeffs_y, device_centering_stencil_coeffs_y);
copy_to_device(host_centering_stencil_coeffs_z, device_centering_stencil_coeffs_z);

amrex::Gpu::synchronize();
}

/**
* \brief
* Set the dotMask container
Expand Down Expand Up @@ -1067,7 +1126,7 @@ WarpX::ReadParameters ()
utils::parser::queryWithParser(
pp_warpx, "current_centering_noz", current_centering_noz);

AllocateCenteringCoefficients(device_current_centering_stencil_coeffs_x,
::AllocateCenteringCoefficients(device_current_centering_stencil_coeffs_x,
device_current_centering_stencil_coeffs_y,
device_current_centering_stencil_coeffs_z,
current_centering_nox,
Expand Down Expand Up @@ -1419,7 +1478,7 @@ WarpX::ReadParameters ()
utils::parser::queryWithParser(
pp_warpx, "field_centering_noz", field_centering_noz);

AllocateCenteringCoefficients(device_field_centering_stencil_coeffs_x,
::AllocateCenteringCoefficients(device_field_centering_stencil_coeffs_x,
device_field_centering_stencil_coeffs_y,
device_field_centering_stencil_coeffs_z,
field_centering_nox,
Expand Down Expand Up @@ -3182,73 +3241,6 @@ WarpX::BuildBufferMasksInBox ( const amrex::Box tbx, amrex::IArrayBox &buffer_ma
});
}

void WarpX::AllocateCenteringCoefficients (amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_x,
amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_y,
amrex::Gpu::DeviceVector<amrex::Real>& device_centering_stencil_coeffs_z,
const int centering_nox,
const int centering_noy,
const int centering_noz,
ablastr::utils::enums::GridType a_grid_type)
{
// Vectors of Fornberg stencil coefficients
amrex::Vector<amrex::Real> Fornberg_stencil_coeffs_x;
amrex::Vector<amrex::Real> Fornberg_stencil_coeffs_y;
amrex::Vector<amrex::Real> Fornberg_stencil_coeffs_z;

// Host vectors of stencil coefficients used for finite-order centering
amrex::Vector<amrex::Real> host_centering_stencil_coeffs_x;
amrex::Vector<amrex::Real> host_centering_stencil_coeffs_y;
amrex::Vector<amrex::Real> host_centering_stencil_coeffs_z;

Fornberg_stencil_coeffs_x = ablastr::math::getFornbergStencilCoefficients(centering_nox, a_grid_type);
Fornberg_stencil_coeffs_y = ablastr::math::getFornbergStencilCoefficients(centering_noy, a_grid_type);
Fornberg_stencil_coeffs_z = ablastr::math::getFornbergStencilCoefficients(centering_noz, a_grid_type);

host_centering_stencil_coeffs_x.resize(centering_nox);
host_centering_stencil_coeffs_y.resize(centering_noy);
host_centering_stencil_coeffs_z.resize(centering_noz);

// Re-order Fornberg stencil coefficients:
// example for order 6: (c_0,c_1,c_2) becomes (c_2,c_1,c_0,c_0,c_1,c_2)
ablastr::math::ReorderFornbergCoefficients(
host_centering_stencil_coeffs_x,
Fornberg_stencil_coeffs_x,
centering_nox
);
ablastr::math::ReorderFornbergCoefficients(
host_centering_stencil_coeffs_y,
Fornberg_stencil_coeffs_y,
centering_noy
);
ablastr::math::ReorderFornbergCoefficients(
host_centering_stencil_coeffs_z,
Fornberg_stencil_coeffs_z,
centering_noz
);

// Device vectors of stencil coefficients used for finite-order centering

device_centering_stencil_coeffs_x.resize(host_centering_stencil_coeffs_x.size());
amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice,
host_centering_stencil_coeffs_x.begin(),
host_centering_stencil_coeffs_x.end(),
device_centering_stencil_coeffs_x.begin());

device_centering_stencil_coeffs_y.resize(host_centering_stencil_coeffs_y.size());
amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice,
host_centering_stencil_coeffs_y.begin(),
host_centering_stencil_coeffs_y.end(),
device_centering_stencil_coeffs_y.begin());

device_centering_stencil_coeffs_z.resize(host_centering_stencil_coeffs_z.size());
amrex::Gpu::copyAsync(amrex::Gpu::hostToDevice,
host_centering_stencil_coeffs_z.begin(),
host_centering_stencil_coeffs_z.end(),
device_centering_stencil_coeffs_z.begin());

amrex::Gpu::synchronize();
}

const iMultiFab*
WarpX::CurrentBufferMasks (int lev)
{
Expand Down
Loading