|
| | RadiationDiagnostics (int verbosity, const std::string &diag_file, bool diag_enable=true, bool diag_stdout_enable=true, bool diag_tagged_enable=true, bool diag_regtest_line_enable=true, bool diag_csv_enable=true, const std::string &diag_callsite_mode="both", amrex::Real diag_dedup_tol=1.0e-12) |
| | Constructor. More...
|
| |
| | ~RadiationDiagnostics () |
| | Destructor. More...
|
| |
| void | append (int step, amrex::Real time, std::string const &call_site, amrex::Real sw_surface, amrex::Real sw_toa, amrex::Real sw_up_toa, amrex::Real lw_net_surface, amrex::Real lw_up_toa, amrex::Real heating_rate_max, amrex::Real seb_residual_mean=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real seb_residual_max=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real t_s_mean=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real t_s_max=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real q_s_mean=std::numeric_limits< amrex::Real >::quiet_NaN(), amrex::Real q_s_max=std::numeric_limits< amrex::Real >::quiet_NaN()) |
| | Append a diagnostic row to the CSV file. More...
|
| |
CSV logger and debug-print manager for radiation module.
Manages output of radiation diagnostics including:
- Tagged debug prints (when verbosity >= 1)
- CSV rows for flux/heating diagnostics
- RADIATION_DIAG: lines for RegTest parsing
Dedup Contract:
Duplicate detection uses a 3-tuple identity (step, call_site, time):
- step: timestep number (int)
- call_site: diagnostic call-site label (e.g., "pre_dycore", "post_dycore")
- time: simulation time with tolerance m_diag_dedup_tol
This ensures:
- Accidental repeated calls at the same (step, call_site, time) are suppressed.
- Legitimate pre_dycore + post_dycore entries at the same step are both retained (they have different call_site values, so dedup identity differs).
- Mode filtering (pre_only, post_only, both) preserves this contract by checking whether to emit BEFORE the dedup guard runs.
Follows the duplicate-write-guard pattern from UCMDiagnostics.
| void RadiationDiagnostics::append |
( |
int |
step, |
|
|
amrex::Real |
time, |
|
|
std::string const & |
call_site, |
|
|
amrex::Real |
sw_surface, |
|
|
amrex::Real |
sw_toa, |
|
|
amrex::Real |
sw_up_toa, |
|
|
amrex::Real |
lw_net_surface, |
|
|
amrex::Real |
lw_up_toa, |
|
|
amrex::Real |
heating_rate_max, |
|
|
amrex::Real |
seb_residual_mean = std::numeric_limits<amrex::Real>::quiet_NaN(), |
|
|
amrex::Real |
seb_residual_max = std::numeric_limits<amrex::Real>::quiet_NaN(), |
|
|
amrex::Real |
t_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN(), |
|
|
amrex::Real |
t_s_max = std::numeric_limits<amrex::Real>::quiet_NaN(), |
|
|
amrex::Real |
q_s_mean = std::numeric_limits<amrex::Real>::quiet_NaN(), |
|
|
amrex::Real |
q_s_max = std::numeric_limits<amrex::Real>::quiet_NaN() |
|
) |
| |
Append a diagnostic row to the CSV file.
Records a row of radiation diagnostics for the current timestep:
CSV columns (order): step, time, call_site, SW_surface, SW_TOA, SW_up_TOA, LW_net_surface, LW_up_TOA, heating_rate_max [optional]: SEB_residual_mean, SEB_residual_max (only if seb_diagnostic_enable=true)
Also prints tagged debug output and RADIATION_DIAG: line for RegTest parsing.
Guards against duplicate writes (uses m_last_write_step).
- Parameters
-
| [in] | step | Current timestep number. |
| [in] | time | Current simulation time [s]. |
| [in] | call_site | Diagnostic call-site label (e.g., "pre_dycore", "post_dycore"). |
| [in] | SW_surface | SW absorbed by the surface, (1 - albedo) * incident [W/m^2]. |
| [in] | SW_TOA | Incident SW at the top of the atmosphere [W/m^2]. |
| [in] | SW_up_TOA | Reflected SW leaving the top of the atmosphere [W/m^2]. |
| [in] | LW_net_surface | Net LW (up - down) at the surface [W/m^2]. |
| [in] | LW_up_TOA | Outgoing LW at the top of the atmosphere [W/m^2]. |
| [in] | heating_rate_max | Maximum heating rate magnitude [K/s]. |
| [in] | seb_residual_mean | [optional] Mean SEB residual [W/m^2]; if non-finite, not written. |
| [in] | seb_residual_max | [optional] Max SEB residual [W/m^2]; if non-finite, not written. |
| [in] | t_s_mean | [optional] Mean surface temperature [K]; if non-finite, written as NaN. |
| [in] | t_s_max | [optional] Max surface temperature [K]; if non-finite, written as NaN. |
| [in] | q_s_mean | [optional] Mean surface moisture [kg/kg]; if non-finite, written as NaN. |
| [in] | q_s_max | [optional] Max surface moisture [kg/kg]; if non-finite, written as NaN. |
95 bool is_pre_site = (call_site.find(
"pre") != std::string::npos);
96 bool is_post_site = (call_site.find(
"post") != std::string::npos);
99 if ((is_pre_site && !should_emit_pre) || (is_post_site && !should_emit_post)) {
128 if (
m_verbosity >= 1 && amrex::ParallelDescriptor::IOProcessor() &&
130 amrex::Print() <<
"[RAD][RadiationDiagnostics::append] step=" << step
132 <<
" call_site=" << call_site
133 <<
" SW_surface=" << SW_surface
134 <<
" SW_TOA=" << SW_TOA <<
" SW_up_TOA=" << SW_up_TOA
135 <<
" LW_net_surface=" << LW_net_surface
136 <<
" LW_up_TOA=" << LW_up_TOA
137 <<
" heating_rate_max=" << heating_rate_max <<
"\n";
143 amrex::Print() <<
"RADIATION_DIAG: step=" << step <<
" time=" << time
144 <<
" call_site=" << call_site
145 <<
" SW_surface=" << std::scientific << std::setprecision(6)
146 << SW_surface <<
" SW_TOA=" << SW_TOA <<
" SW_up_TOA=" << SW_up_TOA
147 <<
" LW_net_surface=" << LW_net_surface <<
" LW_up_TOA=" << LW_up_TOA
148 <<
" heating_rate_max=" << heating_rate_max <<
"\n";
159 if (!outfile.good()) {
160 amrex::Warning(
"RadiationDiagnostics: Could not open file " +
m_diag_file +
166 outfile << step <<
"," << std::scientific << std::setprecision(6) << time <<
","
168 << SW_surface <<
"," << SW_TOA <<
"," << SW_up_TOA <<
"," << LW_net_surface <<
"," << LW_up_TOA
169 <<
"," << heating_rate_max;
172 outfile <<
"," << seb_residual_mean <<
"," << seb_residual_max;
175 outfile <<
"," << t_s_mean <<
"," << t_s_max <<
"," << q_s_mean <<
"," << q_s_max;
int m_last_write_step
Guard against duplicate writes.
Definition: ERF_RadiationDiagnostics.H:145
void write_header_if_needed()
Write CSV header if file is new or doesn't exist.
Definition: ERF_RadiationDiagnostics.cpp:38
amrex::Real m_last_write_time
Definition: ERF_RadiationDiagnostics.H:148
std::string m_last_write_call_site
Definition: ERF_RadiationDiagnostics.H:147
Referenced by TwoStreamRadiation::advance().