Source code for pycif.plugins.chemistries.chimere.make_chemistry

import os

from ....utils.path import init_dir
from .utils import create_mandchem, create_optchem, make_inout_react_graph


[docs] def create_chemicalscheme(self): """Generate CHIMERE chemical-scheme files from the YAML configuration. Counts all species categories (active, emitted, prescribed, …) and delegates to :func:`~pycif.plugins.chemistries.chimere.utils.create_mandchem` and :func:`~pycif.plugins.chemistries.chimere.utils.create_optchem` to write the full set of CHIMERE scheme files: * ``REACTIONS`` / ``CHEMISTRY`` / ``STOICHIOMETRY`` / ``REACTION_RATES`` * ``ACTIVE_SPECIES`` / ``ALL_SPECIES`` / ``OUTPUT_SPECIES`` * ``ANTHROPIC`` / ``BIOGENIC`` / ``DEPO_SPEC`` * ``PHOTO_PARAMETERS`` / ``PHOTO_RATES`` / ``FAMILIES`` * ``chemical_scheme.nml`` — Fortran namelist consumed by LMDZ executables. Also builds ``inout_reaction_graph`` via :func:`~pycif.plugins.chemistries.chimere.utils.make_inout_react_graph`. Args: self: CHIMERE 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 (for LMDZ) 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_SPEC.{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) # MAKE GRAPH OF PRODUCTS AND REACTIVE SPECIES self.inout_reaction_graph = make_inout_react_graph( f"{dirchem_ref}/CHEMISTRY.{self.schemeid}") # 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}')