|
ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
|
#include <ERF_WRFSurfaceFields.H>

Classes | |
| struct | Descriptor |
| struct | HeaderLevel |
| struct | Pending |
Public Types | |
| enum class | Field : int { LAI = 0 , VEGFRA , TMN , ZNT , ALBEDO , ALBBCK , SEAICE , SNOW , SNOWH , TSLB , SMOIS , ZS , DZS , NumFields } |
| enum class | Kind : int { Surface , SoilField , LayerColumn } |
Public Member Functions | |
| void | resize (int nlevs) |
| int | num_levels () const |
| bool | holds_any (int lev) const |
| void | clear (int lev) |
| const amrex::MultiFab * | get (int lev, Field id) const |
| bool | has (int lev, Field id) const |
| const amrex::Vector< amrex::Real > & | soil_depth (int lev) const |
| const amrex::Vector< amrex::Real > & | soil_thickness (int lev) const |
| void | set_soil_layers (int lev, Field id, const amrex::FArrayBox &src) |
| void | fill (int lev, Field id, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm, const amrex::IntVect &ng, int nlayers, const amrex::FArrayBox &src, const amrex::Box &file_box) |
| void | finish_level (int lev, const amrex::Periodicity &period) |
| void | remake (int lev, const amrex::BoxArray &new_ba2d, const amrex::DistributionMapping &new_dm, const amrex::Periodicity &period, const amrex::IntVect &ratio, bool take_coarser_fields, int verbose=0) |
| void | write_checkpoint (const std::string &checkpoint_dir, int nlevels) const |
| bool | read_checkpoint (const std::string &checkpoint_dir, int nlevels, const amrex::Vector< amrex::BoxArray > &ba2d, const amrex::Vector< amrex::DistributionMapping > &dm, const amrex::IntVect &ng, const amrex::Vector< amrex::Periodicity > &period, const amrex::Vector< amrex::IntVect > &ratio) |
| void | write_header (std::ostream &os, int nlevels) const |
Static Public Member Functions | |
| static const std::array< Descriptor, num_fields > & | catalog () |
| static const Descriptor * | find (const std::string &nc_name) |
| static bool | has_soil_layers (const std::string &nc_name) |
| static bool | parse_header (std::istream &is, amrex::Vector< HeaderLevel > &out) |
| static void | fill_ghost_cells (amrex::MultiFab &mf, const amrex::Periodicity &period) |
Static Public Attributes | |
| static constexpr int | num_fields = static_cast<int>(Field::NumFields) |
| static constexpr const char * | checkpoint_header_name = "WRFSurfaceFieldsHeader" |
Private Member Functions | |
| void | drop (int lev, Field id) |
| std::unique_ptr< amrex::MultiFab > | on_grids (int lev, Field id, const amrex::MultiFab *src, const amrex::BoxArray &ba2d, const amrex::DistributionMapping &dm, const amrex::IntVect &ng, const amrex::Periodicity &period, const amrex::IntVect &ratio) const |
Private Attributes | |
| amrex::Vector< std::array< std::unique_ptr< amrex::MultiFab >, num_fields > > | m_fields |
| amrex::Vector< std::array< Pending, num_fields > > | m_pending |
| amrex::Vector< amrex::Vector< amrex::Real > > | m_soil_depth |
| amrex::Vector< amrex::Vector< amrex::Real > > | m_soil_thickness |
|
strong |
The variables, in the order they are requested from the file.
|
strong |
|
static |
The one list of the variables. The reader asks the file for every name in it, and takes the layout of a name from its kind.
The bounds leave out only values that cannot be the named quantity (a negative temperature, a fraction above one). A field that a hand-built file declares and leaves at zero passes; whether zero is usable is for the code that takes the field. The upper bounds of LAI, TMN, ZNT, SNOW, SNOWH, TSLB, ZS and DZS are not physical limits: they are set far above any value of the quantity so that a NetCDF fill value (9.97e36), which is finite, is left out.
| void WRFSurfaceFields::clear | ( | int | lev | ) |
Drop everything held at this level. Prints one line when something was held.
|
private |
| void WRFSurfaceFields::fill | ( | int | lev, |
| Field | id, | ||
| const amrex::BoxArray & | ba2d, | ||
| const amrex::DistributionMapping & | dm, | ||
| const amrex::IntVect & | ng, | ||
| int | nlayers, | ||
| const amrex::FArrayBox & | src, | ||
| const amrex::Box & | file_box | ||
| ) |
Copy the part of one field that one file covers. Every rank calls it, once per file of the level; no MPI call is made here.
The valid cells of the level inside file_box take the file's values. A soil field gets one component per layer, in the file's order. The values are counted against the catalog range here; the report, the decision and the ghost cells are left to finish_level().
| lev | level |
| id | field (not ZS or DZS) |
| ba2d | the level's grids, one cell thick in z |
| dm | the level's distribution |
| ng | ghost cells of the stored field (none in z) |
| nlayers | number of soil layers of the variable in the file (1 for a surface field); the same on every rank |
| src | this rank's part of the field as read; memory a device kernel can read (the reader's fab); its low z index is the first layer |
| file_box | the columns this file covers at this level (z is ignored) |

|
static |
Fill the ghost cells of a field from its valid cells: a ghost cell that the level's grids cover (also through a periodic boundary) takes the value there; one beyond the bounding box of the level's grids takes the nearest column inside it, as the reader's other surface fields do beyond the file; any other takes the nearest column of its own box. Public for the unit tests.

|
static |
The descriptor of the variable with this name in the file, or null when it is not one of these.
Referenced by has_soil_layers().

| void WRFSurfaceFields::finish_level | ( | int | lev, |
| const amrex::Periodicity & | period | ||
| ) |
Close the read of a level, after the last file. Collective: every rank calls it.
Reduces the counts and ranges of fill() over the ranks (two reductions for the level, whatever the number of fields), then for every field read: reports it and fills its ghost cells; or, when a valid cell was not covered by a file, a value lies outside the catalog range, a value is not finite, or two files disagree on the number of layers, reports that with the counts and drops the field. Then drops TSLB, SMOIS, ZS and DZS together when they disagree on the number of soil layers.
| lev | level |
| period | the level's periodicity |

|
inline |
The field at this level, or null when it is not held. Always null for ZS and DZS.
Referenced by has().


|
inline |
|
inlinestatic |
True when the third index of this variable in the file is the soil layer.

| bool WRFSurfaceFields::holds_any | ( | int | lev | ) | const |
True when the level holds a field or a soil layer column.
|
inline |
Referenced by get(), soil_depth(), and soil_thickness().

|
private |

|
static |
Returns false, leaving out empty, when the text is not a header of this class.
| bool WRFSurfaceFields::read_checkpoint | ( | const std::string & | checkpoint_dir, |
| int | nlevels, | ||
| const amrex::Vector< amrex::BoxArray > & | ba2d, | ||
| const amrex::Vector< amrex::DistributionMapping > & | dm, | ||
| const amrex::IntVect & | ng, | ||
| const amrex::Vector< amrex::Periodicity > & | period, | ||
| const amrex::Vector< amrex::IntVect > & | ratio | ||
| ) |
Read what write_checkpoint() wrote, onto the grids of this run (they need not be those of the checkpoint). A checkpoint without the text file (written before this class) leaves the holder empty, prints one line and returns false.
Where this run's grids reach beyond those of the checkpoint, the rule of remake() applies: the columns the checkpoint does not give come from level lev-1, or the field is not restored and one line says so. No cell is left without a value.
| ba2d,dm | the grids and distribution of each level of this run |
| ng | ghost cells of the stored fields |
| period | per level |
| ratio | refinement ratio between level lev and lev+1, per level (z is ignored) |
| void WRFSurfaceFields::remake | ( | int | lev, |
| const amrex::BoxArray & | new_ba2d, | ||
| const amrex::DistributionMapping & | new_dm, | ||
| const amrex::Periodicity & | period, | ||
| const amrex::IntVect & | ratio, | ||
| bool | take_coarser_fields, | ||
| int | verbose = 0 |
||
| ) |
Put the level's fields on new grids (a new level, a regrid or a rebalance). Collective: every rank calls it. Level lev-1 must already be on its new grids.
A field the level holds keeps its values on the columns its old grids covered. The other columns take the values of the column of level lev-1 they lie in. When level lev-1 does not hold the field with the same number of components and the new grids reach beyond the old ones, that field is dropped and one line says so.
With take_coarser_fields, a field the level does not hold and level lev-1 does is taken from level lev-1 on every column, and so are the soil layer columns when the level has none. This is for a level without a file of its own.
The soil layer columns do not depend on the grids and are kept.
| lev | level |
| new_ba2d,new_dm | the new grids, one cell thick in z, and their distribution |
| period | the level's periodicity |
| ratio | refinement ratio between level lev-1 and this level (z is ignored; not used at level 0) |
| take_coarser_fields | take the fields the level lacks from level lev-1 |
| verbose | above zero: one line per field put on new grids, with the number of columns taken from level lev-1 and the range |

| void WRFSurfaceFields::resize | ( | int | nlevs | ) |
| void WRFSurfaceFields::set_soil_layers | ( | int | lev, |
| Field | id, | ||
| const amrex::FArrayBox & | src | ||
| ) |
Take the soil layer depths (ZS) or thicknesses (DZS) from the column a rank has read. Local: every rank reads the same column.
A column that is zero in every layer is taken as not given. Otherwise the depths must be zero or more and increase with the layer (a land model may put its first level at the surface), and the thicknesses must be positive. A column that breaks these rules, or holds a value that is not finite or above the catalog bound, is reported and not held.
| lev | level |
| id | Field::ZS or Field::DZS |
| src | the column as read; host-readable memory; its z range is the soil layers |

|
inline |
Depth of the center of each soil layer [m], top layer first (ZS); empty when not held.

|
inline |
Thickness of each soil layer [m], top layer first (DZS); empty when not held.

| void WRFSurfaceFields::write_checkpoint | ( | const std::string & | checkpoint_dir, |
| int | nlevels | ||
| ) | const |
Write the held fields into a checkpoint directory: one MultiFab file per field under the level's directory, and one text file that lists what each level holds. The text file is written by the I/O rank, also when nothing is held.

| void WRFSurfaceFields::write_header | ( | std::ostream & | os, |
| int | nlevels | ||
| ) | const |
Write and parse the text file; public for the unit tests.

|
staticconstexpr |
Name of the checkpoint's text file that lists what each level holds.
|
private |
Referenced by get(), and num_levels().
|
private |
|
private |
Referenced by soil_depth().
|
private |
Referenced by soil_thickness().
|
staticconstexpr |