Conceptual Models > Incorporation PHREEQC in programming languages

Using Phreeqc in C++

(1/19) > >>

GeeqC:
Dear Dr. Parkhurst,

We are trying to link PhreeqC with a C++ code but encountered some problems. In order to run the example for C++ given in the Readme file we followed the instructions in the Readme file (README.txt). First we wanted to try to run the example_advect_cpp, but we failed.

Here is what we have done:
- An Iphreec.sln file was created using Cmake.
- The program was compiled using Visual Studio (ALL_BUILD, RUN_TESTS, and INSTALL) in released mode.
- An *.exe file was created: example_advect_cpp.exe

When the example was run, an error message appeared:
0x000007FEFD63B87D in example_advect_cpp.exe
and
IPhreeqcStop at 0x00000000002CF0E0.

We would be thankful for some support for this procedure.

Best wishes,
GeeqC

dlparkhurst:
Looks like there is a bug in the INSTALL method or some other problem. We'll have to look at it.

In the mean time, the problem is that the database phreeqc.dat and file ic are not located. You can use ../../../../examples/cpp/advect/ to find the correct files. So modify the source file advect.cpp in the project example_advect_cpp to have

if (this->IPhreeqc_ptr->LoadDatabase("../../../../examples/cpp/advect/phreeqc.dat") != 0) this->EHandler();

and

if (this->IPhreeqc_ptr->RunFile("../../../../examples/cpp/advect/ic") != 0) this->EHandler();

GeeqC:
Dear Mr. Parkhurst,

Here I would like to follow up on the discussion in the "basics" section on the topic "Converting from molality (mol/kgw) to mg/l for high solubility minerals", where you recommended us to better use the module PhreeqcRM for interaction with a reaction transport model. So, this brings us back to this section here, which is on incorporating Phreeqc in C++ language.

In the meantime, we were able to compile both IPhreeqc and PhreeqcRM for C++. While it was possible to transfer data from the reaction-transport model to Iphreeqc via strings, we do not understand how data transfer works for PhreeqcRM. According to the documentation, it should be possible to transfer entire data arrays which would make the interaction with a reaction-transport model much more efficient. However, we do not know the syntax. In the example given, the data are directly read from a file (advect.pqi) written in Visual Basic. But how can we directly transfer a data array from C++?

Best wishes!
Patrick

dlparkhurst:
The strategy of using PhreeqcRM is to define a set of solutions and reactants in the "initial iphreeqc" instance. This can be done by either the RunString or RunFile method of PhreeqcRM (in advection_cpp.cpp, the file advect.pqi is read). The chemistry cells for reactive transport are then populated with the method InitialPhreeqc2Module that transfers solutions and reactants to the cells in the "worker iphreeqc" instance where all of the chemistry calculations for the grid are performed. An initial call to RunCells performs any equilibrations in the worker instance and makes the initial conditions from  available to begin transport and reaction. The main time-stepping loop then consists of interacting with the worker instance(s) with GetConcentrations (or GetSpeciesConcentrations, if you are doing multicomponent diffusion), transport calculation, SetConcentrations (or SetSpeciesConcentrations), and RunCells.

There are quite a few methods altogether to control setting units, defining the grid, setting the database, getting lists of elements and reactants, extracting results, controlling parallelization, and so on.

The file Tests/advect_cpp.cpp gives a fairly complete example of many of the most frequently used methods of PhreeqcRM. If you are doing multicomponent diffusion, look at species_cpp.cpp. Documentation of all PhreeqcRM methods is distributed in the directory Doxygen/html and online at https://water.usgs.gov/water-resources/software/PHREEQC/documentation/phreeqcrm/index.html. The reaction-transport codes PHAST and VS2DRT use PhreeqcRM for their chemistry calculations; the source code may or may not be useful examples for you to read.

To answer your specific question SetConcentrations or SetSpeciesConcentrations and GetConcentrations and GetSpeciesConcentrations tranfer arrays of concentrations to and from the reaction module during time stepping. Look for these methods in advection_cpp.cpp or species_cpp.cpp.

GeeqC:
... it is still not clear to me, how the data can be transferred. Do we have to build the input string in the same way as for Iphreeqc, and including a selected output? How are the concentration vectors read by SetConcentrations transferred to the input string. And how are the selected outputs sent back to the reaction-transport model?

Also, do we have to use RunString or RunCells in this case?

It is furthermore not clear to me, why we need initial conditions. The reaction-transport model already has initial conditions and provides the solutions as input for Phreeqc. And also, how is the "initial Iphreeqc" instance linked to the "worker Iphreeqc" instance?

Thanks for your patience, answering our questions!

Navigation

[0] Message Index

[#] Next page

Go to full version