Skip to content

Commit

Permalink
Implement new AMReX tagging format (#1243)
Browse files Browse the repository at this point in the history
The refinement scheme from AMReX-Codes/amrex#1166 is implemented. Rather than using the Fortran tagging namelist, applications may use the inputs file. The scheme looks like:
```
amr.refinement_indicators = dens temp

amr.refine.dens.max_level = 1
amr.refine.dens.value_greater = 2.0
amr.refine.dens.field_name = Density

amr.refine.temp.max_level = 2
amr.refine.temp.value_less = 1.0
amr.refine.temp.field_name = Temp
```
amr.refinement_indicators is a list of user-defined names for refinement schemes. For each defined name, amr.refine.<name> accepts predefined fields describing when to tag. In the current implementation, these are max_level (maximum level to refine to), start_time (when to start tagging), end_time (when to stop tagging), value_greater (value above which we refine), and value_less (value below which to refine), and field_name (name of the string defining the field in the code). If a refinement indicator is added, either value_greater or value_less must be provided. (In the future we will support other refinement schemes such as gradients.)

A wdmerger setup is converted to the new scheme as a test.
  • Loading branch information
maximumcats authored Sep 29, 2020
1 parent 0f2590a commit 2e5afbd
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 2 deletions.
25 changes: 25 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# 20.10

* A new refinement scheme using the inputs file rather than the Fortran
tagging namelist has been added. (#1243) As an example, consider:

```
amr.refinement_indicators = dens temp
amr.refine.dens.max_level = 1
amr.refine.dens.value_greater = 2.0
amr.refine.dens.field_name = Density
amr.refine.temp.max_level = 2
amr.refine.temp.value_less = 1.0
amr.refine.temp.field_name = Temp
```
`amr.refinement_indicators` is a list of user-defined names for refinement
schemes. For each defined name, amr.refine.<name> accepts predefined fields
describing when to tag. In the current implementation, these are `max_level`
(maximum level to refine to), `start_time` (when to start tagging), `end_time`
(when to stop tagging), `value_greater` (value above which we refine),
`value_less` (value below which to refine), and `field_name` (name of the
string defining the field in the code). If a refinement indicator is added,
either `value_greater` or `value_less` must be provided. (In the future we
will support other refinement schemes such as gradients.)
* Automatic problem parameter configuration is now available to every
problem by placing a _prob_params file in your problem directory.
Examples can be found in most of the problems in Castro/Exec, and you
Expand Down
24 changes: 24 additions & 0 deletions Docs/source/AMR.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ problem_tagging_3d.f90 to our work directory and set it up as follows:

end subroutine set_problem_tags

We also provide a mechanism for defining a limited set of refinement
schemes from the inputs file; for example,

::

amr.refinement_indicators = dens temp

amr.refine.dens.max_level = 1
amr.refine.dens.value_greater = 2.0
amr.refine.dens.field_name = Density

amr.refine.temp.max_level = 2
amr.refine.temp.value_less = 1.0
amr.refine.temp.field_name = Temp

``amr.refinement_indicators`` is a list of user-defined names for refinement
schemes. For each defined name, ``amr.refine.<name>`` accepts predefined fields
describing when to tag. These are ``max_level`` (maximum level to refine to),
``start_time`` (when to start tagging), ``end_time`` (when to stop tagging),
``value_greater`` (value above which we refine), ``value_less`` (value below
which to refine), and ``field_name`` (name of the string defining the field
in the code). If a refinement indicator is added, either ``value_greater`` or
``value_less`` must be provided.

.. _sec:amr_synchronization:

Synchronization Algorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ amr.n_cell = 96 96 96 # Number of cells on the coar
amr.max_level = 1 # Maximum level number allowed
amr.ref_ratio = 2

amr.refinement_indicators = temperature

amr.refine.temperature.max_level = 4
amr.refine.temperature.value_greater = 2.e8
amr.refine.temperature.field_name = Temp

amr.max_grid_size = 32 # Maximum grid size at each level
amr.blocking_factor = 16 # Grid sizes must be a multiple of this

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
/

&tagging
max_temperr_lev = 4
temperr = 2.d8
/

&sponge
Expand Down
5 changes: 5 additions & 0 deletions Source/driver/Castro.H
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,11 @@ public:
static amrex::Vector<int> upass_map;
static amrex::Vector<int> qpass_map;

///
/// Vector storing list of custom error tags.
///
static amrex::Vector<amrex::AMRErrorTag> custom_error_tags;

///
/// This MultiFab is on the coarser level. This is useful for the coarser level
/// to mask out the finer level. We only build this when it is needed.
Expand Down
60 changes: 60 additions & 0 deletions Source/driver/Castro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Vector<std::string> Castro::source_names;
Vector<int> Castro::upass_map;
Vector<int> Castro::qpass_map;

Vector<AMRErrorTag> Castro::custom_error_tags;

#ifdef TRUE_SDC
int Castro::SDC_NODES;
Vector<Real> Castro::dt_sdc;
Expand Down Expand Up @@ -469,6 +471,54 @@ Castro::read_params ()

compute_new_dt_on_regrid = 1;

// Read in custom refinement scheme.

Vector<std::string> refinement_indicators;
ppa.queryarr("refinement_indicators", refinement_indicators, 0, ppa.countval("refinement_indicators"));

for (int i = 0; i < refinement_indicators.size(); ++i)
{
std::string ref_prefix = "amr.refine." + refinement_indicators[i];

ParmParse ppr(ref_prefix);

AMRErrorTagInfo info;

if (ppr.countval("start_time") > 0) {
Real min_time;
ppr.get("start_time", min_time);
info.SetMinTime(min_time);
}
if (ppr.countval("end_time") > 0) {
Real max_time;
ppr.get("end_time", max_time);
info.SetMaxTime(max_time);
}
if (ppr.countval("max_level") > 0) {
int max_level;
ppr.get("max_level", max_level);
info.SetMaxLevel(max_level);
}

if (ppr.countval("value_greater") > 0) {
Real value;
ppr.get("value_greater", value);
std::string field;
ppr.get("field_name", field);
custom_error_tags.push_back(AMRErrorTag(value, AMRErrorTag::GREATER, field, info));
}
else if (ppr.countval("value_less") > 0) {
Real value;
ppr.get("value_less", value);
std::string field;
ppr.get("field_name", field);
custom_error_tags.push_back(AMRErrorTag(value, AMRErrorTag::LESS, field, info));
}
else {
amrex::Abort("Unrecognized refinement indicator for " + refinement_indicators[i]);
}
}

}

Castro::Castro ()
Expand Down Expand Up @@ -3176,6 +3226,16 @@ Castro::errorEst (TagBoxArray& tags,
apply_tagging_func(tags, ltime, j);
}

// Apply each of the custom tagging criteria.

for (int j = 0; j < custom_error_tags.size(); j++) {
std::unique_ptr<MultiFab> mf;
if (custom_error_tags[j].Field() != std::string()) {
mf = derive(custom_error_tags[j].Field(), time, custom_error_tags[j].NGrow());
}
custom_error_tags[j](tags, mf.get(), TagBox::CLEAR, TagBox::SET, time, level, geom);
}

// Now we'll tag any user-specified zones using the full state array.

apply_problem_tags(tags, ltime);
Expand Down

0 comments on commit 2e5afbd

Please sign in to comment.