Software Development: Reaktoro, a unified framework for modeling chemically reactive systems

Reaktoro is a computational framework developed in C++ and Python that implements numerical methods for modeling chemically reactive processes governed by either chemical equilibria, chemical kinetics, or both.
The chemical simulator of Reaktoro is based on the Gibbs energy minimization (GEM) methods as well as a revised law of mass action (rLMA) approach that combines the advantages of both GEM and LMA methods. Recently, on-demand machine learning (ODML) of fast and efficient chemical equilibrium calculations was introduced in Reaktoro.
Chemical equilibrium calculations are essential for many chemical reaction modeling problems. Reaktoro’s computational chemical equilibrium capabilities using Gibbs energy minimization algorithms can be applied to solve a variety of modeling problems. However, sometimes the chemical equilibrium model is not sufficient to understand a chemically reactive process. This happens when we need to understand how the composition of the chemical system changes with time as a result of chemical reactions. For this, chemical kinetics is imperative. Reaktoro can perform chemical kinetics calculations combined with chemical equilibrium (i.e., part of the chemical system evolves under kinetics, while the other is continuously in equilibrium at all times). This mode of calculation is particularly useful for simulating chemically reactive systems in which some reactions have rates that are many orders of magnitude higher than others (and thus can be assumed in instantaneous equilibrium at any time). Finally, chemical equilibrium and kinetics calculations are both space independent. If you need to model transport processes (e.g., advection, diffusion) combined with chemical reactive processes, then chemical transport (or reactive transport) simulations are what you need.
Various interactive examples and tutorials can be found by clicking the button below.
https://img.shields.io/badge/Reaktoro%20Tutorial-Interactive!-E66581.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFkAAABZCAMAAABi1XidAAAB8lBMVEX///9XmsrmZYH1olJXmsr1olJXmsrmZYH1olJXmsr1olJX
On-Demand Machine Learning (ODML) approach

Figure 1: Acceleration of the chemical equilibration calculation in reactive transport modeling of the dolomitization process.
During reactive transport modeling, the computing cost associated with chemical equilibrium calculations can be 10 to 10,000 times higher than that of fluid flow, heat transfer, and species transport computations. These calculations are performed at least once per mesh cell and once per time step, amounting to billions of them throughout the simulation employing high-resolution meshes. To radically reduce the computing cost of chemical equilibrium calculations (each requiring an iterative solution of a system of non-linear equations), an on-demand machine learning (ODML) algorithm has been introduced in [Leal etal 2020]. The method enables quick and accurate prediction of new chemical equilibrium states using the results of previously solved chemical equilibrium problems within the same reactive transport simulation. The training operations occur on-demand, rather than before the start of the simulation when it is not clear how many training points are needed to accurately and reliably predict all possible chemical conditions that may occur during the simulation. Each on-demand training operation consists of fully solving the equilibrium problem and storing some key information about the just computed chemical equilibrium state (which is used subsequently to rapidly predict similar states whenever possible). We study the performance of the on-demand learning algorithm, which is mass conservative by construction, by applying it to a reactive transport modeling example and achieve a speed-up of one or two orders of magnitude (depending on the activity model used). The implementation and numerical tests are carried out in Reaktoro, a unified open-source framework for modeling chemically reactive systems.
The ODML approach in application to the heterogeneous problems
The ODML has been thoroughly tested on the reactive transport problems in heterogeneous porous media. The numerical tests are carried out using the coupling of Reaktoro to the open-source software package Firedrake. The numerical results obtained demonstrate how relatively complex simulations of fluid flow coupled with reactive transport can be performed substantially faster by means of radically decreasing the computing costs of chemical reaction calculations (see Figure 2).
Figure 2: Simulation of (a) the dolomitization process and (b) the hydrogen sulfide scavenging in the heterogeneous media together with the summary of the ODML method’s performance.
Extentions of the ODML approach for chemical kinetics
Besides, we are working on an extension of the ODML approach to support kinetically controlled reactions. We also consider further investigations with more complex geochemical and geological conditions. We plan to extend Reaktoro’s functionality to model reservoirs souring as a result of the activities of sulfide-reducing bacteria, mixing of the groundwater and seawater in the oil reservoir as well as scaling effects this process results to, modeling the effects that seawater or sodium chloride have during the cement rock attack, among many more. An extension to the three-dimensional problem with heterogeneity will require the further implementation of a stable numerical scheme to solve the Darcy problem. To enable full coupling of the transport and flow problems, we plan to continue developing the reactive transport simulator and present obtained results in the future articles.
Reaktoro v2.0 for geobiological simulations
Reaktoro v2.0 can be used for various geobiological simulations. One of them is the modelingof carbonate-rich lakes, which were relatively common on the early Earth. The Earth’s CO2-rich atmosphere can be modeled by fixing the fugacity of the simulated chemical states. In particular, a consequence of early Earth’sCO2-rich atmosphere (corresponding to the partial pressure of CO2 from -2 to 0) is that it would have enhanced the weathering of hydroxyl- and fluorapatite in mafic rocks by lowering the pH of surface waters. Figure 3 plots the two-dimensional dependence of the phosphate solubility and pH on the range of partial CO2 pressures and temperatures.
Figure 3: Calculation of the phosphate solubility in the early Earth carbonat-rich lake using Reaktoro
Reaktoro v2.0 usage for different applications using the ThermoFun
Among many databases, Reaktoro v2.0 allows modeling geochemical applications using ThermoFun, a general-purpose open-source client that provides thermodynamic properties of substancesand reactions at the desired temperature and pressure. Figure 4 below demonstrates the result of the calculation of uranium speciation with changing pH values at fixed CO2partial pressure (left-hand side) and simulations of the limestone addition to the cement formulation (right-hand side).
Figure 4: Illustraton of the different colloborations projects between Reaktoro and Thermofun.
Barite scalling including the ion-exchange effects on therock surface
Barite scaling can be considered as a side effect that occurs during waterflooding of the oil reser-voirs the result of the contrasting compositions of the injected seawater (SW) fluid and the forma-tion water (FW) in the reservoir that coexists with oil. The precipitation of barite BaSO4 happens according to the reaction combining Ba2+ions are present in the FW and abundant SO2−4 ions from the injected seawater. In addition, we assume the presence of clay (an ion-exchange site X− occupied by Na+ions ) in the reservoir. Therefore, in addition to the mineral scaling the ion-exchange reaction. Schematically, we illustrate the reactive transport experiment in Figure 5 (left) and the results of the scaling as well as the ion-exchange reactions are presented on the right-hand side of Figure 5.
Figure 5: Reactive transort modelling of the barite scaling in the reservoir waterflooding including the ion-exchange processes.
Acknowledgments
Reaktoro would not exist without its past and current supporters and contributors, who supported the project with either financial, scientific, and/or coding input.
Academic and Research Institutions
- Imperial College London, UK (2011-2014), Qatar Carbonates and Carbon Storage Research Centre (QCCSRC)
- Paul Scherrer Institute, Switzerland (2014-2015), Laboratory for Waste Management
Industries
Reaktoro is proud of its past and current financial support from industries. We would like to thank:
- Shell (2011-2014, 2019-present), Shell Technology Centre Amsterdam
- Qatar Petroleum and Qatar Science & Technology Park (2011-2014), Qatar Carbonates and Carbon Storage Research Centre (QCCSRC)




