Skip to content

Announcement Release3.2.0

Thomas Kittelmann edited this page May 14, 2023 · 6 revisions

NCrystal v3.2.0 : Easy gas mixtures!

Although NCrystal supports a free-gas model for neutron scattering, it has until now not really been convenient to set up complicated multi-component gas mixtures in NCrystal: users would have to perform tedious calculations of final atomic compositions and densities themselves, taking into account issues such as temperature, pressure, molar/mass-fractions of constituent molecules.

The NCrystal v3.2.0 release makes this a lot easier, allowing the user to simply decribe a gas mixture in the cfg-string. Based on the ideal gas model and Dalton's law of partial pressures (for multi-component gasses), NCrystal will then calculate resulting density and atomic composition and set up a material accordingly.

The following cfg-string examples with comments should hopefully make it obvious how to use these new features. But note that unless massfractions are explicitly requested, by-molar (same as by-volume) fractions are assumed:

  • "gasmix::CO2" : Single component CO₂ gas at P=1atm and T=20℃.
  • "gasmix::He/10bar" : single component CO₂ gas at P=10bar and T=20℃.
  • "gasmix::0.7xCO2+0.3xAr/1.5atm/250K" : 70-30 CO₂-Ar mix by molecular molar fractions (at P=1.5atm, T=250K). Notice that for technical reasons * is not allowed in such strings, so a lower-case x is used as multiplication symbol in components like 0.7xCO2. Also note that under the ideal gas model, molar fractions and volume fractions are the same thing.
  • "gasmix::0.72xCO2+0.28xAr/massfractions/1.5atm/250K" : similar mix specified with molecular mass fractions
  • "gasmix::0.7xCO2+0.3xAr/0.001relhumidity" : 70-30 CO₂-Ar mix with 0.1% relative humidity (at P=1atm, T=20℃). The specification of relative humidity results in an H₂O component being added to the mix, where water's saturated vapour pressure curve is internally based on formulas from doi:10.1175/JAMC-D-17-0334.1 which should at the very least be precise for -100℃-200℃.
  • "gasmix::BF3/2atm/25C/B_is_0.95_B10_0.05_B11" : Enriched BF3 gas (at P=1atm, T=25℃). The syntax of the enrichment follows the usual format of the @ATOMDB section in NCMAT data (for details see NCMAT-format), but using underscores to delimit words.
  • "gasmix::air" : shorthand for air (at P=1atm, T=20℃). This is approximately ~78.1% N₂, ~20.9% O₂, and ~0.9%Ar, but the smaller contributions from CO₂, Ne, He, CH₄, Kr, H₂, and Xe are also accounted for.
  • "gasmix::air/-10C/0.8atm/0.30relhumidity" : air with 30% relative humidity (at P=-0.8atm, T=-10℃)

At present, the physics of the resulting material is simply modelled as a free gas of individual atoms, although it is not inconceivable that this could be further improved in the future.

At a technical level, the above features are implemented as an NCrystal TextData factory. In other words, a small dedicated plugin named gasmix parses and analyses the request and produces corresponding NCMAT data which is then passed on to the rest of NCrystal. To see the intermediate NCMAT data, you can print it in Python like print(NC.createTextData("gasmix:CO2").rawData), or you can use the --extract flag of ncrystal_inspectfile:

$> ncrystal_inspectfile --extract "gasmix::0.35xAr+0.5xCO2+0.15xCF4/2bar"
NCMAT v7
#
# Automatically generated NCMAT data for gas mixture
#
# Request: "gasmix::0.35xAr+0.5xCO2+0.15xCF4/2bar"
#
# Resulting gas parameters:
#
#  T   = 293.15K
#  P   = 200000Pa
#  Rho = 4.03606kg/m^3
#
@STATEOFMATTER
  gas
@TEMPERATURE
  293.15
@DENSITY
  4.0360638605686088 kg_per_m3
@DYNINFO
  element  Ar
  fraction 0.13461538461538458
  type     freegas
@DYNINFO
  element  F
  fraction 0.23076923076923073
  type     freegas
@DYNINFO
  element  C
  fraction 1/4
  type     freegas
@DYNINFO
  element  O
  fraction 0.38461538461538458
  type     freegas

A word of caution: As can be seen above, a new optional NCMAT section, @TEMPERATURE, has been introduced in this release (along with a new format version number, v7, see NCMAT-format for details). This new section is used to prevent users from making the easy mistake of overriding the temperature via the temp cfg-string parameter. I.e. a user might think that "gasmix::CO2/2bar/200K" and "gasmix::CO2/2bar;temp=200K" would mean the same thing. However, in the second case the material density for the produced NCMAT data is first calculated under the ideal gas model assuming P=2bar and T=293.15K, and subsequently the NCMAT data is loaded with T=200K. This is clearly inconsistent, and therefore the NCMAT data is in this case using the new @TEMPERATURE section to pin the temperature value at the initial 293.15K. Accordingly "gasmix::CO2/2bar;temp=200K" will lead to an error, rather than a silent wrong result. It should be noted that this protection only concerns the (very widely used) temp parameter and users might still be able to shoot themselves in the foot by using the atomdb or density cfg-string parameters. A fundamental solution to this issue would require extending the NCMAT format to directly support the notion of molecules and gas mixtures, which might certainly happen at some point in the future.