Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mam4xx/mam4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <mam4xx/ndrop.hpp>
#include <mam4xx/nucleate_ice.hpp>
#include <mam4xx/nucleation.hpp>
#include <mam4xx/physical_limits.hpp>
#include <mam4xx/rename.hpp>
#include <mam4xx/spitfire_transport.hpp>
#include <mam4xx/tropopause.hpp>
Expand Down
77 changes: 77 additions & 0 deletions src/mam4xx/physical_limits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// mam4xx: Copyright (c) 2022,
// Battelle Memorial Institute and
// National Technology & Engineering Solutions of Sandia, LLC (NTESS)
// SPDX-License-Identifier: BSD-3-Clause

#ifndef PHYSICAL_LIMITS_HPP
#define PHYSICAL_LIMITS_HPP
#include <map>
#include <string>
#include <utility>

namespace mam4 {

#if 0
// If a device callable version of physical_min and physical_max is needed along
// with the CPU only version, somthing like this would work. Strings do not do
// well on device but enums are fast.

enum FieldNameIndex { T_mid, qv, qc, qi, nc, nr, ni, nmr, mmr, NUMFIELD};
struct min_max {const Real min; const Real max;};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might this be better-named MinMax?


KOKKOS_INLINE_FUNCTION constexpr min_max physical_min_max(const FieldNameIndex ind) {
const min_max field_min_max[NUMFIELD] = {
{100, 500}, // T_mid
{1e-13, 0.2}, // qv
{0, 0.1}, // qc
{0, 0.1}, // qi
{0, 0.1e11}, // nc
{0, 0.1e10}, // nr
{0, 0.1e10}, // ni
{0, 1e13}, // nmr
{-1e-20, 1e-2} // mmr
};
return field_min_max[ind];
}

KOKKOS_INLINE_FUNCTION constexpr Real physical_min(const FieldNameIndex ind) {
return physical_min_max(ind).min;
}

KOKKOS_INLINE_FUNCTION constexpr Real physical_max(const FieldNameIndex ind) {
return physical_min_max(ind).max;
}

inline const std::pair<Real,Real>& physical_min_max(const std::string &field_name) {
static const std::map<std::string, std::pair<Real,Real>>
limits = {
{"T_mid", {physical_min(T_mid), physical_max(T_mid)} },
{"qv", {physical_min(qv), physical_max(qv)} },
{"qc", {physical_min(qc), physical_max(qc)} },
{"qi", {physical_min(qi), physical_max(qi)} },
{"nc", {physical_min(nc), physical_max(nc)} },
{"nr", {physical_min(nr), physical_max(nr)} },
{"ni", {physical_min(ni), physical_max(ni)} },
{"nmr", {physical_min(nmr), physical_max(nmr)} },
{"mmr", {physical_min(mmr), physical_max(mmr)} }
};
return limits.at(field_name);
}
#endif
inline const std::pair<Real, Real> &
physical_min_max(const std::string &field_name) {
static const std::map<std::string, std::pair<Real, Real>> limits = {
{"T_mid", {100, 500}}, {"qv", {1e-13, 0.2}}, {"qc", {0, 0.1}},
{"qi", {0, 0.1}}, {"nc", {0, 0.1e11}}, {"nr", {0, 0.1e10}},
{"ni", {0, 0.1e10}}, {"nmr", {0, 1e13}}, {"mmr", {-1e-20, 1e-2}}};
return limits.at(field_name);
}
inline Real physical_min(const std::string &field_name) {
return physical_min_max(field_name).first;
}
inline Real physical_max(const std::string &field_name) {
return physical_min_max(field_name).second;
}
} // namespace mam4

#endif
Loading