Paper

Chempl: a playable package for modeling interstellar chemistry

© 2021 National Astronomical Observatories, CAS and IOP Publishing Ltd.
, , Citation Fujun Du 2021 Res. Astron. Astrophys. 21 077 DOI 10.1088/1674-4527/21/3/077

1674-4527/21/3/077

Abstract

Astrochemical modeling is needed for understanding the formation and evolution of interstellar molecules, and for extracting physical information from spectroscopic observations of interstellar clouds. The modeling usually involves the handling of a chemical reaction network and solution of a set of coupled nonlinear ordinary differential equations, which is traditionally done using code written in compiled languages such as Fortran or C/C++. While being computationally efficient, there is room for improvement in the ease of use and interactivity for such an approach. In this work we present a new public code named CHEMPL, which emphasizes interactivity in a modern Python environment, while remaining computationally efficient. Common reaction mechanisms and a three-phase formulation of gas-grain chemistry are implemented by default. It is straightforward to run 0D models with CHEMPL, and only a small amount of additional code is needed to construct 1D or higher-dimensional chemical models. We demonstrate its usage with a few astrochemically relevant examples.

Export citation and abstract BibTeX RIS

1. Introduction

The interstellar medium (ISM) is ever-evolving under the effect of electromagnetic radiation, cosmic-rays, and hydrodynamic motion coupled with gravitational and magnetic field. As the physical condition changes, the chemical composition changes accordingly. The buildup of chemical complexity in the ISM, the chemical heritage of forming stellar and planetary systems, and the possible connection between astronomy and the origin of life are fascinating topics. Over the years the chemistry of ISM has proved to be a powerful diagnostic of the physical parameters. For this to work at a quantitative level, it is necessary to model the chemistry in detail. Except for simple cases, a comprehensive chemical network has to be used, because most of the time it is not easy to figure out beforehand which reactions are important and which are not. With over 200 molecules detected in space (not counting isotopologues) (Endres et al. 2016; McGuire 2018), the scale of chemical networks for modeling interstellar molecules keeps growing, with the largest at the moment containing tens of thousands of reactions. The evolution of a large and interconnected chemical network can only be tracked with numerical methods.

In the field of astrochemistry — namely, the study of the chemical side of astronomy — there are already a few codes, many of which are publicly available, including: Nahoon (Wakelam et al. 2012), MAGICKAL (Garrod 2013), KROME (Grassi et al. 2014), Astrochem (Maret & Bergin 2015), Nautilus (Ruaud et al. 2016), ALCHEMIC (Semenov 2017), and UCLCHEM (Holdship et al. 2017). So why create yet another code?

Traditionally, codes for astrochemistry are written in Fortran or C/C++, and the mode of running is usually like this: (1) The user prepares a few files containing the reaction network, the initial chemical abundances, and the physical parameters, (2) then feeds these files to the compiled program to get the evolution of the abundances of different species as a function of time, with the results saved in files. In some codes a preprocessing step to generate the source code describing the differential equations from a reaction network is needed. (3) To analyze the results, separate code has to be written to load the files containing the results. While this whole process can be pipelined and parallelized (at the process level) to work efficiently, it lacks interactivity. The user has to switch between different execution environments back and forth, e.g., a command line terminal to run the chemical code, and a visualization environment (such as Python/matplotlib) for analyzing and making plots. Such a context switching and the associated data loading could be cumbersome. When working with models with time-dependent physical conditions, one might have to hard-code the time-dependency into the code and recompile the binary executable each time a change is made (it is noted that Nautilus uses input files to implement time-dependency), which could be distracting to say the least.

Here we present a new code CHEMPL 1 , which is aimed at improving interactivity without sacrificing efficiency. In writing CHEMPL, one goal we keep in mind is to make the code as "playable" as possible, hence the name. It should be relatively straightforward to make changes to the model configuration, and be fast to see the effects of the changes that just have been made. The user is able to pause the calculation temporarily, look into the internal states of the chemical system and possibly make some changes to the physical/chemical parameters, and continue the solution afterwards. To ensure performance, under the hood the code is written in C++, and the ODE (ordinary differential equation) solver being used is the time-tested DLSODES solver of the ODEPACK package written in Fortran (Hindmarsh 1983). The interactivity is achieved through integration with Python, and is designed to be used in the iPython or Jupyter environment. We use Cython (Behnel et al. 2011) to wrap the C++ code into a Python module. Most of the internal model data can be accessed as a normal Python variable, and can be saved as human-readable or binary data files, or it may be more beneficial to save the Python data structures using the "pickle" facility of Python (or other structured data format such as the Advanced Scientific Data Format (ASDF)). Note that CHEMPL can also be used in the "traditional" mode (i.e., working with configuration files and launched in the command line), or incorporated into other simulations as a subroutine with a few lines of additional code for setting it up.

Chempl by default supports common first-order and second-order reaction types, includes approximate treatment for the self- and mutual- shielding of H2 and CO molecules, and works with comprehensive gas-grain chemical networks modeled as a three-phase system. As will be shown in example models, it is straightforward to construct 0D or 1D chemical models with CHEMPL. Self-consistent temperature calculation based on heating and cooling balance is not yet included at the moment, but it is in the plan for the near future. For grain surface chemistry, CHEMPL currently adopts the rate equation approach as the mathematical formulation for describing the chemical dynamics. It is known that in some physical conditions the rate equation approach does not accurately capture the stochastic features of the grain surface system, and stochastic simulation (Gillespie 1976; Vasyunin et al. 2009; Chang & Herbst 2014), modifications to the rate equations (Garrod 2008), or moment equation methods (Du & Parise 2011) need to be used. Inclusion of these alternative formulations are also in the plan.

This paper focuses on code capabilities and demonstration of use cases for CHEMPL, instead of the scientific implications of the models. In Section 2 we depict the mathematical framework for interstellar chemistry. In Section 3 we show a few example astrochemical models simulated with CHEMPL. We conclude in Section 4.

2. Mathematical Formulation of Interstellar Chemistry

In astrochemical modeling the abundances of different chemical species are solved as a function of time. The differential equation (actually a set of coupled equations) to be solved is of the form

Equation (1)

where y is a vector with component yi being the abundance of the ith species, usually measured relative to hydrogen nuclei. The vector-valued function f on the right-hand side is a nonlinear function of the components of y , and may be explicitly time-dependent.

Sometimes a steady-state solution is needed, which can be obtained by solving the algebraic equation f (t, y ) = 0, or by evolving y (t) for a very long time by solving Equation (1).

The system of ODE equations in Equation 1 is often stiff, meaning that many vastly different timescales are involved, requiring that implicit, rather than explicit methods, be used for efficient solution. Solvers of stiff ODEs often require knowledge of the Jacobian matrix of the right-hand side, defined as

Equation (2)

which is often sparse for astrochemistry-relevant networks, meaning that a large fraction (≳90%) of the elements of J are identically zero. CHEMPL constructs the sparse structure from the reaction network.

2.1. The Canonical Rate Equations

In interstellar or protoplanetary conditions, where the majority of the gas under consideration has a density typically in the range of ten to the power of a few per cm3, and densities higher than ∼1013 cm–3 rarely need to be considered, three-body chemical reactions are not important and are excluded in astrochemical networks.

When only first- and second-order reactions are included, Equation 1 can be written in component form as

Equation (3)

where ${ {\mathcal F} }_{i,1}$ and ${ {\mathcal F} }_{i,2}$ are the set of first- and second-order reactions that form species i, ${{\mathscr{D}}}_{i,1}$ and ${{\mathscr{D}}}_{i,2}$ are the set of first- and second-order reactions that destroy species i, kj is the rate coefficient of reaction j, and yj,1 and yj,2 are the abundances of the first and second (when applicable) reactants of reaction j. Note that for $j\in {{\mathscr{D}}}_{i,1}$, yj,1 is always simply yi , and for $j\in {{\mathscr{D}}}_{i,2}$, one of yj,1 and yj,2 (or both) must be the same as yi .

Examples of first-order reactions are photodissociation, cosmic-ray ionization, adsorption, and desorption reactions. These reactions are not strictly "uni-molecular", since when one of these reactions happen there must be two particles interacting, with one being the chemical species we care about and the other being a photon, a cosmic-ray particle, or a dust grain. They are treated as first order because the fluxes of photons and cosmic-rays are external inputs and are independent of local conditions, and in the case of adsorption the dust grains can be "reused" (hence effectively being constant). Examples of second-order reactions are neutral-neutral, neutral-ion, dissociative recombination, and radiative association reactions. One may consult Wakelam et al. (2012) or McElroy et al. (2013) for a list of possible types of gasphase reactions relevant for astrochemistry.

2.2. Expressions for Rates of Different Types of Reactions

In this section we describe formulae for calculating the rates for different types of reactions. While these equations can be found in many modeling papers in astrochemistry, they are presented here for reference. More detailed pedagogical discussions can be found in Du (2012). For some reaction types, more realistic expressions for their rates may need to be used when modeling some specific problems. In CHEMPL it is possible to add new reaction types with associated handlers to accomplish this.

2.2.1. Cosmic-ray reactions

For ionization directly caused by cosmic-rays, the rate coefficient is simply a constant:

Equation (4)

where α takes different value for different species. For cosmic-ray-induced photoreactions, the rate coefficient is

Equation (5)

where α, β, and γ are constants, and ω is the albedo of dust grains to dissociative photons, to which we assign a value of 0.6 by default. Both direct and induced reaction rates due to cosmic-rays can be rescaled by the actual cosmic-ray ionization rate (relative to the fiducial rate of ζ0 = 1.36 × 10–17 s–1, see McElroy et al. 2013).

2.2.2. Photoreactions

For photoreactions (photodissociation and photoionization), the rate coefficient is

Equation (6)

where α is the unattenuated rate, γ is a constant to scale the visual extinction AV to the UV band. These rates can also be rescaled by a G0 parameter, namely the ratio between the actual UV field and the Draine interstellar field (Draine 1978).

For species such as H2, CO, and N2, self- and mutual- shielding can be important, and Equation (6) cannot be used. Approximate analytical formulae or tabulated rates (e.g., Draine & Bertoldi 1996; Morris & Jura 1983; Visser et al. 2009; Li et al. 2013) with dependencies on column densities and temperature are available in this case.

2.2.3. Generic two-body reaction rates

The modified Arrhenius equation is often used to calculate the two-body reaction rate coefficients:

Equation (7)

where α, β, and γ are constants provided by the reaction network databases. The reaction rate, or stated more clearly, the number of occurrence of a reaction per unit time per unit volume, can be expressed as

Equation (8)

where ni and nj are the volume density (in cm-3) of the two reactants of a two-body reaction. The time derivative of the density of species i caused by this reaction is then (assuming ij)

Equation (9)

In astrochemistry the abundance of a species relative to hydrogen nuclei is usually used, i.e., ni = yi nH, and the time derivative of yi is then

Equation (10)

Note that the modified Arrhenius equation is an empirical formula and does not apply for all reactions for all temperature ranges (see Sect. 3.2.1).

2.2.4. Adsorption of gas phase species onto the surfaces of dust grains

The number of particles of species i adsorbed onto dust grains per unit volume per unit time is (Du & Bergin 2014)

Equation (11)

where s is the sticking coefficient, σ = π a2 is the dust cross section with a being the dust grain radius, ndust and ni are the volume density of dust grains and species i, and vT(i) is the thermal speed of species i:

Equation (12)

where kB is the Boltzmann constant, and mi is the mass of a particle of species i. Written in terms of abundance relative to hydrogen nuclei, the time derivative is

Equation (13)

where η is the dust-to-hydrogen number ratio, which can be further expressed as:

Equation (14)

where ηM is the dust-to-grain mass ratio, with a canonical value of 0.01, mH is the mass of a hydrogen nucleus, μ is the mean molecular mass per hydrogen nucleus, and ρd is the material density of dust grains. So the rate coefficient of adsorption reaction is

Equation (15)

The sticking coefficient s can be determined by experiments and is usually in the range 0.1–1. Note that for CO molecule, the above expression gives a depletion timescale of ∼4 × 104 yr for the fiducial physical parameters in the parentheses.

2.2.5. Thermal desorption from dust grain surfaces

The thermal desorption rate is

Equation (16)

where Td is the dust temperature (which may be different from the gas temperature), and νi is the vibrational frequency of species i on the dust grain surface:

Equation (17)

Ei is the desorption energy of species i, and ρd is the surface site density typically taken to be 1015 cm–2.

2.2.6. Cosmic-ray desorption

When energetic cosmic-ray particles hit a dust grain, the latter will be promptly heated, leading to evaporation of surface species. The evaporation only lasts a very brief period, because the dust grain cools down quickly. This cosmic-ray-induced desorption is usually implemented using the formulation of Hasegawa & Herbst (1993a):

Equation (18)

where ki (70 K) is the thermal desorption rate of species i calculated with Equation (16) for a dust grain temperature of 70 K, and f(70 K) is the fraction of time a dust grain remains heated around 70 K by a cosmic-ray particle, estimated to be ∼3.16 × 10–19. The number "70 K" is the peak temperature a dust grain can achieve from cosmic-ray heating balanced by evaporative cooling.

2.2.7. Photodesorption

UV photons impinging on dust grains can eject surface molecules into the gas phase. The photodesorption rates have been experimentally measured or theoretically computed for ice species such as CO, H2O, N2, etc. (Öberg et al. 2009a,b; Potapov et al. 2019; González Díaz et al. 2019), and empirical formulae have been used for calculating their rates.

We use a formula of the form for the rate coefficient

Equation (19)

where F is the UV flux (in counts cm–2 s–1), Yi is the photo yield for species i, σ is the dust cross section, and η is the dust-to-gas number ratio. The number of monolayers of species i is:

Equation (20)

where yi is the abundance relative to hydrogen nucleus, and NS is the number of surface reaction sites per grain (∼106 for a dust grain radius of 0.1 μm). The yield Y may depend on the dust temperature. For ice species without experimental data, Y is assumed to be 10–4 by default. However, Equation (19) does not accurately reflect all the complexities found in experiments and should be treated with care when photodesorption is expected to be important.

2.2.8. Chemical desorption

The heat released by exothermic surface reactions may be able to launch the products off the dust grains. This non-thermal desorption mechanism is invoked to explain the observed relatively high abundances of species such as methanol in dark clouds (Garrod et al. 2007). While this mechanism is based on the Rice-Ramsperger-Kassel (RRK) theory, in effect it amounts to adding a branch to each surface two-body reaction, with the products being the gas phase counterparts of the surface products. Hence a new empirical parameter is required to describing the efficacy of chemical desorption, namely the branching ratio between the gas phase to surface channels. CHEMPL by default assumes a value of 0.05 for this parameter.

2.2.9. Two-body reaction rates on dust grain surfaces

For a surface reaction of the form i + j → ⋅, its rate coefficient is

Equation (21)

where kmig,i is the surface migration rate of species i, pij is the probability for i and j to cross over the reaction barrier when they arrive at the same surface site, η is the dust-to-grain number ratio as defined in Equation (14), and NS is the number of reactive sites per grain. The surface migration can be due to either thermal hopping:

Equation (22)

or quantum tunneling (at very low temperatures):

Equation (23)

where νi is the characteristic vibration frequency as defined in Equation (17), Ediff,i is the energy barrier against surface migration for species i, which is usually taken to be a fraction (0.3–0.5) of the desorption energy, and l is the width of the barrier. The reaction probability pij can be calculated similar to kmig,i , except that the factor νi before the exponential function is dropped, and the diffusion barrier is replaced by the reaction barrier.

As a side note, the formation of H2 molecules on dust grain surfaces is treated as a normal two-body surface reaction. This is different from some of the previous works, in which the H2 formation rate is taken to be half of the adsorption rate of H atoms (see, e.g., Holdship et al. 2017).

2.3. Three-phase Model of Gas-grain Chemistry

As already described in previous sections, molecules can be adsorbed on the surface of dust grains. After being adsorbed, these molecules are able to migrate over the dust grain surface and may react with each other when two molecules meet at the same surface site. Since a dust grain has a limited surface area, when many molecules have adsorbed on its surface, newly adsorbed ones will likely sit on top of another. In this way, multiple ice layers will form on the dust grains. In such a description of dust grain structure, usually only molecules on the topmost layer are assumed to be mobile and reactive, while molecules underneath (in the mantle) are "frozen" and nonreactive (however, see Chang & Herbst 2014, 2016). When molecules in the topmost layer evaporate, the underneath layer will be revealed and becomes the new reactive layer. This is the so-called three-phase model of interstellar chemistry, in which the three phases are: gas phase, dust grain surface, and dust grain mantle.

Chempl has implemented the three-phase description of gas-grain chemistry, following the approach of Hasegawa & Herbst (1993b) and Garrod & Pauly (2011) (for a detailed description, see also Du 2012). For each surface species (except for very weakly adsorbed species such as H2) a new mantle species is included in the network. For species i with surface population per grain i, its evolution equation is

Equation (24)

and the mantle population of i evolves according to

Equation (25)

In Equation (24) the two summations are over two-body reactions producing and consuming species i. kads/des(i) is the adsorption/desorption rate coefficient of i, and nG(i) is the gas phase population of i. kads/des is the total adsorption/desorption rate of all the species, nS is the total population of all surface species, nM is the total population of all mantle species, and NS is the number of sites per grain. The quantity "population-per-grain" ${n}_{{\rm{S}}}(i)$ is related with abundance with respect to hydrogen nuclei yi by (see also Eq. (20))

Equation (26)

where η is the dust-to-hydrogen number ratio defined before.

Note that the three-phase formulation is statistical in nature. There are more accurate treatments such as the microscopic kinetic Monte Carlo method (Cuppen & Herbst 2007; Garrod 2013), which tracks the location of each particle on the dust grain surface.

With the inclusion of three-phase chemistry, the code will run slower, not just because of the increase in the number of variables due to addition of mantle species, but also because of the increased non-linearity of Equation (24) relative to Equation (3).

2.4. The Workflow of Chempl

While Chempl can be used as a stand-alone program, it is mainly intended to be used as a Python module. Here we describe the basic workflow of Chempl when used in this mode. A minimal working example is shown in Table 1.

  • Create the ChemModel object. This is the central Python object to work with in Chempl. During the instantiation the user may provide the file names of the reaction network, the initial abundances, and the enthalpies (needed for reaction heat calculation). These files could also be loaded later with the corresponding helper functions. The user could also add reactions one by one using the Python code, and this is the way to load reaction network stored in different formats.
  • Set the physical parameters. Similarly, this could be done with an input file, or using a helper function to set the value of each parameter by its name. They could also be provided in the previous step. Optionally, the user could add time-dependency for certain parameters by providing a lookup table. Internally the code linearly interpolates the table to evaluate time-dependent parameters at arbitrary time.
  • Do some "boilerplate" preparation work. These include, e.g., sorting out reactions of different types, getting the elemental composition of each species and calculating their molecular masses and quantum mobilities, and calculating the heat of each reaction. Such boilerplate work usually only need to be done once for each model, unless during some unusual investigations (e.g., changing the reaction network while the code is running).
  • Setup the ODE solver. This usually amounts to setting the solver ID, which is itself optional (could be useful when running in multi-process mode). Details of the solver setup and preparation are concealed in the C++ code, which includes constructing the sparse structure of the ODE system, allocation of the needed working memories, and assignment of flags defining the working modes of the solver.
  • Feed the current time and abundances, and the required output time, to the solver, then wait for the output.
  • Retrieve and store the output time (which could be different from the value provided in the previous step) and abundances.
  • Terminate if the output time is equal to or greater than the targeted final evolution time; otherwise go to step 5.

Table 1. A minimal working example of a chemical model written in Python using Chempl. Tested with Python 3. The Python bytes objects (in the form of b'***') instead of string objects are needed for interacting with internal C++ code.

import chempl
model = chempl.ChemModel(
    fReactions=b'network_file',
    fInitialAbundances=b'abundance_file',
      phy_params={
       b'Av': 10.0,
       b'G0_UV': 1.0,
       b'Ncol_H2': 1e22,
       b'T_dust': 10.0,
       b'T_gas': 10.0,
       b'chemdesorption_factor': 0.05,
       b'chi_cosmicray': 1.0,
       b'dust2gas_mass': 1e-2,
       b'dust_albedo': 0.6,
       b'dust_material_density': 2.0,
       b'dust_radius': 0.1e-4,
       b'dust_site_density': 1e15,
       b'dv_km_s': 1.0,
       b'mean_mol_weight': 1.4,
       b'n_gas': 2e4)
model.prepare()
model.set_solver()
t = 0.0
dt = 0.1
tRatio = 1.1
tMax = 3.15e10 # in seconds
nMax = 1000
store = {'t': [], 'y': []}
y = model.abundances
for i in range(nMax):
       t, y = model.update(y, t=t, dt=dt)
       store['t'].append(t)
       store['y'].append(y)
        if t > = tMax:
           break
       dt *= tRatio

3. Example models based on Chempl

In this section we present a few example models calculated with Chempl. The chemical networks we use for these examples are the UMIST network, or extended from it. The latest version of the UMIST network is released in 2012, hence it is called RATE12 (McElroy et al. 2013). The default reaction network format supported by Chempl is similar to the KIDA network (Wakelam et al. 2012), instead of the colon-separated format of RATE12, and can support any format with a simple conversion.

3.1. Dark Cloud Models

We first run a model with physical conditions relevant for dark clouds. The physical parameters are listed in Table 2. The initial abundances are listed in Table 3. The network for this model is UMIST RATE12, extended by only adding the H2 formation reaction on dust grain surface and the adsorption and evaporation of H and H2, and no other adsorption/desorption processes and surface reactions are included.

Table 2. Physical Parameters Used in the Example Dark Cloud Model

Av 10
G0 1
NH 2 1022 cm–2
nH 2×104 cm–3
Tdust 10 K
Tgas 10 K
χCR 1.3 ° 10–17 s–1
Dust-to-gas mass ratio0.01
Dust albedo0.6
Dust material density2.0 g cm–3
Dust grain radius0.1 μm
Dust site density1015 cm–2
Chemical desorption efficiency0.05

Table 3. Initial Abundances Used in the Example Dark Cloud Model

H2 0.5
H5 × 10–5
He9 × 10–2
C+ 1.4 × 10–4
N7.5 × 10–5
O3.2 × 10–4
S+ 8 × 10–8
Si+ 8 × 10–9
Fe+ 3 × 10–9
F2 × 10–8
Cl+ 4 × 10–9
Mg+ 7 × 10–9
Na+ 2 × 10–9
P+ 3 × 10–9
E 1.40107 × 10–4

The code takes 4–5 seconds of CPU time 2 to reach 108 yr. The resulting evolution of a few common species are plotted as solid curves in Figure 1. As can be seen, the system reaches steady state at ∼107 yr, after which carbon mainly resides in CO, while oxygen mainly resides in CO and O2. However, this model is not realistic at late times (≳106 yr), because at the low temperature for this model, CO should freeze out onto dust grains. So this model should be only viewed as a code benchmark and it does not accurately describe the actual dark cloud chemical processes.

Fig. 1

Fig. 1 Example results from a basic dark cloud model. Solid curves are calculated without any dust grain chemistry except H2 formation, and dashed curves with the same colors are based on a full three-phase chemical network.

Standard image

So we run another model with the same initial abundances and physical parameters, but with a full three-phase chemical network. Nonthermal desorption (Garrod et al. 2007) by the heat released in surface reactions is also included. With this added complexity, the code takes ∼15 seconds of CPU time to reach 108 yr. The results are plotted as dashed curves in Figure 1. For species such as CO and C, their early-time (≲104 yr) evolution from the two models coincide. This is because their abundances are mainly determined by gas-phase reactions at early times. For species such as H2O, OH, O2, and NH3, their evolution tracks from the two models depart away from each other from the very beginning. This is because they are efficiently formed on the dust grain surface, and the inclusion of surface reactions (together with nonthermal desorption) enhances their abundances from the very beginning.

3.2. Time-dependent Physical Conditions

Chemical models in which physical parameters (most frequently, density and temperature) change with time have been used in the study of warm-up phase of hot cores (Garrod & Herbst 2006). Technically, this time-dependency could be implemented with a series of models with constant physical parameters, and the parameters only gradually change from one model to another. In the series of models the final abundances of a previous model is used as initial condition of the next. However, such an implementation would be computationally inefficient, because the ODE solver would have to reinitialize itself for each individual model, which is a slow process. So it is necessary to add explicit time-dependency directly in a model, specifically, in the right-hand side of Equation (1) or Equation (3).

3.2.1. Continuity of reaction rates

In the RATE12 network each reaction has associated a temperature range in which the rate parameters are most reliable. Some reactions have two temperature ranges, which means a different set of rate parameters must be chosen at different temperatures. This could cause problems when temperature varies as a function of time: at the boundary of two temperature ranges, the reaction rates calculated from two versions of rate parameters are not necessarily continuous, which may confuse the ODE solver and the solution will become unreliable (or the solver will stop working and no solution can be obtained after the boundary of a temperature range is reached).

Chempl ensures continuity (smoothness actually) by joining the rates calculated with two sets of parameters using a weighting function of the form

Equation (27)

where x0 is the interval edge, and w > 0 is the separation from one interval to another. The ± sign takes "+" when x0 is the right edge, and takes "−" when x0 is the left edge. The function g(x) has the property that for x < x0, it quickly approaches unity, while for x > x0, it quickly approaches zero. The choice of weighting function is arbitrary, in the sense that a weighting scheme is allowed as far as the transition across the boundary is smooth and without any artificial bumps.

Figure 2 shows the rate coefficients of two reactions as a function of temperature. As can be seen from the left panel, without a treatment such as the one described here, the rate coefficient would jump from one value to another when the temperature only slightly varies at the boundary (from 100 to 101 K). This may halt the ODE solver since it will have to use exceedingly small time steps (since temperature is a function of time in time-dependent models). With a continuous function, the ODE solver will be able to integrate much easier.

Fig. 2

Fig. 2 Examples showing how the rate coefficients for reactions with two temperature-range-of-applicability in the RATE12 database are calculated to ensure continuity and smoothness with respect to temperature. The left panel corresponds to reaction H + H → H2 + E, and the right panel corresponds to NH + O → NO + H.Blue and orange curves are the rate coefficients calculated with expressions for each temperature range as shown in the legends (dashed parts are outside the range of applicability). The red curves are the smoothed rates joining the two used in the code.

Standard image

Figure 3 and Figure 4 show two example models with time-dependent temperature and density. The reaction network used for them are RATE12 with the addition of adsorption and desorption reactions, while no surface reactions beyond the formation of H2 are included. The time evolution of temperature and density in the two models are arbitrarily designed, while keeping in mind that they may mimic realistic processes occurring in certain interstellar environments. The first model simulates a compressing and heating event, which takes about 40 CPU seconds to reach 107 yr, while the second one simulates a "wavy" or oscillating temperature and density profile, and takes about 16 CPU minutes to reach 107 yr. The abrupt oscillation of temperature and density, especially at late times, limits the step size used internally in the ODE solver and significantly slows down the integration speed.

Fig. 3

Fig. 3 Results from a toy model with time-dependent temperature and density. The top and middle panels show the gas and dust temperature and gas density as a function of time. Solid curves in the bottom panel show the corresponding evolution of abundances of different species, while dashed curves in that panel are calculated with temperature and density kept constant at their initial values.

Standard image
Fig. 4

Fig. 4 Similar to Fig. 3. Results from a toy model with "wavy" and spiky time-dependent temperature and density.

Standard image

Interestingly, the evolution curves plotted in the bottom panel of Figure 4 demonstrate two types of behavior: those which follow temperature (CO, O2, and NH3), and those which follow density (H2O, OH). For species of the first type, their abundances are mostly controlled by desorption, hence their abundances jumps when the dust temperature reaches their desorption temperature, and stays flat after that. For species of the second type, either they are not able to evaporate at dust temperatures ≲40 K (the highest dust temperature in the model), and/or their abundances are mostly determined by gas phase reactions, and their abundances tend to follow the evolution of density. The behavior of C and C+ are more complex. They seem to follow both density and the rise and drop of temperature, which is because their abundances are affected by gas phase reactions which involves species that can evaporate at a dust temperature less than 40 K.

3.3. Circumstellar Envelope

Since we largely use the UMIST RATE12 network as a starting point for Chempl, we also run a model similar to the "carbon-rich circumstellar envelope model" presented in the RATE12 paper (McElroy et al. 2013). This may be viewed as a non-strict benchmark, because a strict one is possible only if the exact parameters (including physical constants) used in their model are adopted. Here we try to use the same input as them, though an exact match is not intended for. The initial abundances and density profile are taken from table 6 of McElroy et al. (2013), and the temperature profile is taken from Cordiner & Millar (2009). The self-shielding of CO from photodissociation is treated using the approach of Morris & Jura (1983), which is also the same as in McElroy et al. (2013). While this model calculates the spatial structure of a circumstellar envelope around a carbon-rich AGB star, however, since the gas in the envelope are launched from very close to the central star with a fully-specified velocity profile, there is a one-to-one mapping between time and radius. Thus the model can be viewed as one in which physical parameters vary with time, which is how we implement it.

The results of the calculation with Chempl are shown as solid curves in Figure 5, overlaid with data from McElroy et al. (2013) shown as dashed curves. It is clear that the two calculations match very well: two versions of most of the curves are almost identical within numerical errors. This close match means our implementation of the envelope structure with Chempl is correct (although there might be some fine details that are not reproduced in our model).

Fig. 5

Fig. 5 A simple circumstellar envelope model. The solid curves in the lower two panels are calculated with Chempl, while the dashed curves are taken from fig. 2 of McElroy et al. (2013) using data file generated with their code. The top panel shows the adopted temperature (blue) and density (orange) profile.

Standard image

3.4. Spatially Dependent Physical Conditions: a Toy PDR Chemical Model

As a final example, we create a model that simulates a plane-parallel photodissociation region. The density is taken to be uniformly 103 cm–3, the G0 parameter of UV field at the edge is set to 100, while the dust temperature profile is calculated using equation (9.18) of Tielens (2005), and the gas temperature is assumed to be uniformly 100 K.

The calculation has to proceed from the surface layer (AV∼ 0) to the deeper layers to take into account the self-shielding of H2 and CO. Here the CO self-shielding is approximated using the same approach as in 3.3, while the H2 self-shielding is implemented following Draine & Bertoldi (1996). More accurate treatment of self and mutual shielding can also be implemented (Visser et al. 2009; Li et al. 2013; Heays et al. 2017).

The resulting abundances of different molecules are shown as a function of depth (AV) and column density are shown in Figure 6. As is commonly known, the H/H2 transition occurs at AV ∼ 1 – 2, while the C+/C/CO transition occurs at AV ∼ 2 – 4 (the exact transition locations depend on the density profile and the intensity of the external UV field).

Fig. 6

Fig. 6 A simple PDR model, which shows the abundances of different species as a function of depth (visual extinction AV or column density of hydrogen nucleus NH). The column density of molecular hydrogen at each depth is marked in the bottom horizontal axis.

Standard image

3.5. Model-level Parallelism

As shown before, when the physical parameters are kept constant, Chempl runs relatively fast. So it is not necessary to parallelize each individual model. However, when doing a parameter study, in which many models with different configurations need to be computed, parallelization becomes helpful. In the case of Chempl, the current parallelization approach is to make use of the Python built-in "multiprocessing" module. With this module, it is possible to run multiple independent models at the same time, which can accelerate the computational speed by a factor depending on the number of CPU cores of the system. We call this approach of parallelization "model-level" parallelism 3 .

When the physical parameters explicitly change with time, especially when the time variation is oscillatory and spiky, as shown in the example model in Figure 4, the computational speed will be significantly reduced. We do not expect an easy solution to alleviate the computation burden here, because the problem is inherently difficult. In principle, one could parallelize the matrix inversion (which is frequently carried out in the solver) in the ODE solver to speed it up, however the effectiveness of doing this remains to be tested.

4. Conclusions

In this paper we introduce a new code named Chempl for astrochemical study. In comparison with other codes in the field, Chempl emphasizes interactivity and "playability". While Chempl can be used as a traditional standalone command line program or called as a subroutine within a bigger simulation, it is mainly meant to be used as a Python module. In the recent years the Python programming language and its ecosystem have become prevalent in astronomical community, and Chempl is joining this trend.

Chempl is not a completed project. It is still evolving. We expect in the future it will keep improving both in performance and in ease-of-use, as well as in incorporating more chemical and physical mechanisms (for example solving the temperature in tandem with chemical abundances, as done in Du & Bergin 2014). One potential feature that might be handy is for the user to be able to choose a different ODE solver. It may also be useful for the chemical solver to be able to switch between the rate equation approach and the Monte Carlo (Vasyunin et al. 2009; Chang & Herbst 2016), the moment equation (Du & Parise 2011), or the modifiedrate- equation approaches (Caselli et al. 1998; Garrod 2008). This will facilitate the study of the fundamental issue of the stochasticity of grain surface reactions.

Acknowledgements

We thank the anonymous referee for making this paper a better read. This work is partially funded by the National Natural Science Foundation of China (Grant Nos. 11873094 and 11873097). F. Du is financially supported by the Hundred Talents Program of Chinese Academy of Sciences. This work makes heavy usage of Cython, Jupyter Notebook, Numpy, Matplotlib, etc. as delivered in the Anaconda platform. The ODEPACK solver collection and the GCC compiler collection are also instrumental for this work.

Footnotes

  • CHEMPL is available at https://github.com/fjdu/chempl . A few reaction networks and initial conditions are also included in this repository. All the scripts for the example models in this paper are available at https://github.com/fjdu/chempl/blob/master/Examples-for-the-chempl-paper-2020-05.ipynb .

  • All the example models reported in this paper are computed with a MacBook Pro (15-inch, 2017), with a processor configuration of "3.1 GHz Quad-Core Intel Core i7".

  • Since there is no interdependence between the models, this type of parallelism is considered to be "embarrassingly parallel".

Please wait… references are loading.
10.1088/1674-4527/21/3/077