24#ifndef BOXLIB_PARTICLE_HPP
25#define BOXLIB_PARTICLE_HPP
29#include <AMReX_BLFort.H>
30#include <AMReX_MultiFabUtil.H>
31#include <AMReX_MultiFabUtil_F.H>
32#include <AMReX_Interpolater.H>
33#include <AMReX_FillPatchUtil.H>
35template<
class PLayout>
42template<
class PLayout>
49template<
class PLayout>
50template<
class FT,
unsigned Dim,
class PT>
56 if ( lbase == lfine ) {
57 this->
scatter(attrib, *(f[lbase].get()), pp, pbin, bin, lbase);
61 const PLayout *layout_p = &this->getLayout();
62 int nGrow = layout_p->refRatio(lbase)[0];
65 for (
int lev = lbase; lev <= lfine; ++lev) {
67 f[lev]->setVal(0.0, f[lev]->nGrow());
71 tmp[lev].reset(
new AmrField_t(ba, dm, 1, nGrow));
72 tmp[lev]->setVal(0.0, nGrow);
75 this->AssignDensityFort(attrib, tmp, lbase, 1, lfine, pbin, bin);
77 for (
int lev = lbase; lev <= lfine; ++lev)
78 AmrField_t::Copy(*f[lev], *tmp[lev], 0, 0, f[lev]->nComp(), f[lev]->nGrow());
82template<
class PLayout>
83template <
class FT,
unsigned Dim,
class PT>
95 this->AssignCellDensitySingleLevelFort(attrib, tmp, level, pbin, bin);
97 f.setVal(0.0, f.nGrow());
99 AmrField_t::Copy(f, tmp, 0, 0, f.nComp(), f.nGrow());
103template<
class PLayout>
104template<
class FT,
unsigned Dim,
class PT>
107 int lbase,
int lfine)
109 this->InterpolateFort(attrib, f, lbase, lfine);
115template<
class PLayout>
116template <
class AType>
119 int lev_min,
int ncomp,
int finest_level,
124 const PLayout *layout_p = &this->getLayout();
129 amrex::PhysBCFunct cphysbc, fphysbc;
130 int lo_bc[] = {INT_DIR, INT_DIR, INT_DIR};
131 int hi_bc[] = {INT_DIR, INT_DIR, INT_DIR};
132 amrex::Vector<amrex::BCRec> bcs(1, amrex::BCRec(lo_bc, hi_bc));
133 amrex::PCInterp mapper;
136 for (
int lev = lev_min; lev <= finest_level; ++lev) {
137 const AmrGrid_t& ba = mf_to_be_filled[lev]->boxArray();
138 const AmrProcMap_t& dm = mf_to_be_filled[lev]->DistributionMap();
140 tmp[lev]->setVal(0.0);
143 for (
int lev = lev_min; lev <= finest_level; ++lev) {
144 AssignCellDensitySingleLevelFort(pa, *mf_to_be_filled[lev], lev, pbin, bin, 1, 0);
146 if (lev < finest_level) {
147 amrex::InterpFromCoarseLevel(*tmp[lev+1], 0.0, *mf_to_be_filled[lev],
148 rho_index, rho_index, ncomp,
149 layout_p->Geom(lev), layout_p->Geom(lev+1),
151 layout_p->refRatio(lev), &mapper, bcs);
158 amrex::sum_fine_to_coarse(*mf_to_be_filled[lev],
159 *mf_to_be_filled[lev-1],
160 rho_index, 1, layout_p->refRatio(lev-1),
161 layout_p->Geom(lev-1), layout_p->Geom(lev));
164 mf_to_be_filled[lev]->plus(*tmp[lev], rho_index, ncomp, 0);
167 for (
int lev = finest_level - 1; lev >= lev_min; --lev) {
168 amrex::average_down(*mf_to_be_filled[lev+1],
169 *mf_to_be_filled[lev], rho_index, ncomp, layout_p->refRatio(lev));
177template<
class PLayout>
178template <
class AType>
189 const PLayout *layout_p = &this->getLayout();
193 if (layout_p->OnSameGrids(level, mf_to_be_filled)) {
196 mf_pointer = &mf_to_be_filled;
201 mf_pointer =
new AmrField_t(layout_p->ParticleBoxArray(level),
202 layout_p->ParticleDistributionMap(level),
203 ncomp, mf_to_be_filled.nGrow());
210 if (mf_pointer->nGrow() < 1)
211 throw OpalException(
"BoxLibParticle::AssignCellDensitySingleLevelFort()",
212 "Must have at least one ghost cell when in AssignCellDensitySingleLevelFort");
219 if (gm.isAnyPeriodic() && ! gm.isAllPeriodic()) {
220 throw OpalException(
"BoxLibParticle::AssignCellDensitySingleLevelFort()",
221 "Problem must be periodic in no or all directions");
224 for (amrex::MFIter mfi(*mf_pointer); mfi.isValid(); ++mfi) {
225 (*mf_pointer)[mfi].setVal(0);
230 size_t lBegin = LocalNumPerLevel.
begin(level);
231 size_t lEnd = LocalNumPerLevel.
end(level);
233 AmrReal_t inv_dx[3] = { 1.0 / dx[0], 1.0 / dx[1], 1.0 / dx[2] };
234 double lxyz[3] = { 0.0, 0.0, 0.0 };
235 double wxyz_hi[3] = { 0.0, 0.0, 0.0 };
236 double wxyz_lo[3] = { 0.0, 0.0, 0.0 };
237 int ijk[3] = {0, 0, 0};
239 for (
size_t ip = lBegin; ip < lEnd; ++ip) {
241 if ( bin > -1 && pbin[ip] != bin )
244 const int grid = this->Grid[ip];
249 for (
int i = 0; i < 3; ++i) {
250 lxyz[i] = ( this->
R[ip](i) - plo[i] ) * inv_dx[i] + 0.5;
252 wxyz_hi[i] = lxyz[i] - ijk[i];
253 wxyz_lo[i] = 1.0 - wxyz_hi[i];
269 fab(i1, 0) += wxyz_lo[0]*wxyz_lo[1]*wxyz_lo[2]*pa[ip];
270 fab(i2, 0) += wxyz_lo[0]*wxyz_lo[1]*wxyz_hi[2]*pa[ip];
271 fab(i3, 0) += wxyz_lo[0]*wxyz_hi[1]*wxyz_lo[2]*pa[ip];
272 fab(i4, 0) += wxyz_lo[0]*wxyz_hi[1]*wxyz_hi[2]*pa[ip];
273 fab(i5, 0) += wxyz_hi[0]*wxyz_lo[1]*wxyz_lo[2]*pa[ip];
274 fab(i6, 0) += wxyz_hi[0]*wxyz_lo[1]*wxyz_hi[2]*pa[ip];
275 fab(i7, 0) += wxyz_hi[0]*wxyz_hi[1]*wxyz_lo[2]*pa[ip];
276 fab(i8, 0) += wxyz_hi[0]*wxyz_hi[1]*wxyz_hi[2]*pa[ip];
280 mf_pointer->SumBoundary(gm.periodicity());
285 const AmrReal_t vol = D_TERM(dx[0], *dx[1], *dx[2]);
287 mf_pointer->mult(1.0/vol, 0, 1, mf_pointer->nGrow());
292 if (mf_pointer != &mf_to_be_filled) {
293 mf_to_be_filled.copy(*mf_pointer,0,0,ncomp);
299template<
class PLayout>
300template <
class AType>
303 int lev_min,
int lev_max)
305 for (
int lev = lev_min; lev <= lev_max; ++lev) {
307 InterpolateMultiLevelFort(pa, mesh_data, lev);
309 InterpolateSingleLevelFort(pa, mesh_data[lev], lev);
314template<
class PLayout>
315template <
class AType>
319 for (std::size_t i = 0; i < mesh_data.size(); ++i) {
320 if (mesh_data[i]->nGrow() < 1)
321 throw OpalException(
"BoxLibParticle::InterpolateSingleLevelFort()",
322 "Must have at least one ghost cell when in InterpolateSingleLevelFort");
325 PLayout *layout_p = &this->getLayout();
333 size_t lBegin = LocalNumPerLevel.
begin(lev);
334 size_t lEnd = LocalNumPerLevel.
end(lev);
337 for (std::size_t i = 0; i < mesh_data.size(); ++i) {
338 mesh_data[i]->FillBoundary(gm.periodicity());
341 AmrReal_t inv_dx[3] = { 1.0 / dx[0], 1.0 / dx[1], 1.0 / dx[2] };
342 double lxyz[3] = { 0.0, 0.0, 0.0 };
343 double wxyz_hi[3] = { 0.0, 0.0, 0.0 };
344 double wxyz_lo[3] = { 0.0, 0.0, 0.0 };
345 int ijk[3] = {0, 0, 0};
346 for (
size_t ip = lBegin; ip < lEnd; ++ip) {
348 const int grid = this->Grid[ip];
356 for (
int i = 0; i < 3; ++i) {
357 lxyz[i] = ( this->
R[ip](i) - plo[i] ) * inv_dx[i] + 0.5;
359 wxyz_hi[i] = lxyz[i] - ijk[i];
360 wxyz_lo[i] = 1.0 - wxyz_hi[i];
376 pa[ip](0) = wxyz_lo[0]*wxyz_lo[1]*wxyz_lo[2]*exfab(i1) +
377 wxyz_lo[0]*wxyz_lo[1]*wxyz_hi[2]*exfab(i2) +
378 wxyz_lo[0]*wxyz_hi[1]*wxyz_lo[2]*exfab(i3) +
379 wxyz_lo[0]*wxyz_hi[1]*wxyz_hi[2]*exfab(i4) +
380 wxyz_hi[0]*wxyz_lo[1]*wxyz_lo[2]*exfab(i5) +
381 wxyz_hi[0]*wxyz_lo[1]*wxyz_hi[2]*exfab(i6) +
382 wxyz_hi[0]*wxyz_hi[1]*wxyz_lo[2]*exfab(i7) +
383 wxyz_hi[0]*wxyz_hi[1]*wxyz_hi[2]*exfab(i8);
385 pa[ip](1) = wxyz_lo[0]*wxyz_lo[1]*wxyz_lo[2]*eyfab(i1) +
386 wxyz_lo[0]*wxyz_lo[1]*wxyz_hi[2]*eyfab(i2) +
387 wxyz_lo[0]*wxyz_hi[1]*wxyz_lo[2]*eyfab(i3) +
388 wxyz_lo[0]*wxyz_hi[1]*wxyz_hi[2]*eyfab(i4) +
389 wxyz_hi[0]*wxyz_lo[1]*wxyz_lo[2]*eyfab(i5) +
390 wxyz_hi[0]*wxyz_lo[1]*wxyz_hi[2]*eyfab(i6) +
391 wxyz_hi[0]*wxyz_hi[1]*wxyz_lo[2]*eyfab(i7) +
392 wxyz_hi[0]*wxyz_hi[1]*wxyz_hi[2]*eyfab(i8);
394 pa[ip](2) = wxyz_lo[0]*wxyz_lo[1]*wxyz_lo[2]*ezfab(i1) +
395 wxyz_lo[0]*wxyz_lo[1]*wxyz_hi[2]*ezfab(i2) +
396 wxyz_lo[0]*wxyz_hi[1]*wxyz_lo[2]*ezfab(i3) +
397 wxyz_lo[0]*wxyz_hi[1]*wxyz_hi[2]*ezfab(i4) +
398 wxyz_hi[0]*wxyz_lo[1]*wxyz_lo[2]*ezfab(i5) +
399 wxyz_hi[0]*wxyz_lo[1]*wxyz_hi[2]*ezfab(i6) +
400 wxyz_hi[0]*wxyz_hi[1]*wxyz_lo[2]*ezfab(i7) +
401 wxyz_hi[0]*wxyz_hi[1]*wxyz_hi[2]*ezfab(i8);
407template<
class PLayout>
408template <
class AType>
413 for (std::size_t i = 0; i < mesh_data[lev].size(); ++i) {
414 if (mesh_data[lev][i]->nGrow() < 1)
415 throw OpalException(
"BoxLibParticle::InterpolateMultiLevelFort()",
416 "Must have at least one ghost cell when in InterpolateMultiLevelFort");
419 PLayout *layout_p = &this->getLayout();
424 const AmrReal_t* cdx = layout_p->Geom(lev-1).CellSize();
425 const AmrReal_t* cplo = layout_p->Geom(lev-1).ProbLo();
429 size_t lBegin = LocalNumPerLevel.
begin(lev);
430 size_t lEnd = LocalNumPerLevel.
end(lev);
433 for (std::size_t i = 0; i < mesh_data[lev].size(); ++i) {
434 mesh_data[lev][i]->FillBoundary(gm.periodicity());
437 AmrReal_t inv_fdx[3] = { 1.0 / fdx[0], 1.0 / fdx[1], 1.0 / fdx[2] };
438 AmrReal_t inv_cdx[3] = { 1.0 / cdx[0], 1.0 / cdx[1], 1.0 / cdx[2] };
439 double lxyz[3] = { 0.0, 0.0, 0.0 };
440 double wxyz_hi[3] = { 0.0, 0.0, 0.0 };
441 double wxyz_lo[3] = { 0.0, 0.0, 0.0 };
442 int ijk[3] = { 0, 0, 0 };
444 const AmrGrid_t& fba = mesh_data[lev][0]->boxArray();
445 const AmrProcMap_t& fdmap = mesh_data[lev][0]->DistributionMap();
450 mesh_data[lev][0]->nComp(),
451 mesh_data[lev][0]->nGrow());
453 cmesh_exdata.setVal(0.0, 0, 1, mesh_data[lev][0]->nGrow());
454 cmesh_exdata.copy(*mesh_data[lev-1][0], 0, 0, 1, 1, 1);
455 cmesh_exdata.FillBoundary(gm.periodicity());
458 mesh_data[lev][1]->nComp(),
459 mesh_data[lev][1]->nGrow());
460 cmesh_eydata.setVal(0.0, 0, 1, mesh_data[lev][1]->nGrow());
461 cmesh_eydata.copy(*mesh_data[lev-1][1], 0, 0, 1, 1, 1);
462 cmesh_eydata.FillBoundary(gm.periodicity());
465 mesh_data[lev][2]->nComp(),
466 mesh_data[lev][2]->nGrow());
467 cmesh_ezdata.setVal(0.0, 0, 1, mesh_data[lev][2]->nGrow());
468 cmesh_ezdata.copy(*mesh_data[lev-1][2], 0, 0, 1, 1, 1);
469 cmesh_ezdata.FillBoundary(gm.periodicity());
471 for (
size_t ip = lBegin; ip < lEnd; ++ip) {
473 const int grid = this->Grid[ip];
483 const typename PLayout::basefab_t& mfab = (*layout_p->getLevelMask(lev))[grid];
487 for (
int ii = 0; ii < 3; ++ii) {
488 lxyz[ii] = ( this->
R[ip](ii) - plo[ii] ) * inv_fdx[ii] + 0.5;
490 wxyz_hi[ii] = lxyz[ii] - ijk[ii];
491 wxyz_lo[ii] = 1.0 - wxyz_hi[ii];
498 bool use_coarse =
false;
505 for (
int ii = 0; ii < 3; ++ii) {
506 lxyz[ii] = ( this->
R[ip](ii) - cplo[ii] ) * inv_cdx[ii] + 0.5;
508 wxyz_hi[ii] = lxyz[ii] - ijk[ii];
509 wxyz_lo[ii] = 1.0 - wxyz_hi[ii];
524 pa[ip](0) = wxyz_lo[0] * wxyz_lo[1] * wxyz_lo[2] * cexfab(i1) +
525 wxyz_lo[0] * wxyz_hi[1] * wxyz_lo[2] * cexfab(i3) +
526 wxyz_hi[0] * wxyz_lo[1] * wxyz_lo[2] * cexfab(i5) +
527 wxyz_hi[0] * wxyz_hi[1] * wxyz_lo[2] * cexfab(i7) +
528 wxyz_lo[0] * wxyz_lo[1] * wxyz_hi[2] * cexfab(i2) +
529 wxyz_lo[0] * wxyz_hi[1] * wxyz_hi[2] * cexfab(i4) +
530 wxyz_hi[0] * wxyz_lo[1] * wxyz_hi[2] * cexfab(i6) +
531 wxyz_hi[0] * wxyz_hi[1] * wxyz_hi[2] * cexfab(i8);
533 pa[ip](1) = wxyz_lo[0] * wxyz_lo[1] * wxyz_lo[2] * ceyfab(i1) +
534 wxyz_lo[0] * wxyz_hi[1] * wxyz_lo[2] * ceyfab(i3) +
535 wxyz_hi[0] * wxyz_lo[1] * wxyz_lo[2] * ceyfab(i5) +
536 wxyz_hi[0] * wxyz_hi[1] * wxyz_lo[2] * ceyfab(i7) +
537 wxyz_lo[0] * wxyz_lo[1] * wxyz_hi[2] * ceyfab(i2) +
538 wxyz_lo[0] * wxyz_hi[1] * wxyz_hi[2] * ceyfab(i4) +
539 wxyz_hi[0] * wxyz_lo[1] * wxyz_hi[2] * ceyfab(i6) +
540 wxyz_hi[0] * wxyz_hi[1] * wxyz_hi[2] * ceyfab(i8);
542 pa[ip](2) = wxyz_lo[0] * wxyz_lo[1] * wxyz_lo[2] * cezfab(i1) +
543 wxyz_lo[0] * wxyz_hi[1] * wxyz_lo[2] * cezfab(i3) +
544 wxyz_hi[0] * wxyz_lo[1] * wxyz_lo[2] * cezfab(i5) +
545 wxyz_hi[0] * wxyz_hi[1] * wxyz_lo[2] * cezfab(i7) +
546 wxyz_lo[0] * wxyz_lo[1] * wxyz_hi[2] * cezfab(i2) +
547 wxyz_lo[0] * wxyz_hi[1] * wxyz_hi[2] * cezfab(i4) +
548 wxyz_hi[0] * wxyz_lo[1] * wxyz_hi[2] * cezfab(i6) +
549 wxyz_hi[0] * wxyz_hi[1] * wxyz_hi[2] * cezfab(i8);
551 pa[ip](0) = wxyz_lo[0] * wxyz_lo[1] * wxyz_lo[2] * exfab(i1) +
552 wxyz_lo[0] * wxyz_hi[1] * wxyz_lo[2] * exfab(i3) +
553 wxyz_hi[0] * wxyz_lo[1] * wxyz_lo[2] * exfab(i5) +
554 wxyz_hi[0] * wxyz_hi[1] * wxyz_lo[2] * exfab(i7) +
555 wxyz_lo[0] * wxyz_lo[1] * wxyz_hi[2] * exfab(i2) +
556 wxyz_lo[0] * wxyz_hi[1] * wxyz_hi[2] * exfab(i4) +
557 wxyz_hi[0] * wxyz_lo[1] * wxyz_hi[2] * exfab(i6) +
558 wxyz_hi[0] * wxyz_hi[1] * wxyz_hi[2] * exfab(i8);
560 pa[ip](1) = wxyz_lo[0] * wxyz_lo[1] * wxyz_lo[2] * eyfab(i1) +
561 wxyz_lo[0] * wxyz_hi[1] * wxyz_lo[2] * eyfab(i3) +
562 wxyz_hi[0] * wxyz_lo[1] * wxyz_lo[2] * eyfab(i5) +
563 wxyz_hi[0] * wxyz_hi[1] * wxyz_lo[2] * eyfab(i7) +
564 wxyz_lo[0] * wxyz_lo[1] * wxyz_hi[2] * eyfab(i2) +
565 wxyz_lo[0] * wxyz_hi[1] * wxyz_hi[2] * eyfab(i4) +
566 wxyz_hi[0] * wxyz_lo[1] * wxyz_hi[2] * eyfab(i6) +
567 wxyz_hi[0] * wxyz_hi[1] * wxyz_hi[2] * eyfab(i8);
569 pa[ip](2) = wxyz_lo[0] * wxyz_lo[1] * wxyz_lo[2] * ezfab(i1) +
570 wxyz_lo[0] * wxyz_hi[1] * wxyz_lo[2] * ezfab(i3) +
571 wxyz_hi[0] * wxyz_lo[1] * wxyz_lo[2] * ezfab(i5) +
572 wxyz_hi[0] * wxyz_hi[1] * wxyz_lo[2] * ezfab(i7) +
573 wxyz_lo[0] * wxyz_lo[1] * wxyz_hi[2] * ezfab(i2) +
574 wxyz_lo[0] * wxyz_hi[1] * wxyz_hi[2] * ezfab(i4) +
575 wxyz_hi[0] * wxyz_lo[1] * wxyz_hi[2] * ezfab(i6) +
576 wxyz_hi[0] * wxyz_hi[1] * wxyz_hi[2] * ezfab(i8);
amr::AmrField_t AmrField_t
bool scatter(Communicate &, InputIterator, InputIterator, RandomIterator, int *, int *, const ScatterOp &)
amrex::IntVect AmrIntVect_t
PLayout::AmrIntVect_t AmrIntVect_t
AmrParticleBase< PLayout >::AmrField_t AmrField_t
PLayout::AmrProcMap_t AmrProcMap_t
void AssignCellDensitySingleLevelFort(ParticleAttrib< AType > &pa, AmrField_t &mf, int level, const ParticleAttrib< int > &pbin, int bin=-1, int ncomp=1, int particle_lvl_offset=0) const
PLayout::AmrGeometry_t AmrGeometry_t
IpplTimings::TimerRef AssignDensityTimer_m
void InterpolateMultiLevelFort(ParticleAttrib< AType > &pa, AmrVectorFieldContainer_t &mesh_data, int lev)
void AssignDensityFort(ParticleAttrib< AType > &pa, AmrScalarFieldContainer_t &mf_to_be_filled, int lev_min, int ncomp, int finest_level, const ParticleAttrib< int > &pbin, int bin=-1) const
AmrParticleBase< PLayout >::AmrVectorField_t AmrVectorField_t
void gather(ParticleAttrib< FT > &attrib, AmrVectorFieldContainer_t &f, ParticleAttrib< Vektor< PT, Dim > > &pp, int lbase, int lfine)
PLayout::AmrGrid_t AmrGrid_t
AmrParticleBase< PLayout >::AmrVectorFieldContainer_t AmrVectorFieldContainer_t
void InterpolateFort(ParticleAttrib< AType > &pa, AmrVectorFieldContainer_t &mesh_data, int lev_min, int lev_max)
amrex::FArrayBox FArrayBox_t
PLayout::AmrReal_t AmrReal_t
void scatter(ParticleAttrib< FT > &attrib, AmrScalarFieldContainer_t &f, ParticleAttrib< Vektor< PT, Dim > > &pp, int lbase, int lfine, const ParticleAttrib< int > &pbin, int bin=-1)
AmrParticleBase< PLayout >::AmrScalarFieldContainer_t AmrScalarFieldContainer_t
void InterpolateSingleLevelFort(ParticleAttrib< AType > &pa, AmrVectorField_t &mesh_data, int lev)
The base class for all OPAL exceptions.
static TimerRef getTimer(const char *nm)
static void stopTimer(TimerRef t)
static void startTimer(TimerRef t)