1#ifndef AMREX_AmrParticles_H_
2#define AMREX_AmrParticles_H_
3#include <AMReX_Config.H>
32template <
typename ParticleType,
int NArrayReal,
int NArrayInt,
33 template<
class>
class Allocator,
class CellAssignor>
37 Vector<std::unique_ptr<MultiFab> >& mf_to_be_filled,
38 int lev_min,
int ncomp,
int finest_level,
int ngrow)
const
41 BL_PROFILE(
"ParticleContainer::AssignDensity()");
43 if (rho_index != 0) {
amrex::Abort(
"AssignDensity only works if rho_index = 0"); }
47 BL_ASSERT(ncomp == 1 || ncomp == AMREX_SPACEDIM+1);
49 if (finest_level == -1) {
52 while (!this->
m_gdb->LevelDefined(finest_level)) {
56 ngrow = std::max(ngrow, 2);
59 mf_to_be_filled.resize(finest_level+1);
60 for (
int lev = lev_min; lev <= finest_level; lev++)
63 mf_to_be_filled[lev] = std::make_unique<MultiFab>(this->
m_gdb->boxArray(lev),
64 this->m_gdb->DistributionMap(lev),
66 mf_to_be_filled[lev]->setVal(0.0);
70 bool all_grids_the_same =
true;
71 for (
int lev = lev_min; lev <= finest_level; lev++)
75 all_grids_the_same =
false;
81 if (!all_grids_the_same)
84 mf_part.resize(finest_level+1);
85 for (
int lev = lev_min; lev <= finest_level; lev++)
92 mf_part[lev]->setVal(0.0);
96 auto & mf = (all_grids_the_same) ? mf_to_be_filled : mf_part;
98 if (finest_level == 0)
104 if ( ! all_grids_the_same) {
105 mf_to_be_filled[0]->ParallelCopy(*mf[0],0,0,ncomp,0,0);
117 for (
int lev = lev_min; lev <= finest_level; ++lev) {
118 const BoxArray& ba = mf[lev]->boxArray();
120 tmp[lev] = std::make_unique<MultiFab>(ba, dm, ncomp, 0,
122 tmp[lev]->setVal(0.0);
125 for (
int lev = lev_min; lev <= finest_level; ++lev) {
129 if (lev < finest_level) {
132 rho_index, rho_index, ncomp,
133 this->
m_gdb->Geom(lev),
134 this->m_gdb->Geom(lev+1),
135 cphysbc, 0, fphysbc, 0,
136 this->m_gdb->refRatio(lev), &mapper,
145 this->
m_gdb->refRatio(lev-1),
146 this->m_gdb->Geom(lev-1),
147 this->m_gdb->Geom(lev));
150 mf[lev]->plus(*tmp[lev], rho_index, ncomp, 0);
153 for (
int lev = finest_level - 1; lev >= lev_min; --lev) {
157 if (!all_grids_the_same) {
158 for (
int lev = lev_min; lev <= finest_level; lev++) {
162 mf_to_be_filled[lev]->ParallelCopy(*mf_part[lev],0,0,ncomp,0,0);
166 int nlevels = finest_level - lev_min + 1;
167 for (
int i = 0; i < nlevels; i++)
169 mf_to_be_filled[i] = std::move(mf_to_be_filled[i+lev_min]);
171 mf_to_be_filled.resize(nlevels);
188template <
class PC,
class F>
192 int lev_min,
int lev_max,
F&& f,
193 bool zero_out_input=
true,
bool vol_weight=
true)
197 if (lev_max == -1) { lev_max = pc.finestLevel(); }
198 while (!pc.GetParGDB()->LevelDefined(lev_max)) { lev_max--; }
202 ParticleToMesh(pc, *mf[0], 0, std::forward<F>(f), zero_out_input);
204 const Real* dx = pc.Geom(0).CellSize();
206 mf[0]->mult(
Real(1.0)/vol, 0, mf[0]->
nComp(), mf[0]->nGrow());
213 mf[0]->nGrow(2)), 2);
217 for (
int lev = lev_min; lev <= lev_max; ++lev)
219 mf[lev]->setVal(
Real(0.0));
225 for (
int lev = lev_min; lev <= lev_max; ++lev)
227 mf_part[lev].define(pc.ParticleBoxArray(lev),
228 pc.ParticleDistributionMap(lev),
229 mf[lev]->nComp(), ngrow,
231 mf_tmp[lev].define( pc.ParticleBoxArray(lev),
232 pc.ParticleDistributionMap(lev),
235 mf_part[lev].setVal(0.0);
236 mf_tmp[lev].setVal( 0.0);
245 for (
int lev = lev_min; lev <= lev_max; ++lev)
249 const Real* dx = pc.Geom(lev).CellSize();
251 mf_part[lev].mult(
Real(1.0)/vol, 0, mf_part[lev].
nComp(), mf_part[lev].nGrow());
257 0, 0, mf_part[lev].
nComp(),
258 pc.GetParGDB()->Geom(lev),
259 pc.GetParGDB()->Geom(lev+1),
260 cphysbc, 0, fphysbc, 0,
261 pc.GetParGDB()->refRatio(lev), &mapper,
270 pc.GetParGDB()->refRatio(lev-1),
271 pc.GetParGDB()->Geom(lev-1),
272 pc.GetParGDB()->Geom(lev));
275 mf_part[lev].plus(mf_tmp[lev], 0, mf_part[lev].
nComp(), 0);
278 for (
int lev = lev_max-1; lev >= lev_min; --lev) {
280 pc.GetParGDB()->refRatio(lev));
283 for (
int lev = lev_min; lev <= lev_max; lev++)
285 if (zero_out_input) {
286 mf[lev]->ParallelCopy(mf_part[lev],0,0,mf_part[lev].
nComp(),0,0);
288 mf[lev]->ParallelAdd(mf_part[lev],0,0,mf_part[lev].
nComp(),0,0);
293template <
typename T_ParticleType,
int NArrayReal=0,
int NArrayInt=0,
294 template<
class>
class Allocator=
DefaultAllocator,
class CellAssignor=DefaultAssignor>
344template <
int T_NStructReal,
int T_NStructInt=0,
int T_NArrayReal=0,
int T_NArrayInt=0,
Particle Geometry, DistributionMapping and BoxArray helper shared by AmrCore-based apps.
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
High-level FillPatch helpers for AMR coarse-to-fine synchronization.
Collection of spatial interpolaters used by FillPatch and flux-register logic.
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Provide basic functionalities to set up an AMR hierarchy.
Definition AMReX_AmrCore.H:31
Particle container that automatically pulls grid metadata from AmrCore when available.
Definition AMReX_AmrParticles.H:300
AmrParticleContainer_impl(const AmrParticleContainer_impl &)=delete
AmrParticleContainer_impl & operator=(const AmrParticleContainer_impl &)=delete
AmrParticleContainer_impl(const Vector< Geometry > &geom, const Vector< DistributionMapping > &dmap, const Vector< BoxArray > &ba, const Vector< int > &rr)
Construct from explicit Geometry, DistributionMapping and BoxArray.
Definition AMReX_AmrParticles.H:326
~AmrParticleContainer_impl() override=default
AmrParticleContainer_impl(AmrCore *amr_core)
Construct from amr_core.
Definition AMReX_AmrParticles.H:313
AmrParticleContainer_impl(AmrParticleContainer_impl &&) noexcept=default
T_ParticleType ParticleType
Definition AMReX_AmrParticles.H:304
AmrParticleContainer_impl()
Construct an empty container (call Define later).
Definition AMReX_AmrParticles.H:307
AmrTracerParticleContainer(AmrTracerParticleContainer &&) noexcept=default
~AmrTracerParticleContainer() override=default
AmrTracerParticleContainer(const AmrTracerParticleContainer &)=delete
AmrTracerParticleContainer(AmrCore *amr_core)
Construct from amr_core.
Definition AMReX_AmrParticles.H:357
Boundary condition record storing low/high face types per coordinate.
Definition AMReX_BCRec.H:25
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:55
Piecewise Constant interpolation on cell centered data.
Definition AMReX_Interpolater.H:423
const DistributionMapping & ParticleDistributionMap(int lev) const
Get the DistributionMapping for a given level.
Definition AMReX_ParticleContainerBase.H:207
ParGDBBase * m_gdb
Definition AMReX_ParticleContainerBase.H:320
const BoxArray & ParticleBoxArray(int lev) const
Get the BoxArray for a given level.
Definition AMReX_ParticleContainerBase.H:200
void SetArena(Arena *a)
Definition AMReX_ParticleContainerBase.H:272
const ParGDBBase * GetParGDB() const
Get the ParGDB object used to define this container (const version).
Definition AMReX_ParticleContainerBase.H:232
bool OnSameGrids(int level, const MF &mf) const
Definition AMReX_ParticleContainerBase.H:266
int finestLevel() const
the finest level actually defined for the ParticleContainer
Definition AMReX_ParticleContainerBase.H:223
A distributed container for Particles sorted onto the levels, grids, and tiles of a block-structured ...
Definition AMReX_ParticleContainer.H:154
static constexpr int NArrayInt
Number of extra integer components stored in struct-of-array form.
Definition AMReX_ParticleContainer.H:167
static constexpr int NArrayReal
Number of extra Real components stored in struct-of-array form.
Definition AMReX_ParticleContainer.H:165
ParticleContainer_impl()
Definition AMReX_ParticleContainer.H:222
void AssignCellDensitySingleLevel(int rho_index, MultiFab &mf, int level, int ncomp=1, int particle_lvl_offset=0) const
Definition AMReX_ParticleContainerI.H:1998
T_CellAssignor CellAssignor
Definition AMReX_ParticleContainer.H:158
static constexpr int NStructReal
Number of extra Real components in the particle struct.
Definition AMReX_ParticleContainer.H:161
Definition AMReX_PhysBCFunct.H:128
TracerParticleContainer(ParGDBBase *gdb)
Definition AMReX_TracerParticles.H:14
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
Arena * The_Async_Arena()
Definition AMReX_Arena.cpp:849
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:54
@ int_dir
Definition AMReX_BC_TYPES.H:89
Definition AMReX_Amr.cpp:50
@ F
Definition AMReX_Order.H:7
void average_down(const MultiFab &S_fine, MultiFab &S_crse, const Geometry &fgeom, const Geometry &cgeom, int scomp, int ncomp, int rr)
Definition AMReX_MultiFabUtil.cpp:360
amrex::ArenaAllocator< T > DefaultAllocator
Definition AMReX_GpuAllocators.H:205
void ParticleToMesh(PC const &pc, const Vector< MultiFab * > &mf, int lev_min, int lev_max, F &&f, bool zero_out_input=true, bool vol_weight=true)
Deposit particles onto a hierarchy of MultiFabs.
Definition AMReX_AmrParticles.H:191
AmrParticleContainer_impl< Particle< T_NStructReal, T_NStructInt >, T_NArrayReal, T_NArrayInt, Allocator, CellAssignor > AmrParticleContainer
Convenience alias that binds Particle<T_NStructReal,T_NStructInt> to AmrParticleContainer_impl.
Definition AMReX_AmrParticles.H:346
int nComp(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nComp().
Definition AMReX_FabArrayBase.cpp:3028
void sum_fine_to_coarse(const MultiFab &S_fine, MultiFab &S_crse, int scomp, int ncomp, const IntVect &ratio, const Geometry &cgeom, const Geometry &)
Definition AMReX_MultiFabUtil.cpp:440
void InterpFromCoarseLevel(MF &mf, Real time, const MF &cmf, int scomp, int dcomp, int ncomp, const Geometry &cgeom, const Geometry &fgeom, BC &cbc, int cbccomp, BC &fbc, int fbccomp, const IntVect &ratio, Interp *mapper, const Vector< BCRec > &bcs, int bcscomp, const PreInterpHook &pre_interp={}, const PostInterpHook &post_interp={})
Fill with interpolation of coarse level data.
Definition AMReX_FillPatchUtil_I.H:1029
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:239
Definition AMReX_ParticleUtil.H:445
Definition AMReX_TypeTraits.H:90
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
The struct used to store particles.
Definition AMReX_Particle.H:405