Skip to content
sintefmathPublic

About

MATLAB tools built on MRST for underground hydrogen storage simulation in saline aquifers and depleted gas reservoirs, with black-oil and compositional models, microbial reactions, and PHREEQC geochemical coupling.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

H2sim

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

What you can simulate

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.

Install

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-sim

If you already cloned without the dependencies, run this from the repository directory:

git submodule update --init --recursive

In MATLAB, set the current folder to the cloned h2-sim directory and initialize:

startupH2sim

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

Run your first simulation

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.

Compare bacterial and abiotic storage

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.

Use PHREEQC chemistry

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.

Explore and reuse results

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').

Tests and support

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.

About

MATLAB tools built on MRST for underground hydrogen storage simulation in saline aquifers and depleted gas reservoirs, with black-oil and compositional models, microbial reactions, and PHREEQC geochemical coupling.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages