Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Easily calling PhreeqcRM from Matlab

License

NotificationsYou must be signed in to change notification settings

simulkade/PhreeqcMatlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DOIView PhreeqcMatlab on File Exchange

PhreeqcMatlab

Documents (work in progress)

Easily calling PhreeqcRM and IPhreeqc from Matlab

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_.

Installation

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.

Test cases

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.

Simple cases

Running a Phreeqc input file or string:

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.

Sensitivity analysis

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();

And more

Look at theexample folder for many more examples of batch and transport geochemical calculations.

Reactive transport

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.

Other packages you might like

There are at least two more packages that have some of the functionalities ofPhreeqcMatlab, and inspired me to write this package.

To do list

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 functions
  • More utility/helper functions
  • More 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)

Author

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.

Citation

Please cite as

Eftekhari, Ali A., and Behzad Hosseinzadeh. Simulkade/PhreeqcMatlab: Preliminary Release of PhreeqcMatlab. Zenodo, 2021, doi:10.5281/ZENODO.5513713.

[8]ページ先頭

©2009-2025 Movatter.jp