Coupling GoldSim and PhreeqC

GoldSim is a software platform for visualizing and simulating dynamically complex flow systems in engineering, science and business. In the environmental and mining arena, GoldSim is typically used to understand (or design) complex fluid or material movement by tracking the quantities of material moving around a system. When GoldSim is used to track fluid flow, operators and regulators are frequently concerned about the chemistry of the solutions as well as their volumes. Although GoldSim can model mass transport and simple chemical reactions (using the Contaminant Transport Module), it cannot simulate complex geochemical reactions such as mineral precipitation and dissolution. PhreeqC, on the other hand, is a computer program written by the USGS that is designed to perform a wide variety of aqueous geochemical calculations which can be used for speciation and saturation-index calculations, as well as reaction-path and 1D advective-transport calculations (including, irreversible reactions, mixing of solutions, mineral and gas equilibria, surface-complexation reactions, and ion-exchange reactions). The use of both software packages allows modelers to simulate solution flow and complex geochemical reactions, but until now, passing data back and forth between the two programs has been a challenge.

The solution to this issue lies with the use of Dynamic Link Libraries (DLLs). GoldSim allows the user to develop separate program modules which can then be directly coupled with the main GoldSim algorithm. These user-defined modules are referred to as external functions and are linked into GoldSim as DLLs. Integrating an external program module into GoldSim requires the development of a "wrapper" or "shell" around the function to compile it into a DLL.

Continuous communication Using DLLs

It is possible to call PhreeqC subroutines from GoldSim to solve more complex geochemical problems when running GoldSim, and this has already been described by Johnson et al. (2018). In the proposed approach, the DLL pauses the GoldSim model and writes the component concentration into a PhreeqC input file, opens DOS, runs PhreeqC to produce an output file and sends the information back to GoldSim which then continues running until the next designated time-step, when the same PhreeqC subroutine is repeated. The DLL provides an adequate, yet cumbersome, workaround for integrating the two programs (for example, the user must change the DLL source code to add a component, an output or a boundary condition, while the periodic pausing of GoldSim to run PhreeqC causes the coupled program to run slowly).

A newer version of PhreeqC was recently released by the USGS, PhreeqcRM. The geochemical modeling of PhreeqcRM is similar to PhreeqC; however, it contains a “shell” of additional libraries that allow PhreeqC to interface with other computer codes. INTERA successfully used this newer version of PhreeqC to develop a fully-integrated GoldSim and PhreeqcRM water-balance and geochemical model. INTERA’s model is similar to the previous coupling attempts in that a DLL is used to link the two programs, but INTERA’s DLL is in continuous communication between GoldSim and PhreeqC (that is, GoldSim does not need to stop running to run PhreeqC separately, resulting in runs up to 50 times faster than the current DLL solution).

Example of an Integrated GoldSim Solution

INTERA uses this integrated tool to combine site-specific flow system data with geochemical modeling to depict geochemical reactions that will likely occur in a dynamic, real-world water balance and mixing scenario. INTERA’s integrated model is ideal for solving mixing, chemical equilibrium, and aqueous speciation problems in complex systems at operating or planned facilities.
In the example provided, the chemical composition of the effluent from a column containing a cation exchanger is simulated. Initially, the column contains a sodium-potassium-nitrate solution in equilibrium with the cation exchanger. The column is then flushed with three pore volumes of calcium chloride solution. Calcium, potassium, and sodium react to equilibrium with the exchanger at all times.

Our people, our commitment, and the solutions we deliver are what differentiate INTERA from other consulting firms. At INTERA, we work diligently every day to achieve our vision of Delivering Excellence with Every Solution. Contact us to learn more.

Reference

Johnson, Brent C.; Rohal, Pamela A.; Eary, L.E. {Ted} (2018): Coupling PHREEQC with GoldSim for a More Dynamic Water Modeling Experience. – In: Wolkersdorfer, Ch.; Sartz, L.; Weber, A.; Burgess, J. & Tremblay, G.: Mine Water – Risk to Opportunity (Vol II). – p. 1081 – 1087; Pretoria, South Africa (Tshwane University of Technology).