|
5 | 5 |
|
6 | 6 | #ifndef PHYSICAL_LIMITS_HPP |
7 | 7 | #define PHYSICAL_LIMITS_HPP |
8 | | -#include <utility> |
9 | | -#include <string> |
10 | 8 | #include <map> |
| 9 | +#include <string> |
| 10 | +#include <utility> |
11 | 11 |
|
12 | 12 | namespace mam4 { |
13 | 13 |
|
| 14 | +#if 0 |
| 15 | + // If a device callable version of physical_min and physical_max is needed along |
| 16 | + // with the CPU only version, somthing like this would work. Strings do not do |
| 17 | + // well on device but enums are fast. |
| 18 | + |
| 19 | + enum FieldNameIndex { T_mid, qv , qc , qt , nc , nr , ni , nmr , mmr, NUMFIELD }; |
| 20 | + struct min_max {const Real min; const Real max;}; |
| 21 | + |
| 22 | + KOKKOS_INLINE_FUNCTION constexpr min_max physical_min_max(const FieldNameIndex ind) { |
| 23 | + const min_max field_min_max[NUMFIELD] = { |
| 24 | + {100, 500}, // T_mid |
| 25 | + {1e-13, 0.2}, // qv |
| 26 | + {0, 0.1}, // qc |
| 27 | + {0, 0.1}, // qt |
| 28 | + {0, 0.1e11}, // nc |
| 29 | + {0, 0.1e10}, // nr |
| 30 | + {0, 0.1e10}, // ni |
| 31 | + {100, 0.1e13}, // nmr |
| 32 | + {100, 0.1e-5} // mmr |
| 33 | + }; |
| 34 | + return field_min_max[ind]; |
| 35 | + } |
| 36 | + |
| 37 | + KOKKOS_INLINE_FUNCTION constexpr Real physical_min(const FieldNameIndex ind) { |
| 38 | + return physical_min_max(ind).min; |
| 39 | + } |
| 40 | + |
| 41 | + KOKKOS_INLINE_FUNCTION constexpr Real physical_max(const FieldNameIndex ind) { |
| 42 | + return physical_min_max(ind).max; |
| 43 | + } |
| 44 | + |
14 | 45 | inline const std::pair<Real,Real>& physical_min_max(const std::string &field_name) { |
15 | 46 | static const std::map<std::string, std::pair<Real,Real>> |
16 | 47 | limits = { |
17 | | - {"T_min", {100, 500} }, |
18 | | - {"qv", {1e-13, 0.2} }, |
19 | | - {"qc", {0, 0.1} }, |
20 | | - {"qt", {0, 0.1} }, |
21 | | - {"nc", {0, 0.1e11} }, |
22 | | - {"nr", {0, 0.1e10} }, |
23 | | - {"ni", {0, 0.1e10} }, |
24 | | - {"nmr", {0, 0.1e13} }, |
25 | | - {"mmr", {0, 0.1e-5} } |
| 48 | + {"T_mid", {physical_min(T_mid), physical_max(T_mid)} }, |
| 49 | + {"qv", {physical_min(qv), physical_max(qv)} }, |
| 50 | + {"qc", {physical_min(qc), physical_max(qc)} }, |
| 51 | + {"qt", {physical_min(qt), physical_max(qt)} }, |
| 52 | + {"nc", {physical_min(nc), physical_max(nc)} }, |
| 53 | + {"nr", {physical_min(nr), physical_max(nr)} }, |
| 54 | + {"ni", {physical_min(ni), physical_max(ni)} }, |
| 55 | + {"nmr", {physical_min(nmr), physical_max(nmr)} }, |
| 56 | + {"mmr", {physical_min(mmr), physical_max(mmr)} } |
26 | 57 | }; |
27 | 58 | return limits.at(field_name); |
28 | 59 | } |
29 | | - |
30 | | - inline Real physical_min(const std::string &field_name) { |
31 | | - return physical_min_max(field_name).first; |
32 | | - } |
33 | | - inline Real physical_max(const std::string &field_name) { |
34 | | - return physical_min_max(field_name).second; |
35 | | - } |
| 60 | +#endif |
| 61 | +inline const std::pair<Real, Real> & |
| 62 | +physical_min_max(const std::string &field_name) { |
| 63 | + static const std::map<std::string, std::pair<Real, Real>> limits = { |
| 64 | + {"T_mid", {100, 500}}, {"qv", {1e-13, 0.2}}, {"qc", {0, 0.1}}, |
| 65 | + {"qt", {0, 0.1}}, {"nc", {0, 0.1e11}}, {"nr", {0, 0.1e10}}, |
| 66 | + {"ni", {0, 0.1e10}}, {"nmr", {0, 0.1e13}}, {"mmr", {0, 0.1e-5}}}; |
| 67 | + return limits.at(field_name); |
| 68 | +} |
| 69 | +inline Real physical_min(const std::string &field_name) { |
| 70 | + return physical_min_max(field_name).first; |
| 71 | +} |
| 72 | +inline Real physical_max(const std::string &field_name) { |
| 73 | + return physical_min_max(field_name).second; |
| 74 | +} |
36 | 75 | } // namespace mam4 |
37 | 76 |
|
38 | 77 | #endif |
0 commit comments