Perform global reduction and write the budget report to file.
182 std::array<amrex::Real, NumScalars*NumFaces + NumScalars*3> packed{};
188 for (
int s = 0; s <
NumScalars; ++s) { packed[index++] = current[s]; }
190 amrex::ParallelDescriptor::ReduceRealSum(packed.data(),
static_cast<int>(packed.size()));
192 std::array<std::array<amrex::Real, NumFaces>,
NumScalars> global_faces{};
195 for (
int f = 0; f <
NumFaces; ++f) { global_faces[s][f] = packed[index++]; }
197 std::array<amrex::Real, NumScalars> initial{};
198 std::array<amrex::Real, NumScalars> global_current{};
200 for (
int s = 0; s <
NumScalars; ++s) { initial[s] = packed[index++]; }
201 for (
int s = 0; s <
NumScalars; ++s) { global_current[s] = packed[index++]; }
202 std::array<amrex::Real, NumScalars> global_internal{};
203 for (
int s = 0; s <
NumScalars; ++s) { global_internal[s] = packed[index++]; }
205 if (amrex::ParallelDescriptor::IOProcessor()) {
206 std::ofstream out(
"cloud_chamber_budget.dat", std::ios::app);
207 if (out.tellp() == std::streampos(0)) {
208 out <<
"# start_step start_time end_step end_time scalar units "
209 "xlo xhi ylo yhi zlo zhi net_boundary volume_change "
210 "internal_source residual tolerance status\n";
212 out << std::setprecision(17);
213 const char* names[
NumScalars] = {
"rhoTheta",
"water_vapor",
"cloud_water"};
214 const char*
units[
NumScalars] = {
"conserved_scalar",
"mixing_ratio_density",
"mixing_ratio_density"};
216 std::array<amrex::Real, NumFaces> faces = global_faces[s];
217 amrex::Real net = faces[0] - faces[1] + faces[2] - faces[3] + faces[4] - faces[5];
218 const amrex::Real change = global_current[s] - initial[s];
220 const amrex::Real residual = change - net -
internal;
222 std::abs(initial[s]), std::abs(global_current[s]),
223 std::abs(net), std::abs(
internal)});
228 for (
const auto value : faces) { boundary_scale += std::abs(value); }
231 (effective_operations * scale + boundary_scale + std::abs(
internal));
232 const bool status = std::abs(residual) <= tolerance;
234 static_cast<Scalar>(s), cloudy, status);
236 << step <<
' ' << time <<
' ' << names[s] <<
' ' <<
units[s];
237 for (
const auto value : faces) { out <<
' ' << value; }
238 out <<
' ' << net <<
' ' << change <<
' ' <<
internal <<
' '
239 << residual <<
' ' << tolerance <<
' ' << status_text <<
'\n';
241 std::array<amrex::Real, NumFaces> total_faces{};
242 for (
int f = 0; f <
NumFaces; ++f) {
243 total_faces[f] = global_faces[
RhoQv][f] + global_faces[
RhoQc][f];
245 const amrex::Real total_net = total_faces[0] - total_faces[1] +
246 total_faces[2] - total_faces[3] + total_faces[4] - total_faces[5];
250 const amrex::Real total_residual = total_change - total_net - total_internal;
252 std::abs(total_net), std::abs(total_internal)});
254 for (
const auto value : total_faces) { total_boundary_scale += std::abs(value); }
258 total_boundary_scale + std::abs(total_internal));
259 const bool total_status = std::abs(total_residual) <= total_tolerance;
261 << step <<
' ' << time <<
" total_nonprecipitating_water mixing_ratio_density";
262 for (
const auto value : total_faces) { out <<
' ' << value; }
263 out <<
' ' << total_net <<
' ' << total_change <<
' ' << total_internal <<
' '
264 << total_residual <<
' ' << total_tolerance <<
' '
265 << (total_status ?
"PASS" :
"FAIL") <<
'\n';
std::string units
Definition: ERF_Plotfile2DCatalog.cpp:103
std::array< amrex::Real, NumScalars > m_initial_state
Definition: ERF_CloudChamberBudget.H:286
double m_interval_start_time
Definition: ERF_CloudChamberBudget.H:283
std::array< amrex::Real, NumScalars > state_integrals(const amrex::MultiFab &cons, const amrex::Geometry &geom) const
Definition: ERF_CloudChamberBudget.H:143
bool m_have_initial
Definition: ERF_CloudChamberBudget.H:284
Scalar
Definition: ERF_CloudChamberBudget.H:33
static const char * row_status(Scalar scalar, bool cloudy, bool closes) noexcept
Definition: ERF_CloudChamberBudget.H:40
int m_interval_start_step
Definition: ERF_CloudChamberBudget.H:282
bool due(int step) const noexcept
Definition: ERF_CloudChamberBudget.H:52
@ cons
Definition: ERF_IndexDefines.H:214
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12