Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MLALaplacian.H
Go to the documentation of this file.
1#ifndef AMREX_MLALAPLACIAN_H_
2#define AMREX_MLALAPLACIAN_H_
3#include <AMReX_Config.H>
4
6#include <AMReX_MLALap_K.H>
8
9namespace amrex {
10
17
18template <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 MLALaplacianT () = default;
44 const Vector<BoxArray>& a_grids,
45 const Vector<DistributionMapping>& a_dmap,
46 const LPInfo& a_info = LPInfo(),
47 const Vector<FabFactory<FAB> const*>& a_factory = {},
48 int a_ncomp = 1);
49 ~MLALaplacianT () override;
50
55
65 void define (const Vector<Geometry>& a_geom,
66 const Vector<BoxArray>& a_grids,
67 const Vector<DistributionMapping>& a_dmap,
68 const LPInfo& a_info = LPInfo(),
69 const Vector<FabFactory<FAB> const*>& a_factory = {});
70
77 void setScalars (RT a, RT b) noexcept;
79 void setACoeffs (int amrlev, const MF& alpha);
81 template <typename AMF>
82 requires (!std::same_as<MF,AMF>)
83 void setACoeffs (int amrlev, const AMF& alpha);
84
85 [[nodiscard]] int getNComp () const override { return m_ncomp; }
86
87 [[nodiscard]] bool needsUpdate () const override {
88 return (m_needs_update || MLCellABecLapT<MF>::needsUpdate());
89 }
90 void update () override;
91
93 void prepareForSolve () final;
94
95 [[nodiscard]] bool supportsMixedPrecision () const override {
96 return typeid(*this) == typeid(MLALaplacianT<MF>);
97 }
98
99 [[nodiscard]] bool isSingular (int amrlev) const final { return m_is_singular[amrlev]; }
101 [[nodiscard]] bool isBottomSingular () const final { return m_is_singular[0]; }
103 void Fapply (int amrlev, int mglev, MF& out, const MF& in) const final;
105 void Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, int redblack) const final;
111 void FFlux (int amrlev, const MFIter& mfi,
112 const Array<FAB*,AMREX_SPACEDIM>& flux,
113 const FAB& sol, Location /* loc */,
114 int face_only=0) const final;
115
117 void normalize (int amrlev, int mglev, MF& mf) const final;
118
120 [[nodiscard]] RT getAScalar () const final { return m_a_scalar; }
122 [[nodiscard]] RT getBScalar () const final { return m_b_scalar; }
124 [[nodiscard]] MF const* getACoeffs (int amrlev, int mglev) const final
125 { return &(m_a_coeffs[amrlev][mglev]); }
126
127 [[nodiscard]] Array<MF const*,AMREX_SPACEDIM> getBCoeffs (int /*amrlev*/, int /*mglev*/) const final
128 { return {{ AMREX_D_DECL(nullptr,nullptr,nullptr)}}; }
129
130 [[nodiscard]] std::unique_ptr<MLLinOpT<MF>> makeNLinOp (int /*grid_size*/) const final {
131 amrex::Abort("MLALaplacian::makeNLinOp: Not implemented");
132 return std::unique_ptr<MLLinOpT<MF>>{};
133 }
134
150
151private:
152
153 bool m_needs_update = true;
154
155 RT m_a_scalar = std::numeric_limits<RT>::quiet_NaN();
156 RT m_b_scalar = std::numeric_limits<RT>::quiet_NaN();
157 Vector<Vector<MF> > m_a_coeffs;
158
159 Vector<int> m_is_singular;
160
161 int m_ncomp = 1;
162
163 void updateSingularFlag ();
164
167 void setSPScale ();
168};
169
170template <typename MF>
172 const Vector<BoxArray>& a_grids,
173 const Vector<DistributionMapping>& a_dmap,
174 const LPInfo& a_info,
175 const Vector<FabFactory<FAB> const*>& a_factory,
176 int a_ncomp)
177 : m_ncomp(a_ncomp)
178{
179 define(a_geom, a_grids, a_dmap, a_info, a_factory);
180}
181
182template <typename MF>
183void
185 const Vector<BoxArray>& a_grids,
186 const Vector<DistributionMapping>& a_dmap,
187 const LPInfo& a_info,
188 const Vector<FabFactory<FAB> const*>& a_factory)
189{
190 BL_PROFILE("MLALaplacian::define()");
191
192 MLCellABecLapT<MF>::define(a_geom, a_grids, a_dmap, this->dpInfo(a_info), a_factory);
193 this->makeSPLinOp(a_info, [&] (auto const& sp_info) {
194 return std::make_unique<MLALaplacianT<fMultiFab>>
195 (this->spGeom(a_geom), a_grids, a_dmap, sp_info,
196 Vector<FabFactory<BaseFab<float>> const*>{}, m_ncomp);
197 });
198
199 const int ncomp = this->getNComp();
200
201 m_a_coeffs.resize(this->m_num_amr_levels);
202 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
203 {
204 m_a_coeffs[amrlev].resize(this->m_num_mg_levels[amrlev]);
205 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev)
206 {
207 m_a_coeffs[amrlev][mglev].define(this->m_grids[amrlev][mglev],
208 this->m_dmap[amrlev][mglev], ncomp, 0);
209 }
210 }
211}
212
213template <typename MF>
215
216template <typename MF>
217void
219{
220 m_a_scalar = a;
221 m_b_scalar = b;
222 if (a == RT(0.0))
223 {
224 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev)
225 {
226 m_a_coeffs[amrlev][0].setVal(RT(0.0));
227 }
228 }
229 m_needs_update = true;
230 // The single precision copy gets the scalars, scaled, in setSPScale.
231}
232
233template <typename MF>
234void
235MLALaplacianT<MF>::setACoeffs (int amrlev, const MF& alpha)
236{
237 const int ncomp = this->getNComp();
238 m_a_coeffs[amrlev][0].LocalCopy(alpha, 0, 0, ncomp, IntVect(0));
239 m_needs_update = true;
240 this->template spForward<MLALaplacianT>([&] (auto* sp) { sp->setACoeffs(amrlev, alpha); });
241}
242
243template <typename MF>
244template <typename AMF>
245requires (!std::same_as<MF,AMF>)
246void
247MLALaplacianT<MF>::setACoeffs (int amrlev, const AMF& alpha)
248{
249 const int ncomp = this->getNComp();
250 m_a_coeffs[amrlev][0].LocalCopy(alpha, 0, 0, ncomp, IntVect(0));
251 m_needs_update = true;
252 this->template spForward<MLALaplacianT>([&] (auto* sp) { sp->setACoeffs(amrlev, alpha); });
253}
254
255template <typename MF>
256void
258{
259 BL_PROFILE("MLALaplacian::averageDownCoeffs()");
260
261 for (int amrlev = this->m_num_amr_levels-1; amrlev > 0; --amrlev)
262 {
263 auto& fine_a_coeffs = m_a_coeffs[amrlev];
264
265 averageDownCoeffsSameAmrLevel(amrlev, fine_a_coeffs);
267 }
268
269 averageDownCoeffsSameAmrLevel(0, m_a_coeffs[0]);
270}
271
272template <typename MF>
273void
275{
276 const int ncomp = this->getNComp();
277 const int nmglevs = a.size();
278 for (int mglev = 1; mglev < nmglevs; ++mglev)
279 {
280 if (m_a_scalar == RT(0.0))
281 {
282 a[mglev].setVal(RT(0.0));
283 }
284 else
285 {
286 AMREX_ASSERT(amrlev == 0 || !this->hasHiddenDimension());
287 IntVect ratio = (amrlev > 0) ? IntVect(this->mg_coarsen_ratio) : this->mg_coarsen_ratio_vec[mglev-1];
288 amrex::average_down(a[mglev-1], a[mglev], 0, ncomp, ratio);
289 }
290 }
291}
292
293template <typename MF>
294void
296{
297 const int ncomp = this->getNComp();
298 auto& fine_a_coeffs = m_a_coeffs[flev ].back();
299 auto& crse_a_coeffs = m_a_coeffs[flev-1].front();
300
301 if (m_a_scalar != RT(0.0)) {
302 // We coarsen from the back of flev to the front of flev-1.
303 // So we use this->mg_coarsen_ratio.
304 amrex::average_down(fine_a_coeffs, crse_a_coeffs, 0, ncomp, this->mg_coarsen_ratio);
305 }
306}
307
308template <typename MF>
309void
310MLALaplacianT<MF>::updateSingularFlag ()
311{
312 m_is_singular.clear();
313 m_is_singular.resize(this->m_num_amr_levels, false);
314 auto itlo = std::ranges::find(this->m_lobc[0], BCType::Dirichlet);
315 auto ithi = std::ranges::find(this->m_hibc[0], BCType::Dirichlet);
316 if (itlo == this->m_lobc[0].end() && ithi == this->m_hibc[0].end())
317 { // No Dirichlet
318 for (int alev = 0; alev < this->m_num_amr_levels; ++alev)
319 {
320 if (this->m_domain_covered[alev])
321 {
322 if (m_a_scalar == RT(0.0))
323 {
324 m_is_singular[alev] = true;
325 }
326 else
327 {
328 // We are only testing component 0 here, assuming the others
329 // are similar.
330 RT asum = m_a_coeffs[alev].back().sum(0,IntVect(0));
331 RT amax = m_a_coeffs[alev].back().norminf(0,1,IntVect(0));
332 m_is_singular[alev] = (std::abs(asum) <= amax * RT(1.e-12));
333 }
334 }
335 }
336 }
337
338 if (!m_is_singular[0] && this->m_needs_coarse_data_for_bc &&
339 this->m_coarse_fine_bc_type == BCType::Neumann)
340 {
341 bool lev0_a_is_zero = false;
342 if (m_a_scalar == RT(0.0)) {
343 lev0_a_is_zero = true;
344 } else {
345 RT asum = m_a_coeffs[0].back().sum(0,IntVect(0));
346 RT amax = m_a_coeffs[0].back().norminf(0,1,IntVect(0));
347 lev0_a_is_zero = std::abs(asum) <= amax * RT(1.e-12);
348 }
349
350 if (lev0_a_is_zero) {
351 auto bbox = this->m_grids[0][0].minimalBox();
352 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
353 if (this->m_lobc[0][idim] == BCType::Dirichlet) {
354 bbox.growLo(idim,1);
355 }
356 if (this->m_hibc[0][idim] == BCType::Dirichlet) {
357 bbox.growHi(idim,1);
358 }
359 }
360 if (this->m_geom[0][0].Domain().contains(bbox)) {
361 m_is_singular[0] = true;
362 }
363 }
364 }
365}
366
367template <typename MF>
368void
370{
371 BL_PROFILE("MLALaplacian::prepareForSolve()");
374 updateSingularFlag();
375 setSPScale();
376 m_needs_update = false;
377}
378
379template <typename MF>
380void
382{
385 updateSingularFlag();
386 setSPScale();
387 m_needs_update = false;
388}
389
390template <typename MF>
391void
392MLALaplacianT<MF>::setSPScale ()
393{
394 this->template spForward<MLALaplacianT>([&] (auto* sp) {
395 // Estimate of the max diagonal of each component on the AMR levels,
396 // one reduction
397 Vector<RT> diag(m_ncomp, RT(0.0));
398 for (int alev = 0; alev < this->m_num_amr_levels; ++alev) {
399 for (int n = 0; n < m_ncomp; ++n) {
400 RT d = std::abs(m_a_scalar) * m_a_coeffs[alev][0].norminf(n, 1, IntVect(0), true);
401 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
402 if (idim == this->info.hidden_direction) { continue; }
403 RT const dxinv = RT(1.0) / this->m_geom[alev][0].CellSize(idim);
404 d += std::abs(m_b_scalar) * RT(2.0)*dxinv*dxinv;
405 }
406 diag[n] = std::max(diag[n], d);
407 }
408 }
410 // The copy's lengths are lambda times ours, which scales its b
411 // term by lambda^-2 and its metric term by lambda^p.
412 RT const sigma = this->spScaleFor(this->spDiagForScale(diag));
413 auto const lambda = static_cast<RT>(this->m_sp_length_scale);
414 this->m_sp_scale = sigma * static_cast<RT>(std::pow(lambda, this->spMetricExponent()));
415 sp->setScalars(static_cast<float>(sigma * m_a_scalar),
416 static_cast<float>(sigma * lambda*lambda * m_b_scalar));
417 });
418}
419
420template <typename MF>
421void
422MLALaplacianT<MF>::Fapply (int amrlev, int mglev, MF& out, const MF& in) const
423{
424 BL_PROFILE("MLALaplacian::Fapply()");
425
426 const int ncomp = this->getNComp();
427
428 const MF& acoef = m_a_coeffs[amrlev][mglev];
429
431 {AMREX_D_DECL(RT(this->m_geom[amrlev][mglev].InvCellSize(0)),
432 RT(this->m_geom[amrlev][mglev].InvCellSize(1)),
433 RT(this->m_geom[amrlev][mglev].InvCellSize(2)))};
434#if (AMREX_SPACEDIM < 3)
435 const RT dx = RT(this->m_geom[amrlev][mglev].CellSize(0));
436 const RT probxlo = RT(this->m_geom[amrlev][mglev].ProbLo(0));
437#endif
438
439#if (AMREX_SPACEDIM == 3)
440 GpuArray<RT,2> dhinv {this->get_d0(dxinv[0], dxinv[1], dxinv[2]),
441 this->get_d1(dxinv[0], dxinv[1], dxinv[2])};
442#endif
443
444 const RT ascalar = m_a_scalar;
445 const RT bscalar = m_b_scalar;
446
447#ifdef AMREX_USE_OMP
448#pragma omp parallel if (Gpu::notInLaunchRegion())
449#endif
450 for (MFIter mfi(out, TilingIfNotGPU()); mfi.isValid(); ++mfi)
451 {
452 const Box& bx = mfi.tilebox();
453 const auto& xfab = in.array(mfi);
454 const auto& yfab = out.array(mfi);
455 const auto& afab = acoef.array(mfi);
456
457#if (AMREX_SPACEDIM != 3)
458 if (this->m_has_metric_term) {
460 {
461 mlalap_adotx_m(tbx, yfab, xfab, afab, dxinv, ascalar, bscalar, dx, probxlo, ncomp);
462 });
463 } else {
465 {
466 mlalap_adotx(tbx, yfab, xfab, afab, dxinv, ascalar, bscalar, ncomp);
467 });
468 }
469#else
470 if (this->hasHiddenDimension()) {
471 Box const& bx2d = this->compactify(bx);
472 const auto& xfab2d = this->compactify(xfab);
473 const auto& yfab2d = this->compactify(yfab);
474 const auto& afab2d = this->compactify(afab);
476 {
477 TwoD::mlalap_adotx(tbx2d, yfab2d, xfab2d, afab2d, dhinv, ascalar, bscalar, ncomp);
478 });
479 } else {
481 {
482 mlalap_adotx(tbx, yfab, xfab, afab, dxinv, ascalar, bscalar, ncomp);
483 });
484 }
485#endif
486 }
487}
488
489template <typename MF>
490void
491MLALaplacianT<MF>::normalize (int amrlev, int mglev, MF& mf) const
492{
493 BL_PROFILE("MLALaplacian::normalize()");
494
495 const int ncomp = this->getNComp();
496
497 const MF& acoef = m_a_coeffs[amrlev][mglev];
498
500 {AMREX_D_DECL(RT(this->m_geom[amrlev][mglev].InvCellSize(0)),
501 RT(this->m_geom[amrlev][mglev].InvCellSize(1)),
502 RT(this->m_geom[amrlev][mglev].InvCellSize(2)))};
503#if (AMREX_SPACEDIM < 3)
504 const RT dx = RT(this->m_geom[amrlev][mglev].CellSize(0));
505 const RT probxlo = RT(this->m_geom[amrlev][mglev].ProbLo(0));
506#endif
507
508#if (AMREX_SPACEDIM == 3)
509 GpuArray<RT,2> dhinv {this->get_d0(dxinv[0], dxinv[1], dxinv[2]),
510 this->get_d1(dxinv[0], dxinv[1], dxinv[2])};
511#endif
512
513 const RT ascalar = m_a_scalar;
514 const RT bscalar = m_b_scalar;
515
516#ifdef AMREX_USE_OMP
517#pragma omp parallel if (Gpu::notInLaunchRegion())
518#endif
519 for (MFIter mfi(mf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
520 {
521 const Box& bx = mfi.tilebox();
522 const auto& fab = mf.array(mfi);
523 const auto& afab = acoef.array(mfi);
524
525#if (AMREX_SPACEDIM != 3)
526 if (this->m_has_metric_term) {
528 {
529 mlalap_normalize_m(tbx, fab, afab, dxinv, ascalar, bscalar, dx, probxlo, ncomp);
530 });
531 } else {
533 {
534 mlalap_normalize(tbx, fab, afab, dxinv, ascalar, bscalar, ncomp);
535 });
536 }
537#else
538 if (this->hasHiddenDimension()) {
539 Box const& bx2d = this->compactify(bx);
540 const auto& fab2d = this->compactify(fab);
541 const auto& afab2d = this->compactify(afab);
543 {
544 TwoD::mlalap_normalize(tbx2d, fab2d, afab2d, dhinv, ascalar, bscalar, ncomp);
545 });
546 } else {
548 {
549 mlalap_normalize(tbx, fab, afab, dxinv, ascalar, bscalar, ncomp);
550 });
551 }
552#endif
553 }
554}
555
556template <typename MF>
557void
558MLALaplacianT<MF>::Fsmooth (int amrlev, int mglev, MF& sol, const MF& rhs, int redblack) const
559{
560 BL_PROFILE("MLALaplacian::Fsmooth()");
561
562 const int ncomp = this->getNComp();
563
564 const MF& acoef = m_a_coeffs[amrlev][mglev];
565 const auto& undrrelxr = this->m_undrrelxr[amrlev][mglev];
566 const auto& maskvals = this->m_maskvals [amrlev][mglev];
567
568 OrientationIter oitr;
569
570 const auto& f0 = undrrelxr[oitr()]; ++oitr;
571 const auto& f1 = undrrelxr[oitr()]; ++oitr;
572#if (AMREX_SPACEDIM > 1)
573 const auto& f2 = undrrelxr[oitr()]; ++oitr;
574 const auto& f3 = undrrelxr[oitr()]; ++oitr;
575#if (AMREX_SPACEDIM > 2)
576 const auto& f4 = undrrelxr[oitr()]; ++oitr;
577 const auto& f5 = undrrelxr[oitr()]; ++oitr;
578#endif
579#endif
580
581 const MultiMask& mm0 = maskvals[0];
582 const MultiMask& mm1 = maskvals[1];
583#if (AMREX_SPACEDIM > 1)
584 const MultiMask& mm2 = maskvals[2];
585 const MultiMask& mm3 = maskvals[3];
586#if (AMREX_SPACEDIM > 2)
587 const MultiMask& mm4 = maskvals[4];
588 const MultiMask& mm5 = maskvals[5];
589#endif
590#endif
591
592 const Real* dxinv = this->m_geom[amrlev][mglev].InvCellSize();
593 AMREX_D_TERM(const RT dhx = m_b_scalar*RT(dxinv[0]*dxinv[0]);,
594 const RT dhy = m_b_scalar*RT(dxinv[1]*dxinv[1]);,
595 const RT dhz = m_b_scalar*RT(dxinv[2]*dxinv[2]););
596
597#if (AMREX_SPACEDIM == 3)
598 RT dh0 = this->get_d0(dhx, dhy, dhz);
599 RT dh1 = this->get_d1(dhx, dhy, dhz);
600#endif
601
602#if (AMREX_SPACEDIM < 3)
603 const RT dx = RT(this->m_geom[amrlev][mglev].CellSize(0));
604 const RT probxlo = RT(this->m_geom[amrlev][mglev].ProbLo(0));
605#endif
606
607 const RT alpha = m_a_scalar;
608
609#ifdef AMREX_USE_GPU
610 if (Gpu::inLaunchRegion() && !this->hasHiddenDimension())
611 {
612 const auto& m0ma = mm0.const_arrays();
613 const auto& m1ma = mm1.const_arrays();
614 const auto& f0ma = f0.const_arrays();
615 const auto& f1ma = f1.const_arrays();
616#if (AMREX_SPACEDIM > 1)
617 const auto& m2ma = mm2.const_arrays();
618 const auto& m3ma = mm3.const_arrays();
619 const auto& f2ma = f2.const_arrays();
620 const auto& f3ma = f3.const_arrays();
621#if (AMREX_SPACEDIM > 2)
622 const auto& m4ma = mm4.const_arrays();
623 const auto& m5ma = mm5.const_arrays();
624 const auto& f4ma = f4.const_arrays();
625 const auto& f5ma = f5.const_arrays();
626#endif
627#endif
628 const auto& solnma = sol.arrays();
629 const auto& rhsma = rhs.const_arrays();
630 const auto& ama = acoef.const_arrays();
631
632#if (AMREX_SPACEDIM < 3)
633 if (this->m_has_metric_term) {
634 ParallelForRedBlack(sol, ncomp, redblack,
635 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
636 {
637 Box vbx(ama[box_no]);
638 mlalap_gsrb_m(i,j,k,n, solnma[box_no], rhsma[box_no], alpha,
639 AMREX_D_DECL(dhx, dhy, dhz), ama[box_no],
640 f0ma[box_no], m0ma[box_no],
641 f1ma[box_no], m1ma[box_no],
642#if (AMREX_SPACEDIM > 1)
643 f2ma[box_no], m2ma[box_no],
644 f3ma[box_no], m3ma[box_no],
645#endif
646 vbx, redblack, dx, probxlo);
647 });
648 } else
649#endif
650 {
651 ParallelForRedBlack(sol, ncomp, redblack,
652 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
653 {
654 Box vbx(ama[box_no]);
655 mlalap_gsrb(i,j,k,n, solnma[box_no], rhsma[box_no], alpha,
656 AMREX_D_DECL(dhx, dhy, dhz), ama[box_no],
657 f0ma[box_no], m0ma[box_no],
658 f1ma[box_no], m1ma[box_no],
659#if (AMREX_SPACEDIM > 1)
660 f2ma[box_no], m2ma[box_no],
661 f3ma[box_no], m3ma[box_no],
662#if (AMREX_SPACEDIM > 2)
663 f4ma[box_no], m4ma[box_no],
664 f5ma[box_no], m5ma[box_no],
665#endif
666#endif
667 vbx, redblack);
668 });
669 }
670 if (!Gpu::inNoSyncRegion()) {
672 }
673 return;
674 }
675#endif
676
677 MFItInfo mfi_info;
678 if (Gpu::notInLaunchRegion()) { mfi_info.EnableTiling().SetDynamic(true); }
679
680#ifdef AMREX_USE_OMP
681#pragma omp parallel if (Gpu::notInLaunchRegion())
682#endif
683 for (MFIter mfi(sol,mfi_info); mfi.isValid(); ++mfi)
684 {
685 const auto& m0 = mm0.array(mfi);
686 const auto& m1 = mm1.array(mfi);
687#if (AMREX_SPACEDIM > 1)
688 const auto& m2 = mm2.array(mfi);
689 const auto& m3 = mm3.array(mfi);
690#if (AMREX_SPACEDIM > 2)
691 const auto& m4 = mm4.array(mfi);
692 const auto& m5 = mm5.array(mfi);
693#endif
694#endif
695
696 const Box& tbx = mfi.tilebox();
697 const Box& vbx = mfi.validbox();
698 const auto& solnfab = sol.array(mfi);
699 const auto& rhsfab = rhs.array(mfi);
700 const auto& afab = acoef.array(mfi);
701
702 const auto& f0fab = f0.array(mfi);
703 const auto& f1fab = f1.array(mfi);
704#if (AMREX_SPACEDIM > 1)
705 const auto& f2fab = f2.array(mfi);
706 const auto& f3fab = f3.array(mfi);
707#if (AMREX_SPACEDIM > 2)
708 const auto& f4fab = f4.array(mfi);
709 const auto& f5fab = f5.array(mfi);
710#endif
711#endif
712
713#if (AMREX_SPACEDIM == 1)
714 if (this->m_has_metric_term) {
716 {
717 mlalap_gsrb_m(thread_box, solnfab, rhsfab, alpha, dhx,
718 afab,
719 f0fab, m0,
720 f1fab, m1,
721 vbx, redblack,
722 dx, probxlo, ncomp);
723 });
724 } else {
726 {
727 mlalap_gsrb(thread_box, solnfab, rhsfab, alpha, dhx,
728 afab,
729 f0fab, m0,
730 f1fab, m1,
731 vbx, redblack, ncomp);
732 });
733 }
734
735#endif
736
737#if (AMREX_SPACEDIM == 2)
738 if (this->m_has_metric_term) {
740 {
741 mlalap_gsrb_m(thread_box, solnfab, rhsfab, alpha, dhx, dhy,
742 afab,
743 f0fab, m0,
744 f1fab, m1,
745 f2fab, m2,
746 f3fab, m3,
747 vbx, redblack,
748 dx, probxlo, ncomp);
749 });
750 } else {
752 {
753 mlalap_gsrb(thread_box, solnfab, rhsfab, alpha, dhx, dhy,
754 afab,
755 f0fab, m0,
756 f1fab, m1,
757 f2fab, m2,
758 f3fab, m3,
759 vbx, redblack, ncomp);
760 });
761 }
762#endif
763
764#if (AMREX_SPACEDIM == 3)
765 if (this->hasHiddenDimension()) {
766 Box const& tbx_2d = this->compactify(tbx);
767 Box const& vbx_2d = this->compactify(vbx);
768 const auto& solnfab_2d = this->compactify(solnfab);
769 const auto& rhsfab_2d = this->compactify(rhsfab);
770 const auto& afab_2d = this->compactify(afab);
771 const auto& f0fab_2d = this->compactify(this->get_d0(f0fab,f1fab,f2fab));
772 const auto& f1fab_2d = this->compactify(this->get_d1(f0fab,f1fab,f2fab));
773 const auto& f2fab_2d = this->compactify(this->get_d0(f3fab,f4fab,f5fab));
774 const auto& f3fab_2d = this->compactify(this->get_d1(f3fab,f4fab,f5fab));
775 const auto& m0_2d = this->compactify(this->get_d0(m0,m1,m2));
776 const auto& m1_2d = this->compactify(this->get_d1(m0,m1,m2));
777 const auto& m2_2d = this->compactify(this->get_d0(m3,m4,m5));
778 const auto& m3_2d = this->compactify(this->get_d1(m3,m4,m5));
780 {
781 TwoD::mlalap_gsrb(thread_box, solnfab_2d, rhsfab_2d, alpha, dh0, dh1,
782 afab_2d,
783 f0fab_2d, m0_2d,
784 f1fab_2d, m1_2d,
785 f2fab_2d, m2_2d,
786 f3fab_2d, m3_2d,
787 vbx_2d, redblack, ncomp);
788 });
789 } else {
791 {
792 mlalap_gsrb(thread_box, solnfab, rhsfab, alpha, dhx, dhy, dhz,
793 afab,
794 f0fab, m0,
795 f1fab, m1,
796 f2fab, m2,
797 f3fab, m3,
798 f4fab, m4,
799 f5fab, m5,
800 vbx, redblack, ncomp);
801 });
802 }
803#endif
804 }
805}
806
807template <typename MF>
808void
809MLALaplacianT<MF>::FFlux (int amrlev, const MFIter& mfi,
810 const Array<FAB*,AMREX_SPACEDIM>& flux,
811 const FAB& sol, Location, int face_only) const
812{
813 BL_PROFILE("MLALaplacian::FFlux()");
814
815 const int ncomp = this->getNComp();
816 const int mglev = 0;
817 const Box& box = mfi.tilebox();
818 const Real* dxinv = this->m_geom[amrlev][mglev].InvCellSize();
819
820 AMREX_D_TERM(const auto& fxarr = flux[0]->array();,
821 const auto& fyarr = flux[1]->array();,
822 const auto& fzarr = flux[2]->array(););
823 const auto& solarr = sol.array();
824
825#if (AMREX_SPACEDIM != 3)
826 const RT dx = RT(this->m_geom[amrlev][mglev].CellSize(0));
827 const RT probxlo = RT(this->m_geom[amrlev][mglev].ProbLo(0));
828#endif
829
830#if (AMREX_SPACEDIM == 3)
831 if (face_only) {
832 if (this->hiddenDirection() != 0) {
833 RT fac = m_b_scalar * RT(dxinv[0]);
834 Box blo = amrex::bdryLo(box, 0);
835 int blen = box.length(0);
837 {
838 mlalap_flux_xface(tbox, fxarr, solarr, fac, blen, ncomp);
839 });
840 } else {
841 flux[0]->template setVal<RunOn::Device>(RT(0.0));
842 }
843 if (this->hiddenDirection() != 1) {
844 RT fac = m_b_scalar * RT(dxinv[1]);
845 Box blo = amrex::bdryLo(box, 1);
846 int blen = box.length(1);
848 {
849 mlalap_flux_yface(tbox, fyarr, solarr, fac, blen, ncomp);
850 });
851 } else {
852 flux[1]->template setVal<RunOn::Device>(RT(0.0));
853 }
854 if (this->hiddenDirection() != 2) {
855 RT fac = m_b_scalar * RT(dxinv[2]);
856 Box blo = amrex::bdryLo(box, 2);
857 int blen = box.length(2);
859 {
860 mlalap_flux_zface(tbox, fzarr, solarr, fac, blen, ncomp);
861 });
862 } else {
863 flux[2]->template setVal<RunOn::Device>(RT(0.0));
864 }
865 } else {
866 if (this->hiddenDirection() != 0) {
867 RT fac = m_b_scalar * RT(dxinv[0]);
868 Box bflux = amrex::surroundingNodes(box, 0);
870 {
871 mlalap_flux_x(tbox, fxarr, solarr, fac, ncomp);
872 });
873 } else {
874 flux[0]->template setVal<RunOn::Device>(RT(0.0));
875 }
876 if (this->hiddenDirection() != 1) {
877 RT fac = m_b_scalar * RT(dxinv[1]);
878 Box bflux = amrex::surroundingNodes(box, 1);
880 {
881 mlalap_flux_y(tbox, fyarr, solarr, fac, ncomp);
882 });
883 } else {
884 flux[1]->template setVal<RunOn::Device>(RT(0.0));
885 }
886 if (this->hiddenDirection() != 2) {
887 RT fac = m_b_scalar * RT(dxinv[2]);
888 Box bflux = amrex::surroundingNodes(box, 2);
890 {
891 mlalap_flux_z(tbox, fzarr, solarr, fac, ncomp);
892 });
893 } else {
894 flux[2]->template setVal<RunOn::Device>(RT(0.0));
895 }
896 }
897#elif (AMREX_SPACEDIM == 2)
898 if (face_only) {
899 if (this->hiddenDirection() != 0) {
900 RT fac = m_b_scalar * RT(dxinv[0]);
901 Box blo = amrex::bdryLo(box, 0);
902 int blen = box.length(0);
903 if (this->m_has_metric_term) {
905 {
906 mlalap_flux_xface_m(tbox, fxarr, solarr, fac, blen, dx, probxlo, ncomp);
907 });
908 } else {
910 {
911 mlalap_flux_xface(tbox, fxarr, solarr, fac, blen, ncomp);
912 });
913 }
914 } else {
915 flux[0]->template setVal<RunOn::Device>(RT(0.0));
916 }
917 if (this->hiddenDirection() != 1) {
918 RT fac = m_b_scalar * RT(dxinv[1]);
919 Box blo = amrex::bdryLo(box, 1);
920 int blen = box.length(1);
921 if (this->m_has_metric_term) {
923 {
924 mlalap_flux_yface_m(tbox, fyarr, solarr, fac, blen, dx, probxlo, ncomp);
925 });
926 } else {
928 {
929 mlalap_flux_yface(tbox, fyarr, solarr, fac, blen, ncomp);
930 });
931 }
932 } else {
933 flux[1]->template setVal<RunOn::Device>(RT(0.0));
934 }
935 } else {
936 if (this->hiddenDirection() != 0) {
937 RT fac = m_b_scalar * RT(dxinv[0]);
938 Box bflux = amrex::surroundingNodes(box, 0);
939 if (this->m_has_metric_term) {
941 {
942 mlalap_flux_x_m(tbox, fxarr, solarr, fac, dx, probxlo, ncomp);
943 });
944 } else {
946 {
947 mlalap_flux_x(tbox, fxarr, solarr, fac, ncomp);
948 });
949 }
950 } else {
951 flux[0]->template setVal<RunOn::Device>(RT(0.0));
952 }
953 if (this->hiddenDirection() != 1) {
954 RT fac = m_b_scalar * RT(dxinv[1]);
955 Box bflux = amrex::surroundingNodes(box, 1);
956 if (this->m_has_metric_term) {
958 {
959 mlalap_flux_y_m(tbox, fyarr, solarr, fac, dx, probxlo, ncomp);
960 });
961 } else {
963 {
964 mlalap_flux_y(tbox, fyarr, solarr, fac, ncomp);
965 });
966 }
967 } else {
968 flux[1]->template setVal<RunOn::Device>(RT(0.0));
969 }
970 }
971#else
972 if (face_only) {
973 RT fac = m_b_scalar * RT(dxinv[0]);
974 Box blo = amrex::bdryLo(box, 0);
975 int blen = box.length(0);
976 if (this->m_has_metric_term) {
978 {
979 mlalap_flux_xface_m(tbox, fxarr, solarr, fac, blen, dx, probxlo, ncomp);
980 });
981 } else {
983 {
984 mlalap_flux_xface(tbox, fxarr, solarr, fac, blen, ncomp);
985 });
986 }
987 } else {
988 RT fac = m_b_scalar * RT(dxinv[0]);
989 Box bflux = amrex::surroundingNodes(box, 0);
990 if (this->m_has_metric_term) {
992 {
993 mlalap_flux_x_m(tbox, fxarr, solarr, fac, dx, probxlo, ncomp);
994 });
995 } else {
997 {
998 mlalap_flux_x(tbox, fxarr, solarr, fac, ncomp);
999 });
1000 }
1001 }
1002#endif
1003}
1004
1005extern template class MLALaplacianT<MultiFab>;
1006#ifdef AMREX_MLMG_HAS_FLOAT
1007extern template class MLALaplacianT<fMultiFab>;
1008#endif
1009
1011
1012}
1013
1014#endif
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:593
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
#define AMREX_GPU_LAUNCH_HOST_DEVICE_LAMBDA_RANGE(TN, TI, block)
Definition AMReX_GpuLaunchMacrosC.nolint.H:4
#define AMREX_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
__host__ __device__ IntVectND< dim > length() const noexcept
Return the length of the BoxND.
Definition AMReX_Box.H:167
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
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
Multi-component ALaplacian (a scalar plus optional spatial a coeffs).
Definition AMReX_MLALaplacian.H:22
RT getAScalar() const final
Definition AMReX_MLALaplacian.H:120
MLALaplacianT< MF > & operator=(const MLALaplacianT< MF > &)=delete
MLALaplacianT(const MLALaplacianT< MF > &)=delete
void averageDownCoeffsToCoarseAmrLevel(int flev)
Average a coefficients from fine AMR level flev to flev-1.
Definition AMReX_MLALaplacian.H:295
~MLALaplacianT() override
typename MF::fab_type FAB
Definition AMReX_MLALaplacian.H:25
void setScalars(RT a, RT b) noexcept
Set constant scalars a and b in a \phi - b \nabla^2 \phi.
Definition AMReX_MLALaplacian.H:218
void FFlux(int amrlev, const MFIter &mfi, const Array< FAB *, 3 > &flux, const FAB &sol, Location, int face_only=0) const final
Produce face fluxes on AMR level amrlev for the tilebox described by mfi using sol,...
Definition AMReX_MLALaplacian.H:809
void update() override
Update for reuse.
Definition AMReX_MLALaplacian.H:381
bool isBottomSingular() const final
Shortcut for the coarsest level singular flag.
Definition AMReX_MLALaplacian.H:101
std::unique_ptr< MLLinOpT< MF > > makeNLinOp(int) const final
Create the NSolve counterpart of this operator with the requested grid size.
Definition AMReX_MLALaplacian.H:130
Array< MF const *, 3 > getBCoeffs(int, int) const final
ALaplacian has no b coefficients; this returns null pointers.
Definition AMReX_MLALaplacian.H:127
MF const * getACoeffs(int amrlev, int mglev) const final
Access the stored a coefficient MultiFab for (amrlev,mglev).
Definition AMReX_MLALaplacian.H:124
void prepareForSolve() final
Complete per-level setup (averaging, singularity flags) before solving.
Definition AMReX_MLALaplacian.H:369
MLALaplacianT(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 that forwards to define().
Definition AMReX_MLALaplacian.H:171
void Fapply(int amrlev, int mglev, MF &out, const MF &in) const final
Apply the ALaplacian to in (writing out) on (amrlev,mglev).
Definition AMReX_MLALaplacian.H:422
LinOpBCType BCType
Definition AMReX_MLALaplacian.H:28
void averageDownCoeffs()
Average a coefficients down across all AMR and MG levels.
Definition AMReX_MLALaplacian.H:257
MLALaplacianT(MLALaplacianT< MF > &&)=delete
bool supportsMixedPrecision() const override
Definition AMReX_MLALaplacian.H:95
bool isSingular(int amrlev) const final
True if level amrlev is singular.
Definition AMReX_MLALaplacian.H:99
MLALaplacianT()=default
Construct an empty operator; call define() before use.
void normalize(int amrlev, int mglev, MultiFab &mf) const final
void Fsmooth(int amrlev, int mglev, MF &sol, const MF &rhs, int redblack) const final
Run a smoothing sweep on (amrlev,mglev). redblack selects the red (0) or black (1) half of the grid.
Definition AMReX_MLALaplacian.H:558
bool needsUpdate() const override
Does it need update if it's reused?
Definition AMReX_MLALaplacian.H:87
void define(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const LPInfo &a_info=LPInfo(), const Vector< FabFactory< FAB > const * > &a_factory={})
Bind the operator to an AMR hierarchy (no overset support).
Definition AMReX_MLALaplacian.H:184
RT getBScalar() const final
Scalar beta applied to the Laplacian term.
Definition AMReX_MLALaplacian.H:122
void averageDownCoeffsSameAmrLevel(int amrlev, Vector< MF > &a)
Average a coefficients down within a single AMR level (fine-to-coarse MG).
Definition AMReX_MLALaplacian.H:274
typename MF::value_type RT
Definition AMReX_MLALaplacian.H:26
int getNComp() const override
Return number of components.
Definition AMReX_MLALaplacian.H:85
void setACoeffs(int amrlev, const MF &alpha)
Provide per-cell a coefficients on AMR level amrlev (stored directly in alpha).
Definition AMReX_MLALaplacian.H:235
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLALaplacian.H:29
bool needsUpdate() const override
Does it need update if it's reused?
Definition AMReX_MLCellABecLap.H:75
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
Vector< Vector< BndryRegisterT< MF > > > m_undrrelxr
Definition AMReX_MLCellLinOp.H:509
bool m_has_metric_term
Definition AMReX_MLCellLinOp.H:454
Vector< Vector< Array< MultiMask, 2 *3 > > > m_maskvals
Definition AMReX_MLCellLinOp.H:512
T get_d0(T const &dx, T const &dy, T const &) const noexcept
Definition AMReX_MLLinOp.H:1312
Vector< Geometry > spGeom(const Vector< Geometry > &a_geom)
Definition AMReX_MLLinOp.H:1102
Vector< Vector< BoxArray > > m_grids
Definition AMReX_MLLinOp.H:1008
static constexpr int mg_coarsen_ratio
Definition AMReX_MLLinOp.H:974
Vector< int > m_num_mg_levels
Definition AMReX_MLLinOp.H:995
Vector< Vector< DistributionMapping > > m_dmap
Definition AMReX_MLLinOp.H:1009
bool hasHiddenDimension() const noexcept
Definition AMReX_MLLinOp.H:1293
int hiddenDirection() const noexcept
Definition AMReX_MLLinOp.H:1294
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
Box compactify(Box const &b) const noexcept
Definition AMReX_MLLinOp.H:2068
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
T get_d1(T const &, T const &dy, T const &dz) const noexcept
Definition AMReX_MLLinOp.H:1322
void spForward(F const &f)
Definition AMReX_MLLinOp.H:1185
int m_num_amr_levels
Definition AMReX_MLLinOp.H:992
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
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
__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
void Max(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:133
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
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
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
LinOpBCType
Definition AMReX_LO_BCTYPES.H:27
MLALaplacianT< MultiFab > MLALaplacian
Definition AMReX_MLALaplacian.H:1010
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:239
__host__ __device__ Dim3 end(BoxND< dim > const &box) noexcept
Return the iterator end coordinate of box as Dim3.
Definition AMReX_Box.H:2259
void setVal(MF &dst, typename MF::value_type val)
dst = val
Definition AMReX_FabArrayUtility.H:2174
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52
Configuration knobs for multilevel linear operators (grid agglomeration, metrics, etc....
Definition AMReX_MLLinOp.H:54
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