Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MultiFab.H
Go to the documentation of this file.
1
2#ifndef BL_MULTIFAB_H
3#define BL_MULTIFAB_H
4#include <AMReX_Config.H>
5
6#include <AMReX_BLassert.H>
7#include <AMReX_BaseFab.H>
8#include <AMReX_FArrayBox.H>
9#include <AMReX_FabArray.H>
11#include <AMReX_Periodicity.H>
12#include <AMReX_NonLocalBC.H>
13
14#include <cstdint>
15
16namespace amrex
17{
18
20
21class iMultiFab;
22
38 :
39 public FabArray<FArrayBox>
40{
41public:
42
49 MultiFab () noexcept;
50
59 explicit MultiFab (Arena* a) noexcept;
60
76 MultiFab (const BoxArray& bxs,
77 const DistributionMapping& dm,
78 int ncomp,
79 int ngrow,
80#ifdef AMREX_STRICT_MODE
81 const MFInfo& info,
82 const FabFactory<FArrayBox>& factory);
83#else
84 const MFInfo& info = MFInfo(),
85 const FabFactory<FArrayBox>& factory = FArrayBoxFactory());
86#endif
87
88 MultiFab (const BoxArray& bxs,
89 const DistributionMapping& dm,
90 int ncomp,
91 const IntVect& ngrow,
92#ifdef AMREX_STRICT_MODE
93 const MFInfo& info,
94 const FabFactory<FArrayBox>& factory);
95#else
96 const MFInfo& info = MFInfo(),
97 const FabFactory<FArrayBox>& factory = FArrayBoxFactory());
98#endif
99
107 MultiFab (const MultiFab& rhs, MakeType maketype, int scomp, int ncomp);
108
109 ~MultiFab ();
110
111 MultiFab (MultiFab&& rhs) noexcept;
112 MultiFab& operator= (MultiFab&& rhs) noexcept = default;
113
114 MultiFab (const MultiFab& rhs) = delete;
115 MultiFab& operator= (const MultiFab& rhs) = delete;
116
117 void define (const BoxArray& bxs,
118 const DistributionMapping& dm,
119 int nvar,
120 int ngrow,
121#ifdef AMREX_STRICT_MODE
122 const MFInfo& info,
123 const FabFactory<FArrayBox>& factory);
124#else
125 const MFInfo& info = MFInfo(),
126 const FabFactory<FArrayBox>& factory = FArrayBoxFactory());
127#endif
128
129 void define (const BoxArray& bxs,
130 const DistributionMapping& dm,
131 int nvar,
132 const IntVect& ngrow,
133#ifdef AMREX_STRICT_MODE
134 const MFInfo& info,
135 const FabFactory<FArrayBox>& factory);
136#else
137 const MFInfo& info = MFInfo(),
138 const FabFactory<FArrayBox>& factory = FArrayBoxFactory());
139#endif
140
142
155 [[nodiscard]] Real min (int comp,
156 int nghost = 0,
157 bool local = false) const;
164 [[nodiscard]] Real min (const Box& region,
165 int comp,
166 int nghost = 0,
167 bool local = false) const;
180 [[nodiscard]] Real max (int comp,
181 int nghost = 0,
182 bool local = false) const;
189 [[nodiscard]] Real max (const Box& region,
190 int comp,
191 int nghost = 0,
192 bool local = false) const;
199 [[nodiscard]] Real norm0 (int comp = 0, int nghost = 0, bool local = false, bool ignore_covered = false ) const;
201 [[nodiscard]] Real norminf (int comp = 0, int nghost = 0, bool local = false, bool ignore_covered = false ) const {
202 return norm0(comp,nghost,local,ignore_covered);
203 }
204
210 [[nodiscard]] Real norm0 (const iMultiFab& mask, int comp = 0, int nghost = 0, bool local = false) const;
212 [[nodiscard]] Real norminf (const iMultiFab& mask, int comp = 0, int nghost = 0, bool local = false) const {
213 return norm0(mask,comp,nghost,local);
214 }
215
221 [[nodiscard]] Real norm0 (int comp, int ncomp, IntVect const& nghost, bool local = false,
222 bool ignore_covered = false) const;
223
225
232 [[nodiscard]] Vector<Real> norm0 (const Vector<int>& comps, int nghost = 0, bool local = false, bool ignore_covered = false ) const;
234 [[nodiscard]] Vector<Real> norminf (const Vector<int>& comps, int nghost = 0, bool local = false, bool ignore_covered = false) const {
235 return norm0(comps,nghost,local,ignore_covered);
236 }
237
245 [[nodiscard]] Real norm1 (int comp, const Periodicity& period, bool ignore_covered = false) const;
253 [[nodiscard]] Real norm1 (int comp = 0, int ngrow = 0, bool local = false) const;
261 [[nodiscard]] Vector<Real> norm1 (const Vector<int>& comps, int ngrow = 0, bool local = false) const;
269 [[nodiscard]] Real norm2 (int comp = 0) const;
277 [[nodiscard]] Real norm2 (int comp, int numcomp) const;
285 [[nodiscard]] Real norm2 (int comp, const Periodicity& period) const;
293 [[nodiscard]] Vector<Real> norm2 (const Vector<int>& comps) const;
300 [[nodiscard]] Real sum (int comp = 0, bool local = false) const;
307 [[nodiscard]] Real sum (Box const& region, int comp = 0, bool local = false) const;
308
310
318 [[nodiscard]] Real sum_unique (int comp = 0,
319 bool local = false,
320 const Periodicity& period = Periodicity::NonPeriodic()) const;
329 [[nodiscard]] Real sum_unique (Box const& region, int comp = 0, bool local = false) const;
339 void plus (Real val,
340 int comp,
341 int num_comp,
342 int nghost = 0);
348 void plus (Real val,
349 const Box& region,
350 int comp,
351 int num_comp,
352 int nghost = 0);
359 void plus (Real val,
360 int nghost);
368 void plus (Real val,
369 const Box& region,
370 int nghost);
379 void mult (Real val,
380 int comp,
381 int num_comp,
382 int nghost = 0);
390 void mult (Real val,
391 const Box& region,
392 int comp,
393 int num_comp,
394 int nghost = 0);
401 void mult (Real val,
402 int nghost = 0);
410 void mult (Real val,
411 const Box& region,
412 int nghost = 0);
421 void invert (Real numerator,
422 int comp,
423 int num_comp,
424 int nghost = 0);
432 void invert (Real numerator,
433 const Box& region,
434 int comp,
435 int num_comp,
436 int nghost = 0);
443 void invert (Real numerator,
444 int nghost);
452 void invert (Real numerator,
453 const Box& region,
454 int nghost);
462 void negate (int comp,
463 int num_comp,
464 int nghost = 0);
470 void negate (const Box& region,
471 int comp,
472 int num_comp,
473 int nghost = 0);
479 void negate (int nghost = 0);
486 void negate (const Box& region,
487 int nghost = 0);
488
494 [[nodiscard]] IntVect minIndex (int comp,
495 int nghost = 0) const;
496
502 [[nodiscard]] IntVect maxIndex (int comp,
503 int nghost = 0) const;
513 void plus (const MultiFab& mf,
514 int strt_comp,
515 int num_comp,
516 int nghost);
526 void minus (const MultiFab& mf,
527 int strt_comp,
528 int num_comp,
529 int nghost);
540 void divide (const MultiFab& mf,
541 int strt_comp,
542 int num_comp,
543 int nghost);
550 static Real Dot (const MultiFab& x, int xcomp,
551 const MultiFab& y, int ycomp,
552 int numcomp, int nghost, bool local = false);
553
560 static Real Dot (const MultiFab& x, int xcomp,
561 int numcomp, int nghost, bool local = false);
562
566 static Real Dot (const iMultiFab& mask,
567 const MultiFab& x, int xcomp,
568 const MultiFab& y, int ycomp,
569 int numcomp, int nghost, bool local = false);
574 static void Add (MultiFab& dst,
575 const MultiFab& src,
576 int srccomp,
577 int dstcomp,
578 int numcomp,
579 int nghost);
580
581 static void Add (MultiFab& dst,
582 const MultiFab& src,
583 int srccomp,
584 int dstcomp,
585 int numcomp,
586 const IntVect& nghost);
587
593 [[nodiscard]] MultiFab deepCopy () const;
594
600 static void Copy (MultiFab& dst,
601 const MultiFab& src,
602 int srccomp,
603 int dstcomp,
604 int numcomp,
605 int nghost);
606
607 static void Copy (MultiFab& dst,
608 const MultiFab& src,
609 int srccomp,
610 int dstcomp,
611 int numcomp,
612 const IntVect& nghost);
613
619 static void Swap (MultiFab& dst,
620 MultiFab& src,
621 int srccomp,
622 int dstcomp,
623 int numcomp,
624 int nghost);
625
626 static void Swap (MultiFab& dst,
627 MultiFab& src,
628 int srccomp,
629 int dstcomp,
630 int numcomp,
631 const IntVect& nghost);
632
637 static void Subtract (MultiFab& dst,
638 const MultiFab& src,
639 int srccomp,
640 int dstcomp,
641 int numcomp,
642 int nghost);
643
644 static void Subtract (MultiFab& dst,
645 const MultiFab& src,
646 int srccomp,
647 int dstcomp,
648 int numcomp,
649 const IntVect& nghost);
654 static void Multiply (MultiFab& dst,
655 const MultiFab& src,
656 int srccomp,
657 int dstcomp,
658 int numcomp,
659 int nghost);
660
661 static void Multiply (MultiFab& dst,
662 const MultiFab& src,
663 int srccomp,
664 int dstcomp,
665 int numcomp,
666 const IntVect& nghost);
671 static void Divide (MultiFab& dst,
672 const MultiFab& src,
673 int srccomp,
674 int dstcomp,
675 int numcomp,
676 int nghost);
677
678 static void Divide (MultiFab& dst,
679 const MultiFab& src,
680 int srccomp,
681 int dstcomp,
682 int numcomp,
683 const IntVect& nghost);
687 static void Saxpy (MultiFab& dst,
688 Real a,
689 const MultiFab& src,
690 int srccomp,
691 int dstcomp,
692 int numcomp,
693 int nghost);
694
696
700 static void Xpay (MultiFab& dst,
701 Real a,
702 const MultiFab& src,
703 int srccomp,
704 int dstcomp,
705 int numcomp,
706 int nghost);
707
709
713 static void LinComb (MultiFab& dst,
714 Real a,
715 const MultiFab& x,
716 int xcomp,
717 Real b,
718 const MultiFab& y,
719 int ycomp,
720 int dstcomp,
721 int numcomp,
722 int nghost);
723
725
729 static void AddProduct (MultiFab& dst,
730 const MultiFab& src1,
731 int comp1,
732 const MultiFab& src2,
733 int comp2,
734 int dstcomp,
735 int numcomp,
736 int nghost);
737
738 static void AddProduct (MultiFab& dst,
739 const MultiFab& src1,
740 int comp1,
741 const MultiFab& src2,
742 int comp2,
743 int dstcomp,
744 int numcomp,
745 const IntVect& nghost);
746
756 [[nodiscard]] bool is_finite (bool local=false) const;
757 [[nodiscard]] bool is_finite (int scomp, int ncomp, int ngrow = 0, bool local=false) const;
758 [[nodiscard]] bool is_finite (int scomp, int ncomp, const IntVect& ngrow, bool local=false) const;
759
769 [[nodiscard]] bool contains_nan (bool local=false) const;
770 [[nodiscard]] bool contains_nan (int scomp, int ncomp, int ngrow = 0, bool local=false) const;
771 [[nodiscard]] bool contains_nan (int scomp, int ncomp, const IntVect& ngrow, bool local=false) const;
780 [[nodiscard]] bool contains_inf (bool local=false) const;
781 [[nodiscard]] bool contains_inf (int scomp, int ncomp, int ngrow = 0, bool local=false) const;
782 [[nodiscard]] bool contains_inf (int scomp, int ncomp, const IntVect& ngrow, bool local=false) const;
783
787 [[nodiscard]] std::unique_ptr<MultiFab> OverlapMask (const Periodicity& period = Periodicity::NonPeriodic()) const;
789 [[nodiscard]] std::unique_ptr<iMultiFab> OwnerMask (const Periodicity& period = Periodicity::NonPeriodic()) const;
790
792 void AverageSync (const Periodicity& period = Periodicity::NonPeriodic());
794 void WeightedSync (const MultiFab& wgt, const Periodicity& period = Periodicity::NonPeriodic());
812 void OverrideSync (const iMultiFab& msk, const Periodicity& period = Periodicity::NonPeriodic());
813
815
816 static void Initialize ();
817 static void Finalize ();
818
819private:
820 //
822 using CopyComTagsContainer = FabArrayBase::CopyComTagsContainer;
823 using MapOfCopyComTagContainers = FabArrayBase::MapOfCopyComTagContainers;
824
825 void initVal ();
826};
827
828#ifndef _MSC_VER
829inline void GccPlacaterMF ()
830{
831 std::allocator<MultiFab*> a1;
832 std::allocator<MultiFab const*> a2;
833 std::allocator<FabArray<FArrayBox>*> a3;
834 std::allocator<FabArray<FArrayBox> const*> a4;
835
840}
841#endif
842
843}
844
845#endif /*BL_MULTIFAB_H*/
Assertion macros used across AMReX for runtime consistency checks.
BaseFab container template providing box-based field storage.
Floating-point specialization of BaseFab plus FAB I/O helpers.
Reduction helpers and utility algorithms for FabArray objects.
Distributed container of FAB objects plus copy and fill utilities.
Array4< int const > mask
Definition AMReX_InterpFaceRegister.cpp:93
Abstract base class for memory arenas.
Definition AMReX_Arena.H:153
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
A Fortran Array of REALs.
Definition AMReX_FArrayBox.H:237
CopyComTag::CopyComTagsContainer CopyComTagsContainer
Definition AMReX_FabArrayBase.H:236
CopyComTag::MapOfCopyComTagContainers MapOfCopyComTagContainers
Definition AMReX_FabArrayBase.H:237
An Array of FortranArrayBox(FAB)-like Objects.
Definition AMReX_FabArray.H:356
Abstract factory interface for creating, aliasing, and destroying FAB objects.
Definition AMReX_FabFactory.H:73
A collection (stored as an array) of FArrayBox objects.
Definition AMReX_MultiFab.H:40
static void LinComb(MultiFab &dst, Real a, const MultiFab &x, int xcomp, Real b, const MultiFab &y, int ycomp, int dstcomp, int numcomp, int nghost)
dst = a*x + b*y
Definition AMReX_MultiFab.cpp:306
void define(const BoxArray &bxs, const DistributionMapping &dm, int nvar, int ngrow, const MFInfo &info=MFInfo(), const FabFactory< FArrayBox > &factory=FArrayBoxFactory())
Definition AMReX_MultiFab.cpp:519
void invert(Real numerator, int comp, int num_comp, int nghost=0)
Replaces the value of each cell in the specified subregion of the MultiFab with its reciprocal multip...
Definition AMReX_MultiFab.cpp:1523
void minus(const MultiFab &mf, int strt_comp, int num_comp, int nghost)
This function subtracts the values of the cells in mf from the corresponding cells of this MultiFab....
Definition AMReX_MultiFab.cpp:1464
Real norm0(int comp=0, int nghost=0, bool local=false, bool ignore_covered=false) const
Returns the maximum absolute value contained in component comp of the MultiFab.
Definition AMReX_MultiFab.cpp:1121
static void Swap(MultiFab &dst, MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
Swap from src to dst including nghost ghost cells. The two MultiFabs MUST have the same underlying Bo...
Definition AMReX_MultiFab.cpp:213
std::unique_ptr< iMultiFab > OwnerMask(const Periodicity &period=Periodicity::NonPeriodic()) const
Owner is the grid with the lowest grid number containing the data.
Definition AMReX_MultiFab.cpp:1627
static void Add(MultiFab &dst, const MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
Add src to dst including nghost ghost cells. The two MultiFabs MUST have the same underlying BoxArray...
Definition AMReX_MultiFab.cpp:151
bool contains_nan(bool local=false) const
Are there any NaNs in the MF? This may return false, even if the MF contains NaNs,...
Definition AMReX_MultiFab.cpp:664
static void Saxpy(MultiFab &dst, Real a, const MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
dst += a*src
Definition AMReX_MultiFab.cpp:292
Real min(int comp, int nghost=0, bool local=false) const
Returns the minimum value contained in component comp of the MultiFab.
Definition AMReX_MultiFab.cpp:725
Real norm1(int comp, const Periodicity &period, bool ignore_covered=false) const
Returns the L1 norm of component comp over the MultiFab.
Definition AMReX_MultiFab.cpp:1229
static void Subtract(MultiFab &dst, const MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
Subtract src from dst including nghost ghost cells. The two MultiFabs MUST have the same underlying B...
Definition AMReX_MultiFab.cpp:232
static void Multiply(MultiFab &dst, const MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
Multiply dst by src including nghost ghost cells. The two MultiFabs MUST have the same underlying Box...
Definition AMReX_MultiFab.cpp:252
static void AddProduct(MultiFab &dst, const MultiFab &src1, int comp1, const MultiFab &src2, int comp2, int dstcomp, int numcomp, int nghost)
dst += src1*src2
Definition AMReX_MultiFab.cpp:315
bool is_finite(bool local=false) const
Are the numbers in the MF finite (i.e., neither nan nor inf)? This may return true,...
Definition AMReX_MultiFab.cpp:609
static void Initialize()
Definition AMReX_MultiFab.cpp:422
void AverageSync(const Periodicity &period=Periodicity::NonPeriodic())
Sync up nodal data via averaging.
Definition AMReX_MultiFab.cpp:1633
bool contains_inf(bool local=false) const
Are there any Infs in the MF? This may return false, even if the MF contains Infs,...
Definition AMReX_MultiFab.cpp:719
static void Xpay(MultiFab &dst, Real a, const MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
dst = src + a*dst
Definition AMReX_MultiFab.cpp:299
static void Divide(MultiFab &dst, const MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
Divide dst by src including nghost ghost cells. The two MultiFabs MUST have the same underlying BoxAr...
Definition AMReX_MultiFab.cpp:272
void mult(Real val, int comp, int num_comp, int nghost=0)
Scales the value of each cell in the specified subregion of the MultiFab by the scalar val (a[i] <- a...
Definition AMReX_MultiFab.cpp:1503
void plus(Real val, int comp, int num_comp, int nghost=0)
Adds the scalar value val to the value of each cell in the specified subregion of the MultiFab.
Definition AMReX_MultiFab.cpp:1476
static void Copy(MultiFab &dst, const MultiFab &src, int srccomp, int dstcomp, int numcomp, int nghost)
Copy from src to dst including nghost ghost cells. The two MultiFabs MUST have the same underlying Bo...
Definition AMReX_MultiFab.cpp:193
Real max(int comp, int nghost=0, bool local=false) const
Returns the maximum value contained in component comp of the MultiFab.
Definition AMReX_MultiFab.cpp:897
MultiFab() noexcept
Constructs an empty MultiFab.
Definition AMReX_MultiFab.cpp:443
void divide(const MultiFab &mf, int strt_comp, int num_comp, int nghost)
This function divides the values of the cells in mf from the corresponding cells of this MultiFab....
Definition AMReX_MultiFab.cpp:1470
void negate(int comp, int num_comp, int nghost=0)
Negates the value of each cell in the specified subregion of the MultiFab. The subregion consists of ...
Definition AMReX_MultiFab.cpp:1543
MultiFab & operator=(MultiFab &&rhs) noexcept=default
MultiFab deepCopy() const
Definition AMReX_MultiFab.cpp:171
void WeightedSync(const MultiFab &wgt, const Periodicity &period=Periodicity::NonPeriodic())
Sync up nodal data with weights.
Definition AMReX_MultiFab.cpp:1644
MultiFab(const MultiFab &rhs)=delete
~MultiFab()
Definition AMReX_MultiFab.cpp:504
static void Finalize()
Definition AMReX_MultiFab.cpp:438
std::unique_ptr< MultiFab > OverlapMask(const Periodicity &period=Periodicity::NonPeriodic()) const
Return a mask indicating how many duplicates are in each point.
Definition AMReX_MultiFab.cpp:1561
void OverrideSync(const iMultiFab &msk, const Periodicity &period=Periodicity::NonPeriodic())
Synchronize nodal data. The synchronization will override valid regions by the intersecting valid reg...
Definition AMReX_MultiFab.cpp:1664
This provides length of period for periodic domains. 0 means it is not periodic in that direction....
Definition AMReX_Periodicity.H:17
static const Periodicity & NonPeriodic() noexcept
Definition AMReX_Periodicity.cpp:52
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
A Collection of IArrayBoxes.
Definition AMReX_iMultiFab.H:34
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
static Real Dot(const MultiFab &x, int xcomp, const MultiFab &y, int ycomp, int numcomp, int nghost, bool local=false)
Returns the dot product of two MultiFabs.
Definition AMReX_MultiFab.cpp:37
Real sum(int comp=0, bool local=false) const
Returns the sum of component "comp" over the MultiFab – no ghost cells are included.
Definition AMReX_MultiFab.cpp:1309
IntVect maxIndex(int comp, int nghost=0) const
Definition AMReX_MultiFab.cpp:1107
Vector< Real > norminf(const Vector< int > &comps, int nghost=0, bool local=false, bool ignore_covered=false) const
Definition AMReX_MultiFab.H:234
Real norminf(int comp=0, int nghost=0, bool local=false, bool ignore_covered=false) const
Definition AMReX_MultiFab.H:201
Real norm2(int comp=0) const
Returns the L2 norm of component comp over the MultiFab. No ghost cells are used.
Definition AMReX_MultiFab.cpp:1151
IntVect minIndex(int comp, int nghost=0) const
Definition AMReX_MultiFab.cpp:1099
Real norminf(const iMultiFab &mask, int comp=0, int nghost=0, bool local=false) const
Definition AMReX_MultiFab.H:212
Real sum_unique(int comp=0, bool local=false, const Periodicity &period=Periodicity::NonPeriodic()) const
Same as sum with local =false, but for non-cell-centered data, this only adds non-unique points that ...
Definition AMReX_MultiFab.cpp:1357
Definition AMReX_Amr.cpp:50
MakeType
Definition AMReX_MakeType.H:7
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:259
DefaultFabFactory< FArrayBox > FArrayBoxFactory
Definition AMReX_FArrayBox.H:547
void GccPlacaterMF()
Definition AMReX_MultiFab.H:829
FabArray memory allocation information.
Definition AMReX_FabArray.H:73