Source code for pycif.plugins.chemistries.TM5.make_chemistry
import os
from ....utils.path import init_dir
from .utils import create_mandchem, create_optchem
[docs]
def create_chemicalscheme(self):
"""Generate TM5 chemical-scheme files from the YAML configuration.
Functionally identical to the CHIMERE ``create_chemicalscheme`` but
uses ``DEPO_SPECIES`` instead of ``DEPO_SPEC`` for the deposition file.
Calls :func:`~pycif.plugins.chemistries.TM5.utils.create_mandchem` and
:func:`~pycif.plugins.chemistries.TM5.utils.create_optchem` to write:
* ``REACTIONS`` / ``CHEMISTRY`` / ``STOICHIOMETRY`` / ``REACTION_RATES``
* ``ACTIVE_SPECIES`` / ``ALL_SPECIES`` / ``ANTHROPIC`` / ``BIOGENIC``
* ``PHOTO_RATES`` / ``FAMILIES``
* ``chemical_scheme.nml``
Args:
self: TM5 chemistry plugin instance with all species lists and
``schemeid`` / ``dirchem_ref`` set.
"""
# Common variables
workdir = self.workdir
mecachim = self.schemeid
dirchem_ref = self.dirchem_ref
# Initializes number of species and reactions
self.nacspecies = (
len(self.acspecies.attributes) if hasattr(self, "acspecies") else 0
)
self.nemisspec = (
len(self.emis_species.attributes)
if hasattr(self, "emis_species")
else 0
)
self.nemisspec_interp = (
len(self.emis_species_interp.attributes)
if hasattr(self, "emis_species_interp")
else 0
)
self.nprspecies = (
len(self.prescrconcs.attributes) if hasattr(self, "prescrconcs") else 0
)
self.nprodspecies = (
len(self.prodloss3d.attributes) if hasattr(self, "prodloss3d") else 0
)
self.ndepspecies = (
len(self.deposition.attributes) if hasattr(self, "deposition") else 0
)
self.nreacs = (
len(self.reactions.attributes) if hasattr(self, "reactions") else 0
)
self.nfamilies = (
len(self.families.attributes) if hasattr(self, "families") else 0
)
# Cleaning the target directory
os.system(f"rm -rf {dirchem_ref}")
init_dir(dirchem_ref)
# List of files
finf = f"{dirchem_ref}/chemical_scheme.nml"
filer = f"{dirchem_ref}/REACTIONS.{mecachim}"
fileps = f"{dirchem_ref}/PRESCRIBED_SPECIES.{mecachim}"
filepl = f"{dirchem_ref}/PRODLOSS_SPECIES.{mecachim}"
filedp = f"{dirchem_ref}/DEPO_SPECIES.{mecachim}"
filea = f"{dirchem_ref}/ANTHROPIC.{mecachim}"
fileb = f"{dirchem_ref}/BIOGENIC.{mecachim}"
mandatory_files = [filer, fileps, filepl, filedp]
create_mandchem(self, mandatory_files)
files = f"{dirchem_ref}/STOICHIOMETRY.{mecachim}"
filec = f"{dirchem_ref}/CHEMISTRY.{mecachim}"
filerr = f"{dirchem_ref}/REACTION_RATES.{mecachim}"
filej = f"{dirchem_ref}/PHOTO_RATES.{mecachim}"
filef = f"{dirchem_ref}/FAMILIES.{mecachim}"
fileals = f"{dirchem_ref}/ALL_SPECIES.{mecachim}"
fileas = f"{dirchem_ref}/ACTIVE_SPECIES.{mecachim}"
nallqmax, nphoto_rates = create_optchem(self, filer, fileps)
# Create chemical_scheme.nml namelist
os.system(f'echo "&args" > {finf}')
os.system(f"echo \"fnacspec = '{fileas}'\" >> {finf}")
os.system(f"echo \"fnallspec = '{fileals}'\" >> {finf}")
os.system(f"echo \"fnprescr = '{fileps}'\" >> {finf}")
os.system(f"echo \"fnprodl = '{filepl}'\" >> {finf}")
os.system(f"echo \"fndep = '{filedp}'\" >> {finf}")
os.system(f"echo \"fnchem = '{filec}'\" >> {finf}")
os.system(f"echo \"fnstoi = '{files}'\" >> {finf}")
os.system(f"echo \"fnrates = '{filerr}'\" >> {finf}")
os.system(f"echo \"fnjrates = '{filej}'\" >> {finf}")
os.system(f"echo \"fnfamilies = '{filef}'\" >> {finf}")
os.system(f'echo "iqmax = {self.nspecies}" >> {finf}')
os.system(f'echo "iallqmax = {nallqmax}" >> {finf}')
os.system(f'echo "iprescrmax = {self.nprspecies}" >> {finf}')
os.system(f'echo "iprodmax = {self.nprodspecies}" >> {finf}')
os.system(f'echo "idepmax = {self.ndepspecies}" >> {finf}')
os.system(f'echo "nreac = {self.nreacs}" >> {finf}')
os.system(f'echo "ijratesmax = {nphoto_rates}" >> {finf}')
os.system(f'echo "/" >> {finf}')