ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
plotfile2d Namespace Reference

Classes

struct  DiagnosticDescriptor
 
struct  PlotVariableSelection
 

Enumerations

enum class  DiagnosticID {
  ZSurf , LandMask , MapFac , LatM ,
  LonM , UStar , WStar , TStar ,
  QStar , Olen , Pblh , TSurf ,
  QSurf , Z0 , OLR , SensFlux ,
  LatenFlux , SurfPres , IntegratedQv , SurfaceDiagnosticSource ,
  SensibleHeatFlux , LatentHeatFlux , ShocUStar , ShocOlen ,
  ShocWthvSfc
}
 
enum class  DiagnosticCategory {
  Geometry , SurfaceLayer , Radiation , SurfaceFlux ,
  PBL , SurfaceState , ColumnIntegral
}
 
enum class  MissingPolicy { AlwaysAvailable , FillZeroWhenUnavailable , FillMinus999WhenUnavailable }
 

Functions

const amrex::Vector< DiagnosticDescriptor > & diagnostic_catalog ()
 
amrex::Vector< std::string > diagnostic_names ()
 
const DiagnosticDescriptorfind_diagnostic (const std::string &name)
 
void fill_component_with_value (MultiFab &dst, int dst_comp, Real value)
 
void fill_component_from_klevel (MultiFab &dst, int dst_comp, const MultiFab &src, int src_k, int src_comp)
 
void fill_component_from_klevel_or_value (MultiFab &dst, int dst_comp, const MultiFab *src, int src_k, Real missing_value, int src_comp)
 
void fill_sensible_heat_flux_from_klevel_or_missing (MultiFab &dst, int dst_comp, const MultiFab *src, int src_k, Real missing_value)
 
void fill_latent_heat_flux_from_klevel_or_missing (MultiFab &dst, int dst_comp, const MultiFab *src, int src_k, Real missing_value)
 
void fill_component_with_value (amrex::MultiFab &dst, int dst_comp, amrex::Real value)
 
void fill_component_from_klevel (amrex::MultiFab &dst, int dst_comp, const amrex::MultiFab &src, int src_k, int src_comp=0)
 
void fill_component_from_klevel_or_value (amrex::MultiFab &dst, int dst_comp, const amrex::MultiFab *src, int src_k, amrex::Real missing_value, int src_comp=0)
 
void fill_sensible_heat_flux_from_klevel_or_missing (amrex::MultiFab &dst, int dst_comp, const amrex::MultiFab *src, int src_k, amrex::Real missing_value)
 
void fill_latent_heat_flux_from_klevel_or_missing (amrex::MultiFab &dst, int dst_comp, const amrex::MultiFab *src, int src_k, amrex::Real missing_value)
 
const char * diagnostic_category_to_string (DiagnosticCategory category) noexcept
 
const char * missing_policy_to_string (MissingPolicy policy) noexcept
 
std::string missing_value_json (MissingPolicy policy)
 
std::string escape_json_string (const std::string &value)
 
std::string metadata_json_filename (const std::string &plotfilename)
 
std::string format_2d_metadata_json (const amrex::Vector< std::string > &varnames)
 
void write_2d_metadata_json (const std::string &plotfilename, const amrex::Vector< std::string > &varnames)
 
PlotVariableSelection select_requested_plot_variables (const amrex::Vector< std::string > &requested, const amrex::Vector< std::string > &available)
 
std::string format_unavailable_2d_plot_var_warning (const std::string &parameter_name, const std::string &unavailable_name, const amrex::Vector< std::string > &available_names)
 
std::string format_plot2d_parameter_name (const std::string &pp_prefix, const std::string &parameter_name)
 
std::string format_2d_component_count_error (int lev, int filled, int expected)
 
std::string format_invalid_2d_stream_error (int which)
 
AMREX_FORCE_INLINE bool use_native_shoc_consumed_flux_source (bool native_shoc_owns_scalar_fluxes, bool native_shoc_has_consumed_flux_diagnostics, bool host_flux_field_available) noexcept
 

Enumeration Type Documentation

◆ DiagnosticCategory

Enumerator
Geometry 
SurfaceLayer 
Radiation 
SurfaceFlux 
PBL 
SurfaceState 
ColumnIntegral 

◆ DiagnosticID

Enumerator
ZSurf 
LandMask 
MapFac 
LatM 
LonM 
UStar 
WStar 
TStar 
QStar 
Olen 
Pblh 
TSurf 
QSurf 
Z0 
OLR 
SensFlux 
LatenFlux 
SurfPres 
IntegratedQv 
SurfaceDiagnosticSource 
SensibleHeatFlux 
LatentHeatFlux 
ShocUStar 
ShocOlen 
ShocWthvSfc 
12 {
13  ZSurf,
14  LandMask,
15  MapFac,
16  LatM,
17  LonM,
18  UStar,
19  WStar,
20  TStar,
21  QStar,
22  Olen,
23  Pblh,
24  TSurf,
25  QSurf,
26  Z0,
27  OLR,
28  SensFlux,
29  LatenFlux,
30  SurfPres,
35  ShocUStar,
36  ShocOlen,
38 };
SurfaceDiagnosticSource
Definition: ERF_SurfaceDiagnosticSource.H:16

◆ MissingPolicy

Enumerator
AlwaysAvailable 
FillZeroWhenUnavailable 
FillMinus999WhenUnavailable 

Function Documentation

◆ diagnostic_catalog()

const amrex::Vector< DiagnosticDescriptor > & plotfile2d::diagnostic_catalog ( )
57 {
58  return catalog_storage();
59 }

Referenced by diagnostic_names(), and find_diagnostic().

Here is the caller graph for this function:

◆ diagnostic_category_to_string()

const char * plotfile2d::diagnostic_category_to_string ( DiagnosticCategory  category)
noexcept
63 {
64  switch (category) {
65  case DiagnosticCategory::Geometry: return "Geometry";
66  case DiagnosticCategory::SurfaceLayer: return "SurfaceLayer";
67  case DiagnosticCategory::Radiation: return "Radiation";
68  case DiagnosticCategory::SurfaceFlux: return "SurfaceFlux";
69  case DiagnosticCategory::PBL: return "PBL";
70  case DiagnosticCategory::SurfaceState: return "SurfaceState";
71  case DiagnosticCategory::ColumnIntegral: return "ColumnIntegral";
72  }
73 
74  amrex::Abort("Unhandled DiagnosticCategory in 2D metadata writer");
75  return "";
76 }

◆ diagnostic_names()

amrex::Vector< std::string > plotfile2d::diagnostic_names ( )
63 {
64  amrex::Vector<std::string> names;
65  names.reserve(diagnostic_catalog().size());
66 
67  for (const auto& descriptor : diagnostic_catalog()) {
68  names.push_back(descriptor.name);
69  }
70 
71  return names;
72 }
const amrex::Vector< DiagnosticDescriptor > & diagnostic_catalog()
Definition: ERF_Plotfile2DCatalog.cpp:56

Referenced by ERF::setPlotVariables2D().

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

◆ escape_json_string()

std::string plotfile2d::escape_json_string ( const std::string &  value)
106 {
107  std::string escaped;
108  escaped.reserve(value.size() + 8);
109 
110  for (unsigned char c : value) {
111  switch (c) {
112  case '\"': escaped += "\\\""; break;
113  case '\\': escaped += "\\\\"; break;
114  case '\n': escaped += "\\n"; break;
115  case '\t': escaped += "\\t"; break;
116  case '\r': escaped += "\\r"; break;
117  default:
118  if (c < 0x20) {
119  append_escaped_codepoint(escaped, c);
120  } else {
121  escaped.push_back(static_cast<char>(c));
122  }
123  break;
124  }
125  }
126 
127  return escaped;
128 }
amrex::Real value
Definition: ERF_HurricaneDiagnostics.H:20

◆ fill_component_from_klevel() [1/2]

void plotfile2d::fill_component_from_klevel ( amrex::MultiFab &  dst,
int  dst_comp,
const amrex::MultiFab &  src,
int  src_k,
int  src_comp = 0 
)

◆ fill_component_from_klevel() [2/2]

void plotfile2d::fill_component_from_klevel ( MultiFab &  dst,
int  dst_comp,
const MultiFab &  src,
int  src_k,
int  src_comp 
)
24 {
25  // Iterate over dst because it defines the 2D output component layout. The
26  // source must be box-compatible with dst on the horizontal tile covered by
27  // each MFIter.
28 #ifdef _OPENMP
29 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
30 #endif
31  for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi)
32  {
33  const Box& bx = mfi.tilebox();
34  const auto& dst_arr = dst.array(mfi);
35  const auto& src_arr = src.const_array(mfi);
36 
37  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
38  dst_arr(i, j, k, dst_comp) = src_arr(i, j, src_k, src_comp);
39  });
40  }
41 }
ParallelFor(grown_box, [=] AMREX_GPU_DEVICE(int i, int j, int k) { qrcuten_arr(i, j, k)=Real(0);qscuten_arr(i, j, k)=Real(0);qicuten_arr(i, j, k)=Real(0);})

Referenced by fill_component_from_klevel_or_value().

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

◆ fill_component_from_klevel_or_value() [1/2]

void plotfile2d::fill_component_from_klevel_or_value ( amrex::MultiFab &  dst,
int  dst_comp,
const amrex::MultiFab *  src,
int  src_k,
amrex::Real  missing_value,
int  src_comp = 0 
)

◆ fill_component_from_klevel_or_value() [2/2]

void plotfile2d::fill_component_from_klevel_or_value ( MultiFab &  dst,
int  dst_comp,
const MultiFab *  src,
int  src_k,
Real  missing_value,
int  src_comp 
)
50 {
51  if (src) {
52  fill_component_from_klevel(dst, dst_comp, *src, src_k, src_comp);
53  } else {
54  fill_component_with_value(dst, dst_comp, missing_value);
55  }
56 }
void fill_component_from_klevel(MultiFab &dst, int dst_comp, const MultiFab &src, int src_k, int src_comp)
Definition: ERF_Plotfile2DFill.cpp:19
void fill_component_with_value(MultiFab &dst, int dst_comp, Real value)
Definition: ERF_Plotfile2DFill.cpp:13

Referenced by ERF::Write2DPlotFile().

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

◆ fill_component_with_value() [1/2]

void plotfile2d::fill_component_with_value ( amrex::MultiFab &  dst,
int  dst_comp,
amrex::Real  value 
)

◆ fill_component_with_value() [2/2]

void plotfile2d::fill_component_with_value ( MultiFab &  dst,
int  dst_comp,
Real  value 
)
14 {
15  dst.setVal(value, dst_comp, 1, 0);
16 }

Referenced by fill_component_from_klevel_or_value(), fill_latent_heat_flux_from_klevel_or_missing(), and fill_sensible_heat_flux_from_klevel_or_missing().

Here is the caller graph for this function:

◆ fill_latent_heat_flux_from_klevel_or_missing() [1/2]

void plotfile2d::fill_latent_heat_flux_from_klevel_or_missing ( amrex::MultiFab &  dst,
int  dst_comp,
const amrex::MultiFab *  src,
int  src_k,
amrex::Real  missing_value 
)

◆ fill_latent_heat_flux_from_klevel_or_missing() [2/2]

void plotfile2d::fill_latent_heat_flux_from_klevel_or_missing ( MultiFab &  dst,
int  dst_comp,
const MultiFab *  src,
int  src_k,
Real  missing_value 
)
95 {
96  if (!src) {
97  fill_component_with_value(dst, dst_comp, missing_value);
98  return;
99  }
100 
101 #ifdef _OPENMP
102 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
103 #endif
104  for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi)
105  {
106  // Keep unit conversion in the surface-flux diagnostic helper so this
107  // mechanical layer does not duplicate physical constants or units.
108  const Box& bx = mfi.tilebox();
109  const auto& dst_arr = dst.array(mfi);
110  const auto& src_arr = src->const_array(mfi);
111 
112  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
113  dst_arr(i, j, k, dst_comp) =
115  src_arr(i, j, src_k, 0));
116  });
117  }
118 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real latent_heat_flux_wm2_from_rhoqv_flux(amrex::Real rhoqv_flux) noexcept
Definition: ERF_SurfaceFluxDiagnostics.H:36

Referenced by ERF::Write2DPlotFile().

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

◆ fill_sensible_heat_flux_from_klevel_or_missing() [1/2]

void plotfile2d::fill_sensible_heat_flux_from_klevel_or_missing ( amrex::MultiFab &  dst,
int  dst_comp,
const amrex::MultiFab *  src,
int  src_k,
amrex::Real  missing_value 
)

◆ fill_sensible_heat_flux_from_klevel_or_missing() [2/2]

void plotfile2d::fill_sensible_heat_flux_from_klevel_or_missing ( MultiFab &  dst,
int  dst_comp,
const MultiFab *  src,
int  src_k,
Real  missing_value 
)
64 {
65  if (!src) {
66  fill_component_with_value(dst, dst_comp, missing_value);
67  return;
68  }
69 
70 #ifdef _OPENMP
71 #pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
72 #endif
73  for (MFIter mfi(dst, TilingIfNotGPU()); mfi.isValid(); ++mfi)
74  {
75  // Keep unit conversion in the surface-flux diagnostic helper so this
76  // mechanical layer does not duplicate physical constants or units.
77  const Box& bx = mfi.tilebox();
78  const auto& dst_arr = dst.array(mfi);
79  const auto& src_arr = src->const_array(mfi);
80 
81  ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
82  dst_arr(i, j, k, dst_comp) =
84  src_arr(i, j, src_k, 0));
85  });
86  }
87 }
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real sensible_heat_flux_wm2_from_rhotheta_flux(amrex::Real rhotheta_flux) noexcept
Definition: ERF_SurfaceFluxDiagnostics.H:29

Referenced by ERF::Write2DPlotFile().

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

◆ find_diagnostic()

const DiagnosticDescriptor * plotfile2d::find_diagnostic ( const std::string &  name)
76 {
77  for (const auto& descriptor : diagnostic_catalog()) {
78  if (name == descriptor.name) {
79  return &descriptor;
80  }
81  }
82 
83  return nullptr;
84 }

Referenced by format_2d_metadata_json().

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

◆ format_2d_component_count_error()

std::string plotfile2d::format_2d_component_count_error ( int  lev,
int  filled,
int  expected 
)
87 {
88  std::ostringstream os;
89  os << "Write2DPlotFile internal error at level " << lev
90  << ": filled " << filled
91  << " components but expected " << expected
92  << ". The 2D plot variable list and fill blocks are inconsistent.";
93  return os.str();
94 }

Referenced by ERF::Write2DPlotFile().

Here is the caller graph for this function:

◆ format_2d_metadata_json()

std::string plotfile2d::format_2d_metadata_json ( const amrex::Vector< std::string > &  varnames)
138 {
139  // Native AMReX 2D plotfiles get a metadata sidecar for the selected
140  // output variables only. The writer formats catalog metadata; it does not
141  // compute diagnostics or encode runtime source selection.
142  std::ostringstream os;
143  os << "{\n";
144  os << " \"format_version\": 1,\n";
145  os << " \"kind\": \"ERF 2D plotfile metadata\",\n";
146  os << " \"n_variables\": " << static_cast<int>(varnames.size()) << ",\n";
147  os << " \"variables\": [\n";
148 
149  for (int i = 0; i < static_cast<int>(varnames.size()); ++i) {
150  const auto* descriptor = find_diagnostic(varnames[i]);
151  if (descriptor == nullptr) {
152  amrex::Abort("2D metadata requested for unknown diagnostic '" + varnames[i] + "'");
153  }
154 
155  append_variable_record(os, *descriptor, i, i == static_cast<int>(varnames.size()) - 1);
156  }
157 
158  os << " ]\n";
159  os << "}\n";
160  return os.str();
161 }
const DiagnosticDescriptor * find_diagnostic(const std::string &name)
Definition: ERF_Plotfile2DCatalog.cpp:75

Referenced by write_2d_metadata_json().

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

◆ format_invalid_2d_stream_error()

std::string plotfile2d::format_invalid_2d_stream_error ( int  which)
98 {
99  std::ostringstream os;
100  os << "Write2DPlotFile received invalid stream index " << which
101  << "; expected 1 or 2.";
102  return os.str();
103 }

◆ format_plot2d_parameter_name()

std::string plotfile2d::format_plot2d_parameter_name ( const std::string &  pp_prefix,
const std::string &  parameter_name 
)
77 {
78  if (pp_prefix.empty()) {
79  return parameter_name;
80  }
81 
82  return pp_prefix + "." + parameter_name;
83 }

Referenced by ERF::setPlotVariables2D().

Here is the caller graph for this function:

◆ format_unavailable_2d_plot_var_warning()

std::string plotfile2d::format_unavailable_2d_plot_var_warning ( const std::string &  parameter_name,
const std::string &  unavailable_name,
const amrex::Vector< std::string > &  available_names 
)
65 {
66  std::ostringstream os;
67  os << "WARNING: Requested 2D plot variable '" << unavailable_name
68  << "' from '" << parameter_name
69  << "' is not available and will be skipped. Available built-in 2D plot variables are: "
70  << join_names(available_names) << ".";
71  return os.str();
72 }

◆ metadata_json_filename()

std::string plotfile2d::metadata_json_filename ( const std::string &  plotfilename)
132 {
133  return plotfilename + "/2DMetadata.json";
134 }

Referenced by write_2d_metadata_json().

Here is the caller graph for this function:

◆ missing_policy_to_string()

const char * plotfile2d::missing_policy_to_string ( MissingPolicy  policy)
noexcept
80 {
81  switch (policy) {
82  case MissingPolicy::AlwaysAvailable: return "AlwaysAvailable";
83  case MissingPolicy::FillZeroWhenUnavailable: return "FillZeroWhenUnavailable";
84  case MissingPolicy::FillMinus999WhenUnavailable: return "FillMinus999WhenUnavailable";
85  }
86 
87  amrex::Abort("Unhandled MissingPolicy in 2D metadata writer");
88  return "";
89 }

◆ missing_value_json()

std::string plotfile2d::missing_value_json ( MissingPolicy  policy)
93 {
94  switch (policy) {
95  case MissingPolicy::AlwaysAvailable: return "null";
96  case MissingPolicy::FillZeroWhenUnavailable: return "0";
97  case MissingPolicy::FillMinus999WhenUnavailable: return "-999";
98  }
99 
100  amrex::Abort("Unhandled MissingPolicy in 2D metadata writer");
101  return {};
102 }

◆ select_requested_plot_variables()

PlotVariableSelection plotfile2d::select_requested_plot_variables ( const amrex::Vector< std::string > &  requested,
const amrex::Vector< std::string > &  available 
)
33 {
34  PlotVariableSelection selection;
35 
36  std::unordered_set<std::string> requested_set(requested.begin(), requested.end());
37  std::unordered_set<std::string> available_set(available.begin(), available.end());
38  std::unordered_set<std::string> seen_unavailable;
39 
40  // Preserve the canonical built-in ordering so component indices remain
41  // stable even when the user lists variables in a different order.
42  for (const auto& name : available) {
43  if (requested_set.count(name) != 0) {
44  selection.accepted.push_back(name);
45  }
46  }
47 
48  // Report each missing name once, in the order it was requested. The caller
49  // uses these names to emit warnings without duplicating messages for repeats.
50  for (const auto& name : requested) {
51  if (available_set.count(name) == 0) {
52  if (seen_unavailable.insert(name).second) {
53  selection.unavailable.push_back(name);
54  }
55  }
56  }
57 
58  return selection;
59 }

Referenced by ERF::setPlotVariables2D().

Here is the caller graph for this function:

◆ use_native_shoc_consumed_flux_source()

AMREX_FORCE_INLINE bool plotfile2d::use_native_shoc_consumed_flux_source ( bool  native_shoc_owns_scalar_fluxes,
bool  native_shoc_has_consumed_flux_diagnostics,
bool  host_flux_field_available 
)
noexcept
23 {
24  return native_shoc_owns_scalar_fluxes &&
25  native_shoc_has_consumed_flux_diagnostics &&
26  host_flux_field_available;
27 }

Referenced by ERF::Write2DPlotFile().

Here is the caller graph for this function:

◆ write_2d_metadata_json()

void plotfile2d::write_2d_metadata_json ( const std::string &  plotfilename,
const amrex::Vector< std::string > &  varnames 
)
166 {
167  // Native AMReX 2D plotfiles write this sidecar next to the plotfile
168  // directory on the I/O processor only.
169  if (!amrex::ParallelDescriptor::IOProcessor()) {
170  return;
171  }
172 
173  const std::string filename = metadata_json_filename(plotfilename);
174  std::ofstream outfile(filename, std::ios::out | std::ios::trunc);
175  if (!outfile.good()) {
176  amrex::FileOpenFailed(filename);
177  }
178 
179  outfile << format_2d_metadata_json(varnames);
180  if (!outfile.good()) {
181  amrex::FileOpenFailed(filename);
182  }
183 }
struct @28 out
std::string format_2d_metadata_json(const amrex::Vector< std::string > &varnames)
Definition: ERF_Plotfile2DMetadata.cpp:137
std::string metadata_json_filename(const std::string &plotfilename)
Definition: ERF_Plotfile2DMetadata.cpp:131

Referenced by ERF::Write2DPlotFile().

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