<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD Journal Publishing with OASIS Tables v3.0 20080202//EN" "journalpub-oasis3.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:oasis="http://docs.oasis-open.org/ns/oasis-exchange/table" xml:lang="en" dtd-version="3.0" article-type="research-article"><?xmltex \makeatother\@nolinetrue\makeatletter?>
  <front>
    <journal-meta><journal-id journal-id-type="publisher">ADGEO</journal-id><journal-title-group>
    <journal-title>Advances in Geosciences</journal-title>
    <abbrev-journal-title abbrev-type="publisher">ADGEO</abbrev-journal-title><abbrev-journal-title abbrev-type="nlm-ta">Adv. Geosci.</abbrev-journal-title>
  </journal-title-group><issn pub-type="epub">1680-7359</issn><publisher>
    <publisher-name>Copernicus Publications</publisher-name>
    <publisher-loc>Göttingen, Germany</publisher-loc>
  </publisher></journal-meta>
    <article-meta>
      <article-id pub-id-type="doi">10.5194/adgeo-56-33-2021</article-id><title-group><article-title>Geochemical and reactive transport modelling in R<?xmltex \hack{\break}?> with the
RedModRphree package</article-title><alt-title>RedModRphree package</alt-title>
      </title-group><?xmltex \runningtitle{RedModRphree package}?><?xmltex \runningauthor{M.~De Lucia and M.~Kühn}?>
      <contrib-group>
        <contrib contrib-type="author" corresp="yes" rid="aff1">
          <name><surname>De Lucia</surname><given-names>Marco</given-names></name>
          <email>delucia@gfz-potsdam.de</email>
        <ext-link>https://orcid.org/0000-0002-1186-4491</ext-link></contrib>
        <contrib contrib-type="author" corresp="no" rid="aff1 aff2">
          <name><surname>Kühn</surname><given-names>Michael</given-names></name>
          
        <ext-link>https://orcid.org/0000-0003-2650-6774</ext-link></contrib>
        <aff id="aff1"><label>1</label><institution>GFZ German Research Centre for Geosciences, Telegrafenberg,
14473 Potsdam, Germany</institution>
        </aff>
        <aff id="aff2"><label>2</label><institution>University of Potsdam, Institute of Geosciences,
Karl-Liebknecht-Str. 24–25, 14476 Potsdam, Germany</institution>
        </aff>
      </contrib-group>
      <author-notes><corresp id="corr1">Marco De Lucia (delucia@gfz-potsdam.de)</corresp></author-notes><pub-date><day>5</day><month>October</month><year>2021</year></pub-date>
      
      <volume>56</volume>
      <fpage>33</fpage><lpage>43</lpage>
      <history>
        <date date-type="received"><day>30</day><month>June</month><year>2021</year></date>
           <date date-type="rev-recd"><day>17</day><month>September</month><year>2021</year></date>
           <date date-type="accepted"><day>17</day><month>September</month><year>2021</year></date>
      </history>
      <permissions>
        <copyright-statement>Copyright: © 2021 Marco De Lucia</copyright-statement>
        <copyright-year>2021</copyright-year>
      <license license-type="open-access"><license-p>This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this licence, visit <ext-link ext-link-type="uri" xlink:href="https://creativecommons.org/licenses/by/4.0/">https://creativecommons.org/licenses/by/4.0/</ext-link></license-p></license></permissions><self-uri xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021.html">This article is available from https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021.html</self-uri><self-uri xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021.pdf">The full text article is available as a PDF file from https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021.pdf</self-uri>
      <abstract><title>Abstract</title>
    <p id="d1e93">Advances in computing and experimental capabilities in the research
of water-rock-interactions require geoscientists to routinely
combine laboratory data and models to produce new knowledge. Data
science is hence a more and more pervasive instrument for
geochemists, which in turn demands flexible and easy to learn
software adaptable to their specific needs. The GNU R language and
programming environment has established itself as de facto standard
language for statistics and machine learning, enjoying increasing
diffusion in many applied scientific fields such as bioinformatics,
chemometrics and ecological modelling. The availability of excellent
third party extensions as well as its advanced graphical and
numerical capabilities make R an ideal platform for comprehensive
geochemical data analysis, experiment evaluation and modelling.</p>
    <p id="d1e96">We introduce the open source <monospace>RedModRphree</monospace> extension
package, which leverages the R interface to the established
<monospace>PHREEQC</monospace> geochemical simulator. The aim of
<monospace>RedModRphree</monospace> is to provide the user with an easy-to-use,
high-level interface to program algorithms involving geochemical
models: parameter calibration, error and sensitivity analysis,
thermodynamical database manipulation, up to CPU-intensive parallel
coupled reactive transport models. Among the out-of-the-box features
included in <monospace>RedModRphree</monospace>, we highlight the computation and
visualization of Pourbaix (Eh-pH) diagrams using full speciation as
computed by <monospace>PHREEQC</monospace> and the implementation of 1D advective
reactive transport supporting the use of surrogate models replacing
expensive equation-based calculations.</p>
  </abstract>
    </article-meta>
  </front>
<body>
      

<sec id="Ch1.S1" sec-type="intro">
  <label>1</label><title>Introduction</title>
      <p id="d1e123">GNU R <xref ref-type="bibr" rid="bib1.bibx19" id="paren.1"/> is an open source software environment and
programming language originally developed for statistical computing
and graphics as new implementation of the closed source S language.
Its expressive and elegant syntax combines elements of object-oriented
and functional languages and is perfectly suited to represent
computational problems in an extremely concise way. R's comprehensive
numerical capabilities and its collaborative development nature has
attracted a large user base over the years, leading to its
establishment as <italic>de facto</italic> standard language in many areas of
mathematics, statistics and machine learning, and as one of the most
successful open source projects overall. R is more and more extending
its ecosystem to different applied sciences, including geosciences,
where the language's core strengths and its extremely large toolbox of
user contributed extension packages benefit the daily work of
students, academics and professionals alike. At the moment of writing,
over 17750 user-contributed extension packages have been submitted to
the official repository called Comprehensive R Archive Network (CRAN).
Indices of these packages, termed “Task Views” <xref ref-type="bibr" rid="bib1.bibx20 bib1.bibx21" id="paren.2"/>, are provided by domain experts to offer guidance in
navigating such an ample landscape by organizing them under specific
topics. For example, the Task View Chemometrics and Computational
Physics <xref ref-type="bibr" rid="bib1.bibx14" id="paren.3"/> lists over 80 packages covering many
aspects of data analysis relevant for chemistry and physics
experiments, and the simulation of physico-chemico systems;
furthermore, it points to other related Task Views of obvious interest
such as Differential Equations and Multivariate Analysis.</p><?xmltex \setfigures?><?xmltex \setlistings?><?xmltex \floatpos{t}?><fig id="Ch1.F1" specific-use="star"><?xmltex \currentcnt{1}?><?xmltex \def\figurename{Listing}?><label>Listing 1</label><caption><p id="d1e141">R code used to obtain the git
version of <monospace>RedModRphree</monospace>.</p></caption>
        <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l01.png"/>

      </fig>

      <?xmltex \floatpos{t}?><fig id="Ch1.F2" specific-use="star"><?xmltex \currentcnt{2}?><?xmltex \def\figurename{Listing}?><label>Listing 2</label><caption><p id="d1e156">Code snippet illustrating the
manipulation of an exemplary input script to compute calcite
solubility in a 0.1 molal NaCl solution.</p></caption>
        <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l02.png"/>

      </fig>

      <?pagebreak page34?><p id="d1e165"><?xmltex \hack{\newpage}?>Specifically for geochemistry, the <monospace>CHNOSZ</monospace> package
<xref ref-type="bibr" rid="bib1.bibx7" id="paren.4"/> allows for thermodynamic calculations in aqueous
geochemistry and geobiochemistry based on the Helgeson-Kirkham-Flowers
(HKF) equations <xref ref-type="bibr" rid="bib1.bibx12" id="paren.5"/>, extending the capabilities of the
well known SUPCRT92 software. Furthermore, an interface to the
established geochemical simulator <monospace>PHREEQC</monospace> <xref ref-type="bibr" rid="bib1.bibx1 bib1.bibx16" id="paren.6"/> for the R language is available on CRAN as package
<monospace>phreeqc</monospace> <xref ref-type="bibr" rid="bib1.bibx2" id="paren.7"><named-content content-type="post">note the lowercase writing adopted in this
paper to distinguish it from <monospace>PHREEQC</monospace> itself</named-content></xref>.
However, this interface only exposes the Application Programming
Interface (API) of <monospace>PHREEQC</monospace> to R, and does not provide utility
functions to quickly setup new models or in general to program
algorithms involving geochemical calculations.</p>
      <p id="d1e199">The freely available extension package <monospace>RedModRphree</monospace>,
introduced with this contribution, aims at fulfilling this need. Its
goal is to enhance the user experience by streamlining repetitive
tasks connected with the utilization of <monospace>PHREEQC</monospace> for
computing-intensive tasks, leveraging at the same time the software
infrastructure offered by the R environment. <monospace>RedModRphree</monospace>
supersedes a discontinued package called <monospace>Rphree</monospace>
<xref ref-type="bibr" rid="bib1.bibx4" id="paren.8"><named-content content-type="pre"><uri>https://rphree.r-forge.r-project.org/</uri>, last access: 30 September 2021</named-content></xref>,
which involved modifications of <monospace>PHREEQC</monospace>'s source code at c
level. The availability of the <monospace>phreeqc</monospace> extension package
<xref ref-type="bibr" rid="bib1.bibx2" id="paren.9"/>, on par with each new <monospace>PHREEQC</monospace>'s release
made this approach superfluous.</p>
      <p id="d1e234">New functionalities and applications have been added to
<monospace>RedModRphree</monospace> over the years. In particular, the package
version 0.3.6 includes a novel implementation of Pourbaix diagrams
computation following the suggestions of <xref ref-type="bibr" rid="bib1.bibx13" id="text.10"/>, which
will be explained and demonstrated in Sect. <xref ref-type="sec" rid="Ch1.S3.SS1"/>.
Advective one-dimensional reactive transport simulations which can use
surrogates to speedup lengthy <monospace>PHREEQC</monospace> calculation are
discussed in Sect. <xref ref-type="sec" rid="Ch1.S3.SS2"/>. Before diving into
these applications, however, in the next section we provide a general
overview of <monospace>RedModRphree</monospace>, its logic and its fundamentals
illustrated with code examples.</p>

      <?xmltex \floatpos{t}?><fig id="Ch1.F3" specific-use="star"><?xmltex \currentcnt{3}?><?xmltex \def\figurename{Listing}?><label>Listing 3</label><caption><p id="d1e256">Exemplary usage of the
<monospace>Distribute</monospace> function to create input scripts “distributing”
varying values of a given property, in this case calcite solubility as
function of temperature in 16 steps from 25 to 100 <inline-formula><mml:math id="M1" display="inline"><mml:msup><mml:mi/><mml:mo>∘</mml:mo></mml:msup></mml:math></inline-formula>C.</p></caption>
        <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l03.png"/>

      </fig>

      <?xmltex \floatpos{t}?><fig id="Ch1.F4" specific-use="star"><?xmltex \currentcnt{4}?><?xmltex \def\figurename{Listing}?><label>Listing 4</label><caption><p id="d1e280">Running the simulation with
<monospace>phreeqc</monospace> functions.</p></caption>
        <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l04.png"/>

      </fig>

</sec>
<sec id="Ch1.S2">
  <label>2</label><title>Methods</title>
<sec id="Ch1.S2.SS1">
  <label>2.1</label><title>Package description</title>
      <p id="d1e307"><monospace>PHREEQC</monospace> itself operates by interpreting input scripts written
in its own syntax, and outputting the results either as formatted text
or as data tables. Thus, the primary need for a high-level interface
to the chemical engine is offering comfortable mechanisms to create,
manipulate and check the input scripts and to parse the structured
text outputs. Much of <monospace>RedModRphree</monospace> code is hence related to
text manipulation.</p>
      <p id="d1e315">Several programmatic design choices were made in the development of
<monospace>RedModRphree</monospace>:
<list list-type="bullet"><list-item>
      <p id="d1e323">the user is assumed to be familiar with <monospace>PHREEQC</monospace> and its
syntax. The package does not hide it under own classes or
abstractions, and instead only provides functions to manipulate
input scripts and obtain calculations' results back into the R
runtime;</p></list-item><list-item>
      <p id="d1e330">minimal number of external dependencies, meaning that code is in
standard R for maximum portability, maintenance and ease of
installation;</p></list-item><list-item>
      <p id="d1e334">code is platform-independent, however development and testing
are mainly focused on POSIX operating systems such as Linux.</p></list-item></list></p>
      <p id="d1e337">The current <monospace>RedModRphree</monospace> version 0.3.6 supports
<monospace>PHREEQC</monospace> keywords <monospace>EQUILIBRIUM_PHASES</monospace> and
<monospace>KINETICS</monospace>. Support of further options such as surface
complexation, solid solutions and isotope is planned for future
versions.</p>
</sec>
<?pagebreak page35?><sec id="Ch1.S2.SS2">
  <label>2.2</label><title>Basic usage demonstration</title>
      <p id="d1e360"><monospace>RedModRphree</monospace> version 0.3.6, which is the version considered
in this paper, can be downloaded from Zenodo
(<ext-link xlink:href="https://doi.org/10.5281/zenodo.5046427" ext-link-type="DOI">10.5281/zenodo.5046427</ext-link>) or by anonymous download
from the git server of GFZ. The commands given in
Listing <xref ref-type="fig" rid="Ch1.F1"/> install it along with the required
dependencies.</p>
      <p id="d1e370"><monospace>RedModRphree</monospace> provides utility functions to manipulate input
scripts, which are represented in R as character vectors whose
elements correspond to a line of a <monospace>PHREEQC</monospace> input script. The
current <monospace>RedModRphree</monospace> version does not support line
continuation (i.e., logical lines splitted across different actual
text lines), so the user must be aware of this convention.</p>
      <p id="d1e381">The fundamental input manipulations are provided by the functions
<monospace>AddProp</monospace> and <monospace>RepSol</monospace>. The first adds to a base script
a property such as a concentration or an equilibrium mineral and
should be called explicitly for each new property added.
Listing <xref ref-type="fig" rid="Ch1.F2"/> illustrates its use leveraging the
<italic>pipe</italic> operator <monospace>%&gt;%</monospace> for code clarity, which must be
enabled explicitly since it is not loaded by the package itself. When
calling <monospace>AddProp</monospace>, the user must specify to which logical block
the new property belongs as per standard <monospace>PHREEQC</monospace> syntax. This
can be one of <monospace>tot</monospace> (a property belonging under the
<monospace>SOLUTION</monospace> keyword, e.g. pH, temperature or total element
concentrations), <monospace>pphases</monospace> (a mineral or a gas at equilibrium,
from the conventional name “pure phases” used in <monospace>PHREEQC</monospace>;
the package always adopts the <monospace>PURE</monospace> alternative keyword to
<monospace>EQUILIBRIUM_PHASES</monospace>) or <monospace>kin</monospace> (for <monospace>KINETICS</monospace>
blocks). <monospace>RepSol</monospace> repeats a template script a specified amount
of times.</p>

      <?xmltex \floatpos{t}?><fig id="Ch1.F5" specific-use="star"><?xmltex \currentcnt{5}?><?xmltex \def\figurename{Listing}?><label>Listing 5</label><caption><p id="d1e436">Parse a <monospace>PHREEQC</monospace> output
with the <monospace>ReadOut</monospace> function.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l05.png"/>

        </fig>

      <?xmltex \floatpos{t}?><fig id="Ch1.F6" specific-use="star"><?xmltex \currentcnt{6}?><?xmltex \def\figurename{Listing}?><label>Listing 6</label><caption><p id="d1e453">Generate a
<monospace>SELECTED_OUTPUT</monospace> block from an already calculated simulation
parsed by the <monospace>ReadOut</monospace> function.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l06.png"/>

        </fig>

      <?xmltex \floatpos{t}?><fig id="Ch1.F7" specific-use="star"><?xmltex \currentcnt{7}?><?xmltex \def\figurename{Listing}?><label>Listing 7</label><caption><p id="d1e470">Using the generated
<monospace>SELECTED_OUTPUT</monospace> block with function <monospace>RunPQC</monospace>.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l07.png"/>

        </fig>

      <p id="d1e485">The next step is to use this basic template script to create
meaningful calculations. The fundamental mechanism provided by
<monospace>RedModRphree</monospace> is the function <monospace>Distribute</monospace> (and its
variant <monospace>DistributeKin</monospace> which deals specifically with kinetic
blocks). In Listing <xref ref-type="fig" rid="Ch1.F3"/> is demonstrated how to create
an input script which computes the solubility of calcite as function
of temperature, varying it between 25 and 100 <inline-formula><mml:math id="M2" display="inline"><mml:msup><mml:mi/><mml:mo>∘</mml:mo></mml:msup></mml:math></inline-formula>C.</p>
      <p id="d1e508">By inspecting the new <monospace>simT</monospace> input buffer, it becomes clear
that the initial template script was repeated 16 times, each with a
different value of temperature. The new script can then be run with
<monospace>phreeqc</monospace>-provided functions.</p>
      <p id="d1e518">The results of these <monospace>PHREEQC</monospace> calculations are stored as text
buffer in the <monospace>out</monospace> variable <xref ref-type="fig" rid="Ch1.F4"/>, using its
standard format. <monospace>RedModRphree</monospace> provides functions to parse
such output and obtain the numerical values as R objects (function
<monospace>ReadOut</monospace>, Listing <xref ref-type="fig" rid="Ch1.F5"/>). In particular,
<monospace>ReadOut</monospace> returns a list where each element is one simulation
in the output buffer, and each simulation itself is a set of tabular
data (specifically, <monospace>data.frame</monospace>s in R) corresponding to the
logical blocks in the output file. These logical blocks are named
<monospace>desc</monospace> (some descriptive parameters about the calculated
solutions such as<?pagebreak page36?> pe, pH and ionic strength), <monospace>tot</monospace> (total
elements concentrations), <monospace>SI</monospace> (saturation indices of
minerals), <monospace>pphases</monospace> (equilibrium minerals) and
<monospace>species</monospace> (concentration of dissolved species).</p>
      <p id="d1e560">It is possible to transform back such a list to a valid
<monospace>PHREEQC</monospace> input using the function <monospace>InputFromList</monospace>.
Another way to obtain the needed results from <monospace>PHREEQC</monospace> is by
specifying a <monospace>SELECTED_OUTPUT</monospace> or <monospace>USER_PUNCH</monospace>. When
such blocks are specified, a data.frame containing the numerical
values is directly returned to R from <monospace>phreeqc</monospace>. A simple
mechanism to generate a <monospace>SELECTED_OUTPUT</monospace> block from a parsed
simulation is provided by function <monospace>FormSelectedOutput</monospace>
(Listing <xref ref-type="fig" rid="Ch1.F6"/>).</p>
      <p id="d1e590"><monospace>res2</monospace> is the resulting table containing all the variables
included in the <monospace>SELECTED_OUTPUT</monospace> block.</p>
</sec>
<sec id="Ch1.S2.SS3">
  <label>2.3</label><title>Parallel computations</title>
      <p id="d1e606">R offers an easy way to parallelize computing-intensive tasks. In
<monospace>RedModRphree</monospace> this capability is leveraged making use of the
extension packages <monospace>foreach</monospace> and <monospace>doParallel</monospace>. In
particular the <monospace>RunPQC</monospace> function offers the option of parallel
computing, however in this case it expects as input a list of input
scripts which represent the tasks to be parallelized. A simple example
of parallel computation of 320 simulations on 4 CPUs is given in
listing <xref ref-type="fig" rid="Ch1.F8"/>.</p>

      <?xmltex \floatpos{t}?><fig id="Ch1.F8" specific-use="star"><?xmltex \currentcnt{8}?><?xmltex \def\figurename{Listing}?><label>Listing 8</label><caption><p id="d1e625">Example of parallel execution
with function <monospace>RunPQC</monospace>.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l08.png"/>

        </fig>

      <p id="d1e637">The <monospace>res3</monospace> variable contains the selected output corresponding
to the 320 rows of the <monospace>df</monospace> data.frame. R offers many options
to visualize three-dimensional data. Listing <xref ref-type="fig" rid="Ch1.F9"/> gives an
example of interactive visualization using the <monospace>plotly</monospace> package
<xref ref-type="bibr" rid="bib1.bibx18" id="paren.11"/>. The resulting picture is interactive and opens in a
browser. A screenshot is given in Fig. <xref ref-type="fig" rid="Ch1.F10"/>.</p>

      <?xmltex \floatpos{t}?><fig id="Ch1.F9" specific-use="star"><?xmltex \currentcnt{9}?><?xmltex \def\figurename{Listing}?><label>Listing 9</label><caption><p id="d1e660">3D visualization of the
computed solubility of calcite as function of temperature and NaCl
salinity using package <monospace>plotly</monospace>.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l09.png"/>

        </fig>

<?xmltex \setfigures?><?xmltex \floatpos{t}?><fig id="Ch1.F10"><?xmltex \currentcnt{1}?><?xmltex \def\figurename{Figure}?><label>Figure 1</label><caption><p id="d1e675">Screenshot of the interactive visualization of the results
of the calcite solubility as function of <inline-formula><mml:math id="M3" display="inline"><mml:mi>T</mml:mi></mml:math></inline-formula> and salinity computed
with Listing <xref ref-type="fig" rid="Ch1.F8"/>.</p></caption>
          <?xmltex \igopts{width=241.848425pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-f01.png"/>

        </fig>

      <?xmltex \floatpos{t}?><fig id="Ch1.F11"><?xmltex \currentcnt{2}?><?xmltex \def\figurename{Figure}?><label>Figure 2</label><caption><p id="d1e695">Pourbaix diagrams of copper across aqueous and solid
species, using the <monospace>llnl.dat</monospace> thermodynamical database.
Since at each point of the diagram all equilibrium activities are
considered, the boundaries between predominance regions are no
longer straight lines but curves. The interpretation of these
diagrams requires expert knowledge. For example, kinetic
limitation would prevent precipitation of delafossite from aqueous
phase at 25 <inline-formula><mml:math id="M4" display="inline"><mml:msup><mml:mi/><mml:mo>∘</mml:mo></mml:msup></mml:math></inline-formula>C <xref ref-type="bibr" rid="bib1.bibx11" id="paren.12"/>.</p></caption>
          <?xmltex \igopts{width=241.848425pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-f02.png"/>

        </fig>

</sec>
<sec id="Ch1.S2.SS4">
  <label>2.4</label><title>Additional resources: demos and documentation</title>
      <p id="d1e727">The previous sections showcase a simple working session with the
package. These functions are the fundamental building blocks needed to
quickly create complex calculations, and can be easily leveraged to
efficiently implement algorithms involving geochemical models, such as
reactive transport simulations. The package includes further utilities
to deal with <monospace>KINETICS</monospace> blocks and to parse and manipulate
thermodynamical databases, which are not covered in this manuscript,
and for which the reader is referred to the package documentation and
demo.</p>
      <p id="d1e733"><monospace>RedModRphree</monospace> ships with functions' documentation, usage
examples and with a set of demos which illustrate in more detail
different use cases not covered in this manuscript
(Listing <xref ref-type="fig" rid="Ch1.F12"/>). The code of the included demos is commented
and intended as additional documentation.</p><?xmltex \setfigures?><?xmltex \setlistings?><?xmltex \floatpos{t}?><fig id="Ch1.F12" specific-use="star"><?xmltex \currentcnt{10}?><?xmltex \def\figurename{Listing}?><label>Listing 10</label><caption><p id="d1e743">Commands to list all functions
and demos and run one.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l10.png"/>

        </fig>

      <p id="d1e753">In particular, several demos focus on the use of pre-trained emulators
or surrogates instead of more computationally expensive
<monospace>PHREEQC</monospace> calculations in 1D advective reactive transport
simulations <xref ref-type="bibr" rid="bib1.bibx5" id="paren.13"/>. Surrogates are machine learning
regressors able to reproduce a multivariate output as function of
multivariate input. They must be trained in advance on a set of
<monospace>PHREEQC</monospace> simulations, and can then be plugged-in in coupled
reactive transport simulations for speedup. More details concerning
the reactive transport capabilities of RedModRphree are given in
Sect. <xref ref-type="sec" rid="Ch1.S3.SS2"/>.</p>
</sec>
</sec>
<sec id="Ch1.S3">
  <label>3</label><title>Applications</title>
<sec id="Ch1.S3.SS1">
  <label>3.1</label><title>Pourbaix diagrams</title>
      <p id="d1e783">Pourbaix or Eh-pH diagrams were first introduced by the Belgian
chemist Marcel Pourbaix in 1945. They are standard phase diagrams with
electrochemical potential (Eh or pe) and pH as axes, and are a
valuable tool in electrochemistry, material science and in general in
aqueous chemistry and geochemistry <xref ref-type="bibr" rid="bib1.bibx9 bib1.bibx8" id="paren.14"/>,
since they synthetically summarize the thermodynamically stable phases
(i.e., at chemical equilibrium) of an aqueous electrochemical system.
Since they are based on thermodynamics, like all phase diagrams, they
do not account for reaction rates or kinetic effects. Classically, the
boundaries between predominant chemical species (aqueous ions in
solution or solid phases) are straight lines computed directly by
evaluating Nernst and Law of Mass Action equations and imposing a
condition of equality between two species' activities. Such approach
is for example employed by the <monospace>CHNOSZ</monospace> package
<xref ref-type="bibr" rid="bib1.bibx7" id="paren.15"/>. However, beside potential and pH, the equilibrium
activities depend also upon temperature, pressure, and, crucially, on
the activities of all other dissolved species in the considered
system. This makes the classical approach illicit from a rigorous
standpoint <xref ref-type="bibr" rid="bib1.bibx13" id="paren.16"/>. In<?pagebreak page37?> particular, the predominance
region for a given species should be defined as the locus of points in
the diagram where its activity is larger than the activities of
<italic>all</italic> other species. The borders between regions would not result
in straight lines anymore, but curves.</p>
      <p id="d1e801"><monospace>PHREEQC</monospace> offers the capability to calculate the speciation of
a solution in its entirety; and using <monospace>RedModRphree</monospace> it is
simple to achieve a more realistic predominance diagram as suggested
by <xref ref-type="bibr" rid="bib1.bibx13" id="text.17"/>. This has been implemented in the
<monospace>Pourbaix</monospace> function, which performs the computations and
visualizes the diagram in a convenient way. The user provides a base
script describing the solution and defines at which levels of pe and
pH the speciation must be calculated; the function computes all
combinations of these levels in a dense grid, restricted to the
stability region of water, approximated by the limiting boundaries for
release of molecular hydrogen and oxygen respectively
(Eqs. <xref ref-type="disp-formula" rid="Ch1.E1"/>, <xref ref-type="disp-formula" rid="Ch1.E2"/>), not considering the effect of temperature.

                <disp-formula specific-use="gather" content-type="numbered"><mml:math id="M5" display="block"><mml:mtable displaystyle="true"><mml:mlabeledtr id="Ch1.E1"><mml:mtd><mml:mtext>1</mml:mtext></mml:mtd><mml:mtd><mml:mrow><mml:mstyle displaystyle="true" class="stylechange"/><mml:mrow class="chem"><mml:mi mathvariant="normal">pe</mml:mi></mml:mrow><mml:mo>=</mml:mo><mml:mn mathvariant="normal">0</mml:mn><mml:mo>-</mml:mo><mml:mrow class="chem"><mml:mi mathvariant="normal">pH</mml:mi></mml:mrow><mml:mspace width="2em" linebreak="nobreak"/><mml:mtext>release of free hydrogen</mml:mtext></mml:mrow></mml:mtd></mml:mlabeledtr><mml:mlabeledtr id="Ch1.E2"><mml:mtd><mml:mtext>2</mml:mtext></mml:mtd><mml:mtd><mml:mrow><mml:mstyle displaystyle="true" class="stylechange"/><mml:mrow class="chem"><mml:mi mathvariant="normal">pe</mml:mi></mml:mrow><mml:mo>=</mml:mo><mml:mn mathvariant="normal">20.75</mml:mn><mml:mo>-</mml:mo><mml:mrow class="chem"><mml:mi mathvariant="normal">pH</mml:mi></mml:mrow><mml:mspace linebreak="nobreak" width="2em"/><mml:mtext>release of free oxygen</mml:mtext></mml:mrow></mml:mtd></mml:mlabeledtr></mml:mtable></mml:math></disp-formula></p>
      <p id="d1e869">The corresponding simulations are computed in parallel if the
<monospace>procs</monospace> argument is larger than one. Then from the results for
each simulation point, the mineral with largest positive saturation
index is extracted, or, if none has positive SI, the largest activity
of all the dissolved species. Once all the data are collected, the
whole parameter space is displayed assigning a different colour for
each phase. Each region is labelled with the brute formula of the
represented species, written in italic font under their name for the
minerals. Optionally the function restricts the diagram only to phases
or species containing one element, specified by the <monospace>element</monospace>
argument. If left unspecified, then all computed saturation indices
and activities are considered in the diagram. The current version of
<monospace>Pourbaix()</monospace> does not support the inclusion of pure phases<?pagebreak page38?> at
equilibrium with the system, such as partial pressure of
<inline-formula><mml:math id="M6" display="inline"><mml:mrow class="chem"><mml:msub><mml:mi mathvariant="normal">CO</mml:mi><mml:mn mathvariant="normal">2</mml:mn></mml:msub><mml:mo>(</mml:mo><mml:mi mathvariant="normal">g</mml:mi><mml:mo>)</mml:mo></mml:mrow></mml:math></inline-formula>. Furthermore, no check is performed whether the
resulting equilibrated solutions have a different pH or pe than the
values specified in the input for each simulation point. Frequent
numerical instabilities and non-convergence of simulations happen near
the boundaries of the water stability region, in particular for large
pe values. Since no error control mechanism is implemented in the
current <monospace>RedModRphree</monospace> version, the user is recommended to
restrict the range of pe and pH and to try different resolutions of
the calculation grid.</p>
      <p id="d1e901">Figure <xref ref-type="fig" rid="Ch1.F11"/> (Listing <xref ref-type="fig" rid="Ch1.F13"/>) displays
the Pourbaix diagram for copper speciation in a solution containing
Na, Cl, Ca and Fe, on a <inline-formula><mml:math id="M7" display="inline"><mml:mrow><mml:mn mathvariant="normal">101</mml:mn><mml:mo>×</mml:mo><mml:mn mathvariant="normal">101</mml:mn></mml:mrow></mml:math></inline-formula> grid for a total of 8239 simulations
inside the water stability region, which computes in under three
seconds employing two CPUs.</p>

      <?xmltex \floatpos{t}?><fig id="Ch1.F13" specific-use="star"><?xmltex \currentcnt{11}?><?xmltex \def\figurename{Listing}?><label>Listing 11</label><caption><p id="d1e923">R code used to obtain
Fig. <xref ref-type="fig" rid="Ch1.F11"/>, which represents the equilibrium speciation of
<inline-formula><mml:math id="M8" display="inline"><mml:mrow><mml:msup><mml:mn mathvariant="normal">10</mml:mn><mml:mrow><mml:mo>-</mml:mo><mml:mn mathvariant="normal">3</mml:mn></mml:mrow></mml:msup></mml:mrow></mml:math></inline-formula> moles of copper in 1 kg of water in presence of total
dissolved Ca, Cl, Na and Fe concentrations as indicated in the
picture.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l11.png"/>

        </fig>

      <p id="d1e948">Specifying <monospace>aqonly=TRUE</monospace> restricts the diagram to aqueous
species only. In this case, the user can specify a specific valence
state for the <monospace>element</monospace> argument, for example with
<monospace>element='Fe(2)'</monospace>. This option is only reliable for aqueous
species since the valence state of an element in minerals is not
readily obtainable by parsing the stoichiometric equations in a
<monospace>PHREEQC</monospace> database. Finally, the user can specify a list of
species or phases to be excluded from the diagram, enumerating them
using the argument <monospace>suppress</monospace>.</p>
      <p id="d1e966">A Pourbaix diagram is a synthetic way to highlight discrepancies in
different thermodynamic databases, indicating the need for a closer
inspection of the applied databases<?pagebreak page39?> and/or more experimental data to
support them. Figure <xref ref-type="fig" rid="Ch1.F14"/>
(Listing <xref ref-type="fig" rid="Ch1.F15"/>) showcases the aqueous speciation of
iron computed by evaluating the same base solution with the
<monospace>phreeqc.dat</monospace> and <monospace>llnl.dat</monospace> databases. It is apparent
that the stability region of ferric oxyhydroxide <inline-formula><mml:math id="M9" display="inline"><mml:mrow class="chem"><mml:msup><mml:mi mathvariant="normal">Fe</mml:mi><mml:mi mathvariant="normal">III</mml:mi></mml:msup><mml:mo>(</mml:mo><mml:mi mathvariant="normal">OH</mml:mi><mml:msub><mml:mo>)</mml:mo><mml:mn mathvariant="normal">3</mml:mn></mml:msub></mml:mrow></mml:math></inline-formula>
is quite different following the two databases.</p><?xmltex \setfigures?><?xmltex \floatpos{p}?><fig id="Ch1.F14" specific-use="star"><?xmltex \currentcnt{3}?><?xmltex \def\figurename{Figure}?><label>Figure 3</label><caption><p id="d1e1001">Pourbaix diagrams of aqueous iron speciation at
25 <inline-formula><mml:math id="M10" display="inline"><mml:msup><mml:mi/><mml:mo>∘</mml:mo></mml:msup></mml:math></inline-formula>C and <inline-formula><mml:math id="M11" display="inline"><mml:mrow><mml:mi>p</mml:mi><mml:mo>=</mml:mo><mml:mn mathvariant="normal">01</mml:mn></mml:mrow></mml:math></inline-formula>:00 atm using two different thermodynamic
databases: <bold>(a)</bold> phreeqc.dat and <bold>(b)</bold> llnl.dat.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-f03.png"/>

        </fig>

<?xmltex \setfigures?><?xmltex \setlistings?><?xmltex \floatpos{p}?><fig id="Ch1.F15" specific-use="star"><?xmltex \currentcnt{12}?><?xmltex \def\figurename{Listing}?><label>Listing 12</label><caption><p id="d1e1042">R code used to obtain
Figure <xref ref-type="fig" rid="Ch1.F14"/>.</p></caption>
          <?xmltex \igopts{width=503.61378pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-l12.png"/>

        </fig>

<?xmltex \setfigures?><?xmltex \floatpos{t}?><fig id="Ch1.F16" specific-use="star"><?xmltex \currentcnt{4}?><?xmltex \def\figurename{Figure}?><label>Figure 4</label><caption><p id="d1e1056">Profiles of variables across a 1D domain resulting from
kinetic reactive transport simulations computed with the
<monospace>ReactTranspBalanceKin</monospace> function and <monospace>PHREEQC</monospace>'s
<monospace>ADVECTION</monospace> keyword respectively, for validation. A
<inline-formula><mml:math id="M12" display="inline"><mml:mrow class="chem"><mml:msub><mml:mi mathvariant="normal">MgCl</mml:mi><mml:mn mathvariant="normal">2</mml:mn></mml:msub></mml:mrow></mml:math></inline-formula> solution is injected from the left inlet of the
domain which is initially at equilibrium with calcite, triggering
the transient precipitation of Dolomite. Displayed are the
relevant total dissolved concentrations and amounts of minerals
(scale on the left <inline-formula><mml:math id="M13" display="inline"><mml:mi>y</mml:mi></mml:math></inline-formula>-axis) and pH (in gray, right <inline-formula><mml:math id="M14" display="inline"><mml:mi>y</mml:mi></mml:math></inline-formula>-axis) after 30
coupling iterations. The code used to produce this picture is
included in the package as <monospace>demo-validate</monospace>.</p></caption>
          <?xmltex \igopts{width=398.338583pt}?><graphic xlink:href="https://adgeo.copernicus.org/articles/56/33/2021/adgeo-56-33-2021-f04.png"/>

        </fig>

      <p id="d1e1103">A major advantage of a Pourbaix diagram computed in this way is that
it can be applied to “real” solutions of any complexity, not being
restricted to pure systems of 4 or 5 components as in the classical
approach. Furthermore, it is straightforward to implement the same
kind of calculations as result of kinetic simulations, thus removing
the last limitation shared with the classical diagrams. In facts, in
most natural systems even if a mineral is thermodynamically the most
favoured in a specific diagram region, other minerals with lower
saturation index but faster kinetics may be the phases actually formed
<xref ref-type="bibr" rid="bib1.bibx13" id="paren.18"/>.</p>
</sec>
<sec id="Ch1.S3.SS2">
  <label>3.2</label><title>1D reactive transport using surrogate models</title>
      <?pagebreak page41?><p id="d1e1117">A further application provided by <monospace>RedModRphree</monospace> pertains to 1D
reactive transport models. The functions <monospace>ReactTranspBalanceEq</monospace>
and <monospace>ReactTranspBalanceKin</monospace> implement, for equilibrium minerals
and kinetics respectively, a sequential non-iterative coupling between
transport and chemistry similar to the <monospace>PHREEQC</monospace>'s
<monospace>ADVECTION</monospace> keyword, however disregarding heat transport and
changes in porosity and hence assuming stationary Darcy flow. In
particular, these functions transport total elements concentrations –
a valid assumption in case of pure advection – and the proton and
electron activities instead of total H, total O and charge imbalance,
as done by <monospace>PHREEQC</monospace> internally <xref ref-type="bibr" rid="bib1.bibx17" id="paren.19"/>.
Figure <xref ref-type="fig" rid="Ch1.F16"/> shows a visual validation of this
simplified advection approach by comparing the results of a reactive
transport benchmark on a one-dimensional grid with 50 elements
computed once with <monospace>PHREEQC</monospace>'s <monospace>ADVECTION</monospace> and once with
<monospace>ReactTranspBalanceKin</monospace>. The whole computation is included in
<monospace>RedModRphree</monospace> as <monospace>demo-validate</monospace>). In the benchmark, a
<inline-formula><mml:math id="M15" display="inline"><mml:mrow class="chem"><mml:msub><mml:mi mathvariant="normal">MgCl</mml:mi><mml:mn mathvariant="normal">2</mml:mn></mml:msub></mml:mrow></mml:math></inline-formula> solution is injected at the left inlet in a medium
initially at equilibrium with calcite. This reactive solution triggers
the dissolution of calcite and the transient precipitation of
dolomite. All reactions involving minerals are kinetically controlled
with a Lasaga rate law <xref ref-type="bibr" rid="bib1.bibx15" id="paren.20"/>. After 30 iterations with
fixed time step of 999 s, the variables' profiles across the
domain resulting from the two simulations are perfectly superposable,
up to some negligible error imputable to truncation of floating point
numbers occurring when passing from <monospace>PHREEQC</monospace>'s c<inline-formula><mml:math id="M16" display="inline"><mml:mrow><mml:mo>+</mml:mo><mml:mo>+</mml:mo></mml:mrow></mml:math></inline-formula> domain and
R, which happens through strings.</p>
      <p id="d1e1187">Furthermore, the above mentioned functions implement an acceleration
technique which at each iteration minimizes the chemical evaluations
by identifying grid elements with nearly equal geochemical problems
<xref ref-type="bibr" rid="bib1.bibx4" id="paren.21"/>. This is achieved by compressing the matrix used
to represent the governing variables for the whole grid (one row per
grid element, one column per concentration). This option is fully
automatic and can be activated by setting argument
<monospace>reduce=TRUE</monospace>. It achieves important speedups for initially
homogeneous systems. Moreover, the simulations are again internally
parallelized when argument <monospace>procs</monospace> is larger than one. The
users are referred to the specific functions documentation for more
usage details.</p>
      <p id="d1e1199">The main motivation for the development of these reactive transport
functions was investigating the substitution of equation-based
numerical solution of the chemical sub-process with a pre-trained
statistical surrogate for computational speedup <xref ref-type="bibr" rid="bib1.bibx10 bib1.bibx6 bib1.bibx5" id="paren.22"><named-content content-type="post">which points
to more advanced numerical experiments than those included as demo
into the package</named-content></xref>. The user
can activate this capability by providing a named list containing the
trained regressors and an R function which uses them to perform the
surrogate geochemistry calculations. This surrogate function is then
called after each advective step, and its predictions are checked for
plausibility by computing mass balances. The predictions trespassing a
user-imposed threshold are rejected and in their place
<monospace>PHREEQC</monospace> simulations are run instead. This process is repeated
at each transport-chemistry iteration.</p>
      <p id="d1e1210">Five of <monospace>RedModRphree</monospace>'s demos extensively illustrate the usage
of its reactive transport capability. <monospace>demo-validate</monospace>,
<monospace>demo-equilibrium</monospace> and <monospace>demo-kinetics</monospace> are simulations
using only <monospace>PHREEQC</monospace>; <monospace>demo-eq-surr-RF</monospace> and
<monospace>demo-kin-surr-RF</monospace> use Random Forests as surrogates for the
equilibrium and kinetic version of the same reactive transport
problem.</p>
</sec>
</sec>
<sec id="Ch1.S4" sec-type="conclusions">
  <label>4</label><title>Conclusions</title>
      <p id="d1e1244">The richness of high-quality third-party applications, the large
number of users and the overall maturity and stability of its code
base make R an attractive computing platform for geoscientists and in
particular for geochemists.</p>
      <p id="d1e1247">The free and open source <monospace>RedModRphree</monospace> package offers
high-level programming utilities and out-of-the-box applications to
enhance users' productivity when working with <monospace>PHREEQC</monospace>
geochemical models. The utility functions provided by
<monospace>RedModRphree</monospace> help to rapidly perform many parallelized
calculations and collect the corresponding results as required, e.g.,
in sensitivity and uncertainty analyses, thus profiting from the
excellence of the R ecosystem in that area and its graphics
capabilities for visualization.</p>
      <p id="d1e1259">The <monospace>RedModRphree</monospace> version 0.3.6 offers novel applications of
general interest for geochemists, in particular the calculation of
Pourbaix diagrams based on the actual full speciation of complex
aqueous systems. It is a valuable computational tool which overcomes
some limitations of classical stability diagrams. Further development
will aim at including<?pagebreak page42?> kinetic control of reactions, three-dimensional
stability diagrams, and having different variables as one of the axes,
for example partial pressure of <inline-formula><mml:math id="M17" display="inline"><mml:mrow class="chem"><mml:msub><mml:mi mathvariant="normal">CO</mml:mi><mml:mrow><mml:mn mathvariant="normal">2</mml:mn><mml:mo>(</mml:mo><mml:mi mathvariant="normal">g</mml:mi><mml:mo>)</mml:mo></mml:mrow></mml:msub></mml:mrow></mml:math></inline-formula>.</p>
      <p id="d1e1283">The package release is meant to attract users and foster collaborative
development in order to increase both the coverage of <monospace>PHREEQC</monospace>
functionalities and number and scope of provided applications.</p>
</sec>

      
      </body>
    <back><notes notes-type="codeavailability"><title>Code availability</title>

      <p id="d1e1294">RedModRphree is released under LGPL v2.1 license. A
copy of the 0.3.6 version of the package has been stored on Zenodo
at <ext-link xlink:href="https://doi.org/10.5281/zenodo.5046427" ext-link-type="DOI">10.5281/zenodo.5046427</ext-link> <xref ref-type="bibr" rid="bib1.bibx3" id="paren.23"/>. Until the process of
inclusion into the Comprehensive R Archive Network (CRAN) is
completed, development versions can be installed from
<uri>https://git.gfz-potsdam.de/delucia/RedModRphree</uri>, last access: 30 September 2021.</p>
  </notes><notes notes-type="authorcontribution"><title>Author contributions</title>

      <p id="d1e1309">MDL shaped the research, performed analyses,
programming and wrote the manuscript. MK helped providing funding,
shaping the research, and revised the
manuscript.</p>
  </notes><notes notes-type="competinginterests"><title>Competing interests</title>

      <p id="d1e1315">The contact author has declared that neither they nor their co-author has any competing interests.</p>
  </notes><notes notes-type="disclaimer"><title>Disclaimer</title>

      <p id="d1e1321">Publisher’s note: Copernicus Publications remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.</p>
  </notes><notes notes-type="sistatement"><title>Special issue statement</title>

      <p id="d1e1327">This article is part of the special issue “European Geosciences Union General Assembly 2021, EGU Division Energy, Resources &amp; Environment (ERE)”. It is a result of the EGU General Assembly 2021, 19–30 April 2021.</p>
  </notes><ack><title>Acknowledgements</title><p id="d1e1333">The authors gratefully acknowledge  Helge Moog and an anonymous reviewer for their suggestions which greatily improved the manuscript.</p></ack><notes notes-type="financialsupport"><title>Financial support</title>

      <p id="d1e1338">This research has been supported by the Helmholtz Association in the framework of the project “Reduced Complexity Models – Explore advanced data science techniques to create models of reduced complexity” (grant no. ZT-I-0010).<?xmltex \hack{\newline}?><?xmltex \hack{\newline}?>The article processing charges for this open-access <?xmltex \notforhtml{\newline}?>publication were covered by the Helmholtz Centre Potsdam – <?xmltex \notforhtml{\newline}?>GFZ German Research Centre for Geosciences.</p>
  </notes><notes notes-type="reviewstatement"><title>Review statement</title>

      <p id="d1e1351">This paper was edited by Sonja Martens and reviewed by Helge Moog and one anonymous referee.</p>
  </notes><ref-list>
    <title>References</title>

      <ref id="bib1.bibx1"><?xmltex \def\ref@label{{Appelo et~al.(2013)Appelo, Parkhurst, and Post}}?><label>Appelo et al.(2013)Appelo, Parkhurst, and Post</label><?label Appelo2013?><mixed-citation>Appelo, C. A. J., Parkhurst, D. L., and Post, V. E. A.: Equations for
calculating hydrogeochemical reactions of minerals and gases such as CO<inline-formula><mml:math id="M18" display="inline"><mml:msub><mml:mi/><mml:mn mathvariant="normal">2</mml:mn></mml:msub></mml:math></inline-formula> at
high pressures and temperatures, Geochim. Cosmochim. Ac., 125, 49–67, <ext-link xlink:href="https://doi.org/10.1016/j.gca.2013.10.003" ext-link-type="DOI">10.1016/j.gca.2013.10.003</ext-link>, 2013.</mixed-citation></ref>
      <ref id="bib1.bibx2"><?xmltex \def\ref@label{{Charlton and Parkhurst(2011)}}?><label>Charlton and Parkhurst(2011)</label><?label Charlton2011?><mixed-citation>Charlton, S. R. and Parkhurst, D. L.: Modules based on the geochemical model
PHREEQC for use in scripting and programming languages, Comput.
Geosci., 37, 1653–1663,
<ext-link xlink:href="https://doi.org/10.1016/j.cageo.2011.02.005" ext-link-type="DOI">10.1016/j.cageo.2011.02.005</ext-link>, 2011.</mixed-citation></ref>
      <ref id="bib1.bibx3"><?xmltex \def\ref@label{De~Lucia(2021)}?><label>De Lucia(2021)</label><?label DeLucia2021b?><mixed-citation>De Lucia, M.: RedModRphree (0.3.6), Zenodo [code], <ext-link xlink:href="https://doi.org/10.5281/zenodo.5046427" ext-link-type="DOI">10.5281/zenodo.5046427</ext-link>, last access: 30 September 2021.</mixed-citation></ref>
      <ref id="bib1.bibx4"><?xmltex \def\ref@label{{De Lucia and Kühn(2013)}}?><label>De Lucia and Kühn(2013)</label><?label DeLucia2013?><mixed-citation>De Lucia, M. and Kühn, M.: Coupling R and PHREEQC: Efficient
Programming of Geochemical Models, Energy Proced., 40, 464–471,
<ext-link xlink:href="https://doi.org/10.1016/j.egypro.2013.08.053" ext-link-type="DOI">10.1016/j.egypro.2013.08.053</ext-link>, 2013.</mixed-citation></ref>
      <ref id="bib1.bibx5"><?xmltex \def\ref@label{{De~Lucia and K\"{u}hn(2021)}}?><label>De Lucia and Kühn(2021)</label><?label DeLucia2021?><mixed-citation>De Lucia, M. and Kühn, M.: DecTree v1.0 – chemistry speedup in reactive transport simulations: purely data-driven and physics-based surrogates, Geosci. Model Dev., 14, 4713–4730, <ext-link xlink:href="https://doi.org/10.5194/gmd-14-4713-2021" ext-link-type="DOI">10.5194/gmd-14-4713-2021</ext-link>, 2021.</mixed-citation></ref>
      <ref id="bib1.bibx6"><?xmltex \def\ref@label{{De Lucia et~al.(2017){De Lucia}, Kempka, Jatnieks, and
Kühn}}?><label>De Lucia et al.(2017)De Lucia, Kempka, Jatnieks, and
Kühn</label><?label DeLucia2017?><mixed-citation>De Lucia, M., Kempka, T., Jatnieks, J., and Kühn, M.: Integrating surrogate
models into subsurface simulation framework allows computation of complex
reactive transport scenarios, Energy Proced., 125, 580–587,
<ext-link xlink:href="https://doi.org/10.1016/j.egypro.2017.08.200" ext-link-type="DOI">10.1016/j.egypro.2017.08.200</ext-link>, 2017.</mixed-citation></ref>
      <ref id="bib1.bibx7"><?xmltex \def\ref@label{{Dick(2019)}}?><label>Dick(2019)</label><?label Dick2019?><mixed-citation>Dick, J. M.: CHNOSZ: Thermodynamic Calculations and Diagrams for
Geochemistry, Front. Earth Sci., 7,
<ext-link xlink:href="https://doi.org/10.3389/feart.2019.00180" ext-link-type="DOI">10.3389/feart.2019.00180</ext-link>,   2019.</mixed-citation></ref>
      <ref id="bib1.bibx8"><?xmltex \def\ref@label{{Hennig et~al.(2020)Hennig, Stockmann, and Kühn}}?><label>Hennig et al.(2020)Hennig, Stockmann, and Kühn</label><?label Hennig2020?><mixed-citation>Hennig, T., Stockmann, M., and Kühn, M.: Simulation of diffusive uranium
transport and sorption processes in the Opalinus Clay, Appl. Geochem.,
123, 104777, <ext-link xlink:href="https://doi.org/10.1016/j.apgeochem.2020.104777" ext-link-type="DOI">10.1016/j.apgeochem.2020.104777</ext-link>, 2020.</mixed-citation></ref>
      <ref id="bib1.bibx9"><?xmltex \def\ref@label{{Huang(2016)}}?><label>Huang(2016)</label><?label Huang2016?><mixed-citation>Huang, H.-H.: The Eh-pH Diagram and Its Advances, Metals, 6, 23,
<ext-link xlink:href="https://doi.org/10.3390/met6010023" ext-link-type="DOI">10.3390/met6010023</ext-link>, 2016.</mixed-citation></ref>
      <ref id="bib1.bibx10"><?xmltex \def\ref@label{{Jatnieks et~al.(2016)Jatnieks, {De Lucia}, Dransch, and
Sips}}?><label>Jatnieks et al.(2016)Jatnieks, De Lucia, Dransch, and
Sips</label><?label Jatnieks2016?><mixed-citation>Jatnieks, J., De Lucia, M., Dransch, D., and Sips, M.: Data-driven
Surrogate Model Approach for Improving the Performance of
Reactive Transport Simulations, Energy Proced., 97, 447–453,
<ext-link xlink:href="https://doi.org/10.1016/j.egypro.2016.10.047" ext-link-type="DOI">10.1016/j.egypro.2016.10.047</ext-link>, 2016.</mixed-citation></ref>
      <ref id="bib1.bibx11"><?xmltex \def\ref@label{{John et~al.(2016)John, Heuss-Aßbichler, and Ullrich}}?><label>John et al.(2016)John, Heuss-Aßbichler, and Ullrich</label><?label John2016?><mixed-citation>John, M., Heuss-Aßbichler, S., and Ullrich, A.: Conditions and mechanisms for
the formation of nano-sized Delafossite (CuFeO<inline-formula><mml:math id="M19" display="inline"><mml:msub><mml:mi/><mml:mn mathvariant="normal">2</mml:mn></mml:msub></mml:math></inline-formula>) at temperatures <inline-formula><mml:math id="M20" display="inline"><mml:mrow><mml:mo>≤</mml:mo><mml:mn mathvariant="normal">90</mml:mn></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M21" display="inline"><mml:msup><mml:mi/><mml:mo>∘</mml:mo></mml:msup></mml:math></inline-formula>C in
aqueous solution, J. Solid State Chem., 234, 55–62,
<ext-link xlink:href="https://doi.org/10.1016/j.jssc.2015.11.033" ext-link-type="DOI">10.1016/j.jssc.2015.11.033</ext-link>, 2016.</mixed-citation></ref>
      <ref id="bib1.bibx12"><?xmltex \def\ref@label{{Johnson et~al.(1992)Johnson, Oelkers, and Helgeson}}?><label>Johnson et al.(1992)Johnson, Oelkers, and Helgeson</label><?label Johnson1992?><mixed-citation>Johnson, J. W., Oelkers, E. H., and Helgeson, H. C.: SUPCRT92: A software
package for calculating the standard molal thermodynamic properties of
minerals, gases, aqueous species, and reactions from 1 to 5000 bar and 0 to
1000 <inline-formula><mml:math id="M22" display="inline"><mml:msup><mml:mi/><mml:mo>∘</mml:mo></mml:msup></mml:math></inline-formula>C, Comput. Geosci., 18, 899–947,
<ext-link xlink:href="https://doi.org/10.1016/0098-3004(92)90029-q" ext-link-type="DOI">10.1016/0098-3004(92)90029-q</ext-link>, 1992.</mixed-citation></ref>
      <ref id="bib1.bibx13"><?xmltex \def\ref@label{{Kölling et~al.(2000)Kölling, Ebert, and Schulz}}?><label>Kölling et al.(2000)Kölling, Ebert, and Schulz</label><?label Koelling2000?><mixed-citation>Kölling, M., Ebert, M., and Schulz, H. D.: A Novel Approach to the
Presentation of pε/pH-Diagrams, in: Redox: Fundamentals, Processes
and Applications, edited by: Schüring, J., Schulz, H. D., Fischer, W. R.,
Böttcher, J., and Duijnisveld, W. H. M.,   Springer, Berlin,
Heidelberg, 55–63, <ext-link xlink:href="https://doi.org/10.1007/978-3-662-04080-5_5" ext-link-type="DOI">10.1007/978-3-662-04080-5_5</ext-link>, 2000.</mixed-citation></ref>
      <ref id="bib1.bibx14"><?xmltex \def\ref@label{{Mullen(2021)}}?><label>Mullen(2021)</label><?label TaskChemPhys?><mixed-citation>Mullen, K.: CRAN Task View: Chemometrics and Computational Physics, available at:
<uri>https://cran.r-project.org/web/views/ChemPhys.html</uri>, last access:
30 June 2021.</mixed-citation></ref>
      <ref id="bib1.bibx15"><?xmltex \def\ref@label{{Palandri and Kharaka(2004)}}?><label>Palandri and Kharaka(2004)</label><?label Palandri2004?><mixed-citation>Palandri, J. L. and Kharaka, Y. K.: A compilation of rate parameters <?pagebreak page43?>of water-mineral interaction kinetics for application to geochemical modeling, Tech. Rep., USGS Menlo Park, California, USA, available at:
<uri>https://pubs.usgs.gov/of/2004/1068/</uri> (last access: 30 September 2021), 2004.</mixed-citation></ref>
      <ref id="bib1.bibx16"><?xmltex \def\ref@label{{Parkhurst and Appelo(2013)}}?><label>Parkhurst and Appelo(2013)</label><?label Parkhurst2013?><mixed-citation>Parkhurst, D. L. and Appelo, C. A. J.: Description of input and examples for
PHREEQC version 3 – A computer program for speciation, batch-reaction,
one-dimensional transport, and inverse geochemical calculations, available at:
<uri>https://pubs.usgs.gov/tm/06/a43</uri> (last access: 30 September 2021), 2013.</mixed-citation></ref>
      <ref id="bib1.bibx17"><?xmltex \def\ref@label{{Parkhurst and Wissmeier(2015)}}?><label>Parkhurst and Wissmeier(2015)</label><?label Parkhurst2015?><mixed-citation>Parkhurst, D. L. and Wissmeier, L.: PhreeqcRM: A reaction module for
transport simulators based on the geochemical model PHREEQC, Adv.
Water Resour., 83, 176–189, <ext-link xlink:href="https://doi.org/10.1016/j.advwatres.2015.06.001" ext-link-type="DOI">10.1016/j.advwatres.2015.06.001</ext-link>, 2015.
</mixed-citation></ref><?xmltex \hack{\newpage}?>
      <ref id="bib1.bibx18"><?xmltex \def\ref@label{{Plotly~Technologies(2015)}}?><label>Plotly Technologies(2015)</label><?label plotly?><mixed-citation>Plotly Technologies, I.: Collaborative data science,
available at: <uri>https://plot.ly</uri> (last access: 30 June 2021), 2015.</mixed-citation></ref>
      <ref id="bib1.bibx19"><?xmltex \def\ref@label{{R Core Team(2021)}}?><label>R Core Team(2021)</label><?label R2021?><mixed-citation>R Core Team: R: A Language and Environment for Statistical Computing, R
Foundation for Statistical Computing, Vienna, Austria, available at:
<uri>https://www.R-project.org/</uri>, last access: 30 September 2021.</mixed-citation></ref>
      <ref id="bib1.bibx20"><?xmltex \def\ref@label{{Zeileis(2005)}}?><label>Zeileis(2005)</label><?label TaskView?><mixed-citation>Zeileis, A.: CRAN Task Views, R News, 5, 39–40, available at:
<uri>https://CRAN.R-project.org/doc/Rnews/</uri> (last access: 30 June 2021),
2005.</mixed-citation></ref>
      <ref id="bib1.bibx21"><?xmltex \def\ref@label{{Zeileis(2021)}}?><label>Zeileis(2021)</label><?label TaskViewUrl?><mixed-citation>Zeileis, A.: CRAN Task View, available at: <uri>https://cran.r-project.org/web/views/</uri>,
last access:  30 June 2021.</mixed-citation></ref>

  </ref-list></back>
    <!--<article-title-html>Geochemical and reactive transport modelling in R with the RedModRphree package</article-title-html>
<abstract-html><p>Advances in computing and experimental capabilities in the research
of water-rock-interactions require geoscientists to routinely
combine laboratory data and models to produce new knowledge. Data
science is hence a more and more pervasive instrument for
geochemists, which in turn demands flexible and easy to learn
software adaptable to their specific needs. The GNU R language and
programming environment has established itself as de facto standard
language for statistics and machine learning, enjoying increasing
diffusion in many applied scientific fields such as bioinformatics,
chemometrics and ecological modelling. The availability of excellent
third party extensions as well as its advanced graphical and
numerical capabilities make R an ideal platform for comprehensive
geochemical data analysis, experiment evaluation and modelling.</p><p>We introduce the open source <span style="" class="text typewriter">RedModRphree</span> extension
package, which leverages the R interface to the established
<span style="" class="text typewriter">PHREEQC</span> geochemical simulator. The aim of
<span style="" class="text typewriter">RedModRphree</span> is to provide the user with an easy-to-use,
high-level interface to program algorithms involving geochemical
models: parameter calibration, error and sensitivity analysis,
thermodynamical database manipulation, up to CPU-intensive parallel
coupled reactive transport models. Among the out-of-the-box features
included in <span style="" class="text typewriter">RedModRphree</span>, we highlight the computation and
visualization of Pourbaix (Eh-pH) diagrams using full speciation as
computed by <span style="" class="text typewriter">PHREEQC</span> and the implementation of 1D advective
reactive transport supporting the use of surrogate models replacing
expensive equation-based calculations.</p></abstract-html>
<ref-html id="bib1.bib1"><label>Appelo et al.(2013)Appelo, Parkhurst, and Post</label><mixed-citation>
Appelo, C. A. J., Parkhurst, D. L., and Post, V. E. A.: Equations for
calculating hydrogeochemical reactions of minerals and gases such as CO<sub>2</sub> at
high pressures and temperatures, Geochim. Cosmochim. Ac., 125, 49–67, <a href="https://doi.org/10.1016/j.gca.2013.10.003" target="_blank">https://doi.org/10.1016/j.gca.2013.10.003</a>, 2013.
</mixed-citation></ref-html>
<ref-html id="bib1.bib2"><label>Charlton and Parkhurst(2011)</label><mixed-citation>
Charlton, S. R. and Parkhurst, D. L.: Modules based on the geochemical model
PHREEQC for use in scripting and programming languages, Comput.
Geosci., 37, 1653–1663,
<a href="https://doi.org/10.1016/j.cageo.2011.02.005" target="_blank">https://doi.org/10.1016/j.cageo.2011.02.005</a>, 2011.
</mixed-citation></ref-html>
<ref-html id="bib1.bib3"><label>De Lucia(2021)</label><mixed-citation>
De Lucia, M.: RedModRphree (0.3.6), Zenodo [code], <a href="https://doi.org/10.5281/zenodo.5046427" target="_blank">https://doi.org/10.5281/zenodo.5046427</a>, last access: 30 September 2021.
</mixed-citation></ref-html>
<ref-html id="bib1.bib4"><label>De Lucia and Kühn(2013)</label><mixed-citation>
De Lucia, M. and Kühn, M.: Coupling R and PHREEQC: Efficient
Programming of Geochemical Models, Energy Proced., 40, 464–471,
<a href="https://doi.org/10.1016/j.egypro.2013.08.053" target="_blank">https://doi.org/10.1016/j.egypro.2013.08.053</a>, 2013.
</mixed-citation></ref-html>
<ref-html id="bib1.bib5"><label>De Lucia and Kühn(2021)</label><mixed-citation>
De Lucia, M. and Kühn, M.: DecTree v1.0 – chemistry speedup in reactive transport simulations: purely data-driven and physics-based surrogates, Geosci. Model Dev., 14, 4713–4730, <a href="https://doi.org/10.5194/gmd-14-4713-2021" target="_blank">https://doi.org/10.5194/gmd-14-4713-2021</a>, 2021.
</mixed-citation></ref-html>
<ref-html id="bib1.bib6"><label>De Lucia et al.(2017)De Lucia, Kempka, Jatnieks, and
Kühn</label><mixed-citation>
De Lucia, M., Kempka, T., Jatnieks, J., and Kühn, M.: Integrating surrogate
models into subsurface simulation framework allows computation of complex
reactive transport scenarios, Energy Proced., 125, 580–587,
<a href="https://doi.org/10.1016/j.egypro.2017.08.200" target="_blank">https://doi.org/10.1016/j.egypro.2017.08.200</a>, 2017.
</mixed-citation></ref-html>
<ref-html id="bib1.bib7"><label>Dick(2019)</label><mixed-citation>
Dick, J. M.: CHNOSZ: Thermodynamic Calculations and Diagrams for
Geochemistry, Front. Earth Sci., 7,
<a href="https://doi.org/10.3389/feart.2019.00180" target="_blank">https://doi.org/10.3389/feart.2019.00180</a>,   2019.
</mixed-citation></ref-html>
<ref-html id="bib1.bib8"><label>Hennig et al.(2020)Hennig, Stockmann, and Kühn</label><mixed-citation>
Hennig, T., Stockmann, M., and Kühn, M.: Simulation of diffusive uranium
transport and sorption processes in the Opalinus Clay, Appl. Geochem.,
123, 104777, <a href="https://doi.org/10.1016/j.apgeochem.2020.104777" target="_blank">https://doi.org/10.1016/j.apgeochem.2020.104777</a>, 2020.
</mixed-citation></ref-html>
<ref-html id="bib1.bib9"><label>Huang(2016)</label><mixed-citation>
Huang, H.-H.: The Eh-pH Diagram and Its Advances, Metals, 6, 23,
<a href="https://doi.org/10.3390/met6010023" target="_blank">https://doi.org/10.3390/met6010023</a>, 2016.
</mixed-citation></ref-html>
<ref-html id="bib1.bib10"><label>Jatnieks et al.(2016)Jatnieks, De Lucia, Dransch, and
Sips</label><mixed-citation>
Jatnieks, J., De Lucia, M., Dransch, D., and Sips, M.: Data-driven
Surrogate Model Approach for Improving the Performance of
Reactive Transport Simulations, Energy Proced., 97, 447–453,
<a href="https://doi.org/10.1016/j.egypro.2016.10.047" target="_blank">https://doi.org/10.1016/j.egypro.2016.10.047</a>, 2016.
</mixed-citation></ref-html>
<ref-html id="bib1.bib11"><label>John et al.(2016)John, Heuss-Aßbichler, and Ullrich</label><mixed-citation>
John, M., Heuss-Aßbichler, S., and Ullrich, A.: Conditions and mechanisms for
the formation of nano-sized Delafossite (CuFeO<sub>2</sub>) at temperatures  ≤ 90&thinsp;°C in
aqueous solution, J. Solid State Chem., 234, 55–62,
<a href="https://doi.org/10.1016/j.jssc.2015.11.033" target="_blank">https://doi.org/10.1016/j.jssc.2015.11.033</a>, 2016.
</mixed-citation></ref-html>
<ref-html id="bib1.bib12"><label>Johnson et al.(1992)Johnson, Oelkers, and Helgeson</label><mixed-citation>
Johnson, J. W., Oelkers, E. H., and Helgeson, H. C.: SUPCRT92: A software
package for calculating the standard molal thermodynamic properties of
minerals, gases, aqueous species, and reactions from 1 to 5000&thinsp;bar and 0 to
1000&thinsp;°C, Comput. Geosci., 18, 899–947,
<a href="https://doi.org/10.1016/0098-3004(92)90029-q" target="_blank">https://doi.org/10.1016/0098-3004(92)90029-q</a>, 1992.
</mixed-citation></ref-html>
<ref-html id="bib1.bib13"><label>Kölling et al.(2000)Kölling, Ebert, and Schulz</label><mixed-citation>
Kölling, M., Ebert, M., and Schulz, H. D.: A Novel Approach to the
Presentation of pε/pH-Diagrams, in: Redox: Fundamentals, Processes
and Applications, edited by: Schüring, J., Schulz, H. D., Fischer, W. R.,
Böttcher, J., and Duijnisveld, W. H. M.,   Springer, Berlin,
Heidelberg, 55–63, <a href="https://doi.org/10.1007/978-3-662-04080-5_5" target="_blank">https://doi.org/10.1007/978-3-662-04080-5_5</a>, 2000.
</mixed-citation></ref-html>
<ref-html id="bib1.bib14"><label>Mullen(2021)</label><mixed-citation>
Mullen, K.: CRAN Task View: Chemometrics and Computational Physics, available at:
<a href="https://cran.r-project.org/web/views/ChemPhys.html" target="_blank"/>, last access:
30 June 2021.
</mixed-citation></ref-html>
<ref-html id="bib1.bib15"><label>Palandri and Kharaka(2004)</label><mixed-citation>
Palandri, J. L. and Kharaka, Y. K.: A compilation of rate parameters of water-mineral interaction kinetics for application to geochemical modeling, Tech. Rep., USGS Menlo Park, California, USA, available at:
<a href="https://pubs.usgs.gov/of/2004/1068/" target="_blank"/> (last access: 30 September 2021), 2004.
</mixed-citation></ref-html>
<ref-html id="bib1.bib16"><label>Parkhurst and Appelo(2013)</label><mixed-citation>
Parkhurst, D. L. and Appelo, C. A. J.: Description of input and examples for
PHREEQC version 3 – A computer program for speciation, batch-reaction,
one-dimensional transport, and inverse geochemical calculations, available at:
<a href="https://pubs.usgs.gov/tm/06/a43" target="_blank"/> (last access: 30 September 2021), 2013.
</mixed-citation></ref-html>
<ref-html id="bib1.bib17"><label>Parkhurst and Wissmeier(2015)</label><mixed-citation>
Parkhurst, D. L. and Wissmeier, L.: PhreeqcRM: A reaction module for
transport simulators based on the geochemical model PHREEQC, Adv.
Water Resour., 83, 176–189, <a href="https://doi.org/10.1016/j.advwatres.2015.06.001" target="_blank">https://doi.org/10.1016/j.advwatres.2015.06.001</a>, 2015.

</mixed-citation></ref-html>
<ref-html id="bib1.bib18"><label>Plotly Technologies(2015)</label><mixed-citation>
Plotly Technologies, I.: Collaborative data science,
available at: <a href="https://plot.ly" target="_blank"/> (last access: 30 June 2021), 2015.
</mixed-citation></ref-html>
<ref-html id="bib1.bib19"><label>R Core Team(2021)</label><mixed-citation>
R Core Team: R: A Language and Environment for Statistical Computing, R
Foundation for Statistical Computing, Vienna, Austria, available at:
<a href="https://www.R-project.org/" target="_blank"/>, last access: 30 September 2021.
</mixed-citation></ref-html>
<ref-html id="bib1.bib20"><label>Zeileis(2005)</label><mixed-citation>
Zeileis, A.: CRAN Task Views, R News, 5, 39–40, available at:
<a href="https://CRAN.R-project.org/doc/Rnews/" target="_blank"/> (last access: 30 June 2021),
2005.
</mixed-citation></ref-html>
<ref-html id="bib1.bib21"><label>Zeileis(2021)</label><mixed-citation>
Zeileis, A.: CRAN Task View, available at: <a href="https://cran.r-project.org/web/views/" target="_blank"/>,
last access:  30 June 2021.
</mixed-citation></ref-html>--></article>
