Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MLABecLaplacian.H
Go to the documentation of this file.
1#ifndef AMREX_ML_ABECLAPLACIAN_H_
2#define AMREX_ML_ABECLAPLACIAN_H_
3#include <AMReX_Config.H>
4
6#include <AMReX_MLABecLap_K.H>
7
8namespace amrex {
9
16
19template <typename MF>
21 : public MLCellABecLapT<MF>
22{
23public:
24
25 using FAB = typename MF::fab_type;
26 using RT = typename MF::value_type;
27
30
32 MLABecLaplacianT () = default;
35 const Vector<BoxArray>& a_grids,
36 const Vector<DistributionMapping>& a_dmap,
37 const LPInfo& a_info = LPInfo(),
38 const Vector<FabFactory<FAB> const*>& a_factory = {},
39 int a_ncomp = 1);
40
43 const Vector<BoxArray>& a_grids,
44 const Vector<DistributionMapping>& a_dmap,
45 const Vector<iMultiFab const*>& a_overset_mask, // 1: unknown, 0: known
46 const LPInfo& a_info = LPInfo(),
47 const Vector<FabFactory<FAB> const*>& a_factory = {},
48 int a_ncomp = 1);
49
50 ~MLABecLaplacianT () override;
51
56
67 void define (const Vector<Geometry>& a_geom,
68 const Vector<BoxArray>& a_grids,
69 const Vector<DistributionMapping>& a_dmap,
70 const LPInfo& a_info = LPInfo(),
71 const Vector<FabFactory<FAB> const*>& a_factory = {},
72 int a_ncomp = 1);
73
85 void define (const Vector<Geometry>& a_geom,
86 const Vector<BoxArray>& a_grids,
87 const Vector<DistributionMapping>& a_dmap,
88 const Vector<iMultiFab const*>& a_overset_mask,
89 const LPInfo& a_info = LPInfo(),
90 const Vector<FabFactory<FAB> const*>& a_factory = {},
91 int a_ncomp = 1);
92
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>)
100 void setScalars (T1 a, T2 b) noexcept;
101
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);
114
124 template <typename T>
125 requires (std::is_convertible_v<T, typename MF::value_type>)
126 void setACoeffs (int amrlev, T alpha);
127
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);
140
150 template <typename T>
151 requires (std::is_convertible_v<T, typename MF::value_type>)
152 void setBCoeffs (int amrlev, T beta);
153
163 template <typename T>
164 requires (std::is_convertible_v<T, typename MF::value_type>)
165 void setBCoeffs (int amrlev, Vector<T> const& beta);
166
167 [[nodiscard]] int getNComp () const override { return m_ncomp; }
168
170 [[nodiscard]] bool needsUpdate () const override {
171 return (m_needs_update || MLCellABecLapT<MF>::needsUpdate());
172 }
173
174 void update () override;
175
177 void prepareForSolve () override;
178
179 [[nodiscard]] bool supportsMixedPrecision () const override {
180 return typeid(*this) == typeid(MLABecLaplacianT<MF>);
181 }
182
183 [[nodiscard]] bool isSingular (int amrlev) const override { return m_is_singular[amrlev]; }
185 [[nodiscard]] bool isBottomSingular () const override { return m_is_singular[0]; }
190 void Fapply (int amrlev, int mglev, MF& out, const MF& in) const override;
196 void Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, int redblack) const override;
202 void FFlux (int amrlev, const MFIter& mfi,
203 const Array<FAB*,AMREX_SPACEDIM>& flux,
204 const FAB& sol, Location /* loc */,
205 int face_only=0) const override;
206
208 void normalize (int amrlev, int mglev, MF& mf) const override;
209
211 [[nodiscard]] RT getAScalar () const final { return m_a_scalar; }
213 [[nodiscard]] RT getBScalar () const final { return m_b_scalar; }
215 [[nodiscard]] MF const* getACoeffs (int amrlev, int mglev) const final
216 { return &(m_a_coeffs[amrlev][mglev]); }
217
218 [[nodiscard]] Array<MF const*,AMREX_SPACEDIM> getBCoeffs (int amrlev, int mglev) const final
219 { return amrex::GetArrOfConstPtrs(m_b_coeffs[amrlev][mglev]); }
220
222 [[nodiscard]] std::unique_ptr<MLLinOpT<MF>> makeNLinOp (int /*grid_size*/) const final;
223
225 [[nodiscard]] bool supportNSolve () const override;
226
228 void copyNSolveSolution (MF& dst, MF const& src) const final;
229
237
240
243
256 static void FFlux (Box const& box, Real const* dxinv, RT bscalar,
258 Array<FAB*,AMREX_SPACEDIM> const& flux,
259 FAB const& sol, int face_only, int ncomp);
260
261 RT m_a_scalar = std::numeric_limits<RT>::quiet_NaN();
262 RT m_b_scalar = std::numeric_limits<RT>::quiet_NaN();
265
266 bool m_scalars_set = false;
267 bool m_acoef_set = false;
268
269protected:
270
272
273 // Robin BC modifies alpha, which has only one component.
274 [[nodiscard]] bool supportRobinBC () const noexcept override { return getNComp() == 1; }
275
276private:
277
278 bool m_needs_update = true;
279
280 int m_ncomp = 1;
281
282 Vector<int> m_a_metric_applied;
283 Vector<int> m_b_metric_applied;
284
285 void define_ab_coeffs ();
286
287 void update_singular_flags ();
288
292 void setSPScale (RT a_scalar);
293};
294
295template <typename MF>
297 const Vector<BoxArray>& a_grids,
298 const Vector<DistributionMapping>& a_dmap,
299 const LPInfo& a_info,
300 const Vector<FabFactory<FAB> const*>& a_factory,
301 int a_ncomp)
302{
303 define(a_geom, a_grids, a_dmap, a_info, a_factory, a_ncomp);
304}
305
306template <typename MF>
308 const Vector<BoxArray>& a_grids,
309 const Vector<DistributionMapping>& a_dmap,
310 const Vector<iMultiFab const*>& a_overset_mask,
311 const LPInfo& a_info,
312 const Vector<FabFactory<FAB> const*>& a_factory,
313 int a_ncomp)
314{
315 define(a_geom, a_grids, a_dmap, a_overset_mask, a_info, a_factory, a_ncomp);
316}
317
318template <typename MF> MLABecLaplacianT<MF>::~MLABecLaplacianT () = default;
319
320template <typename MF>
321void
323 const Vector<BoxArray>& a_grids,
324 const Vector<DistributionMapping>& a_dmap,
325 const LPInfo& a_info,
326 const Vector<FabFactory<FAB> const*>& a_factory,
327 int a_ncomp)
328{
329 BL_PROFILE("MLABecLaplacian::define()");
330 this->m_ncomp = a_ncomp;
331 MLCellABecLapT<MF>::define(a_geom, a_grids, a_dmap, this->dpInfo(a_info), a_factory);
332 define_ab_coeffs();
333 if (typeid(*this) == typeid(MLABecLaplacianT<MF>)) { // a derived operator builds its own copy
334 this->makeSPLinOp(a_info, [&] (auto const& sp_info) {
335 return std::make_unique<MLABecLaplacianT<fMultiFab>>
336 (this->spGeom(a_geom), a_grids, a_dmap, sp_info, Vector<FabFactory<BaseFab<float>> const*>{}, a_ncomp);
337 });
338 }
339}
340
341template <typename MF>
342void
344 const Vector<BoxArray>& a_grids,
345 const Vector<DistributionMapping>& a_dmap,
346 const Vector<iMultiFab const*>& a_overset_mask,
347 const LPInfo& a_info,
348 const Vector<FabFactory<FAB> const*>& a_factory,
349 int a_ncomp)
350{
351 BL_PROFILE("MLABecLaplacian::define(overset)");
352 this->m_ncomp = a_ncomp;
353 MLCellABecLapT<MF>::define(a_geom, a_grids, a_dmap, a_overset_mask, this->dpInfo(a_info), a_factory);
354 define_ab_coeffs();
355 if (typeid(*this) == typeid(MLABecLaplacianT<MF>)) { // a derived operator builds its own copy
356 this->makeSPLinOp(a_info, [&] (auto const& sp_info) {
357 return std::make_unique<MLABecLaplacianT<fMultiFab>>
358 (this->spGeom(a_geom), a_grids, a_dmap, a_overset_mask, sp_info,
359 Vector<FabFactory<BaseFab<float>> const*>{}, a_ncomp);
360 });
361 }
362}
363
364template <typename MF>
365void
366MLABecLaplacianT<MF>::define_ab_coeffs ()
367{
368 m_a_coeffs.resize(this->m_num_amr_levels);
369 m_b_coeffs.resize(this->m_num_amr_levels);
370 m_a_metric_applied.assign(this->m_num_amr_levels, 0);
371 m_b_metric_applied.assign(this->m_num_amr_levels, 0);
372 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
373 {
374 m_a_coeffs[amrlev].resize(this->m_num_mg_levels[amrlev]);
375 m_b_coeffs[amrlev].resize(this->m_num_mg_levels[amrlev]);
376 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
377 {
378 m_a_coeffs[amrlev][mglev].define
379 (this->m_grids[amrlev][mglev], this->m_dmap[amrlev][mglev],
380 1, 0, MFInfo(), *(this->m_factory[amrlev][mglev]));
381 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
382 {
383 const BoxArray& ba = amrex::convert(this->m_grids[amrlev][mglev],
385 m_b_coeffs[amrlev][mglev][idim].define
386 (ba, this->m_dmap[amrlev][mglev], m_ncomp, 0, MFInfo(),
387 *(this->m_factory[amrlev][mglev]));
388 }
389 }
390 }
391}
392
393template <typename MF>
394template <typename T1, typename T2>
395requires (std::is_convertible_v<T1, typename MF::value_type> && std::is_convertible_v<T2, typename MF::value_type>)
396void
398{
399 m_a_scalar = RT(a);
400 m_b_scalar = RT(b);
401 if (m_a_scalar == RT(0.0)) {
402 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
403 m_a_coeffs[amrlev][0].setVal(RT(0.0));
404 }
405 m_acoef_set = true;
406 }
407 m_needs_update = true;
408 m_scalars_set = true;
409 // The single precision copy gets the scalars, scaled, in setSPScale.
410}
411
412template <typename MF>
413template <FabArrayType AMF>
414requires (std::is_convertible_v<typename AMF::value_type, typename MF::value_type>)
415void
416MLABecLaplacianT<MF>::setACoeffs (int amrlev, const AMF& alpha)
417{
418 AMREX_ASSERT_WITH_MESSAGE(alpha.nComp() == 1,
419 "MLABecLaplacian::setACoeffs: alpha is supposed to be single component.");
420 m_a_coeffs[amrlev][0].LocalCopy(alpha, 0, 0, 1, IntVect(0));
421 m_a_metric_applied[amrlev] = 0;
422 m_needs_update = true;
423 m_acoef_set = true;
424 this->template spForward<MLABecLaplacianT>([&] (auto* sp) { sp->setACoeffs(amrlev, alpha); });
425}
426
427template <typename MF>
428template <typename T>
429requires (std::is_convertible_v<T, typename MF::value_type>)
430void
432{
433 m_a_coeffs[amrlev][0].setVal(RT(alpha));
434 m_a_metric_applied[amrlev] = 0;
435 m_needs_update = true;
436 m_acoef_set = true;
437 this->template spForward<MLABecLaplacianT>([&] (auto* sp) { sp->setACoeffs(amrlev, alpha); });
438}
439
440
441template <typename MF>
442template <FabArrayType AMF>
443requires (std::is_convertible_v<typename AMF::value_type, typename MF::value_type>)
444void
447{
448 const int ncomp = this->getNComp();
449 AMREX_ASSERT(beta[0]->nComp() == 1 || beta[0]->nComp() == ncomp);
450 if (beta[0]->nComp() == ncomp) {
451 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
452 for (int icomp = 0; icomp < ncomp; ++icomp) {
453 m_b_coeffs[amrlev][0][idim].LocalCopy(*beta[idim], icomp, icomp, 1, IntVect(0));
454 }
455 }
456 } else {
457 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
458 for (int icomp = 0; icomp < ncomp; ++icomp) {
459 m_b_coeffs[amrlev][0][idim].LocalCopy(*beta[idim], 0, icomp, 1, IntVect(0));
460 }
461 }
462 }
463 m_b_metric_applied[amrlev] = 0;
464 m_needs_update = true;
465 this->template spForward<MLABecLaplacianT>([&] (auto* sp) { sp->setBCoeffs(amrlev, beta); });
466}
467
468template <typename MF>
469template <typename T>
470requires (std::is_convertible_v<T, typename MF::value_type>)
471void
473{
474 [[maybe_unused]] Gpu::SyncAtExitOnly no_sync{};
475 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
476 m_b_coeffs[amrlev][0][idim].setVal(RT(beta));
477 }
478 m_b_metric_applied[amrlev] = 0;
479 m_needs_update = true;
480 this->template spForward<MLABecLaplacianT>([&] (auto* sp) { sp->setBCoeffs(amrlev, beta); });
481}
482
483template <typename MF>
484template <typename T>
485requires (std::is_convertible_v<T, typename MF::value_type>)
486void
488{
489 [[maybe_unused]] Gpu::SyncAtExitOnly no_sync{};
490 const int ncomp = this->getNComp();
491 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
492 for (int icomp = 0; icomp < ncomp; ++icomp) {
493 m_b_coeffs[amrlev][0][idim].setVal(RT(beta[icomp]), icomp, 1, 0);
494 }
495 }
496 m_b_metric_applied[amrlev] = 0;
497 m_needs_update = true;
498 this->template spForward<MLABecLaplacianT>([&] (auto* sp) { sp->setBCoeffs(amrlev, beta); });
499}
500
501template <typename MF>
502void
504{
507 }
508
509 RT const a_scalar = m_a_scalar;
510
511#if (AMREX_SPACEDIM != 3)
513#endif
514
516
518
519 update_singular_flags();
520
521 setSPScale(a_scalar);
522
523 m_needs_update = false;
524}
525
526template <typename MF>
527void
529{
530 BL_PROFILE("MLABecLaplacian::prepareForSolve()");
531
533
534 RT const a_scalar = m_a_scalar;
535
536#if (AMREX_SPACEDIM != 3)
538#endif
539
541
543
544 update_singular_flags();
545
546 setSPScale(a_scalar);
547
548 m_needs_update = false;
549}
550
551template <typename MF>
552void
553MLABecLaplacianT<MF>::setSPScale (RT a_scalar)
554{
555 this->template spForward<MLABecLaplacianT>([&] (auto* sp) {
556 // Estimate of the max diagonal of each component on the AMR levels,
557 // one reduction
558 Vector<RT> diag(m_ncomp, RT(0.0));
559 for (int alev = 0; alev < this->m_num_amr_levels; ++alev) {
560 RT const da = std::abs(m_a_scalar) * m_a_coeffs[alev][0].norminf(0, 1, IntVect(0), true);
561 for (int n = 0; n < m_ncomp; ++n) {
562 RT d = da;
563 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
564 if (idim == this->info.hidden_direction) { continue; }
565 RT const dxinv = RT(1.0) / this->m_geom[alev][0].CellSize(idim);
566 d += std::abs(m_b_scalar) * m_b_coeffs[alev][0][idim].norminf(n, 1, IntVect(0), true)
567 * RT(2.0)*dxinv*dxinv;
568 }
569 diag[n] = std::max(diag[n], d);
570 }
571 }
573 // The copy's lengths are lambda times ours, which scales its b
574 // term by lambda^-2 and its metric term by lambda^p.
575 RT const sigma = this->spScaleFor(this->spDiagForScale(diag));
576 auto const lambda = static_cast<RT>(this->m_sp_length_scale);
577 this->m_sp_scale = sigma * static_cast<RT>(std::pow(lambda, this->spMetricExponent()));
578 sp->setScalars(sigma * a_scalar, sigma * lambda*lambda * m_b_scalar);
579 });
580}
581
582template <typename MF>
583void
585{
586#if (AMREX_SPACEDIM != 3)
587 for (int alev = 0; alev < this->m_num_amr_levels; ++alev)
588 {
589 const int mglev = 0;
590 if (!m_a_metric_applied[alev]) {
591 this->applyMetricTerm(alev, mglev, m_a_coeffs[alev][mglev]);
592 m_a_metric_applied[alev] = 1;
593 }
594 if (!m_b_metric_applied[alev]) {
595 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
596 {
597 this->applyMetricTerm(alev, mglev, m_b_coeffs[alev][mglev][idim]);
598 }
599 m_b_metric_applied[alev] = 1;
600 }
601 }
602#endif
603}
604
605//
606// Suppose we are solving `alpha u - del (beta grad u) = rhs` (Scalar
607// coefficients can be easily added back in the end) and there is Robin BC
608// `a u + b du/dn = f` at the upper end of the x-direction. The 1D
609// discretization at the last cell i is
610//
611// alpha u_i + (beta_{i-1/2} (du/dx)_{i-1/2} - beta_{i+1/2} (du/dx)_{i+1/2}) / h = rhs_i
612//
613// where h is the cell size. At `i+1/2` (i.e., the boundary), we have
614//
615// a (u_i + u_{i+1})/2 + b (u_{i+1}-u_i)/h = f,
616//
617// according to the Robin BC. This gives
618//
619// u_{i+1} = A + B u_i,
620//
621// where `A = f/(b/h + a/2)` and `B = (b/h - a/2) / (b/h + a/2). We then
622// use `u_i` and `u_{i+1}` to compute `(du/dx)_{i+1/2}`. The discretization
623// at cell i then becomes
624//
625// \tilde{alpha}_i u_i + (beta_{i-1/2} (du/dx)_{i-1/2} - 0) / h = \tilde{rhs}_i
626//
627// This is equivalent to having homogeneous Neumann BC with modified alpha and rhs.
628//
629// \tilde{alpha}_i = alpha_i + (1-B) beta_{i+1/2} / h^2
630// \tilde{rhs}_i = rhs_i + A beta_{i+1/2} / h^2
631//
633namespace detail {
634template <typename LP>
635void applyRobinBCTermsCoeffs (LP& linop)
636{
637 using RT = typename LP::RT;
638
639 const int ncomp = linop.getNComp();
640 bool reset_alpha = false;
641 if (linop.m_a_scalar == RT(0.0)) {
642 linop.m_a_scalar = RT(1.0);
643 reset_alpha = true;
644 }
645 const RT bovera = linop.m_b_scalar/linop.m_a_scalar;
646
647 if (!reset_alpha) {
648 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(linop.m_scalars_set && linop.m_acoef_set,
649 "To reuse solver With Robin BC, one must re-call setScalars (and setACoeffs if the scalar is not zero)");
650 }
651
652 linop.m_scalars_set = false;
653 linop.m_acoef_set = false;
654
655 for (int amrlev = 0; amrlev < linop.NAMRLevels(); ++amrlev) {
656 const int mglev = 0;
657 const Box& domain = linop.Geom(amrlev,mglev).Domain();
658 const RT dxi = static_cast<RT>(linop.Geom(amrlev,mglev).InvCellSize(0));
659 const RT dyi = static_cast<RT>((AMREX_SPACEDIM >= 2) ? linop.Geom(amrlev,mglev).InvCellSize(1) : Real(1.0));
660 const RT dzi = static_cast<RT>((AMREX_SPACEDIM == 3) ? linop.Geom(amrlev,mglev).InvCellSize(2) : Real(1.0));
661
662 if (reset_alpha) {
663 linop.m_a_coeffs[amrlev][mglev].setVal(RT(0.0));
664 }
665
666 MFItInfo mfi_info;
667 if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }
668
669#ifdef AMREX_USE_OMP
670#pragma omp parallel if (Gpu::notInLaunchRegion())
671#endif
672 for (MFIter mfi(linop.m_a_coeffs[amrlev][mglev], mfi_info); mfi.isValid(); ++mfi)
673 {
674 const Box& vbx = mfi.validbox();
675 auto const& afab = linop.m_a_coeffs[amrlev][mglev].array(mfi);
676 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
677 auto const& bfab = linop.m_b_coeffs[amrlev][mglev][idim].const_array(mfi);
678 const Box& blo = amrex::adjCellLo(vbx,idim);
679 const Box& bhi = amrex::adjCellHi(vbx,idim);
680 bool outside_domain_lo = !(domain.contains(blo));
681 bool outside_domain_hi = !(domain.contains(bhi));
682 if ((!outside_domain_lo) && (!outside_domain_hi)) { continue; }
683 for (int icomp = 0; icomp < ncomp; ++icomp) {
684 auto const& rbc = (*(linop.m_robin_bcval[amrlev]))[mfi].const_array(icomp*3);
685 if (linop.m_lobc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_lo)
686 {
687 if (idim == 0) {
688 RT fac = bovera*dxi*dxi;
689 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
690 {
691 RT B = (rbc(i,j,k,1)*dxi - rbc(i,j,k,0)*RT(0.5))
692 / (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
693 afab(i+1,j,k,icomp) += fac*bfab(i+1,j,k,icomp)*(RT(1.0)-B);
694 });
695 } else if (idim == 1) {
696 RT fac = bovera*dyi*dyi;
697 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
698 {
699 RT B = (rbc(i,j,k,1)*dyi - rbc(i,j,k,0)*RT(0.5))
700 / (rbc(i,j,k,1)*dyi + rbc(i,j,k,0)*RT(0.5));
701 afab(i,j+1,k,icomp) += fac*bfab(i,j+1,k,icomp)*(RT(1.0)-B);
702 });
703 } else {
704 RT fac = bovera*dzi*dzi;
705 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
706 {
707 RT B = (rbc(i,j,k,1)*dzi - rbc(i,j,k,0)*RT(0.5))
708 / (rbc(i,j,k,1)*dzi + rbc(i,j,k,0)*RT(0.5));
709 afab(i,j,k+1,icomp) += fac*bfab(i,j,k+1,icomp)*(RT(1.0)-B);
710 });
711 }
712 }
713 if (linop.m_hibc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_hi)
714 {
715 if (idim == 0) {
716 RT fac = bovera*dxi*dxi;
717 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
718 {
719 RT B = (rbc(i,j,k,1)*dxi - rbc(i,j,k,0)*RT(0.5))
720 / (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
721 afab(i-1,j,k,icomp) += fac*bfab(i,j,k,icomp)*(RT(1.0)-B);
722 });
723 } else if (idim == 1) {
724 RT fac = bovera*dyi*dyi;
725 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
726 {
727 RT B = (rbc(i,j,k,1)*dyi - rbc(i,j,k,0)*RT(0.5))
728 / (rbc(i,j,k,1)*dyi + rbc(i,j,k,0)*RT(0.5));
729 afab(i,j-1,k,icomp) += fac*bfab(i,j,k,icomp)*(RT(1.0)-B);
730 });
731 } else {
732 RT fac = bovera*dzi*dzi;
733 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
734 {
735 RT B = (rbc(i,j,k,1)*dzi - rbc(i,j,k,0)*RT(0.5))
736 / (rbc(i,j,k,1)*dzi + rbc(i,j,k,0)*RT(0.5));
737 afab(i,j,k-1,icomp) += fac*bfab(i,j,k,icomp)*(RT(1.0)-B);
738 });
739 }
740 }
741 }
742 }
743 }
744 }
745}
746} // namespace detail
748
749template <typename MF>
750void
752{
753 if (this->hasRobinBC()) {
754 detail::applyRobinBCTermsCoeffs(*this);
755 }
756}
757
758template <typename MF>
759void
761{
762 BL_PROFILE("MLABecLaplacian::averageDownCoeffs()");
763
764 for (int amrlev = this->m_num_amr_levels-1; amrlev > 0; --amrlev)
765 {
766 auto& fine_a_coeffs = m_a_coeffs[amrlev];
767 auto& fine_b_coeffs = m_b_coeffs[amrlev];
768
769 averageDownCoeffsSameAmrLevel(amrlev, fine_a_coeffs, fine_b_coeffs);
771 }
772
774}
775
776template <typename MF>
777void
780{
781 int nmglevs = a.size();
782 for (int mglev = 1; mglev < nmglevs; ++mglev)
783 {
784 IntVect ratio = (amrlev > 0) ? IntVect(this->mg_coarsen_ratio) : this->mg_coarsen_ratio_vec[mglev-1];
785 if (this->hasHiddenDimension()) { ratio[this->hiddenDirection()] = 1; }
786
787 if (m_a_scalar == 0.0)
788 {
789 a[mglev].setVal(RT(0.0));
790 }
791 else
792 {
793 amrex::average_down(a[mglev-1], a[mglev], 0, 1, ratio);
794 }
795
796 Vector<const MF*> fine {AMREX_D_DECL(&(b[mglev-1][0]),
797 &(b[mglev-1][1]),
798 &(b[mglev-1][2]))};
799 Vector<MF*> crse {AMREX_D_DECL(&(b[mglev][0]),
800 &(b[mglev][1]),
801 &(b[mglev][2]))};
802
803 amrex::average_down_faces(fine, crse, ratio, 0);
804 }
805
806 for (int mglev = 1; mglev < nmglevs; ++mglev)
807 {
808 if (this->m_overset_mask[amrlev][mglev]) {
809 const RT fac = static_cast<RT>(1 << mglev); // 2**mglev
810 const RT osfac = RT(2.0)*fac/(fac+RT(1.0));
811 const int ncomp = this->getNComp();
812#ifdef AMREX_USE_OMP
813#pragma omp parallel if (Gpu::notInLaunchRegion())
814#endif
815 for (MFIter mfi(a[mglev],TilingIfNotGPU()); mfi.isValid(); ++mfi)
816 {
817 AMREX_D_TERM(Box const& xbx = mfi.nodaltilebox(0);,
818 Box const& ybx = mfi.nodaltilebox(1);,
819 Box const& zbx = mfi.nodaltilebox(2));
820 AMREX_D_TERM(auto const& bx = b[mglev][0].array(mfi);,
821 auto const& by = b[mglev][1].array(mfi);,
822 auto const& bz = b[mglev][2].array(mfi));
823 auto const& osm = this->m_overset_mask[amrlev][mglev]->const_array(mfi);
824#if defined(AMREX_USE_CUDA) && defined(_WIN32)
826 (xbx, t_xbx,
827 {
828 overset_rescale_bcoef_x(t_xbx, bx, osm, ncomp, osfac);
829 });
830#if (AMREX_SPACEDIM >= 2)
832 (ybx, t_ybx,
833 {
834 overset_rescale_bcoef_y(t_ybx, by, osm, ncomp, osfac);
835 });
836#endif
837#if (AMREX_SPACEDIM == 3)
839 (zbx, t_zbx,
840 {
841 overset_rescale_bcoef_z(t_zbx, bz, osm, ncomp, osfac);
842 });
843#endif
844#else
846 (xbx, t_xbx,
847 {
848 overset_rescale_bcoef_x(t_xbx, bx, osm, ncomp, osfac);
849 },
850 ybx, t_ybx,
851 {
852 overset_rescale_bcoef_y(t_ybx, by, osm, ncomp, osfac);
853 },
854 zbx, t_zbx,
855 {
856 overset_rescale_bcoef_z(t_zbx, bz, osm, ncomp, osfac);
857 });
858#endif
859 }
860 }
861 }
862}
863
864template <typename MF>
865void
867{
868 auto& fine_a_coeffs = m_a_coeffs[flev ].back();
869 auto& fine_b_coeffs = m_b_coeffs[flev ].back();
870 auto& crse_a_coeffs = m_a_coeffs[flev-1].front();
871 auto& crse_b_coeffs = m_b_coeffs[flev-1].front();
872
873 if (m_a_scalar != 0.0) {
874 // We coarsen from the back of flev to the front of flev-1.
875 // So we use mg_coarsen_ratio.
876 amrex::average_down(fine_a_coeffs, crse_a_coeffs, 0, 1, this->mg_coarsen_ratio);
877 }
878
880 amrex::GetArrOfPtrs(crse_b_coeffs),
882 this->m_geom[flev-1][0]);
883}
884
885template <typename MF>
886void
887MLABecLaplacianT<MF>::update_singular_flags ()
888{
889 m_is_singular.clear();
890 m_is_singular.resize(this->m_num_amr_levels, false);
891 auto itlo = std::ranges::find(this->m_lobc[0], BCType::Dirichlet);
892 auto ithi = std::ranges::find(this->m_hibc[0], BCType::Dirichlet);
893 if (itlo == this->m_lobc[0].end() && ithi == this->m_hibc[0].end())
894 { // No Dirichlet
895 for (int alev = 0; alev < this->m_num_amr_levels; ++alev)
896 {
897 // For now this assumes that overset regions are treated as Dirichlet bc's
898 if (this->m_domain_covered[alev] && !this->m_overset_mask[alev][0])
899 {
900 if (m_a_scalar == Real(0.0))
901 {
902 m_is_singular[alev] = true;
903 }
904 else
905 {
906 RT asum = m_a_coeffs[alev].back().sum(0,IntVect(0));
907 RT amax = m_a_coeffs[alev].back().norminf(0,1,IntVect(0));
908 m_is_singular[alev] = (std::abs(asum) <= amax * RT(1.e-12));
909 }
910 }
911 }
912 }
913
914 if (!m_is_singular[0] && this->m_needs_coarse_data_for_bc &&
915 this->m_coarse_fine_bc_type == LinOpBCType::Neumann)
916 {
917 AMREX_ASSERT(this->m_overset_mask[0][0] == nullptr);
918
919 bool lev0_a_is_zero = false;
920 if (m_a_scalar == Real(0.0)) {
921 lev0_a_is_zero = true;
922 } else {
923 RT asum = m_a_coeffs[0].back().sum(0,IntVect(0));
924 RT amax = m_a_coeffs[0].back().norminf(0,1,IntVect(0));
925 bool a_is_almost_zero = std::abs(asum) <= amax * RT(1.e-12);
926 if (a_is_almost_zero) { lev0_a_is_zero = true; }
927 }
928
929 if (lev0_a_is_zero) {
930 auto bbox = this->m_grids[0][0].minimalBox();
931 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
932 if (this->m_lobc[0][idim] == LinOpBCType::Dirichlet) {
933 bbox.growLo(idim,1);
934 }
935 if (this->m_hibc[0][idim] == LinOpBCType::Dirichlet) {
936 bbox.growHi(idim,1);
937 }
938 }
939 if (this->m_geom[0][0].Domain().contains(bbox)) {
940 m_is_singular[0] = true;
941 }
942 }
943 }
944}
945
946template <typename MF>
947void
948MLABecLaplacianT<MF>::Fapply (int amrlev, int mglev, MF& out, const MF& in) const
949{
950 BL_PROFILE("MLABecLaplacian::Fapply()");
951
952 const MF& acoef = m_a_coeffs[amrlev][mglev];
953 AMREX_D_TERM(const MF& bxcoef = m_b_coeffs[amrlev][mglev][0];,
954 const MF& bycoef = m_b_coeffs[amrlev][mglev][1];,
955 const MF& bzcoef = m_b_coeffs[amrlev][mglev][2];);
956
958 {AMREX_D_DECL(static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0)),
959 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(1)),
960 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(2)))};
961
962 const RT ascalar = m_a_scalar;
963 const RT bscalar = m_b_scalar;
964
965 const int ncomp = this->getNComp();
966
967#ifdef AMREX_USE_GPU
968 if (Gpu::inLaunchRegion()) {
969 const auto& xma = in.const_arrays();
970 const auto& yma = out.arrays();
971 const auto& ama = acoef.arrays();
972 AMREX_D_TERM(const auto& bxma = bxcoef.const_arrays();,
973 const auto& byma = bycoef.const_arrays();,
974 const auto& bzma = bzcoef.const_arrays(););
975 if (this->m_overset_mask[amrlev][mglev]) {
976 const auto& osmma = this->m_overset_mask[amrlev][mglev]->const_arrays();
977 ParallelFor(out, IntVect(0), ncomp,
978 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
979 {
980 mlabeclap_adotx_os(i,j,k,n, yma[box_no], xma[box_no], ama[box_no],
981 AMREX_D_DECL(bxma[box_no],byma[box_no],bzma[box_no]),
982 osmma[box_no], dxinv, ascalar, bscalar);
983 });
984 } else {
985 ParallelFor(out, IntVect(0), ncomp,
986 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
987 {
988 mlabeclap_adotx(i,j,k,n, yma[box_no], xma[box_no], ama[box_no],
989 AMREX_D_DECL(bxma[box_no],byma[box_no],bzma[box_no]),
990 dxinv, ascalar, bscalar);
991 });
992 }
993 if (!Gpu::inNoSyncRegion()) {
995 }
996 } else
997#endif
998 {
999#ifdef AMREX_USE_OMP
1000#pragma omp parallel if (Gpu::notInLaunchRegion())
1001#endif
1002 for (MFIter mfi(out, TilingIfNotGPU()); mfi.isValid(); ++mfi)
1003 {
1004 const Box& bx = mfi.tilebox();
1005 const auto& xfab = in.array(mfi);
1006 const auto& yfab = out.array(mfi);
1007 const auto& afab = acoef.array(mfi);
1008 AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi);,
1009 const auto& byfab = bycoef.array(mfi);,
1010 const auto& bzfab = bzcoef.array(mfi););
1011 if (this->m_overset_mask[amrlev][mglev]) {
1012 const auto& osm = this->m_overset_mask[amrlev][mglev]->const_array(mfi);
1013 AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, ncomp, i, j, k, n,
1014 {
1015 mlabeclap_adotx_os(i,j,k,n, yfab, xfab, afab, AMREX_D_DECL(bxfab,byfab,bzfab),
1016 osm, dxinv, ascalar, bscalar);
1017 });
1018 } else {
1019 AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, ncomp, i, j, k, n,
1020 {
1021 mlabeclap_adotx(i,j,k,n, yfab, xfab, afab, AMREX_D_DECL(bxfab,byfab,bzfab),
1022 dxinv, ascalar, bscalar);
1023 });
1024 }
1025 }
1026 }
1027}
1028
1029template <typename MF>
1030void
1031MLABecLaplacianT<MF>::Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, int redblack) const
1032{
1033 BL_PROFILE("MLABecLaplacian::Fsmooth()");
1034
1035 bool regular_coarsening = true;
1036 if (amrlev == 0 && mglev > 0) {
1037 regular_coarsening = this->mg_coarsen_ratio_vec[mglev-1] == this->mg_coarsen_ratio;
1038 }
1039
1040 MF Ax;
1041 if (! this->m_use_gauss_seidel && regular_coarsening) { // jacobi
1042 Ax.define(sol.boxArray(), sol.DistributionMap(), sol.nComp(), 0,
1043 MFInfo().SetArena(The_Async_Arena()));
1044 Fapply(amrlev, mglev, Ax, sol);
1045 }
1046
1047 const MF& acoef = m_a_coeffs[amrlev][mglev];
1048 AMREX_ALWAYS_ASSERT(acoef.nGrowVect() == 0);
1049 AMREX_D_TERM(const MF& bxcoef = m_b_coeffs[amrlev][mglev][0];,
1050 const MF& bycoef = m_b_coeffs[amrlev][mglev][1];,
1051 const MF& bzcoef = m_b_coeffs[amrlev][mglev][2];);
1052 const auto& undrrelxr = this->m_undrrelxr[amrlev][mglev];
1053 const auto& maskvals = this->m_maskvals [amrlev][mglev];
1054
1055 OrientationIter oitr;
1056
1057 const auto& f0 = undrrelxr[oitr()]; ++oitr;
1058 const auto& f1 = undrrelxr[oitr()]; ++oitr;
1059#if (AMREX_SPACEDIM > 1)
1060 const auto& f2 = undrrelxr[oitr()]; ++oitr;
1061 const auto& f3 = undrrelxr[oitr()]; ++oitr;
1062#if (AMREX_SPACEDIM > 2)
1063 const auto& f4 = undrrelxr[oitr()]; ++oitr;
1064 const auto& f5 = undrrelxr[oitr()]; ++oitr;
1065#endif
1066#endif
1067
1068 const MultiMask& mm0 = maskvals[0];
1069 const MultiMask& mm1 = maskvals[1];
1070#if (AMREX_SPACEDIM > 1)
1071 const MultiMask& mm2 = maskvals[2];
1072 const MultiMask& mm3 = maskvals[3];
1073#if (AMREX_SPACEDIM > 2)
1074 const MultiMask& mm4 = maskvals[4];
1075 const MultiMask& mm5 = maskvals[5];
1076#endif
1077#endif
1078
1079 const int nc = this->getNComp();
1080 const Real* h = this->m_geom[amrlev][mglev].CellSize();
1081 AMREX_D_TERM(const RT dhx = m_b_scalar/static_cast<RT>(h[0]*h[0]);,
1082 const RT dhy = m_b_scalar/static_cast<RT>(h[1]*h[1]);,
1083 const RT dhz = m_b_scalar/static_cast<RT>(h[2]*h[2]));
1084 const RT alpha = m_a_scalar;
1085
1086#ifdef AMREX_USE_GPU
1087 // The line solve taken for semi-coarsened levels is host only.
1088 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(regular_coarsening
1089 || this->m_overset_mask[amrlev][mglev]
1091 "MLABecLaplacian::Fsmooth: line solve is not supported on GPU");
1093 && (this->m_overset_mask[amrlev][mglev] || regular_coarsening))
1094 {
1095 const auto& m0ma = mm0.const_arrays();
1096 const auto& m1ma = mm1.const_arrays();
1097#if (AMREX_SPACEDIM > 1)
1098 const auto& m2ma = mm2.const_arrays();
1099 const auto& m3ma = mm3.const_arrays();
1100#if (AMREX_SPACEDIM > 2)
1101 const auto& m4ma = mm4.const_arrays();
1102 const auto& m5ma = mm5.const_arrays();
1103#endif
1104#endif
1105
1106 const auto& solnma = sol.arrays();
1107 const auto& rhsma = rhs.const_arrays();
1108 const auto& ama = acoef.const_arrays();
1109
1110 AMREX_D_TERM(const auto& bxma = bxcoef.const_arrays();,
1111 const auto& byma = bycoef.const_arrays();,
1112 const auto& bzma = bzcoef.const_arrays(););
1113
1114 const auto& f0ma = f0.const_arrays();
1115 const auto& f1ma = f1.const_arrays();
1116#if (AMREX_SPACEDIM > 1)
1117 const auto& f2ma = f2.const_arrays();
1118 const auto& f3ma = f3.const_arrays();
1119#if (AMREX_SPACEDIM > 2)
1120 const auto& f4ma = f4.const_arrays();
1121 const auto& f5ma = f5.const_arrays();
1122#endif
1123#endif
1124
1125 if (this->m_overset_mask[amrlev][mglev]) {
1126 const auto& osmma = this->m_overset_mask[amrlev][mglev]->const_arrays();
1127 if (this->m_use_gauss_seidel) {
1128 ParallelForRedBlack(sol, nc, redblack,
1129 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1130 {
1131 Box vbx(ama[box_no]);
1132 abec_gsrb_os(i,j,k,n, solnma[box_no], rhsma[box_no], alpha, ama[box_no],
1133 AMREX_D_DECL(dhx, dhy, dhz),
1134 AMREX_D_DECL(bxma[box_no],byma[box_no],bzma[box_no]),
1135 AMREX_D_DECL(m0ma[box_no],m2ma[box_no],m4ma[box_no]),
1136 AMREX_D_DECL(m1ma[box_no],m3ma[box_no],m5ma[box_no]),
1137 AMREX_D_DECL(f0ma[box_no],f2ma[box_no],f4ma[box_no]),
1138 AMREX_D_DECL(f1ma[box_no],f3ma[box_no],f5ma[box_no]),
1139 osmma[box_no], vbx, redblack);
1140 });
1141 } else {
1142 const auto& axma = Ax.const_arrays();
1143 ParallelFor(sol, IntVect(0), nc,
1144 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1145 {
1146 Box vbx(ama[box_no]);
1147 abec_jacobi_os(i,j,k,n, solnma[box_no], rhsma[box_no], axma[box_no],
1148 alpha, ama[box_no],
1149 AMREX_D_DECL(dhx, dhy, dhz),
1150 AMREX_D_DECL(bxma[box_no],byma[box_no],bzma[box_no]),
1151 AMREX_D_DECL(m0ma[box_no],m2ma[box_no],m4ma[box_no]),
1152 AMREX_D_DECL(m1ma[box_no],m3ma[box_no],m5ma[box_no]),
1153 AMREX_D_DECL(f0ma[box_no],f2ma[box_no],f4ma[box_no]),
1154 AMREX_D_DECL(f1ma[box_no],f3ma[box_no],f5ma[box_no]),
1155 osmma[box_no], vbx);
1156 });
1157 }
1158 } else if (regular_coarsening) {
1159 if (this->m_use_gauss_seidel) {
1160 ParallelForRedBlack(sol, nc, redblack,
1161 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1162 {
1163 Box vbx(ama[box_no]);
1164 abec_gsrb(i,j,k,n, solnma[box_no], rhsma[box_no], alpha, ama[box_no],
1165 AMREX_D_DECL(dhx, dhy, dhz),
1166 AMREX_D_DECL(bxma[box_no],byma[box_no],bzma[box_no]),
1167 AMREX_D_DECL(m0ma[box_no],m2ma[box_no],m4ma[box_no]),
1168 AMREX_D_DECL(m1ma[box_no],m3ma[box_no],m5ma[box_no]),
1169 AMREX_D_DECL(f0ma[box_no],f2ma[box_no],f4ma[box_no]),
1170 AMREX_D_DECL(f1ma[box_no],f3ma[box_no],f5ma[box_no]),
1171 vbx, redblack);
1172 });
1173 } else {
1174 const auto& axma = Ax.const_arrays();
1175 ParallelFor(sol, IntVect(0), nc,
1176 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1177 {
1178 Box vbx(ama[box_no]);
1179 abec_jacobi(i,j,k,n, solnma[box_no], rhsma[box_no], axma[box_no],
1180 alpha, ama[box_no],
1181 AMREX_D_DECL(dhx, dhy, dhz),
1182 AMREX_D_DECL(bxma[box_no],byma[box_no],bzma[box_no]),
1183 AMREX_D_DECL(m0ma[box_no],m2ma[box_no],m4ma[box_no]),
1184 AMREX_D_DECL(m1ma[box_no],m3ma[box_no],m5ma[box_no]),
1185 AMREX_D_DECL(f0ma[box_no],f2ma[box_no],f4ma[box_no]),
1186 AMREX_D_DECL(f1ma[box_no],f3ma[box_no],f5ma[box_no]),
1187 vbx);
1188 });
1189 }
1190 }
1191 if (!Gpu::inNoSyncRegion()) {
1193 }
1194 } else
1195#endif
1196 {
1197 MFItInfo mfi_info;
1198 mfi_info.SetDynamic(true);
1199 // The line solve below needs whole valid boxes, not tiles: a tile
1200 // would truncate the tridiagonal lines and make neighboring threads
1201 // race on the cells at the tile edges.
1202 if (regular_coarsening || this->m_overset_mask[amrlev][mglev]) {
1203 mfi_info.EnableTiling();
1204 }
1205
1206#ifdef AMREX_USE_OMP
1207#pragma omp parallel if (Gpu::notInLaunchRegion())
1208#endif
1209 for (MFIter mfi(sol,mfi_info); mfi.isValid(); ++mfi)
1210 {
1211 const auto& m0 = mm0.array(mfi);
1212 const auto& m1 = mm1.array(mfi);
1213#if (AMREX_SPACEDIM > 1)
1214 const auto& m2 = mm2.array(mfi);
1215 const auto& m3 = mm3.array(mfi);
1216#if (AMREX_SPACEDIM > 2)
1217 const auto& m4 = mm4.array(mfi);
1218 const auto& m5 = mm5.array(mfi);
1219#endif
1220#endif
1221
1222 const Box& tbx = mfi.tilebox();
1223 const Box& vbx = mfi.validbox();
1224 const auto& solnfab = sol.array(mfi);
1225 const auto& rhsfab = rhs.const_array(mfi);
1226 const auto& afab = acoef.const_array(mfi);
1227
1228 AMREX_D_TERM(const auto& bxfab = bxcoef.const_array(mfi);,
1229 const auto& byfab = bycoef.const_array(mfi);,
1230 const auto& bzfab = bzcoef.const_array(mfi););
1231
1232 const auto& f0fab = f0.const_array(mfi);
1233 const auto& f1fab = f1.const_array(mfi);
1234#if (AMREX_SPACEDIM > 1)
1235 const auto& f2fab = f2.const_array(mfi);
1236 const auto& f3fab = f3.const_array(mfi);
1237#if (AMREX_SPACEDIM > 2)
1238 const auto& f4fab = f4.const_array(mfi);
1239 const auto& f5fab = f5.const_array(mfi);
1240#endif
1241#endif
1242
1243 if (this->m_overset_mask[amrlev][mglev]) {
1244 const auto& osm = this->m_overset_mask[amrlev][mglev]->const_array(mfi);
1245 if (this->m_use_gauss_seidel) {
1246 AMREX_LOOP_4D(tbx, nc, i, j, k, n,
1247 {
1248 abec_gsrb_os(i,j,k,n, solnfab, rhsfab, alpha, afab,
1249 AMREX_D_DECL(dhx, dhy, dhz),
1250 AMREX_D_DECL(bxfab, byfab, bzfab),
1251 AMREX_D_DECL(m0,m2,m4),
1252 AMREX_D_DECL(m1,m3,m5),
1253 AMREX_D_DECL(f0fab,f2fab,f4fab),
1254 AMREX_D_DECL(f1fab,f3fab,f5fab),
1255 osm, vbx, redblack);
1256 });
1257 } else {
1258 const auto& axfab = Ax.const_array(mfi);
1259 AMREX_LOOP_4D(tbx, nc, i, j, k, n,
1260 {
1261 abec_jacobi_os(i,j,k,n, solnfab, rhsfab, axfab,
1262 alpha, afab,
1263 AMREX_D_DECL(dhx, dhy, dhz),
1264 AMREX_D_DECL(bxfab, byfab, bzfab),
1265 AMREX_D_DECL(m0,m2,m4),
1266 AMREX_D_DECL(m1,m3,m5),
1267 AMREX_D_DECL(f0fab,f2fab,f4fab),
1268 AMREX_D_DECL(f1fab,f3fab,f5fab),
1269 osm, vbx);
1270 });
1271 }
1272 } else if (regular_coarsening) {
1273 if (this->m_use_gauss_seidel) {
1274 AMREX_LOOP_4D(tbx, nc, i, j, k, n,
1275 {
1276 abec_gsrb(i,j,k,n, solnfab, rhsfab, alpha, afab,
1277 AMREX_D_DECL(dhx, dhy, dhz),
1278 AMREX_D_DECL(bxfab, byfab, bzfab),
1279 AMREX_D_DECL(m0,m2,m4),
1280 AMREX_D_DECL(m1,m3,m5),
1281 AMREX_D_DECL(f0fab,f2fab,f4fab),
1282 AMREX_D_DECL(f1fab,f3fab,f5fab),
1283 vbx, redblack);
1284 });
1285 } else {
1286 const auto& axfab = Ax.const_array(mfi);
1287 AMREX_LOOP_4D(tbx, nc, i, j, k, n,
1288 {
1289 abec_jacobi(i,j,k,n, solnfab, rhsfab, axfab,
1290 alpha, afab,
1291 AMREX_D_DECL(dhx, dhy, dhz),
1292 AMREX_D_DECL(bxfab, byfab, bzfab),
1293 AMREX_D_DECL(m0,m2,m4),
1294 AMREX_D_DECL(m1,m3,m5),
1295 AMREX_D_DECL(f0fab,f2fab,f4fab),
1296 AMREX_D_DECL(f1fab,f3fab,f5fab),
1297 vbx);
1298 });
1299 }
1300 } else {
1301 // Line solve for semi-coarsening. Host only, and tbx == vbx
1302 // because tiling is disabled above for this branch.
1303 abec_gsrb_with_line_solve(tbx, solnfab, rhsfab, alpha, afab,
1304 AMREX_D_DECL(dhx, dhy, dhz),
1305 AMREX_D_DECL(bxfab, byfab, bzfab),
1306 AMREX_D_DECL(m0,m2,m4),
1307 AMREX_D_DECL(m1,m3,m5),
1308 AMREX_D_DECL(f0fab,f2fab,f4fab),
1309 AMREX_D_DECL(f1fab,f3fab,f5fab),
1310 vbx, redblack, nc);
1311 }
1312 }
1313 }
1314}
1315
1316template <typename MF>
1317void
1318MLABecLaplacianT<MF>::FFlux (int amrlev, const MFIter& mfi,
1319 const Array<FAB*,AMREX_SPACEDIM>& flux,
1320 const FAB& sol, Location, int face_only) const
1321{
1322 BL_PROFILE("MLABecLaplacian::FFlux()");
1323
1324 const int mglev = 0;
1325 const Box& box = mfi.tilebox();
1326 const Real* dxinv = this->m_geom[amrlev][mglev].InvCellSize();
1327 const int ncomp = this->getNComp();
1328 FFlux(box, dxinv, m_b_scalar,
1329 Array<FAB const*,AMREX_SPACEDIM>{{AMREX_D_DECL(&(m_b_coeffs[amrlev][mglev][0][mfi]),
1330 &(m_b_coeffs[amrlev][mglev][1][mfi]),
1331 &(m_b_coeffs[amrlev][mglev][2][mfi]))}},
1332 flux, sol, face_only, ncomp);
1333}
1334
1335template <typename MF>
1336void
1337MLABecLaplacianT<MF>::FFlux (Box const& box, Real const* dxinv, RT bscalar,
1339 Array<FAB*,AMREX_SPACEDIM> const& flux,
1340 FAB const& sol, int face_only, int ncomp)
1341{
1342 AMREX_D_TERM(const auto bx = bcoef[0]->const_array();,
1343 const auto by = bcoef[1]->const_array();,
1344 const auto bz = bcoef[2]->const_array(););
1345 AMREX_D_TERM(const auto& fxarr = flux[0]->array();,
1346 const auto& fyarr = flux[1]->array();,
1347 const auto& fzarr = flux[2]->array(););
1348 const auto& solarr = sol.array();
1349
1350 if (face_only)
1351 {
1352 RT fac = bscalar*static_cast<RT>(dxinv[0]);
1353 Box blo = amrex::bdryLo(box, 0);
1354 int blen = box.length(0);
1356 {
1357 mlabeclap_flux_xface(tbox, fxarr, solarr, bx, fac, blen, ncomp);
1358 });
1359#if (AMREX_SPACEDIM >= 2)
1360 fac = bscalar*static_cast<RT>(dxinv[1]);
1361 blo = amrex::bdryLo(box, 1);
1362 blen = box.length(1);
1364 {
1365 mlabeclap_flux_yface(tbox, fyarr, solarr, by, fac, blen, ncomp);
1366 });
1367#endif
1368#if (AMREX_SPACEDIM == 3)
1369 fac = bscalar*static_cast<RT>(dxinv[2]);
1370 blo = amrex::bdryLo(box, 2);
1371 blen = box.length(2);
1373 {
1374 mlabeclap_flux_zface(tbox, fzarr, solarr, bz, fac, blen, ncomp);
1375 });
1376#endif
1377 }
1378 else
1379 {
1380 RT fac = bscalar*static_cast<RT>(dxinv[0]);
1381 Box bflux = amrex::surroundingNodes(box, 0);
1383 {
1384 mlabeclap_flux_x(tbox, fxarr, solarr, bx, fac, ncomp);
1385 });
1386#if (AMREX_SPACEDIM >= 2)
1387 fac = bscalar*static_cast<RT>(dxinv[1]);
1388 bflux = amrex::surroundingNodes(box, 1);
1390 {
1391 mlabeclap_flux_y(tbox, fyarr, solarr, by, fac, ncomp);
1392 });
1393#endif
1394#if (AMREX_SPACEDIM == 3)
1395 fac = bscalar*static_cast<RT>(dxinv[2]);
1396 bflux = amrex::surroundingNodes(box, 2);
1398 {
1399 mlabeclap_flux_z(tbox, fzarr, solarr, bz, fac, ncomp);
1400 });
1401#endif
1402 }
1403}
1404
1405template <typename MF>
1406void
1407MLABecLaplacianT<MF>::normalize (int amrlev, int mglev, MF& mf) const
1408{
1409 BL_PROFILE("MLABecLaplacian::normalize()");
1410
1411 const auto& acoef = m_a_coeffs[amrlev][mglev];
1412 AMREX_D_TERM(const auto& bxcoef = m_b_coeffs[amrlev][mglev][0];,
1413 const auto& bycoef = m_b_coeffs[amrlev][mglev][1];,
1414 const auto& bzcoef = m_b_coeffs[amrlev][mglev][2];);
1415
1416 const GpuArray<RT,AMREX_SPACEDIM> dxinv
1417 {AMREX_D_DECL(static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0)),
1418 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(1)),
1419 static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(2)))};
1420
1421 const RT ascalar = m_a_scalar;
1422 const RT bscalar = m_b_scalar;
1423
1424 const int ncomp = getNComp();
1425
1426#ifdef AMREX_USE_GPU
1427 if (Gpu::inLaunchRegion()) {
1428 const auto& ma = mf.arrays();
1429 const auto& ama = acoef.const_arrays();
1430 AMREX_D_TERM(const auto& bxma = bxcoef.const_arrays();,
1431 const auto& byma = bycoef.const_arrays();,
1432 const auto& bzma = bzcoef.const_arrays(););
1433 ParallelFor(mf, IntVect(0), ncomp,
1434 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1435 {
1436 mlabeclap_normalize(i,j,k,n, ma[box_no], ama[box_no],
1437 AMREX_D_DECL(bxma[box_no],byma[box_no],bzma[box_no]),
1438 dxinv, ascalar, bscalar);
1439 });
1440 if (!Gpu::inNoSyncRegion()) {
1442 }
1443 } else
1444#endif
1445 {
1446#ifdef AMREX_USE_OMP
1447#pragma omp parallel if (Gpu::notInLaunchRegion())
1448#endif
1449 for (MFIter mfi(mf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
1450 {
1451 const Box& bx = mfi.tilebox();
1452 const auto& fab = mf.array(mfi);
1453 const auto& afab = acoef.array(mfi);
1454 AMREX_D_TERM(const auto& bxfab = bxcoef.array(mfi);,
1455 const auto& byfab = bycoef.array(mfi);,
1456 const auto& bzfab = bzcoef.array(mfi););
1457
1458 AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, ncomp, i, j, k, n,
1459 {
1460 mlabeclap_normalize(i,j,k,n, fab, afab, AMREX_D_DECL(bxfab,byfab,bzfab),
1461 dxinv, ascalar, bscalar);
1462 });
1463 }
1464 }
1465}
1466
1467template <typename MF>
1468bool
1470{
1471 bool support = false;
1472 if (this->m_overset_mask[0][0]) {
1473 if (this->m_geom[0].back().Domain().coarsenable(MLLinOp::mg_coarsen_ratio,
1474 this->mg_domain_min_width)
1475 && this->m_grids[0].back().coarsenable(MLLinOp::mg_coarsen_ratio, this->mg_box_min_width))
1476 {
1477 support = true;
1478 }
1479 }
1480 return support;
1481}
1482
1483template <typename MF>
1484std::unique_ptr<MLLinOpT<MF>>
1485MLABecLaplacianT<MF>::makeNLinOp (int /*grid_size*/) const
1486{
1487 if (this->m_overset_mask[0][0] == nullptr) { return nullptr; }
1488
1489 const Geometry& geom = this->m_geom[0].back();
1490 const BoxArray& ba = this->m_grids[0].back();
1491 const DistributionMapping& dm = this->m_dmap[0].back();
1492
1493 std::unique_ptr<MLLinOpT<MF>> r
1494 {new MLABecLaplacianT<MF>({geom}, {ba}, {dm}, this->m_lpinfo_arg, {}, m_ncomp)};
1495
1496 auto nop = dynamic_cast<MLABecLaplacianT<MF>*>(r.get());
1497 if (!nop) {
1498 return nullptr;
1499 }
1500
1501 nop->m_parent = this;
1502
1503 nop->setMaxOrder(this->maxorder);
1504 nop->setVerbose(this->verbose);
1505
1506 nop->setDomainBC(this->m_lobc, this->m_hibc);
1507
1508 if (this->needsCoarseDataForBC())
1509 {
1510 const Real* dx0 = this->m_geom[0][0].CellSize();
1512 fac *= Real(0.5);
1513 RealVect cbloc {AMREX_D_DECL(dx0[0]*fac[0], dx0[1]*fac[1], dx0[2]*fac[2])};
1514 nop->setCoarseFineBCLocation(cbloc);
1515 }
1516
1517 // Pinning the masked cells with a huge alpha below requires a nonzero
1518 // a-scalar. The parent's alpha does not contribute if its a-scalar is zero.
1519 const RT ascalar = (m_a_scalar == RT(0.0)) ? RT(1.0) : m_a_scalar;
1520 const RT afac = m_a_scalar / ascalar; // 1 unless m_a_scalar is zero
1521 nop->setScalars(ascalar, m_b_scalar);
1522
1523 MF const& alpha_bottom = m_a_coeffs[0].back();
1524 iMultiFab const& osm_bottom = *(this->m_overset_mask[0].back());
1525 const int ncomp = alpha_bottom.nComp();
1526 MF alpha(ba, dm, ncomp, 0, MFInfo().SetArena(The_Async_Arena()));
1527
1528 RT a_max = alpha_bottom.norminf(0, ncomp, IntVect(0), true, true);
1529 const int ncomp_b = m_b_coeffs[0].back()[0].nComp();
1530 AMREX_D_TERM(RT bx_max = m_b_coeffs[0].back()[0].norminf(0,ncomp_b,IntVect(0),true,true);,
1531 RT by_max = m_b_coeffs[0].back()[1].norminf(0,ncomp_b,IntVect(0),true,true);,
1532 RT bz_max = m_b_coeffs[0].back()[2].norminf(0,ncomp_b,IntVect(0),true,true));
1533 const GpuArray<RT,AMREX_SPACEDIM> dxinv
1534 {AMREX_D_DECL(static_cast<RT>(geom.InvCellSize(0)),
1535 static_cast<RT>(geom.InvCellSize(1)),
1536 static_cast<RT>(geom.InvCellSize(2)))};
1537 RT huge_alpha = RT(1.e30) *
1538 amrex::max(a_max*std::abs(m_a_scalar),
1539 AMREX_D_DECL(std::abs(m_b_scalar)*bx_max*dxinv[0]*dxinv[0],
1540 std::abs(m_b_scalar)*by_max*dxinv[1]*dxinv[1],
1541 std::abs(m_b_scalar)*bz_max*dxinv[2]*dxinv[2]));
1543
1544#ifdef AMREX_USE_GPU
1545 if (Gpu::inLaunchRegion() && alpha.isFusingCandidate()) {
1546 auto const& ama = alpha.arrays();
1547 auto const& abotma = alpha_bottom.const_arrays();
1548 auto const& mma = osm_bottom.const_arrays();
1549 ParallelFor(alpha, IntVect(0), ncomp,
1550 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1551 {
1552 if (mma[box_no](i,j,k)) {
1553 ama[box_no](i,j,k,n) = afac*abotma[box_no](i,j,k,n);
1554 } else {
1555 ama[box_no](i,j,k,n) = huge_alpha;
1556 }
1557 });
1558 if (!Gpu::inNoSyncRegion()) {
1560 }
1561 } else
1562#endif
1563 {
1564#ifdef AMREX_USE_OMP
1565#pragma omp parallel if (Gpu::notInLaunchRegion())
1566#endif
1567 for (MFIter mfi(alpha,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1568 Box const& bx = mfi.tilebox();
1569 auto const& a = alpha.array(mfi);
1570 auto const& abot = alpha_bottom.const_array(mfi);
1571 auto const& m = osm_bottom.const_array(mfi);
1572 AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, ncomp, i, j, k, n,
1573 {
1574 if (m(i,j,k)) {
1575 a(i,j,k,n) = afac*abot(i,j,k,n);
1576 } else {
1577 a(i,j,k,n) = huge_alpha;
1578 }
1579 });
1580 }
1581 }
1582
1583 nop->setACoeffs(0, alpha);
1584 nop->setBCoeffs(0, GetArrOfConstPtrs(m_b_coeffs[0].back()));
1585
1586 return r;
1587}
1588
1589template <typename MF>
1590void
1591MLABecLaplacianT<MF>::copyNSolveSolution (MF& dst, MF const& src) const
1592{
1593 if (this->m_overset_mask[0].back() == nullptr) { return; }
1594
1595 const int ncomp = dst.nComp();
1596
1597#ifdef AMREX_USE_GPU
1598 if (Gpu::inLaunchRegion() && dst.isFusingCandidate()) {
1599 auto const& dstma = dst.arrays();
1600 auto const& srcma = src.const_arrays();
1601 auto const& mma = this->m_overset_mask[0].back()->const_arrays();
1602 ParallelFor(dst, IntVect(0), ncomp,
1603 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
1604 {
1605 if (mma[box_no](i,j,k)) {
1606 dstma[box_no](i,j,k,n) = srcma[box_no](i,j,k,n);
1607 } else {
1608 dstma[box_no](i,j,k,n) = RT(0.0);
1609 }
1610 });
1611 if (!Gpu::inNoSyncRegion()) {
1613 }
1614 } else
1615#endif
1616 {
1617#ifdef AMREX_USE_OMP
1618#pragma omp parallel if (Gpu::notInLaunchRegion())
1619#endif
1620 for (MFIter mfi(dst,TilingIfNotGPU()); mfi.isValid(); ++mfi) {
1621 Box const& bx = mfi.tilebox();
1622 auto const& dfab = dst.array(mfi);
1623 auto const& sfab = src.const_array(mfi);
1624 auto const& m = this->m_overset_mask[0].back()->const_array(mfi);
1625 AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, ncomp, i, j, k, n,
1626 {
1627 if (m(i,j,k)) {
1628 dfab(i,j,k,n) = sfab(i,j,k,n);
1629 } else {
1630 dfab(i,j,k,n) = RT(0.0);
1631 }
1632 });
1633 }
1634 }
1635}
1636
1637extern template class MLABecLaplacianT<MultiFab>;
1638#ifdef AMREX_MLMG_HAS_FLOAT
1639extern template class MLABecLaplacianT<fMultiFab>;
1640#endif
1641
1644
1645}
1646
1647#endif
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#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
#define AMREX_LOOP_4D(bx, ncomp, i, j, k, n, block)
#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:681
__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:55
int nComp() const noexcept
Return number of variables (aka components) associated with each point.
Definition AMReX_FabArrayBase.H:88
MultiArray4< typename FabArray< FAB >::value_type const > const_arrays() const noexcept
Read-only convenience wrapper equivalent to arrays() const.
Definition AMReX_FabArray.H:759
Array4< typename FabArray< FAB >::value_type const > const_array(const MFIter &mfi) const noexcept
Synonym for array(const MFIter&) that highlights read-only semantics.
Definition AMReX_FabArray.H:677
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:87
__host__ static __device__ constexpr IntVectND< dim > TheDimensionVector(int d) noexcept
Definition AMReX_IntVect.H:797
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:176
Definition AMReX_MLABecLaplacian.H:22
RT getBScalar() const final
Scalar beta applied to the b-coefficient term.
Definition AMReX_MLABecLaplacian.H:213
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:1318
void setACoeffs(int amrlev, const AMF &alpha)
bool isSingular(int amrlev) const override
Query whether AMR level amrlev is singular (null space present).
Definition AMReX_MLABecLaplacian.H:183
void define(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const Vector< iMultiFab const * > &a_overset_mask, const LPInfo &a_info=LPInfo(), const Vector< FabFactory< FAB > const * > &a_factory={}, int a_ncomp=1)
Define coefficients/layouts plus overset-mask information.
Definition AMReX_MLABecLaplacian.H:343
LinOpBCType BCType
Definition AMReX_MLABecLaplacian.H:28
void applyRobinBCTermsCoeffs()
Modify coefficients to honor Robin BC terms introduced at level boundaries.
Definition AMReX_MLABecLaplacian.H:751
Vector< Vector< Array< MultiFab, 3 > > > m_b_coeffs
Definition AMReX_MLABecLaplacian.H:264
typename MF::fab_type FAB
Definition AMReX_MLABecLaplacian.H:25
void setBCoeffs(int amrlev, const Array< AMF const *, 3 > &beta)
MLABecLaplacianT< MF > & operator=(const MLABecLaplacianT< MF > &)=delete
bool supportRobinBC() const noexcept override
Definition AMReX_MLABecLaplacian.H:274
RT m_b_scalar
Definition AMReX_MLABecLaplacian.H:262
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:528
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:322
RT m_a_scalar
Definition AMReX_MLABecLaplacian.H:261
MLABecLaplacianT(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const Vector< iMultiFab const * > &a_overset_mask, const LPInfo &a_info=LPInfo(), const Vector< FabFactory< FAB > const * > &a_factory={}, int a_ncomp=1)
Convenience constructor that includes overset-mask handling (1 = unknown, 0 = known).
Definition AMReX_MLABecLaplacian.H:307
void averageDownCoeffsToCoarseAmrLevel(int flev)
Average coefficients from fine AMR level flev to coarse AMR level flev-1.
Definition AMReX_MLABecLaplacian.H:866
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:778
static void FFlux(Box const &box, Real const *dxinv, RT bscalar, Array< FAB const *, 3 > const &bcoef, Array< FAB *, 3 > const &flux, FAB const &sol, int face_only, int ncomp)
Helper that computes face fluxes for a single tilebox.
Definition AMReX_MLABecLaplacian.H:1337
bool m_scalars_set
Definition AMReX_MLABecLaplacian.H:266
Vector< int > m_is_singular
Definition AMReX_MLABecLaplacian.H:271
void averageDownCoeffs()
Average a and b coefficients down across all AMR and MG levels.
Definition AMReX_MLABecLaplacian.H:760
RT getAScalar() const final
Scalar alpha applied to the a-coefficient term.
Definition AMReX_MLABecLaplacian.H:211
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:1407
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:1031
MLABecLaplacianT(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)
Convenience constructor for cell-based solves without overset regions.
Definition AMReX_MLABecLaplacian.H:296
std::unique_ptr< MLLinOpT< MF > > makeNLinOp(int) const final
Build the NSolve counterpart of this operator.
Definition AMReX_MLABecLaplacian.H:1485
bool m_acoef_set
Definition AMReX_MLABecLaplacian.H:267
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:218
MLABecLaplacianT(MLABecLaplacianT< MF > &&)=delete
Vector< Vector< MultiFab > > m_a_coeffs
Definition AMReX_MLABecLaplacian.H:263
void setScalars(T1 a, T2 b) noexcept
bool isBottomSingular() const override
Convenience helper for the coarsest level singularity flag.
Definition AMReX_MLABecLaplacian.H:185
void applyMetricTermsCoeffs()
Apply metric factors to the stored coefficients when solving in mapped space.
Definition AMReX_MLABecLaplacian.H:584
void copyNSolveSolution(MF &dst, MF const &src) const final
Copy an NSolve solution from src to dst.
Definition AMReX_MLABecLaplacian.H:1591
bool supportNSolve() const override
Whether this operator supports NSolve.
Definition AMReX_MLABecLaplacian.H:1469
bool supportsMixedPrecision() const override
Definition AMReX_MLABecLaplacian.H:179
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:215
void update() override
Average coefficients and enforce boundary-provided adjustments when needed.
Definition AMReX_MLABecLaplacian.H:503
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:948
MLABecLaplacianT(const MLABecLaplacianT< MF > &)=delete
LPInfo m_lpinfo_arg
Definition AMReX_MLCellABecLap.H:153
bool needsUpdate() const override
Does it need update if it's reused?
Definition AMReX_MLCellABecLap.H:75
Vector< Vector< std::unique_ptr< iMultiFab > > > m_overset_mask
Definition AMReX_MLCellABecLap.H:151
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:160
void prepareForSolve() override
Standard hook called before MLMG iterates (fixes BC data, etc.).
Definition AMReX_MLCellABecLap.H:323
void update() override
Average coefficients/metrics when marked dirty.
Definition AMReX_MLCellABecLap.H:316
void applyMetricTerm(int amrlev, int mglev, MF &rhs) const final
Multiply the RHS by metric terms appropriate for curvilinear coordinates.
Definition AMReX_MLCellLinOp.H:1836
Vector< Vector< BndryRegisterT< MF > > > m_undrrelxr
Definition AMReX_MLCellLinOp.H:509
bool m_use_gauss_seidel
Definition AMReX_MLCellLinOp.H:518
Vector< Vector< Array< MultiMask, 2 *3 > > > m_maskvals
Definition AMReX_MLCellLinOp.H:512
int mg_domain_min_width
Definition AMReX_MLLinOp.H:976
Vector< Geometry > spGeom(const Vector< Geometry > &a_geom)
Definition AMReX_MLLinOp.H:1102
int mg_box_min_width
Definition AMReX_MLLinOp.H:975
bool hasRobinBC() const noexcept
Definition AMReX_MLLinOp.H:2061
Vector< Array< BCType, 3 > > m_hibc
Definition AMReX_MLLinOp.H:966
Vector< Vector< BoxArray > > m_grids
Definition AMReX_MLLinOp.H:1008
static constexpr int mg_coarsen_ratio
Definition AMReX_MLLinOp.H:974
Vector< Vector< DistributionMapping > > m_dmap
Definition AMReX_MLLinOp.H:1009
int verbose
Definition AMReX_MLLinOp.H:983
IntVect m_coarse_data_crse_ratio
Definition AMReX_MLLinOp.H:1037
bool needsCoarseDataForBC() const noexcept
Needs coarse data for bc?
Definition AMReX_MLLinOp.H:249
bool hasHiddenDimension() const noexcept
Definition AMReX_MLLinOp.H:1293
int hiddenDirection() const noexcept
Definition AMReX_MLLinOp.H:1294
Vector< Array< BCType, 3 > > m_lobc
Definition AMReX_MLLinOp.H:965
Vector< Vector< Geometry > > m_geom
first Vector is for amr level and second is mg level
Definition AMReX_MLLinOp.H:1007
LPInfo dpInfo(LPInfo const &a_info) const
Definition AMReX_MLLinOp.H:1128
int maxorder
Definition AMReX_MLLinOp.H:986
Vector< IntVect > mg_coarsen_ratio_vec
Definition AMReX_MLLinOp.H:1004
LinOpEnumType::Location Location
Definition AMReX_MLLinOp.H:174
void makeSPLinOp(LPInfo const &a_info, F const &f)
Definition AMReX_MLLinOp.H:1145
void spForward(F const &f)
Definition AMReX_MLLinOp.H:1185
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:80
__host__ __device__ BoxND< dim > adjCellHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the high end along coordinate direction dir.
Definition AMReX_Box.H:1850
__host__ __device__ BoxND< dim > 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:1632
__host__ __device__ BoxND< dim > adjCellLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the low end along coordinate direction dir.
Definition AMReX_Box.H:1819
__host__ __device__ BoxND< dim > surroundingNodes(const BoxND< dim > &b, int dir) noexcept
Return a BoxND with NODE based coordinates in direction dir that encloses BoxND b.
Definition AMReX_Box.H:1584
__host__ __device__ BoxND< dim > 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:1717
std::array< T, N > Array
Definition AMReX_Array.H:31
Arena * The_Async_Arena()
Definition AMReX_Arena.cpp:849
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:133
MLABecLaplacianT< MultiFab > MLABecLaplacian
Definition AMReX_MLABecLaplacian.H:1643
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:54
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:329
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:89
bool inNoSyncRegion() noexcept
Definition AMReX_GpuControl.H:148
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
Definition AMReX_Amr.cpp:50
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:360
void ParallelForRedBlack(MF const &mf, int redblack, F &&f)
ParallelFor over the red or black points of the valid region of a MultiFab/FabArray.
Definition AMReX_MFParallelFor.H:529
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:1062
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
int nComp(FabArrayBase const &fa)
Convenience wrapper that forwards to fa.nComp().
Definition AMReX_FabArrayBase.cpp:3028
LinOpBCType
Definition AMReX_LO_BCTYPES.H:27
@ Robin
Definition AMReX_LO_BCTYPES.H:36
@ Neumann
Definition AMReX_LO_BCTYPES.H:30
@ Dirichlet
Definition AMReX_LO_BCTYPES.H:29
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
MF::value_type norminf(MF const &mf, int scomp, int ncomp, IntVect const &nghost, bool local=false)
Return the infinity norm, with an MPI maximum unless local is true.
Definition AMReX_FabArrayUtility.H:2275
RealVectND< 3 > RealVect
Definition AMReX_ParmParse.H:40
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2259
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52
Definition AMReX_GpuDevice.H:593
Configuration knobs for multilevel linear operators (grid agglomeration, metrics, etc....
Definition AMReX_MLLinOp.H:54
FabArray memory allocation information.
Definition AMReX_FabArray.H:73
Definition AMReX_MFIter.H:20
MFItInfo & SetDynamic(bool f) noexcept
Definition AMReX_MFIter.H:43
MFItInfo & EnableTiling(const IntVect &ts=FabArrayBase::mfiter_tile_size) noexcept
Definition AMReX_MFIter.H:31