1#ifndef AMREX_ML_ABECLAPLACIAN_H_
2#define AMREX_ML_ABECLAPLACIAN_H_
3#include <AMReX_Config.H>
6#include <AMReX_MLABecLap_K.H>
25 using FAB =
typename MF::fab_type;
26 using RT =
typename MF::value_type;
98 template <
typename T1,
typename T2>
99 requires (std::is_convertible_v<T1, typename MF::value_type> && std::is_convertible_v<T2, typename MF::value_type>)
111 template <FabArrayType AMF>
112 requires (std::is_convertible_v<typename AMF::value_type, typename MF::value_type>)
113 void setACoeffs (
int amrlev,
const AMF& alpha);
124 template <
typename T>
125 requires (std::is_convertible_v<T, typename MF::value_type>)
137 template <FabArrayType AMF>
138 requires (std::is_convertible_v<typename AMF::value_type, typename MF::value_type>)
139 void setBCoeffs (
int amrlev,
const Array<AMF const*,AMREX_SPACEDIM>& beta);
150 template <
typename T>
151 requires (std::is_convertible_v<T, typename MF::value_type>)
163 template <
typename T>
164 requires (std::is_convertible_v<T, typename MF::value_type>)
165 void setBCoeffs (
int amrlev, Vector<T>
const& beta);
167 [[nodiscard]]
int getNComp ()
const override {
return m_ncomp; }
186 void Fapply (
int amrlev,
int mglev, MF& out,
const MF& in)
const override;
192 void Fsmooth (
int amrlev,
int mglev, MF& sol,
const MF& rhs,
int redblack)
const override;
201 int face_only=0)
const override;
204 void normalize (
int amrlev,
int mglev, MF& mf)
const override;
211 [[nodiscard]] MF
const*
getACoeffs (
int amrlev,
int mglev)
const final
218 [[nodiscard]] std::unique_ptr<MLLinOpT<MF>>
makeNLinOp (
int )
const final;
255 FAB const& sol,
int face_only,
int ncomp);
273 bool m_needs_update =
true;
277 void define_ab_coeffs ();
279 void update_singular_flags ();
282template <
typename MF>
290 define(a_geom, a_grids, a_dmap, a_info, a_factory, a_ncomp);
293template <
typename MF>
302 define(a_geom, a_grids, a_dmap, a_overset_mask, a_info, a_factory, a_ncomp);
307template <
typename MF>
317 this->m_ncomp = a_ncomp;
322template <
typename MF>
332 BL_PROFILE(
"MLABecLaplacian::define(overset)");
333 this->m_ncomp = a_ncomp;
338template <
typename MF>
342 m_a_coeffs.resize(this->m_num_amr_levels);
343 m_b_coeffs.resize(this->m_num_amr_levels);
344 for (
int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
346 m_a_coeffs[amrlev].resize(this->m_num_mg_levels[amrlev]);
347 m_b_coeffs[amrlev].resize(this->m_num_mg_levels[amrlev]);
348 for (
int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
350 m_a_coeffs[amrlev][mglev].
define
351 (this->m_grids[amrlev][mglev], this->m_dmap[amrlev][mglev],
352 1, 0,
MFInfo(), *(this->m_factory[amrlev][mglev]));
353 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim)
357 m_b_coeffs[amrlev][mglev][idim].define
358 (ba, this->m_dmap[amrlev][mglev], m_ncomp, 0,
MFInfo(),
359 *(this->m_factory[amrlev][mglev]));
365template <
typename MF>
366template <
typename T1,
typename T2>
367requires (std::is_convertible_v<T1, typename MF::value_type> && std::is_convertible_v<T2, typename MF::value_type>)
373 if (m_a_scalar ==
RT(0.0)) {
374 for (
int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
375 m_a_coeffs[amrlev][0].setVal(
RT(0.0));
379 m_scalars_set =
true;
382template <
typename MF>
383template <FabArrayType AMF>
384requires (std::is_convertible_v<typename AMF::value_type, typename MF::value_type>)
389 "MLABecLaplacian::setACoeffs: alpha is supposed to be single component.");
390 m_a_coeffs[amrlev][0].LocalCopy(alpha, 0, 0, 1,
IntVect(0));
391 m_needs_update =
true;
395template <
typename MF>
397requires (std::is_convertible_v<T, typename MF::value_type>)
401 m_a_coeffs[amrlev][0].setVal(
RT(alpha));
402 m_needs_update =
true;
407template <
typename MF>
408template <FabArrayType AMF>
409requires (std::is_convertible_v<typename AMF::value_type, typename MF::value_type>)
414 const int ncomp = this->getNComp();
416 if (beta[0]->
nComp() == ncomp) {
417 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
418 for (
int icomp = 0; icomp < ncomp; ++icomp) {
419 m_b_coeffs[amrlev][0][idim].LocalCopy(*beta[idim], icomp, icomp, 1,
IntVect(0));
423 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
424 for (
int icomp = 0; icomp < ncomp; ++icomp) {
425 m_b_coeffs[amrlev][0][idim].LocalCopy(*beta[idim], 0, icomp, 1,
IntVect(0));
429 m_needs_update =
true;
432template <
typename MF>
434requires (std::is_convertible_v<T, typename MF::value_type>)
438 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
439 m_b_coeffs[amrlev][0][idim].setVal(
RT(beta));
441 m_needs_update =
true;
444template <
typename MF>
446requires (std::is_convertible_v<T, typename MF::value_type>)
450 const int ncomp = this->getNComp();
451 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
452 for (
int icomp = 0; icomp < ncomp; ++icomp) {
453 m_b_coeffs[amrlev][0][idim].setVal(
RT(beta[icomp]), icomp, 1, 0);
456 m_needs_update =
true;
459template <
typename MF>
467#if (AMREX_SPACEDIM != 3)
468 applyMetricTermsCoeffs();
471 applyRobinBCTermsCoeffs();
475 update_singular_flags();
477 m_needs_update =
false;
480template <
typename MF>
484 BL_PROFILE(
"MLABecLaplacian::prepareForSolve()");
488#if (AMREX_SPACEDIM != 3)
489 applyMetricTermsCoeffs();
492 applyRobinBCTermsCoeffs();
496 update_singular_flags();
498 m_needs_update =
false;
501template <
typename MF>
505#if (AMREX_SPACEDIM != 3)
506 for (
int alev = 0; alev < this->m_num_amr_levels; ++alev)
509 this->applyMetricTerm(alev, mglev, m_a_coeffs[alev][mglev]);
510 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim)
512 this->applyMetricTerm(alev, mglev, m_b_coeffs[alev][mglev][idim]);
547template <
typename LP>
548void applyRobinBCTermsCoeffs (LP& linop)
550 using RT =
typename LP::RT;
552 const int ncomp = linop.getNComp();
553 bool reset_alpha =
false;
554 if (linop.m_a_scalar == RT(0.0)) {
555 linop.m_a_scalar = RT(1.0);
558 const RT bovera = linop.m_b_scalar/linop.m_a_scalar;
562 "To reuse solver With Robin BC, one must re-call setScalars (and setACoeffs if the scalar is not zero)");
565 linop.m_scalars_set =
false;
566 linop.m_acoef_set =
false;
568 for (
int amrlev = 0; amrlev < linop.NAMRLevels(); ++amrlev) {
570 const Box& domain = linop.Geom(amrlev,mglev).Domain();
571 const RT dxi =
static_cast<RT
>(linop.Geom(amrlev,mglev).InvCellSize(0));
572 const RT dyi =
static_cast<RT
>((AMREX_SPACEDIM >= 2) ? linop.Geom(amrlev,mglev).InvCellSize(1) :
Real(1.0));
573 const RT dzi =
static_cast<RT
>((AMREX_SPACEDIM == 3) ? linop.Geom(amrlev,mglev).InvCellSize(2) :
Real(1.0));
576 linop.m_a_coeffs[amrlev][mglev].setVal(RT(0.0));
583#pragma omp parallel if (Gpu::notInLaunchRegion())
585 for (MFIter mfi(linop.m_a_coeffs[amrlev][mglev], mfi_info); mfi.isValid(); ++mfi)
587 const Box& vbx = mfi.validbox();
588 auto const& afab = linop.m_a_coeffs[amrlev][mglev].array(mfi);
589 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
590 auto const& bfab = linop.m_b_coeffs[amrlev][mglev][idim].const_array(mfi);
593 bool outside_domain_lo = !(domain.contains(blo));
594 bool outside_domain_hi = !(domain.contains(bhi));
595 if ((!outside_domain_lo) && (!outside_domain_hi)) {
continue; }
596 for (
int icomp = 0; icomp < ncomp; ++icomp) {
597 auto const& rbc = (*(linop.m_robin_bcval[amrlev]))[mfi].const_array(icomp*3);
601 RT fac = bovera*dxi*dxi;
604 RT B = (rbc(i,j,k,1)*dxi - rbc(i,j,k,0)*RT(0.5))
605 / (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
606 afab(i+1,j,k,icomp) += fac*bfab(i+1,j,k,icomp)*(RT(1.0)-B);
608 }
else if (idim == 1) {
609 RT fac = bovera*dyi*dyi;
612 RT B = (rbc(i,j,k,1)*dyi - rbc(i,j,k,0)*RT(0.5))
613 / (rbc(i,j,k,1)*dyi + rbc(i,j,k,0)*RT(0.5));
614 afab(i,j+1,k,icomp) += fac*bfab(i,j+1,k,icomp)*(RT(1.0)-B);
617 RT fac = bovera*dzi*dzi;
620 RT B = (rbc(i,j,k,1)*dzi - rbc(i,j,k,0)*RT(0.5))
621 / (rbc(i,j,k,1)*dzi + rbc(i,j,k,0)*RT(0.5));
622 afab(i,j,k+1,icomp) += fac*bfab(i,j,k+1,icomp)*(RT(1.0)-B);
629 RT fac = bovera*dxi*dxi;
632 RT B = (rbc(i,j,k,1)*dxi - rbc(i,j,k,0)*RT(0.5))
633 / (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
634 afab(i-1,j,k,icomp) += fac*bfab(i,j,k,icomp)*(RT(1.0)-B);
636 }
else if (idim == 1) {
637 RT fac = bovera*dyi*dyi;
640 RT B = (rbc(i,j,k,1)*dyi - rbc(i,j,k,0)*RT(0.5))
641 / (rbc(i,j,k,1)*dyi + rbc(i,j,k,0)*RT(0.5));
642 afab(i,j-1,k,icomp) += fac*bfab(i,j,k,icomp)*(RT(1.0)-B);
645 RT fac = bovera*dzi*dzi;
648 RT B = (rbc(i,j,k,1)*dzi - rbc(i,j,k,0)*RT(0.5))
649 / (rbc(i,j,k,1)*dzi + rbc(i,j,k,0)*RT(0.5));
650 afab(i,j,k-1,icomp) += fac*bfab(i,j,k,icomp)*(RT(1.0)-B);
662template <
typename MF>
666 if (this->hasRobinBC()) {
667 detail::applyRobinBCTermsCoeffs(*
this);
671template <
typename MF>
675 BL_PROFILE(
"MLABecLaplacian::averageDownCoeffs()");
677 for (
int amrlev = this->m_num_amr_levels-1; amrlev > 0; --amrlev)
679 auto& fine_a_coeffs = m_a_coeffs[amrlev];
680 auto& fine_b_coeffs = m_b_coeffs[amrlev];
682 averageDownCoeffsSameAmrLevel(amrlev, fine_a_coeffs, fine_b_coeffs);
683 averageDownCoeffsToCoarseAmrLevel(amrlev);
686 averageDownCoeffsSameAmrLevel(0, m_a_coeffs[0], m_b_coeffs[0]);
689template <
typename MF>
694 int nmglevs = a.
size();
695 for (
int mglev = 1; mglev < nmglevs; ++mglev)
697 IntVect ratio = (amrlev > 0) ?
IntVect(this->mg_coarsen_ratio) : this->mg_coarsen_ratio_vec[mglev-1];
699 if (m_a_scalar == 0.0)
701 a[mglev].setVal(
RT(0.0));
718 for (
int mglev = 1; mglev < nmglevs; ++mglev)
720 if (this->m_overset_mask[amrlev][mglev]) {
721 const RT fac =
static_cast<RT>(1 << mglev);
722 const RT osfac =
RT(2.0)*fac/(fac+
RT(1.0));
723 const int ncomp = this->getNComp();
725#pragma omp parallel if (Gpu::notInLaunchRegion())
730 Box const& ybx = mfi.nodaltilebox(1);,
731 Box const& zbx = mfi.nodaltilebox(2));
733 auto const& by = b[mglev][1].array(mfi);,
734 auto const& bz = b[mglev][2].array(mfi));
735 auto const& osm = this->m_overset_mask[amrlev][mglev]->const_array(mfi);
736#if defined(AMREX_USE_CUDA) && defined(_WIN32)
740 overset_rescale_bcoef_x(t_xbx, bx, osm, ncomp, osfac);
742#if (AMREX_SPACEDIM >= 2)
746 overset_rescale_bcoef_y(t_ybx, by, osm, ncomp, osfac);
749#if (AMREX_SPACEDIM == 3)
753 overset_rescale_bcoef_z(t_zbx, bz, osm, ncomp, osfac);
760 overset_rescale_bcoef_x(t_xbx, bx, osm, ncomp, osfac);
764 overset_rescale_bcoef_y(t_ybx, by, osm, ncomp, osfac);
768 overset_rescale_bcoef_z(t_zbx, bz, osm, ncomp, osfac);
776template <
typename MF>
780 auto& fine_a_coeffs = m_a_coeffs[flev ].back();
781 auto& fine_b_coeffs = m_b_coeffs[flev ].back();
782 auto& crse_a_coeffs = m_a_coeffs[flev-1].front();
783 auto& crse_b_coeffs = m_b_coeffs[flev-1].front();
785 if (m_a_scalar != 0.0) {
793 IntVect(this->mg_coarsen_ratio),
794 this->m_geom[flev-1][0]);
797template <
typename MF>
801 m_is_singular.clear();
802 m_is_singular.resize(this->m_num_amr_levels,
false);
803 auto itlo = std::ranges::find(this->m_lobc[0], BCType::Dirichlet);
804 auto ithi = std::ranges::find(this->m_hibc[0], BCType::Dirichlet);
805 if (itlo == this->m_lobc[0].
end() && ithi == this->m_hibc[0].
end())
807 for (
int alev = 0; alev < this->m_num_amr_levels; ++alev)
810 if (this->m_domain_covered[alev] && !this->m_overset_mask[alev][0])
812 if (m_a_scalar ==
Real(0.0))
814 m_is_singular[alev] =
true;
818 RT asum = m_a_coeffs[alev].back().sum(0,
IntVect(0));
819 RT amax = m_a_coeffs[alev].back().norminf(0,1,
IntVect(0));
820 m_is_singular[alev] = (std::abs(asum) <= amax * RT(1.e-12));
826 if (!m_is_singular[0] && this->m_needs_coarse_data_for_bc &&
831 bool lev0_a_is_zero =
false;
832 if (m_a_scalar ==
Real(0.0)) {
833 lev0_a_is_zero =
true;
835 RT asum = m_a_coeffs[0].back().sum(0,
IntVect(0));
836 RT amax = m_a_coeffs[0].back().norminf(0,1,
IntVect(0));
837 bool a_is_almost_zero = std::abs(asum) <= amax * RT(1.e-12);
838 if (a_is_almost_zero) { lev0_a_is_zero =
true; }
841 if (lev0_a_is_zero) {
842 auto bbox = this->m_grids[0][0].minimalBox();
843 for (
int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
851 if (this->m_geom[0][0].Domain().contains(bbox)) {
852 m_is_singular[0] =
true;
858template <
typename MF>
864 const MF& acoef = m_a_coeffs[amrlev][mglev];
865 AMREX_D_TERM(
const MF& bxcoef = m_b_coeffs[amrlev][mglev][0];,
866 const MF& bycoef = m_b_coeffs[amrlev][mglev][1];,
867 const MF& bzcoef = m_b_coeffs[amrlev][mglev][2];);
870 {
AMREX_D_DECL(
static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0)),
871 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(1)),
872 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(2)))};
874 const RT ascalar = m_a_scalar;
875 const RT bscalar = m_b_scalar;
877 const int ncomp = this->getNComp();
881 const auto& xma = in.const_arrays();
882 const auto& yma = out.arrays();
883 const auto& ama = acoef.arrays();
885 const auto& byma = bycoef.const_arrays();,
886 const auto& bzma = bzcoef.const_arrays(););
887 if (this->m_overset_mask[amrlev][mglev]) {
888 const auto& osmma = this->m_overset_mask[amrlev][mglev]->const_arrays();
892 mlabeclap_adotx_os(i,j,k,n, yma[box_no], xma[box_no], ama[box_no],
894 osmma[box_no], dxinv, ascalar, bscalar);
900 mlabeclap_adotx(i,j,k,n, yma[box_no], xma[box_no], ama[box_no],
902 dxinv, ascalar, bscalar);
912#pragma omp parallel if (Gpu::notInLaunchRegion())
916 const Box& bx = mfi.tilebox();
917 const auto& xfab = in.array(mfi);
918 const auto& yfab = out.array(mfi);
919 const auto& afab = acoef.array(mfi);
921 const auto& byfab = bycoef.array(mfi);,
922 const auto& bzfab = bzcoef.array(mfi););
923 if (this->m_overset_mask[amrlev][mglev]) {
924 const auto& osm = this->m_overset_mask[amrlev][mglev]->const_array(mfi);
927 mlabeclap_adotx_os(i,j,k,n, yfab, xfab, afab,
AMREX_D_DECL(bxfab,byfab,bzfab),
928 osm, dxinv, ascalar, bscalar);
933 mlabeclap_adotx(i,j,k,n, yfab, xfab, afab,
AMREX_D_DECL(bxfab,byfab,bzfab),
934 dxinv, ascalar, bscalar);
941template <
typename MF>
947 bool regular_coarsening =
true;
948 if (amrlev == 0 && mglev > 0) {
949 regular_coarsening = this->mg_coarsen_ratio_vec[mglev-1] == this->mg_coarsen_ratio;
953 if (! this->m_use_gauss_seidel && regular_coarsening) {
954 Ax.define(sol.boxArray(), sol.DistributionMap(), sol.nComp(), 0);
955 Fapply(amrlev, mglev, Ax, sol);
958 const MF& acoef = m_a_coeffs[amrlev][mglev];
960 AMREX_D_TERM(
const MF& bxcoef = m_b_coeffs[amrlev][mglev][0];,
961 const MF& bycoef = m_b_coeffs[amrlev][mglev][1];,
962 const MF& bzcoef = m_b_coeffs[amrlev][mglev][2];);
963 const auto& undrrelxr = this->m_undrrelxr[amrlev][mglev];
964 const auto& maskvals = this->m_maskvals [amrlev][mglev];
968 const auto& f0 = undrrelxr[oitr()]; ++oitr;
969 const auto& f1 = undrrelxr[oitr()]; ++oitr;
970#if (AMREX_SPACEDIM > 1)
971 const auto& f2 = undrrelxr[oitr()]; ++oitr;
972 const auto& f3 = undrrelxr[oitr()]; ++oitr;
973#if (AMREX_SPACEDIM > 2)
974 const auto& f4 = undrrelxr[oitr()]; ++oitr;
975 const auto& f5 = undrrelxr[oitr()]; ++oitr;
981#if (AMREX_SPACEDIM > 1)
984#if (AMREX_SPACEDIM > 2)
990 const int nc = this->getNComp();
991 const Real* h = this->m_geom[amrlev][mglev].CellSize();
993 const RT dhy = m_b_scalar/
static_cast<RT>(h[1]*h[1]);,
994 const RT dhz = m_b_scalar/
static_cast<RT>(h[2]*h[2]));
995 const RT alpha = m_a_scalar;
999 && (this->m_overset_mask[amrlev][mglev] || regular_coarsening))
1003#if (AMREX_SPACEDIM > 1)
1006#if (AMREX_SPACEDIM > 2)
1012 const auto& solnma = sol.arrays();
1013 const auto& rhsma = rhs.const_arrays();
1014 const auto& ama = acoef.const_arrays();
1016 AMREX_D_TERM(
const auto& bxma = bxcoef.const_arrays();,
1017 const auto& byma = bycoef.const_arrays();,
1018 const auto& bzma = bzcoef.const_arrays(););
1020 const auto& f0ma = f0.const_arrays();
1021 const auto& f1ma = f1.const_arrays();
1022#if (AMREX_SPACEDIM > 1)
1023 const auto& f2ma = f2.const_arrays();
1024 const auto& f3ma = f3.const_arrays();
1025#if (AMREX_SPACEDIM > 2)
1026 const auto& f4ma = f4.const_arrays();
1027 const auto& f5ma = f5.const_arrays();
1031 if (this->m_overset_mask[amrlev][mglev]) {
1032 const auto& osmma = this->m_overset_mask[amrlev][mglev]->const_arrays();
1033 if (this->m_use_gauss_seidel) {
1037 Box vbx(ama[box_no]);
1038 abec_gsrb_os(i,j,k,n, solnma[box_no], rhsma[box_no], alpha, ama[box_no],
1045 osmma[box_no], vbx, redblack);
1048 const auto& axma = Ax.const_arrays();
1052 Box vbx(ama[box_no]);
1053 abec_jacobi_os(i,j,k,n, solnma[box_no], rhsma[box_no], axma[box_no],
1061 osmma[box_no], vbx);
1064 }
else if (regular_coarsening) {
1065 if (this->m_use_gauss_seidel) {
1069 Box vbx(ama[box_no]);
1070 abec_gsrb(i,j,k,n, solnma[box_no], rhsma[box_no], alpha, ama[box_no],
1080 const auto& axma = Ax.const_arrays();
1084 Box vbx(ama[box_no]);
1085 abec_jacobi(i,j,k,n, solnma[box_no], rhsma[box_no], axma[box_no],
1107#pragma omp parallel if (Gpu::notInLaunchRegion())
1111 const auto& m0 = mm0.
array(mfi);
1112 const auto& m1 = mm1.
array(mfi);
1113#if (AMREX_SPACEDIM > 1)
1114 const auto& m2 = mm2.
array(mfi);
1115 const auto& m3 = mm3.
array(mfi);
1116#if (AMREX_SPACEDIM > 2)
1117 const auto& m4 = mm4.
array(mfi);
1118 const auto& m5 = mm5.
array(mfi);
1122 const Box& tbx = mfi.tilebox();
1123 const Box& vbx = mfi.validbox();
1124 const auto& solnfab = sol.array(mfi);
1125 const auto& rhsfab = rhs.const_array(mfi);
1126 const auto& afab = acoef.const_array(mfi);
1128 AMREX_D_TERM(
const auto& bxfab = bxcoef.const_array(mfi);,
1129 const auto& byfab = bycoef.const_array(mfi);,
1130 const auto& bzfab = bzcoef.const_array(mfi););
1132 const auto& f0fab = f0.const_array(mfi);
1133 const auto& f1fab = f1.const_array(mfi);
1134#if (AMREX_SPACEDIM > 1)
1135 const auto& f2fab = f2.const_array(mfi);
1136 const auto& f3fab = f3.const_array(mfi);
1137#if (AMREX_SPACEDIM > 2)
1138 const auto& f4fab = f4.const_array(mfi);
1139 const auto& f5fab = f5.const_array(mfi);
1143 if (this->m_overset_mask[amrlev][mglev]) {
1144 const auto& osm = this->m_overset_mask[amrlev][mglev]->const_array(mfi);
1145 if (this->m_use_gauss_seidel) {
1148 abec_gsrb_os(i,j,k,n, solnfab, rhsfab, alpha, afab,
1155 osm, vbx, redblack);
1158 const auto& axfab = Ax.const_array(mfi);
1161 abec_jacobi_os(i,j,k,n, solnfab, rhsfab, axfab,
1172 }
else if (regular_coarsening) {
1173 if (this->m_use_gauss_seidel) {
1176 abec_gsrb(i,j,k,n, solnfab, rhsfab, alpha, afab,
1186 const auto& axfab = Ax.const_array(mfi);
1189 abec_jacobi(i,j,k,n, solnfab, rhsfab, axfab,
1202 abec_gsrb_with_line_solve(tbx, solnfab, rhsfab, alpha, afab,
1215template <
typename MF>
1223 const int mglev = 0;
1225 const Real* dxinv = this->m_geom[amrlev][mglev].InvCellSize();
1226 const int ncomp = this->getNComp();
1227 FFlux(box, dxinv, m_b_scalar,
1229 &(m_b_coeffs[amrlev][mglev][1][mfi]),
1230 &(m_b_coeffs[amrlev][mglev][2][mfi]))}},
1231 flux, sol, face_only, ncomp);
1234template <
typename MF>
1239 FAB const& sol,
int face_only,
int ncomp)
1242 const auto by = bcoef[1]->const_array();,
1243 const auto bz = bcoef[2]->const_array(););
1245 const auto& fyarr = flux[1]->array();,
1246 const auto& fzarr = flux[2]->array(););
1247 const auto& solarr = sol.array();
1251 RT fac = bscalar*
static_cast<RT>(dxinv[0]);
1253 int blen = box.
length(0);
1256 mlabeclap_flux_xface(tbox, fxarr, solarr, bx, fac, blen, ncomp);
1258#if (AMREX_SPACEDIM >= 2)
1259 fac = bscalar*
static_cast<RT>(dxinv[1]);
1264 mlabeclap_flux_yface(tbox, fyarr, solarr, by, fac, blen, ncomp);
1267#if (AMREX_SPACEDIM == 3)
1268 fac = bscalar*
static_cast<RT>(dxinv[2]);
1273 mlabeclap_flux_zface(tbox, fzarr, solarr, bz, fac, blen, ncomp);
1279 RT fac = bscalar*
static_cast<RT>(dxinv[0]);
1283 mlabeclap_flux_x(tbox, fxarr, solarr, bx, fac, ncomp);
1285#if (AMREX_SPACEDIM >= 2)
1286 fac = bscalar*
static_cast<RT>(dxinv[1]);
1290 mlabeclap_flux_y(tbox, fyarr, solarr, by, fac, ncomp);
1293#if (AMREX_SPACEDIM == 3)
1294 fac = bscalar*
static_cast<RT>(dxinv[2]);
1298 mlabeclap_flux_z(tbox, fzarr, solarr, bz, fac, ncomp);
1304template <
typename MF>
1310 const auto& acoef = m_a_coeffs[amrlev][mglev];
1311 AMREX_D_TERM(
const auto& bxcoef = m_b_coeffs[amrlev][mglev][0];,
1312 const auto& bycoef = m_b_coeffs[amrlev][mglev][1];,
1313 const auto& bzcoef = m_b_coeffs[amrlev][mglev][2];);
1316 {
AMREX_D_DECL(
static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0)),
1317 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(1)),
1318 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(2)))};
1320 const RT ascalar = m_a_scalar;
1321 const RT bscalar = m_b_scalar;
1323 const int ncomp = getNComp();
1327 const auto& ma = mf.arrays();
1328 const auto& ama = acoef.const_arrays();
1329 AMREX_D_TERM(
const auto& bxma = bxcoef.const_arrays();,
1330 const auto& byma = bycoef.const_arrays();,
1331 const auto& bzma = bzcoef.const_arrays(););
1335 mlabeclap_normalize(i,j,k,n, ma[box_no], ama[box_no],
1337 dxinv, ascalar, bscalar);
1346#pragma omp parallel if (Gpu::notInLaunchRegion())
1350 const Box& bx = mfi.tilebox();
1351 const auto& fab = mf.array(mfi);
1352 const auto& afab = acoef.array(mfi);
1354 const auto& byfab = bycoef.array(mfi);,
1355 const auto& bzfab = bzcoef.array(mfi););
1359 mlabeclap_normalize(i,j,k,n, fab, afab,
AMREX_D_DECL(bxfab,byfab,bzfab),
1360 dxinv, ascalar, bscalar);
1366template <
typename MF>
1370 bool support =
false;
1371 if (this->m_overset_mask[0][0]) {
1373 this->mg_domain_min_width)
1382template <
typename MF>
1383std::unique_ptr<MLLinOpT<MF>>
1386 if (this->m_overset_mask[0][0] ==
nullptr) {
return nullptr; }
1388 const Geometry& geom = this->m_geom[0].back();
1389 const BoxArray& ba = this->m_grids[0].back();
1392 std::unique_ptr<MLLinOpT<MF>> r
1402 nop->setMaxOrder(this->maxorder);
1403 nop->setVerbose(this->verbose);
1405 nop->setDomainBC(this->m_lobc, this->m_hibc);
1407 if (this->needsCoarseDataForBC())
1409 const Real* dx0 = this->m_geom[0][0].CellSize();
1410 RealVect fac(this->m_coarse_data_crse_ratio);
1413 nop->setCoarseFineBCLocation(cbloc);
1416 nop->setScalars(m_a_scalar, m_b_scalar);
1418 MF
const& alpha_bottom = m_a_coeffs[0].back();
1419 iMultiFab const& osm_bottom = *(this->m_overset_mask[0].back());
1420 const int ncomp = alpha_bottom.
nComp();
1421 MF alpha(ba, dm, ncomp, 0);
1423 RT a_max = alpha_bottom.norminf(0, ncomp,
IntVect(0),
true,
true);
1424 const int ncomp_b = m_b_coeffs[0].back()[0].nComp();
1426 RT by_max = m_b_coeffs[0].back()[1].
norminf(0,ncomp_b,
IntVect(0),
true,
true);,
1427 RT bz_max = m_b_coeffs[0].back()[2].
norminf(0,ncomp_b,
IntVect(0),
true,
true));
1432 RT huge_alpha =
RT(1.e30) *
1434 AMREX_D_DECL(std::abs(m_b_scalar)*bx_max*dxinv[0]*dxinv[0],
1435 std::abs(m_b_scalar)*by_max*dxinv[1]*dxinv[1],
1436 std::abs(m_b_scalar)*bz_max*dxinv[2]*dxinv[2]));
1441 auto const& ama = alpha.arrays();
1442 auto const& abotma = alpha_bottom.const_arrays();
1447 if (mma[box_no](i,j,k)) {
1448 ama[box_no](i,j,k,n) = abotma[box_no](i,j,k,n);
1450 ama[box_no](i,j,k,n) = huge_alpha;
1460#pragma omp parallel if (Gpu::notInLaunchRegion())
1463 Box const& bx = mfi.tilebox();
1464 auto const& a = alpha.array(mfi);
1465 auto const& abot = alpha_bottom.const_array(mfi);
1470 a(i,j,k,n) = abot(i,j,k,n);
1472 a(i,j,k,n) = huge_alpha;
1478 nop->setACoeffs(0, alpha);
1484template <
typename MF>
1488 if (this->m_overset_mask[0].back() ==
nullptr) {
return; }
1490 const int ncomp = dst.nComp();
1494 auto const& dstma = dst.arrays();
1495 auto const& srcma = src.const_arrays();
1496 auto const& mma = this->m_overset_mask[0].back()->const_arrays();
1500 if (mma[box_no](i,j,k)) {
1501 dstma[box_no](i,j,k,n) = srcma[box_no](i,j,k,n);
1503 dstma[box_no](i,j,k,n) =
RT(0.0);
1513#pragma omp parallel if (Gpu::notInLaunchRegion())
1516 Box const& bx = mfi.tilebox();
1517 auto const& dfab = dst.array(mfi);
1518 auto const& sfab = src.const_array(mfi);
1519 auto const& m = this->m_overset_mask[0].back()->const_array(mfi);
1523 dfab(i,j,k,n) = sfab(i,j,k,n);
1525 dfab(i,j,k,n) =
RT(0.0);
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define AMREX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:49
#define AMREX_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:37
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
#define AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE(TN, TI, block)
Definition AMReX_GpuLaunchMacrosC.nolint.H:4
#define AMREX_HOST_DEVICE_FOR_3D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:106
#define AMREX_HOST_DEVICE_PARALLEL_FOR_4D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:111
#define AMREX_LAUNCH_HOST_DEVICE_LAMBDA_DIM(...)
Definition AMReX_GpuLaunch.nolint.H:37
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
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
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:676
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:167
const Real * InvCellSize() const noexcept
Returns the inverse cellsize for each coordinate direction.
Definition AMReX_CoordSys.H:91
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
int nComp() const noexcept
Return number of variables (aka components) associated with each point.
Definition AMReX_FabArrayBase.H:83
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
__host__ static __device__ constexpr IntVectND< dim > TheDimensionVector(int d) noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:790
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
Box tilebox() const noexcept
Return the tile Box at the current index.
Definition AMReX_MFIter.cpp:389
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:172
Definition AMReX_MLABecLaplacian.H:22
RT getBScalar() const final
Scalar beta applied to the b-coefficient term.
Definition AMReX_MLABecLaplacian.H:209
int getNComp() const override
Return number of components.
Definition AMReX_MLABecLaplacian.H:167
void FFlux(int amrlev, const MFIter &mfi, const Array< FAB *, 3 > &flux, const FAB &sol, Location, int face_only=0) const override
Compute fluxes on AMR level amrlev for the tilebox described by mfi using sol, writing to flux and ho...
Definition AMReX_MLABecLaplacian.H:1217
void setACoeffs(int amrlev, const AMF &alpha)
Definition AMReX_MLABecLaplacian.H:386
bool isSingular(int amrlev) const override
Query whether AMR level amrlev is singular (null space present).
Definition AMReX_MLABecLaplacian.H:179
void applyRobinBCTermsCoeffs()
Modify coefficients to honor Robin BC terms introduced at level boundaries.
Definition AMReX_MLABecLaplacian.H:664
Vector< Vector< Array< MF, 3 > > > m_b_coeffs
Definition AMReX_MLABecLaplacian.H:260
typename MF::fab_type FAB
Definition AMReX_MLABecLaplacian.H:25
void setBCoeffs(int amrlev, const Array< AMF const *, 3 > &beta)
Definition AMReX_MLABecLaplacian.H:411
MLABecLaplacianT< MF > & operator=(const MLABecLaplacianT< MF > &)=delete
bool supportRobinBC() const noexcept override
Definition AMReX_MLABecLaplacian.H:269
RT m_b_scalar
Definition AMReX_MLABecLaplacian.H:258
typename MF::value_type RT
Definition AMReX_MLABecLaplacian.H:26
~MLABecLaplacianT() override
void prepareForSolve() override
Finalize singular flags and metric/Robin adjustments prior to calling MLMG.
Definition AMReX_MLABecLaplacian.H:482
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={}, int a_ncomp=1)
Define coefficients/layouts for a standard cell-centered solve.
Definition AMReX_MLABecLaplacian.H:309
RT m_a_scalar
Definition AMReX_MLABecLaplacian.H:257
void averageDownCoeffsToCoarseAmrLevel(int flev)
Average coefficients from fine AMR level flev to coarse AMR level flev-1.
Definition AMReX_MLABecLaplacian.H:778
void averageDownCoeffsSameAmrLevel(int amrlev, Vector< MF > &a, Vector< Array< MF, 3 > > &b)
Average coefficients down within AMR level amrlev (fine-to-coarse multigrid) updating a and b.
Definition AMReX_MLABecLaplacian.H:691
bool m_scalars_set
Definition AMReX_MLABecLaplacian.H:262
Vector< int > m_is_singular
Definition AMReX_MLABecLaplacian.H:267
void averageDownCoeffs()
Average a and b coefficients down across all AMR and MG levels.
Definition AMReX_MLABecLaplacian.H:673
RT getAScalar() const final
Scalar alpha applied to the a-coefficient term.
Definition AMReX_MLABecLaplacian.H:207
void normalize(int amrlev, int mglev, MF &mf) const override
Divide mf by the diagonal of the operator (used by CG-family bottom solvers).
Definition AMReX_MLABecLaplacian.H:1306
void Fsmooth(int amrlev, int mglev, MF &sol, const MF &rhs, int redblack) const override
Perform one smoothing pass on (amrlev,mglev) updating sol against rhs. redblack selects the red (0) o...
Definition AMReX_MLABecLaplacian.H:943
std::unique_ptr< MLLinOpT< MF > > makeNLinOp(int) const final
Build the NSolve counterpart of this operator.
Definition AMReX_MLABecLaplacian.H:1384
bool m_acoef_set
Definition AMReX_MLABecLaplacian.H:263
Array< MF const *, 3 > getBCoeffs(int amrlev, int mglev) const final
Access the stored b coefficients on AMR level amrlev and MG level mglev.
Definition AMReX_MLABecLaplacian.H:214
MLABecLaplacianT(MLABecLaplacianT< MF > &&)=delete
Vector< Vector< MF > > m_a_coeffs
Definition AMReX_MLABecLaplacian.H:259
void setScalars(T1 a, T2 b) noexcept
Definition AMReX_MLABecLaplacian.H:369
bool isBottomSingular() const override
Convenience helper for the coarsest level singularity flag.
Definition AMReX_MLABecLaplacian.H:181
void applyMetricTermsCoeffs()
Apply metric factors to the stored coefficients when solving in mapped space.
Definition AMReX_MLABecLaplacian.H:503
void copyNSolveSolution(MF &dst, MF const &src) const final
Copy an NSolve solution from src to dst.
Definition AMReX_MLABecLaplacian.H:1486
bool supportNSolve() const override
Whether this operator supports NSolve.
Definition AMReX_MLABecLaplacian.H:1368
MLABecLaplacianT()=default
Construct an empty operator; call define() before solving.
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLABecLaplacian.H:29
MF const * getACoeffs(int amrlev, int mglev) const final
Access the stored a coefficient on AMR level amrlev and MG level mglev.
Definition AMReX_MLABecLaplacian.H:211
void update() override
Average coefficients and enforce boundary-provided adjustments when needed.
Definition AMReX_MLABecLaplacian.H:461
bool needsUpdate() const override
True if coefficients need to be averaged down before the next apply().
Definition AMReX_MLABecLaplacian.H:170
void Fapply(int amrlev, int mglev, MF &out, const MF &in) const override
Apply the operator on (amrlev,mglev), storing L(in) in out.
Definition AMReX_MLABecLaplacian.H:860
MLABecLaplacianT(const MLABecLaplacianT< MF > &)=delete
Cell-centered operator that exposes ABec Laplacian helpers to derived classes.
Definition AMReX_MLCellABecLap.H:22
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={})
Describe the AMR hierarchy when overset masks are not required.
Definition AMReX_MLCellABecLap.H:150
void prepareForSolve() override
Standard hook called before MLMG iterates (fixes BC data, etc.).
Definition AMReX_MLCellABecLap.H:305
void update() override
Average coefficients/metrics when marked dirty.
Definition AMReX_MLCellABecLap.H:298
static constexpr int mg_coarsen_ratio
Definition AMReX_MLLinOp.H:857
static constexpr int mg_box_min_width
Definition AMReX_MLLinOp.H:858
const MLLinOpT< MF > * m_parent
Definition AMReX_MLLinOp.H:873
Definition AMReX_MultiMask.H:23
MultiArray4< int const > const_arrays() const noexcept
Return const multi-array views (alias of arrays()).
Definition AMReX_MultiMask.H:86
Array4< int const > array(const MFIter &mfi) const noexcept
Return an Array4 view (const) for iterator mfi.
Definition AMReX_MultiMask.H:69
An Iterator over the Orientation of Faces of a Box.
Definition AMReX_Orientation.H:135
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
Long size() const noexcept
Definition AMReX_Vector.H:54
A Collection of IArrayBoxes.
Definition AMReX_iMultiFab.H:34
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 > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1630
__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 > bdryLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len on the low boundary of b along coordinate direction dir.
Definition AMReX_Box.H:1715
std::array< T, N > Array
Definition AMReX_Array.H:31
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:133
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:53
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
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2852
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Create an array of const-qualified pointers from an array of objects.
Definition AMReX_Array.H:1079
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
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
void average_down_faces(const Vector< const MF * > &fine, const Vector< MF * > &crse, const IntVect &ratio, int ngcrse=0)
Average fine face-based FabArray onto crse face-based FabArray.
Definition AMReX_MultiFabUtil.H:1056
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Create an array of pointers from an array of objects.
Definition AMReX_Array.H:1033
LinOpBCType
Definition AMReX_LO_BCTYPES.H:27
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
MF::value_type norminf(MF const &mf, int scomp, int ncomp, IntVect const &nghost, bool local=false)
Definition AMReX_FabArrayUtility.H:1961
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2257
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
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