Talk Hydro-Geo-Chemial Modeling with Phreeqpy

Abstract

Modeling of hydro-geo-chemical processes in the subsurface or in lakes and rivers is an established method to characterize water quality and predict its changes over time. It can also be used to estimate the impact of anthropogenic activities on the water composition in these systems.

PHREEQC (Parkhurst and Appelo, 1999) is one of the most used codes for hydro-geo-chemical modeling. It provides many features to model speciation, equilibrium as well as kinetic reactions and a variety of other processes. It is frequently coupled to, typically multi-dimensional, transport codes allowing sophisticated reactive transport modeling.

There are two general methods for coupling:

  • tight coupling by modification of the public domain C source code or
  • loose coupling by generating PHREEQC input files, starting PHREEQC as process and reading the resulting output file.

While tight coupling often achieves shorter run times, it demands major effort modifying the source, requiring detailed knowledge of implementation internals and additional effort adapting to each new release. Loose coupling can be slow, on the other hand, because repeatedly starting a new process that initializes a database of reactions and allocates new memory takes additional run time, but programming is much simpler than the tight coupling and updates of the PHREEQC executable typically require no changes.

The new IPhreeqc interface (Parkhurst and Charlton, 2011) offers an API that allows combining the advantages of tight and loose coupling while largely eliminating the disadvantages of both approaches. The API calls expect strings with statements in the domain specific language that has been used for PHREEQC input for many years. The procedure is similar to dynamic creation of SQL statements when working with databases.

The IPhreeqc interface is available in C, C++ and FORTRAN as well as COM for all languages that have COM interfaces. While Python can be used with COM, this approach is restricted to windows operating systems. Phreeqpy uses cytpes to wrap the IPhreeqc shared library, making Python bindings available on all major operating systems. In addition to providing the same API as IPhreeqc, Phreeqpy offers convenience methods to simplify common tasks such as reading whole arrays.

A simple example of coupling PHREEQC with a transport code is presented here. Solutions with traditional loose coupling, IPhreeqc with C++ as well as Phreeqpy via COM and via ctypes are compared in terms of run time and implementation effort. The Phreeqpy approach is about one order of magnitude faster than the loosely coupled version. Even though the C++ solution is about 40 % faster than the ones with Python, the implementation effort with Python is considerably smaller.

In conclusion, Phreeqpy offers a new way to use Python with PHREEQC. It is simpler and faster than the loosely coupled approach that dominated model coupling so far. It is expected that new Phreeqpy-based tools for hydro-geo-chemical tasks will be built because it is easier to learn for scientists with little programming experience and offers more possibilities than previous approaches.

tagged by
no related entity