eagles-project / mam4xx

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

Reconcile Units With Calculations in gas_chem.hpp #232

Open mjs271 opened 1 year ago

mjs271 commented 1 year ago

There are several places in gas_chem.hpp and gas_chem_mechanism.hpp that appear to have inconsistent units (e.g., additions of 2 quantities with differing units). This is based on comments specifying the following units for arrays containing chemical species qoi and reaction rates (paraphrased):

solution := species volume mixing ratio [kmol species/kmol dry air]
rxt := reaction rates in 1D array [1/cm^3/s]
het_rates := washout rates [1/s]

It's entirely possible, if not likely, that the calculations are correct and only comments need to be updated, but we do need to investigate and reconcile this. Additionally, I would argue in favor of separating different physical quantities into separate arrays for the sake of clarity.

Related to #229.

@odiazib @brigaudet @singhbalwinder @jeff-cohere

pbosler commented 1 year ago

It might be worth considering variable names that have units, e.g., rx_rates_per_cc_per_s, washout_rates_per_s.

brigaudet commented 1 year ago

Just to follow up on this some -- I went through the Fortran version of the code more carefully (specifically subroutine gas_phase_chemdr, variable reaction_rates), tracking down the origin of the relevant equations. I found the following: 1) at least all of the chemical reaction elements of this array seem to have the same units with each other at any given time; 2) however, the units of all these elements do change multiple times over the coarse of this subroutine. Specifically, they start off (after the call to setrxt) as cm^3 / (molecule -- s) (i.e., like a reaction rate constant for a second-order reaction), but after the call to adjrxt they become s^{-1}; then during the call to rate_diags_calc they become molecules / (cm^3 - s).

mjs271 commented 1 year ago

Thank you for looking into this, Brian! That certainly provides some peace of mind.

And, based on this, it appears that the arrays carrying quantities and rates likely contain entries with heterogeneous units. As such, this should be looked into after porting is complete/validated and we can modify/improve the code.

edit: follow-up thoughts