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
67
68 bool check_input = true;
69 bool use_new_chop = false;
72
79};
80
83 : protected AmrInfo
84{
85public:
86
94 friend std::ostream& operator<< (std::ostream& os, AmrMesh const& amr_mesh);
95
97 AmrMesh ();
98
111 AmrMesh (const RealBox* rb, int max_level_in,
112 const Vector<int>& n_cell_in, int coord=-1,
114 const int* is_per = nullptr);
115
126 AmrMesh (const RealBox& rb, int max_level_in,
127 const Vector<int>& n_cell_in, int coord,
128 Vector<IntVect> const& a_refrat,
129 Array<int,AMREX_SPACEDIM> const& is_per);
130
137 AmrMesh (Geometry const& level_0_geom, AmrInfo const& amr_info);
138
139 AmrMesh (const AmrMesh& rhs) = delete;
140 AmrMesh& operator= (const AmrMesh& rhs) = delete;
141
142 AmrMesh (AmrMesh&& rhs) = default;
143 AmrMesh& operator= (AmrMesh&& rhs) = default;
144
145 virtual ~AmrMesh () = default;
146
147 [[nodiscard]] int Verbose () const noexcept { return verbose; }
148
150 [[nodiscard]] int maxLevel () const noexcept { return max_level; }
151
153 [[nodiscard]] int finestLevel () const noexcept { return finest_level; }
154
156 [[nodiscard]] IntVect refRatio (int lev) const noexcept { return ref_ratio[lev]; }
157
159 [[nodiscard]] int MaxRefRatio (int lev) const noexcept;
160
162 [[nodiscard]] const Vector<IntVect>& refRatio () const noexcept { return ref_ratio; }
163
164 [[nodiscard]] const Vector<Geometry>& Geom () const noexcept { return geom; }
165 [[nodiscard]] const Vector<DistributionMapping>& DistributionMap () const noexcept { return dmap; }
166 [[nodiscard]] const Vector<BoxArray>& boxArray () const noexcept { return grids; }
167
168 [[nodiscard]] const Geometry& Geom (int lev) const noexcept { return geom[lev]; }
169 [[nodiscard]] const DistributionMapping& DistributionMap (int lev) const noexcept { return dmap[lev]; }
170 [[nodiscard]] const BoxArray& boxArray (int lev) const noexcept { return grids[lev]; }
171
172 [[nodiscard]] Vector<Geometry> Geom (int a_coarsest_lev, int a_finest_lev) const noexcept {
174 r.reserve(a_finest_lev-a_coarsest_lev+1);
175 for (int lev = a_coarsest_lev; lev <= a_finest_lev; ++lev) {
176 r.push_back(geom[lev]);
177 }
178 return r;
179 }
180 [[nodiscard]] Vector<BoxArray> boxArray (int a_coarsest_lev, int a_finest_lev) const noexcept {
182 r.reserve(a_finest_lev-a_coarsest_lev+1);
183 for (int lev = a_coarsest_lev; lev <= a_finest_lev; ++lev) {
184 r.push_back(grids[lev]);
185 }
186 return r;
187 }
188 [[nodiscard]] Vector<DistributionMapping> DistributionMap (int a_coarsest_lev, int a_finest_lev) const noexcept {
190 r.reserve(a_finest_lev-a_coarsest_lev+1);
191 for (int lev = a_coarsest_lev; lev <= a_finest_lev; ++lev) {
192 r.push_back(dmap[lev]);
193 }
194 return r;
195 }
196
197 Vector<Geometry>& Geom () noexcept { return geom; }
198 Geometry& Geom (int lev) noexcept { return geom[lev]; }
199
205 void SetMaxGridSize (int new_mgs) noexcept {
206 max_grid_size.assign(max_level+1, IntVect{AMREX_D_DECL(new_mgs,new_mgs,new_mgs)});
207 }
209 void SetMaxGridSize (const IntVect& new_mgs) noexcept {
210 max_grid_size.assign(max_level+1, new_mgs);
211 }
213 void SetMaxGridSize (const Vector<int>& new_mgs) noexcept {
214 max_grid_size.resize(max_level+1);
215 for (int i = 0; i <= max_level; ++i) {
216 max_grid_size[i] = IntVect{AMREX_D_DECL(new_mgs[i],new_mgs[i],new_mgs[i])};
217 }
218 }
220 void SetMaxGridSize (const Vector<IntVect>& new_mgs) noexcept {
221 max_grid_size.assign(new_mgs.cbegin(), new_mgs.cbegin()+max_level+1);
222 }
223
229 void SetBlockingFactor (int new_bf) noexcept {
230 blocking_factor.assign(max_level+1, IntVect{AMREX_D_DECL(new_bf,new_bf,new_bf)});
231 }
233 void SetBlockingFactor (const IntVect& new_bf) noexcept {
234 blocking_factor.assign(max_level+1, new_bf);
235 }
237 void SetBlockingFactor (const Vector<int>& new_bf) noexcept {
238 blocking_factor.resize(max_level+1);
239 for (int i = 0; i <= max_level; ++i) {
240 blocking_factor[i] = IntVect{AMREX_D_DECL(new_bf[i],new_bf[i],new_bf[i])};
241 }
242 }
244 void SetBlockingFactor (const Vector<IntVect>& new_bf) {
245 AMREX_ALWAYS_ASSERT(new_bf.size() >= (max_level+1));
246 blocking_factor.assign(new_bf.cbegin(), new_bf.cbegin()+max_level+1);
247 }
248
250 void SetGridEff (Real eff) noexcept { grid_eff = eff; }
251
253 void SetNProper (int n) noexcept { n_proper = n; }
254
255 // There is no set for ref_ratio because it would require rebuilding Geometry objects.
256
258 void SetFinestLevel (int new_finest_level) noexcept { finest_level = new_finest_level; }
265 void SetDistributionMap (int lev, const DistributionMapping& dmap_in) noexcept;
266
273 void SetBoxArray (int lev, const BoxArray& ba_in) noexcept;
274
281 void SetGeometry (int lev, const Geometry& geom_in) noexcept;
282
284 [[nodiscard]] int GetLevel (Box const& domain) const noexcept;
285
287 void ClearDistributionMap (int lev) noexcept;
289 void ClearBoxArray (int lev) noexcept;
290
292 [[nodiscard]] int nErrorBuf (int lev, int direction = 0) const noexcept { return n_error_buf[lev][direction]; }
293
295 [[nodiscard]] const IntVect& nErrorBufVect (int lev) const noexcept { return n_error_buf[lev]; }
296
298 [[nodiscard]] Real gridEff () const noexcept { return grid_eff; }
299
301 [[nodiscard]] int nProper () const noexcept { return n_proper; }
302
304 [[nodiscard]] const IntVect& blockingFactor (int lev) const noexcept { return blocking_factor[lev]; }
305
307 [[nodiscard]] const IntVect& maxGridSize (int lev) const noexcept { return max_grid_size[lev]; }
308
316 [[nodiscard]] IntVect effectiveMaxGridSize (int lev) const noexcept;
317
326 [[nodiscard]] IntVect bfLev (int lev) const noexcept;
327
329 [[nodiscard]] bool LevelDefined (int lev) const noexcept;
330
332 [[nodiscard]] bool useFixedCoarseGrids () const noexcept { return use_fixed_coarse_grids; }
333
335 [[nodiscard]] int useFixedUpToLevel () const noexcept { return use_fixed_upto_level; }
336
344 void ChopGrids (int lev, BoxArray& ba, int target_size) const;
345
347 [[nodiscard]] BoxArray MakeBaseGrids () const;
348
371 void MakeNewGrids (int lbase, Real time, int& new_finest, Vector<BoxArray>& new_grids);
372
374 void MakeNewGrids (Real time = 0.0);
375
384 virtual void MakeNewLevelFromScratch (int lev, Real time, const BoxArray& ba, const DistributionMapping& dm) {
385 amrex::ignore_unused(lev, time, ba, dm);
386 }
387
396 virtual void ErrorEst (int lev, TagBoxArray& tags, Real time, int ngrow) {
397 amrex::ignore_unused(lev, tags, time, ngrow);
398 }
399
407 virtual void ManualTagsPlacement (int lev, TagBoxArray& tags, const Vector<IntVect>& bf_lev) {
408 amrex::ignore_unused(lev, tags, bf_lev);
409 }
410
421 virtual void PostProcessBaseGrids(BoxArray& box_array) const { amrex::ignore_unused(box_array); }
422
426 [[nodiscard]] virtual BoxArray GetAreaNotToTag (int lev) { (void)lev; return BoxArray(); }
427
429 [[nodiscard]] Long CountCells (int lev) const noexcept;
430
432 [[nodiscard]] virtual DistributionMapping MakeDistributionMap (int lev, BoxArray const& ba);
433
434protected:
435
440
441#ifdef AMREX_USE_BITTREE
442 bool use_bittree = false;
443 std::unique_ptr<bittree::BittreeAmr> btmesh;
444#endif
445
446 unsigned int num_setdm = 0;
447 unsigned int num_setba = 0;
448
450 void checkInput();
451
453 [[nodiscard]] bool useLegacyGridding () const noexcept;
454
456 [[nodiscard]] bool hasOddRefRatio (int lev) const noexcept;
457
459 void SetIterateToFalse () noexcept { iterate_on_new_grids = false; }
460
462 void SetUseNewChop () noexcept { use_new_chop = true; }
463
464private:
465 void ChopGridsExtended (int lev, BoxArray& ba, int target_size) const;
466 [[nodiscard]] BoxArray MakeBaseGridsNoBoxSplit () const;
467 void MakeNewGridsExtended (int lbase, Real time, int& new_finest,
468 Vector<BoxArray>& new_grids);
469 void checkInputExtended ();
470
471 void InitAmrMesh (int max_level_in, const Vector<int>& n_cell_in,
473 const RealBox* rb = nullptr, int coord = -1,
474 const int* is_per = nullptr);
475
476 static void ProjPeriodic (BoxList& blout, const Box& domain,
477 Array<int,AMREX_SPACEDIM> const& is_per);
478};
479
481std::ostream& operator<< (std::ostream& os, AmrMesh const& amr_mesh);
482
483}
484
485#endif
Fixed-size array types for use on GPU and CPU.
#define AMREX_ALWAYS_ASSERT(EX)
Definition AMReX_BLassert.H:50
Container and helper utilities for sets of boxes on integer index space.
Maps FABs in a FabArray to MPI processes.
Problem-domain geometry: maps between index space and physical space.
#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:84
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:384
const Geometry & Geom(int lev) const noexcept
Definition AMReX_AmrMesh.H:168
virtual void ErrorEst(int lev, TagBoxArray &tags, Real time, int ngrow)
Hook for tagging cells on level lev.
Definition AMReX_AmrMesh.H:396
void SetBlockingFactor(const Vector< IntVect > &new_bf)
Override per-level blocking factors using explicit IntVect vector new_bf.
Definition AMReX_AmrMesh.H:244
AmrMesh()
Construct an empty mesh.
Definition AMReX_AmrMesh.cpp:18
Vector< Geometry > geom
Definition AMReX_AmrMesh.H:437
const Vector< DistributionMapping > & DistributionMap() const noexcept
Definition AMReX_AmrMesh.H:165
int maxLevel() const noexcept
Return the max level.
Definition AMReX_AmrMesh.H:150
void SetIterateToFalse() noexcept
Disable the iterate-on-new-grids loop for the next MakeNewGrids call.
Definition AMReX_AmrMesh.H:459
unsigned int num_setdm
Definition AMReX_AmrMesh.H:446
bool useLegacyGridding() const noexcept
Use the original gridding rules unless no_box_split_dir is set.
Definition AMReX_AmrMesh.cpp:479
void SetBlockingFactor(const Vector< int > &new_bf) noexcept
Override per-level blocking factors using scalar-per-level vector new_bf.
Definition AMReX_AmrMesh.H:237
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:1372
const BoxArray & boxArray(int lev) const noexcept
Definition AMReX_AmrMesh.H:170
IntVect effectiveMaxGridSize(int lev) const noexcept
Return the largest allowable grid at level lev, with the no_box_split_dir (if set) relaxed to the ext...
Definition AMReX_AmrMeshGridding.cpp:13
void SetBoxArray(int lev, const BoxArray &ba_in) noexcept
Install a BoxArray for level lev.
Definition AMReX_AmrMesh.cpp:418
const IntVect & nErrorBufVect(int lev) const noexcept
Return the number of buffer cells (as an IntVect) in error estimator.
Definition AMReX_AmrMesh.H:295
AmrMesh(AmrMesh &&rhs)=default
unsigned int num_setba
Definition AMReX_AmrMesh.H:447
void SetDistributionMap(int lev, const DistributionMapping &dmap_in) noexcept
Install a DistributionMapping for level lev.
Definition AMReX_AmrMesh.cpp:411
void SetMaxGridSize(int new_mgs) noexcept
Override the max grid size constraint for all levels (scalar version).
Definition AMReX_AmrMesh.H:205
bool LevelDefined(int lev) const noexcept
Return true if valid grids/dmaps exist for level lev.
Definition AMReX_AmrMesh.cpp:453
void SetUseNewChop() noexcept
Force MakeNewGrids to use the newer chopping algorithm.
Definition AMReX_AmrMesh.H:462
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:407
const IntVect & blockingFactor(int lev) const noexcept
Return the blocking factor at level lev.
Definition AMReX_AmrMesh.H:304
Vector< DistributionMapping > DistributionMap(int a_coarsest_lev, int a_finest_lev) const noexcept
Definition AMReX_AmrMesh.H:188
Vector< Geometry > Geom(int a_coarsest_lev, int a_finest_lev) const noexcept
Definition AMReX_AmrMesh.H:172
int useFixedUpToLevel() const noexcept
Up to what level should we keep the coarser grids fixed (and not regrid those levels)?
Definition AMReX_AmrMesh.H:335
int finestLevel() const noexcept
Return the finest level.
Definition AMReX_AmrMesh.H:153
int GetLevel(Box const &domain) const noexcept
Given domain box, return AMR level. Return -1 if there is no match.
Definition AMReX_AmrMesh.cpp:431
void SetGridEff(Real eff) noexcept
Set the minimum acceptable grid efficiency to eff.
Definition AMReX_AmrMesh.H:250
int finest_level
Current finest level.
Definition AMReX_AmrMesh.H:436
Geometry & Geom(int lev) noexcept
Definition AMReX_AmrMesh.H:198
Real gridEff() const noexcept
Return the minimum allowable grid efficiency.
Definition AMReX_AmrMesh.H:298
IntVect refRatio(int lev) const noexcept
Return the refinement ratio for level lev.
Definition AMReX_AmrMesh.H:156
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:491
int MaxRefRatio(int lev) const noexcept
Return the maximum refinement ratio in any direction.
Definition AMReX_AmrMesh.cpp:401
virtual ~AmrMesh()=default
void checkInput()
Validate AmrInfo inputs (throws if inconsistent).
Definition AMReX_AmrMesh.cpp:1221
IntVect bfLev(int lev) const noexcept
Return the factor by which the tags on level lev are coarsened before they are clustered into level l...
Definition AMReX_AmrMeshGridding.cpp:27
void SetMaxGridSize(const IntVect &new_mgs) noexcept
Override the max grid size constraint using explicit IntVect new_mgs.
Definition AMReX_AmrMesh.H:209
virtual BoxArray GetAreaNotToTag(int lev)
Return a BoxArray that should never be tagged on level lev (e.g., buffer zones).
Definition AMReX_AmrMesh.H:426
Vector< BoxArray > boxArray(int a_coarsest_lev, int a_finest_lev) const noexcept
Definition AMReX_AmrMesh.H:180
int Verbose() const noexcept
Definition AMReX_AmrMesh.H:147
int nProper() const noexcept
Return the number of cell blocks to define proper nesting.
Definition AMReX_AmrMesh.H:301
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:425
const DistributionMapping & DistributionMap(int lev) const noexcept
Definition AMReX_AmrMesh.H:169
void SetFinestLevel(int new_finest_level) noexcept
Update the recorded finest level index to new_finest_level (without reallocating).
Definition AMReX_AmrMesh.H:258
const IntVect & maxGridSize(int lev) const noexcept
Return the largest allowable grid.
Definition AMReX_AmrMesh.H:307
Vector< DistributionMapping > dmap
Definition AMReX_AmrMesh.H:438
void SetBlockingFactor(int new_bf) noexcept
Override the blocking factor constraint for all levels (scalar version).
Definition AMReX_AmrMesh.H:229
bool hasOddRefRatio(int lev) const noexcept
True if ref_ratio[lev] is odd (and not 1) in some direction.
Definition AMReX_AmrMesh.cpp:485
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:459
const Vector< IntVect > & refRatio() const noexcept
Return refinement ratios between all levels.
Definition AMReX_AmrMesh.H:162
const Vector< Geometry > & Geom() const noexcept
Definition AMReX_AmrMesh.H:164
BoxArray MakeBaseGrids() const
Make a level-0 BoxArray covering the whole domain (without installing it).
Definition AMReX_AmrMesh.cpp:550
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:580
Vector< Geometry > & Geom() noexcept
Definition AMReX_AmrMesh.H:197
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:292
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:220
virtual void PostProcessBaseGrids(BoxArray &box_array) const
Allow derived classes to edit the base-level grids before installing them.
Definition AMReX_AmrMesh.H:421
Long CountCells(int lev) const noexcept
Count the total number of cells at level lev.
Definition AMReX_AmrMesh.cpp:1367
void SetBlockingFactor(const IntVect &new_bf) noexcept
Override blocking factor using explicit IntVect new_bf.
Definition AMReX_AmrMesh.H:233
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:213
Vector< BoxArray > grids
Definition AMReX_AmrMesh.H:439
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:253
bool useFixedCoarseGrids() const noexcept
Should we keep the coarser grids fixed (and not regrid those levels) at all?
Definition AMReX_AmrMesh.H:332
const Vector< BoxArray > & boxArray() const noexcept
Definition AMReX_AmrMesh.H:166
void ClearDistributionMap(int lev) noexcept
Clear the stored DistributionMapping for level lev.
Definition AMReX_AmrMesh.cpp:441
void ClearBoxArray(int lev) noexcept
Clear the stored BoxArray for level lev.
Definition AMReX_AmrMesh.cpp:447
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:681
A list of Boxes sharing a common IndexType.
Definition AMReX_BoxList.H:109
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:85
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:29
Long size() const noexcept
Definition AMReX_Vector.H:54
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:80
amrex_long Long
Definition AMReX_INT.H:30
std::array< T, N > Array
Definition AMReX_Array.H:31
Definition AMReX_Amr.cpp:50
std::ostream & operator<<(std::ostream &os, AmrMesh const &amr_mesh)
Stream helper; forwards to the friend declared inside AmrMesh.
Definition AMReX_AmrMesh.cpp:1372
__host__ __device__ void ignore_unused(const Ts &...)
No-op helper that marks variables as intentionally unused.
Definition AMReX.H:259
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
Definition AMReX_AmrMesh.H:25
int no_box_split_dir
Definition AMReX_AmrMesh.H:78
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:69
Real grid_eff
Grid efficiency.
Definition AMReX_AmrMesh.H:42
int refine_whole_domain_dir
Definition AMReX_AmrMesh.H:66
bool iterate_on_new_grids
Definition AMReX_AmrMesh.H:70
int max_grid_iterations
Definition AMReX_AmrMesh.H:71
bool check_input
Definition AMReX_AmrMesh.H:68
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