Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_AmrMesh.H
Go to the documentation of this file.
1#ifndef BL_AMRMESH_H_
2#define BL_AMRMESH_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_Array.H>
6#include <AMReX_Vector.H>
7#include <AMReX_RealBox.H>
8#include <AMReX_IntVect.H>
9#include <AMReX_Geometry.H>
11#include <AMReX_BoxArray.H>
12#include <AMReX_TagBox.H>
13
19#ifdef AMREX_USE_BITTREE
20#include <Bittree_BittreeAmr.h>
21#endif
22
23namespace amrex {
24
25struct AmrInfo {
26 int verbose = 0;
28 int max_level = 0;
34#if defined(AMREX_USE_GPU)
36#else
38#endif
42 Real grid_eff = static_cast<Real>(0.7);
44 int n_proper = 1;
47
52 bool refine_grid_layout = true;
53
59
60 bool check_input = true;
61 bool use_new_chop = false;
64};
65
68 : protected AmrInfo
69{
70public:
71
79 friend std::ostream& operator<< (std::ostream& os, AmrMesh const& amr_mesh);
80
82 AmrMesh ();
83
96 AmrMesh (const RealBox* rb, int max_level_in,
97 const Vector<int>& n_cell_in, int coord=-1,
99 const int* is_per = nullptr);
100
111 AmrMesh (const RealBox& rb, int max_level_in,
112 const Vector<int>& n_cell_in, int coord,
113 Vector<IntVect> const& a_refrat,
114 Array<int,AMREX_SPACEDIM> const& is_per);
115
122 AmrMesh (Geometry const& level_0_geom, AmrInfo const& amr_info);
123
124 AmrMesh (const AmrMesh& rhs) = delete;
125 AmrMesh& operator= (const AmrMesh& rhs) = delete;
126
127 AmrMesh (AmrMesh&& rhs) = default;
128 AmrMesh& operator= (AmrMesh&& rhs) = default;
129
130 virtual ~AmrMesh () = default;
131
132 [[nodiscard]] int Verbose () const noexcept { return verbose; }
133
135 [[nodiscard]] int maxLevel () const noexcept { return max_level; }
136
138 [[nodiscard]] int finestLevel () const noexcept { return finest_level; }
139
141 [[nodiscard]] IntVect refRatio (int lev) const noexcept { return ref_ratio[lev]; }
142
144 [[nodiscard]] int MaxRefRatio (int lev) const noexcept;
145
147 [[nodiscard]] const Vector<IntVect>& refRatio () const noexcept { return ref_ratio; }
148
149 [[nodiscard]] const Vector<Geometry>& Geom () const noexcept { return geom; }
150 [[nodiscard]] const Vector<DistributionMapping>& DistributionMap () const noexcept { return dmap; }
151 [[nodiscard]] const Vector<BoxArray>& boxArray () const noexcept { return grids; }
152
153 [[nodiscard]] const Geometry& Geom (int lev) const noexcept { return geom[lev]; }
154 [[nodiscard]] const DistributionMapping& DistributionMap (int lev) const noexcept { return dmap[lev]; }
155 [[nodiscard]] const BoxArray& boxArray (int lev) const noexcept { return grids[lev]; }
156
157 [[nodiscard]] Vector<Geometry> Geom (int a_coarsest_lev, int a_finest_lev) const noexcept {
159 r.reserve(a_finest_lev-a_coarsest_lev+1);
160 for (int lev = a_coarsest_lev; lev <= a_finest_lev; ++lev) {
161 r.push_back(geom[lev]);
162 }
163 return r;
164 }
165 [[nodiscard]] Vector<BoxArray> boxArray (int a_coarsest_lev, int a_finest_lev) const noexcept {
167 r.reserve(a_finest_lev-a_coarsest_lev+1);
168 for (int lev = a_coarsest_lev; lev <= a_finest_lev; ++lev) {
169 r.push_back(grids[lev]);
170 }
171 return r;
172 }
173 [[nodiscard]] Vector<DistributionMapping> DistributionMap (int a_coarsest_lev, int a_finest_lev) const noexcept {
175 r.reserve(a_finest_lev-a_coarsest_lev+1);
176 for (int lev = a_coarsest_lev; lev <= a_finest_lev; ++lev) {
177 r.push_back(dmap[lev]);
178 }
179 return r;
180 }
181
182 Vector<Geometry>& Geom () noexcept { return geom; }
183 Geometry& Geom (int lev) noexcept { return geom[lev]; }
184
190 void SetMaxGridSize (int new_mgs) noexcept {
191 max_grid_size.assign(max_level+1, IntVect{AMREX_D_DECL(new_mgs,new_mgs,new_mgs)});
192 }
194 void SetMaxGridSize (const IntVect& new_mgs) noexcept {
195 max_grid_size.assign(max_level+1, new_mgs);
196 }
198 void SetMaxGridSize (const Vector<int>& new_mgs) noexcept {
199 max_grid_size.resize(max_level+1);
200 for (int i = 0; i <= max_level; ++i) {
201 max_grid_size[i] = IntVect{AMREX_D_DECL(new_mgs[i],new_mgs[i],new_mgs[i])};
202 }
203 }
205 void SetMaxGridSize (const Vector<IntVect>& new_mgs) noexcept {
206 max_grid_size.assign(new_mgs.cbegin(), new_mgs.cbegin()+max_level+1);
207 }
208
214 void SetBlockingFactor (int new_bf) noexcept {
215 blocking_factor.assign(max_level+1, IntVect{AMREX_D_DECL(new_bf,new_bf,new_bf)});
216 }
218 void SetBlockingFactor (const IntVect& new_bf) noexcept {
219 blocking_factor.assign(max_level+1, new_bf);
220 }
222 void SetBlockingFactor (const Vector<int>& new_bf) noexcept {
223 blocking_factor.resize(max_level+1);
224 for (int i = 0; i <= max_level; ++i) {
225 blocking_factor[i] = IntVect{AMREX_D_DECL(new_bf[i],new_bf[i],new_bf[i])};
226 }
227 }
229 void SetBlockingFactor (const Vector<IntVect>& new_bf) noexcept {
230 AMREX_ALWAYS_ASSERT(new_bf.size() >= (max_level+1));
231 blocking_factor.assign(new_bf.cbegin(), new_bf.cbegin()+max_level+1);
232 }
233
235 void SetGridEff (Real eff) noexcept { grid_eff = eff; }
236
238 void SetNProper (int n) noexcept { n_proper = n; }
239
240 // There is no set for ref_ratio because it would require rebuilding Geometry objects.
241
243 void SetFinestLevel (int new_finest_level) noexcept { finest_level = new_finest_level; }
250 void SetDistributionMap (int lev, const DistributionMapping& dmap_in) noexcept;
251
258 void SetBoxArray (int lev, const BoxArray& ba_in) noexcept;
259
266 void SetGeometry (int lev, const Geometry& geom_in) noexcept;
267
269 [[nodiscard]] int GetLevel (Box const& domain) const noexcept;
270
272 void ClearDistributionMap (int lev) noexcept;
274 void ClearBoxArray (int lev) noexcept;
275
277 [[nodiscard]] int nErrorBuf (int lev, int direction = 0) const noexcept { return n_error_buf[lev][direction]; }
278
280 [[nodiscard]] const IntVect& nErrorBufVect (int lev) const noexcept { return n_error_buf[lev]; }
281
283 [[nodiscard]] Real gridEff () const noexcept { return grid_eff; }
284
286 [[nodiscard]] int nProper () const noexcept { return n_proper; }
287
289 [[nodiscard]] const IntVect& blockingFactor (int lev) const noexcept { return blocking_factor[lev]; }
290
292 [[nodiscard]] const IntVect& maxGridSize (int lev) const noexcept { return max_grid_size[lev]; }
293
295 [[nodiscard]] bool LevelDefined (int lev) const noexcept;
296
298 [[nodiscard]] bool useFixedCoarseGrids () const noexcept { return use_fixed_coarse_grids; }
299
301 [[nodiscard]] int useFixedUpToLevel () const noexcept { return use_fixed_upto_level; }
302
310 void ChopGrids (int lev, BoxArray& ba, int target_size) const;
311
313 [[nodiscard]] BoxArray MakeBaseGrids () const;
314
337 void MakeNewGrids (int lbase, Real time, int& new_finest, Vector<BoxArray>& new_grids);
338
340 void MakeNewGrids (Real time = 0.0);
341
350 virtual void MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba, const DistributionMapping& dm) {
351 amrex::ignore_unused(lev, time, ba, dm);
352 }
353
362 virtual void ErrorEst (int lev, TagBoxArray& tags, Real time, int ngrow) {
363 amrex::ignore_unused(lev, tags, time, ngrow);
364 }
365
373 virtual void ManualTagsPlacement (int lev, TagBoxArray& tags, const Vector<IntVect>& bf_lev) {
374 amrex::ignore_unused(lev, tags, bf_lev);
375 }
376
387 virtual void PostProcessBaseGrids(BoxArray& box_array) const { amrex::ignore_unused(box_array); }
388
392 [[nodiscard]] virtual BoxArray GetAreaNotToTag (int lev) { (void)lev; return BoxArray(); }
393
395 [[nodiscard]] Long CountCells (int lev) const noexcept;
396
398 [[nodiscard]] virtual DistributionMapping MakeDistributionMap (int lev, BoxArray const& ba);
399
400protected:
401
406
407#ifdef AMREX_USE_BITTREE
408 bool use_bittree = false;
409 std::unique_ptr<bittree::BittreeAmr> btmesh;
410#endif
411
412 unsigned int num_setdm = 0;
413 unsigned int num_setba = 0;
414
416 void checkInput();
417
419 void SetIterateToFalse () noexcept { iterate_on_new_grids = false; }
420
422 void SetUseNewChop () noexcept { use_new_chop = true; }
423
424private:
425 void InitAmrMesh (int max_level_in, const Vector<int>& n_cell_in,
427 const RealBox* rb = nullptr, int coord = -1,
428 const int* is_per = nullptr);
429
430 static void ProjPeriodic (BoxList& blout, const Box& domain,
431 Array<int,AMREX_SPACEDIM> const& is_per);
432};
433
435std::ostream& operator<< (std::ostream& os, AmrMesh const& amr_mesh);
436
437}
438
439#endif
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
#define AMREX_D_PICK(a, b, c)
Definition AMReX_SPACE.H:173
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Tag storage used for AMR error estimation and refinement decisions.
Definition AMReX_AmrMesh.H:69
void SetBlockingFactor(const Vector< IntVect > &new_bf) noexcept
Override per-level blocking factors using explicit IntVect vector new_bf.
Definition AMReX_AmrMesh.H:229
virtual void MakeNewLevelFromScratch(int lev, Real time, const BoxArray &ba, const DistributionMapping &dm)
Hook invoked by MakeNewGrids() to build a fresh level.
Definition AMReX_AmrMesh.H:350
const Geometry & Geom(int lev) const noexcept
Definition AMReX_AmrMesh.H:153
virtual void ErrorEst(int lev, TagBoxArray &tags, Real time, int ngrow)
Hook for tagging cells on level lev.
Definition AMReX_AmrMesh.H:362
AmrMesh()
Construct an empty mesh.
Definition AMReX_AmrMesh.cpp:18
Vector< Geometry > geom
Definition AMReX_AmrMesh.H:403
const Vector< DistributionMapping > & DistributionMap() const noexcept
Definition AMReX_AmrMesh.H:150
int maxLevel() const noexcept
Return the max level.
Definition AMReX_AmrMesh.H:135
void SetIterateToFalse() noexcept
Disable the iterate-on-new-grids loop for the next MakeNewGrids call.
Definition AMReX_AmrMesh.H:419
unsigned int num_setdm
Definition AMReX_AmrMesh.H:412
void SetBlockingFactor(const Vector< int > &new_bf) noexcept
Override per-level blocking factors using scalar-per-level vector new_bf.
Definition AMReX_AmrMesh.H:222
friend std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream a summary of the mesh hierarchy (level extents, cell counts, etc.).
Definition AMReX_AmrMesh.cpp:1238
const BoxArray & boxArray(int lev) const noexcept
Definition AMReX_AmrMesh.H:155
void SetBoxArray(int lev, const BoxArray &ba_in) noexcept
Install a BoxArray for level lev.
Definition AMReX_AmrMesh.cpp:408
const IntVect & nErrorBufVect(int lev) const noexcept
Return the number of buffer cells (as an IntVect) in error estimator.
Definition AMReX_AmrMesh.H:280
AmrMesh(AmrMesh &&rhs)=default
unsigned int num_setba
Definition AMReX_AmrMesh.H:413
void SetDistributionMap(int lev, const DistributionMapping &dmap_in) noexcept
Install a DistributionMapping for level lev.
Definition AMReX_AmrMesh.cpp:401
void SetMaxGridSize(int new_mgs) noexcept
Override the max grid size constraint for all levels (scalar version).
Definition AMReX_AmrMesh.H:190
bool LevelDefined(int lev) const noexcept
Return true if valid grids/dmaps exist for level lev.
Definition AMReX_AmrMesh.cpp:443
void SetUseNewChop() noexcept
Force MakeNewGrids to use the newer chopping algorithm.
Definition AMReX_AmrMesh.H:422
virtual void ManualTagsPlacement(int lev, TagBoxArray &tags, const Vector< IntVect > &bf_lev)
Manual tagging hook. Tags are defined on level lev grids coarsened by bf_lev[lev].
Definition AMReX_AmrMesh.H:373
const IntVect & blockingFactor(int lev) const noexcept
Return the blocking factor at level lev.
Definition AMReX_AmrMesh.H:289
Vector< DistributionMapping > DistributionMap(int a_coarsest_lev, int a_finest_lev) const noexcept
Definition AMReX_AmrMesh.H:173
Vector< Geometry > Geom(int a_coarsest_lev, int a_finest_lev) const noexcept
Definition AMReX_AmrMesh.H:157
int useFixedUpToLevel() const noexcept
Up to what level should we keep the coarser grids fixed (and not regrid those levels)?
Definition AMReX_AmrMesh.H:301
int finestLevel() const noexcept
Return the finest level.
Definition AMReX_AmrMesh.H:138
int GetLevel(Box const &domain) const noexcept
Given domain box, return AMR level. Return -1 if there is no match.
Definition AMReX_AmrMesh.cpp:421
void SetGridEff(Real eff) noexcept
Set the minimum acceptable grid efficiency to eff.
Definition AMReX_AmrMesh.H:235
int finest_level
Current finest level.
Definition AMReX_AmrMesh.H:402
Geometry & Geom(int lev) noexcept
Definition AMReX_AmrMesh.H:183
Real gridEff() const noexcept
Return the minimum allowable grid efficiency.
Definition AMReX_AmrMesh.H:283
IntVect refRatio(int lev) const noexcept
Return the refinement ratio for level lev.
Definition AMReX_AmrMesh.H:141
void ChopGrids(int lev, BoxArray &ba, int target_size) const
Try to chop grids on level lev until BoxArray ba has at least target_size boxes.
Definition AMReX_AmrMesh.cpp:469
int MaxRefRatio(int lev) const noexcept
Return the maximum refinement ratio in any direction.
Definition AMReX_AmrMesh.cpp:391
virtual ~AmrMesh()=default
void checkInput()
Validate AmrInfo inputs (throws if inconsistent).
Definition AMReX_AmrMesh.cpp:1120
void SetMaxGridSize(const IntVect &new_mgs) noexcept
Override the max grid size constraint using explicit IntVect new_mgs.
Definition AMReX_AmrMesh.H:194
virtual BoxArray GetAreaNotToTag(int lev)
Return a BoxArray that should never be tagged on level lev (e.g., buffer zones).
Definition AMReX_AmrMesh.H:392
Vector< BoxArray > boxArray(int a_coarsest_lev, int a_finest_lev) const noexcept
Definition AMReX_AmrMesh.H:165
int Verbose() const noexcept
Definition AMReX_AmrMesh.H:132
int nProper() const noexcept
Return the number of cell blocks to define proper nesting.
Definition AMReX_AmrMesh.H:286
AmrMesh(const AmrMesh &rhs)=delete
void SetGeometry(int lev, const Geometry &geom_in) noexcept
Install a Geometry object for level lev.
Definition AMReX_AmrMesh.cpp:415
const DistributionMapping & DistributionMap(int lev) const noexcept
Definition AMReX_AmrMesh.H:154
void SetFinestLevel(int new_finest_level) noexcept
Update the recorded finest level index to new_finest_level (without reallocating).
Definition AMReX_AmrMesh.H:243
const IntVect & maxGridSize(int lev) const noexcept
Return the largest allowable grid.
Definition AMReX_AmrMesh.H:292
Vector< DistributionMapping > dmap
Definition AMReX_AmrMesh.H:404
void SetBlockingFactor(int new_bf) noexcept
Override the blocking factor constraint for all levels (scalar version).
Definition AMReX_AmrMesh.H:214
virtual DistributionMapping MakeDistributionMap(int lev, BoxArray const &ba)
Build a distribution map for level lev grid layout ba (override to customize load balancing).
Definition AMReX_AmrMesh.cpp:449
const Vector< IntVect > & refRatio() const noexcept
Return refinement ratios between all levels.
Definition AMReX_AmrMesh.H:147
const Vector< Geometry > & Geom() const noexcept
Definition AMReX_AmrMesh.H:149
BoxArray MakeBaseGrids() const
Make a level-0 BoxArray covering the whole domain (without installing it).
Definition AMReX_AmrMesh.cpp:523
void MakeNewGrids(int lbase, Real time, int &new_finest, Vector< BoxArray > &new_grids)
Make new grids based on error estimates. This function expects that valid BoxArrays exist in this->gr...
Definition AMReX_AmrMesh.cpp:550
Vector< Geometry > & Geom() noexcept
Definition AMReX_AmrMesh.H:182
int nErrorBuf(int lev, int direction=0) const noexcept
Return the number of buffer cells (as a single integer) in error estimator.
Definition AMReX_AmrMesh.H:277
void SetMaxGridSize(const Vector< IntVect > &new_mgs) noexcept
Override per-level max grid sizes using explicit IntVect-per-level vector new_mgs.
Definition AMReX_AmrMesh.H:205
virtual void PostProcessBaseGrids(BoxArray &box_array) const
Allow derived classes to edit the base-level grids before installing them.
Definition AMReX_AmrMesh.H:387
Long CountCells(int lev) const noexcept
Count the total number of cells at level lev.
Definition AMReX_AmrMesh.cpp:1233
void SetBlockingFactor(const IntVect &new_bf) noexcept
Override blocking factor using explicit IntVect new_bf.
Definition AMReX_AmrMesh.H:218
void SetMaxGridSize(const Vector< int > &new_mgs) noexcept
Override per-level max grid sizes using scalar-per-level vector new_mgs.
Definition AMReX_AmrMesh.H:198
Vector< BoxArray > grids
Definition AMReX_AmrMesh.H:405
AmrMesh & operator=(const AmrMesh &rhs)=delete
void SetNProper(int n) noexcept
Set the number of cell blocks required for proper nesting to n.
Definition AMReX_AmrMesh.H:238
bool useFixedCoarseGrids() const noexcept
Should we keep the coarser grids fixed (and not regrid those levels) at all?
Definition AMReX_AmrMesh.H:298
const Vector< BoxArray > & boxArray() const noexcept
Definition AMReX_AmrMesh.H:151
void ClearDistributionMap(int lev) noexcept
Clear the stored DistributionMapping for level lev.
Definition AMReX_AmrMesh.cpp:431
void ClearBoxArray(int lev) noexcept
Clear the stored BoxArray for level lev.
Definition AMReX_AmrMesh.cpp:437
A collection of Boxes stored in an Array.
Definition AMReX_BoxArray.H:568
A class for managing a List of Boxes that share a common IndexType. This class implements operations ...
Definition AMReX_BoxList.H:52
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:43
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:74
A Box with real dimensions.
Definition AMReX_RealBox.H:28
An array of TagBoxes.
Definition AMReX_TagBox.H:151
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:28
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
amrex_long Long
Definition AMReX_INT.H:30
std::array< T, N > Array
Definition AMReX_Array.H:26
Definition AMReX_Amr.cpp:49
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1238
__host__ __device__ void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition AMReX.H:139
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:33
Definition AMReX_AmrMesh.H:25
int n_proper
Cells required for proper nesting.
Definition AMReX_AmrMesh.H:44
bool refine_grid_layout
Definition AMReX_AmrMesh.H:52
bool use_fixed_coarse_grids
Definition AMReX_AmrMesh.H:46
Vector< IntVect > ref_ratio
Refinement ratios.
Definition AMReX_AmrMesh.H:30
bool use_new_chop
Definition AMReX_AmrMesh.H:61
Real grid_eff
Grid efficiency.
Definition AMReX_AmrMesh.H:42
bool iterate_on_new_grids
Definition AMReX_AmrMesh.H:62
int max_grid_iterations
Definition AMReX_AmrMesh.H:63
bool check_input
Definition AMReX_AmrMesh.H:60
Vector< IntVect > n_error_buf
Buffer cells around each tagged cell.
Definition AMReX_AmrMesh.H:40
int max_level
Maximum allowed level.
Definition AMReX_AmrMesh.H:28
IntVect refine_grid_layout_dims
Definition AMReX_AmrMesh.H:58
Vector< IntVect > max_grid_size
Maximum allowable grid size (by level).
Definition AMReX_AmrMesh.H:35
int use_fixed_upto_level
Definition AMReX_AmrMesh.H:45
int verbose
Definition AMReX_AmrMesh.H:26
Vector< IntVect > blocking_factor
Blocking factor in grid generation (by level).
Definition AMReX_AmrMesh.H:32