Skip to content

Commit

Permalink
Enable refined region to be set by specifing the bounding box of the … (
Browse files Browse the repository at this point in the history
erf-model#1631)

* Enable refined region to be set by specifing the bounding box of the refined region using the fine level index space rather than the real physical positions

* remove unused inputs_file
  • Loading branch information
asalmgren authored May 26, 2024
1 parent fb65da6 commit cef8354
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 92 deletions.
57 changes: 38 additions & 19 deletions Docs/sphinx_doc/MeshRefinement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ See the `Gridding`_ section of the AMReX documentation for details of how indivi
Static Mesh Refinement
----------------------

For static refinement, we control the placement of grids by specifying
the low and high extents (in physical space) of each box in the lateral
directions. ERF enforces that all refinement spans the entire vertical direction.
For static refinement, we can control the placement of grids by specifying
the low and high extents (in physical space or index space) of each box.

The following example demonstrates how to tag regions for static refinement.
In this first example, all cells in the region ((.15,.25,prob_lo_z)(.35,.45,prob_hi_z))
and in the region ((.65,.75,prob_lo_z)(.85,.95,prob_hi_z)) are tagged for
one level of refinement, where prob_lo_z and prob_hi_z are the vertical extents of the domain:
In this first example, all cells in the region ((.15,.25,0.)(.35,.45,1.))
and in the region ((.65,.75,0.0)(.85,.95,1.0)) are tagged for
one level of refinement.

::

Expand All @@ -39,13 +38,13 @@ one level of refinement, where prob_lo_z and prob_hi_z are the vertical extents

erf.refinement_indicators = box1 box2

erf.box1.in_box_lo = .15 .25
erf.box1.in_box_hi = .35 .45
erf.box1.in_box_lo = .15 .25 0.0
erf.box1.in_box_hi = .35 .45 1.0

erf.box2.in_box_lo = .65 .75
erf.box2.in_box_hi = .85 .95
erf.box2.in_box_lo = .65 .75 0.0
erf.box2.in_box_hi = .85 .95 1.0

In the example below, we refine the region ((.15,.25,prob_lo_z)(.35,.45,prob_hi_z))
In the example below, we refine the region ((.15,.25,0.)(.35,.45,.5))
by two levels of factor 3 refinement. In this case, the refined region at level 1 will
be sufficient to enclose the refined region at level 2.

Expand All @@ -56,11 +55,11 @@ be sufficient to enclose the refined region at level 2.

erf.refinement_indicators = box1

erf.box1.in_box_lo = .15 .25
erf.box1.in_box_hi = .35 .45
erf.box1.in_box_lo = .15 .25 0.0
erf.box1.in_box_hi = .35 .45 1.0

And in this final example, the region ((.15,.25,prob_lo_z)(.35,.45,prob_hi_z))
will be refined by two levels of factor 3, but the larger region, ((.05,.05,prob_lo_z)(.75,.75,prob_hi_z))
And in this final example, the region ((.15,.25,0.)(.35,.45,1.))
will be refined by two levels of factor 3, but the larger region, ((.05,.05,0.)(.75,.75,1.))
will be refined by a single factor 3 refinement.

::
Expand All @@ -70,12 +69,30 @@ will be refined by a single factor 3 refinement.

erf.refinement_indicators = box1 box2

erf.box1.in_box_lo = .15 .25
erf.box1.in_box_hi = .35 .45
erf.box1.in_box_lo = .15 .25 0.0
erf.box1.in_box_hi = .35 .45 1.0

erf.box2.in_box_lo = .05 .05
erf.box2.in_box_hi = .75 .75
erf.box2.max_level = 1
erf.box2.in_box_lo = .05 .05 0.0
erf.box2.in_box_hi = .75 .75 1.0


We note that instead of specifying the physical extent enclosed, we can instead specify the indices of
the bounding box of the refined region in the index space of that fine level.
To do this we use
``in_box_lo_indices`` and ``in_box_hi_indices`` instead of ``in_box_lo`` and ``in_box_hi``.
If we want to refine the inner region (spanning half the width in each direction) by one level of
factor 2 refinement, and the domain has 32x64x8 cells at level 0 covering the domain, then we would set

::

amr.max_level = 1
amr.ref_ratio = 2

erf.refinement_indicators = box1

erf.box1.in_box_lo_indices = 16 32 4
erf.box1.in_box_hi_indices = 47 95 11


Dynamic Mesh Refinement
Expand All @@ -84,6 +101,8 @@ Dynamic Mesh Refinement
Dynamically created tagging functions are based on runtime data specified in the inputs file.
These dynamically generated functions test on either state variables or derived variables
defined in ERF_derive.cpp and included in the derive_lst in Setup.cpp.
(We note that static refinement can also be achieved by using the refinement criteria as specified below
but setting ``erf.regrid_int`` to a number greater than the total number of steps that will be taken.)

Available tests include

Expand Down
72 changes: 0 additions & 72 deletions Exec/RegTests/Couette_Poiseuille/inputs_neumann_test

This file was deleted.

55 changes: 54 additions & 1 deletion Source/ERF_Tagging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,26 @@ ERF::refinement_criteria_setup ()
ParmParse ppr(ref_prefix);
RealBox realbox;
int lev_for_box;
if (ppr.countval("in_box_lo")) {

int num_real_lo = ppr.countval("in_box_lo");
int num_indx_lo = ppr.countval("in_box_lo_indices");

if ( !((num_real_lo == AMREX_SPACEDIM && num_indx_lo == 0) ||
(num_indx_lo == AMREX_SPACEDIM && num_real_lo == 0) ||
(num_indx_lo == 0 && num_real_lo == 0)) )
{
amrex::Abort("Must only specify box for refinement using real OR index space");
}

if (num_real_lo > 0) {
std::vector<Real> box_lo(3), box_hi(3);
ppr.get("max_level",lev_for_box);
if (lev_for_box <= max_level)
{
if (n_error_buf[0] != IntVect::TheZeroVector()) {
amrex::Abort("Don't use n_error_buf > 0 when setting the box explicitly");
}

ppr.getarr("in_box_lo",box_lo,0,AMREX_SPACEDIM);
ppr.getarr("in_box_hi",box_hi,0,AMREX_SPACEDIM);
realbox = RealBox(&(box_lo[0]),&(box_hi[0]));
Expand Down Expand Up @@ -152,6 +167,44 @@ ERF::refinement_criteria_setup ()

}
}

} else if (num_indx_lo > 0) {

std::vector<int> box_lo(3), box_hi(3);
ppr.get("max_level",lev_for_box);
if (lev_for_box <= max_level)
{
if (n_error_buf[0] != IntVect::TheZeroVector()) {
amrex::Abort("Don't use n_error_buf > 0 when setting the box explicitly");
}

ppr.getarr("in_box_lo_indices",box_lo,0,AMREX_SPACEDIM);
ppr.getarr("in_box_hi_indices",box_hi,0,AMREX_SPACEDIM);

Box bx(IntVect(box_lo[0],box_lo[1],box_lo[2]),IntVect(box_hi[0],box_hi[1],box_hi[2]));
amrex::Print() << "BOX " << bx << std::endl;

const auto* dx = geom[lev_for_box].CellSize();
const Real* plo = geom[lev_for_box].ProbLo();
realbox = RealBox(plo[0]+ box_lo[0] *dx[0],plo[1] +box_lo[1] *dx[1],plo[2] +box_lo[2] *dx[2],
plo[0]+(box_hi[0]+1)*dx[0],plo[1]+(box_hi[1]+1)*dx[1],plo[2]+(box_hi[2]+1)*dx[2]);

Print() << "Reading " << bx << " at level " << lev_for_box << std::endl;
num_boxes_at_level[lev_for_box] += 1;

if ( (box_lo[0]%ref_ratio[lev_for_box-1][0] != 0) || ((box_hi[0]+1)%ref_ratio[lev_for_box-1][0] != 0) ||
(box_lo[1]%ref_ratio[lev_for_box-1][1] != 0) || ((box_hi[1]+1)%ref_ratio[lev_for_box-1][1] != 0) ||
(box_lo[2]%ref_ratio[lev_for_box-1][2] != 0) || ((box_hi[2]+1)%ref_ratio[lev_for_box-1][2] != 0) )
amrex::Error("Fine box is not legit with this ref_ratio");
boxes_at_level[lev_for_box].push_back(bx);
Print() << "Saving in 'boxes at level' as " << bx << std::endl;
} // lev
if (init_type == "real" || init_type == "metgrid") {
if (num_boxes_at_level[lev_for_box] != num_files_at_level[lev_for_box]) {
amrex::Error("Number of boxes doesnt match number of input files");

}
}
}

AMRErrorTagInfo info;
Expand Down

0 comments on commit cef8354

Please sign in to comment.