eagles-project / mam4xx

A C++ implementation of MAM4
https://eagles-project.github.io/mam4xx/
Other
7 stars 6 forks source link

Issue with units in vmr <-> mmr conversion calculations #152

Open mjs271 opened 1 year ago

mjs271 commented 1 year ago

It appears we are off by a factor of 1000 in our volume mixing ratio $\leftrightarrow$ mass mixing ratio conversion.

In mam4xx/conversions.hpp the units are all kilo- and appear to line up properly:

/// Given a molar mixing ratio (vmr) for a species or mixture
/// [kmol species/kmol dry air], computes and returns a mass mixing ratio
/// [kg species/kg dry air] based on its molecular weight.
/// @param [in] vmr The molar mixing ratio of the species/mixture [kmol/kmol
/// air]
/// @param [in] molecular_wt The molecular weight of the species/mixture
/// [kg/kmol]
KOKKOS_INLINE_FUNCTION Real mmr_from_vmr(Real vmr, Real molecular_wt) {
  const auto mw_dry_air = Constants::molec_weight_dry_air;
  return vmr * molecular_wt / mw_dry_air;
}

/// Given a mass mixing ratio (mmr) for a species or mixture [kg species/kg
/// dry air], computes and returns a molar mixing ratio [kmol species/k dry air]
/// based on its molecular weight.
/// @param [in] mmr The mass mixing ratio of the species/mixture [kg/kg dry air]
/// @param [in] molecular_wt The molecular weight of the species/mixture
/// [kg/kmol]
KOKKOS_INLINE_FUNCTION Real vmr_from_mmr(Real mmr, Real molecular_wt) {
  const auto mw_dry_air = Constants::molec_weight_dry_air;
  return mmr * mw_dry_air / molecular_wt;
}

However the value of Constants::molec_weight_dry_air from haero/constants.hpp has units of kg/mol, which lines up with what I found with a google (28.96 g/mol == 0.02896 kg/mol). However, this is not in line with what is shown in conversions.hpp.

/// Molecular weight of dry air [kg/mol]
static constexpr Real molec_weight_dry_air = 0.028966;

So, a couple questions:

@pressel @jeff-cohere @pbosler @odiazib

pbosler commented 1 year ago
  1. We prefer SI units.
  2. Keep the constant in haero in SI units, and write a conversion factor into the process where a different unit is required, like this:
constexpr Real mol_to_kmol = 1e-3;
auto my_val = mol_to_kmol * constant_with_si_units;
mjs271 commented 1 year ago

Ok, so... I've down some follow-up digging on this and the related issue #157, as well as the comments in PR #155. My goals were:

  1. Nail down the definition for a mixing ratio.
  2. Determine the proper SI units for "molecular weight".
  3. Write it down here as a reference and to solicit the input of others.

Mixing Ratio

In the comments in response to the cancelled PR #155, there was a lack of agreement as to the units associated with mixing ratios. So, I did a (very much non-exhaustive) lit search of googling around and looking into any books on my shelf that are atmoshperic-ish, and found the following. If anyone can provide better answers from better references, I'd welcome them.

Questions

As this is far from a comprehensive lit search, and largely based on gaseous quantities, rather than aerosols, I think these are the questions to be answered:

  1. What are the proper units for mixing ratios?
    • As far as MAM4xx is concerned, it appears that our current usage of the quantities referred to as mass and volume (molar) "mixing ratios" is correct, in that they are ratios of species to dry air, with the same units employed for the species (numerator) as for dry air (denominator).
    • Note that number mixing ratio is the odd one out, with dimension number of molecules / kg dry air.

Molecular Weight

Questions

  1. Do we embrace the kg/kmol units, as that seems to be the preference within MAM4?
    • Danger: There's a chance this could be as simple as changing the values and units of molecular weights in /haero/constants.hpp, but there's a nonzero chance that this could cause issues in already-ported code.
      • e.g., If a haero-sourced molecular weight is used in MAM4xx, and the author of the code, knowing this to be given in kg/mol converted to kg/kmol for use within the code.
    • Also, from what I can gather, it appears that usages of Avogadro's number within MAM4xx employ the correspondingly correct units. However, Haero's $N_A$ is given in units of number/mol, so any usages of that quantity would need to be revisited if we enforce kg/kmol throughout.
  2. How much does the molar/molecular and mass/weight syntactical distinction matter to us?
    • i.e., Do we keep the term molecular weight in MAM4xx?
    • It appears that we are always actually using the proper molar mass (up to chosen units 🙃 ) in MAM4xx, so this is likely only a syntax difference and should not affect the validity of the science/code.
  3. Do we make note of this convention/distinction anywhere other than here and within source code?
    • The Haero docs include kmol units quite frequently, though I haven't looked too closely.

Kilomoles

Units Computations for Issue.pdf

mjs271 commented 1 year ago

@odiazib @pressel @jeff-cohere @pbosler @singhbalwinder

jeff-cohere commented 1 year ago

Thanks for the rundown, @mjs271 !

Here are my thoughts regarding the molecular weight:

  1. Do we embrace the kg/kmol units, as that seems to be the preference within MAM4?
  2. How much does the molar/molecular and mass/weight syntactical distinction matter to us? i.e., Do we keep the term molecular weight in MAM4xx?

I think we should continue using "molecular weight," since that's what MAM4 uses, and I feel like we should try to keep things the same until we can get some expert opinions on switching terminology (e.g. to "molar mass"). And if we're using molecular weight, we should change Haero's molecular weights so that they are in SI units [kg/kmol]. If this breaks things, we can fix them in the same PR in which we make the change. Mike, you don't have to do this if you don't want to, but we should do this soon if everyone agrees this is the best approach.

  1. Do we make note of this convention/distinction anywhere other than here and within source code?

The above approach lets us adhere to SI units, which I believe we do say we do in the documentation. We should document the molecular weight units in the constants file where they're declared, at the very least, though.

What do others think?

odiazib commented 1 year ago

I agree with @jeff-cohere. Let's use "molecular weight" with units of kg/kmol.

singhbalwinder commented 1 year ago

Thanks @mjs271 for the well-written summary! I haven't looked at the parts of the MAM4xx code that deals with converting kg/mol to kg/kmol. Are there many places where we do this conversion?

mjs271 commented 1 year ago

It looks like rename.hpp is the only one currently using one of the functions in question. And I believe rename uses internally defined molecular weights, so I'd say the chances of a units conflict with Constants::molec_weight_dry_air is somewhere between possible and probable, though I haven't verified it yet. As well, I haven't looked hard enough to see if any of these types of conversion done within processes without the use of the conversion functions, though. Will certainly look into all of this subsequently, though, assuming everyone's on board with molecular weight := kg/kmol.

singhbalwinder commented 1 year ago

Thanks! Yes, let's use kg/kmol for the molecular weights.