Underground hydrogen storage simulation, built on the MATLAB Reservoir Simulation Toolbox (MRST).
H2sim provides MATLAB models and examples for hydrogen storage in saline aquifers and depleted gas reservoirs. Explore storage cycles, hydrogen dissolution, microbial consumption, gas composition, and geochemical feedback.
Documentation · Installation · Examples and notebooks · Publications
| Model family | Capabilities |
|---|---|
| Hydrogen storage in saline aquifers — h2-store | Black-oil flow, injection and withdrawal cycles, gravity, capillarity, dissolved hydrogen, and fluid-property tables. |
| Hydrogen storage in depleted gas reservoirs — h2-biochem | Compositional flow with residual gas and microbial reactions: methanogenesis, acetogenesis, and sulfate reduction. Compare bacterial and abiotic storage. |
| PHREEQC coupling | Sequential compositional–geochemical coupling and multirate microbial reaction substeps with aqueous equilibrium feedback. Inspect pH, aqueous chemistry, and mineral effects. |
| Hydrogen–brine thermodynamics | RK, Søreide–Whitson, PR, and Henry–Setschenow calculations, comparisons with supplied ePC-SAFT reference tables, and black-oil PVT tabulation. |
Use MATLAB R2021a or newer and Git. Clone the repository with its pinned MRST and PhreeqcMatlab dependencies:
git clone --recurse-submodules https://github.com/sintefmath/h2-sim.git
cd h2-simIf you already cloned without the dependencies, run this from the repository directory:
git submodule update --init --recursiveIn MATLAB, set the current folder to the cloned h2-sim directory and initialize:
startupH2simStartup initializes MRST and adds the H2sim modules. Use this startup function rather than recursively adding the entire MRST tree with genpath.
Parallel Computing Toolbox is optional. The selected examples run serially by default. Optional AMGCL acceleration for larger compositional simulations requires a supported C++ compiler and MRST's compiled gateway; see the installation guide.
The 2D saline-aquifer example includes hydrogen build-up and five storage cycles. It requires neither PHREEQC nor Parallel Computing Toolbox:
result = exampleBlackOilAquifer2D;
plotBlackOilAquifer2D(result);
% Inspect the final gas saturation.
lastState = result.states{end};
gasSaturation = lastState.s(:, 2);The aquifer notebook explains the setup and shows storage-cycle, dissolution, and fluid-table figures.
Run the existing 2D depleted-reservoir case with three microbial reactions:
results = exampleCompositionalBacterial2DThreeReactions( ...
'numCycles', 5, 'scenarios', {'bacterial', 'abiotic'}, ...
'molecularDiffusion', false, 'molecularDispersion', false);
plotCompositionalBacterial2DThreeReactions(results);This is a larger simulation than the introductory aquifer example. The bacterial storage notebook presents hydrogen consumption by reaction, spatial results, and signed well component rates with bottom-hole pressure.
H2sim’s core storage and thermodynamic workflows do not require Windows. The two sequential PHREEQC backends currently use IPhreeqcCOM, which requires MATLAB on Windows, and a registered server from the USGS PHREEQC distribution. See the PHREEQC installation instructions.
After installing IPhreeqcCOM and running startupH2sim, check the interface and bundled database:
db = which('h2_biogeochemistry.dat');
assert(~isempty(db), 'Initialize H2sim first.');
iph = actxserver('IPhreeqcCOM.Object');
status = iph.LoadDatabase(db);
assert(status == 0, 'PHREEQC database loading failed.');
delete(iph);Run a small mineral-chemistry setup check and inspect its final pH:
comparison = exampleCompositionalBacterial1DPhreeqcMinerals( ...
'gridCells', 4, 'maximumFlowSteps', 2);
pH = comparison(2).states{end}.phreeqcPH;
plotPhreeqcMineralComparison(comparison);Read the PHREEQC workflow guide before comparing backends: their microbial kinetic ownership and splitting differ. The bundled database originates from UGFACT; its source revision, checksum, and attribution are recorded in the database README. The full-cycle validation notebook compares results against a separate reference implementation.
- Selected examples and downloadable notebooks: model setup, saved figures, and MATLAB commands.
- Hydrogen–brine phase behavior: pressure, temperature, salinity, and fluid-property calculations.
- Dependencies: required software and optional acceleration.
- Publications and presentations: related research and references.
The plotting functions above accept completed result structures, so you can redraw figures without rerunning the simulations. For later use, save the returned structure in MATLAB, for example save('aquiferResults.mat', 'result', '-v7.3').
Run the MATLAB regression suite from the repository root after startup:
checks = runtests(fullfile(pwd, 'h2-biochem', 'tests'));
assertSuccess(checks);Tests requiring IPhreeqcCOM are skipped when that interface is unavailable.
Report bugs or request features through GitHub Issues. Include your MATLAB version, operating system, example command, and error message so the issue can be reproduced.