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