ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_SBMCanonicalIdentity.H
Go to the documentation of this file.
1 #ifndef ERF_SBM_CANONICAL_IDENTITY_H_
2 #define ERF_SBM_CANONICAL_IDENTITY_H_
3 
4 #include <AMReX_REAL.H>
5 
6 #include <cmath>
7 #include <iomanip>
8 #include <limits>
9 #include <locale>
10 #include <sstream>
11 #include <string>
12 
13 namespace erf_sbm {
14 
15 // Scientific metadata is part of the restart/schema identity. Keep this
16 // policy in one place so grids and layouts cannot silently serialize the same
17 // value with different precision or locale rules.
18 inline std::string canonical_real (const amrex::Real value,
19  const bool allow_unbounded_nan = false)
20 {
21  if (allow_unbounded_nan && std::isnan(value)) return "unbounded";
22  std::ostringstream out;
23  out.imbue(std::locale::classic());
24  out.setf(std::ios_base::scientific, std::ios_base::floatfield);
25  out << std::setprecision(std::numeric_limits<amrex::Real>::max_digits10) << value;
26  return out.str();
27 }
28 
29 } // namespace erf_sbm
30 
31 #endif
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF.H:108
std::string canonical_real(const amrex::Real value, const bool allow_unbounded_nan=false)
Definition: ERF_SBMCanonicalIdentity.H:18