Skip to content

Commit

Permalink
WarpXSumGuardCells: move function definitions in cpp file (ECP-WarpX#…
Browse files Browse the repository at this point in the history
…4521)

* move function definition in cpp file

* fix bugs

* fix issue found with clang-tidy

* Clean Commented Line

Co-authored-by: Luca Fedeli <[email protected]>

---------

Co-authored-by: Axel Huebl <[email protected]>
  • Loading branch information
2 people authored and dpgrote committed Dec 19, 2023
1 parent 841fa2c commit ee5edfc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
1 change: 1 addition & 0 deletions Source/Parallelization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ foreach(D IN LISTS WarpX_DIMS)
GuardCellManager.cpp
WarpXComm.cpp
WarpXRegrid.cpp
WarpXSumGuardCells.cpp
)
endforeach()
1 change: 1 addition & 0 deletions Source/Parallelization/Make.package
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CEXE_sources += WarpXComm.cpp
CEXE_sources += WarpXRegrid.cpp
CEXE_sources += GuardCellManager.cpp
CEXE_sources += WarpXSumGuardCells.cpp

VPATH_LOCATIONS += $(WARPX_HOME)/Source/Parallelization
37 changes: 4 additions & 33 deletions Source/Parallelization/WarpXSumGuardCells.H
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#ifndef WARPX_SUM_GUARD_CELLS_H_
#define WARPX_SUM_GUARD_CELLS_H_

#include "Utils/WarpXAlgorithmSelection.H"

#include <ablastr/utils/Communication.H>

#include <AMReX_MultiFab.H>

/** \brief Sum the values of `mf`, where the different boxes overlap
Expand All @@ -26,21 +22,10 @@
* updates both the *valid* cells and *guard* cells. (This is because a
* spectral solver requires the value of the sources over a large stencil.)
*/
inline void
void
WarpXSumGuardCells(amrex::MultiFab& mf, const amrex::Periodicity& period,
const amrex::IntVect& src_ngrow,
const int icomp=0, const int ncomp=1)
{
amrex::IntVect n_updated_guards;

// Update both valid cells and guard cells
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
n_updated_guards = mf.nGrowVect();
} else { // Update only the valid cells
n_updated_guards = amrex::IntVect::TheZeroVector();
}
ablastr::utils::communication::SumBoundary(mf, icomp, ncomp, src_ngrow, n_updated_guards, WarpX::do_single_precision_comms, period);
}
int icomp=0, int ncomp=1);

/** \brief Sum the values of `src` where the different boxes overlap
* (i.e. in the guard cells) and copy them into `dst`
Expand All @@ -57,24 +42,10 @@ WarpXSumGuardCells(amrex::MultiFab& mf, const amrex::Periodicity& period,
* Note: `i_comp` is the component where the results will be stored in `dst`;
* The component from which we copy in `src` is always 0.
*/
inline void
void
WarpXSumGuardCells(amrex::MultiFab& dst, amrex::MultiFab& src,
const amrex::Periodicity& period,
const amrex::IntVect& src_ngrow,
const int icomp=0, const int ncomp=1)
{
amrex::IntVect n_updated_guards;

// Update both valid cells and guard cells
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
n_updated_guards = dst.nGrowVect();
} else { // Update only the valid cells
n_updated_guards = amrex::IntVect::TheZeroVector();
}

dst.setVal(0., icomp, ncomp, n_updated_guards);
// ablastr::utils::communication::ParallelAdd(dst, src, 0, icomp, ncomp, src_ngrow, n_updated_guards, period);
dst.ParallelAdd(src, 0, icomp, ncomp, src_ngrow, n_updated_guards, period);
}
int icomp=0, int ncomp=1);

#endif // WARPX_SUM_GUARD_CELLS_H_
51 changes: 51 additions & 0 deletions Source/Parallelization/WarpXSumGuardCells.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Copyright 2019 Maxence Thevenet, Remi Lehe, Weiqun Zhang
*
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/

#include "WarpXSumGuardCells.H"

#include "Utils/WarpXAlgorithmSelection.H"

#include "WarpX.H"

#include <ablastr/utils/Communication.H>

void
WarpXSumGuardCells(amrex::MultiFab& mf, const amrex::Periodicity& period,
const amrex::IntVect& src_ngrow,
const int icomp, const int ncomp)
{
amrex::IntVect n_updated_guards;

// Update both valid cells and guard cells
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
n_updated_guards = mf.nGrowVect();
} else { // Update only the valid cells
n_updated_guards = amrex::IntVect::TheZeroVector();
}
ablastr::utils::communication::SumBoundary(mf, icomp, ncomp, src_ngrow, n_updated_guards, WarpX::do_single_precision_comms, period);
}


void
WarpXSumGuardCells(amrex::MultiFab& dst, amrex::MultiFab& src,
const amrex::Periodicity& period,
const amrex::IntVect& src_ngrow,
const int icomp, const int ncomp)
{
amrex::IntVect n_updated_guards;

// Update both valid cells and guard cells
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
n_updated_guards = dst.nGrowVect();
} else { // Update only the valid cells
n_updated_guards = amrex::IntVect::TheZeroVector();
}

dst.setVal(0., icomp, ncomp, n_updated_guards);
dst.ParallelAdd(src, 0, icomp, ncomp, src_ngrow, n_updated_guards, period);
}

0 comments on commit ee5edfc

Please sign in to comment.