ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ChopGrids.cpp File Reference
#include <ERF_Utils.H>
Include dependency graph for ERF_ChopGrids.cpp:

Functions

BoxArray ERFPostProcessBaseGrids (const Box &domain, bool decompose_in_z)
 
void ChopGrids2D (BoxArray &ba, const Box &domain, int target_size)
 

Function Documentation

◆ ChopGrids2D()

void ChopGrids2D ( BoxArray &  ba,
const Box &  domain,
int  target_size 
)

Iteratively decompose grids in 2D until the target number of grids is reached.

Parameters
[in,out]baBoxArray to be decomposed.
domainBox specifying the domain.
target_sizeTarget number of grids.
36 {
37  IntVect chunk = domain.length();
38 
39  while (ba.size() < target_size)
40  {
41  IntVect chunk_prev = chunk;
42 
43  // We only decompose in x and y, so this array holds only those two directions;
44  // sizing it with AMREX_SPACEDIM would leave a default {0,0} entry that sorts
45  // to the front and pushes the largest direction out of the loop below
46  std::array<std::pair<int,int>,2>
47  chunk_dir{std::make_pair(chunk[0],int(0)),
48  std::make_pair(chunk[1],int(1))};
49  std::sort(chunk_dir.begin(), chunk_dir.end());
50 
51  // Try the largest direction first, then the smaller one
52  for (int idx = 1; idx >= 0; idx--) {
53  int idim = chunk_dir[idx].second;
54  int new_chunk_size = chunk[idim] / 2;
55  if (new_chunk_size != 0)
56  {
57  chunk[idim] = new_chunk_size;
58  ba.maxSize(chunk);
59  break;
60  }
61  }
62 
63  if (chunk == chunk_prev) {
64  break;
65  }
66  }
67 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int idx(int i, int j, int k, int nx, int ny)
Definition: ERF_InitForEnsemble.cpp:365

Referenced by ERF::initHSE(), and make_terrain_fitted_coords().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ERFPostProcessBaseGrids()

BoxArray ERFPostProcessBaseGrids ( const Box &  domain,
bool  decompose_in_z 
)

Decompose the base grids to avoid creating too many grids for the number of processors.

Parameters
domainBox specifying the domain to decompose.
decompose_in_zWhether to decompose in the z-direction.
Returns
BoxArray of the decomposed grids.
14 {
15  //
16  // This is used to avoid the case where the native amrex decomposition makes
17  // too many grids for the number of processors.
18  //
19  // The idea is to not override the user preference if expressed by max_grid_size
20  // but instead to ensure that the default behavior is what we want.
21  //
22  BoxArray ba0 = amrex::decompose(domain, ParallelDescriptor::NProcs(),
23  {true,true,decompose_in_z});
24  return ba0;
25 }

Referenced by ERF::MakeNewLevelFromScratch().

Here is the caller graph for this function: