@@ -8,9 +8,23 @@ namespace scream {
8
8
9
9
HistogramDiag::HistogramDiag (const ekat::Comm &comm, const ekat::ParameterList ¶ms)
10
10
: AtmosphereDiagnostic(comm, params) {
11
- const auto &field_name = m_params.get <std::string>(" field_name" );
12
- m_bin_configuration = params.get <std::string>(" bin_configuration" );
13
- m_diag_name = field_name + " _histogram_" + m_bin_configuration;
11
+ const auto &field_name = m_params.get <std::string>(" field_name" );
12
+ const std::string bin_config = m_params.get <std::string>(" bin_configuration" );
13
+ m_diag_name = field_name + " _histogram_" + bin_config;
14
+
15
+ // extract bin values from configuration, append end values, and check
16
+ const std::vector<std::string> bin_strings = ekat::split (bin_config, " _" );
17
+ m_bin_reals.resize (bin_strings.size ()+2 );
18
+ m_bin_reals[0 ] = std::numeric_limits<Real>::lowest ();
19
+ for (int i=1 ; i < m_bin_reals.size ()-1 ; i++)
20
+ {
21
+ m_bin_reals[i] = std::stod (bin_strings[i-1 ]);
22
+ EKAT_REQUIRE_MSG (m_bin_reals[i] > m_bin_reals[i-1 ],
23
+ " Error! HistogramDiag bin values must be monotonically "
24
+ " increasing.\n "
25
+ " - bin configuration: " + bin_config + " \n " );
26
+ }
27
+ m_bin_reals.back () = std::numeric_limits<Real>::max ();
14
28
}
15
29
16
30
void HistogramDiag::set_grids (const std::shared_ptr<const GridsManager> grids_manager) {
@@ -34,11 +48,8 @@ void HistogramDiag::initialize_impl(const RunType /*run_type*/) {
34
48
" - field layout: " +
35
49
field_layout.to_string () + " \n " );
36
50
37
- // extract bin values from configuration
38
- std::vector<std::string> bin_strings = ekat::split (m_bin_configuration, " _" );
39
- const int num_bins = bin_strings.size ()-1 ;
40
-
41
51
// allocate histogram field
52
+ const int num_bins = m_bin_reals.size ()-1 ;
42
53
FieldLayout diagnostic_layout ({CMP}, {num_bins}, {" bin" });
43
54
FieldIdentifier diagnostic_id (m_diag_name, diagnostic_layout,
44
55
FieldIdentifier::Units::nondimensional (),
@@ -56,7 +67,7 @@ void HistogramDiag::initialize_impl(const RunType /*run_type*/) {
56
67
using RangePolicy = Kokkos::RangePolicy<Field::device_t ::execution_space>;
57
68
Kokkos::parallel_for (" store_histogram_bin_values_" + field.name (),
58
69
RangePolicy (0 , bin_values_layout.dim (0 )), [&] (int i) {
59
- bin_values_view (i) = std::stod (bin_strings [i]) ;
70
+ bin_values_view (i) = m_bin_reals [i];
60
71
});
61
72
}
62
73
0 commit comments