make_chemistry.py 3.77 KB
Newer Older
1
import os
Antoine Berchet's avatar
Antoine Berchet committed
2

3
from ....utils.path import init_dir
Antoine Berchet's avatar
Antoine Berchet committed
4
from .utils import create_mandchem, create_optchem
5
6
7
8
9
10
11
12


def create_chemicalscheme(self):
    """
    Read the mandatory chemistry files, create the optional ones and set the
    species attributes
    consistently with the data retrieved
    """
Antoine Berchet's avatar
Antoine Berchet committed
13

14
15
16
17
    # Common variables
    workdir = self.workdir
    mecachim = self.schemeid
    dirchem_ref = self.dirchem_ref
Antoine Berchet's avatar
Antoine Berchet committed
18

19
    # Initializes number of species and reactions
Antoine Berchet's avatar
Antoine Berchet committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    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
    )

49
    # Cleaning the target directory
Antoine Berchet's avatar
Antoine Berchet committed
50
    os.system("rm -rf  {}".format(dirchem_ref))
51
    init_dir(dirchem_ref)
Antoine Berchet's avatar
Antoine Berchet committed
52

53
    # List of files
Antoine Berchet's avatar
Antoine Berchet committed
54
55
56
57
58
59
60
61
    finf = "{}/chemical_scheme.nml".format(dirchem_ref)
    filer = "{}/REACTIONS.{}".format(dirchem_ref, mecachim)
    fileps = "{}/PRESCRIBED_SPECIES.{}".format(dirchem_ref, mecachim)
    filepl = "{}/PRODLOSS_SPECIES.{}".format(dirchem_ref, mecachim)
    filedp = "{}/DEPO_SPECIES.{}".format(dirchem_ref, mecachim)
    filea = "{}/ANTHROPIC.{}".format(dirchem_ref, mecachim)
    fileb = "{}/BIOGENIC.{}".format(dirchem_ref, mecachim)

62
    mandatory_files = [filer, fileps, filepl, filedp]
63
    create_mandchem(self, mandatory_files)
Antoine Berchet's avatar
Antoine Berchet committed
64
65
66
67
68
69
70
71

    files = "{}/STOICHIOMETRY.{}".format(dirchem_ref, mecachim)
    filec = "{}/CHEMISTRY.{}".format(dirchem_ref, mecachim)
    filerr = "{}/REACTION_RATES.{}".format(dirchem_ref, mecachim)
    filej = "{}/PHOTO_RATES.{}".format(dirchem_ref, mecachim)
    filef = "{}/FAMILIES.{}".format(dirchem_ref, mecachim)
    fileals = "{}/ALL_SPECIES.{}".format(dirchem_ref, mecachim)
    fileas = "{}/ACTIVE_SPECIES.{}".format(dirchem_ref, mecachim)
Antoine Berchet's avatar
Antoine Berchet committed
72

73
    nallqmax, nphoto_rates = create_optchem(self, filer, fileps)
Antoine Berchet's avatar
Antoine Berchet committed
74

75
76
    # Create chemical_scheme.nml namelist
    os.system('echo "&args" > {}'.format(finf))
Antoine Berchet's avatar
Antoine Berchet committed
77
78
79
80
81
82
83
84
85
86
    os.system("echo \"fnacspec = '{}'\" >> {}".format(fileas, finf))
    os.system("echo \"fnallspec = '{}'\" >> {}".format(fileals, finf))
    os.system("echo \"fnprescr = '{}'\" >> {}".format(fileps, finf))
    os.system("echo \"fnprodl = '{}'\" >> {}".format(filepl, finf))
    os.system("echo \"fndep = '{}'\" >> {}".format(filedp, finf))
    os.system("echo \"fnchem = '{}'\" >> {}".format(filec, finf))
    os.system("echo \"fnstoi = '{}'\" >> {}".format(files, finf))
    os.system("echo \"fnrates = '{}'\" >> {}".format(filerr, finf))
    os.system("echo \"fnjrates = '{}'\" >> {}".format(filej, finf))
    os.system("echo \"fnfamilies = '{}'\" >> {}".format(filef, finf))
87
88
    os.system('echo "iqmax = {}" >> {}'.format(self.nspecies, finf))
    os.system('echo "iallqmax = {}" >> {}'.format(nallqmax, finf))
Antoine Berchet's avatar
Antoine Berchet committed
89
90
91
    os.system('echo "iprescrmax = {}" >> {}'.format(self.nprspecies, finf))
    os.system('echo "iprodmax = {}" >> {}'.format(self.nprodspecies, finf))
    os.system('echo "idepmax = {}" >> {}'.format(self.ndepspecies, finf))
92
93
94
    os.system('echo "nreac = {}" >> {}'.format(self.nreacs, finf))
    os.system('echo "ijratesmax = {}" >> {}'.format(nphoto_rates, finf))
    os.system('echo "/" >> {}'.format(finf))