Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MLCellLinOp.H
Go to the documentation of this file.
1#ifndef AMREX_ML_CELL_LINOP_H_
2#define AMREX_ML_CELL_LINOP_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_MLLinOp.H>
6#include <AMReX_iMultiFab.H>
9#include <AMReX_MLLinOp_K.H>
10#include <AMReX_MLMG_K.H>
11
12#ifndef BL_NO_FORT
13#include <AMReX_MLLinOp_F.H>
14#endif
15
16namespace amrex {
17
24
25template <typename T>
27
28template <typename MF>
29class MLCellLinOpT // NOLINT(cppcoreguidelines-virtual-class-destructor)
30 : public MLLinOpT<MF>
31{
32public:
33
36
38 using BCMode = typename MLLinOpT<MF>::BCMode;
41
43 ~MLCellLinOpT () override = default;
44
45 MLCellLinOpT (const MLCellLinOpT<MF>&) = delete;
49
59 void define (const Vector<Geometry>& a_geom,
60 const Vector<BoxArray>& a_grids,
61 const Vector<DistributionMapping>& a_dmap,
62 const LPInfo& a_info = LPInfo(),
63 const Vector<FabFactory<FAB> const*>& a_factory = {});
64
78 void setLevelBC (int amrlev, const MF* levelbcdata,
79 const MF* robinbc_a = nullptr,
80 const MF* robinbc_b = nullptr,
81 const MF* robinbc_f = nullptr) final;
82
83 template <MultiFabLike AMF>
84 requires (!std::same_as<MF,AMF>)
85 void setLevelBC (int amrlev, const AMF* levelbcdata,
86 const AMF* robinbc_a = nullptr,
87 const AMF* robinbc_b = nullptr,
88 const AMF* robinbc_f = nullptr)
89 {
90 this->MLLinOpT<MF>::template setLevelBC<AMF>(amrlev, levelbcdata, robinbc_a, robinbc_b, robinbc_f);
91 }
92
93 bool needsUpdate () const override {
95 }
96 void update () override;
97
104 void setGaussSeidel (bool flag) noexcept {
105 m_use_gauss_seidel = flag;
107 if (this->m_sp_linop) {
108 static_cast<MLCellLinOpT<fMultiFab>*>(this->m_sp_linop.get())->setGaussSeidel(flag);
109 }
110 }
111 }
112
114 virtual bool isCrossStencil () const { return true; }
116 virtual bool isTensorOp () const { return false; }
117
124 void updateSolBC (int amrlev, const MF& crse_bcdata) const;
131 void updateCorBC (int amrlev, const MF& crse_bcdata) const;
132
144 virtual void applyBC (int amrlev, int mglev, MF& in, BCMode bc_mode, StateMode s_mode,
145 const MLMGBndryT<MF>* bndry=nullptr, bool skip_fillboundary=false) const;
146
148 BoxArray makeNGrids (int grid_size) const;
149
158 void restriction (int amrlev, int cmglev, MF& crse, MF& fine) const override;
159
169 void interpolation (int amrlev, int fmglev, MF& fine, const MF& crse) const override;
170
180 void interpAssign (int amrlev, int fmglev, MF& fine, MF& crse) const override;
181
191 void interpolationAmr (int famrlev, MF& fine, const MF& crse,
192 IntVect const& nghost) const override;
193
203 void averageDownSolutionRHS (int camrlev, MF& crse_sol, MF& crse_rhs,
204 const MF& fine_sol, const MF& fine_rhs) override;
205
217 void apply (int amrlev, int mglev, MF& out, MF& in, BCMode bc_mode,
218 StateMode s_mode, const MLMGBndryT<MF>* bndry=nullptr) const override;
229 void smooth (int amrlev, int mglev, MF& sol, const MF& rhs,
230 bool skip_fillboundary, int niter) const override;
231
241 void solutionResidual (int amrlev, MF& resid, MF& x, const MF& b,
242 const MF* crse_bcdata=nullptr) override;
243
250 void prepareForFluxes (int amrlev, const MF* crse_bcdata = nullptr) override;
251
263 void correctionResidual (int amrlev, int mglev, MF& resid, MF& x, const MF& b,
264 BCMode bc_mode, const MF* crse_bcdata=nullptr) final;
265
279 void reflux (int crse_amrlev,
280 MF& res, const MF& crse_sol, const MF&,
281 MF&, MF& fine_sol, const MF&) const final;
290 void compFlux (int amrlev, const Array<MF*,AMREX_SPACEDIM>& fluxes,
291 MF& sol, Location loc) const override;
300 void compGrad (int amrlev, const Array<MF*,AMREX_SPACEDIM>& grad,
301 MF& sol, Location loc) const override;
302
310 void applyMetricTerm (int amrlev, int mglev, MF& rhs) const final;
318 void unapplyMetricTerm (int amrlev, int mglev, MF& rhs) const final;
327 Vector<RT> getSolvabilityOffset (int amrlev, int mglev,
328 MF const& rhs) const override;
337 void fixSolvabilityByOffset (int amrlev, int mglev, MF& rhs,
338 Vector<RT> const& offset) const override;
339
341 void prepareForSolve () override;
342
353 RT xdoty (int amrlev, int mglev, const MF& x, const MF& y, bool local) const final;
354
363 RT dotProductPrecond (Vector<MF const*> const& x, Vector<MF const*> const& y) const final;
364
372 RT norm2Precond (Vector<MF const*> const& x) const final;
373
374 virtual void Fapply (int amrlev, int mglev, MF& out, const MF& in) const = 0;
375 virtual void Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, int redblack) const = 0;
376 virtual void FFlux (int amrlev, const MFIter& mfi,
377 const Array<FAB*,AMREX_SPACEDIM>& flux,
378 const FAB& sol, Location loc, int face_only=0) const = 0;
379
388 virtual void addInhomogNeumannFlux (int /*amrlev*/,
389 const Array<MF*,AMREX_SPACEDIM>& /*grad*/,
390 MF const& /*sol*/,
391 bool /*mult_bcoef*/) const {}
392
400 RT normInf (int amrlev, MF const& mf, bool local) const override;
401
407 void averageDownAndSync (Vector<MF>& sol) const override;
408
416 void avgDownResAmr (int clev, MF& cres, MF const& fres) const override;
417
419 void beginPrecondBC () override;
421 void endPrecondBC () override;
422
424 struct BCTL {
425 BoundCond type;
426 RT location;
427 };
429
431
438 m_interpbndry_halfwidth = w;
440 if (this->m_sp_linop) {
441 static_cast<MLCellLinOpT<fMultiFab>*>(this->m_sp_linop.get())->setInterpBndryHalfWidth(w);
442 }
443 }
444 }
445
446protected:
447 void spCopySettings () override
448 {
451 setInterpBndryHalfWidth(m_interpbndry_halfwidth);
452 }
453
454 bool m_has_metric_term = false;
455
458
461
463
464 // In case of agglomeration, coarse MG grids on amr level 0 are
465 // not simply coarsened from fine MG grids. So we need to build
466 // bcond and bcloc for each MG level.
470 class BndryCondLoc
471 {
472 public:
473 BndryCondLoc (const BoxArray& ba, const DistributionMapping& dm, int ncomp);
474
475 void setLOBndryConds (const Geometry& geom, const Real* dx,
478 IntVect const& ratio, const RealVect& interior_bloc,
479 const Array<Real,AMREX_SPACEDIM>& domain_bloc_lo,
480 const Array<Real,AMREX_SPACEDIM>& domain_bloc_hi,
481 LinOpBCType crse_fine_bc_type);
482
483 const Vector<BCTuple>& bndryConds (const MFIter& mfi) const noexcept {
484 return bcond[mfi];
485 }
486 const Vector<RealTuple>& bndryLocs (const MFIter& mfi) const noexcept {
487 return bcloc[mfi];
488 }
489 const BCTuple& bndryConds (const MFIter& mfi, int icomp) const noexcept {
490 return bcond[mfi][icomp];
491 }
492 const RealTuple& bndryLocs (const MFIter& mfi, int icomp) const noexcept {
493 return bcloc[mfi][icomp];
494 }
495 GpuArray<BCTL,2*AMREX_SPACEDIM> const* getBCTLPtr (const MFIter& mfi) const noexcept {
496 return bctl[mfi];
497 }
498 private:
503 int m_ncomp;
504 };
507
508 // used to save interpolation coefficients of the first interior cells
510
511 // boundary cell flags for covered, not_covered, outside_domain
513
515
517
518 bool m_use_gauss_seidel = true; // use red-black Gauss-Seidel by default
519
520private:
521
522 void defineAuxData ();
523 void defineBC ();
524
525 void computeVolInv () const;
526 mutable Vector<Vector<RT> > m_volinv; // used by solvability fix
527
528 int m_interpbndry_halfwidth = 2;
529
530 mutable Vector<Vector<TagVector<MLMGABCTag<RT>>>> m_bc_tags;
531};
532
534
535template <typename T>
536struct MLMGABCTag {
538 T bcloc;
539 Box bx;
540 BoundCond bctype;
541 int blen;
542 int comp;
543 Orientation face;
544 int local_index;
545
547 Box const& box() const noexcept { return bx; }
548};
549
550template <typename T>
551struct MLMGPSTag {
552 Array4<T> flo;
553 Array4<T> fhi;
554 Array4<int const> mlo;
555 Array4<int const> mhi;
556 T bcllo;
557 T bclhi;
558 Box bx;
559 BoundCond bctlo;
560 BoundCond bcthi;
561 int blen;
562 int comp;
563 int dir;
564
566 Box const& box() const noexcept { return bx; }
567};
568
569#ifdef AMREX_USE_EB
570template <typename T>
571struct MLMGPSEBTag {
572 Array4<T> flo;
573 Array4<T> fhi;
574 Array4<T const> ap;
575 Array4<int const> mlo;
576 Array4<int const> mhi;
577 T bcllo;
578 T bclhi;
579 Box bx;
580 BoundCond bctlo;
581 BoundCond bcthi;
582 int blen;
583 int comp;
584 int dir;
585
587 Box const& box() const noexcept { return bx; }
588};
589#endif
590
591template <typename MF>
593 const DistributionMapping& dm,
594 int ncomp)
595 : bcond(ba, dm),
596 bcloc(ba, dm),
597 bctl(ba, dm),
598 bctl_dv(bctl.local_size()*ncomp),
599 m_ncomp(ncomp)
600{
601 auto* dp = bctl_dv.data();
602 for (MFIter mfi(bcloc); mfi.isValid(); ++mfi) {
603 bcond[mfi].resize(ncomp);
604 bcloc[mfi].resize(ncomp);
605 bctl[mfi] = dp;
606 dp += ncomp;
607 }
608}
609
610template <typename MF>
611void
613setLOBndryConds (const Geometry& geom, const Real* dx,
616 IntVect const& ratio, const RealVect& interior_bloc,
617 const Array<Real,AMREX_SPACEDIM>& domain_bloc_lo,
618 const Array<Real,AMREX_SPACEDIM>& domain_bloc_hi,
619 LinOpBCType crse_fine_bc_type)
620{
621 const Box& domain = geom.Domain();
622
623#ifdef AMREX_USE_OMP
624#pragma omp parallel
625#endif
626 for (MFIter mfi(bcloc); mfi.isValid(); ++mfi)
627 {
628 const Box& bx = mfi.validbox();
629 for (int icomp = 0; icomp < m_ncomp; ++icomp) {
630 RealTuple & bloc = bcloc[mfi][icomp];
631 BCTuple & bctag = bcond[mfi][icomp];
632 MLMGBndryT<MF>::setBoxBC(bloc, bctag, bx, domain,
633 lobc[icomp], hibc[icomp],
634 dx, ratio, interior_bloc,
635 domain_bloc_lo, domain_bloc_hi,
636 geom.isPeriodicArray(),
637 crse_fine_bc_type);
638 }
639 }
640
642 hv.reserve(bctl_dv.size());
643 for (MFIter mfi(bctl); mfi.isValid(); ++mfi)
644 {
645 for (int icomp = 0; icomp < m_ncomp; ++icomp) {
647 for (int m = 0; m < 2*AMREX_SPACEDIM; ++m) {
648 tmp[m].type = bcond[mfi][icomp][m];
649 tmp[m].location = bcloc[mfi][icomp][m];
650 }
651 hv.push_back(std::move(tmp));
652 }
653 }
654 Gpu::copyAsync(Gpu::hostToDevice, hv.begin(), hv.end(), bctl_dv.begin());
656}
657
659
660template <typename MF>
665
666template <typename MF>
667void
669 const Vector<BoxArray>& a_grids,
670 const Vector<DistributionMapping>& a_dmap,
671 const LPInfo& a_info,
672 const Vector<FabFactory<FAB> const*>& a_factory)
673{
674 // defineAuxData needs all MG levels, which a deferred hierarchy lacks.
676 "MLCellLinOp: anisotropic coarsening is not supported");
677 MLLinOpT<MF>::define(a_geom, a_grids, a_dmap, a_info, a_factory);
678 defineAuxData();
679 defineBC();
680}
681
682template <typename MF>
683void
684MLCellLinOpT<MF>::defineAuxData ()
685{
686 BL_PROFILE("MLCellLinOp::defineAuxData()");
687
688 m_undrrelxr.resize(this->m_num_amr_levels);
689 m_maskvals.resize(this->m_num_amr_levels);
690 m_fluxreg.resize(this->m_num_amr_levels-1);
691 m_norm_fine_mask.resize(this->m_num_amr_levels-1);
692 m_bc_tags.resize(this->m_num_amr_levels);
693
694 const int ncomp = this->getNComp();
695
696 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
697 {
698 m_undrrelxr[amrlev].resize(this->m_num_mg_levels[amrlev]);
699 m_bc_tags[amrlev].resize(this->m_num_mg_levels[amrlev]);
700 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
701 {
702 m_undrrelxr[amrlev][mglev].define(this->m_grids[amrlev][mglev],
703 this->m_dmap[amrlev][mglev],
704 1, 0, 0, ncomp);
705 }
706 }
707
708 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
709 {
710 m_maskvals[amrlev].resize(this->m_num_mg_levels[amrlev]);
711 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
712 {
713 for (OrientationIter oitr; oitr; ++oitr)
714 {
715 const Orientation face = oitr();
716 const int ngrow = 1;
717 const int extent = this->isCrossStencil() ? 0 : 1; // extend to corners
718 m_maskvals[amrlev][mglev][face].define(this->m_grids[amrlev][mglev],
719 this->m_dmap[amrlev][mglev],
720 this->m_geom[amrlev][mglev],
721 face, 0, ngrow, extent, 1, true);
722 }
723 }
724 }
725
726 for (int amrlev = 0; amrlev < this->m_num_amr_levels-1; ++amrlev)
727 {
728 const IntVect ratio{this->AMRRefRatioVect(amrlev)};
729 m_fluxreg[amrlev].define(this->m_grids[amrlev+1][0],
730 this->m_grids[amrlev][0],
731 this->m_dmap[amrlev+1][0],
732 this->m_dmap[amrlev][0],
733 this->m_geom[amrlev+1][0],
734 this->m_geom[amrlev][0],
735 ratio, amrlev+1, ncomp);
736 m_fluxreg[amrlev].setDeterministic(this->info.deterministic);
737 m_norm_fine_mask[amrlev] = std::make_unique<iMultiFab>
738 (makeFineMask(this->m_grids[amrlev][0], this->m_dmap[amrlev][0],
739 this->m_grids[amrlev+1][0],
740 ratio, 1, 0));
741 }
742
743#if (AMREX_SPACEDIM != 3)
744 m_has_metric_term = !this->m_geom[0][0].IsCartesian() && this->info.has_metric_term;
745#endif
746}
747
748template <typename MF>
749void
750MLCellLinOpT<MF>::defineBC ()
751{
752 BL_PROFILE("MLCellLinOp::defineBC()");
753
754 const int ncomp = this->getNComp();
755
756 m_bndry_sol.resize(this->m_num_amr_levels);
757 m_crse_sol_br.resize(this->m_num_amr_levels);
758
759 m_bndry_cor.resize(this->m_num_amr_levels);
760 m_crse_cor_br.resize(this->m_num_amr_levels);
761
762 m_robin_bcval.resize(this->m_num_amr_levels);
763
764 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
765 {
766 m_bndry_sol[amrlev] = std::make_unique<MLMGBndryT<MF>>(this->m_grids[amrlev][0],
767 this->m_dmap[amrlev][0],
768 ncomp,
769 this->m_geom[amrlev][0]);
770 }
771
772 for (int amrlev = 1; amrlev < this->m_num_amr_levels; ++amrlev)
773 {
774 const int in_rad = 0;
775 const int out_rad = 1;
776 const int extent_rad = 2;
777 const IntVect crse_ratio = this->AMRRefRatioVect(amrlev-1);
778 BoxArray cba = this->m_grids[amrlev][0];
779 cba.coarsen(crse_ratio);
780 m_crse_sol_br[amrlev] = std::make_unique<BndryRegisterT<MF>>
781 (cba, this->m_dmap[amrlev][0], in_rad, out_rad, extent_rad, ncomp);
782 }
783
784 for (int amrlev = 1; amrlev < this->m_num_amr_levels; ++amrlev)
785 {
786 const int in_rad = 0;
787 const int out_rad = 1;
788 const int extent_rad = 2;
789 const IntVect crse_ratio = this->AMRRefRatioVect(amrlev-1);
790 BoxArray cba = this->m_grids[amrlev][0];
791 cba.coarsen(crse_ratio);
792 m_crse_cor_br[amrlev] = std::make_unique<BndryRegisterT<MF>>
793 (cba, this->m_dmap[amrlev][0], in_rad, out_rad, extent_rad, ncomp);
794 m_crse_cor_br[amrlev]->setVal(RT(0.0));
795 }
796
797 // This has be to done after m_crse_cor_br is defined.
798 for (int amrlev = 1; amrlev < this->m_num_amr_levels; ++amrlev)
799 {
800 m_bndry_cor[amrlev] = std::make_unique<MLMGBndryT<MF>>
801 (this->m_grids[amrlev][0], this->m_dmap[amrlev][0], ncomp, this->m_geom[amrlev][0]);
802 MF bc_data(this->m_grids[amrlev][0], this->m_dmap[amrlev][0], ncomp, 1);
803 bc_data.setVal(0.0);
804
805 m_bndry_cor[amrlev]->setBndryValues(*m_crse_cor_br[amrlev], 0, bc_data, 0, 0, ncomp,
806 this->AMRRefRatioVect(amrlev-1),
808 m_interpbndry_halfwidth);
809
811 (ncomp,Array<LinOpBCType,AMREX_SPACEDIM>{{AMREX_D_DECL(BCType::Dirichlet,
812 BCType::Dirichlet,
813 BCType::Dirichlet)}});
814 m_bndry_cor[amrlev]->setLOBndryConds(bclohi, bclohi, this->AMRRefRatioVect(amrlev-1), RealVect{});
815 }
816
817 m_bcondloc.resize(this->m_num_amr_levels);
818 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
819 {
820 m_bcondloc[amrlev].resize(this->m_num_mg_levels[amrlev]);
821 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
822 {
823 m_bcondloc[amrlev][mglev] = std::make_unique<BndryCondLoc>(this->m_grids[amrlev][mglev],
824 this->m_dmap[amrlev][mglev],
825 ncomp);
826 }
827 }
828}
829
830template <typename MF>
831void
832MLCellLinOpT<MF>::setLevelBC (int amrlev, const MF* a_levelbcdata, const MF* robinbc_a,
833 const MF* robinbc_b, const MF* robinbc_f)
834{
835 BL_PROFILE("MLCellLinOp::setLevelBC()");
836
837 AMREX_ALWAYS_ASSERT(amrlev >= 0 && amrlev < this->m_num_amr_levels);
838
839 const int ncomp = this->getNComp();
840
841 // The single precision copy solves the correction equation: homogeneous
842 // BC, Robin a and b with f = 0.
843 if (this->m_sp_linop && !this->m_precond_mode) {
844 if (this->hasRobinBC()) {
845 AMREX_ASSERT(robinbc_a != nullptr && robinbc_b != nullptr);
846 fMultiFab ra(robinbc_a->boxArray(), robinbc_a->DistributionMap(),
847 robinbc_a->nComp(), robinbc_a->nGrowVect());
848 fMultiFab rb(robinbc_b->boxArray(), robinbc_b->DistributionMap(),
849 robinbc_b->nComp(), robinbc_b->nGrowVect());
850 fMultiFab rf(robinbc_b->boxArray(), robinbc_b->DistributionMap(),
851 robinbc_b->nComp(), robinbc_b->nGrowVect());
852 ra.LocalCopy(*robinbc_a, 0, 0, ra.nComp(), ra.nGrowVect());
853 rb.LocalCopy(*robinbc_b, 0, 0, rb.nComp(), rb.nGrowVect());
854 if (this->m_sp_length_scale != Real(1.0)) { // b multiplies a derivative
855 auto const lambda = static_cast<float>(this->m_sp_length_scale);
856 for (MFIter mfi(rb); mfi.isValid(); ++mfi) { // the data are in the ghost cells
857 rb[mfi].template mult<RunOn::Device>(lambda, rb[mfi].box(), 0, rb.nComp());
858 }
859 }
860 rf.setVal(0.0F);
861 this->m_sp_linop->setLevelBC(amrlev, nullptr, &ra, &rb, &rf);
862 } else {
863 this->m_sp_linop->setLevelBC(amrlev, nullptr);
864 }
865 }
866
867 MF zero;
868 IntVect ng(1);
869 if (this->hasHiddenDimension()) { ng[this->hiddenDirection()] = 0; }
870 if (a_levelbcdata == nullptr) {
871 zero.define(this->m_grids[amrlev][0], this->m_dmap[amrlev][0], ncomp, ng);
872 zero.setVal(RT(0.0));
873 } else {
874 AMREX_ALWAYS_ASSERT(a_levelbcdata->nGrowVect().allGE(ng));
875 }
876 const MF& bcdata = (a_levelbcdata == nullptr) ? zero : *a_levelbcdata;
877
878 IntVect br_ref_ratio(-1);
879
880 if (amrlev == 0)
881 {
882 if (this->needsCoarseDataForBC())
883 {
884 // AMREX_ALWAYS_ASSERT(!this->hasHiddenDimension());
885 if (this->hasHiddenDimension()) {
886 int hidden_dir = this->hiddenDirection();
887 AMREX_ALWAYS_ASSERT(this->m_coarse_data_crse_ratio[hidden_dir] == 1);
888 }
889 br_ref_ratio = this->m_coarse_data_crse_ratio.allGT(0) ? this->m_coarse_data_crse_ratio : IntVect(2);
890 if (this->m_crse_sol_br[amrlev] == nullptr && br_ref_ratio.allGT(0))
891 {
892 const int in_rad = 0;
893 const int out_rad = 1;
894 const int extent_rad = 2;
895 const IntVect crse_ratio = br_ref_ratio;
896 BoxArray cba = this->m_grids[amrlev][0];
897 cba.coarsen(crse_ratio);
898 this->m_crse_sol_br[amrlev] = std::make_unique<BndryRegisterT<MF>>
899 (cba, this->m_dmap[amrlev][0], in_rad, out_rad, extent_rad, ncomp);
900 }
901 if (this->m_coarse_data_for_bc != nullptr) {
903 const Box& cbx = amrex::coarsen(this->m_geom[0][0].Domain(), this->m_coarse_data_crse_ratio);
904 this->m_crse_sol_br[amrlev]->copyFrom(*(this->m_coarse_data_for_bc), 0, 0, 0, ncomp,
905 this->m_geom[0][0].periodicity(cbx));
906 } else {
907 this->m_crse_sol_br[amrlev]->setVal(RT(0.0));
908 }
909 this->m_bndry_sol[amrlev]->setBndryValues(*(this->m_crse_sol_br[amrlev]), 0,
910 bcdata, 0, 0, ncomp, br_ref_ratio,
912 this->m_interpbndry_halfwidth);
913 br_ref_ratio = this->m_coarse_data_crse_ratio;
914 }
915 else
916 {
917 this->m_bndry_sol[amrlev]->setPhysBndryValues(bcdata,0,0,ncomp);
918 br_ref_ratio = IntVect(1);
919 }
920 }
921 else
922 {
923 this->m_bndry_sol[amrlev]->setPhysBndryValues(bcdata,0,0,ncomp);
924 br_ref_ratio = this->AMRRefRatioVect(amrlev-1);
925 }
926
927 auto crse_fine_bc_type = (amrlev == 0) ? this->m_coarse_fine_bc_type : LinOpBCType::Dirichlet;
928 this->m_bndry_sol[amrlev]->setLOBndryConds(this->m_lobc, this->m_hibc, br_ref_ratio,
929 this->m_coarse_bc_loc, crse_fine_bc_type);
930
931 const Real* dx = this->m_geom[amrlev][0].CellSize();
932 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
933 {
934 this->m_bcondloc[amrlev][mglev]->setLOBndryConds(this->m_geom[amrlev][mglev], dx,
935 this->m_lobc, this->m_hibc,
936 br_ref_ratio, this->m_coarse_bc_loc,
938 crse_fine_bc_type);
939 m_bc_tags[amrlev][mglev].undefine();
940 }
941
942 // In precond mode beginPrecondBC calls this with null Robin data; keep
943 // the user's a, b and f rather than dereferencing the null pointers.
944 if (this->hasRobinBC() && !this->m_precond_mode) {
945 AMREX_ASSERT(robinbc_a != nullptr && robinbc_b != nullptr && robinbc_f != nullptr);
946 this->m_robin_bcval[amrlev] = std::make_unique<MF>(this->m_grids[amrlev][0],
947 this->m_dmap[amrlev][0],
948 ncomp*3, 1);
949 const Box& domain = this->m_geom[amrlev][0].Domain();
950 MFItInfo mfi_info;
951 if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }
952#ifdef AMREX_USE_OMP
953#pragma omp parallel if (Gpu::notInLaunchRegion())
954#endif
955 for (MFIter mfi(*(this->m_robin_bcval[amrlev]), mfi_info); mfi.isValid(); ++mfi) {
956 Box const& vbx = mfi.validbox();
957 Array4<RT const> const& ra = robinbc_a->const_array(mfi);
958 Array4<RT const> const& rb = robinbc_b->const_array(mfi);
959 Array4<RT const> const& rf = robinbc_f->const_array(mfi);
960 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
961 const Box& blo = amrex::adjCellLo(vbx, idim);
962 const Box& bhi = amrex::adjCellHi(vbx, idim);
963 bool outside_domain_lo = !(domain.contains(blo));
964 bool outside_domain_hi = !(domain.contains(bhi));
965 if ((!outside_domain_lo) && (!outside_domain_hi)) { continue; }
966 for (int icomp = 0; icomp < ncomp; ++icomp) {
967 Array4<RT> const& rbc = (*(this->m_robin_bcval[amrlev]))[mfi].array(icomp*3);
968 if (this->m_lobc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_lo)
969 {
971 {
972 rbc(i,j,k,0) = ra(i,j,k,icomp);
973 rbc(i,j,k,1) = rb(i,j,k,icomp);
974 rbc(i,j,k,2) = rf(i,j,k,icomp);
975 });
976 }
977 if (this->m_hibc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_hi)
978 {
980 {
981 rbc(i,j,k,0) = ra(i,j,k,icomp);
982 rbc(i,j,k,1) = rb(i,j,k,icomp);
983 rbc(i,j,k,2) = rf(i,j,k,icomp);
984 });
985 }
986 }
987 }
988 }
989 }
990}
991
992template <typename MF>
993void
998
999template <typename MF>
1000void
1001MLCellLinOpT<MF>::updateSolBC (int amrlev, const MF& crse_bcdata) const
1002{
1003 BL_PROFILE("MLCellLinOp::updateSolBC()");
1004
1005 AMREX_ALWAYS_ASSERT(amrlev > 0);
1006 const int ncomp = this->getNComp();
1007 m_crse_sol_br[amrlev]->copyFrom(crse_bcdata, 0, 0, 0, ncomp,
1008 this->m_geom[amrlev-1][0].periodicity());
1009 m_bndry_sol[amrlev]->updateBndryValues(*m_crse_sol_br[amrlev], 0, 0, ncomp,
1010 this->AMRRefRatioVect(amrlev-1),
1012 m_interpbndry_halfwidth);
1013}
1014
1015template <typename MF>
1016void
1017MLCellLinOpT<MF>::updateCorBC (int amrlev, const MF& crse_bcdata) const
1018{
1019 BL_PROFILE("MLCellLinOp::updateCorBC()");
1020 AMREX_ALWAYS_ASSERT(amrlev > 0);
1021 const int ncomp = this->getNComp();
1022 m_crse_cor_br[amrlev]->copyFrom(crse_bcdata, 0, 0, 0, ncomp,
1023 this->m_geom[amrlev-1][0].periodicity());
1024 m_bndry_cor[amrlev]->updateBndryValues(*m_crse_cor_br[amrlev], 0, 0, ncomp,
1025 this->AMRRefRatioVect(amrlev-1),
1027 m_interpbndry_halfwidth);
1028}
1029
1030template <typename MF>
1031void
1032MLCellLinOpT<MF>::applyBC (int amrlev, int mglev, MF& in, BCMode bc_mode, StateMode,
1033 const MLMGBndryT<MF>* bndry, bool skip_fillboundary) const
1034{
1035 BL_PROFILE("MLCellLinOp::applyBC()");
1036 // No coarsened boundary values, cannot apply inhomog at mglev>0.
1037 BL_ASSERT(mglev == 0 || bc_mode == BCMode::Homogeneous);
1038 BL_ASSERT(bndry != nullptr || bc_mode == BCMode::Homogeneous);
1039
1040 const int ncomp = this->getNComp();
1041 const int cross = isCrossStencil();
1042 const int tensorop = isTensorOp();
1043 if (!skip_fillboundary) {
1044 in.FillBoundary(0, ncomp, this->m_geom[amrlev][mglev].periodicity(), cross);
1045 }
1046
1047 int flagbc = bc_mode == BCMode::Inhomogeneous;
1048 const int imaxorder = this->maxorder;
1049
1050 const Real* dxinv = this->m_geom[amrlev][mglev].InvCellSize();
1051 const RT dxi = static_cast<RT>(dxinv[0]);
1052 const RT dyi = (AMREX_SPACEDIM >= 2) ? static_cast<RT>(dxinv[1]) : RT(1.0);
1053 const RT dzi = (AMREX_SPACEDIM == 3) ? static_cast<RT>(dxinv[2]) : RT(1.0);
1054
1055 const auto& maskvals = m_maskvals[amrlev][mglev];
1056 const auto& bcondloc = *m_bcondloc[amrlev][mglev];
1057
1058 FAB foofab(Box::TheUnitBox(),ncomp);
1059 const auto& foo = foofab.const_array();
1060
1061 MFItInfo mfi_info;
1062 if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }
1063
1065 "non-cross stencil not support for gpu");
1066
1067 const int hidden_direction = this->hiddenDirection();
1068
1069#ifdef AMREX_USE_GPU
1070 if ((cross || tensorop) && Gpu::inLaunchRegion())
1071 {
1072 if (! m_bc_tags[amrlev][mglev].is_defined()) {
1074 tags.reserve(in.local_size()*2*AMREX_SPACEDIM*ncomp);
1075 for (MFIter mfi(in); mfi.isValid(); ++mfi) {
1076 const Box& vbx = mfi.validbox();
1077 const auto & bdlv = bcondloc.bndryLocs(mfi);
1078 const auto & bdcv = bcondloc.bndryConds(mfi);
1079
1080 const int local_index = mfi.LocalIndex();
1081
1082 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1083 if (idim != hidden_direction) {
1084 const Orientation olo(idim,Orientation::low);
1085 const Orientation ohi(idim,Orientation::high);
1086 for (int icomp = 0; icomp < ncomp; ++icomp) {
1087 tags.emplace_back(MLMGABCTag<RT>{
1088 maskvals[olo].const_array(mfi),
1089 bdlv[icomp][olo],
1090 amrex::adjCell(vbx,olo),
1091 bdcv[icomp][olo], vbx.length(idim),
1092 icomp, olo, local_index
1093 });
1094 tags.emplace_back(MLMGABCTag<RT>{
1095 maskvals[ohi].const_array(mfi),
1096 bdlv[icomp][ohi],
1097 amrex::adjCell(vbx,ohi),
1098 bdcv[icomp][ohi], vbx.length(idim),
1099 icomp, ohi, local_index
1100 });
1101 }
1102 }
1103 }
1104 }
1105 m_bc_tags[amrlev][mglev].define(tags);
1106 }
1107
1108 MultiArray4<RT const> foo_ma;
1109 Array<MultiArray4<RT const>, 2*AMREX_SPACEDIM> bndry_arrays;
1110 for (OrientationIter oit; oit; ++oit) {
1111 const Orientation ori = oit();
1112 bndry_arrays[ori] = (bndry != nullptr) ?
1113 bndry->bndryValues(ori).arrays() : foo_ma;
1114 }
1115
1116 auto inma = in.arrays();
1117 ParallelFor(m_bc_tags[amrlev][mglev],
1118 [=] AMREX_GPU_DEVICE (int i, int j, int k, MLMGABCTag<RT> const& tag) noexcept
1119 {
1120 const auto& bcval = bndry_arrays[tag.face][tag.local_index];
1121 const int side = tag.face.faceDir();
1122 if (tag.face.coordDir() == 0) {
1123 mllinop_apply_bc_x(side, i, j, k, tag.blen, inma[tag.local_index],
1124 tag.mask, tag.bctype, tag.bcloc, bcval,
1125 imaxorder, dxi, flagbc, tag.comp);
1126 }
1127#if (AMREX_SPACEDIM > 1)
1128 else
1129#if (AMREX_SPACEDIM > 2)
1130 if (tag.face.coordDir() == 1)
1131#endif
1132 {
1133 mllinop_apply_bc_y(side, i, j, k, tag.blen, inma[tag.local_index],
1134 tag.mask, tag.bctype, tag.bcloc, bcval,
1135 imaxorder, dyi, flagbc, tag.comp);
1136 }
1137#if (AMREX_SPACEDIM > 2)
1138 else {
1139 mllinop_apply_bc_z(side, i, j, k, tag.blen, inma[tag.local_index],
1140 tag.mask, tag.bctype, tag.bcloc, bcval,
1141 imaxorder, dzi, flagbc, tag.comp);
1142 }
1143#endif
1144#endif
1145 });
1146 } else
1147#endif
1148 if (cross || tensorop)
1149 {
1150#ifdef AMREX_USE_OMP
1151#pragma omp parallel if (Gpu::notInLaunchRegion())
1152#endif
1153 for (MFIter mfi(in, mfi_info); mfi.isValid(); ++mfi)
1154 {
1155 const Box& vbx = mfi.validbox();
1156 const auto& iofab = in.array(mfi);
1157
1158 const auto & bdlv = bcondloc.bndryLocs(mfi);
1159 const auto & bdcv = bcondloc.bndryConds(mfi);
1160
1161 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
1162 {
1163 if (hidden_direction == idim) { continue; }
1164 const Orientation olo(idim,Orientation::low);
1165 const Orientation ohi(idim,Orientation::high);
1166 const Box blo = amrex::adjCellLo(vbx, idim);
1167 const Box bhi = amrex::adjCellHi(vbx, idim);
1168 const int blen = vbx.length(idim);
1169 const auto& mlo = maskvals[olo].array(mfi);
1170 const auto& mhi = maskvals[ohi].array(mfi);
1171 const auto& bvlo = (bndry != nullptr) ? bndry->bndryValues(olo).const_array(mfi) : foo;
1172 const auto& bvhi = (bndry != nullptr) ? bndry->bndryValues(ohi).const_array(mfi) : foo;
1173 for (int icomp = 0; icomp < ncomp; ++icomp) {
1174 const BoundCond bctlo = bdcv[icomp][olo];
1175 const BoundCond bcthi = bdcv[icomp][ohi];
1176 const RT bcllo = bdlv[icomp][olo];
1177 const RT bclhi = bdlv[icomp][ohi];
1178 if (idim == 0) {
1179 mllinop_apply_bc_x(0, blo, blen, iofab, mlo,
1180 bctlo, bcllo, bvlo,
1181 imaxorder, dxi, flagbc, icomp);
1182 mllinop_apply_bc_x(1, bhi, blen, iofab, mhi,
1183 bcthi, bclhi, bvhi,
1184 imaxorder, dxi, flagbc, icomp);
1185 } else if (idim == 1) {
1186 mllinop_apply_bc_y(0, blo, blen, iofab, mlo,
1187 bctlo, bcllo, bvlo,
1188 imaxorder, dyi, flagbc, icomp);
1189 mllinop_apply_bc_y(1, bhi, blen, iofab, mhi,
1190 bcthi, bclhi, bvhi,
1191 imaxorder, dyi, flagbc, icomp);
1192 } else {
1193 mllinop_apply_bc_z(0, blo, blen, iofab, mlo,
1194 bctlo, bcllo, bvlo,
1195 imaxorder, dzi, flagbc, icomp);
1196 mllinop_apply_bc_z(1, bhi, blen, iofab, mhi,
1197 bcthi, bclhi, bvhi,
1198 imaxorder, dzi, flagbc, icomp);
1199 }
1200 }
1201 }
1202 }
1203 }
1204 else
1205 {
1206#ifdef BL_NO_FORT
1207 amrex::Abort("amrex_mllinop_apply_bc not available when BL_NO_FORT=TRUE");
1208#else
1209 if constexpr (std::is_same_v<Real,RT>) {
1210#ifdef AMREX_USE_OMP
1211#pragma omp parallel
1212#endif
1213 for (MFIter mfi(in, mfi_info); mfi.isValid(); ++mfi)
1214 {
1215 const Box& vbx = mfi.validbox();
1216
1217 const auto & bdlv = bcondloc.bndryLocs(mfi);
1218 const auto & bdcv = bcondloc.bndryConds(mfi);
1219
1220 const RealTuple & bdl = bdlv[0];
1221 const BCTuple & bdc = bdcv[0];
1222
1223 for (OrientationIter oitr; oitr; ++oitr)
1224 {
1225 const Orientation ori = oitr();
1226
1227 int cdr = ori;
1228 RT bcl = bdl[ori];
1229 int bct = bdc[ori];
1230
1231 const auto& fsfab = (bndry != nullptr) ? bndry->bndryValues(ori)[mfi] : foofab;
1232
1233 const Mask& m = maskvals[ori][mfi];
1234
1236 BL_TO_FORTRAN_ANYD(in[mfi]),
1238 cdr, bct, bcl,
1239 BL_TO_FORTRAN_ANYD(fsfab),
1240 imaxorder, dxinv, flagbc, ncomp, cross);
1241 }
1242 }
1243 } else {
1244 amrex::Abort("Not supported");
1245 }
1246#endif
1247 }
1248}
1249
1250template <typename MF>
1252MLCellLinOpT<MF>::makeNGrids (int grid_size) const
1253{
1254 const Box& dombx = this->m_geom[0].back().Domain();
1255
1256 const BoxArray& old_ba = this->m_grids[0].back();
1257 const int N = old_ba.size();
1258 Vector<Box> bv;
1259 bv.reserve(N);
1260 for (int i = 0; i < N; ++i)
1261 {
1262 Box b = old_ba[i];
1263 b.coarsen(grid_size);
1264 b.refine(grid_size);
1265 IntVect sz = b.size();
1266 const IntVect nblks {AMREX_D_DECL(sz[0]/grid_size, sz[1]/grid_size, sz[2]/grid_size)};
1267
1268 IntVect big = b.smallEnd() + grid_size - 1;
1269 b.setBig(big);
1270
1271#if (AMREX_SPACEDIM == 3)
1272 for (int kk = 0; kk < nblks[2]; ++kk) {
1273#endif
1274#if (AMREX_SPACEDIM >= 2)
1275 for (int jj = 0; jj < nblks[1]; ++jj) {
1276#endif
1277 for (int ii = 0; ii < nblks[0]; ++ii)
1278 {
1279 IntVect shft{AMREX_D_DECL(ii*grid_size,jj*grid_size,kk*grid_size)};
1280 Box bb = amrex::shift(b,shft);
1281 bb &= dombx;
1282 bv.push_back(bb);
1283 }
1284#if (AMREX_SPACEDIM >= 2)
1285 }
1286#endif
1287#if (AMREX_SPACEDIM == 3)
1288 }
1289#endif
1290 }
1291
1292 std::sort(bv.begin(), bv.end());
1293 bv.erase(std::unique(bv.begin(), bv.end()), bv.end());
1294
1295 BoxList bl(std::move(bv));
1296
1297 return BoxArray{std::move(bl)};
1298}
1299
1300template <typename MF>
1301void
1302MLCellLinOpT<MF>::restriction (int amrlev, int cmglev, MF& crse, MF& fine) const
1303{
1304 const int ncomp = this->getNComp();
1305 IntVect ratio = (amrlev > 0) ? IntVect(2) : this->mg_coarsen_ratio_vec[cmglev-1];
1306 // MG levels inside a fine AMR level are not coarsened in the hidden
1307 // direction either.
1308 if (this->hasHiddenDimension()) { ratio[this->hiddenDirection()] = 1; }
1309 amrex::average_down(fine, crse, 0, ncomp, ratio);
1310}
1311
1312template <typename MF>
1313void
1314MLCellLinOpT<MF>::interpolation (int amrlev, int fmglev, MF& fine, const MF& crse) const
1315{
1316 const int ncomp = this->getNComp();
1317
1318 Dim3 ratio3 = {.x = 2, .y = 2, .z = 2};
1319 IntVect ratio = (amrlev > 0) ? IntVect(2) : this->mg_coarsen_ratio_vec[fmglev];
1320 if (this->hasHiddenDimension()) { ratio[this->hiddenDirection()] = 1; }
1321 AMREX_D_TERM(ratio3.x = ratio[0];,
1322 ratio3.y = ratio[1];,
1323 ratio3.z = ratio[2];);
1324
1325#ifdef AMREX_USE_GPU
1326 if (Gpu::inLaunchRegion() && fine.isFusingCandidate()) {
1327 auto const& finema = fine.arrays();
1328 auto const& crsema = crse.const_arrays();
1329 ParallelFor(fine, IntVect(0), ncomp,
1330 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1331 {
1332 int ic = amrex::coarsen(i,ratio3.x);
1333 int jc = amrex::coarsen(j,ratio3.y);
1334 int kc = amrex::coarsen(k,ratio3.z);
1335 finema[box_no](i,j,k,n) += crsema[box_no](ic,jc,kc,n);
1336 });
1337 if (!Gpu::inNoSyncRegion()) {
1339 }
1340 } else
1341#endif
1342 {
1343#ifdef AMREX_USE_OMP
1344#pragma omp parallel if (Gpu::notInLaunchRegion())
1345#endif
1346 for (MFIter mfi(fine,TilingIfNotGPU()); mfi.isValid(); ++mfi)
1347 {
1348 const Box& bx = mfi.tilebox();
1349 Array4<RT const> const& cfab = crse.const_array(mfi);
1350 Array4<RT> const& ffab = fine.array(mfi);
1351 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( bx, ncomp, i, j, k, n,
1352 {
1353 int ic = amrex::coarsen(i,ratio3.x);
1354 int jc = amrex::coarsen(j,ratio3.y);
1355 int kc = amrex::coarsen(k,ratio3.z);
1356 ffab(i,j,k,n) += cfab(ic,jc,kc,n);
1357 });
1358 }
1359 }
1360}
1361
1362template <typename MF>
1363void
1364MLCellLinOpT<MF>::interpAssign (int amrlev, int fmglev, MF& fine, MF& crse) const
1365{
1366 const int ncomp = this->getNComp();
1367
1368 const Geometry& crse_geom = this->Geom(amrlev,fmglev+1);
1369 IntVect refratio = (amrlev > 0) ? IntVect(2) : this->mg_coarsen_ratio_vec[fmglev];
1370 if (this->hasHiddenDimension()) { refratio[this->hiddenDirection()] = 1; }
1371 const IntVect ng = crse.nGrowVect();
1372
1373 MF cfine;
1374 const MF* cmf;
1375
1376 // Ghost cells not filled from valid cells are zero in both cases.
1377 if (amrex::isMFIterSafe(crse, fine))
1378 {
1379 crse.setBndry(RT(0.0));
1380 crse.FillBoundary(crse_geom.periodicity());
1381 cmf = &crse;
1382 }
1383 else
1384 {
1385 BoxArray cba = fine.boxArray();
1386 cba.coarsen(refratio);
1387 cfine.define(cba, fine.DistributionMap(), ncomp, ng, MFInfo().SetArena(The_Async_Arena()));
1388 cfine.setBndry(RT(0.0));
1389 cfine.ParallelCopy(crse, 0, 0, ncomp, IntVect(0), ng, crse_geom.periodicity());
1390 cmf = & cfine;
1391 }
1392
1393 bool isEB = fine.hasEBFabFactory();
1394 ignore_unused(isEB);
1395
1396#ifdef AMREX_USE_EB
1397 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(&(fine.Factory()));
1398 const FabArray<EBCellFlagFab>* flags = (factory) ? &(factory->getMultiEBCellFlagFab()) : nullptr;
1399#endif
1400
1401 MFItInfo mfi_info;
1402 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
1403#ifdef AMREX_USE_OMP
1404#pragma omp parallel if (Gpu::notInLaunchRegion())
1405#endif
1406 for (MFIter mfi(fine, mfi_info); mfi.isValid(); ++mfi)
1407 {
1408 const Box& bx = mfi.tilebox();
1409 const auto& ff = fine.array(mfi);
1410 const auto& cc = cmf->array(mfi);
1411#ifdef AMREX_USE_EB
1412 bool call_lincc;
1413 if (isEB)
1414 {
1415 const auto& flag = (*flags)[mfi];
1416 if (flag.getType(amrex::grow(bx,1)) == FabType::regular) {
1417 call_lincc = true;
1418 } else {
1419 Array4<EBCellFlag const> const& flg = flag.const_array();
1421 {
1422 mlmg_eb_cc_interp_r<2>(tbx, ff, cc, flg, ncomp);
1423 });
1424
1425 call_lincc = false;
1426 }
1427 }
1428 else
1429 {
1430 call_lincc = true;
1431 }
1432#else
1433 const bool call_lincc = true;
1434#endif
1435 if (call_lincc)
1436 {
1437#if (AMREX_SPACEDIM == 3)
1438 if (this->hasHiddenDimension()) {
1439 Box const& bx_2d = this->compactify(bx);
1440 auto const& ff_2d = this->compactify(ff);
1441 auto const& cc_2d = this->compactify(cc);
1443 {
1444 TwoD::mlmg_lin_cc_interp_r2(tbx, ff_2d, cc_2d, ncomp);
1445 });
1446 } else
1447#endif
1448 {
1450 {
1451 mlmg_lin_cc_interp_r2(tbx, ff, cc, ncomp);
1452 });
1453 }
1454 }
1455 }
1456}
1457
1458template <typename MF>
1459void
1460MLCellLinOpT<MF>::interpolationAmr (int famrlev, MF& fine, const MF& crse,
1461 IntVect const& /*nghost*/) const
1462{
1463 const int ncomp = this->getNComp();
1464 const IntVect refratioV = this->AMRRefRatioVect(famrlev-1);
1465 // AMRRefRatioVect sets hidden direction to 1 and active directions to the
1466 // scalar ratio; max() cleanly recovers the active ratio in all cases.
1467 const int refratio = refratioV.max();
1468
1469#ifdef AMREX_USE_EB
1470 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(famrlev));
1471 const FabArray<EBCellFlagFab>* flags = (factory) ? &(factory->getMultiEBCellFlagFab()) : nullptr;
1472#endif
1473
1474 MFItInfo mfi_info;
1475 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
1476#ifdef AMREX_USE_OMP
1477#pragma omp parallel if (Gpu::notInLaunchRegion())
1478#endif
1479 for (MFIter mfi(fine, mfi_info); mfi.isValid(); ++mfi)
1480 {
1481 const Box& bx = mfi.tilebox();
1482 auto const& ff = fine.array(mfi);
1483 auto const& cc = crse.const_array(mfi);
1484#ifdef AMREX_USE_EB
1485 bool call_lincc;
1486 if (factory)
1487 {
1488 const auto& flag = (*flags)[mfi];
1489 if (flag.getType(amrex::grow(bx,1)) == FabType::regular) {
1490 call_lincc = true;
1491 } else {
1492 Array4<EBCellFlag const> const& flg = flag.const_array();
1493 switch(refratio) {
1494 case 2:
1495 {
1497 {
1498 mlmg_eb_cc_interp_r<2>(tbx, ff, cc, flg, ncomp);
1499 });
1500 break;
1501 }
1502 case 4:
1503 {
1505 {
1506 mlmg_eb_cc_interp_r<4>(tbx, ff, cc, flg, ncomp);
1507 });
1508 break;
1509 }
1510 default:
1511 amrex::Abort("mlmg_eb_cc_interp: only refratio 2 and 4 are supported");
1512 }
1513
1514 call_lincc = false;
1515 }
1516 }
1517 else
1518 {
1519 call_lincc = true;
1520 }
1521#else
1522 const bool call_lincc = true;
1523#endif
1524 if (call_lincc)
1525 {
1526#if (AMREX_SPACEDIM == 3)
1527 if (this->hasHiddenDimension()) {
1528 Box const& bx_2d = this->compactify(bx);
1529 auto const& ff_2d = this->compactify(ff);
1530 auto const& cc_2d = this->compactify(cc);
1531 switch(refratio) {
1532 case 2:
1533 {
1535 {
1536 TwoD::mlmg_lin_cc_interp_r2(tbx, ff_2d, cc_2d, ncomp);
1537 });
1538 break;
1539 }
1540 case 4:
1541 {
1543 {
1544 TwoD::mlmg_lin_cc_interp_r4(tbx, ff_2d, cc_2d, ncomp);
1545 });
1546 break;
1547 }
1548 default:
1549 amrex::Abort("mlmg_lin_cc_interp: only refratio 2 and 4 are supported");
1550 }
1551 } else
1552#endif
1553 {
1554 switch(refratio) {
1555 case 2:
1556 {
1558 {
1559 mlmg_lin_cc_interp_r2(tbx, ff, cc, ncomp);
1560 });
1561 break;
1562 }
1563 case 4:
1564 {
1566 {
1567 mlmg_lin_cc_interp_r4(tbx, ff, cc, ncomp);
1568 });
1569 break;
1570 }
1571 default:
1572 amrex::Abort("mlmg_lin_cc_interp: only refratio 2 and 4 are supported");
1573 }
1574 }
1575 }
1576 }
1577}
1578
1579template <typename MF>
1580void
1581MLCellLinOpT<MF>::averageDownSolutionRHS (int camrlev, MF& crse_sol, MF& crse_rhs,
1582 const MF& fine_sol, const MF& fine_rhs)
1583{
1584 const auto amrrr = this->AMRRefRatioVect(camrlev);
1585 const int ncomp = this->getNComp();
1586 amrex::average_down(fine_sol, crse_sol, 0, ncomp, amrrr);
1587 amrex::average_down(fine_rhs, crse_rhs, 0, ncomp, amrrr);
1588}
1589
1590template <typename MF>
1591void
1592MLCellLinOpT<MF>::apply (int amrlev, int mglev, MF& out, MF& in, BCMode bc_mode,
1593 StateMode s_mode, const MLMGBndryT<MF>* bndry) const
1594{
1595 BL_PROFILE("MLCellLinOp::apply()");
1596 applyBC(amrlev, mglev, in, bc_mode, s_mode, bndry);
1597 Fapply(amrlev, mglev, out, in);
1598}
1599
1600template <typename MF>
1601void
1602MLCellLinOpT<MF>::smooth (int amrlev, int mglev, MF& sol, const MF& rhs,
1603 bool skip_fillboundary, int niter) const
1604{
1605 BL_PROFILE("MLCellLinOp::smooth()");
1606 for (int i = 0; i < niter; ++i) {
1607 for (int redblack = 0; redblack < 2; ++redblack)
1608 {
1609 applyBC(amrlev, mglev, sol, BCMode::Homogeneous, StateMode::Solution,
1610 nullptr, skip_fillboundary);
1611 Fsmooth(amrlev, mglev, sol, rhs, redblack);
1612 skip_fillboundary = false;
1613 }
1614 }
1615}
1616
1617template <typename MF>
1618void
1619MLCellLinOpT<MF>::solutionResidual (int amrlev, MF& resid, MF& x, const MF& b,
1620 const MF* crse_bcdata)
1621{
1622 BL_PROFILE("MLCellLinOp::solutionResidual()");
1623 const int ncomp = this->getNComp();
1624 if (crse_bcdata != nullptr) {
1625 updateSolBC(amrlev, *crse_bcdata);
1626 }
1627 const int mglev = 0;
1628 apply(amrlev, mglev, resid, x, BCMode::Inhomogeneous, StateMode::Solution,
1629 m_bndry_sol[amrlev].get());
1630
1631 AMREX_ASSERT(resid.nComp() == b.nComp());
1632 MF::Xpay(resid, RT(-1.0), b, 0, 0, ncomp, IntVect(0));
1633}
1634
1635template <typename MF>
1636void
1637MLCellLinOpT<MF>::prepareForFluxes (int amrlev, const MF* crse_bcdata)
1638{
1639 if (crse_bcdata != nullptr) {
1640 updateSolBC(amrlev, *crse_bcdata);
1641 }
1642}
1643
1644template <typename MF>
1645void
1646MLCellLinOpT<MF>::correctionResidual (int amrlev, int mglev, MF& resid, MF& x, const MF& b,
1647 BCMode bc_mode, const MF* crse_bcdata)
1648{
1649 BL_PROFILE("MLCellLinOp::correctionResidual()");
1650 const int ncomp = this->getNComp();
1651 if (bc_mode == BCMode::Inhomogeneous)
1652 {
1653 if (crse_bcdata)
1654 {
1655 AMREX_ASSERT(mglev == 0 && amrlev > 0);
1656 updateCorBC(amrlev, *crse_bcdata);
1657 }
1658 apply(amrlev, mglev, resid, x, BCMode::Inhomogeneous, StateMode::Correction,
1659 m_bndry_cor[amrlev].get());
1660 }
1661 else
1662 {
1663 AMREX_ASSERT(crse_bcdata == nullptr);
1664 apply(amrlev, mglev, resid, x, BCMode::Homogeneous, StateMode::Correction, nullptr);
1665 }
1666
1667 MF::Xpay(resid, Real(-1.0), b, 0, 0, ncomp, IntVect(0));
1668}
1669
1670template <typename MF>
1671void
1672MLCellLinOpT<MF>::reflux (int crse_amrlev, MF& res, const MF& crse_sol, const MF&,
1673 MF&, MF& fine_sol, const MF&) const
1674{
1675 BL_PROFILE("MLCellLinOp::reflux()");
1676
1677 auto& fluxreg = m_fluxreg[crse_amrlev];
1678 fluxreg.reset();
1679
1680 const int ncomp = this->getNComp();
1681
1682 const int fine_amrlev = crse_amrlev+1;
1683
1684 Real dt = Real(1.0);
1685 const Real* crse_dx = this->m_geom[crse_amrlev][0].CellSize();
1686 const Real* fine_dx = this->m_geom[fine_amrlev][0].CellSize();
1687
1688 const int mglev = 0;
1689 applyBC(fine_amrlev, mglev, fine_sol, BCMode::Inhomogeneous, StateMode::Solution,
1690 m_bndry_sol[fine_amrlev].get());
1691
1692 MFItInfo mfi_info;
1693 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
1694
1695#ifdef AMREX_USE_OMP
1696#pragma omp parallel if (Gpu::notInLaunchRegion())
1697#endif
1698 {
1700 Array<FAB*,AMREX_SPACEDIM> pflux {{ AMREX_D_DECL(flux.data(), flux.data()+1, flux.data()+2) }};
1701 Array<FAB const*,AMREX_SPACEDIM> cpflux {{ AMREX_D_DECL(flux.data(), flux.data()+1, flux.data()+2) }};
1702
1703 for (MFIter mfi(crse_sol, mfi_info); mfi.isValid(); ++mfi)
1704 {
1705 if (fluxreg.CrseHasWork(mfi))
1706 {
1707 const Box& tbx = mfi.tilebox();
1708 AMREX_D_TERM(flux[0].resize(amrex::surroundingNodes(tbx,0),ncomp,The_Async_Arena());,
1709 flux[1].resize(amrex::surroundingNodes(tbx,1),ncomp,The_Async_Arena());,
1710 flux[2].resize(amrex::surroundingNodes(tbx,2),ncomp,The_Async_Arena()););
1711 FFlux(crse_amrlev, mfi, pflux, crse_sol[mfi], Location::FaceCentroid);
1712 fluxreg.CrseAdd(mfi, cpflux, crse_dx, dt, RunOn::Gpu);
1713 }
1714 }
1715
1716#ifdef AMREX_USE_OMP
1717#pragma omp barrier
1718#endif
1719
1720 for (MFIter mfi(fine_sol, mfi_info); mfi.isValid(); ++mfi)
1721 {
1722 if (fluxreg.FineHasWork(mfi))
1723 {
1724 const Box& tbx = mfi.tilebox();
1725 const int face_only = true;
1726 AMREX_D_TERM(flux[0].resize(amrex::surroundingNodes(tbx,0),ncomp,The_Async_Arena());,
1727 flux[1].resize(amrex::surroundingNodes(tbx,1),ncomp,The_Async_Arena());,
1728 flux[2].resize(amrex::surroundingNodes(tbx,2),ncomp,The_Async_Arena()););
1729 FFlux(fine_amrlev, mfi, pflux, fine_sol[mfi], Location::FaceCentroid, face_only);
1730 fluxreg.FineAdd(mfi, cpflux, fine_dx, dt, RunOn::Gpu);
1731 }
1732 }
1733 }
1734
1735 fluxreg.Reflux(res);
1736 this->applyOverset(crse_amrlev, res);
1737}
1738
1739template <typename MF>
1740void
1742 MF& sol, Location loc) const
1743{
1744 BL_PROFILE("MLCellLinOp::compFlux()");
1745
1746 const int mglev = 0;
1747 const int ncomp = this->getNComp();
1748 applyBC(amrlev, mglev, sol, BCMode::Inhomogeneous, StateMode::Solution,
1749 m_bndry_sol[amrlev].get());
1750
1751 MFItInfo mfi_info;
1752 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
1753
1754#ifdef AMREX_USE_OMP
1755#pragma omp parallel if (Gpu::notInLaunchRegion())
1756#endif
1757 {
1759 Array<FAB*,AMREX_SPACEDIM> pflux {{ AMREX_D_DECL(flux.data(), flux.data()+1, flux.data()+2) }};
1760 for (MFIter mfi(sol, mfi_info); mfi.isValid(); ++mfi)
1761 {
1762 const Box& tbx = mfi.tilebox();
1763 AMREX_D_TERM(flux[0].resize(amrex::surroundingNodes(tbx,0),ncomp,The_Async_Arena());,
1764 flux[1].resize(amrex::surroundingNodes(tbx,1),ncomp,The_Async_Arena());,
1765 flux[2].resize(amrex::surroundingNodes(tbx,2),ncomp,The_Async_Arena()););
1766 FFlux(amrlev, mfi, pflux, sol[mfi], loc);
1767 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1768 const Box& nbx = mfi.nodaltilebox(idim);
1769 auto const& dst = fluxes[idim]->array(mfi);
1770 auto const& src = pflux[idim]->const_array();
1771 AMREX_HOST_DEVICE_PARALLEL_FOR_4D (nbx, ncomp, i, j, k, n,
1772 {
1773 dst(i,j,k,n) = src(i,j,k,n);
1774 });
1775 }
1776 }
1777 }
1778}
1779
1780template <typename MF>
1781void
1783 MF& sol, Location /*loc*/) const
1784{
1785 BL_PROFILE("MLCellLinOp::compGrad()");
1786
1787 if (sol.nComp() > 1) {
1788 amrex::Abort("MLCellLinOp::compGrad called, but only works for single-component solves");
1789 }
1790
1791 const int mglev = 0;
1792 applyBC(amrlev, mglev, sol, BCMode::Inhomogeneous, StateMode::Solution,
1793 m_bndry_sol[amrlev].get());
1794
1795 const int ncomp = this->getNComp();
1796
1797 AMREX_D_TERM(const RT dxi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0));,
1798 const RT dyi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(1));,
1799 const RT dzi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(2)););
1800#ifdef AMREX_USE_OMP
1801#pragma omp parallel if (Gpu::notInLaunchRegion())
1802#endif
1803 for (MFIter mfi(sol, TilingIfNotGPU()); mfi.isValid(); ++mfi)
1804 {
1805 AMREX_D_TERM(const Box& xbx = mfi.nodaltilebox(0);,
1806 const Box& ybx = mfi.nodaltilebox(1);,
1807 const Box& zbx = mfi.nodaltilebox(2););
1808 const auto& s = sol.array(mfi);
1809 AMREX_D_TERM(const auto& gx = grad[0]->array(mfi);,
1810 const auto& gy = grad[1]->array(mfi);,
1811 const auto& gz = grad[2]->array(mfi););
1812
1813 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( xbx, ncomp, i, j, k, n,
1814 {
1815 gx(i,j,k,n) = dxi*(s(i,j,k,n) - s(i-1,j,k,n));
1816 });
1817#if (AMREX_SPACEDIM >= 2)
1818 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( ybx, ncomp, i, j, k, n,
1819 {
1820 gy(i,j,k,n) = dyi*(s(i,j,k,n) - s(i,j-1,k,n));
1821 });
1822#endif
1823#if (AMREX_SPACEDIM == 3)
1824 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( zbx, ncomp, i, j, k, n,
1825 {
1826 gz(i,j,k,n) = dzi*(s(i,j,k,n) - s(i,j,k-1,n));
1827 });
1828#endif
1829 }
1830
1831 addInhomogNeumannFlux(amrlev, grad, sol, false);
1832}
1833
1834template <typename MF>
1835void
1836MLCellLinOpT<MF>::applyMetricTerm (int amrlev, int mglev, MF& rhs) const
1837{
1838 amrex::ignore_unused(amrlev,mglev,rhs);
1839#if (AMREX_SPACEDIM != 3)
1840 if (!m_has_metric_term) { return; }
1841
1842 const int ncomp = rhs.nComp();
1843
1844 bool cc = rhs.ixType().cellCentered(0);
1845
1846 const Geometry& geom = this->m_geom[amrlev][mglev];
1847 const RT dx = static_cast<RT>(geom.CellSize(0));
1848 const RT probxlo = static_cast<RT>(geom.ProbLo(0));
1849
1850#ifdef AMREX_USE_OMP
1851#pragma omp parallel if (Gpu::notInLaunchRegion())
1852#endif
1853 for (MFIter mfi(rhs,TilingIfNotGPU()); mfi.isValid(); ++mfi)
1854 {
1855 const Box& tbx = mfi.tilebox();
1856 auto const& rhsarr = rhs.array(mfi);
1857#if (AMREX_SPACEDIM == 1)
1858 if (cc) {
1859 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1860 {
1861 RT rc = probxlo + (RT(i)+RT(0.5))*dx;
1862 rhsarr(i,j,k,n) *= rc*rc;
1863 });
1864 } else {
1865 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1866 {
1867 RT re = probxlo + RT(i)*dx;
1868 rhsarr(i,j,k,n) *= re*re;
1869 });
1870 }
1871#elif (AMREX_SPACEDIM == 2)
1872 if (cc) {
1873 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1874 {
1875 RT rc = probxlo + (RT(i)+RT(0.5))*dx;
1876 rhsarr(i,j,k,n) *= rc;
1877 });
1878 } else {
1879 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1880 {
1881 RT re = probxlo + RT(i)*dx;
1882 rhsarr(i,j,k,n) *= re;
1883 });
1884 }
1885#endif
1886 }
1887#endif
1888}
1889
1890template <typename MF>
1891void
1892MLCellLinOpT<MF>::unapplyMetricTerm (int amrlev, int mglev, MF& rhs) const
1893{
1894 amrex::ignore_unused(amrlev,mglev,rhs);
1895#if (AMREX_SPACEDIM != 3)
1896 if (!m_has_metric_term) { return; }
1897
1898 const int ncomp = rhs.nComp();
1899
1900 bool cc = rhs.ixType().cellCentered(0);
1901
1902 const Geometry& geom = this->m_geom[amrlev][mglev];
1903 const RT dx = static_cast<RT>(geom.CellSize(0));
1904 const RT probxlo = static_cast<RT>(geom.ProbLo(0));
1905
1906#ifdef AMREX_USE_OMP
1907#pragma omp parallel if (Gpu::notInLaunchRegion())
1908#endif
1909 for (MFIter mfi(rhs,TilingIfNotGPU()); mfi.isValid(); ++mfi)
1910 {
1911 const Box& tbx = mfi.tilebox();
1912 auto const& rhsarr = rhs.array(mfi);
1913#if (AMREX_SPACEDIM == 1)
1914 if (cc) {
1915 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1916 {
1917 RT rcinv = RT(1.0)/(probxlo + (RT(i)+RT(0.5))*dx);
1918 rhsarr(i,j,k,n) *= rcinv*rcinv;
1919 });
1920 } else {
1921 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1922 {
1923 RT re = probxlo + RT(i)*dx;
1924 RT reinv = (re==RT(0.0)) ? RT(0.0) : RT(1.)/re;
1925 rhsarr(i,j,k,n) *= reinv*reinv;
1926 });
1927 }
1928#elif (AMREX_SPACEDIM == 2)
1929 if (cc) {
1930 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1931 {
1932 RT rcinv = RT(1.0)/(probxlo + (RT(i)+RT(0.5))*dx);
1933 rhsarr(i,j,k,n) *= rcinv;
1934 });
1935 } else {
1936 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1937 {
1938 RT re = probxlo + RT(i)*dx;
1939 RT reinv = (re==RT(0.0)) ? RT(0.0) : RT(1.)/re;
1940 rhsarr(i,j,k,n) *= reinv;
1941 });
1942 }
1943#endif
1944 }
1945#endif
1946}
1947
1948template <typename MF>
1949auto
1950MLCellLinOpT<MF>::getSolvabilityOffset (int amrlev, int mglev, MF const& rhs) const
1951 -> Vector<RT>
1952{
1953 computeVolInv();
1954
1955 const int ncomp = this->getNComp();
1956 Vector<RT> offset(ncomp);
1957
1958#ifdef AMREX_USE_EB
1959 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(amrlev,mglev));
1960 if (factory && !factory->isAllRegular())
1961 {
1962 if constexpr (std::is_same<MF,MultiFab>()) {
1963 const MultiFab& vfrac = factory->getVolFrac();
1964 for (int c = 0; c < ncomp; ++c) {
1965 offset[c] = amrex::Dot(rhs, c, vfrac, 0, 1, IntVect(0), true)
1966 * m_volinv[amrlev][mglev];
1967 }
1968 } else {
1969 amrex::Abort("TODO: MLMG with EB only works with MultiFab");
1970 }
1971 }
1972 else
1973#endif
1974 {
1975 for (int c = 0; c < ncomp; ++c) {
1976 offset[c] = rhs.sum(c,IntVect(0),true) * m_volinv[amrlev][mglev];
1977 }
1978 }
1979
1981
1982 return offset;
1983}
1984
1985template <typename MF>
1986void
1987MLCellLinOpT<MF>::fixSolvabilityByOffset (int /*amrlev*/, int /*mglev*/, MF& rhs,
1988 Vector<RT> const& offset) const
1989{
1990 const int ncomp = this->getNComp();
1991 for (int c = 0; c < ncomp; ++c) {
1992 rhs.plus(-offset[c], c, 1);
1993 }
1994#ifdef AMREX_USE_EB
1995 if (!rhs.isAllRegular()) {
1996 if constexpr (std::is_same<MF,MultiFab>()) {
1997 amrex::EB_set_covered(rhs, 0, ncomp, 0, 0.0_rt);
1998 } else {
1999 amrex::Abort("amrex::EB_set_covered only works with MultiFab");
2000 }
2001 }
2002#endif
2003}
2004
2005template <typename MF>
2006void
2008{
2009 BL_PROFILE("MLCellLinOp::prepareForSolve()");
2010
2011 const int imaxorder = this->maxorder;
2012 const int ncomp = this->getNComp();
2013 const int hidden_direction = this->hiddenDirection();
2014 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
2015 {
2016 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
2017 {
2018 const auto& bcondloc = *m_bcondloc[amrlev][mglev];
2019 const auto& maskvals = m_maskvals[amrlev][mglev];
2020
2021 const RT dxi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0));
2022 const RT dyi = static_cast<RT>((AMREX_SPACEDIM >= 2) ? this->m_geom[amrlev][mglev].InvCellSize(1) : Real(1.0));
2023 const RT dzi = static_cast<RT>((AMREX_SPACEDIM == 3) ? this->m_geom[amrlev][mglev].InvCellSize(2) : Real(1.0));
2024
2025 auto& undrrelxr = this->m_undrrelxr[amrlev][mglev];
2026 MF foo(this->m_grids[amrlev][mglev], this->m_dmap[amrlev][mglev], ncomp, 0, MFInfo().SetAlloc(false));
2027
2028#ifdef AMREX_USE_EB
2029 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->m_factory[amrlev][mglev].get());
2030 const FabArray<EBCellFlagFab>* flags =
2031 (factory) ? &(factory->getMultiEBCellFlagFab()) : nullptr;
2032 auto area = (factory) ? factory->getAreaFrac()
2033 : Array<const MultiCutFab*,AMREX_SPACEDIM>{AMREX_D_DECL(nullptr,nullptr,nullptr)};
2035#endif
2036
2037#ifdef AMREX_USE_GPU
2038 if (Gpu::inLaunchRegion()) {
2039#ifdef AMREX_USE_EB
2040 if (factory && !factory->isAllRegular()) {
2041#if defined(AMREX_USE_CUDA) && defined(_WIN32)
2042 if (!std::is_same<MF,MultiFab>()) {
2043#else
2044 if constexpr (!std::is_same<MF,MultiFab>()) {
2045#endif
2046 amrex::Abort("MLCellLinOp with EB only works with MultiFab");
2047 } else {
2049 tags.reserve(foo.local_size()*AMREX_SPACEDIM*ncomp);
2050
2051 for (MFIter mfi(foo); mfi.isValid(); ++mfi)
2052 {
2053 const Box& vbx = mfi.validbox();
2054
2055 const auto & bdlv = bcondloc.bndryLocs(mfi);
2056 const auto & bdcv = bcondloc.bndryConds(mfi);
2057
2058 auto fabtyp = (flags) ? (*flags)[mfi].getType(vbx) : FabType::regular;
2059
2060 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
2061 {
2062 if (idim != hidden_direction && fabtyp != FabType::covered) {
2063 const Orientation olo(idim,Orientation::low);
2064 const Orientation ohi(idim,Orientation::high);
2065 auto const& ap = (fabtyp == FabType::singlevalued)
2066 ? area[idim]->const_array(mfi) : Array4<Real const>{};
2067 for (int icomp = 0; icomp < ncomp; ++icomp) {
2068 tags.emplace_back(MLMGPSEBTag<RT>{undrrelxr[olo].array(mfi),
2069 undrrelxr[ohi].array(mfi),
2070 ap,
2071 maskvals[olo].const_array(mfi),
2072 maskvals[ohi].const_array(mfi),
2073 bdlv[icomp][olo], bdlv[icomp][ohi],
2074 amrex::adjCell(vbx,olo),
2075 bdcv[icomp][olo], bdcv[icomp][ohi],
2076 vbx.length(idim), icomp, idim});
2077 }
2078 }
2079 }
2080 }
2081
2082 ParallelFor(tags,
2083 [=] AMREX_GPU_DEVICE (int i, int j, int k, MLMGPSEBTag<RT> const& tag) noexcept
2084 {
2085 if (tag.ap) {
2086 if (tag.dir == 0)
2087 {
2088 mllinop_comp_interp_coef0_x_eb
2089 (0, i , j, k, tag.blen, tag.flo, tag.mlo, tag.ap,
2090 tag.bctlo, tag.bcllo, imaxorder, dxi, tag.comp);
2091 mllinop_comp_interp_coef0_x_eb
2092 (1, i+tag.blen+1, j, k, tag.blen, tag.fhi, tag.mhi, tag.ap,
2093 tag.bcthi, tag.bclhi, imaxorder, dxi, tag.comp);
2094 }
2095#if (AMREX_SPACEDIM > 1)
2096 else
2097#if (AMREX_SPACEDIM > 2)
2098 if (tag.dir == 1)
2099#endif
2100 {
2101 mllinop_comp_interp_coef0_y_eb
2102 (0, i, j , k, tag.blen, tag.flo, tag.mlo, tag.ap,
2103 tag.bctlo, tag.bcllo, imaxorder, dyi, tag.comp);
2104 mllinop_comp_interp_coef0_y_eb
2105 (1, i, j+tag.blen+1, k, tag.blen, tag.fhi, tag.mhi, tag.ap,
2106 tag.bcthi, tag.bclhi, imaxorder, dyi, tag.comp);
2107 }
2108#if (AMREX_SPACEDIM > 2)
2109 else {
2110 mllinop_comp_interp_coef0_z_eb
2111 (0, i, j, k , tag.blen, tag.flo, tag.mlo, tag.ap,
2112 tag.bctlo, tag.bcllo, imaxorder, dzi, tag.comp);
2113 mllinop_comp_interp_coef0_z_eb
2114 (1, i, j, k+tag.blen+1, tag.blen, tag.fhi, tag.mhi, tag.ap,
2115 tag.bcthi, tag.bclhi, imaxorder, dzi, tag.comp);
2116 }
2117#endif
2118#endif
2119 } else {
2120 if (tag.dir == 0)
2121 {
2122 mllinop_comp_interp_coef0_x
2123 (0, i , j, k, tag.blen, tag.flo, tag.mlo,
2124 tag.bctlo, tag.bcllo, imaxorder, dxi, tag.comp);
2125 mllinop_comp_interp_coef0_x
2126 (1, i+tag.blen+1, j, k, tag.blen, tag.fhi, tag.mhi,
2127 tag.bcthi, tag.bclhi, imaxorder, dxi, tag.comp);
2128 }
2129#if (AMREX_SPACEDIM > 1)
2130 else
2131#if (AMREX_SPACEDIM > 2)
2132 if (tag.dir == 1)
2133#endif
2134 {
2135 mllinop_comp_interp_coef0_y
2136 (0, i, j , k, tag.blen, tag.flo, tag.mlo,
2137 tag.bctlo, tag.bcllo, imaxorder, dyi, tag.comp);
2138 mllinop_comp_interp_coef0_y
2139 (1, i, j+tag.blen+1, k, tag.blen, tag.fhi, tag.mhi,
2140 tag.bcthi, tag.bclhi, imaxorder, dyi, tag.comp);
2141 }
2142#if (AMREX_SPACEDIM > 2)
2143 else {
2144 mllinop_comp_interp_coef0_z
2145 (0, i, j, k , tag.blen, tag.flo, tag.mlo,
2146 tag.bctlo, tag.bcllo, imaxorder, dzi, tag.comp);
2147 mllinop_comp_interp_coef0_z
2148 (1, i, j, k+tag.blen+1, tag.blen, tag.fhi, tag.mhi,
2149 tag.bcthi, tag.bclhi, imaxorder, dzi, tag.comp);
2150 }
2151#endif
2152#endif
2153 }
2154 });
2155 }
2156 } else
2157#endif
2158 {
2160 tags.reserve(foo.local_size()*AMREX_SPACEDIM*ncomp);
2161
2162 for (MFIter mfi(foo); mfi.isValid(); ++mfi)
2163 {
2164 const Box& vbx = mfi.validbox();
2165
2166 const auto & bdlv = bcondloc.bndryLocs(mfi);
2167 const auto & bdcv = bcondloc.bndryConds(mfi);
2168
2169 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
2170 {
2171 if (idim != hidden_direction) {
2172 const Orientation olo(idim,Orientation::low);
2173 const Orientation ohi(idim,Orientation::high);
2174 for (int icomp = 0; icomp < ncomp; ++icomp) {
2175 tags.emplace_back(MLMGPSTag<RT>{undrrelxr[olo].array(mfi),
2176 undrrelxr[ohi].array(mfi),
2177 maskvals[olo].const_array(mfi),
2178 maskvals[ohi].const_array(mfi),
2179 bdlv[icomp][olo], bdlv[icomp][ohi],
2180 amrex::adjCell(vbx,olo),
2181 bdcv[icomp][olo], bdcv[icomp][ohi],
2182 vbx.length(idim), icomp, idim});
2183 }
2184 }
2185 }
2186 }
2187
2188 ParallelFor(tags,
2189 [=] AMREX_GPU_DEVICE (int i, int j, int k, MLMGPSTag<RT> const& tag) noexcept
2190 {
2191 if (tag.dir == 0)
2192 {
2193 mllinop_comp_interp_coef0_x
2194 (0, i , j, k, tag.blen, tag.flo, tag.mlo,
2195 tag.bctlo, tag.bcllo, imaxorder, dxi, tag.comp);
2196 mllinop_comp_interp_coef0_x
2197 (1, i+tag.blen+1, j, k, tag.blen, tag.fhi, tag.mhi,
2198 tag.bcthi, tag.bclhi, imaxorder, dxi, tag.comp);
2199 }
2200#if (AMREX_SPACEDIM > 1)
2201 else
2202#if (AMREX_SPACEDIM > 2)
2203 if (tag.dir == 1)
2204#endif
2205 {
2206 mllinop_comp_interp_coef0_y
2207 (0, i, j , k, tag.blen, tag.flo, tag.mlo,
2208 tag.bctlo, tag.bcllo, imaxorder, dyi, tag.comp);
2209 mllinop_comp_interp_coef0_y
2210 (1, i, j+tag.blen+1, k, tag.blen, tag.fhi, tag.mhi,
2211 tag.bcthi, tag.bclhi, imaxorder, dyi, tag.comp);
2212 }
2213#if (AMREX_SPACEDIM > 2)
2214 else {
2215 mllinop_comp_interp_coef0_z
2216 (0, i, j, k , tag.blen, tag.flo, tag.mlo,
2217 tag.bctlo, tag.bcllo, imaxorder, dzi, tag.comp);
2218 mllinop_comp_interp_coef0_z
2219 (1, i, j, k+tag.blen+1, tag.blen, tag.fhi, tag.mhi,
2220 tag.bcthi, tag.bclhi, imaxorder, dzi, tag.comp);
2221 }
2222#endif
2223#endif
2224 });
2225 }
2226 } else
2227#endif
2228 {
2229#ifdef AMREX_USE_OMP
2230#pragma omp parallel
2231#endif
2232 for (MFIter mfi(foo, MFItInfo{}.SetDynamic(true)); mfi.isValid(); ++mfi)
2233 {
2234 const Box& vbx = mfi.validbox();
2235
2236 const auto & bdlv = bcondloc.bndryLocs(mfi);
2237 const auto & bdcv = bcondloc.bndryConds(mfi);
2238
2239#ifdef AMREX_USE_EB
2240 auto fabtyp = (flags) ? (*flags)[mfi].getType(vbx) : FabType::regular;
2241#endif
2242 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
2243 {
2244 if (idim == hidden_direction) { continue; }
2245 const Orientation olo(idim,Orientation::low);
2246 const Orientation ohi(idim,Orientation::high);
2247 const Box blo = amrex::adjCellLo(vbx, idim);
2248 const Box bhi = amrex::adjCellHi(vbx, idim);
2249 const int blen = vbx.length(idim);
2250 const auto& mlo = maskvals[olo].array(mfi);
2251 const auto& mhi = maskvals[ohi].array(mfi);
2252 const auto& flo = undrrelxr[olo].array(mfi);
2253 const auto& fhi = undrrelxr[ohi].array(mfi);
2254 for (int icomp = 0; icomp < ncomp; ++icomp) {
2255 const BoundCond bctlo = bdcv[icomp][olo];
2256 const BoundCond bcthi = bdcv[icomp][ohi];
2257 const auto bcllo = bdlv[icomp][olo];
2258 const auto bclhi = bdlv[icomp][ohi];
2259#ifdef AMREX_USE_EB
2260 if (fabtyp == FabType::singlevalued) {
2261 if constexpr (!std::is_same<MF,MultiFab>()) {
2262 amrex::Abort("MLCellLinOp with EB only works with MultiFab");
2263 } else {
2264 auto const& ap = area[idim]->const_array(mfi);
2265 if (idim == 0) {
2266 mllinop_comp_interp_coef0_x_eb
2267 (0, blo, blen, flo, mlo, ap, bctlo, bcllo,
2268 imaxorder, dxi, icomp);
2269 mllinop_comp_interp_coef0_x_eb
2270 (1, bhi, blen, fhi, mhi, ap, bcthi, bclhi,
2271 imaxorder, dxi, icomp);
2272 } else if (idim == 1) {
2273 mllinop_comp_interp_coef0_y_eb
2274 (0, blo, blen, flo, mlo, ap, bctlo, bcllo,
2275 imaxorder, dyi, icomp);
2276 mllinop_comp_interp_coef0_y_eb
2277 (1, bhi, blen, fhi, mhi, ap, bcthi, bclhi,
2278 imaxorder, dyi, icomp);
2279 } else {
2280 mllinop_comp_interp_coef0_z_eb
2281 (0, blo, blen, flo, mlo, ap, bctlo, bcllo,
2282 imaxorder, dzi, icomp);
2283 mllinop_comp_interp_coef0_z_eb
2284 (1, bhi, blen, fhi, mhi, ap, bcthi, bclhi,
2285 imaxorder, dzi, icomp);
2286 }
2287 }
2288 } else if (fabtyp == FabType::regular)
2289#endif
2290 {
2291 if (idim == 0) {
2292 mllinop_comp_interp_coef0_x
2293 (0, blo, blen, flo, mlo, bctlo, bcllo,
2294 imaxorder, dxi, icomp);
2295 mllinop_comp_interp_coef0_x
2296 (1, bhi, blen, fhi, mhi, bcthi, bclhi,
2297 imaxorder, dxi, icomp);
2298 } else if (idim == 1) {
2299 mllinop_comp_interp_coef0_y
2300 (0, blo, blen, flo, mlo, bctlo, bcllo,
2301 imaxorder, dyi, icomp);
2302 mllinop_comp_interp_coef0_y
2303 (1, bhi, blen, fhi, mhi, bcthi, bclhi,
2304 imaxorder, dyi, icomp);
2305 } else {
2306 mllinop_comp_interp_coef0_z
2307 (0, blo, blen, flo, mlo, bctlo, bcllo,
2308 imaxorder, dzi, icomp);
2309 mllinop_comp_interp_coef0_z
2310 (1, bhi, blen, fhi, mhi, bcthi, bclhi,
2311 imaxorder, dzi, icomp);
2312 }
2313 }
2314 }
2315 }
2316 }
2317 }
2318 }
2319 }
2320
2321#ifdef AMREX_USE_GPU
2323#endif
2324}
2325
2326template <typename MF>
2327auto
2328MLCellLinOpT<MF>::xdoty (int /*amrlev*/, int /*mglev*/, const MF& x, const MF& y, bool local) const
2329 -> RT
2330{
2331 const int ncomp = this->getNComp();
2332 const IntVect nghost(0);
2333 RT result = amrex::Dot(x,0,y,0,ncomp,nghost,true);
2334 if (!local) {
2336 }
2337 return result;
2338}
2339
2340template <typename MF>
2341auto
2343{
2344 const int ncomp = this->getNComp();
2345 const IntVect nghost(0);
2346 RT result = 0;
2347 for (int ilev = 0; ilev < this->NAMRLevels()-1; ++ilev) {
2348 result += amrex::Dot(*m_norm_fine_mask[ilev], *x[ilev], 0, *y[ilev], 0, ncomp, nghost, true);
2349 }
2350 result += amrex::Dot(*x[this->NAMRLevels()-1], 0,
2351 *y[this->NAMRLevels()-1], 0, ncomp, nghost, true);
2353 return result;
2354}
2355
2356template <typename MF>
2357auto
2359{
2360 const int ncomp = this->getNComp();
2361 const IntVect nghost(0);
2362 RT result = 0;
2363 for (int ilev = 0; ilev < this->NAMRLevels()-1; ++ilev) {
2364 result += amrex::Dot(*m_norm_fine_mask[ilev], *x[ilev], 0, ncomp, nghost, true);
2365 }
2366 result += amrex::Dot(*x[this->NAMRLevels()-1], 0, ncomp, nghost, true);
2368 return std::sqrt(result);
2369}
2370
2371template <typename MF>
2372void
2373MLCellLinOpT<MF>::computeVolInv () const
2374{
2375 if (!m_volinv.empty()) { return; }
2376
2377 m_volinv.resize(this->m_num_amr_levels);
2378 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
2379 m_volinv[amrlev].resize(this->NMGLevels(amrlev));
2380 }
2381
2382 // We don't need to compute for every level
2383
2384 auto f = [&] (int amrlev, int mglev) {
2385#ifdef AMREX_USE_EB
2386 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(amrlev,mglev));
2387 if (factory && !factory->isAllRegular())
2388 {
2389 if constexpr (std::is_same<MF,MultiFab>()) {
2390 const auto& vfrac = factory->getVolFrac();
2391 m_volinv[amrlev][mglev] = vfrac.sum(0,true);
2392 } else {
2393 amrex::Abort("MLCellLinOp with EB only works with MultiFab");
2394 }
2395 }
2396 else
2397#endif
2398 {
2399 auto const npts = (this->m_coarse_fine_bc_type == LinOpBCType::Dirichlet)
2400 ? this->compactify(this->Geom(amrlev,mglev).Domain()).d_numPts()
2401 : this->m_grids[amrlev][mglev].d_numPts();
2402 AMREX_ASSERT(npts > 0.);
2403 m_volinv[amrlev][mglev] = RT(1.0 / npts);
2404 }
2405 };
2406
2407 // amrlev = 0, mglev = 0
2408 f(0,0);
2409
2410 int mgbottom = this->NMGLevels(0)-1;
2411 f(0,mgbottom);
2412
2413#ifdef AMREX_USE_EB
2414 RT temp1, temp2;
2415 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(0,0));
2416 if (factory && !factory->isAllRegular())
2417 {
2418 ParallelAllReduce::Sum<RT>({m_volinv[0][0], m_volinv[0][mgbottom]},
2420 temp1 = RT(1.0)/m_volinv[0][0];
2421 temp2 = RT(1.0)/m_volinv[0][mgbottom];
2422 }
2423 else
2424 {
2425 temp1 = m_volinv[0][0];
2426 temp2 = m_volinv[0][mgbottom];
2427 }
2428 m_volinv[0][0] = temp1;
2429 m_volinv[0][mgbottom] = temp2;
2430#endif
2431}
2432
2433template <typename MF>
2434auto
2435MLCellLinOpT<MF>::normInf (int amrlev, MF const& mf, bool local) const -> RT
2436{
2437 const int ncomp = this->getNComp();
2438 const int finest_level = this->NAMRLevels() - 1;
2439 RT norm = RT(0.0);
2440#ifdef AMREX_USE_EB
2441 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(amrlev));
2442 if (factory && !factory->isAllRegular()) {
2443#if defined(AMREX_USE_CUDA) && defined(_WIN32)
2444 if (!std::is_same<MF,MultiFab>()) {
2445#else
2446 if constexpr (!std::is_same<MF,MultiFab>()) {
2447#endif
2448 amrex::Abort("MLCellLinOpT with EB only works with MultiFab");
2449 } else {
2450 const MultiFab& vfrac = factory->getVolFrac();
2451 // |r*vfrac| with NaN as +inf; covered cells do not count.
2452 Math::detail::AbsNanToInf<Real> const absinf{};
2453 if (amrlev == finest_level) {
2454#ifdef AMREX_USE_GPU
2455 if (Gpu::inLaunchRegion()) {
2456 auto const& ma = mf.const_arrays();
2457 auto const& vfrac_ma = vfrac.const_arrays();
2459 mf, IntVect(0), ncomp,
2460 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n)
2462 {
2463 Real const vf = vfrac_ma[box_no](i,j,k);
2464 return (vf > Real(0)) ? absinf(ma[box_no](i,j,k,n))*vf : Real(0);
2465 });
2466 } else
2467#endif
2468 {
2469#ifdef AMREX_USE_OMP
2470#pragma omp parallel reduction(max:norm)
2471#endif
2472 for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
2473 Box const& bx = mfi.tilebox();
2474 auto const& fab = mf.const_array(mfi);
2475 auto const& v = vfrac.const_array(mfi);
2476 AMREX_LOOP_4D(bx, ncomp, i, j, k, n,
2477 {
2478 if (v(i,j,k) > Real(0)) {
2479 norm = std::max(norm, absinf(fab(i,j,k,n))*v(i,j,k));
2480 }
2481 });
2482 }
2483 }
2484 } else {
2485#ifdef AMREX_USE_GPU
2486 if (Gpu::inLaunchRegion()) {
2487 auto const& ma = mf.const_arrays();
2488 auto const& mask_ma = m_norm_fine_mask[amrlev]->const_arrays();
2489 auto const& vfrac_ma = vfrac.const_arrays();
2491 mf, IntVect(0), ncomp,
2492 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n)
2494 {
2495 if (mask_ma[box_no](i,j,k)) {
2496 Real const vf = vfrac_ma[box_no](i,j,k);
2497 return (vf > Real(0)) ? absinf(ma[box_no](i,j,k,n))*vf : Real(0);
2498 } else {
2499 return Real(0.0);
2500 }
2501 });
2502 } else
2503#endif
2504 {
2505#ifdef AMREX_USE_OMP
2506#pragma omp parallel reduction(max:norm)
2507#endif
2508 for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
2509 Box const& bx = mfi.tilebox();
2510 auto const& fab = mf.const_array(mfi);
2511 auto const& mask = m_norm_fine_mask[amrlev]->const_array(mfi);
2512 auto const& v = vfrac.const_array(mfi);
2513 AMREX_LOOP_4D(bx, ncomp, i, j, k, n,
2514 {
2515 if (mask(i,j,k) && v(i,j,k) > Real(0)) {
2516 norm = std::max(norm, absinf(fab(i,j,k,n))*v(i,j,k));
2517 }
2518 });
2519 }
2520 }
2521 }
2522 }
2523 } else
2524#endif
2525 {
2526 if (amrlev == finest_level) {
2527 norm = mf.norminf(0, ncomp, IntVect(0), true);
2528 } else {
2529 norm = mf.norminf(*m_norm_fine_mask[amrlev], 0, ncomp, IntVect(0), true);
2530 }
2531 }
2532
2534 return norm;
2535}
2536
2537template <typename MF>
2538void
2540{
2541 int ncomp = this->getNComp();
2542 for (int falev = this->NAMRLevels()-1; falev > 0; --falev)
2543 {
2544#ifdef AMREX_USE_EB
2545 if (!sol[falev].isAllRegular()) {
2546 if constexpr (std::is_same<MF,MultiFab>()) {
2547 amrex::EB_average_down(sol[falev], sol[falev-1], 0, ncomp, this->AMRRefRatioVect(falev-1));
2548 } else {
2549 amrex::Abort("EB_average_down only works with MultiFab");
2550 }
2551 } else
2552#endif
2553 {
2554 amrex::average_down(sol[falev], sol[falev-1], 0, ncomp, this->AMRRefRatioVect(falev-1));
2555 }
2556 }
2557}
2558
2559template <typename MF>
2560void
2561MLCellLinOpT<MF>::avgDownResAmr (int clev, MF& cres, MF const& fres) const
2562{
2563#ifdef AMREX_USE_EB
2564 if (!fres.isAllRegular()) {
2565 if constexpr (std::is_same<MF,MultiFab>()) {
2566 amrex::EB_average_down(fres, cres, 0, this->getNComp(),
2567 this->AMRRefRatioVect(clev));
2568 } else {
2569 amrex::Abort("EB_average_down only works with MultiFab");
2570 }
2571 } else
2572#endif
2573 {
2574 amrex::average_down(fres, cres, 0, this->getNComp(),
2575 this->AMRRefRatioVect(clev));
2576 }
2577}
2578
2579template <typename MF>
2580void
2582{
2583 this->m_precond_mode = true;
2584
2585 if (m_bndry_sol_zero.empty()) {
2586 m_bndry_sol_zero.resize(m_bndry_sol.size());
2587 const int ncomp = this->getNComp();
2588 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
2589 m_bndry_sol_zero[amrlev] = std::make_unique<MLMGBndryT<MF>>
2590 (this->m_grids[amrlev][0],
2591 this->m_dmap[amrlev][0],
2592 ncomp,
2593 this->m_geom[amrlev][0]);
2594 }
2595 std::swap(m_bndry_sol, m_bndry_sol_zero);
2596 MF const* coarse_data_for_bc_save = this->m_coarse_data_for_bc;
2597 this->m_coarse_data_for_bc = nullptr;
2598 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
2599 this->setLevelBC(amrlev, nullptr);
2600 }
2601 this->m_coarse_data_for_bc = coarse_data_for_bc_save;
2602 } else {
2603 std::swap(m_bndry_sol, m_bndry_sol_zero);
2604 }
2605}
2606
2607template <typename MF>
2608void
2610{
2611 this->m_precond_mode = false;
2612 std::swap(m_bndry_sol, m_bndry_sol_zero);
2613}
2614
2615extern template class MLCellLinOpT<MultiFab>;
2616#ifdef AMREX_MLMG_HAS_FLOAT
2617extern template class MLCellLinOpT<fMultiFab>;
2618#endif
2619
2621
2622}
2623
2624#endif
#define BL_TO_FORTRAN_BOX(x)
Definition AMReX_ArrayLim.H:51
#define BL_TO_FORTRAN_ANYD(x)
Definition AMReX_ArrayLim.H:44
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define BL_ASSERT(EX)
Definition AMReX_BLassert.H:39
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:123
#define AMREX_HOST_DEVICE_PARALLEL_FOR_3D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:110
#define AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE(TN, TI, block)
Definition AMReX_GpuLaunchMacrosC.nolint.H:4
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:111
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
void amrex_mllinop_apply_bc(const int *lo, const int *hi, amrex_real *phi, const int *philo, const int *phihi, const int *mask, const int *mlo, const int *mhi, int cdir, int bct, amrex_real bcl, const amrex_real *bcval, const int *blo, const int *bhi, int maxorder, const amrex_real *dxinv, int inhomog, int nc, int cross)
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Yet-another flux register for refluxing.
const FabSetT< MF > & bndryValues(Orientation face) const noexcept
Access the boundary values stored on orientation face.
Definition AMReX_BndryData.H:93
Maintain an identifier for boundary condition types.
Definition AMReX_BoundCond.H:25
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
void define(const Box &bx)
Initialize the BoxArray from a single box.
Definition AMReX_BoxArray.cpp:352
BoxArray & coarsen(int refinement_ratio)
Coarsen each Box in the BoxArray by refinement_ratio.
Definition AMReX_BoxArray.cpp:685
Long size() const noexcept
Return the number of boxes in the BoxArray.
Definition AMReX_BoxArray.H:758
A list of Boxes sharing a common IndexType.
Definition AMReX_BoxList.H:109
__host__ __device__ BoxND & setBig(const IntVectND< dim > &bg) noexcept
Redefine the big end of the BoxND.
Definition AMReX_Box.H:516
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:167
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
__host__ __device__ IntVectND< dim > size() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:160
__host__ __device__ BoxND & coarsen(int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition AMReX_Box.H:754
__host__ __device__ BoxND & refine(int ref_ratio) noexcept
Refine BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo*ratio...
Definition AMReX_Box.H:730
__host__ static __device__ BoxND TheUnitBox() noexcept
Definition AMReX_Box.H:783
__host__ __device__ const IntVectND< dim > & smallEnd() const &noexcept
Return the inclusive lower bound of the box.
Definition AMReX_Box.H:124
const Real * CellSize() const noexcept
Returns the cellsize for each coordinate direction.
Definition AMReX_CoordSys.H:79
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:55
Definition AMReX_EBFabFactory.H:32
IntVect nGrowVect() const noexcept
Definition AMReX_FabArrayBase.H:85
int nComp() const noexcept
Return number of variables (aka components) associated with each point.
Definition AMReX_FabArrayBase.H:88
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:383
void LocalCopy(FabArray< SFAB > const &src, int scomp, int dcomp, int ncomp, IntVect const &nghost)
Perform local copy of FabArray data.
Definition AMReX_FabArray.H:2333
MultiArray4< typename FabArray< FAB >::value_type const > const_arrays() const noexcept
Read-only convenience wrapper equivalent to arrays() const.
Definition AMReX_FabArray.H:759
void setVal(value_type val)
Set all components in the entire region of each FAB to val.
Definition AMReX_FabArray.H:3068
Array4< typename FabArray< FAB >::value_type const > const_array(const MFIter &mfi) const noexcept
Synonym for array(const MFIter&) that highlights read-only semantics.
Definition AMReX_FabArray.H:677
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:87
Periodicity periodicity() const noexcept
Return the Periodicity based on the length of the domain.
Definition AMReX_Geometry.H:426
const Real * ProbLo() const noexcept
Returns the lo end of the problem domain in each dimension.
Definition AMReX_Geometry.H:210
GPU-compatible tuple.
Definition AMReX_Tuple.H:104
__host__ __device__ constexpr bool allGT(const IntVectND< dim > &rhs) const noexcept
Returns true if this is greater than argument for all components. NOTE: This is NOT a strict weak ord...
Definition AMReX_IntVect.H:524
__host__ static __device__ constexpr IntVectND< dim > TheCellVector() noexcept
Definition AMReX_IntVect.H:839
__host__ __device__ constexpr int max() const noexcept
maximum (no absolute values) value
Definition AMReX_IntVect.H:320
static constexpr int IBD_max_order_DEF
Definition AMReX_InterpBndryData.H:143
a one-thingy-per-box distributed object
Definition AMReX_LayoutData.H:13
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:176
Definition AMReX_MLCellLinOp.H:31
virtual void Fsmooth(int amrlev, int mglev, MultiFab &sol, const MultiFab &rhs, int redblack) const=0
Vector< RT > getSolvabilityOffset(int amrlev, int mglev, MultiFab const &rhs) const override
void averageDownSolutionRHS(int camrlev, MF &crse_sol, MF &crse_rhs, const MF &fine_sol, const MF &fine_rhs) override
Average fine solution/RHS onto the next coarser AMR level.
Definition AMReX_MLCellLinOp.H:1581
void averageDownAndSync(Vector< MF > &sol) const override
Average the solution hierarchy down (fine-to-coarse) and sync.
Definition AMReX_MLCellLinOp.H:2539
void smooth(int amrlev, int mglev, MF &sol, const MF &rhs, bool skip_fillboundary, int niter) const override
Perform niter smoothing iterations on the supplied residual equation.
Definition AMReX_MLCellLinOp.H:1602
BoxArray makeNGrids(int grid_size) const
Helper that builds a BoxArray for NSolve with boxes no larger than the requested grid_size.
Definition AMReX_MLCellLinOp.H:1252
Vector< YAFluxRegisterT< MultiFab > > m_fluxreg
Definition AMReX_MLCellLinOp.H:516
virtual void applyBC(int amrlev, int mglev, MF &in, BCMode bc_mode, StateMode s_mode, const MLMGBndryT< MF > *bndry=nullptr, bool skip_fillboundary=false) const
Apply physical BCs (optionally skipping FillBoundary).
Definition AMReX_MLCellLinOp.H:1032
void updateSolBC(int amrlev, const MF &crse_bcdata) const
Refresh stored solution BC data from coarse inputs.
Definition AMReX_MLCellLinOp.H:1001
Vector< std::unique_ptr< MLMGBndryT< MultiFab > > > m_bndry_sol
Definition AMReX_MLCellLinOp.H:456
MLCellLinOpT< MF > & operator=(const MLCellLinOpT< MF > &)=delete
void compGrad(int amrlev, const Array< MultiFab *, 3 > &grad, MultiFab &sol, Location loc) const override
void avgDownResAmr(int clev, MF &cres, MF const &fres) const override
Average a residual from a fine AMR level to its coarse parent.
Definition AMReX_MLCellLinOp.H:2561
void reflux(int crse_amrlev, MultiFab &res, const MultiFab &crse_sol, const MultiFab &, MultiFab &, MultiFab &fine_sol, const MultiFab &) const final
RT dotProductPrecond(Vector< MultiFab const * > const &x, Vector< MultiFab const * > const &y) const final
virtual void Fapply(int amrlev, int mglev, MultiFab &out, const MultiFab &in) const=0
typename FabDataType< MF >::value_type RT
Definition AMReX_MLCellLinOp.H:35
void endPrecondBC() override
Called when the operator stops being used as a preconditioner.
Definition AMReX_MLCellLinOp.H:2609
void update() override
Update for reuse.
Definition AMReX_MLCellLinOp.H:994
LinOpBCType BCType
Definition AMReX_MLCellLinOp.H:37
void correctionResidual(int amrlev, int mglev, MF &resid, MF &x, const MF &b, BCMode bc_mode, const MF *crse_bcdata=nullptr) final
Compute the correction residual with optional coarse data.
Definition AMReX_MLCellLinOp.H:1646
MLCellLinOpT(const MLCellLinOpT< MF > &)=delete
typename MLLinOpT< MF >::BCMode BCMode
Definition AMReX_MLCellLinOp.H:38
RT normInf(int amrlev, MF const &mf, bool local) const override
Infinity norm helper used by solvers and diagnostics.
Definition AMReX_MLCellLinOp.H:2435
virtual bool isCrossStencil() const
Whether the stencil is the cross shape.
Definition AMReX_MLCellLinOp.H:114
void updateCorBC(int amrlev, const MF &crse_bcdata) const
Refresh stored correction BC data from coarse inputs.
Definition AMReX_MLCellLinOp.H:1017
Array< RT, 2 *3 > RealTuple
Definition AMReX_MLCellLinOp.H:467
void interpolation(int amrlev, int fmglev, MF &fine, const MF &crse) const override
Add the prolongation of coarse data onto the fine grid (fine += prolong(crse)).
Definition AMReX_MLCellLinOp.H:1314
RT xdoty(int amrlev, int mglev, const MultiFab &x, const MultiFab &y, bool local) const final
Array< BoundCond, 2 *3 > BCTuple
Definition AMReX_MLCellLinOp.H:468
void unapplyMetricTerm(int amrlev, int mglev, MultiFab &rhs) const final
void apply(int amrlev, int mglev, MF &out, MF &in, BCMode bc_mode, StateMode s_mode, const MLMGBndryT< MF > *bndry=nullptr) const override
Apply the linear operator with boundary conditions.
Definition AMReX_MLCellLinOp.H:1592
void applyMetricTerm(int amrlev, int mglev, MultiFab &rhs) const final
Vector< std::unique_ptr< BndryRegisterT< MultiFab > > > m_crse_cor_br
Definition AMReX_MLCellLinOp.H:460
RT norm2Precond(Vector< MultiFab const * > const &x) const final
void beginPrecondBC() override
Called when the operator starts being used as a preconditioner.
Definition AMReX_MLCellLinOp.H:2581
Vector< Vector< std::unique_ptr< BndryCondLoc > > > m_bcondloc
Definition AMReX_MLCellLinOp.H:506
void restriction(int amrlev, int cmglev, MF &crse, MF &fine) const override
Restrict a fine-grid field onto its coarse counterpart.
Definition AMReX_MLCellLinOp.H:1302
void setGaussSeidel(bool flag) noexcept
Toggle Gauss–Seidel smoothing in place of Jacobi relaxation.
Definition AMReX_MLCellLinOp.H:104
Vector< std::unique_ptr< MultiFab > > m_robin_bcval
Definition AMReX_MLCellLinOp.H:430
void define(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const LPInfo &a_info=LPInfo(), const Vector< FabFactory< FAB > const * > &a_factory={})
Bind the operator to an AMR hierarchy.
Definition AMReX_MLCellLinOp.H:668
~MLCellLinOpT() override=default
virtual bool isTensorOp() const
Whether this operator is a tensor solve.
Definition AMReX_MLCellLinOp.H:116
void setInterpBndryHalfWidth(int w)
Control how many cells the interpolation boundary stencil spans.
Definition AMReX_MLCellLinOp.H:437
Vector< Vector< BndryRegisterT< MultiFab > > > m_undrrelxr
Definition AMReX_MLCellLinOp.H:509
MLCellLinOpT()
Definition AMReX_MLCellLinOp.H:661
MLCellLinOpT(MLCellLinOpT< MF > &&)=delete
typename FabDataType< MF >::fab_type FAB
Definition AMReX_MLCellLinOp.H:34
void interpAssign(int amrlev, int fmglev, MF &fine, MF &crse) const override
Overwrite fine data with the prolongation of coarse data (fine = prolong(crse)).
Definition AMReX_MLCellLinOp.H:1364
void fixSolvabilityByOffset(int amrlev, int mglev, MultiFab &rhs, Vector< RT > const &offset) const override
Vector< std::unique_ptr< MLMGBndryT< MultiFab > > > m_bndry_cor
Definition AMReX_MLCellLinOp.H:459
void compFlux(int amrlev, const Array< MultiFab *, 3 > &fluxes, MultiFab &sol, Location loc) const override
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLCellLinOp.H:40
void prepareForFluxes(int amrlev, const MF *crse_bcdata=nullptr) override
Ensure BC caches are ready for flux computations (e.g., getFluxes).
Definition AMReX_MLCellLinOp.H:1637
void solutionResidual(int amrlev, MF &resid, MF &x, const MF &b, const MF *crse_bcdata=nullptr) override
Compute the residual resid = b - A(x) using solution boundary data.
Definition AMReX_MLCellLinOp.H:1619
bool m_has_metric_term
Definition AMReX_MLCellLinOp.H:454
bool m_use_gauss_seidel
Definition AMReX_MLCellLinOp.H:518
Vector< std::unique_ptr< MLMGBndryT< MultiFab > > > m_bndry_sol_zero
Definition AMReX_MLCellLinOp.H:462
Vector< std::unique_ptr< BndryRegisterT< MultiFab > > > m_crse_sol_br
Definition AMReX_MLCellLinOp.H:457
void interpolationAmr(int famrlev, MF &fine, const MF &crse, IntVect const &nghost) const override
Prolong AMR-level data during FMG initialization.
Definition AMReX_MLCellLinOp.H:1460
virtual void addInhomogNeumannFlux(int, const Array< MultiFab *, 3 > &, MultiFab const &, bool) const
Definition AMReX_MLCellLinOp.H:388
Vector< std::unique_ptr< iMultiFab > > m_norm_fine_mask
Definition AMReX_MLCellLinOp.H:514
void spCopySettings() override
Definition AMReX_MLCellLinOp.H:447
typename MLLinOpT< MF >::StateMode StateMode
Definition AMReX_MLCellLinOp.H:39
void setLevelBC(int amrlev, const MF *levelbcdata, const MF *robinbc_a=nullptr, const MF *robinbc_b=nullptr, const MF *robinbc_f=nullptr) final
Provide per-level inhomogeneous boundary data.
Definition AMReX_MLCellLinOp.H:832
bool needsUpdate() const override
Does it need update if it's reused?
Definition AMReX_MLCellLinOp.H:93
Vector< Vector< Array< MultiMask, 2 *3 > > > m_maskvals
Definition AMReX_MLCellLinOp.H:512
virtual void FFlux(int amrlev, const MFIter &mfi, const Array< FAB *, 3 > &flux, const FAB &sol, Location loc, int face_only=0) const=0
const MF * m_coarse_data_for_bc
Definition AMReX_MLLinOp.H:1039
Vector< Vector< std::unique_ptr< FabFactory< FAB > > > > m_factory
Definition AMReX_MLLinOp.H:1010
int NAMRLevels() const noexcept
Return the number of AMR levels.
Definition AMReX_MLLinOp.H:951
IntVect m_ixtype
Definition AMReX_MLLinOp.H:998
RealVect m_coarse_bc_loc
Definition AMReX_MLLinOp.H:1038
virtual bool needsUpdate() const
Does it need update if it's reused?
Definition AMReX_MLLinOp.H:390
virtual void applyOverset(int amrlev, MF &rhs) const
Overset-only hook for zeroing regions covered by masks.
Definition AMReX_MLLinOp.H:647
FabFactory< FAB > const * Factory(int amr_lev, int mglev=0) const noexcept
Definition AMReX_MLLinOp.H:1209
LinOpEnumType::StateMode StateMode
Definition AMReX_MLLinOp.H:173
Array< Real, 3 > m_domain_bloc_hi
Definition AMReX_MLLinOp.H:1033
virtual void spCopySettings()
Definition AMReX_MLLinOp.H:1165
bool hasRobinBC() const noexcept
Definition AMReX_MLLinOp.H:2061
Vector< Array< BCType, 3 > > m_hibc
Definition AMReX_MLLinOp.H:966
virtual int getNComp() const
Return number of components.
Definition AMReX_MLLinOp.H:385
IntVect m_coarse_data_crse_ratio
Definition AMReX_MLLinOp.H:1037
Vector< Array< BCType, 3 > > m_hibc_orig
Definition AMReX_MLLinOp.H:970
bool needsCoarseDataForBC() const noexcept
Needs coarse data for bc?
Definition AMReX_MLLinOp.H:249
virtual void update()
Update for reuse.
Definition AMReX_MLLinOp.H:392
Vector< Array< BCType, 3 > > m_lobc_orig
Definition AMReX_MLLinOp.H:969
bool m_precond_mode
Definition AMReX_MLLinOp.H:1042
bool hasHiddenDimension() const noexcept
Definition AMReX_MLLinOp.H:1293
virtual bool supportsAnisotropicCoarsening() const
True if the operator supports MG levels coarsened in any subset of directions. Then MLMG coarsens str...
Definition AMReX_MLLinOp.H:823
const Geometry & Geom(int amr_lev, int mglev=0) const noexcept
Geometry accessor for (amr_lev,mglev).
Definition AMReX_MLLinOp.H:962
int hiddenDirection() const noexcept
Definition AMReX_MLLinOp.H:1294
Vector< Array< BCType, 3 > > m_lobc
Definition AMReX_MLLinOp.H:965
Vector< Vector< Geometry > > m_geom
first Vector is for amr level and second is mg level
Definition AMReX_MLLinOp.H:1007
Box compactify(Box const &b) const noexcept
Definition AMReX_MLLinOp.H:2068
Real m_sp_length_scale
Definition AMReX_MLLinOp.H:1065
int maxorder
Definition AMReX_MLLinOp.H:986
void define(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const LPInfo &a_info, const Vector< FabFactory< FAB > const * > &a_factory, bool eb_limit_coarsening=true)
Initialize the operator hierarchy on a set of AMR levels.
Definition AMReX_MLLinOp.H:1356
Vector< IntVect > mg_coarsen_ratio_vec
Definition AMReX_MLLinOp.H:1004
LinOpEnumType::Location Location
Definition AMReX_MLLinOp.H:174
LinOpEnumType::BCMode BCMode
Definition AMReX_MLLinOp.H:172
static constexpr bool mixed_precision_capable
Definition AMReX_MLLinOp.H:1047
LinOpBCType m_coarse_fine_bc_type
Definition AMReX_MLLinOp.H:1036
Array< Real, 3 > m_domain_bloc_lo
Definition AMReX_MLLinOp.H:1032
std::unique_ptr< MLLinOpT< fMultiFab > > m_sp_linop
Definition AMReX_MLLinOp.H:1053
friend class MLLinOpT
Definition AMReX_MLLinOp.H:159
IntVect AMRRefRatioVect(int amr_lev) const noexcept
Return AMR refinement ratio as IntVect (1 in hidden direction).
Definition AMReX_MLLinOp.H:1203
int m_num_amr_levels
Definition AMReX_MLLinOp.H:992
Boundary helper for MLMG that manages coarse/fine and physical BC metadata.
Definition AMReX_MLMGBndry.H:20
static void setBoxBC(RealTuple &bloc, BCTuple &bctag, const Box &bx, const Box &domain, const Array< LinOpBCType, 3 > &lo, const Array< LinOpBCType, 3 > &hi, const Real *dx, IntVect const &ratio, const RealVect &interior_bloc, const Array< Real, 3 > &domain_bloc_lo, const Array< Real, 3 > &domain_bloc_hi, const GpuArray< int, 3 > &is_periodic, LinOpBCType a_crse_fine_bc_type)
Helper that sets up BC tuples for a single box.
Definition AMReX_MLMGBndry.H:163
Definition AMReX_Mask.H:33
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
An Iterator over the Orientation of Faces of a Box.
Definition AMReX_Orientation.H:135
Encapsulation of the Orientation of the Faces of a Box.
Definition AMReX_Orientation.H:29
@ low
Definition AMReX_Orientation.H:34
@ high
Definition AMReX_Orientation.H:34
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Checks if a type is amrex::MultiFab-like (i.e., FabArray<FAB>, where FAB is a BaseFabType).
Definition AMReX_Concepts.H:26
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
ArrayND< T, 4, true > Array4
Convenient alias for a 4D ArrayND with three spatial dimensions plus a component dimension.
Definition AMReX_Array4.H:1352
@ singlevalued
No multivalued cells; not entirely regular or covered.
Definition AMReX_FabFactory.H:30
@ covered
Every cell in the region is covered.
Definition AMReX_FabFactory.H:28
@ regular
Every cell in the region is regular.
Definition AMReX_FabFactory.H:29
__host__ __device__ BoxND< dim > adjCellHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the high end along coordinate direction dir.
Definition AMReX_Box.H:1850
__host__ __device__ BoxND< dim > adjCellLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the low end along coordinate direction dir.
Definition AMReX_Box.H:1819
__host__ __device__ BoxND< dim > surroundingNodes(const BoxND< dim > &b, int dir) noexcept
Return a BoxND with NODE based coordinates in direction dir that encloses BoxND b.
Definition AMReX_Box.H:1584
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b coarsened by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1471
__host__ __device__ BoxND< dim > adjCell(const BoxND< dim > &b, Orientation face, int len=1) noexcept
Similar to adjCellLo and adjCellHi except that it operates on the given face of BoxND b.
Definition AMReX_Box.H:1882
__host__ __device__ BoxND< dim > shift(const BoxND< dim > &b, int dir, int nzones) noexcept
Return a copy of b shifted by nzones cells in direction dir.
Definition AMReX_Box.H:1550
__host__ __device__ BoxND< dim > grow(const BoxND< dim > &b, int i) noexcept
Return a copy of b grown uniformly by i cells in every direction.
Definition AMReX_Box.H:1328
PODVector< T, PinnedArenaAllocator< T > > PinnedVector
A PODVector that uses the pinned memory arena.
Definition AMReX_GpuContainers.H:48
std::array< T, N > Array
Definition AMReX_Array.H:31
PODVector< T, ArenaAllocator< T > > DeviceVector
A PODVector that uses the standard memory Arena. Note that the memory might or might not be managed d...
Definition AMReX_GpuContainers.H:24
Arena * The_Async_Arena()
Definition AMReX_Arena.cpp:849
void Sum(Gpu::DeviceVector< T > &v, MPI_Comm comm)
Definition AMReX_GpuParallelReduce.H:37
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:133
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
A host-to-device copy routine. Note this is just a wrapper around memcpy, so it assumes contiguous st...
Definition AMReX_GpuContainers.H:228
static constexpr HostToDevice hostToDevice
Definition AMReX_GpuContainers.H:105
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:329
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:89
bool inNoSyncRegion() noexcept
Definition AMReX_GpuControl.H:148
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:273
__host__ __device__ T norm(const GpuComplex< T > &a_z) noexcept
Return the norm (magnitude squared) of a complex number.
Definition AMReX_GpuComplex.H:349
ReduceData< Ts... >::Type ParReduce(TypeList< Ops... > operation_list, TypeList< Ts... > type_list, FabArray< FAB > const &fa, IntVect const &nghost, F &&f)
Parallel reduce for MultiFab/FabArray. The reduce result is local and it's the user's responsibility ...
Definition AMReX_ParReduce.H:48
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
@ zero
Definition AMReX.H:560
@ Gpu
Definition AMReX_GpuControl.H:65
iMultiFab makeFineMask(const BoxArray &cba, const DistributionMapping &cdm, const BoxArray &fba, const IntVect &ratio, int crse_value, int fine_value, MFInfo const &info)
Definition AMReX_MultiFabUtil.cpp:655
void EB_set_covered(MultiFab &mf, Real val)
Fill all covered cells with a single value val.
Definition AMReX_EBMultiFabUtil.cpp:21
FAB::value_type Dot(FabArray< FAB > const &x, int xcomp, FabArray< FAB > const &y, int ycomp, int ncomp, IntVect const &nghost, bool local=false)
Compute dot products of two FabArrays.
Definition AMReX_FabArrayUtility.H:1906
void ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
bool isMFIterSafe(const FabArrayBase &x, const FabArrayBase &y)
Definition AMReX_MFIter.H:256
LinOpBCType
Definition AMReX_LO_BCTYPES.H:27
@ Robin
Definition AMReX_LO_BCTYPES.H:36
@ Dirichlet
Definition AMReX_LO_BCTYPES.H:29
void EB_average_down(const MultiFab &S_fine, MultiFab &S_crse, const MultiFab &vol_fine, const MultiFab &vfrac_fine, int scomp, int ncomp, const IntVect &ratio)
Volume-weighted average-down from fine to coarse using EB volume fractions.
Definition AMReX_EBMultiFabUtil.cpp:336
@ y
Definition AMReX_Orientation.H:14
@ x
Definition AMReX_Orientation.H:14
FabArray< BaseFab< float > > fMultiFab
Definition AMReX_MultiFab.H:19
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
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
RealVectND< 3 > RealVect
Definition AMReX_ParmParse.H:40
MLCellLinOpT< MultiFab > MLCellLinOp
Definition AMReX_MLCellLinOp.H:2620
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get the Idx-th element of IntVectND<dim>.
Definition AMReX_IntVect.H:1367
A simple struct holding 3 int values for a 3D index.
Definition AMReX_Dim3.H:24
int x
Definition AMReX_Dim3.H:24
int z
Definition AMReX_Dim3.H:24
int y
Definition AMReX_Dim3.H:24
Type trait specialized for MultiFab-like types and their containers.
Definition AMReX_FabDataType.H:16
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52
Configuration knobs for multilevel linear operators (grid agglomeration, metrics, etc....
Definition AMReX_MLLinOp.H:54
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
Definition AMReX_MFIter.H:20
MFItInfo & SetDynamic(bool f) noexcept
Definition AMReX_MFIter.H:43
MFItInfo & EnableTiling(const IntVect &ts=FabArrayBase::mfiter_tile_size) noexcept
Definition AMReX_MFIter.H:31
Definition AMReX_MLCellLinOp.H:26
Definition AMReX_FabArray.H:195
Struct for holding types.
Definition AMReX_TypeList.H:13