Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MLCellABecLap.H
Go to the documentation of this file.
1#ifndef AMREX_ML_CELL_ABECLAP_H_
2#define AMREX_ML_CELL_ABECLAP_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_MLCellLinOp.H>
6#include <AMReX_MLCellABecLap_K.H>
7
8namespace amrex {
9
18template <typename MF>
20class MLCellABecLapT // NOLINT(cppcoreguidelines-virtual-class-destructor)
21 : public MLCellLinOpT<MF>
22{
23public:
24
25 using FAB = typename MF::fab_type;
26 using RT = typename MF::value_type;
27
29
30 MLCellABecLapT () = default;
31 ~MLCellABecLapT () override = default;
32
37
47 void define (const Vector<Geometry>& a_geom,
48 const Vector<BoxArray>& a_grids,
49 const Vector<DistributionMapping>& a_dmap,
50 const LPInfo& a_info = LPInfo(),
51 const Vector<FabFactory<FAB> const*>& a_factory = {});
52
63 void define (const Vector<Geometry>& a_geom,
64 const Vector<BoxArray>& a_grids,
65 const Vector<DistributionMapping>& a_dmap,
66 const Vector<iMultiFab const*>& a_overset_mask,
67 const LPInfo& a_info = LPInfo(),
68 const Vector<FabFactory<FAB> const*>& a_factory = {});
69
71 [[nodiscard]] iMultiFab const* getOversetMask (int amrlev, int mglev) const {
72 return m_overset_mask[amrlev][mglev].get();
73 }
74
75 [[nodiscard]] bool needsUpdate () const override {
77 }
79 void update () override;
80
82 void prepareForSolve () override;
83
88 void setDirichletNodesToZero (int amrlev, int mglev, MF& mf) const override;
89
97 void getFluxes (const Vector<Array<MF*,AMREX_SPACEDIM> >& a_flux,
98 const Vector<MF*>& a_sol,
99 Location a_loc) const final;
104 void getFluxes (const Vector<MF*>& a_flux,
105 const Vector<MF*>& a_sol) const final {
106 amrex::ignore_unused(a_flux, a_sol);
107 amrex::Abort("MLCellABecLap::getFluxes: How did we get here?");
108 }
109
111 virtual RT getAScalar () const = 0;
113 virtual RT getBScalar () const = 0;
115 virtual MF const* getACoeffs (int amrlev, int mglev) const = 0;
117 virtual Array<MF const*,AMREX_SPACEDIM> getBCoeffs (int amrlev, int mglev) const = 0;
118
120 void applyInhomogNeumannTerm (int amrlev, MF& rhs) const final;
121
124 int amrlev, const Array<MF*,AMREX_SPACEDIM>& grad,
125 MF const& sol, bool mult_bcoef) const final;
126
128 void applyOverset (int amrlev, MF& rhs) const override;
129
130#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
132 [[nodiscard]] std::unique_ptr<Hypre> makeHypre (Hypre::Interface hypre_interface) const override;
133#endif
134
135#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
137 [[nodiscard]] std::unique_ptr<PETScABecLap> makePETSc () const override;
138#endif
139
140protected:
142
144
145 [[nodiscard]] bool supportInhomogNeumannBC () const noexcept override { return true; }
146};
147
148template <typename MF>
149void
151 const Vector<BoxArray>& a_grids,
152 const Vector<DistributionMapping>& a_dmap,
153 const LPInfo& a_info,
154 const Vector<FabFactory<FAB> const*>& a_factory)
155{
156 MLCellLinOpT<MF>::define(a_geom, a_grids, a_dmap, a_info, a_factory);
157
158 this->m_overset_mask.resize(this->m_num_amr_levels);
159 for (int amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
160 this->m_overset_mask[amrlev].resize(this->m_num_mg_levels[amrlev]);
161 }
162}
163
164template <typename MF>
165void
167 const Vector<BoxArray>& a_grids,
168 const Vector<DistributionMapping>& a_dmap,
169 const Vector<iMultiFab const*>& a_overset_mask,
170 const LPInfo& a_info,
171 const Vector<FabFactory<FAB> const*>& a_factory)
172{
173 BL_PROFILE("MLCellABecLap::define(overset)");
174
175 AMREX_ALWAYS_ASSERT(!this->hasHiddenDimension());
176
177 this->m_lpinfo_arg = a_info;
178
179 auto namrlevs = static_cast<int>(a_geom.size());
180 this->m_overset_mask.resize(namrlevs);
181 for (int amrlev = 0; amrlev < namrlevs; ++amrlev)
182 {
183 this->m_overset_mask[amrlev].push_back(std::make_unique<iMultiFab>(a_grids[amrlev],
184 a_dmap[amrlev], 1, 1));
185 iMultiFab::Copy(*(this->m_overset_mask[amrlev][0]), *a_overset_mask[amrlev], 0, 0, 1, 0);
186 if (amrlev > 1) {
187 AMREX_ALWAYS_ASSERT(amrex::refine(a_geom[amrlev-1].Domain(),2)
188 == a_geom[amrlev].Domain());
189 }
190 }
191
192 int amrlev = 0;
193 Box dom = a_geom[0].Domain();
194 for (int mglev = 1; mglev <= a_info.max_coarsening_level; ++mglev)
195 {
196 AMREX_ALWAYS_ASSERT(this->mg_coarsen_ratio == 2);
197 iMultiFab const& fine = *(this->m_overset_mask[amrlev][mglev-1]);
198 if (dom.coarsenable(2) && fine.boxArray().coarsenable(2)) {
199 dom.coarsen(2);
200 auto crse = std::make_unique<iMultiFab>(amrex::coarsen(fine.boxArray(),2),
201 fine.DistributionMap(), 1, 1);
202 ReduceOps<ReduceOpSum> reduce_op;
203 ReduceData<int> reduce_data(reduce_op);
204 using ReduceTuple = typename decltype(reduce_data)::Type;
205#ifdef AMREX_USE_OMP
206#pragma omp parallel if (Gpu::notInLaunchRegion())
207#endif
208 for (MFIter mfi(*crse, TilingIfNotGPU()); mfi.isValid(); ++mfi)
209 {
210 const Box& bx = mfi.tilebox();
211 Array4<int const> const& fmsk = fine.const_array(mfi);
212 Array4<int> const& cmsk = crse->array(mfi);
213 reduce_op.eval(bx, reduce_data,
214 [=] AMREX_GPU_HOST_DEVICE (Box const& b) -> ReduceTuple
215 {
216 return { coarsen_overset_mask(b, cmsk, fmsk) };
217 });
218 }
219 ReduceTuple hv = reduce_data.value(reduce_op);
220 if (amrex::get<0>(hv) == 0) {
221 this->m_overset_mask[amrlev].push_back(std::move(crse));
222 } else {
223 break;
224 }
225 } else {
226 break;
227 }
228 }
229 int max_overset_mask_coarsening_level = this->m_overset_mask[amrlev].size()-1;
230 ParallelAllReduce::Min(max_overset_mask_coarsening_level, ParallelContext::CommunicatorSub());
231 this->m_overset_mask[amrlev].resize(max_overset_mask_coarsening_level+1);
232
233 LPInfo linfo = a_info;
234 linfo.max_coarsening_level = std::min(a_info.max_coarsening_level,
235 max_overset_mask_coarsening_level);
236
237 MLCellLinOpT<MF>::define(a_geom, a_grids, a_dmap, linfo, a_factory);
238
239 amrlev = 0;
240 for (int mglev = 1; mglev < this->m_num_mg_levels[amrlev]; ++mglev) {
241 MF foo(this->m_grids[amrlev][mglev], this->m_dmap[amrlev][mglev], 1, 0, MFInfo().SetAlloc(false));
242 if (! amrex::isMFIterSafe(*(this->m_overset_mask[amrlev][mglev]), foo)) {
243 auto osm = std::make_unique<iMultiFab>(this->m_grids[amrlev][mglev],
244 this->m_dmap[amrlev][mglev], 1, 1);
245 osm->ParallelCopy(*(this->m_overset_mask[amrlev][mglev]));
246 std::swap(osm, this->m_overset_mask[amrlev][mglev]);
247 }
248 }
249
250 for (amrlev = 1; amrlev < this->m_num_amr_levels; ++amrlev) {
251 for (int mglev = 1; mglev < this->m_num_mg_levels[amrlev]; ++mglev) { // for ref_ratio 4
252 this->m_overset_mask[amrlev].push_back(std::make_unique<iMultiFab>(this->m_grids[amrlev][mglev],
253 this->m_dmap[amrlev][mglev],
254 1, 1));
255
256#ifdef AMREX_USE_GPU
257 if (Gpu::inLaunchRegion() && this->m_overset_mask[amrlev][mglev]->isFusingCandidate()) {
258 auto const& crsema = this->m_overset_mask[amrlev][mglev]->arrays();
259 auto const& finema = this->m_overset_mask[amrlev][mglev-1]->const_arrays();
260 ParallelFor(*(this->m_overset_mask[amrlev][mglev]),
261 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k) noexcept
262 {
263 coarsen_overset_mask(i,j,k, crsema[box_no], finema[box_no]);
264 });
265 if (!Gpu::inNoSyncRegion()) {
267 }
268 } else
269#endif
270 {
271#ifdef AMREX_USE_OMP
272#pragma omp parallel if (Gpu::notInLaunchRegion())
273#endif
274 for (MFIter mfi(*(this->m_overset_mask[amrlev][mglev]), TilingIfNotGPU()); mfi.isValid(); ++mfi)
275 {
276 const Box& bx = mfi.tilebox();
277 Array4<int> const& cmsk = this->m_overset_mask[amrlev][mglev]->array(mfi);
278 Array4<int const> const fmsk = this->m_overset_mask[amrlev][mglev-1]->const_array(mfi);
280 {
281 coarsen_overset_mask(i,j,k, cmsk, fmsk);
282 });
283 }
284 }
285 }
286 }
287
288 for (amrlev = 0; amrlev < this->m_num_amr_levels; ++amrlev) {
289 for (int mglev = 0; mglev < this->m_num_mg_levels[amrlev]; ++mglev) {
290 this->m_overset_mask[amrlev][mglev]->setBndry(1);
291 this->m_overset_mask[amrlev][mglev]->FillBoundary(this->m_geom[amrlev][mglev].periodicity());
292 }
293 }
294}
295
296template <typename MF>
297void
302
303template <typename MF>
304void
309
310template <typename MF>
311void
312MLCellABecLapT<MF>::setDirichletNodesToZero (int amrlev, int mglev, MF& mf) const
313{
314 auto const* omask = this->getOversetMask(amrlev, mglev);
315 if (omask) {
316 const int ncomp = this->getNComp();
317 auto const& mskma = omask->const_arrays();
318 auto const& ma = mf.arrays();
319 ParallelFor(mf, IntVect(0), ncomp,
320 [=] AMREX_GPU_DEVICE (int bno, int i, int j, int k, int n)
321 {
322 if (mskma[bno](i,j,k) == 0) { ma[bno](i,j,k,n) = RT(0.0); }
323 });
324 if (!Gpu::inNoSyncRegion()) {
326 }
327 }
328}
329
330template <typename MF>
331void
333 const Vector<MF*>& a_sol,
334 Location a_loc) const
335{
336 BL_PROFILE("MLMG::getFluxes()");
337
338 const int ncomp = this->getNComp();
339 const RT betainv = RT(1.0) / getBScalar();
340 const int nlevs = this->NAMRLevels();
341 for (int alev = 0; alev < nlevs; ++alev) {
342 this->compFlux(alev, a_flux[alev], *a_sol[alev], a_loc);
343 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
344 if (betainv != RT(1.0)) {
345 a_flux[alev][idim]->mult(betainv, 0, ncomp);
346 }
347 }
348 this->addInhomogNeumannFlux(alev, a_flux[alev], *a_sol[alev], true);
349 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
350 this->unapplyMetricTerm(alev, 0, *a_flux[alev][idim]);
351 }
352 }
353}
354
355template <typename MF>
356void
358{
359 bool has_inhomog_neumann = this->hasInhomogNeumannBC();
360 bool has_robin = this->hasRobinBC();
361
362 if (!has_inhomog_neumann && !has_robin) { return; }
363
364 int ncomp = this->getNComp();
365 const int mglev = 0;
366
367 const auto problo = this->m_geom[amrlev][mglev].ProbLoArray();
368 const auto probhi = this->m_geom[amrlev][mglev].ProbHiArray();
369 amrex::ignore_unused(probhi);
370 const RT dxi = static_cast<RT>(this->m_geom[amrlev][mglev].InvCellSize(0));
371 const RT dyi = static_cast<RT>((AMREX_SPACEDIM >= 2) ? this->m_geom[amrlev][mglev].InvCellSize(1) : Real(1.0));
372 const RT dzi = static_cast<RT>((AMREX_SPACEDIM == 3) ? this->m_geom[amrlev][mglev].InvCellSize(2) : Real(1.0));
373 const RT xlo = static_cast<RT>(problo[0]);
374 const RT dx = static_cast<RT>(this->m_geom[amrlev][mglev].CellSize(0));
375 const Box& domain = this->m_geom[amrlev][mglev].Domain();
376
377 const RT beta = getBScalar();
378 Array<MF const*, AMREX_SPACEDIM> const& bcoef = getBCoeffs(amrlev,mglev);
379 FAB foo(Box(IntVect(0),IntVect(1)));
380 bool has_bcoef = (bcoef[0] != nullptr);
381
382 const auto& maskvals = this->m_maskvals[amrlev][mglev];
383 const auto& bcondloc = *(this->m_bcondloc[amrlev][mglev]);
384 const auto& bndry = *(this->m_bndry_sol[amrlev]);
385
386 MFItInfo mfi_info;
387 if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }
388
389#ifdef AMREX_USE_OMP
390#pragma omp parallel if (Gpu::notInLaunchRegion())
391#endif
392 for (MFIter mfi(rhs, mfi_info); mfi.isValid(); ++mfi)
393 {
394 const Box& vbx = mfi.validbox();
395 auto const& rhsfab = rhs.array(mfi);
396
397 const auto & bdlv = bcondloc.bndryLocs(mfi);
398 const auto & bdcv = bcondloc.bndryConds(mfi);
399
400 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
401 {
402 auto const bfab = (has_bcoef)
403 ? bcoef[idim]->const_array(mfi) : foo.const_array();
404 const Orientation olo(idim,Orientation::low);
405 const Orientation ohi(idim,Orientation::high);
406 const Box blo = amrex::adjCellLo(vbx, idim);
407 const Box bhi = amrex::adjCellHi(vbx, idim);
408 const auto& mlo = maskvals[olo].array(mfi);
409 const auto& mhi = maskvals[ohi].array(mfi);
410 const auto& bvlo = bndry.bndryValues(olo).array(mfi);
411 const auto& bvhi = bndry.bndryValues(ohi).array(mfi);
412 bool outside_domain_lo = !(domain.contains(blo));
413 bool outside_domain_hi = !(domain.contains(bhi));
414 if ((!outside_domain_lo) && (!outside_domain_hi)) { continue; }
415 for (int icomp = 0; icomp < ncomp; ++icomp) {
416 const BoundCond bctlo = bdcv[icomp][olo];
417 const BoundCond bcthi = bdcv[icomp][ohi];
418 const RT bcllo = bdlv[icomp][olo];
419 const RT bclhi = bdlv[icomp][ohi];
420 if (this->m_lobc_orig[icomp][idim] == LinOpBCType::inhomogNeumann && outside_domain_lo)
421 {
422 if (idim == 0) {
423 RT fac = beta*dxi;
424 if (this->m_has_metric_term && !has_bcoef) {
425#if (AMREX_SPACEDIM == 1)
426 fac *= static_cast<RT>(problo[0]*problo[0]);
427#elif (AMREX_SPACEDIM == 2)
428 fac *= static_cast<RT>(problo[0]);
429#endif
430 }
431 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
432 {
433 mllinop_apply_innu_xlo(i,j,k, rhsfab, mlo, bfab,
434 bctlo, bcllo, bvlo,
435 fac, has_bcoef, icomp);
436 });
437 } else if (idim == 1) {
438 RT fac = beta*dyi;
439 if (this->m_has_metric_term && !has_bcoef) {
440 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
441 {
442 mllinop_apply_innu_ylo_m(i,j,k, rhsfab, mlo,
443 bctlo, bcllo, bvlo,
444 fac, xlo, dx, icomp);
445 });
446 }
447 else {
448 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
449 {
450 mllinop_apply_innu_ylo(i,j,k, rhsfab, mlo, bfab,
451 bctlo, bcllo, bvlo,
452 fac, has_bcoef, icomp);
453 });
454 }
455 } else {
456 RT fac = beta*dzi;
457 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
458 {
459 mllinop_apply_innu_zlo(i,j,k, rhsfab, mlo, bfab,
460 bctlo, bcllo, bvlo,
461 fac, has_bcoef, icomp);
462 });
463 }
464 }
465 if (this->m_hibc_orig[icomp][idim] == LinOpBCType::inhomogNeumann && outside_domain_hi)
466 {
467 if (idim == 0) {
468 RT fac = beta*dxi;
469 if (this->m_has_metric_term && !has_bcoef) {
470#if (AMREX_SPACEDIM == 1)
471 fac *= static_cast<RT>(probhi[0]*probhi[0]);
472#elif (AMREX_SPACEDIM == 2)
473 fac *= static_cast<RT>(probhi[0]);
474#endif
475 }
476 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
477 {
478 mllinop_apply_innu_xhi(i,j,k, rhsfab, mhi, bfab,
479 bcthi, bclhi, bvhi,
480 fac, has_bcoef, icomp);
481 });
482 } else if (idim == 1) {
483 RT fac = beta*dyi;
484 if (this->m_has_metric_term && !has_bcoef) {
485 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
486 {
487 mllinop_apply_innu_yhi_m(i,j,k, rhsfab, mhi,
488 bcthi, bclhi, bvhi,
489 fac, xlo, dx, icomp);
490 });
491 } else {
492 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
493 {
494 mllinop_apply_innu_yhi(i,j,k, rhsfab, mhi, bfab,
495 bcthi, bclhi, bvhi,
496 fac, has_bcoef, icomp);
497 });
498 }
499 } else {
500 RT fac = beta*dzi;
501 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
502 {
503 mllinop_apply_innu_zhi(i,j,k, rhsfab, mhi, bfab,
504 bcthi, bclhi, bvhi,
505 fac, has_bcoef, icomp);
506 });
507 }
508 }
509
510 if (has_robin) {
511 // For Robin BC, see comments in AMReX_MLABecLaplacian.cpp above
512 // function applyRobinBCTermsCoeffs.
513 auto const& rbc = (*this->m_robin_bcval[amrlev])[mfi].const_array(icomp*3);
514 if (this->m_lobc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_lo)
515 {
516 if (idim == 0) {
517 RT fac = beta*dxi*dxi;
518 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
519 {
520 RT A = rbc(i,j,k,2)
521 / (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
522 rhsfab(i+1,j,k,icomp) += fac*bfab(i+1,j,k,icomp)*A;
523 });
524 } else if (idim == 1) {
525 RT fac = beta*dyi*dyi;
526 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
527 {
528 RT A = rbc(i,j,k,2)
529 / (rbc(i,j,k,1)*dyi + rbc(i,j,k,0)*RT(0.5));
530 rhsfab(i,j+1,k,icomp) += fac*bfab(i,j+1,k,icomp)*A;
531 });
532 } else {
533 RT fac = beta*dzi*dzi;
534 AMREX_HOST_DEVICE_FOR_3D(blo, i, j, k,
535 {
536 RT A = rbc(i,j,k,2)
537 / (rbc(i,j,k,1)*dzi + rbc(i,j,k,0)*RT(0.5));
538 rhsfab(i,j,k+1,icomp) += fac*bfab(i,j,k+1,icomp)*A;
539 });
540 }
541 }
542 if (this->m_hibc_orig[icomp][idim] == LinOpBCType::Robin && outside_domain_hi)
543 {
544 if (idim == 0) {
545 RT fac = beta*dxi*dxi;
546 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
547 {
548 RT A = rbc(i,j,k,2)
549 / (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
550 rhsfab(i-1,j,k,icomp) += fac*bfab(i,j,k,icomp)*A;
551 });
552 } else if (idim == 1) {
553 RT fac = beta*dyi*dyi;
554 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
555 {
556 RT A = rbc(i,j,k,2)
557 / (rbc(i,j,k,1)*dyi + rbc(i,j,k,0)*RT(0.5));
558 rhsfab(i,j-1,k,icomp) += fac*bfab(i,j,k,icomp)*A;
559 });
560 } else {
561 RT fac = beta*dzi*dzi;
562 AMREX_HOST_DEVICE_FOR_3D(bhi, i, j, k,
563 {
564 RT A = rbc(i,j,k,2)
565 / (rbc(i,j,k,1)*dzi + rbc(i,j,k,0)*RT(0.5));
566 rhsfab(i,j,k-1,icomp) += fac*bfab(i,j,k,icomp)*A;
567 });
568 }
569 }
570 }
571 }
572 }
573
574 }
575}
576
577template <typename MF>
578void
580 int amrlev, const Array<MF*,AMREX_SPACEDIM>& grad, MF const& sol,
581 bool mult_bcoef) const
582{
583 /*
584 * if (mult_bcoef == true)
585 * grad is -bceof*grad phi
586 * else
587 * grad is grad phi
588 */
589 RT fac = mult_bcoef ? RT(-1.0) : RT(1.0);
590
591 bool has_inhomog_neumann = this->hasInhomogNeumannBC();
592 bool has_robin = this->hasRobinBC();
593
594 if (!has_inhomog_neumann && !has_robin) { return; }
595
596 int ncomp = this->getNComp();
597 const int mglev = 0;
598
599 const auto dxinv = this->m_geom[amrlev][mglev].InvCellSize();
600 const Box domain = this->m_geom[amrlev][mglev].growPeriodicDomain(1);
601
602 Array<MF const*, AMREX_SPACEDIM> bcoef = {AMREX_D_DECL(nullptr,nullptr,nullptr)};
603 if (mult_bcoef) {
604 bcoef = getBCoeffs(amrlev,mglev);
605 }
606
607 const auto& bndry = *this->m_bndry_sol[amrlev];
608
609 MFItInfo mfi_info;
610 if (Gpu::notInLaunchRegion()) { mfi_info.SetDynamic(true); }
611
612#ifdef AMREX_USE_OMP
613#pragma omp parallel if (Gpu::notInLaunchRegion())
614#endif
615 for (MFIter mfi(sol, mfi_info); mfi.isValid(); ++mfi)
616 {
617 Box const& vbx = mfi.validbox();
618 for (OrientationIter orit; orit.isValid(); ++orit) {
619 const Orientation ori = orit();
620 const int idim = ori.coordDir();
621 const Box& ccb = amrex::adjCell(vbx, ori);
622 const Dim3 os = IntVect::TheDimensionVector(idim).dim3();
623 const RT dxi = static_cast<RT>(dxinv[idim]);
624 if (! domain.contains(ccb)) {
625 for (int icomp = 0; icomp < ncomp; ++icomp) {
626 auto const& phi = sol.const_array(mfi,icomp);
627 auto const& bv = bndry.bndryValues(ori).multiFab().const_array(mfi,icomp);
628 auto const& bc = bcoef[idim] ? bcoef[idim]->const_array(mfi,icomp)
630 auto const& f = grad[idim]->array(mfi,icomp);
631 if (ori.isLow()) {
632 if (this->m_lobc_orig[icomp][idim] ==
634 AMREX_HOST_DEVICE_FOR_3D(ccb, i, j, k,
635 {
636 int ii = i+os.x;
637 int jj = j+os.y;
638 int kk = k+os.z;
639 RT b = bc ? bc(ii,jj,kk) : RT(1.0);
640 f(ii,jj,kk) = fac*b*bv(i,j,k);
641 });
642 } else if (this->m_lobc_orig[icomp][idim] ==
644 auto const& rbc = (*this->m_robin_bcval[amrlev])[mfi].const_array(icomp*3);
645 AMREX_HOST_DEVICE_FOR_3D(ccb, i, j, k,
646 {
647 int ii = i+os.x;
648 int jj = j+os.y;
649 int kk = k+os.z;
650 RT tmp = RT(1.0) /
651 (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
652 RT RA = rbc(i,j,k,2) * tmp;
653 RT RB = (rbc(i,j,k,1)*dxi - rbc(i,j,k,0)*RT(0.5)) * tmp;
654 RT b = bc ? bc(ii,jj,kk) : RT(1.0);
655 f(ii,jj,kk) = fac*b*dxi*((RT(1.0)-RB)*phi(ii,jj,kk)-RA);
656 });
657 }
658 } else {
659 if (this->m_hibc_orig[icomp][idim] ==
661 AMREX_HOST_DEVICE_FOR_3D(ccb, i, j, k,
662 {
663 RT b = bc ? bc(i,j,k) : RT(1.0);
664 f(i,j,k) = fac*b*bv(i,j,k);
665 });
666 } else if (this->m_hibc_orig[icomp][idim] ==
668 auto const& rbc = (*this->m_robin_bcval[amrlev])[mfi].const_array(icomp*3);
669 AMREX_HOST_DEVICE_FOR_3D(ccb, i, j, k,
670 {
671 RT tmp = RT(1.0) /
672 (rbc(i,j,k,1)*dxi + rbc(i,j,k,0)*RT(0.5));
673 RT RA = rbc(i,j,k,2) * tmp;
674 RT RB = (rbc(i,j,k,1)*dxi - rbc(i,j,k,0)*RT(0.5)) * tmp;
675 RT b = bc ? bc(i,j,k) : RT(1.0);
676 f(i,j,k) = fac*b*dxi*(RA+(RB-RT(1.0))*
677 phi(i-os.x,j-os.y,k-os.z));
678 });
679 }
680 }
681 }
682 }
683 }
684 }
685}
686
687template <typename MF>
688void
689MLCellABecLapT<MF>::applyOverset (int amrlev, MF& rhs) const
690{
691 if (m_overset_mask[amrlev][0]) {
692 const int ncomp = this->getNComp();
693#ifdef AMREX_USE_GPU
694 if (Gpu::inLaunchRegion() && m_overset_mask[amrlev][0]->isFusingCandidate()) {
695 auto const& osma = m_overset_mask[amrlev][0]->const_arrays();
696 auto const& rhsa = rhs.arrays();
697 ParallelFor(*m_overset_mask[amrlev][0], IntVect(0), ncomp,
698 [=] AMREX_GPU_DEVICE (int box_no, int i, int j, int k, int n) noexcept
699 {
700 if (osma[box_no](i,j,k) == 0) {
701 rhsa[box_no](i,j,k,n) = RT(0.0);
702 }
703 });
704 if (!Gpu::inNoSyncRegion()) {
706 }
707 } else
708#endif
709 {
710#ifdef AMREX_USE_OMP
711#pragma omp parallel if (Gpu::notInLaunchRegion())
712#endif
713 for (MFIter mfi(*m_overset_mask[amrlev][0],TilingIfNotGPU()); mfi.isValid(); ++mfi)
714 {
715 const Box& bx = mfi.tilebox();
716 auto const& rfab = rhs.array(mfi);
717 auto const& osm = m_overset_mask[amrlev][0]->const_array(mfi);
718 AMREX_HOST_DEVICE_PARALLEL_FOR_4D(bx, ncomp, i, j, k, n,
719 {
720 if (osm(i,j,k) == 0) { rfab(i,j,k,n) = RT(0.0); }
721 });
722 }
723 }
724 }
725}
726
727#if defined(AMREX_USE_HYPRE) && (AMREX_SPACEDIM > 1)
728template <typename MF>
729std::unique_ptr<Hypre>
731{
732 if constexpr (!std::is_same<MF,MultiFab>()) {
733 amrex::Abort("MLCellABecLap Hypre interface only supports MultiFab");
734 } else {
735 const BoxArray& ba = this->m_grids[0].back();
736 const DistributionMapping& dm = this->m_dmap[0].back();
737 const Geometry& geom = this->m_geom[0].back();
738 const auto& factory = *(this->m_factory[0].back());
739 MPI_Comm comm = this->BottomCommunicator();
740
741 const int mglev = this->NMGLevels(0)-1;
742
743 auto om = getOversetMask(0, mglev);
744
745 auto hypre_solver = amrex::makeHypre(ba, dm, geom, comm, hypre_interface, om);
746
747 hypre_solver->setScalars(getAScalar(), getBScalar());
748
749 auto ac = getACoeffs(0, mglev);
750 if (ac)
751 {
752 hypre_solver->setACoeffs(*ac);
753 }
754 else
755 {
756 MultiFab alpha(ba,dm,1,0,MFInfo(),factory);
757 alpha.setVal(0.0);
758 hypre_solver->setACoeffs(alpha);
759 }
760
761 auto bc = getBCoeffs(0, mglev);
762 if (bc[0])
763 {
764 hypre_solver->setBCoeffs(bc);
765 }
766 else
767 {
768 Array<MultiFab,AMREX_SPACEDIM> beta;
769 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
770 {
771 beta[idim].define(amrex::convert(ba,IntVect::TheDimensionVector(idim)),
772 dm, 1, 0, MFInfo(), factory);
773 beta[idim].setVal(1.0);
774 }
775 hypre_solver->setBCoeffs(amrex::GetArrOfConstPtrs(beta));
776 }
777 hypre_solver->setIsMatrixSingular(this->isBottomSingular());
778
779 return hypre_solver;
780 }
781 return nullptr;
782}
783#endif
784
785#if defined(AMREX_USE_PETSC) && (AMREX_SPACEDIM > 1)
786template <typename MF>
787std::unique_ptr<PETScABecLap>
788MLCellABecLapT<MF>::makePETSc () const
789{
790 if constexpr (!std::is_same<MF,MultiFab>()) {
791 amrex::Abort("MLCellABecLap PETSc interface only supports MultiFab");
792 } else {
793 const BoxArray& ba = this->m_grids[0].back();
794 const DistributionMapping& dm = this->m_dmap[0].back();
795 const Geometry& geom = this->m_geom[0].back();
796 const auto& factory = *(this->m_factory[0].back());
797 MPI_Comm comm = this->BottomCommunicator();
798
799 auto petsc_solver = makePetsc(ba, dm, geom, comm);
800
801 petsc_solver->setScalars(getAScalar(), getBScalar());
802
803 const int mglev = this->NMGLevels(0)-1;
804 auto ac = getACoeffs(0, mglev);
805 if (ac)
806 {
807 petsc_solver->setACoeffs(*ac);
808 }
809 else
810 {
811 MultiFab alpha(ba,dm,1,0,MFInfo(),factory);
812 alpha.setVal(0.0);
813 petsc_solver->setACoeffs(alpha);
814 }
815
816 auto bc = getBCoeffs(0, mglev);
817 if (bc[0])
818 {
819 petsc_solver->setBCoeffs(bc);
820 }
821 else
822 {
823 Array<MultiFab,AMREX_SPACEDIM> beta;
824 for (int idim = 0; idim < AMREX_SPACEDIM; ++idim)
825 {
826 beta[idim].define(amrex::convert(ba,IntVect::TheDimensionVector(idim)),
827 dm, 1, 0, MFInfo(), factory);
828 beta[idim].setVal(1.0);
829 }
830 petsc_solver->setBCoeffs(amrex::GetArrOfConstPtrs(beta));
831 }
832 return petsc_solver;
833 }
834 return nullptr;
835}
836#endif
837
838extern template class MLCellABecLapT<MultiFab>;
839
842
843}
844
845#endif
#define BL_PROFILE(a)
Definition AMReX_BLProfiler.H:551
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
#define AMREX_HOST_DEVICE_PARALLEL_FOR_3D(...)
Definition AMReX_GpuLaunchMacrosC.nolint.H:110
#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_GPU_DEVICE
Definition AMReX_GpuQualifiers.H:18
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
Array4< Real > fine
Definition AMReX_InterpFaceRegister.cpp:90
Array4< Real const > crse
Definition AMReX_InterpFaceRegister.cpp:92
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Maintain an identifier for boundary condition types.
Definition AMReX_BoundCond.H:25
__host__ __device__ bool contains(const IntVectND< dim > &p) const noexcept
Return true if argument is contained within BoxND.
Definition AMReX_Box.H:233
__host__ __device__ bool coarsenable(const IntVectND< dim > &refrat, const IntVectND< dim > &min_width) const noexcept
Return whether this Box is coarsenable.
Definition AMReX_Box.H:802
__host__ __device__ BoxND & coarsen(int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition AMReX_Box.H:754
const FAB & get(const MFIter &mfi) const noexcept
Return a constant reference to the FAB associated with mfi.
Definition AMReX_FabArray.H:511
Definition AMReX_FabFactory.H:50
Interface
HYPRE interface modes supported.
Definition AMReX_Hypre.H:37
__host__ static __device__ constexpr IntVectND< dim > TheDimensionVector(int d) noexcept
This static member function returns a reference to a constant IntVectND object, all of whose dim argu...
Definition AMReX_IntVect.H:790
Iterator for looping ever tiles and boxes of amrex::FabArray based containers.
Definition AMReX_MFIter.H:88
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:172
Cell-centered operator that exposes ABec Laplacian helpers to derived classes.
Definition AMReX_MLCellABecLap.H:22
void addInhomogNeumannFlux(int amrlev, const Array< MF *, 3 > &grad, MF const &sol, bool mult_bcoef) const final
Add inhomogeneous Neumann/Robin flux contributions into grad from sol (include b when mult_bcoef is t...
Definition AMReX_MLCellABecLap.H:579
MLCellABecLapT(const MLCellABecLapT< MF > &)=delete
void getFluxes(const Vector< MF * > &a_flux, const Vector< MF * > &a_sol) const final
Guard overload that aborts if called (cell-centered flux extraction requires per-direction face array...
Definition AMReX_MLCellABecLap.H:104
LPInfo m_lpinfo_arg
Definition AMReX_MLCellABecLap.H:143
virtual MF const * getACoeffs(int amrlev, int mglev) const =0
Cell-centered a coefficient MultiFab for AMR level amrlev and MG level mglev.
void getFluxes(const Vector< Array< MF *, 3 > > &a_flux, const Vector< MF * > &a_sol, Location a_loc) const final
Fill per-face fluxes using the supplied solution hierarchy.
Definition AMReX_MLCellABecLap.H:332
MLCellABecLapT< MF > & operator=(const MLCellABecLapT< MF > &)=delete
MLCellABecLapT(MLCellABecLapT< MF > &&)=delete
virtual Array< MF const *, 3 > getBCoeffs(int amrlev, int mglev) const =0
Face-centered b coefficients for AMR level amrlev and MG level mglev.
typename MF::value_type RT
Definition AMReX_MLCellABecLap.H:26
void setDirichletNodesToZero(int amrlev, int mglev, MF &mf) const override
Zero out Dirichlet nodes on (amrlev,mglev) so that GMRES can treat them as known.
Definition AMReX_MLCellABecLap.H:312
void applyOverset(int amrlev, MF &rhs) const override
Zero RHS entries in rhs that are covered by overset masks on level amrlev.
Definition AMReX_MLCellABecLap.H:689
virtual RT getBScalar() const =0
Scalar applied to b on the current operator.
iMultiFab const * getOversetMask(int amrlev, int mglev) const
Overset mask for (amrlev,mglev); returns nullptr when not defined.
Definition AMReX_MLCellABecLap.H:71
bool needsUpdate() const override
Does it need update if it's reused?
Definition AMReX_MLCellABecLap.H:75
typename MLLinOpT< MF >::Location Location
Definition AMReX_MLCellABecLap.H:28
typename MF::fab_type FAB
Definition AMReX_MLCellABecLap.H:25
Vector< Vector< std::unique_ptr< iMultiFab > > > m_overset_mask
Definition AMReX_MLCellABecLap.H:141
void define(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const LPInfo &a_info=LPInfo(), const Vector< FabFactory< FAB > const * > &a_factory={})
Describe the AMR hierarchy when overset masks are not required.
Definition AMReX_MLCellABecLap.H:150
bool supportInhomogNeumannBC() const noexcept override
Definition AMReX_MLCellABecLap.H:145
void prepareForSolve() override
Standard hook called before MLMG iterates (fixes BC data, etc.).
Definition AMReX_MLCellABecLap.H:305
~MLCellABecLapT() override=default
virtual RT getAScalar() const =0
Scalar applied to a on the current operator.
void applyInhomogNeumannTerm(int amrlev, MF &rhs) const final
Apply stored Neumann data to the RHS rhs on AMR level amrlev.
Definition AMReX_MLCellABecLap.H:357
void update() override
Average coefficients/metrics when marked dirty.
Definition AMReX_MLCellABecLap.H:298
Definition AMReX_MLCellLinOp.H:31
void update() override
Update for reuse.
Definition AMReX_MLCellLinOp.H:942
void prepareForSolve() override
Prepare multilevel metadata before MLMG iterates (coefficients, BC caches, etc.).
Definition AMReX_MLCellLinOp.H:1948
void define(const Vector< Geometry > &a_geom, const Vector< BoxArray > &a_grids, const Vector< DistributionMapping > &a_dmap, const LPInfo &a_info=LPInfo(), const Vector< FabFactory< FAB > const * > &a_factory={})
Bind the operator to an AMR hierarchy.
Definition AMReX_MLCellLinOp.H:648
bool needsUpdate() const override
Does it need update if it's reused?
Definition AMReX_MLCellLinOp.H:93
An Iterator over the Orientation of Faces of a Box.
Definition AMReX_Orientation.H:135
__host__ __device__ bool isValid() const noexcept
Is the iterator valid?
Definition AMReX_Orientation.H:156
Encapsulation of the Orientation of the Faces of a Box.
Definition AMReX_Orientation.H:29
__host__ __device__ bool isLow() const noexcept
Returns true if Orientation is low.
Definition AMReX_Orientation.H:89
__host__ __device__ int coordDir() const noexcept
Returns the coordinate direction.
Definition AMReX_Orientation.H:83
@ low
Definition AMReX_Orientation.H:34
@ high
Definition AMReX_Orientation.H:34
Definition AMReX_Reduce.H:438
Type value()
Definition AMReX_Reduce.H:473
Definition AMReX_Reduce.H:597
void eval(MF const &mf, IntVect const &nghost, D &reduce_data, F &&f)
Definition AMReX_Reduce.H:731
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
static void Copy(iMultiFab &dst, const iMultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
Copy from src to dst including nghost ghost cells. The two iMultiFabs MUST have the same underlying B...
Definition AMReX_iMultiFab.cpp:51
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
__host__ __device__ BoxND< dim > adjCellHi(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the high end along coordinate direction dir.
Definition AMReX_Box.H:1848
__host__ __device__ BoxND< dim > convert(const BoxND< dim > &b, const IntVectND< dim > &typ) noexcept
Return a copy of b converted to the nodal flags typ.
Definition AMReX_Box.H:1630
__host__ __device__ BoxND< dim > adjCellLo(const BoxND< dim > &b, int dir, int len=1) noexcept
Return the BoxND of length len adjacent to b on the low end along coordinate direction dir.
Definition AMReX_Box.H:1817
__host__ __device__ BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b coarsened by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1469
__host__ __device__ BoxND< dim > adjCell(const BoxND< dim > &b, Orientation face, int len=1) noexcept
Similar to adjCellLo and adjCellHi except that it operates on the given face of BoxND b.
Definition AMReX_Box.H:1880
__host__ __device__ BoxND< dim > refine(const BoxND< dim > &b, int ref_ratio) noexcept
Return a copy of b refined by the isotropic ratio ref_ratio.
Definition AMReX_Box.H:1510
std::array< T, N > Array
Definition AMReX_Array.H:31
void Min(KeyValuePair< K, V > &vi, MPI_Comm comm)
Definition AMReX_ParallelReduce.H:161
void streamSynchronize() noexcept
Definition AMReX_GpuDevice.H:310
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
bool notInLaunchRegion() noexcept
Definition AMReX_GpuControl.H:89
bool inNoSyncRegion() noexcept
Definition AMReX_GpuControl.H:148
MPI_Comm CommunicatorSub() noexcept
sub-communicator for current frame
Definition AMReX_ParallelContext.H:70
int MPI_Comm
Definition AMReX_ccse-mpi.H:51
Definition AMReX_Amr.cpp:50
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:259
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 ParallelFor(TypeList< CTOs... > ctos, std::array< int, sizeof...(CTOs)> const &runtime_options, T N, F &&f)
Definition AMReX_CTOParallelForImpl.H:202
BoxND< 3 > Box
Box is an alias for amrex::BoxND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:35
bool isMFIterSafe(const FabArrayBase &x, const FabArrayBase &y)
Definition AMReX_MFIter.H:252
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
std::unique_ptr< Hypre > makeHypre(const BoxArray &grids, const DistributionMapping &dmap, const Geometry &geom, MPI_Comm comm_, Hypre::Interface interface, const iMultiFab *overset_mask)
Factory that instantiates the requested HYPRE interface.
Definition AMReX_Hypre.cpp:12
bool TilingIfNotGPU() noexcept
Definition AMReX_MFIter.H:12
std::unique_ptr< PETScABecLap > makePetsc(const BoxArray &grids, const DistributionMapping &dmap, const Geometry &geom, MPI_Comm comm_)
Factory helper that instantiates a PETSc ABec Laplacian on one level.
Definition AMReX_PETSc.cpp:58
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:241
A multidimensional array accessor.
Definition AMReX_Array4.H:288
A simple struct holding 3 int values for a 3D index.
Definition AMReX_Dim3.H:24
int x
Definition AMReX_Dim3.H:24
int z
Definition AMReX_Dim3.H:24
int y
Definition AMReX_Dim3.H:24
Configuration knobs for multilevel linear operators (grid agglomeration, metrics, etc....
Definition AMReX_MLLinOp.H:51
int max_coarsening_level
Definition AMReX_MLLinOp.H:60
Location
Definition AMReX_MLLinOp.H:119
FabArray memory allocation information.
Definition AMReX_FabArray.H:68
Definition AMReX_MFIter.H:20
MFItInfo & SetDynamic(bool f) noexcept
Definition AMReX_MFIter.H:43