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