ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_MaterialProperties.H
Go to the documentation of this file.
1 #ifndef MATERIALPROPERTIES_H
2 #define MATERIALPROPERTIES_H
3 
4 #include <AMReX_Enum.H>
5 #include <AMReX_REAL.H>
6 #include <AMReX_Gpu.H>
7 #include <AMReX_MultiFab.H>
8 #include "ERF_Constants.H"
9 
10 /*! Materials */
11 namespace Species
12 {
13  AMREX_ENUM(Name,
14  H2O,
15  NaCl,
16  NH42SO4,
17  NH4HSO4,
18  soil,
19  water, // same as H2O, to test multispecies SDM
20  agua, // same as H2O, to test multispecies SDM
21  none
22  );
23 }
24 
25 /*! Functions for computing saturation pressure and vapour fraction */
26 namespace saturation_funcs
27 {
28  /*! \brief Null function for saturation pressure */
29  AMREX_GPU_HOST
30  void compute_saturation_pressure_null ( amrex::MultiFab&, const amrex::MultiFab& );
31  /*! \brief Compute saturation pressure for moist air */
32  AMREX_GPU_HOST
33  void compute_saturation_pressure_H2O ( amrex::MultiFab&, const amrex::MultiFab& );
34 
35  /*! \brief Null function for saturation vapour fraction */
36  AMREX_GPU_HOST
37  void compute_saturation_vapfrac_null ( amrex::MultiFab&,
38  const amrex::MultiFab&,
39  const amrex::MultiFab& );
40  /*! \brief Compute saturation vapour fraction for moist air */
41  AMREX_GPU_HOST
42  void compute_saturation_vapfrac_H2O ( amrex::MultiFab&,
43  const amrex::MultiFab&,
44  const amrex::MultiFab& );
45 }
46 
47 struct MaterialPropertiesCore { // For GPU
48 
49  static constexpr amrex::Real s_N_av = amrex::Real(6.02214076e23); /*!< Avogadro's number */
50  static constexpr amrex::Real s_kb = amrex::Real(1.380649e-23); /*!< Boltzmann constant [J K^{-1}] */
51 
52  /*! Molecular weight of air [kg mol^{-1}] */
53  static constexpr amrex::Real s_mol_weight_air = amrex::Real(0.0289647);
54  /*! Molecular length scale of air [m] */
55  static constexpr amrex::Real s_sigma_air = amrex::Real(3.62e-10);
56  /*! Temperature parameter for air [K] */
57  static constexpr amrex::Real s_eps_air_k = 97;
58 
59 #ifdef AMREX_USE_FLOAT
60  amrex::Real m_density = std::numeric_limits<float>::max(); /*!< density */
61  amrex::Real m_ionization = std::numeric_limits<float>::max(); /*!< ionization */
62  amrex::Real m_mol_weight = std::numeric_limits<float>::max(); /*!< molecular weight (condensate) */
63  amrex::Real m_lat_vap = std::numeric_limits<float>::max(); /*!< latent heat of vaporization */
64  amrex::Real m_Rv = std::numeric_limits<float>::max(); /*!< gas constant for vapour of this material */
65  amrex::Real m_Tc = std::numeric_limits<float>::max(); /*!< critical temperature for surface tension */
66  amrex::Real m_Tb = std::numeric_limits<float>::max(); /*!< boiling temperature */
67  amrex::Real m_Nav_by_molweight = std::numeric_limits<float>::max(); /*!< Avogadro number by vapour mol. weight */
68 #else
69  amrex::Real m_density = std::numeric_limits<double>::max(); /*!< density */
70  amrex::Real m_ionization = std::numeric_limits<double>::max(); /*!< ionization */
71  amrex::Real m_mol_weight = std::numeric_limits<double>::max(); /*!< molecular weight (condensate) */
72  amrex::Real m_lat_vap = std::numeric_limits<double>::max(); /*!< latent heat of vaporization */
73  amrex::Real m_Rv = std::numeric_limits<double>::max(); /*!< gas constant for vapour of this material */
74  amrex::Real m_Tc = std::numeric_limits<double>::max(); /*!< critical temperature for surface tension */
75  amrex::Real m_Tb = std::numeric_limits<double>::max(); /*!< boiling temperature */
76  amrex::Real m_Nav_by_molweight = std::numeric_limits<float>::max(); /*!< Avogadro number by vapour mol. weight */
77 #endif
78  /*! vector of molar heat capacity polynomial coeffs */
80  amrex::Real(DBL_MAX),
81  amrex::Real(DBL_MAX),
82  amrex::Real(DBL_MAX),
83  amrex::Real(DBL_MAX),
84  amrex::Real(DBL_MAX),
85  amrex::Real(DBL_MAX) };
86  bool m_is_soluble = false; /*!< is soluble in water? */
87  bool m_is_water = false; /*!< is this water? */
88 
89  /*! \brief Return the molar heat capacity */
90  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
92  {
93  auto retval = zero;
94  auto term = one;
95  for (auto i = 0; i < 7; i++) {
96  retval += (m_mol_Cp_coeffs[i] * term);
97  term *= a_T;
98  }
99  return retval;
100  }
101 
102  /*! \brief Compute the surface tension coeff given temperature */
103  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
105  {
106  if (m_is_water) {
107  return amrex::Real(0.076148325); // N m^{-1}
108  } else {
109  auto term1 = amrex::Real(6.0) * std::cbrt(s_N_av);
110  auto term2 = std::cbrt((m_density/m_mol_weight)*(m_density/m_mol_weight));
111  auto retval = molarHeatCapacity(a_T)*(term2/term1)*(m_Tc - a_T);
112  return retval;
113  }
114  }
115 
116  /*! \brief Return the coeff of curvature given the temperature */
117  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
118  amrex::Real coeffCurv( const amrex::Real a_T ) const
119  {
120  auto surf_tens = surfaceTension(a_T);
121  auto retval = 2 * surf_tens / (m_Rv * m_density);
122  return retval;
123  }
124 
125  /*! \brief Return the vapour pressure coefficient */
126  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
128  {
129  auto retval = (amrex::Real(0.75)/PI)*(m_mol_weight/m_density);
130  if (m_is_water) {
131  retval = amrex::Real(4.3e-06);
132  }
133  return retval;
134  }
135 
136  /*! \brief Return the molecular diffusion coefficient given temperature and pressure */
137  AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
139  {
140  if (m_is_water) {
141 
142  return diffelq; // from ERF_Constants.H (amrex::Real(2.21e-05) [m^2 s^{-1}])
143 
144  } else {
145 
146  auto mol_weight_v = s_N_av/m_Nav_by_molweight;
147  auto sigma = amrex::Real(1.18e-8) * std::cbrt(mol_weight_v/m_density);
148  auto sigma_v_air = myhalf * (sigma + s_sigma_air);
149 
150  auto eps_v = amrex::Real(1.15) * m_Tb * s_kb;
151  auto eps_v_air = std::sqrt( eps_v * s_eps_air_k * s_kb);
152  auto T_star = a_T / (eps_v_air/s_kb);
153 
154  auto omegaD = amrex::Real(1.06036) / std::pow(T_star, amrex::Real(0.1561))
155  + amrex::Real(0.193) / std::exp(amrex::Real(0.47635)*T_star)
156  + amrex::Real(1.03587) / std::exp(amrex::Real(1.52996)*T_star)
157  + amrex::Real(1.76474) / std::exp(amrex::Real(3.89411)*T_star);
158 
159  auto term1 = 3 * std::sqrt( s_kb*a_T * s_kb*a_T * s_kb*a_T);
160  auto term2 = amrex::Real(8.0) * std::sqrt(2*PI) * a_P * sigma_v_air*sigma_v_air * omegaD;
161  auto term3 = std::sqrt( m_Nav_by_molweight + s_N_av/s_mol_weight_air );
162 
163  auto retval = term1*term3/term2;
164  return retval;
165  }
166  }
167 
168 };
169 
170 /*! Class for material properties */
172 
173  Species::Name m_name = Species::Name::none; /*!< name */
174 
175  /*! pointer to function to compute saturation pressure */
177  /*! pointer to function to compute vapour fraction */
179 
180  /*! \brief Constructor */
181  AMREX_GPU_HOST_DEVICE
182  MaterialProperties ( const Species::Name& a_name );
183 
184  /*! \brief Copy constructor */
185  AMREX_GPU_HOST_DEVICE
186  MaterialProperties ( const MaterialProperties& a_matprop );
187 
188  /*! \brief Default destructor */
189  AMREX_GPU_HOST_DEVICE
190  ~MaterialProperties () = default;
191 
192  /*! \brief Print parameters */
193  AMREX_GPU_HOST
194  void print() const {
195  amrex::Print() << "Material properties of " << amrex::getEnumNameString(m_name) << ":\n";
196  amrex::Print() << " density: " << m_density << "\n";
197  amrex::Print() << " ionization: " << m_ionization << "\n";
198  amrex::Print() << " mol. weight: " << m_mol_weight << "\n";
199  amrex::Print() << " latent heat (vap.): " << m_lat_vap << "\n";
200  amrex::Print() << " Rv: " << m_Rv << "\n";
201  amrex::Print() << " Tc: " << m_Tc << "\n";
202  amrex::Print() << " Tb: " << m_Tb << "\n";
203  amrex::Print() << " N_av/mol.weight: " << m_Nav_by_molweight << "\n";
204  amrex::Print() << " mol. Cp coeffs: ";
205  for (int i = 0; i < 7; i++) { amrex::Print() << m_mol_Cp_coeffs[i] << ", "; }
206  amrex::Print() << "\n";
207  }
208 
209  /*! \brief Set this material to H20 */
210  AMREX_GPU_HOST_DEVICE
211  void setProperties_H2O();
212  /*! \brief Set this material to water */
213  AMREX_GPU_HOST_DEVICE
214  void setProperties_water();
215  /*! \brief Set this material to agua */
216  AMREX_GPU_HOST_DEVICE
217  void setProperties_agua();
218  /*! \brief Set this material to NaCl */
219  AMREX_GPU_HOST_DEVICE
220  void setProperties_NaCl();
221  /*! \brief Set this material to ammonium sulfate */
222  AMREX_GPU_HOST_DEVICE
223  void setProperties_NH42SO4();
224  /*! \brief Set this material to ammonium bisulfate */
225  AMREX_GPU_HOST_DEVICE
226  void setProperties_NH4HSO4();
227  /*! \brief Set this material to soil */
228  AMREX_GPU_HOST_DEVICE
229  void setProperties_soil();
230 
231  /*! \brief Compute saturation pressure */
232  AMREX_GPU_HOST AMREX_FORCE_INLINE
233  void computeSaturationPressure ( amrex::MultiFab& a_e, const amrex::MultiFab& a_T) const
234  {
235  m_saturation_pressure_func(a_e, a_T);
236  }
237 
238  /*! \brief Compute saturation vapour fraction */
239  AMREX_GPU_HOST AMREX_FORCE_INLINE
240  void computeSaturationVapFrac ( amrex::MultiFab& a_S,
241  const amrex::MultiFab& a_T,
242  const amrex::MultiFab& a_p ) const
243  {
244  m_saturation_vapfrac_func(a_S, a_T, a_p);
245  }
246 };
247 
248 #endif
constexpr amrex::Real one
Definition: ERF_Constants.H:7
constexpr amrex::Real diffelq
Definition: ERF_Constants.H:84
constexpr amrex::Real zero
Definition: ERF_Constants.H:6
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:11
constexpr amrex::Real PI
Definition: ERF_Constants.H:16
amrex::Real sigma
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:11
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_MaterialProperties.H:12
AMREX_ENUM(Name, H2O, NaCl, NH42SO4, NH4HSO4, soil, water, agua, none)
Definition: ERF_MaterialProperties.cpp:7
AMREX_GPU_HOST void compute_saturation_pressure_null(MultiFab &, const MultiFab &)
Definition: ERF_MaterialProperties.cpp:9
AMREX_GPU_HOST void compute_saturation_vapfrac_H2O(MultiFab &a_mf_sat_vapfrac, const MultiFab &a_mf_temperature, const MultiFab &a_mf_pressure)
Definition: ERF_MaterialProperties.cpp:32
AMREX_GPU_HOST void compute_saturation_vapfrac_null(MultiFab &, const MultiFab &)
Definition: ERF_MaterialProperties.cpp:29
AMREX_GPU_HOST void compute_saturation_pressure_H2O(MultiFab &a_mf_sat_pressure, const MultiFab &a_mf_temperature)
Definition: ERF_MaterialProperties.cpp:12
Definition: ERF_MaterialProperties.H:47
amrex::Real m_mol_weight
Definition: ERF_MaterialProperties.H:71
bool m_is_water
Definition: ERF_MaterialProperties.H:87
static constexpr amrex::Real s_sigma_air
Definition: ERF_MaterialProperties.H:55
amrex::Real m_mol_Cp_coeffs[7]
Definition: ERF_MaterialProperties.H:79
static constexpr amrex::Real s_mol_weight_air
Definition: ERF_MaterialProperties.H:53
static constexpr amrex::Real s_kb
Definition: ERF_MaterialProperties.H:50
amrex::Real m_Rv
Definition: ERF_MaterialProperties.H:73
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real molarHeatCapacity(const amrex::Real a_T) const
Return the molar heat capacity.
Definition: ERF_MaterialProperties.H:91
static constexpr amrex::Real s_eps_air_k
Definition: ERF_MaterialProperties.H:57
amrex::Real m_Nav_by_molweight
Definition: ERF_MaterialProperties.H:76
amrex::Real m_ionization
Definition: ERF_MaterialProperties.H:70
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real coeffCurv(const amrex::Real a_T) const
Return the coeff of curvature given the temperature.
Definition: ERF_MaterialProperties.H:118
amrex::Real m_Tb
Definition: ERF_MaterialProperties.H:75
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real coeffMolecularDiffusion(const amrex::Real a_T, const amrex::Real a_P) const
Return the molecular diffusion coefficient given temperature and pressure.
Definition: ERF_MaterialProperties.H:138
amrex::Real m_density
Definition: ERF_MaterialProperties.H:69
bool m_is_soluble
Definition: ERF_MaterialProperties.H:86
static constexpr amrex::Real s_N_av
Definition: ERF_MaterialProperties.H:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real coeffVPSolute() const
Return the vapour pressure coefficient.
Definition: ERF_MaterialProperties.H:127
amrex::Real m_lat_vap
Definition: ERF_MaterialProperties.H:72
amrex::Real m_Tc
Definition: ERF_MaterialProperties.H:74
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real surfaceTension(const amrex::Real a_T) const
Compute the surface tension coeff given temperature.
Definition: ERF_MaterialProperties.H:104
Definition: ERF_MaterialProperties.H:171
AMREX_GPU_HOST_DEVICE ~MaterialProperties()=default
Default destructor.
AMREX_GPU_HOST_DEVICE void setProperties_water()
Set this material to water.
Definition: ERF_MaterialProperties.cpp:122
AMREX_GPU_HOST AMREX_FORCE_INLINE void computeSaturationVapFrac(amrex::MultiFab &a_S, const amrex::MultiFab &a_T, const amrex::MultiFab &a_p) const
Compute saturation vapour fraction.
Definition: ERF_MaterialProperties.H:240
decltype(saturation_funcs::compute_saturation_pressure_null) * m_saturation_pressure_func
Definition: ERF_MaterialProperties.H:176
AMREX_GPU_HOST AMREX_FORCE_INLINE void computeSaturationPressure(amrex::MultiFab &a_e, const amrex::MultiFab &a_T) const
Compute saturation pressure.
Definition: ERF_MaterialProperties.H:233
AMREX_GPU_HOST_DEVICE void setProperties_NH4HSO4()
Set this material to ammonium bisulfate.
Definition: ERF_MaterialProperties.cpp:158
AMREX_GPU_HOST_DEVICE void setProperties_soil()
Set this material to soil.
Definition: ERF_MaterialProperties.cpp:170
AMREX_GPU_HOST_DEVICE void setProperties_NH42SO4()
Set this material to ammonium sulfate.
Definition: ERF_MaterialProperties.cpp:146
AMREX_GPU_HOST_DEVICE MaterialProperties(const Species::Name &a_name)
Constructor.
Definition: ERF_MaterialProperties.cpp:56
AMREX_GPU_HOST void print() const
Print parameters.
Definition: ERF_MaterialProperties.H:194
AMREX_GPU_HOST_DEVICE void setProperties_NaCl()
Set this material to NaCl.
Definition: ERF_MaterialProperties.cpp:134
AMREX_GPU_HOST_DEVICE void setProperties_H2O()
Set this material to H20.
Definition: ERF_MaterialProperties.cpp:102
AMREX_GPU_HOST_DEVICE void setProperties_agua()
Set this material to agua.
Definition: ERF_MaterialProperties.cpp:128
Species::Name m_name
Definition: ERF_MaterialProperties.H:173
decltype(saturation_funcs::compute_saturation_vapfrac_null) * m_saturation_vapfrac_func
Definition: ERF_MaterialProperties.H:178