- Notifications
You must be signed in to change notification settings - Fork4
Easily calling PhreeqcRM from Matlab
License
simulkade/PhreeqcMatlab
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
PhreeqcMatlab
is a wrapper for thePhreeqcRMC interface andIPhreeqc. Most of the functions are wrapped, with the exception of MPI function (that I neither use nor know how to wrap). In general, the C++ interface of PhreeqcRM has more functionality and is easier to call. Therefore, I have implemented several classes and functions to make the usage of this package more convenient, similar to its c++ interface and better. All the original PhreeqcRM functions start withRM_
. The additional utility functions that I have added do not have this extraRM_
.
PhreeqcMatlab
automatically downloads the latest compiled phreeqcRM.dll
on Windows and.so
on Linux machines, fromthis repository. I don't have access to macOS; hence, no library there and you'll have to compile PhreeqcRM yourself for mac. On Windows, you will need to haveVisual C++ Redistributable for VC 2019 installed. All you need to do is to download or clone this repository and run thestartup.m
file. Before running the example, make sure thatC/C++ compiler is already installed in your Matlab. Please let me know if you have any error messages when running the file.
SimpleAdvect.m
andAdvect.m
demonstrate advection simulation for Phreeqc reactive transport modeling software. It sets up initial conditions, defines boundary conditions, and runs a transient loop simulating advection.Species.m
demonstrates species transport using PhreeqcRM.Gas_m.m
demonstrates the equilibration of gas with an aqueous phase
You can run all tests by executingmain.m
.
Need more examples? Go to theexamples folder and run the files.
Don't forget to run thestartup
file before running the examples.
iph= IPhreeqc();% load the libraryiph=iph.CreateIPhreeqc();% create an IPhreeqc instanceiph_string= ['SOLUTION 1 brine\n' ...'pH 7.0\n' ...'temp 25.0\n' ...'Na 1.0\n' ...'Cl 1.0\n' ...'END\n' ...'SELECTED_OUTPUT 1\n'...'-reset false\n'...'-totals Na Cl\n'...'END'];% create the Phreeqc stringout_string=iph.RunPhreeqcString(iph_string, database_file('phreeqc.dat'));% Run the stringdisp(out_string)% display the resultsiph.DestroyIPhreeqc();% kill the phreeqc instance
Alternatively, you can save the string in a file and call it withRunPhreeqcFile
function as shownhere.
Inthis folder, there are a couple of examples that shows how to investigate the effect of temperature on the dissolution of anhydrite and gypsum. Save the following Phreeqc input in a file namedex2_input.pqc
(example 2 of Phreeqc manual)
#TITLE Example 2.--Temperature dependence of solubility of gypsum and anhydriteSOLUTION 1 Pure water pH 7.0 temp 25.0 EQUILIBRIUM_PHASES 1 Gypsum 0.0 1.0 Anhydrite 0.0 1.0ENDSELECTED_OUTPUT 1 -reset false -si Anhydrite GypsumUSER_PUNCH -headings equi_anhydrite 10 PUNCH EQUI("Anhydrite")END
and run the following script to calculate and plot the solubility in different temperatures:
phreeqc_rm= PhreeqcSingleCell('ex2_input.pqc','phreeqc.dat');n_data=51;h_out=phreeqc_rm.GetSelectedOutputHeadings(1);temperature= linspace(25.0,75.0,n_data);% degree Cs_out= zeros(n_data, length(h_out));for i=1:length(temperature)phreeqc_rm.RM_SetTemperature(temperature(i)); status=phreeqc_rm.RM_RunCells(); c_out=phreeqc_rm.GetConcentrations(); s_out(i,:)=phreeqc_rm.GetSelectedOutput(1);endplot(temperature,s_out,'-s');legend(string(h_out));xlabel('T (C)');ylabel('SI');status=phreeqc_rm.RM_Destroy();
Look at theexample folder for many more examples of batch and transport geochemical calculations.
I'm writing several examples that calls this package from my finite volume packageFVTool. You can help me by providing reactive transport cases with analytical solutions.
There are at least two more packages that have some of the functionalities ofPhreeqcMatlab
, and inspired me to write this package.
This package probably won't be broken by sudden changes. So you can start using it. Here's a list of near future activities. You contributions/suggestions are more than welcome :-)
Wrap IPhreeqc functionsMore utility/helper functionsMore tests- Documentation (please help)
- New classes for solution, phases, surfaces, etc (in progress)
- Utility functions for the IPhreeqc wrapper (in progress)
- More examples for both IPhreeqc and PhreeqcRM (in progress)
- More keywords in the new input file specific to PhreeqcMatlab
- Simple GUI (in progress as part of a DOTC project)
The original package was written byAli A. Eftekhari in his free time. It is/will be used in some of the projects/publications at theDanish Offshore Technology Centre (DOTC) at theTechnical University of Denmark. Some of the current development is done as part of an ongoing project at the DOTC.
Please cite as
Eftekhari, Ali A., and Behzad Hosseinzadeh. Simulkade/PhreeqcMatlab: Preliminary Release of PhreeqcMatlab. Zenodo, 2021, doi:10.5281/ZENODO.5513713.
About
Easily calling PhreeqcRM from Matlab