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
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
42 MLCellLinOpT ();
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 { m_use_gauss_seidel = flag; }
105
107 virtual bool isCrossStencil () const { return true; }
109 virtual bool isTensorOp () const { return false; }
110
117 void updateSolBC (int amrlev, const MF& crse_bcdata) const;
124 void updateCorBC (int amrlev, const MF& crse_bcdata) const;
125
137 virtual void applyBC (int amrlev, int mglev, MF& in, BCMode bc_mode, StateMode s_mode,
138 const MLMGBndryT<MF>* bndry=nullptr, bool skip_fillboundary=false) const;
139
141 BoxArray makeNGrids (int grid_size) const;
142
151 void restriction (int amrlev, int cmglev, MF& crse, MF& fine) const override;
152
162 void interpolation (int amrlev, int fmglev, MF& fine, const MF& crse) const override;
163
173 void interpAssign (int amrlev, int fmglev, MF& fine, MF& crse) const override;
174
184 void interpolationAmr (int famrlev, MF& fine, const MF& crse,
185 IntVect const& nghost) const override;
186
196 void averageDownSolutionRHS (int camrlev, MF& crse_sol, MF& crse_rhs,
197 const MF& fine_sol, const MF& fine_rhs) override;
198
210 void apply (int amrlev, int mglev, MF& out, MF& in, BCMode bc_mode,
211 StateMode s_mode, const MLMGBndryT<MF>* bndry=nullptr) const override;
222 void smooth (int amrlev, int mglev, MF& sol, const MF& rhs,
223 bool skip_fillboundary, int niter) const final;
224
234 void solutionResidual (int amrlev, MF& resid, MF& x, const MF& b,
235 const MF* crse_bcdata=nullptr) override;
236
243 void prepareForFluxes (int amrlev, const MF* crse_bcdata = nullptr) override;
244
256 void correctionResidual (int amrlev, int mglev, MF& resid, MF& x, const MF& b,
257 BCMode bc_mode, const MF* crse_bcdata=nullptr) final;
258
272 void reflux (int crse_amrlev,
273 MF& res, const MF& crse_sol, const MF&,
274 MF&, MF& fine_sol, const MF&) const final;
283 void compFlux (int amrlev, const Array<MF*,AMREX_SPACEDIM>& fluxes,
284 MF& sol, Location loc) const override;
293 void compGrad (int amrlev, const Array<MF*,AMREX_SPACEDIM>& grad,
294 MF& sol, Location loc) const override;
295
303 void applyMetricTerm (int amrlev, int mglev, MF& rhs) const final;
311 void unapplyMetricTerm (int amrlev, int mglev, MF& rhs) const final;
320 Vector<RT> getSolvabilityOffset (int amrlev, int mglev,
321 MF const& rhs) const override;
330 void fixSolvabilityByOffset (int amrlev, int mglev, MF& rhs,
331 Vector<RT> const& offset) const override;
332
334 void prepareForSolve () override;
335
346 RT xdoty (int amrlev, int mglev, const MF& x, const MF& y, bool local) const final;
347
356 RT dotProductPrecond (Vector<MF const*> const& x, Vector<MF const*> const& y) const final;
357
365 RT norm2Precond (Vector<MF const*> const& x) const final;
366
367 virtual void Fapply (int amrlev, int mglev, MF& out, const MF& in) const = 0;
368 virtual void Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, int redblack) const = 0;
369 virtual void FFlux (int amrlev, const MFIter& mfi,
370 const Array<FAB*,AMREX_SPACEDIM>& flux,
371 const FAB& sol, Location loc, int face_only=0) const = 0;
372
381 virtual void addInhomogNeumannFlux (int /*amrlev*/,
382 const Array<MF*,AMREX_SPACEDIM>& /*grad*/,
383 MF const& /*sol*/,
384 bool /*mult_bcoef*/) const {}
385
393 RT normInf (int amrlev, MF const& mf, bool local) const override;
394
400 void averageDownAndSync (Vector<MF>& sol) const override;
401
409 void avgDownResAmr (int clev, MF& cres, MF const& fres) const override;
410
412 void beginPrecondBC () override;
414 void endPrecondBC () override;
415
417 struct BCTL {
418 BoundCond type;
419 RT location;
420 };
422
424
430 void setInterpBndryHalfWidth (int w) { m_interpbndry_halfwidth = w; }
431
432protected:
433
434 bool m_has_metric_term = false;
435
438
441
443
444 // In case of agglomeration, coarse MG grids on amr level 0 are
445 // not simply coarsened from fine MG grids. So we need to build
446 // bcond and bcloc for each MG level.
450 class BndryCondLoc
451 {
452 public:
453 BndryCondLoc (const BoxArray& ba, const DistributionMapping& dm, int ncomp);
454
455 void setLOBndryConds (const Geometry& geom, const Real* dx,
458 IntVect const& ratio, const RealVect& interior_bloc,
459 const Array<Real,AMREX_SPACEDIM>& domain_bloc_lo,
460 const Array<Real,AMREX_SPACEDIM>& domain_bloc_hi,
461 LinOpBCType crse_fine_bc_type);
462
463 const Vector<BCTuple>& bndryConds (const MFIter& mfi) const noexcept {
464 return bcond[mfi];
465 }
466 const Vector<RealTuple>& bndryLocs (const MFIter& mfi) const noexcept {
467 return bcloc[mfi];
468 }
469 const BCTuple& bndryConds (const MFIter& mfi, int icomp) const noexcept {
470 return bcond[mfi][icomp];
471 }
472 const RealTuple& bndryLocs (const MFIter& mfi, int icomp) const noexcept {
473 return bcloc[mfi][icomp];
474 }
475 GpuArray<BCTL,2*AMREX_SPACEDIM> const* getBCTLPtr (const MFIter& mfi) const noexcept {
476 return bctl[mfi];
477 }
478 private:
483 int m_ncomp;
484 };
487
488 // used to save interpolation coefficients of the first interior cells
490
491 // boundary cell flags for covered, not_covered, outside_domain
493
495
497
498 bool m_use_gauss_seidel = true; // use red-black Gauss-Seidel by default
499
500private:
501
502 void defineAuxData ();
503 void defineBC ();
504
505 void computeVolInv () const;
506 mutable Vector<Vector<RT> > m_volinv; // used by solvability fix
507
508 int m_interpbndry_halfwidth = 2;
509
510 mutable Vector<Vector<TagVector<MLMGABCTag<RT>>>> m_bc_tags;
511};
512
514
515template <typename T>
516struct MLMGABCTag {
518 T bcloc;
519 Box bx;
520 BoundCond bctype;
521 int blen;
522 int comp;
523 Orientation face;
524 int local_index;
525
527 Box const& box() const noexcept { return bx; }
528};
529
530template <typename T>
531struct MLMGPSTag {
532 Array4<T> flo;
533 Array4<T> fhi;
534 Array4<int const> mlo;
535 Array4<int const> mhi;
536 T bcllo;
537 T bclhi;
538 Box bx;
539 BoundCond bctlo;
540 BoundCond bcthi;
541 int blen;
542 int comp;
543 int dir;
544
546 Box const& box() const noexcept { return bx; }
547};
548
549#ifdef AMREX_USE_EB
550template <typename T>
551struct MLMGPSEBTag {
552 Array4<T> flo;
553 Array4<T> fhi;
554 Array4<T const> ap;
555 Array4<int const> mlo;
556 Array4<int const> mhi;
557 T bcllo;
558 T bclhi;
559 Box bx;
560 BoundCond bctlo;
561 BoundCond bcthi;
562 int blen;
563 int comp;
564 int dir;
565
567 Box const& box() const noexcept { return bx; }
568};
569#endif
570
571template <typename MF>
572MLCellLinOpT<MF>::BndryCondLoc::BndryCondLoc (const BoxArray& ba,
573 const DistributionMapping& dm,
574 int ncomp)
575 : bcond(ba, dm),
576 bcloc(ba, dm),
577 bctl(ba, dm),
578 bctl_dv(bctl.local_size()*ncomp),
579 m_ncomp(ncomp)
580{
581 auto* dp = bctl_dv.data();
582 for (MFIter mfi(bcloc); mfi.isValid(); ++mfi) {
583 bcond[mfi].resize(ncomp);
584 bcloc[mfi].resize(ncomp);
585 bctl[mfi] = dp;
586 dp += ncomp;
587 }
588}
589
590template <typename MF>
591void
592MLCellLinOpT<MF>::BndryCondLoc::
593setLOBndryConds (const Geometry& geom, const Real* dx,
594 const Vector<Array<BCType,AMREX_SPACEDIM> >& lobc,
595 const Vector<Array<BCType,AMREX_SPACEDIM> >& hibc,
596 IntVect const& ratio, const RealVect& interior_bloc,
597 const Array<Real,AMREX_SPACEDIM>& domain_bloc_lo,
598 const Array<Real,AMREX_SPACEDIM>& domain_bloc_hi,
599 LinOpBCType crse_fine_bc_type)
600{
601 const Box& domain = geom.Domain();
602
603#ifdef AMREX_USE_OMP
604#pragma omp parallel
605#endif
606 for (MFIter mfi(bcloc); mfi.isValid(); ++mfi)
607 {
608 const Box& bx = mfi.validbox();
609 for (int icomp = 0; icomp < m_ncomp; ++icomp) {
610 RealTuple & bloc = bcloc[mfi][icomp];
611 BCTuple & bctag = bcond[mfi][icomp];
612 MLMGBndryT<MF>::setBoxBC(bloc, bctag, bx, domain,
613 lobc[icomp], hibc[icomp],
614 dx, ratio, interior_bloc,
615 domain_bloc_lo, domain_bloc_hi,
616 geom.isPeriodicArray(),
617 crse_fine_bc_type);
618 }
619 }
620
621 Gpu::PinnedVector<GpuArray<BCTL,2*AMREX_SPACEDIM> > hv;
622 hv.reserve(bctl_dv.size());
623 for (MFIter mfi(bctl); mfi.isValid(); ++mfi)
624 {
625 for (int icomp = 0; icomp < m_ncomp; ++icomp) {
626 GpuArray<BCTL,2*AMREX_SPACEDIM> tmp;
627 for (int m = 0; m < 2*AMREX_SPACEDIM; ++m) {
628 tmp[m].type = bcond[mfi][icomp][m];
629 tmp[m].location = bcloc[mfi][icomp][m];
630 }
631 hv.push_back(std::move(tmp));
632 }
633 }
634 Gpu::copyAsync(Gpu::hostToDevice, hv.begin(), hv.end(), bctl_dv.begin());
636}
637
639
640template <typename MF>
642{
643 this->m_ixtype = IntVect::TheCellVector();
644}
645
646template <typename MF>
647void
649 const Vector<BoxArray>& a_grids,
650 const Vector<DistributionMapping>& a_dmap,
651 const LPInfo& a_info,
652 const Vector<FabFactory<FAB> const*>& a_factory)
653{
654 MLLinOpT<MF>::define(a_geom, a_grids, a_dmap, a_info, a_factory);
655 defineAuxData();
656 defineBC();
657}
658
659template <typename MF>
660void
662{
663 BL_PROFILE("MLCellLinOp::defineAuxData()");
664
665 m_undrrelxr.resize(this->m_num_amr_levels);
666 m_maskvals.resize(this->m_num_amr_levels);
667 m_fluxreg.resize(this->m_num_amr_levels-1);
668 m_norm_fine_mask.resize(this->m_num_amr_levels-1);
669 m_bc_tags.resize(this->m_num_amr_levels);
670
671 const int ncomp = this->getNComp();
672
673 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
674 {
675 m_undrrelxr[amrlev].resize(this->m_num_mg_levels[amrlev]);
676 m_bc_tags[amrlev].resize(this->m_num_mg_levels[amrlev]);
677 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
678 {
679 m_undrrelxr[amrlev][mglev].define(this->m_grids[amrlev][mglev],
680 this->m_dmap[amrlev][mglev],
681 1, 0, 0, ncomp);
682 }
683 }
684
685 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
686 {
687 m_maskvals[amrlev].resize(this->m_num_mg_levels[amrlev]);
688 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
689 {
690 for (OrientationIter oitr; oitr; ++oitr)
691 {
692 const Orientation face = oitr();
693 const int ngrow = 1;
694 const int extent = this->isCrossStencil() ? 0 : 1; // extend to corners
695 m_maskvals[amrlev][mglev][face].define(this->m_grids[amrlev][mglev],
696 this->m_dmap[amrlev][mglev],
697 this->m_geom[amrlev][mglev],
698 face, 0, ngrow, extent, 1, true);
699 }
700 }
701 }
702
703 for (int amrlev = 0; amrlev < this->m_num_amr_levels-1; ++amrlev)
704 {
705 const IntVect ratio{this->AMRRefRatioVect(amrlev)};
706 m_fluxreg[amrlev].define(this->m_grids[amrlev+1][0],
707 this->m_grids[amrlev][0],
708 this->m_dmap[amrlev+1][0],
709 this->m_dmap[amrlev][0],
710 this->m_geom[amrlev+1][0],
711 this->m_geom[amrlev][0],
712 ratio, amrlev+1, ncomp);
713 m_fluxreg[amrlev].setDeterministic(this->info.deterministic);
714 m_norm_fine_mask[amrlev] = std::make_unique<iMultiFab>
715 (makeFineMask(this->m_grids[amrlev][0], this->m_dmap[amrlev][0],
716 this->m_grids[amrlev+1][0],
717 ratio, 1, 0));
718 }
719
720#if (AMREX_SPACEDIM != 3)
721 m_has_metric_term = !this->m_geom[0][0].IsCartesian() && this->info.has_metric_term;
722#endif
723}
724
725template <typename MF>
726void
727MLCellLinOpT<MF>::defineBC ()
728{
729 BL_PROFILE("MLCellLinOp::defineBC()");
730
731 const int ncomp = this->getNComp();
732
733 m_bndry_sol.resize(this->m_num_amr_levels);
734 m_crse_sol_br.resize(this->m_num_amr_levels);
735
736 m_bndry_cor.resize(this->m_num_amr_levels);
737 m_crse_cor_br.resize(this->m_num_amr_levels);
738
739 m_robin_bcval.resize(this->m_num_amr_levels);
740
741 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
742 {
743 m_bndry_sol[amrlev] = std::make_unique<MLMGBndryT<MF>>(this->m_grids[amrlev][0],
744 this->m_dmap[amrlev][0],
745 ncomp,
746 this->m_geom[amrlev][0]);
747 }
748
749 for (int amrlev = 1; amrlev < this->m_num_amr_levels; ++amrlev)
750 {
751 const int in_rad = 0;
752 const int out_rad = 1;
753 const int extent_rad = 2;
754 const IntVect crse_ratio = this->AMRRefRatioVect(amrlev-1);
755 BoxArray cba = this->m_grids[amrlev][0];
756 cba.coarsen(crse_ratio);
757 m_crse_sol_br[amrlev] = std::make_unique<BndryRegisterT<MF>>
758 (cba, this->m_dmap[amrlev][0], in_rad, out_rad, extent_rad, ncomp);
759 }
760
761 for (int amrlev = 1; amrlev < this->m_num_amr_levels; ++amrlev)
762 {
763 const int in_rad = 0;
764 const int out_rad = 1;
765 const int extent_rad = 2;
766 const IntVect crse_ratio = this->AMRRefRatioVect(amrlev-1);
767 BoxArray cba = this->m_grids[amrlev][0];
768 cba.coarsen(crse_ratio);
769 m_crse_cor_br[amrlev] = std::make_unique<BndryRegisterT<MF>>
770 (cba, this->m_dmap[amrlev][0], in_rad, out_rad, extent_rad, ncomp);
771 m_crse_cor_br[amrlev]->setVal(RT(0.0));
772 }
773
774 // This has be to done after m_crse_cor_br is defined.
775 for (int amrlev = 1; amrlev < this->m_num_amr_levels; ++amrlev)
776 {
777 m_bndry_cor[amrlev] = std::make_unique<MLMGBndryT<MF>>
778 (this->m_grids[amrlev][0], this->m_dmap[amrlev][0], ncomp, this->m_geom[amrlev][0]);
779 MF bc_data(this->m_grids[amrlev][0], this->m_dmap[amrlev][0], ncomp, 1);
780 bc_data.setVal(0.0);
781
782 m_bndry_cor[amrlev]->setBndryValues(*m_crse_cor_br[amrlev], 0, bc_data, 0, 0, ncomp,
783 this->AMRRefRatioVect(amrlev-1),
785 m_interpbndry_halfwidth);
786
787 Vector<Array<LinOpBCType,AMREX_SPACEDIM> > bclohi
788 (ncomp,Array<LinOpBCType,AMREX_SPACEDIM>{{AMREX_D_DECL(BCType::Dirichlet,
789 BCType::Dirichlet,
790 BCType::Dirichlet)}});
791 m_bndry_cor[amrlev]->setLOBndryConds(bclohi, bclohi, this->AMRRefRatioVect(amrlev-1), RealVect{});
792 }
793
794 m_bcondloc.resize(this->m_num_amr_levels);
795 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
796 {
797 m_bcondloc[amrlev].resize(this->m_num_mg_levels[amrlev]);
798 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
799 {
800 m_bcondloc[amrlev][mglev] = std::make_unique<BndryCondLoc>(this->m_grids[amrlev][mglev],
801 this->m_dmap[amrlev][mglev],
802 ncomp);
803 }
804 }
805}
806
807template <typename MF>
808void
809MLCellLinOpT<MF>::setLevelBC (int amrlev, const MF* a_levelbcdata, const MF* robinbc_a,
810 const MF* robinbc_b, const MF* robinbc_f)
811{
812 BL_PROFILE("MLCellLinOp::setLevelBC()");
813
814 AMREX_ALWAYS_ASSERT(amrlev >= 0 && amrlev < this->m_num_amr_levels);
815
816 const int ncomp = this->getNComp();
817
818 MF zero;
819 IntVect ng(1);
820 if (this->hasHiddenDimension()) { ng[this->hiddenDirection()] = 0; }
821 if (a_levelbcdata == nullptr) {
822 zero.define(this->m_grids[amrlev][0], this->m_dmap[amrlev][0], ncomp, ng);
823 zero.setVal(RT(0.0));
824 } else {
825 AMREX_ALWAYS_ASSERT(a_levelbcdata->nGrowVect().allGE(ng));
826 }
827 const MF& bcdata = (a_levelbcdata == nullptr) ? zero : *a_levelbcdata;
828
829 IntVect br_ref_ratio(-1);
830
831 if (amrlev == 0)
832 {
833 if (this->needsCoarseDataForBC())
834 {
835 // AMREX_ALWAYS_ASSERT(!this->hasHiddenDimension());
836 if (this->hasHiddenDimension()) {
837 int hidden_dir = this->hiddenDirection();
838 AMREX_ALWAYS_ASSERT(this->m_coarse_data_crse_ratio[hidden_dir] == 1);
839 }
840 br_ref_ratio = this->m_coarse_data_crse_ratio.allGT(0) ? this->m_coarse_data_crse_ratio : IntVect(2);
841 if (this->m_crse_sol_br[amrlev] == nullptr && br_ref_ratio.allGT(0))
842 {
843 const int in_rad = 0;
844 const int out_rad = 1;
845 const int extent_rad = 2;
846 const IntVect crse_ratio = br_ref_ratio;
847 BoxArray cba = this->m_grids[amrlev][0];
848 cba.coarsen(crse_ratio);
849 this->m_crse_sol_br[amrlev] = std::make_unique<BndryRegisterT<MF>>
850 (cba, this->m_dmap[amrlev][0], in_rad, out_rad, extent_rad, ncomp);
851 }
852 if (this->m_coarse_data_for_bc != nullptr) {
853 AMREX_ALWAYS_ASSERT(this->m_coarse_data_crse_ratio.allGT(0));
854 const Box& cbx = amrex::coarsen(this->m_geom[0][0].Domain(), this->m_coarse_data_crse_ratio);
855 this->m_crse_sol_br[amrlev]->copyFrom(*(this->m_coarse_data_for_bc), 0, 0, 0, ncomp,
856 this->m_geom[0][0].periodicity(cbx));
857 } else {
858 this->m_crse_sol_br[amrlev]->setVal(RT(0.0));
859 }
860 this->m_bndry_sol[amrlev]->setBndryValues(*(this->m_crse_sol_br[amrlev]), 0,
861 bcdata, 0, 0, ncomp, br_ref_ratio,
863 this->m_interpbndry_halfwidth);
864 br_ref_ratio = this->m_coarse_data_crse_ratio;
865 }
866 else
867 {
868 this->m_bndry_sol[amrlev]->setPhysBndryValues(bcdata,0,0,ncomp);
869 br_ref_ratio = IntVect(1);
870 }
871 }
872 else
873 {
874 this->m_bndry_sol[amrlev]->setPhysBndryValues(bcdata,0,0,ncomp);
875 br_ref_ratio = this->AMRRefRatioVect(amrlev-1);
876 }
877
878 auto crse_fine_bc_type = (amrlev == 0) ? this->m_coarse_fine_bc_type : LinOpBCType::Dirichlet;
879 this->m_bndry_sol[amrlev]->setLOBndryConds(this->m_lobc, this->m_hibc, br_ref_ratio,
880 this->m_coarse_bc_loc, crse_fine_bc_type);
881
882 const Real* dx = this->m_geom[amrlev][0].CellSize();
883 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
884 {
885 this->m_bcondloc[amrlev][mglev]->setLOBndryConds(this->m_geom[amrlev][mglev], dx,
886 this->m_lobc, this->m_hibc,
887 br_ref_ratio, this->m_coarse_bc_loc,
888 this->m_domain_bloc_lo, this->m_domain_bloc_hi,
889 crse_fine_bc_type);
890 }
891
892 if (this->hasRobinBC()) {
893 AMREX_ASSERT(robinbc_a != nullptr && robinbc_b != nullptr && robinbc_f != nullptr);
894 this->m_robin_bcval[amrlev] = std::make_unique<MF>(this->m_grids[amrlev][0],
895 this->m_dmap[amrlev][0],
896 ncomp*3, 1);
897 const Box& domain = this->m_geom[amrlev][0].Domain();
898 MFItInfo mfi_info;
899 if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }
900#ifdef AMREX_USE_OMP
901#pragma omp parallel if (Gpu::notInLaunchRegion())
902#endif
903 for (MFIter mfi(*(this->m_robin_bcval[amrlev]), mfi_info); mfi.isValid(); ++mfi) {
904 Box const& vbx = mfi.validbox();
905 Array4<RT const> const& ra = robinbc_a->const_array(mfi);
906 Array4<RT const> const& rb = robinbc_b->const_array(mfi);
907 Array4<RT const> const& rf = robinbc_f->const_array(mfi);
908 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
909 const Box& blo = amrex::adjCellLo(vbx, idim);
910 const Box& bhi = amrex::adjCellHi(vbx, idim);
911 bool outside_domain_lo = !(domain.contains(blo));
912 bool outside_domain_hi = !(domain.contains(bhi));
913 if ((!outside_domain_lo) && (!outside_domain_hi)) { continue; }
914 for (int icomp = 0; icomp < ncomp; ++icomp) {
915 Array4<RT> const& rbc = (*(this->m_robin_bcval[amrlev]))[mfi].array(icomp*3);
916 if (this->m_lobc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_lo)
917 {
919 {
920 rbc(i,j,k,0) = ra(i,j,k,icomp);
921 rbc(i,j,k,1) = rb(i,j,k,icomp);
922 rbc(i,j,k,2) = rf(i,j,k,icomp);
923 });
924 }
925 if (this->m_hibc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_hi)
926 {
928 {
929 rbc(i,j,k,0) = ra(i,j,k,icomp);
930 rbc(i,j,k,1) = rb(i,j,k,icomp);
931 rbc(i,j,k,2) = rf(i,j,k,icomp);
932 });
933 }
934 }
935 }
936 }
937 }
938}
939
940template <typename MF>
941void
946
947template <typename MF>
948void
949MLCellLinOpT<MF>::updateSolBC (int amrlev, const MF& crse_bcdata) const
950{
951 BL_PROFILE("MLCellLinOp::updateSolBC()");
952
953 AMREX_ALWAYS_ASSERT(amrlev > 0);
954 const int ncomp = this->getNComp();
955 m_crse_sol_br[amrlev]->copyFrom(crse_bcdata, 0, 0, 0, ncomp,
956 this->m_geom[amrlev-1][0].periodicity());
957 m_bndry_sol[amrlev]->updateBndryValues(*m_crse_sol_br[amrlev], 0, 0, ncomp,
958 this->AMRRefRatioVect(amrlev-1),
960 m_interpbndry_halfwidth);
961}
962
963template <typename MF>
964void
965MLCellLinOpT<MF>::updateCorBC (int amrlev, const MF& crse_bcdata) const
966{
967 BL_PROFILE("MLCellLinOp::updateCorBC()");
968 AMREX_ALWAYS_ASSERT(amrlev > 0);
969 const int ncomp = this->getNComp();
970 m_crse_cor_br[amrlev]->copyFrom(crse_bcdata, 0, 0, 0, ncomp,
971 this->m_geom[amrlev-1][0].periodicity());
972 m_bndry_cor[amrlev]->updateBndryValues(*m_crse_cor_br[amrlev], 0, 0, ncomp,
973 this->AMRRefRatioVect(amrlev-1),
975 m_interpbndry_halfwidth);
976}
977
978template <typename MF>
979void
980MLCellLinOpT<MF>::applyBC (int amrlev, int mglev, MF& in, BCMode bc_mode, StateMode,
981 const MLMGBndryT<MF>* bndry, bool skip_fillboundary) const
982{
983 BL_PROFILE("MLCellLinOp::applyBC()");
984 // No coarsened boundary values, cannot apply inhomog at mglev>0.
985 BL_ASSERT(mglev == 0 || bc_mode == BCMode::Homogeneous);
986 BL_ASSERT(bndry != nullptr || bc_mode == BCMode::Homogeneous);
987
988 const int ncomp = this->getNComp();
989 const int cross = isCrossStencil();
990 const int tensorop = isTensorOp();
991 if (!skip_fillboundary) {
992 in.FillBoundary(0, ncomp, this->m_geom[amrlev][mglev].periodicity(), cross);
993 }
994
995 int flagbc = bc_mode == BCMode::Inhomogeneous;
996 const int imaxorder = this->maxorder;
997
998 const Real* dxinv = this->m_geom[amrlev][mglev].InvCellSize();
999 const RT dxi = static_cast<RT>(dxinv[0]);
1000 const RT dyi = (AMREX_SPACEDIM >= 2) ? static_cast<RT>(dxinv[1]) : RT(1.0);
1001 const RT dzi = (AMREX_SPACEDIM == 3) ? static_cast<RT>(dxinv[2]) : RT(1.0);
1002
1003 const auto& maskvals = m_maskvals[amrlev][mglev];
1004 const auto& bcondloc = *m_bcondloc[amrlev][mglev];
1005
1006 FAB foofab(Box::TheUnitBox(),ncomp);
1007 const auto& foo = foofab.const_array();
1008
1009 MFItInfo mfi_info;
1010 if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }
1011
1013 "non-cross stencil not support for gpu");
1014
1015 const int hidden_direction = this->hiddenDirection();
1016
1017#ifdef AMREX_USE_GPU
1018 if ((cross || tensorop) && Gpu::inLaunchRegion())
1019 {
1020 if (! m_bc_tags[amrlev][mglev].is_defined()) {
1022 tags.reserve(in.local_size()*2*AMREX_SPACEDIM*ncomp);
1023 for (MFIter mfi(in); mfi.isValid(); ++mfi) {
1024 const Box& vbx = mfi.validbox();
1025 const auto & bdlv = bcondloc.bndryLocs(mfi);
1026 const auto & bdcv = bcondloc.bndryConds(mfi);
1027
1028 const int local_index = mfi.LocalIndex();
1029
1030 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1031 if (idim != hidden_direction) {
1032 const Orientation olo(idim,Orientation::low);
1033 const Orientation ohi(idim,Orientation::high);
1034 for (int icomp = 0; icomp < ncomp; ++icomp) {
1035 tags.emplace_back(MLMGABCTag<RT>{
1036 maskvals[olo].const_array(mfi),
1037 bdlv[icomp][olo],
1038 amrex::adjCell(vbx,olo),
1039 bdcv[icomp][olo], vbx.length(idim),
1040 icomp, olo, local_index
1041 });
1042 tags.emplace_back(MLMGABCTag<RT>{
1043 maskvals[ohi].const_array(mfi),
1044 bdlv[icomp][ohi],
1045 amrex::adjCell(vbx,ohi),
1046 bdcv[icomp][ohi], vbx.length(idim),
1047 icomp, ohi, local_index
1048 });
1049 }
1050 }
1051 }
1052 }
1053 m_bc_tags[amrlev][mglev].define(tags);
1054 }
1055
1056 MultiArray4<RT const> foo_ma;
1057 Array<MultiArray4<RT const>, 2*AMREX_SPACEDIM> bndry_arrays;
1058 for (OrientationIter oit; oit; ++oit) {
1059 const Orientation ori = oit();
1060 bndry_arrays[ori] = (bndry != nullptr) ?
1061 bndry->bndryValues(ori).arrays() : foo_ma;
1062 }
1063
1064 auto inma = in.arrays();
1065 ParallelFor(m_bc_tags[amrlev][mglev],
1066 [=] AMREX_GPU_DEVICE (int i, int j, int k, MLMGABCTag<RT> const& tag) noexcept
1067 {
1068 const auto& bcval = bndry_arrays[tag.face][tag.local_index];
1069 const int side = tag.face.faceDir();
1070 if (tag.face.coordDir() == 0) {
1071 mllinop_apply_bc_x(side, i, j, k, tag.blen, inma[tag.local_index],
1072 tag.mask, tag.bctype, tag.bcloc, bcval,
1073 imaxorder, dxi, flagbc, tag.comp);
1074 }
1075#if (AMREX_SPACEDIM > 1)
1076 else
1077#if (AMREX_SPACEDIM > 2)
1078 if (tag.face.coordDir() == 1)
1079#endif
1080 {
1081 mllinop_apply_bc_y(side, i, j, k, tag.blen, inma[tag.local_index],
1082 tag.mask, tag.bctype, tag.bcloc, bcval,
1083 imaxorder, dyi, flagbc, tag.comp);
1084 }
1085#if (AMREX_SPACEDIM > 2)
1086 else {
1087 mllinop_apply_bc_z(side, i, j, k, tag.blen, inma[tag.local_index],
1088 tag.mask, tag.bctype, tag.bcloc, bcval,
1089 imaxorder, dzi, flagbc, tag.comp);
1090 }
1091#endif
1092#endif
1093 });
1094 } else
1095#endif
1096 if (cross || tensorop)
1097 {
1098#ifdef AMREX_USE_OMP
1099#pragma omp parallel if (Gpu::notInLaunchRegion())
1100#endif
1101 for (MFIter mfi(in, mfi_info); mfi.isValid(); ++mfi)
1102 {
1103 const Box& vbx = mfi.validbox();
1104 const auto& iofab = in.array(mfi);
1105
1106 const auto & bdlv = bcondloc.bndryLocs(mfi);
1107 const auto & bdcv = bcondloc.bndryConds(mfi);
1108
1109 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
1110 {
1111 if (hidden_direction == idim) { continue; }
1112 const Orientation olo(idim,Orientation::low);
1113 const Orientation ohi(idim,Orientation::high);
1114 const Box blo = amrex::adjCellLo(vbx, idim);
1115 const Box bhi = amrex::adjCellHi(vbx, idim);
1116 const int blen = vbx.length(idim);
1117 const auto& mlo = maskvals[olo].array(mfi);
1118 const auto& mhi = maskvals[ohi].array(mfi);
1119 const auto& bvlo = (bndry != nullptr) ? bndry->bndryValues(olo).const_array(mfi) : foo;
1120 const auto& bvhi = (bndry != nullptr) ? bndry->bndryValues(ohi).const_array(mfi) : foo;
1121 for (int icomp = 0; icomp < ncomp; ++icomp) {
1122 const BoundCond bctlo = bdcv[icomp][olo];
1123 const BoundCond bcthi = bdcv[icomp][ohi];
1124 const RT bcllo = bdlv[icomp][olo];
1125 const RT bclhi = bdlv[icomp][ohi];
1126 if (idim == 0) {
1127 mllinop_apply_bc_x(0, blo, blen, iofab, mlo,
1128 bctlo, bcllo, bvlo,
1129 imaxorder, dxi, flagbc, icomp);
1130 mllinop_apply_bc_x(1, bhi, blen, iofab, mhi,
1131 bcthi, bclhi, bvhi,
1132 imaxorder, dxi, flagbc, icomp);
1133 } else if (idim == 1) {
1134 mllinop_apply_bc_y(0, blo, blen, iofab, mlo,
1135 bctlo, bcllo, bvlo,
1136 imaxorder, dyi, flagbc, icomp);
1137 mllinop_apply_bc_y(1, bhi, blen, iofab, mhi,
1138 bcthi, bclhi, bvhi,
1139 imaxorder, dyi, flagbc, icomp);
1140 } else {
1141 mllinop_apply_bc_z(0, blo, blen, iofab, mlo,
1142 bctlo, bcllo, bvlo,
1143 imaxorder, dzi, flagbc, icomp);
1144 mllinop_apply_bc_z(1, bhi, blen, iofab, mhi,
1145 bcthi, bclhi, bvhi,
1146 imaxorder, dzi, flagbc, icomp);
1147 }
1148 }
1149 }
1150 }
1151 }
1152 else
1153 {
1154#ifdef BL_NO_FORT
1155 amrex::Abort("amrex_mllinop_apply_bc not available when BL_NO_FORT=TRUE");
1156#else
1157 if constexpr (std::is_same_v<Real,RT>) {
1158#ifdef AMREX_USE_OMP
1159#pragma omp parallel
1160#endif
1161 for (MFIter mfi(in, mfi_info); mfi.isValid(); ++mfi)
1162 {
1163 const Box& vbx = mfi.validbox();
1164
1165 const auto & bdlv = bcondloc.bndryLocs(mfi);
1166 const auto & bdcv = bcondloc.bndryConds(mfi);
1167
1168 const RealTuple & bdl = bdlv[0];
1169 const BCTuple & bdc = bdcv[0];
1170
1171 for (OrientationIter oitr; oitr; ++oitr)
1172 {
1173 const Orientation ori = oitr();
1174
1175 int cdr = ori;
1176 RT bcl = bdl[ori];
1177 int bct = bdc[ori];
1178
1179 const auto& fsfab = (bndry != nullptr) ? bndry->bndryValues(ori)[mfi] : foofab;
1180
1181 const Mask& m = maskvals[ori][mfi];
1182
1184 BL_TO_FORTRAN_ANYD(in[mfi]),
1186 cdr, bct, bcl,
1187 BL_TO_FORTRAN_ANYD(fsfab),
1188 imaxorder, dxinv, flagbc, ncomp, cross);
1189 }
1190 }
1191 } else {
1192 amrex::Abort("Not supported");
1193 }
1194#endif
1195 }
1196}
1197
1198template <typename MF>
1200MLCellLinOpT<MF>::makeNGrids (int grid_size) const
1201{
1202 const Box& dombx = this->m_geom[0].back().Domain();
1203
1204 const BoxArray& old_ba = this->m_grids[0].back();
1205 const int N = old_ba.size();
1206 Vector<Box> bv;
1207 bv.reserve(N);
1208 for (int i = 0; i < N; ++i)
1209 {
1210 Box b = old_ba[i];
1211 b.coarsen(grid_size);
1212 b.refine(grid_size);
1213 IntVect sz = b.size();
1214 const IntVect nblks {AMREX_D_DECL(sz[0]/grid_size, sz[1]/grid_size, sz[2]/grid_size)};
1215
1216 IntVect big = b.smallEnd() + grid_size - 1;
1217 b.setBig(big);
1218
1219#if (AMREX_SPACEDIM == 3)
1220 for (int kk = 0; kk < nblks[2]; ++kk) {
1221#endif
1222#if (AMREX_SPACEDIM >= 2)
1223 for (int jj = 0; jj < nblks[1]; ++jj) {
1224#endif
1225 for (int ii = 0; ii < nblks[0]; ++ii)
1226 {
1227 IntVect shft{AMREX_D_DECL(ii*grid_size,jj*grid_size,kk*grid_size)};
1228 Box bb = amrex::shift(b,shft);
1229 bb &= dombx;
1230 bv.push_back(bb);
1231 }
1232#if (AMREX_SPACEDIM >= 2)
1233 }
1234#endif
1235#if (AMREX_SPACEDIM == 3)
1236 }
1237#endif
1238 }
1239
1240 std::sort(bv.begin(), bv.end());
1241 bv.erase(std::unique(bv.begin(), bv.end()), bv.end());
1242
1243 BoxList bl(std::move(bv));
1244
1245 return BoxArray{std::move(bl)};
1246}
1247
1248template <typename MF>
1249void
1250MLCellLinOpT<MF>::restriction (int amrlev, int cmglev, MF& crse, MF& fine) const
1251{
1252 const int ncomp = this->getNComp();
1253 IntVect ratio = (amrlev > 0) ? IntVect(2) : this->mg_coarsen_ratio_vec[cmglev-1];
1254 amrex::average_down(fine, crse, 0, ncomp, ratio);
1255}
1256
1257template <typename MF>
1258void
1259MLCellLinOpT<MF>::interpolation (int amrlev, int fmglev, MF& fine, const MF& crse) const
1260{
1261 const int ncomp = this->getNComp();
1262
1263 Dim3 ratio3 = {.x = 2, .y = 2, .z = 2};
1264 IntVect ratio = (amrlev > 0) ? IntVect(2) : this->mg_coarsen_ratio_vec[fmglev];
1265 AMREX_D_TERM(ratio3.x = ratio[0];,
1266 ratio3.y = ratio[1];,
1267 ratio3.z = ratio[2];);
1268
1269#ifdef AMREX_USE_GPU
1270 if (Gpu::inLaunchRegion() && fine.isFusingCandidate()) {
1271 auto const& finema = fine.arrays();
1272 auto const& crsema = crse.const_arrays();
1273 ParallelFor(fine, IntVect(0), ncomp,
1274 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1275 {
1276 int ic = amrex::coarsen(i,ratio3.x);
1277 int jc = amrex::coarsen(j,ratio3.y);
1278 int kc = amrex::coarsen(k,ratio3.z);
1279 finema[box_no](i,j,k,n) += crsema[box_no](ic,jc,kc,n);
1280 });
1281 if (!Gpu::inNoSyncRegion()) {
1283 }
1284 } else
1285#endif
1286 {
1287#ifdef AMREX_USE_OMP
1288#pragma omp parallel if (Gpu::notInLaunchRegion())
1289#endif
1290 for (MFIter mfi(fine,TilingIfNotGPU()); mfi.isValid(); ++mfi)
1291 {
1292 const Box& bx = mfi.tilebox();
1293 Array4<RT const> const& cfab = crse.const_array(mfi);
1294 Array4<RT> const& ffab = fine.array(mfi);
1295 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( bx, ncomp, i, j, k, n,
1296 {
1297 int ic = amrex::coarsen(i,ratio3.x);
1298 int jc = amrex::coarsen(j,ratio3.y);
1299 int kc = amrex::coarsen(k,ratio3.z);
1300 ffab(i,j,k,n) += cfab(ic,jc,kc,n);
1301 });
1302 }
1303 }
1304}
1305
1306template <typename MF>
1307void
1308MLCellLinOpT<MF>::interpAssign (int amrlev, int fmglev, MF& fine, MF& crse) const
1309{
1310 const int ncomp = this->getNComp();
1311
1312 const Geometry& crse_geom = this->Geom(amrlev,fmglev+1);
1313 const IntVect refratio = (amrlev > 0) ? IntVect(2) : this->mg_coarsen_ratio_vec[fmglev];
1314 const IntVect ng = crse.nGrowVect();
1315
1316 MF cfine;
1317 const MF* cmf;
1318
1320 {
1321 crse.FillBoundary(crse_geom.periodicity());
1322 cmf = &crse;
1323 }
1324 else
1325 {
1326 BoxArray cba = fine.boxArray();
1327 cba.coarsen(refratio);
1328 cfine.define(cba, fine.DistributionMap(), ncomp, ng);
1329 cfine.setVal(RT(0.0));
1330 cfine.ParallelCopy(crse, 0, 0, ncomp, IntVect(0), ng, crse_geom.periodicity());
1331 cmf = & cfine;
1332 }
1333
1334 bool isEB = fine.hasEBFabFactory();
1335 ignore_unused(isEB);
1336
1337#ifdef AMREX_USE_EB
1338 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(&(fine.Factory()));
1339 const FabArray<EBCellFlagFab>* flags = (factory) ? &(factory->getMultiEBCellFlagFab()) : nullptr;
1340#endif
1341
1342 MFItInfo mfi_info;
1343 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
1344#ifdef AMREX_USE_OMP
1345#pragma omp parallel if (Gpu::notInLaunchRegion())
1346#endif
1347 for (MFIter mfi(fine, mfi_info); mfi.isValid(); ++mfi)
1348 {
1349 const Box& bx = mfi.tilebox();
1350 const auto& ff = fine.array(mfi);
1351 const auto& cc = cmf->array(mfi);
1352#ifdef AMREX_USE_EB
1353 bool call_lincc;
1354 if (isEB)
1355 {
1356 const auto& flag = (*flags)[mfi];
1357 if (flag.getType(amrex::grow(bx,1)) == FabType::regular) {
1358 call_lincc = true;
1359 } else {
1360 Array4<EBCellFlag const> const& flg = flag.const_array();
1362 {
1363 mlmg_eb_cc_interp_r<2>(tbx, ff, cc, flg, ncomp);
1364 });
1365
1366 call_lincc = false;
1367 }
1368 }
1369 else
1370 {
1371 call_lincc = true;
1372 }
1373#else
1374 const bool call_lincc = true;
1375#endif
1376 if (call_lincc)
1377 {
1378#if (AMREX_SPACEDIM == 3)
1379 if (this->hasHiddenDimension()) {
1380 Box const& bx_2d = this->compactify(bx);
1381 auto const& ff_2d = this->compactify(ff);
1382 auto const& cc_2d = this->compactify(cc);
1384 {
1385 TwoD::mlmg_lin_cc_interp_r2(tbx, ff_2d, cc_2d, ncomp);
1386 });
1387 } else
1388#endif
1389 {
1391 {
1392 mlmg_lin_cc_interp_r2(tbx, ff, cc, ncomp);
1393 });
1394 }
1395 }
1396 }
1397}
1398
1399template <typename MF>
1400void
1401MLCellLinOpT<MF>::interpolationAmr (int famrlev, MF& fine, const MF& crse,
1402 IntVect const& /*nghost*/) const
1403{
1404 const int ncomp = this->getNComp();
1405 const IntVect refratioV = this->AMRRefRatioVect(famrlev-1);
1406 // AMRRefRatioVect sets hidden direction to 1 and active directions to the
1407 // scalar ratio; max() cleanly recovers the active ratio in all cases.
1408 const int refratio = refratioV.max();
1409
1410#ifdef AMREX_USE_EB
1411 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(famrlev));
1412 const FabArray<EBCellFlagFab>* flags = (factory) ? &(factory->getMultiEBCellFlagFab()) : nullptr;
1413#endif
1414
1415 MFItInfo mfi_info;
1416 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
1417#ifdef AMREX_USE_OMP
1418#pragma omp parallel if (Gpu::notInLaunchRegion())
1419#endif
1420 for (MFIter mfi(fine, mfi_info); mfi.isValid(); ++mfi)
1421 {
1422 const Box& bx = mfi.tilebox();
1423 auto const& ff = fine.array(mfi);
1424 auto const& cc = crse.const_array(mfi);
1425#ifdef AMREX_USE_EB
1426 bool call_lincc;
1427 if (factory)
1428 {
1429 const auto& flag = (*flags)[mfi];
1430 if (flag.getType(amrex::grow(bx,1)) == FabType::regular) {
1431 call_lincc = true;
1432 } else {
1433 Array4<EBCellFlag const> const& flg = flag.const_array();
1434 switch(refratio) {
1435 case 2:
1436 {
1438 {
1439 mlmg_eb_cc_interp_r<2>(tbx, ff, cc, flg, ncomp);
1440 });
1441 break;
1442 }
1443 case 4:
1444 {
1446 {
1447 mlmg_eb_cc_interp_r<4>(tbx, ff, cc, flg, ncomp);
1448 });
1449 break;
1450 }
1451 default:
1452 amrex::Abort("mlmg_eb_cc_interp: only refratio 2 and 4 are supported");
1453 }
1454
1455 call_lincc = false;
1456 }
1457 }
1458 else
1459 {
1460 call_lincc = true;
1461 }
1462#else
1463 const bool call_lincc = true;
1464#endif
1465 if (call_lincc)
1466 {
1467#if (AMREX_SPACEDIM == 3)
1468 if (this->hasHiddenDimension()) {
1469 Box const& bx_2d = this->compactify(bx);
1470 auto const& ff_2d = this->compactify(ff);
1471 auto const& cc_2d = this->compactify(cc);
1472 switch(refratio) {
1473 case 2:
1474 {
1476 {
1477 TwoD::mlmg_lin_cc_interp_r2(tbx, ff_2d, cc_2d, ncomp);
1478 });
1479 break;
1480 }
1481 case 4:
1482 {
1484 {
1485 TwoD::mlmg_lin_cc_interp_r4(tbx, ff_2d, cc_2d, ncomp);
1486 });
1487 break;
1488 }
1489 default:
1490 amrex::Abort("mlmg_lin_cc_interp: only refratio 2 and 4 are supported");
1491 }
1492 } else
1493#endif
1494 {
1495 switch(refratio) {
1496 case 2:
1497 {
1499 {
1500 mlmg_lin_cc_interp_r2(tbx, ff, cc, ncomp);
1501 });
1502 break;
1503 }
1504 case 4:
1505 {
1507 {
1508 mlmg_lin_cc_interp_r4(tbx, ff, cc, ncomp);
1509 });
1510 break;
1511 }
1512 default:
1513 amrex::Abort("mlmg_lin_cc_interp: only refratio 2 and 4 are supported");
1514 }
1515 }
1516 }
1517 }
1518}
1519
1520template <typename MF>
1521void
1522MLCellLinOpT<MF>::averageDownSolutionRHS (int camrlev, MF& crse_sol, MF& crse_rhs,
1523 const MF& fine_sol, const MF& fine_rhs)
1524{
1525 const auto amrrr = this->AMRRefRatioVect(camrlev);
1526 const int ncomp = this->getNComp();
1527 amrex::average_down(fine_sol, crse_sol, 0, ncomp, amrrr);
1528 amrex::average_down(fine_rhs, crse_rhs, 0, ncomp, amrrr);
1529}
1530
1531template <typename MF>
1532void
1533MLCellLinOpT<MF>::apply (int amrlev, int mglev, MF& out, MF& in, BCMode bc_mode,
1534 StateMode s_mode, const MLMGBndryT<MF>* bndry) const
1535{
1536 BL_PROFILE("MLCellLinOp::apply()");
1537 applyBC(amrlev, mglev, in, bc_mode, s_mode, bndry);
1538 Fapply(amrlev, mglev, out, in);
1539}
1540
1541template <typename MF>
1542void
1543MLCellLinOpT<MF>::smooth (int amrlev, int mglev, MF& sol, const MF& rhs,
1544 bool skip_fillboundary, int niter) const
1545{
1546 BL_PROFILE("MLCellLinOp::smooth()");
1547 for (int i = 0; i < niter; ++i) {
1548 for (int redblack = 0; redblack < 2; ++redblack)
1549 {
1550 applyBC(amrlev, mglev, sol, BCMode::Homogeneous, StateMode::Solution,
1551 nullptr, skip_fillboundary);
1552 Fsmooth(amrlev, mglev, sol, rhs, redblack);
1553 skip_fillboundary = false;
1554 }
1555 }
1556}
1557
1558template <typename MF>
1559void
1560MLCellLinOpT<MF>::solutionResidual (int amrlev, MF& resid, MF& x, const MF& b,
1561 const MF* crse_bcdata)
1562{
1563 BL_PROFILE("MLCellLinOp::solutionResidual()");
1564 const int ncomp = this->getNComp();
1565 if (crse_bcdata != nullptr) {
1566 updateSolBC(amrlev, *crse_bcdata);
1567 }
1568 const int mglev = 0;
1569 apply(amrlev, mglev, resid, x, BCMode::Inhomogeneous, StateMode::Solution,
1570 m_bndry_sol[amrlev].get());
1571
1572 AMREX_ASSERT(resid.nComp() == b.nComp());
1573 MF::Xpay(resid, RT(-1.0), b, 0, 0, ncomp, IntVect(0));
1574}
1575
1576template <typename MF>
1577void
1578MLCellLinOpT<MF>::prepareForFluxes (int amrlev, const MF* crse_bcdata)
1579{
1580 if (crse_bcdata != nullptr) {
1581 updateSolBC(amrlev, *crse_bcdata);
1582 }
1583}
1584
1585template <typename MF>
1586void
1587MLCellLinOpT<MF>::correctionResidual (int amrlev, int mglev, MF& resid, MF& x, const MF& b,
1588 BCMode bc_mode, const MF* crse_bcdata)
1589{
1590 BL_PROFILE("MLCellLinOp::correctionResidual()");
1591 const int ncomp = this->getNComp();
1592 if (bc_mode == BCMode::Inhomogeneous)
1593 {
1594 if (crse_bcdata)
1595 {
1596 AMREX_ASSERT(mglev == 0 && amrlev > 0);
1597 updateCorBC(amrlev, *crse_bcdata);
1598 }
1599 apply(amrlev, mglev, resid, x, BCMode::Inhomogeneous, StateMode::Correction,
1600 m_bndry_cor[amrlev].get());
1601 }
1602 else
1603 {
1604 AMREX_ASSERT(crse_bcdata == nullptr);
1605 apply(amrlev, mglev, resid, x, BCMode::Homogeneous, StateMode::Correction, nullptr);
1606 }
1607
1608 MF::Xpay(resid, Real(-1.0), b, 0, 0, ncomp, IntVect(0));
1609}
1610
1611template <typename MF>
1612void
1613MLCellLinOpT<MF>::reflux (int crse_amrlev, MF& res, const MF& crse_sol, const MF&,
1614 MF&, MF& fine_sol, const MF&) const
1615{
1616 BL_PROFILE("MLCellLinOp::reflux()");
1617
1618 auto& fluxreg = m_fluxreg[crse_amrlev];
1619 fluxreg.reset();
1620
1621 const int ncomp = this->getNComp();
1622
1623 const int fine_amrlev = crse_amrlev+1;
1624
1625 Real dt = Real(1.0);
1626 const Real* crse_dx = this->m_geom[crse_amrlev][0].CellSize();
1627 const Real* fine_dx = this->m_geom[fine_amrlev][0].CellSize();
1628
1629 const int mglev = 0;
1630 applyBC(fine_amrlev, mglev, fine_sol, BCMode::Inhomogeneous, StateMode::Solution,
1631 m_bndry_sol[fine_amrlev].get());
1632
1633 MFItInfo mfi_info;
1634 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
1635
1636#ifdef AMREX_USE_OMP
1637#pragma omp parallel if (Gpu::notInLaunchRegion())
1638#endif
1639 {
1641 Array<FAB*,AMREX_SPACEDIM> pflux {{ AMREX_D_DECL(flux.data(), flux.data()+1, flux.data()+2) }};
1642 Array<FAB const*,AMREX_SPACEDIM> cpflux {{ AMREX_D_DECL(flux.data(), flux.data()+1, flux.data()+2) }};
1643
1644 for (MFIter mfi(crse_sol, mfi_info); mfi.isValid(); ++mfi)
1645 {
1646 if (fluxreg.CrseHasWork(mfi))
1647 {
1648 const Box& tbx = mfi.tilebox();
1649 AMREX_D_TERM(flux[0].resize(amrex::surroundingNodes(tbx,0),ncomp,The_Async_Arena());,
1650 flux[1].resize(amrex::surroundingNodes(tbx,1),ncomp,The_Async_Arena());,
1651 flux[2].resize(amrex::surroundingNodes(tbx,2),ncomp,The_Async_Arena()););
1652 FFlux(crse_amrlev, mfi, pflux, crse_sol[mfi], Location::FaceCentroid);
1653 fluxreg.CrseAdd(mfi, cpflux, crse_dx, dt, RunOn::Gpu);
1654 }
1655 }
1656
1657#ifdef AMREX_USE_OMP
1658#pragma omp barrier
1659#endif
1660
1661 for (MFIter mfi(fine_sol, mfi_info); mfi.isValid(); ++mfi)
1662 {
1663 if (fluxreg.FineHasWork(mfi))
1664 {
1665 const Box& tbx = mfi.tilebox();
1666 const int face_only = true;
1667 AMREX_D_TERM(flux[0].resize(amrex::surroundingNodes(tbx,0),ncomp,The_Async_Arena());,
1668 flux[1].resize(amrex::surroundingNodes(tbx,1),ncomp,The_Async_Arena());,
1669 flux[2].resize(amrex::surroundingNodes(tbx,2),ncomp,The_Async_Arena()););
1670 FFlux(fine_amrlev, mfi, pflux, fine_sol[mfi], Location::FaceCentroid, face_only);
1671 fluxreg.FineAdd(mfi, cpflux, fine_dx, dt, RunOn::Gpu);
1672 }
1673 }
1674 }
1675
1676 fluxreg.Reflux(res);
1677 this->applyOverset(crse_amrlev, res);
1678}
1679
1680template <typename MF>
1681void
1683 MF& sol, Location loc) const
1684{
1685 BL_PROFILE("MLCellLinOp::compFlux()");
1686
1687 const int mglev = 0;
1688 const int ncomp = this->getNComp();
1689 applyBC(amrlev, mglev, sol, BCMode::Inhomogeneous, StateMode::Solution,
1690 m_bndry_sol[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 for (MFIter mfi(sol, mfi_info); mfi.isValid(); ++mfi)
1702 {
1703 const Box& tbx = mfi.tilebox();
1704 AMREX_D_TERM(flux[0].resize(amrex::surroundingNodes(tbx,0),ncomp,The_Async_Arena());,
1705 flux[1].resize(amrex::surroundingNodes(tbx,1),ncomp,The_Async_Arena());,
1706 flux[2].resize(amrex::surroundingNodes(tbx,2),ncomp,The_Async_Arena()););
1707 FFlux(amrlev, mfi, pflux, sol[mfi], loc);
1708 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
1709 const Box& nbx = mfi.nodaltilebox(idim);
1710 auto const& dst = fluxes[idim]->array(mfi);
1711 auto const& src = pflux[idim]->const_array();
1712 AMREX_HOST_DEVICE_PARALLEL_FOR_4D (nbx, ncomp, i, j, k, n,
1713 {
1714 dst(i,j,k,n) = src(i,j,k,n);
1715 });
1716 }
1717 }
1718 }
1719}
1720
1721template <typename MF>
1722void
1724 MF& sol, Location /*loc*/) const
1725{
1726 BL_PROFILE("MLCellLinOp::compGrad()");
1727
1728 if (sol.nComp() > 1) {
1729 amrex::Abort("MLCellLinOp::compGrad called, but only works for single-component solves");
1730 }
1731
1732 const int mglev = 0;
1733 applyBC(amrlev, mglev, sol, BCMode::Inhomogeneous, StateMode::Solution,
1734 m_bndry_sol[amrlev].get());
1735
1736 const int ncomp = this->getNComp();
1737
1738 AMREX_D_TERM(const RT dxi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0));,
1739 const RT dyi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(1));,
1740 const RT dzi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(2)););
1741#ifdef AMREX_USE_OMP
1742#pragma omp parallel if (Gpu::notInLaunchRegion())
1743#endif
1744 for (MFIter mfi(sol, TilingIfNotGPU()); mfi.isValid(); ++mfi)
1745 {
1746 AMREX_D_TERM(const Box& xbx = mfi.nodaltilebox(0);,
1747 const Box& ybx = mfi.nodaltilebox(1);,
1748 const Box& zbx = mfi.nodaltilebox(2););
1749 const auto& s = sol.array(mfi);
1750 AMREX_D_TERM(const auto& gx = grad[0]->array(mfi);,
1751 const auto& gy = grad[1]->array(mfi);,
1752 const auto& gz = grad[2]->array(mfi););
1753
1754 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( xbx, ncomp, i, j, k, n,
1755 {
1756 gx(i,j,k,n) = dxi*(s(i,j,k,n) - s(i-1,j,k,n));
1757 });
1758#if (AMREX_SPACEDIM >= 2)
1759 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( ybx, ncomp, i, j, k, n,
1760 {
1761 gy(i,j,k,n) = dyi*(s(i,j,k,n) - s(i,j-1,k,n));
1762 });
1763#endif
1764#if (AMREX_SPACEDIM == 3)
1765 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( zbx, ncomp, i, j, k, n,
1766 {
1767 gz(i,j,k,n) = dzi*(s(i,j,k,n) - s(i,j,k-1,n));
1768 });
1769#endif
1770 }
1771
1772 addInhomogNeumannFlux(amrlev, grad, sol, false);
1773}
1774
1775template <typename MF>
1776void
1777MLCellLinOpT<MF>::applyMetricTerm (int amrlev, int mglev, MF& rhs) const
1778{
1779 amrex::ignore_unused(amrlev,mglev,rhs);
1780#if (AMREX_SPACEDIM != 3)
1781 if (!m_has_metric_term) { return; }
1782
1783 const int ncomp = rhs.nComp();
1784
1785 bool cc = rhs.ixType().cellCentered(0);
1786
1787 const Geometry& geom = this->m_geom[amrlev][mglev];
1788 const RT dx = static_cast<RT>(geom.CellSize(0));
1789 const RT probxlo = static_cast<RT>(geom.ProbLo(0));
1790
1791#ifdef AMREX_USE_OMP
1792#pragma omp parallel if (Gpu::notInLaunchRegion())
1793#endif
1794 for (MFIter mfi(rhs,TilingIfNotGPU()); mfi.isValid(); ++mfi)
1795 {
1796 const Box& tbx = mfi.tilebox();
1797 auto const& rhsarr = rhs.array(mfi);
1798#if (AMREX_SPACEDIM == 1)
1799 if (cc) {
1800 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1801 {
1802 RT rc = probxlo + (i+RT(0.5))*dx;
1803 rhsarr(i,j,k,n) *= rc*rc;
1804 });
1805 } else {
1806 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1807 {
1808 RT re = probxlo + i*dx;
1809 rhsarr(i,j,k,n) *= re*re;
1810 });
1811 }
1812#elif (AMREX_SPACEDIM == 2)
1813 if (cc) {
1814 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1815 {
1816 RT rc = probxlo + (i+RT(0.5))*dx;
1817 rhsarr(i,j,k,n) *= rc;
1818 });
1819 } else {
1820 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1821 {
1822 RT re = probxlo + i*dx;
1823 rhsarr(i,j,k,n) *= re;
1824 });
1825 }
1826#endif
1827 }
1828#endif
1829}
1830
1831template <typename MF>
1832void
1833MLCellLinOpT<MF>::unapplyMetricTerm (int amrlev, int mglev, MF& rhs) const
1834{
1835 amrex::ignore_unused(amrlev,mglev,rhs);
1836#if (AMREX_SPACEDIM != 3)
1837 if (!m_has_metric_term) { return; }
1838
1839 const int ncomp = rhs.nComp();
1840
1841 bool cc = rhs.ixType().cellCentered(0);
1842
1843 const Geometry& geom = this->m_geom[amrlev][mglev];
1844 const RT dx = static_cast<RT>(geom.CellSize(0));
1845 const RT probxlo = static_cast<RT>(geom.ProbLo(0));
1846
1847#ifdef AMREX_USE_OMP
1848#pragma omp parallel if (Gpu::notInLaunchRegion())
1849#endif
1850 for (MFIter mfi(rhs,TilingIfNotGPU()); mfi.isValid(); ++mfi)
1851 {
1852 const Box& tbx = mfi.tilebox();
1853 auto const& rhsarr = rhs.array(mfi);
1854#if (AMREX_SPACEDIM == 1)
1855 if (cc) {
1856 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1857 {
1858 RT rcinv = RT(1.0)/(probxlo + (i+RT(0.5))*dx);
1859 rhsarr(i,j,k,n) *= rcinv*rcinv;
1860 });
1861 } else {
1862 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1863 {
1864 RT re = probxlo + i*dx;
1865 RT reinv = (re==RT(0.0)) ? RT(0.0) : RT(1.)/re;
1866 rhsarr(i,j,k,n) *= reinv*reinv;
1867 });
1868 }
1869#elif (AMREX_SPACEDIM == 2)
1870 if (cc) {
1871 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1872 {
1873 RT rcinv = RT(1.0)/(probxlo + (i+RT(0.5))*dx);
1874 rhsarr(i,j,k,n) *= rcinv;
1875 });
1876 } else {
1877 AMREX_HOST_DEVICE_PARALLEL_FOR_4D ( tbx, ncomp, i, j, k, n,
1878 {
1879 RT re = probxlo + i*dx;
1880 RT reinv = (re==RT(0.0)) ? RT(0.0) : RT(1.)/re;
1881 rhsarr(i,j,k,n) *= reinv;
1882 });
1883 }
1884#endif
1885 }
1886#endif
1887}
1888
1889template <typename MF>
1890auto
1891MLCellLinOpT<MF>::getSolvabilityOffset (int amrlev, int mglev, MF const& rhs) const
1892 -> Vector<RT>
1893{
1894 computeVolInv();
1895
1896 const int ncomp = this->getNComp();
1897 Vector<RT> offset(ncomp);
1898
1899#ifdef AMREX_USE_EB
1900 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(amrlev,mglev));
1901 if (factory && !factory->isAllRegular())
1902 {
1903 if constexpr (std::is_same<MF,MultiFab>()) {
1904 const MultiFab& vfrac = factory->getVolFrac();
1905 for (int c = 0; c < ncomp; ++c) {
1906 offset[c] = amrex::Dot(rhs, c, vfrac, 0, 1, IntVect(0), true)
1907 * m_volinv[amrlev][mglev];
1908 }
1909 } else {
1910 amrex::Abort("TODO: MLMG with EB only works with MultiFab");
1911 }
1912 }
1913 else
1914#endif
1915 {
1916 for (int c = 0; c < ncomp; ++c) {
1917 offset[c] = rhs.sum(c,IntVect(0),true) * m_volinv[amrlev][mglev];
1918 }
1919 }
1920
1922
1923 return offset;
1924}
1925
1926template <typename MF>
1927void
1928MLCellLinOpT<MF>::fixSolvabilityByOffset (int /*amrlev*/, int /*mglev*/, MF& rhs,
1929 Vector<RT> const& offset) const
1930{
1931 const int ncomp = this->getNComp();
1932 for (int c = 0; c < ncomp; ++c) {
1933 rhs.plus(-offset[c], c, 1);
1934 }
1935#ifdef AMREX_USE_EB
1936 if (!rhs.isAllRegular()) {
1937 if constexpr (std::is_same<MF,MultiFab>()) {
1938 amrex::EB_set_covered(rhs, 0, ncomp, 0, 0.0_rt);
1939 } else {
1940 amrex::Abort("amrex::EB_set_covered only works with MultiFab");
1941 }
1942 }
1943#endif
1944}
1945
1946template <typename MF>
1947void
1949{
1950 BL_PROFILE("MLCellLinOp::prepareForSolve()");
1951
1952 const int imaxorder = this->maxorder;
1953 const int ncomp = this->getNComp();
1954 const int hidden_direction = this->hiddenDirection();
1955 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
1956 {
1957 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
1958 {
1959 const auto& bcondloc = *m_bcondloc[amrlev][mglev];
1960 const auto& maskvals = m_maskvals[amrlev][mglev];
1961
1962 const RT dxi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0));
1963 const RT dyi = static_cast<RT>((AMREX_SPACEDIM >= 2) ? this->m_geom[amrlev][mglev].InvCellSize(1) : Real(1.0));
1964 const RT dzi = static_cast<RT>((AMREX_SPACEDIM == 3) ? this->m_geom[amrlev][mglev].InvCellSize(2) : Real(1.0));
1965
1966 auto& undrrelxr = this->m_undrrelxr[amrlev][mglev];
1967 MF foo(this->m_grids[amrlev][mglev], this->m_dmap[amrlev][mglev], ncomp, 0, MFInfo().SetAlloc(false));
1968
1969#ifdef AMREX_USE_EB
1970 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->m_factory[amrlev][mglev].get());
1971 const FabArray<EBCellFlagFab>* flags =
1972 (factory) ? &(factory->getMultiEBCellFlagFab()) : nullptr;
1973 auto area = (factory) ? factory->getAreaFrac()
1974 : Array<const MultiCutFab*,AMREX_SPACEDIM>{AMREX_D_DECL(nullptr,nullptr,nullptr)};
1976#endif
1977
1978#ifdef AMREX_USE_GPU
1979 if (Gpu::inLaunchRegion()) {
1980#ifdef AMREX_USE_EB
1981 if (factory && !factory->isAllRegular()) {
1982#if defined(AMREX_USE_CUDA) && defined(_WIN32)
1983 if (!std::is_same<MF,MultiFab>()) {
1984#else
1985 if constexpr (!std::is_same<MF,MultiFab>()) {
1986#endif
1987 amrex::Abort("MLCellLinOp with EB only works with MultiFab");
1988 } else {
1990 tags.reserve(foo.local_size()*AMREX_SPACEDIM*ncomp);
1991
1992 for (MFIter mfi(foo); mfi.isValid(); ++mfi)
1993 {
1994 const Box& vbx = mfi.validbox();
1995
1996 const auto & bdlv = bcondloc.bndryLocs(mfi);
1997 const auto & bdcv = bcondloc.bndryConds(mfi);
1998
1999 auto fabtyp = (flags) ? (*flags)[mfi].getType(vbx) : FabType::regular;
2000
2001 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
2002 {
2003 if (idim != hidden_direction && fabtyp != FabType::covered) {
2004 const Orientation olo(idim,Orientation::low);
2005 const Orientation ohi(idim,Orientation::high);
2006 auto const& ap = (fabtyp == FabType::singlevalued)
2007 ? area[idim]->const_array(mfi) : Array4<Real const>{};
2008 for (int icomp = 0; icomp < ncomp; ++icomp) {
2009 tags.emplace_back(MLMGPSEBTag<RT>{undrrelxr[olo].array(mfi),
2010 undrrelxr[ohi].array(mfi),
2011 ap,
2012 maskvals[olo].const_array(mfi),
2013 maskvals[ohi].const_array(mfi),
2014 bdlv[icomp][olo], bdlv[icomp][ohi],
2015 amrex::adjCell(vbx,olo),
2016 bdcv[icomp][olo], bdcv[icomp][ohi],
2017 vbx.length(idim), icomp, idim});
2018 }
2019 }
2020 }
2021 }
2022
2023 ParallelFor(tags,
2024 [=] AMREX_GPU_DEVICE (int i, int j, int k, MLMGPSEBTag<RT> const& tag) noexcept
2025 {
2026 if (tag.ap) {
2027 if (tag.dir == 0)
2028 {
2029 mllinop_comp_interp_coef0_x_eb
2030 (0, i , j, k, tag.blen, tag.flo, tag.mlo, tag.ap,
2031 tag.bctlo, tag.bcllo, imaxorder, dxi, tag.comp);
2032 mllinop_comp_interp_coef0_x_eb
2033 (1, i+tag.blen+1, j, k, tag.blen, tag.fhi, tag.mhi, tag.ap,
2034 tag.bcthi, tag.bclhi, imaxorder, dxi, tag.comp);
2035 }
2036#if (AMREX_SPACEDIM > 1)
2037 else
2038#if (AMREX_SPACEDIM > 2)
2039 if (tag.dir == 1)
2040#endif
2041 {
2042 mllinop_comp_interp_coef0_y_eb
2043 (0, i, j , k, tag.blen, tag.flo, tag.mlo, tag.ap,
2044 tag.bctlo, tag.bcllo, imaxorder, dyi, tag.comp);
2045 mllinop_comp_interp_coef0_y_eb
2046 (1, i, j+tag.blen+1, k, tag.blen, tag.fhi, tag.mhi, tag.ap,
2047 tag.bcthi, tag.bclhi, imaxorder, dyi, tag.comp);
2048 }
2049#if (AMREX_SPACEDIM > 2)
2050 else {
2051 mllinop_comp_interp_coef0_z_eb
2052 (0, i, j, k , tag.blen, tag.flo, tag.mlo, tag.ap,
2053 tag.bctlo, tag.bcllo, imaxorder, dzi, tag.comp);
2054 mllinop_comp_interp_coef0_z_eb
2055 (1, i, j, k+tag.blen+1, tag.blen, tag.fhi, tag.mhi, tag.ap,
2056 tag.bcthi, tag.bclhi, imaxorder, dzi, tag.comp);
2057 }
2058#endif
2059#endif
2060 } else {
2061 if (tag.dir == 0)
2062 {
2063 mllinop_comp_interp_coef0_x
2064 (0, i , j, k, tag.blen, tag.flo, tag.mlo,
2065 tag.bctlo, tag.bcllo, imaxorder, dxi, tag.comp);
2066 mllinop_comp_interp_coef0_x
2067 (1, i+tag.blen+1, j, k, tag.blen, tag.fhi, tag.mhi,
2068 tag.bcthi, tag.bclhi, imaxorder, dxi, tag.comp);
2069 }
2070#if (AMREX_SPACEDIM > 1)
2071 else
2072#if (AMREX_SPACEDIM > 2)
2073 if (tag.dir == 1)
2074#endif
2075 {
2076 mllinop_comp_interp_coef0_y
2077 (0, i, j , k, tag.blen, tag.flo, tag.mlo,
2078 tag.bctlo, tag.bcllo, imaxorder, dyi, tag.comp);
2079 mllinop_comp_interp_coef0_y
2080 (1, i, j+tag.blen+1, k, tag.blen, tag.fhi, tag.mhi,
2081 tag.bcthi, tag.bclhi, imaxorder, dyi, tag.comp);
2082 }
2083#if (AMREX_SPACEDIM > 2)
2084 else {
2085 mllinop_comp_interp_coef0_z
2086 (0, i, j, k , tag.blen, tag.flo, tag.mlo,
2087 tag.bctlo, tag.bcllo, imaxorder, dzi, tag.comp);
2088 mllinop_comp_interp_coef0_z
2089 (1, i, j, k+tag.blen+1, tag.blen, tag.fhi, tag.mhi,
2090 tag.bcthi, tag.bclhi, imaxorder, dzi, tag.comp);
2091 }
2092#endif
2093#endif
2094 }
2095 });
2096 }
2097 } else
2098#endif
2099 {
2101 tags.reserve(foo.local_size()*AMREX_SPACEDIM*ncomp);
2102
2103 for (MFIter mfi(foo); mfi.isValid(); ++mfi)
2104 {
2105 const Box& vbx = mfi.validbox();
2106
2107 const auto & bdlv = bcondloc.bndryLocs(mfi);
2108 const auto & bdcv = bcondloc.bndryConds(mfi);
2109
2110 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
2111 {
2112 if (idim != hidden_direction) {
2113 const Orientation olo(idim,Orientation::low);
2114 const Orientation ohi(idim,Orientation::high);
2115 for (int icomp = 0; icomp < ncomp; ++icomp) {
2116 tags.emplace_back(MLMGPSTag<RT>{undrrelxr[olo].array(mfi),
2117 undrrelxr[ohi].array(mfi),
2118 maskvals[olo].const_array(mfi),
2119 maskvals[ohi].const_array(mfi),
2120 bdlv[icomp][olo], bdlv[icomp][ohi],
2121 amrex::adjCell(vbx,olo),
2122 bdcv[icomp][olo], bdcv[icomp][ohi],
2123 vbx.length(idim), icomp, idim});
2124 }
2125 }
2126 }
2127 }
2128
2129 ParallelFor(tags,
2130 [=] AMREX_GPU_DEVICE (int i, int j, int k, MLMGPSTag<RT> const& tag) noexcept
2131 {
2132 if (tag.dir == 0)
2133 {
2134 mllinop_comp_interp_coef0_x
2135 (0, i , j, k, tag.blen, tag.flo, tag.mlo,
2136 tag.bctlo, tag.bcllo, imaxorder, dxi, tag.comp);
2137 mllinop_comp_interp_coef0_x
2138 (1, i+tag.blen+1, j, k, tag.blen, tag.fhi, tag.mhi,
2139 tag.bcthi, tag.bclhi, imaxorder, dxi, tag.comp);
2140 }
2141#if (AMREX_SPACEDIM > 1)
2142 else
2143#if (AMREX_SPACEDIM > 2)
2144 if (tag.dir == 1)
2145#endif
2146 {
2147 mllinop_comp_interp_coef0_y
2148 (0, i, j , k, tag.blen, tag.flo, tag.mlo,
2149 tag.bctlo, tag.bcllo, imaxorder, dyi, tag.comp);
2150 mllinop_comp_interp_coef0_y
2151 (1, i, j+tag.blen+1, k, tag.blen, tag.fhi, tag.mhi,
2152 tag.bcthi, tag.bclhi, imaxorder, dyi, tag.comp);
2153 }
2154#if (AMREX_SPACEDIM > 2)
2155 else {
2156 mllinop_comp_interp_coef0_z
2157 (0, i, j, k , tag.blen, tag.flo, tag.mlo,
2158 tag.bctlo, tag.bcllo, imaxorder, dzi, tag.comp);
2159 mllinop_comp_interp_coef0_z
2160 (1, i, j, k+tag.blen+1, tag.blen, tag.fhi, tag.mhi,
2161 tag.bcthi, tag.bclhi, imaxorder, dzi, tag.comp);
2162 }
2163#endif
2164#endif
2165 });
2166 }
2167 } else
2168#endif
2169 {
2170#ifdef AMREX_USE_OMP
2171#pragma omp parallel
2172#endif
2173 for (MFIter mfi(foo, MFItInfo{}.SetDynamic(true)); mfi.isValid(); ++mfi)
2174 {
2175 const Box& vbx = mfi.validbox();
2176
2177 const auto & bdlv = bcondloc.bndryLocs(mfi);
2178 const auto & bdcv = bcondloc.bndryConds(mfi);
2179
2180#ifdef AMREX_USE_EB
2181 auto fabtyp = (flags) ? (*flags)[mfi].getType(vbx) : FabType::regular;
2182#endif
2183 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
2184 {
2185 if (idim == hidden_direction) { continue; }
2186 const Orientation olo(idim,Orientation::low);
2187 const Orientation ohi(idim,Orientation::high);
2188 const Box blo = amrex::adjCellLo(vbx, idim);
2189 const Box bhi = amrex::adjCellHi(vbx, idim);
2190 const int blen = vbx.length(idim);
2191 const auto& mlo = maskvals[olo].array(mfi);
2192 const auto& mhi = maskvals[ohi].array(mfi);
2193 const auto& flo = undrrelxr[olo].array(mfi);
2194 const auto& fhi = undrrelxr[ohi].array(mfi);
2195 for (int icomp = 0; icomp < ncomp; ++icomp) {
2196 const BoundCond bctlo = bdcv[icomp][olo];
2197 const BoundCond bcthi = bdcv[icomp][ohi];
2198 const auto bcllo = bdlv[icomp][olo];
2199 const auto bclhi = bdlv[icomp][ohi];
2200#ifdef AMREX_USE_EB
2201 if (fabtyp == FabType::singlevalued) {
2202 if constexpr (!std::is_same<MF,MultiFab>()) {
2203 amrex::Abort("MLCellLinOp with EB only works with MultiFab");
2204 } else {
2205 auto const& ap = area[idim]->const_array(mfi);
2206 if (idim == 0) {
2207 mllinop_comp_interp_coef0_x_eb
2208 (0, blo, blen, flo, mlo, ap, bctlo, bcllo,
2209 imaxorder, dxi, icomp);
2210 mllinop_comp_interp_coef0_x_eb
2211 (1, bhi, blen, fhi, mhi, ap, bcthi, bclhi,
2212 imaxorder, dxi, icomp);
2213 } else if (idim == 1) {
2214 mllinop_comp_interp_coef0_y_eb
2215 (0, blo, blen, flo, mlo, ap, bctlo, bcllo,
2216 imaxorder, dyi, icomp);
2217 mllinop_comp_interp_coef0_y_eb
2218 (1, bhi, blen, fhi, mhi, ap, bcthi, bclhi,
2219 imaxorder, dyi, icomp);
2220 } else {
2221 mllinop_comp_interp_coef0_z_eb
2222 (0, blo, blen, flo, mlo, ap, bctlo, bcllo,
2223 imaxorder, dzi, icomp);
2224 mllinop_comp_interp_coef0_z_eb
2225 (1, bhi, blen, fhi, mhi, ap, bcthi, bclhi,
2226 imaxorder, dzi, icomp);
2227 }
2228 }
2229 } else if (fabtyp == FabType::regular)
2230#endif
2231 {
2232 if (idim == 0) {
2233 mllinop_comp_interp_coef0_x
2234 (0, blo, blen, flo, mlo, bctlo, bcllo,
2235 imaxorder, dxi, icomp);
2236 mllinop_comp_interp_coef0_x
2237 (1, bhi, blen, fhi, mhi, bcthi, bclhi,
2238 imaxorder, dxi, icomp);
2239 } else if (idim == 1) {
2240 mllinop_comp_interp_coef0_y
2241 (0, blo, blen, flo, mlo, bctlo, bcllo,
2242 imaxorder, dyi, icomp);
2243 mllinop_comp_interp_coef0_y
2244 (1, bhi, blen, fhi, mhi, bcthi, bclhi,
2245 imaxorder, dyi, icomp);
2246 } else {
2247 mllinop_comp_interp_coef0_z
2248 (0, blo, blen, flo, mlo, bctlo, bcllo,
2249 imaxorder, dzi, icomp);
2250 mllinop_comp_interp_coef0_z
2251 (1, bhi, blen, fhi, mhi, bcthi, bclhi,
2252 imaxorder, dzi, icomp);
2253 }
2254 }
2255 }
2256 }
2257 }
2258 }
2259 }
2260 }
2261}
2262
2263template <typename MF>
2264auto
2265MLCellLinOpT<MF>::xdoty (int /*amrlev*/, int /*mglev*/, const MF& x, const MF& y, bool local) const
2266 -> RT
2267{
2268 const int ncomp = this->getNComp();
2269 const IntVect nghost(0);
2270 RT result = amrex::Dot(x,0,y,0,ncomp,nghost,true);
2271 if (!local) {
2273 }
2274 return result;
2275}
2276
2277template <typename MF>
2278auto
2280{
2281 const int ncomp = this->getNComp();
2282 const IntVect nghost(0);
2283 RT result = 0;
2284 for (int ilev = 0; ilev < this->NAMRLevels()-1; ++ilev) {
2285 result += amrex::Dot(*m_norm_fine_mask[ilev], *x[ilev], 0, *y[ilev], 0, ncomp, nghost, true);
2286 }
2287 result += amrex::Dot(*x[this->NAMRLevels()-1], 0,
2288 *y[this->NAMRLevels()-1], 0, ncomp, nghost, true);
2290 return result;
2291}
2292
2293template <typename MF>
2294auto
2296{
2297 const int ncomp = this->getNComp();
2298 const IntVect nghost(0);
2299 RT result = 0;
2300 for (int ilev = 0; ilev < this->NAMRLevels()-1; ++ilev) {
2301 result += amrex::Dot(*m_norm_fine_mask[ilev], *x[ilev], 0, ncomp, nghost, true);
2302 }
2303 result += amrex::Dot(*x[this->NAMRLevels()-1], 0, ncomp, nghost, true);
2305 return std::sqrt(result);
2306}
2307
2308template <typename MF>
2309void
2311{
2312 if (!m_volinv.empty()) { return; }
2313
2314 m_volinv.resize(this->m_num_amr_levels);
2315 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
2316 m_volinv[amrlev].resize(this->NMGLevels(amrlev));
2317 }
2318
2319 // We don't need to compute for every level
2320
2321 auto f = [&] (int amrlev, int mglev) {
2322#ifdef AMREX_USE_EB
2323 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(amrlev,mglev));
2324 if (factory && !factory->isAllRegular())
2325 {
2326 if constexpr (std::is_same<MF,MultiFab>()) {
2327 const auto& vfrac = factory->getVolFrac();
2328 m_volinv[amrlev][mglev] = vfrac.sum(0,true);
2329 } else {
2330 amrex::Abort("MLCellLinOp with EB only works with MultiFab");
2331 }
2332 }
2333 else
2334#endif
2335 {
2336 auto const npts = (this->m_coarse_fine_bc_type == LinOpBCType::Dirichlet)
2337 ? this->compactify(this->Geom(amrlev,mglev).Domain()).d_numPts()
2338 : this->m_grids[amrlev][mglev].d_numPts();
2339 AMREX_ASSERT(npts > 0.);
2340 m_volinv[amrlev][mglev] = RT(1.0 / npts);
2341 }
2342 };
2343
2344 // amrlev = 0, mglev = 0
2345 f(0,0);
2346
2347 int mgbottom = this->NMGLevels(0)-1;
2348 f(0,mgbottom);
2349
2350#ifdef AMREX_USE_EB
2351 RT temp1, temp2;
2352 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(0,0));
2353 if (factory && !factory->isAllRegular())
2354 {
2355 ParallelAllReduce::Sum<RT>({m_volinv[0][0], m_volinv[0][mgbottom]},
2357 temp1 = RT(1.0)/m_volinv[0][0];
2358 temp2 = RT(1.0)/m_volinv[0][mgbottom];
2359 }
2360 else
2361 {
2362 temp1 = m_volinv[0][0];
2363 temp2 = m_volinv[0][mgbottom];
2364 }
2365 m_volinv[0][0] = temp1;
2366 m_volinv[0][mgbottom] = temp2;
2367#endif
2368}
2369
2370template <typename MF>
2371auto
2372MLCellLinOpT<MF>::normInf (int amrlev, MF const& mf, bool local) const -> RT
2373{
2374 const int ncomp = this->getNComp();
2375 const int finest_level = this->NAMRLevels() - 1;
2376 RT norm = RT(0.0);
2377#ifdef AMREX_USE_EB
2378 const auto *factory = dynamic_cast<EBFArrayBoxFactory const*>(this->Factory(amrlev));
2379 if (factory && !factory->isAllRegular()) {
2380#if defined(AMREX_USE_CUDA) && defined(_WIN32)
2381 if (!std::is_same<MF,MultiFab>()) {
2382#else
2383 if constexpr (!std::is_same<MF,MultiFab>()) {
2384#endif
2385 amrex::Abort("MLCellLinOpT with EB only works with MultiFab");
2386 } else {
2387 const MultiFab& vfrac = factory->getVolFrac();
2388 if (amrlev == finest_level) {
2389#ifdef AMREX_USE_GPU
2390 if (Gpu::inLaunchRegion()) {
2391 auto const& ma = mf.const_arrays();
2392 auto const& vfrac_ma = vfrac.const_arrays();
2394 mf, IntVect(0), ncomp,
2395 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n)
2397 {
2398 return std::abs(ma[box_no](i,j,k,n)
2399 *vfrac_ma[box_no](i,j,k));
2400 });
2401 } else
2402#endif
2403 {
2404#ifdef AMREX_USE_OMP
2405#pragma omp parallel reduction(max:norm)
2406#endif
2407 for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
2408 Box const& bx = mfi.tilebox();
2409 auto const& fab = mf.const_array(mfi);
2410 auto const& v = vfrac.const_array(mfi);
2411 AMREX_LOOP_4D(bx, ncomp, i, j, k, n,
2412 {
2413 norm = std::max(norm, std::abs(fab(i,j,k,n)*v(i,j,k)));
2414 });
2415 }
2416 }
2417 } else {
2418#ifdef AMREX_USE_GPU
2419 if (Gpu::inLaunchRegion()) {
2420 auto const& ma = mf.const_arrays();
2421 auto const& mask_ma = m_norm_fine_mask[amrlev]->const_arrays();
2422 auto const& vfrac_ma = vfrac.const_arrays();
2424 mf, IntVect(0), ncomp,
2425 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n)
2427 {
2428 if (mask_ma[box_no](i,j,k)) {
2429 return std::abs(ma[box_no](i,j,k,n)
2430 *vfrac_ma[box_no](i,j,k));
2431 } else {
2432 return Real(0.0);
2433 }
2434 });
2435 } else
2436#endif
2437 {
2438#ifdef AMREX_USE_OMP
2439#pragma omp parallel reduction(max:norm)
2440#endif
2441 for (MFIter mfi(mf,true); mfi.isValid(); ++mfi) {
2442 Box const& bx = mfi.tilebox();
2443 auto const& fab = mf.const_array(mfi);
2444 auto const& mask = m_norm_fine_mask[amrlev]->const_array(mfi);
2445 auto const& v = vfrac.const_array(mfi);
2446 AMREX_LOOP_4D(bx, ncomp, i, j, k, n,
2447 {
2448 if (mask(i,j,k)) {
2449 norm = std::max(norm, std::abs(fab(i,j,k,n)*v(i,j,k)));
2450 }
2451 });
2452 }
2453 }
2454 }
2455 }
2456 } else
2457#endif
2458 {
2459 if (amrlev == finest_level) {
2460 norm = mf.norminf(0, ncomp, IntVect(0), true);
2461 } else {
2462 norm = mf.norminf(*m_norm_fine_mask[amrlev], 0, ncomp, IntVect(0), true);
2463 }
2464 }
2465
2467 return norm;
2468}
2469
2470template <typename MF>
2471void
2473{
2474 int ncomp = this->getNComp();
2475 for (int falev = this->NAMRLevels()-1; falev > 0; --falev)
2476 {
2477#ifdef AMREX_USE_EB
2478 if (!sol[falev].isAllRegular()) {
2479 if constexpr (std::is_same<MF,MultiFab>()) {
2480 amrex::EB_average_down(sol[falev], sol[falev-1], 0, ncomp, this->AMRRefRatioVect(falev-1));
2481 } else {
2482 amrex::Abort("EB_average_down only works with MultiFab");
2483 }
2484 } else
2485#endif
2486 {
2487 amrex::average_down(sol[falev], sol[falev-1], 0, ncomp, this->AMRRefRatioVect(falev-1));
2488 }
2489 }
2490}
2491
2492template <typename MF>
2493void
2494MLCellLinOpT<MF>::avgDownResAmr (int clev, MF& cres, MF const& fres) const
2495{
2496#ifdef AMREX_USE_EB
2497 if (!fres.isAllRegular()) {
2498 if constexpr (std::is_same<MF,MultiFab>()) {
2499 amrex::EB_average_down(fres, cres, 0, this->getNComp(),
2500 this->AMRRefRatioVect(clev));
2501 } else {
2502 amrex::Abort("EB_average_down only works with MultiFab");
2503 }
2504 } else
2505#endif
2506 {
2507 amrex::average_down(fres, cres, 0, this->getNComp(),
2508 this->AMRRefRatioVect(clev));
2509 }
2510}
2511
2512template <typename MF>
2513void
2515{
2516 this->m_precond_mode = true;
2517
2518 if (m_bndry_sol_zero.empty()) {
2519 m_bndry_sol_zero.resize(m_bndry_sol.size());
2520 const int ncomp = this->getNComp();
2521 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
2522 m_bndry_sol_zero[amrlev] = std::make_unique<MLMGBndryT<MF>>
2523 (this->m_grids[amrlev][0],
2524 this->m_dmap[amrlev][0],
2525 ncomp,
2526 this->m_geom[amrlev][0]);
2527 }
2528 std::swap(m_bndry_sol, m_bndry_sol_zero);
2529 MF const* coarse_data_for_bc_save = this->m_coarse_data_for_bc;
2530 this->m_coarse_data_for_bc = nullptr;
2531 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
2532 this->setLevelBC(amrlev, nullptr);
2533 }
2534 this->m_coarse_data_for_bc = coarse_data_for_bc_save;
2535 } else {
2536 std::swap(m_bndry_sol, m_bndry_sol_zero);
2537 }
2538}
2539
2540template <typename MF>
2541void
2543{
2544 this->m_precond_mode = false;
2545 std::swap(m_bndry_sol, m_bndry_sol_zero);
2546}
2547
2548extern template class MLCellLinOpT<MultiFab>;
2549
2551
2552}
2553
2554#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:551
#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:124
#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
Array4< int const > offset
Definition AMReX_HypreMLABecLap.cpp:1129
Box cbx
Definition AMReX_HypreMLABecLap.cpp:1131
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
Array4< int const > mask
Definition AMReX_InterpFaceRegister.cpp:93
Array4< Real const > crse
Definition AMReX_InterpFaceRegister.cpp:92
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
Definition AMReX_Loop.nolint.H:16
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:676
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:672
Long size() const noexcept
Return the number of boxes in the BoxArray.
Definition AMReX_BoxArray.H:753
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
This static member function returns a constant reference to an object of type BoxND representing the ...
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:51
Definition AMReX_EBFabFactory.H:32
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:344
MultiArray4< typename FabArray< FAB >::value_type const > const_arrays() const noexcept
Definition AMReX_FabArray.H:647
Array4< typename FabArray< FAB >::value_type const > const_array(const MFIter &mfi) const noexcept
Definition AMReX_FabArray.H:585
Definition AMReX_FabFactory.H:50
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:75
Periodicity periodicity() const noexcept
Definition AMReX_Geometry.H:361
const Real * ProbLo() const noexcept
Returns the lo end of the problem domain in each dimension.
Definition AMReX_Geometry.H:184
GPU-compatible tuple.
Definition AMReX_Tuple.H:98
__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:517
__host__ __device__ IntVectND & setVal(int i, int val) noexcept
Set i'th coordinate of IntVectND to val.
Definition AMReX_IntVect.H:373
__host__ static __device__ constexpr IntVectND< dim > TheCellVector() noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:810
__host__ __device__ constexpr int max() const noexcept
maximum (no absolute values) value
Definition AMReX_IntVect.H:313
An InterpBndryData object adds to a BndryData object the ability to manipulate and set the data store...
Definition AMReX_InterpBndryData.H:45
static constexpr int IBD_max_order_DEF
Definition AMReX_InterpBndryData.H:126
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:172
Definition AMReX_MLCellLinOp.H:31
virtual void Fsmooth(int amrlev, int mglev, MF &sol, const MF &rhs, int redblack) const =0
Vector< RT > getSolvabilityOffset(int amrlev, int mglev, MF const &rhs) const override
Compute the average offset needed to enforce solvability constraints.
Definition AMReX_MLCellLinOp.H:1891
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:1522
void averageDownAndSync(Vector< MF > &sol) const override
Average the solution hierarchy down (fine-to-coarse) and sync.
Definition AMReX_MLCellLinOp.H:2472
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:1200
Vector< YAFluxRegisterT< MF > > m_fluxreg
Definition AMReX_MLCellLinOp.H:496
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:980
void updateSolBC(int amrlev, const MF &crse_bcdata) const
Refresh stored solution BC data from coarse inputs.
Definition AMReX_MLCellLinOp.H:949
Vector< std::unique_ptr< MLMGBndryT< MF > > > m_bndry_sol
Definition AMReX_MLCellLinOp.H:436
MLCellLinOpT< MF > & operator=(const MLCellLinOpT< MF > &)=delete
void compGrad(int amrlev, const Array< MF *, 3 > &grad, MF &sol, Location loc) const override
Compute directional gradients of the solution.
Definition AMReX_MLCellLinOp.H:1723
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:2494
void reflux(int crse_amrlev, MF &res, const MF &crse_sol, const MF &, MF &, MF &fine_sol, const MF &) const final
Reflux fine-level fluxes into the coarse residual.
Definition AMReX_MLCellLinOp.H:1613
RT dotProductPrecond(Vector< MF const * > const &x, Vector< MF const * > const &y) const final
Dot product over the composite AMR hierarchy, excluding cells covered by finer levels (used when the ...
Definition AMReX_MLCellLinOp.H:2279
virtual void Fapply(int amrlev, int mglev, MF &out, const MF &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:2542
void update() override
Update for reuse.
Definition AMReX_MLCellLinOp.H:942
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:1587
MLCellLinOpT(const MLCellLinOpT< MF > &)=delete
typename MLLinOpT< MF >::BCMode BCMode
Definition AMReX_MLCellLinOp.H:38
void smooth(int amrlev, int mglev, MF &sol, const MF &rhs, bool skip_fillboundary, int niter) const final
Perform niter smoothing iterations on the supplied residual equation.
Definition AMReX_MLCellLinOp.H:1543
RT normInf(int amrlev, MF const &mf, bool local) const override
Infinity norm helper used by solvers and diagnostics.
Definition AMReX_MLCellLinOp.H:2372
virtual bool isCrossStencil() const
Whether the stencil is the cross shape.
Definition AMReX_MLCellLinOp.H:107
void updateCorBC(int amrlev, const MF &crse_bcdata) const
Refresh stored correction BC data from coarse inputs.
Definition AMReX_MLCellLinOp.H:965
Array< RT, 2 *3 > RealTuple
Definition AMReX_MLCellLinOp.H:447
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:1259
RT xdoty(int amrlev, int mglev, const MF &x, const MF &y, bool local) const final
Dot product helper.
Definition AMReX_MLCellLinOp.H:2265
Array< BoundCond, 2 *3 > BCTuple
Definition AMReX_MLCellLinOp.H:448
void prepareForSolve() override
Prepare multilevel metadata before MLMG iterates (coefficients, BC caches, etc.).
Definition AMReX_MLCellLinOp.H:1948
void unapplyMetricTerm(int amrlev, int mglev, MF &rhs) const final
Remove metric scaling previously applied to the RHS.
Definition AMReX_MLCellLinOp.H:1833
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:1533
void applyMetricTerm(int amrlev, int mglev, MF &rhs) const final
Multiply the RHS by metric terms appropriate for curvilinear coordinates.
Definition AMReX_MLCellLinOp.H:1777
Vector< std::unique_ptr< BndryRegisterT< MF > > > m_crse_cor_br
Definition AMReX_MLCellLinOp.H:440
RT norm2Precond(Vector< MF const * > const &x) const final
L2 norm over the composite AMR hierarchy, excluding cells covered by finer levels (used when the oper...
Definition AMReX_MLCellLinOp.H:2295
void beginPrecondBC() override
Called when the operator starts being used as a preconditioner.
Definition AMReX_MLCellLinOp.H:2514
Vector< Vector< std::unique_ptr< BndryCondLoc > > > m_bcondloc
Definition AMReX_MLCellLinOp.H:486
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:1250
void setGaussSeidel(bool flag) noexcept
Toggle Gauss–Seidel smoothing in place of Jacobi relaxation.
Definition AMReX_MLCellLinOp.H:104
Vector< std::unique_ptr< MF > > m_robin_bcval
Definition AMReX_MLCellLinOp.H:423
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:648
~MLCellLinOpT() override=default
virtual bool isTensorOp() const
Whether this operator is a tensor solve.
Definition AMReX_MLCellLinOp.H:109
void setInterpBndryHalfWidth(int w)
Control how many cells the interpolation boundary stencil spans.
Definition AMReX_MLCellLinOp.H:430
Vector< Vector< BndryRegisterT< MF > > > m_undrrelxr
Definition AMReX_MLCellLinOp.H:489
MLCellLinOpT()
Definition AMReX_MLCellLinOp.H:641
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:1308
void fixSolvabilityByOffset(int amrlev, int mglev, MF &rhs, Vector< RT > const &offset) const override
Apply solvability offsets to the RHS (subtracting the average).
Definition AMReX_MLCellLinOp.H:1928
Vector< std::unique_ptr< MLMGBndryT< MF > > > m_bndry_cor
Definition AMReX_MLCellLinOp.H:439
void compFlux(int amrlev, const Array< MF *, 3 > &fluxes, MF &sol, Location loc) const override
Compute face-centered fluxes from the supplied solution.
Definition AMReX_MLCellLinOp.H:1682
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:1578
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:1560
bool m_has_metric_term
Definition AMReX_MLCellLinOp.H:434
bool m_use_gauss_seidel
Definition AMReX_MLCellLinOp.H:498
Vector< std::unique_ptr< MLMGBndryT< MF > > > m_bndry_sol_zero
Definition AMReX_MLCellLinOp.H:442
Vector< std::unique_ptr< BndryRegisterT< MF > > > m_crse_sol_br
Definition AMReX_MLCellLinOp.H:437
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:1401
virtual void addInhomogNeumannFlux(int, const Array< MF *, 3 > &, MF const &, bool) const
Optional hook for adding inhomogeneous Neumann contributions.
Definition AMReX_MLCellLinOp.H:381
Vector< std::unique_ptr< iMultiFab > > m_norm_fine_mask
Definition AMReX_MLCellLinOp.H:494
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:809
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:492
virtual void FFlux(int amrlev, const MFIter &mfi, const Array< FAB *, 3 > &flux, const FAB &sol, Location loc, int face_only=0) const =0
Abstract base class for multilevel linear operators used by MLMG and the bottom solvers.
Definition AMReX_MLLinOp.H:137
virtual bool needsUpdate() const
Does it need update if it's reused?
Definition AMReX_MLLinOp.H:332
virtual void update()
Update for reuse.
Definition AMReX_MLLinOp.H:334
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:1056
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
Dynamically allocated vector for trivially copyable data.
Definition AMReX_PODVector.H:308
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:79
__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:1848
__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:1817
__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:1582
__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:1469
__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:1880
__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:1548
__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:1326
std::array< T, N > Array
Definition AMReX_Array.H:31
Arena * The_Async_Arena()
Definition AMReX_Arena.cpp:830
void Sum(Gpu::DeviceVector< T > &v, MPI_Comm comm)
Definition AMReX_GpuParallelReduce.H:34
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:310
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:259
__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:359
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:652
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:1609
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:252
LinOpBCType
Definition AMReX_LO_BCTYPES.H:27
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
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
RealVectND< 3 > RealVect
Definition AMReX_ParmParse.H:37
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:241
__host__ __device__ constexpr int get(IntVectND< dim > const &iv) noexcept
Get I'th element of IntVectND<dim>
Definition AMReX_IntVect.H:1334
A multidimensional array accessor.
Definition AMReX_Array4.H:288
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
Definition AMReX_FabDataType.H:10
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:51
StateMode
Definition AMReX_MLLinOp.H:118
BCMode
Definition AMReX_MLLinOp.H:117
Location
Definition AMReX_MLLinOp.H:119
FabArray memory allocation information.
Definition AMReX_FabArray.H:68
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:156
Struct for holding types.
Definition AMReX_TypeList.H:13