ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_DiffStruct.H
Go to the documentation of this file.
1 #ifndef ERF_DIFF_STRUCT_H_
2 #define ERF_DIFF_STRUCT_H_
3 
4 #include <string>
5 #include <iostream>
6 
7 #include <AMReX_ParmParse.H>
8 #include <AMReX_Print.H>
9 #include <AMReX_Gpu.H>
10 
11 #include "ERF_IndexDefines.H"
12 #include "ERF_NumericalConstants.H"
13 
14 /**
15  * @brief Molecular diffusion model used for transport coefficients.
16  */
17 enum struct MolecDiffType {
19 };
20 
21 /**
22  * Container holding diffusion-related choices
23  */
24 
25 struct DiffChoice {
26  public:
27  /**
28  * @brief Read diffusion options from the input parameter database.
29  * @param pp_prefix ParmParse prefix for the ERF input namespace.
30  */
31  void init_params (std::string pp_prefix)
32  {
33  amrex::ParmParse pp(pp_prefix);
34 
35  static std::string molec_diff_type_string = "None";
36  pp.queryAdd("molec_diff_type",molec_diff_type_string);
37 
38  if (!molec_diff_type_string.compare("Constant")) {
40  } else if (!molec_diff_type_string.compare("ConstantAlpha")) {
42  } else if (!molec_diff_type_string.compare("None")) {
44  } else {
45  amrex::Error("Don't know this molec_diff_type");
46  }
47 
49  pp.queryAdd("alpha_T", alpha_T);
50  pp.queryAdd("alpha_C", alpha_C);
51  pp.queryAdd("dynamic_viscosity", dynamic_viscosity);
52  pp.queryAdd("rho0_trans", rho0_trans);
53  pp.queryAdd("eb_diff_constraint_x", eb_diff_constraint_x);
54  pp.queryAdd("eb_diff_constraint_y", eb_diff_constraint_y);
55  pp.queryAdd("eb_diff_constraint_z", eb_diff_constraint_z);
56  }
57 
58  // Compute relevant forms of diffusion parameters
61 
63  amrex::Print() << "Using constant kinematic diffusion coefficients" << std::endl;
64  amrex::Print() << " momentum : " << dynamic_viscosity/rho0_trans << " m^2/s" << std::endl;
65  amrex::Print() << " temperature : " << alpha_T << " m^2/s" << std::endl;
66  amrex::Print() << " scalar : " << alpha_C << " m^2/s" << std::endl;
67  }
69  amrex::Print() << "Using constant dynamic diffusion coefficients" << std::endl;
70  amrex::Print() << " momentum : " << dynamic_viscosity << " kg/(m-s)" << std::endl;
71  amrex::Print() << " temperature : " << rhoAlpha_T << " kg/(m-s)" << std::endl;
72  amrex::Print() << " scalar : " << rhoAlpha_C << " kg/(m-s)" << std::endl;
73  }
74 
75  }
76 
77  /**
78  * @brief Print the configured diffusion options.
79  */
80  void display ()
81  {
82  amrex::Print() << "Diffusion choices: " << std::endl;
83  amrex::Print() << " rho0_trans : " << rho0_trans << std::endl;
84  amrex::Print() << " alpha_T : " << alpha_T << std::endl;
85  amrex::Print() << " alpha_C : " << alpha_C << std::endl;
86  amrex::Print() << " dynamic_viscosity : " << dynamic_viscosity << std::endl;
87 
89  amrex::Print() << "Using constant molecular diffusivity (relevant for DNS)" << std::endl;
90  } else if (molec_diff_type == MolecDiffType::None) {
91  amrex::Print() << "Not using any molecular diffusivity, i.e. using the modeled turbulent diffusivity"
92  << std::endl;
93  }
94  }
95 
96  // Molecular transport model
98 
99  // Diffusive/viscous coefficients [m2/s]
100  amrex::Real alpha_T = zero;
101  amrex::Real alpha_C = zero;
102 
103  // Density for computation of rhoAlpha (which is assumed constant) [kg/m3]
104  amrex::Real rho0_trans = one;
105 
106  // Dynamic diffusion coefficients [kg/(m-s)]
107  amrex::Real rhoAlpha_T = zero;
108  amrex::Real rhoAlpha_C = zero;
109  amrex::Real dynamic_viscosity = zero;
110  bool eb_diff_constraint_x = false;
111  bool eb_diff_constraint_y = false;
112  bool eb_diff_constraint_z = false;
113 
114  // Number of water (moist) species in the conserved state, starting at RhoQ1_comp.
115  // Set from Microphysics::Get_Qstate_Moist_Size() once the microphysics model exists;
116  // any non-water species a model carries are packed directly after these.
119  amrex::GpuArray<bool, NVAR_max - RhoQ1_comp> qstate_is_diagnostic{};
120 
121  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
122  bool host_transports (int n) const noexcept
123  {
124  AMREX_ASSERT(n >= 0 && n < NVAR_max);
125  return n < RhoQ1_comp || !qstate_is_diagnostic[n - RhoQ1_comp];
126  }
127 
128  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
129  bool implicit_q (int n) const noexcept
130  {
131  return n >= RhoQ1_comp &&
133  host_transports(n);
134  }
135 };
136 
137 /**
138  * @var DiffChoice::molec_diff_type
139  * @brief Selected molecular transport model.
140  * @var DiffChoice::alpha_T
141  * @brief Kinematic temperature diffusivity [m2/s].
142  * @var DiffChoice::alpha_C
143  * @brief Kinematic scalar diffusivity [m2/s].
144  * @var DiffChoice::rho0_trans
145  * @brief Reference density used to compute dynamic diffusion coefficients [kg/m3].
146  * @var DiffChoice::rhoAlpha_T
147  * @brief Dynamic temperature diffusion coefficient [kg/(m-s)].
148  * @var DiffChoice::rhoAlpha_C
149  * @brief Dynamic scalar diffusion coefficient [kg/(m-s)].
150  * @var DiffChoice::dynamic_viscosity
151  * @brief Dynamic viscosity for momentum diffusion [kg/(m-s)].
152  * @var DiffChoice::eb_diff_constraint_x
153  * @brief Whether to constrain EB diffusion in the x direction.
154  * @var DiffChoice::eb_diff_constraint_y
155  * @brief Whether to constrain EB diffusion in the y direction.
156  * @var DiffChoice::eb_diff_constraint_z
157  * @brief Whether to constrain EB diffusion in the z direction.
158  * @var DiffChoice::n_qstate_moist
159  * @brief Number of water-related conserved components starting at RhoQ1_comp,
160  * retaining their water-species molecular-diffusion coefficients.
161  */
162 #endif
MolecDiffType
Molecular diffusion model used for transport coefficients.
Definition: ERF_DiffStruct.H:17
#define NVAR_max
Definition: ERF_IndexDefines.H:45
#define RhoQ1_comp
Definition: ERF_IndexDefines.H:78
#define NMOIST_max
Definition: ERF_IndexDefines.H:37
ParmParse pp("prob")
Dimensionless numeric literals and pure mathematical constants.
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:37
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:36
Definition: ERF_DiffStruct.H:25
bool eb_diff_constraint_z
Whether to constrain EB diffusion in the z direction.
Definition: ERF_DiffStruct.H:112
int n_qstate_moist
Number of water-related conserved components starting at RhoQ1_comp, retaining their water-species mo...
Definition: ERF_DiffStruct.H:117
amrex::GpuArray< bool, NVAR_max - RhoQ1_comp > qstate_is_diagnostic
Definition: ERF_DiffStruct.H:119
MolecDiffType molec_diff_type
Selected molecular transport model.
Definition: ERF_DiffStruct.H:97
amrex::Real rhoAlpha_T
Dynamic temperature diffusion coefficient [kg/(m-s)].
Definition: ERF_DiffStruct.H:107
int n_qstate_nonmoist
Definition: ERF_DiffStruct.H:118
bool eb_diff_constraint_y
Whether to constrain EB diffusion in the y direction.
Definition: ERF_DiffStruct.H:111
amrex::Real alpha_C
Kinematic scalar diffusivity [m2/s].
Definition: ERF_DiffStruct.H:101
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool host_transports(int n) const noexcept
Definition: ERF_DiffStruct.H:122
bool eb_diff_constraint_x
Whether to constrain EB diffusion in the x direction.
Definition: ERF_DiffStruct.H:110
amrex::Real dynamic_viscosity
Dynamic viscosity for momentum diffusion [kg/(m-s)].
Definition: ERF_DiffStruct.H:109
void init_params(std::string pp_prefix)
Read diffusion options from the input parameter database.
Definition: ERF_DiffStruct.H:31
void display()
Print the configured diffusion options.
Definition: ERF_DiffStruct.H:80
amrex::Real rho0_trans
Reference density used to compute dynamic diffusion coefficients [kg/m3].
Definition: ERF_DiffStruct.H:104
amrex::Real alpha_T
Kinematic temperature diffusivity [m2/s].
Definition: ERF_DiffStruct.H:100
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool implicit_q(int n) const noexcept
Definition: ERF_DiffStruct.H:129
amrex::Real rhoAlpha_C
Dynamic scalar diffusion coefficient [kg/(m-s)].
Definition: ERF_DiffStruct.H:108