Skip to main content

Python Library for automating reaction simulations using TOUGHREACT, TMVOC and TMVOC-BIO

Project description

PyTOUGHREACT

PyTOUGHREACT is a Python package for automating reactive transport simulations including biodegradation reactions. It makes use of TOUGHREACT, TMVOC and TMVOCBIO executables for running the simulations. These executables are interfaced with python to automate the runs. It will be particularly useful for uncertainty quantifications, sensitivity analysis without the need to have a lot of files stored on your local computer. It builds on the PyTOUGH software which processes for the TOUGH2 executables.

Installation

PyTOUGHREACT is available on PyPI which is a repository of softwares built with the Python Programming Language. Before installing PyTOUGHREACT, it is required to have Python >=3.7 installed on your local computer. Python can be downloaded from the python.org website and installing it by following the instructions. Windows users should ensure that the path to the python is set in the environment variable to ensure availability everywhere.

Use the package manager pip to install PyTOUGHREACT.

pip install pytoughreact

The package can also be forked from this GitHub page and installation performed using

python setup.py install  or py setup.py install

Because pytoughreact requires PyTOUGH, this library also needs to be installed. PyTOUGH can be installed by running the command below

pip install PyTOUGH

Usage

import os
from mulgrids import mulgrid
from pytoughreact.writers.react_writing import t2react
from pytoughreact.pytough_wrapper.wrapper.reactgrid import t2reactgrid
from pytoughreact.pytough_wrapper.wrapper.reactzone import t2zone
from pytoughreact.chemical.chemical_composition import PrimarySpecies, WaterComp, Water, ReactGas
from pytoughreact.chemical.mineral_composition import MineralComp
from pytoughreact.chemical.mineral_zone import MineralZone
from pytoughreact.chemical.mineral_description import Mineral
from pytoughreact.constants.default_minerals import get_kinetics_minerals, get_specific_mineral
from pytoughreact.writers.chemical_writing import t2chemical
from pytoughreact.writers.solute_writing import t2solute
from t2grids import rocktype

#__________________________________FLOW.INP____________________________________________
length = 0.1
nblks = 1
dx = [length / nblks] * nblks
dy = [0.5]
dz = [0.5] * 1
geo = mulgrid().rectangular(dx, dy, dz)
geo.write('geom.dat')

react = t2react()
react.title = 'Reaction example'

react.multi = {'num_components': 1, 'num_equations': 1, 'num_phases': 2,
               'num_secondary_parameters': 6}

react.grid = t2reactgrid().fromgeo(geo)

react.parameter.update(
    {'print_level': 4,
     'max_timesteps': 9999,
     'tstop': 8640,
     'const_timestep': 10.,
     'print_interval': 1,
     'gravity': 9.81,
     'relative_error': 1e-5,
     'phase_index': 2,
     'default_incons': [1.013e5, 25]})

sand = rocktype('ROCK1', 0, 2600, 0.1, [6.51e-12, 6.51e-12, 6.51e-12], 0.0, 952.9)

react.grid.delete_rocktype('dfalt')
react.grid.add_rocktype(sand)

for blk in react.grid.blocklist[0:]:
    blk.rocktype = react.grid.rocktype[sand.name]


zone1 = t2zone('zone1')

react.grid.add_zone(zone1)

for blk in react.grid.blocklist[0:]:
    blk.zone = react.grid.zone[zone1.name]

react.start = True

react.write('flow.inp')

#____________________________________CHEMICAL.INP________________________________________
h2o = PrimarySpecies('h2o', 0)
h = PrimarySpecies('h+', 0)
na = PrimarySpecies('na+', 0)
cl = PrimarySpecies('cl-', 0)
hco3 = PrimarySpecies('hco3-', 0)
ca = PrimarySpecies('ca+2', 0)
so4 = PrimarySpecies('so4-2', 0)
mg = PrimarySpecies('mg+2', 0)
h4sio4 = PrimarySpecies('h4sio4', 0)
al = PrimarySpecies('al+3', 0)
fe = PrimarySpecies('fe+2', 0)
hs = PrimarySpecies('hs-', 0)

all_species = [h2o, h,na, cl, hco3, ca, so4, mg, h4sio4, al, fe, hs]

h2o_comp1 = WaterComp(h2o, 1, 1.0000E+00, 1.000000E+00)
h_comp1 = WaterComp(h, 1, 1E-7, 1E-7)
na_comp1 = WaterComp(na, 1, 1E-10, 2.93E-2)
cl_comp1 = WaterComp(cl, 1, 1E-10, 1.08E-3)
hco3_comp1 = WaterComp(hco3, 1, 1E-10, 2.21E-08)
ca_comp1 = WaterComp(ca, 1, 1E-10, 5.9E-03)
so4_comp1 = WaterComp(so4, 1, 1E-10, 6.94E-3)
mg_comp1 = WaterComp(mg, 1, 1E-10, 2.54E-8)
h4sio4_comp1 = WaterComp(h4sio4, 1, 1E-10, 1E-10)
al_comp1 = WaterComp(al, 1, 1E-10, 9.96E-5)
fe_comp1 = WaterComp(fe, 1, 1E-10, 9.7E-9)
hs_comp1 = WaterComp(hs, 1, 1E-10, 1E-10)

initial_water_zone1 = Water([h2o_comp1, h_comp1, na_comp1, cl_comp1, hco3_comp1, ca_comp1, so4_comp1, mg_comp1, h4sio4_comp1, al_comp1, fe_comp1, hs_comp1], 25, 200)

mineral_list = ['c3fh6', 'tobermorite', 'calcite', 'csh' , 'portlandite', 'ettringite', 'katoite', 'hydrotalcite']
all_minerals = get_kinetics_minerals(mineral_list)


c3fh6_zone1 = MineralComp(get_specific_mineral(mineral_list[0]), 0.1, 0, 0.0E-00, 20000.0, 0)
tobermorite_zone1 = MineralComp(get_specific_mineral(mineral_list[1]), 0.05, 0, 0.0E-00, 20000.0, 0)
calcite_zone1 = MineralComp(get_specific_mineral(mineral_list[2]), 0.4, 1, 0.0E-00, 260.0, 0)
csh_zone1 = MineralComp(get_specific_mineral(mineral_list[3]), 0.1, 1, 0.0E-00, 20000.0, 0)
portlandite_zone1 = MineralComp(get_specific_mineral(mineral_list[4]), 0.1, 1, 0.0E-00, 1540.0, 0)
ettringite_zone1 = MineralComp(get_specific_mineral(mineral_list[5]), 0.1, 1, 0.0E-00, 20000.0, 0)
katoite_zone1 = MineralComp(get_specific_mineral(mineral_list[6]), 0.1, 1, 0.0E-00, 570.0, 0)
hydrotalcite_zone1 = MineralComp(get_specific_mineral(mineral_list[7]), 0.05, 1, 0.0E-00, 1000.0, 0)

initial_co2 = ReactGas('co2(g)', 0, 1.1)
ijgas = [[initial_co2], []]

zone1.water = [[initial_water_zone1], []]
zone1.gas = [[initial_co2], []]
mineral_zone1 = MineralZone([c3fh6_zone1, tobermorite_zone1, calcite_zone1, csh_zone1, portlandite_zone1, ettringite_zone1, katoite_zone1, hydrotalcite_zone1])
zone1.mineral_zone = mineral_zone1

writeChemical = t2chemical(t2reactgrid=react.grid)
writeChemical.minerals = all_minerals
writeChemical.title = 'Automating Tough react'
writeChemical.primary_aqueous = all_species
writeChemical.gases = initial_co2
writeChemical.write()

#____________________________________SOLUTE.INP__________________________________________
writeSolute = t2solute(writeChemical)
writeSolute.nodes_to_write = [0]
masa = writeSolute.getgrid_info()
writeSolute.write()

#___________________________________ RUN SIMULATION ______________________________________
react.run(simulator='treacteos1.exe', runlocation=os.getcwd())

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Contributing to the code would involve you following the below procedures to quickly get started

  1. Clone the repo using preferred cloning method
  2. Install the library to enable you able to use the test example using
pip install -e .
  1. Modify the code
  2. Tests are conducted with pytest and coverage reports are performed using pytest-cov. Install pytest and pytest-cov using the commands below
pip install pytest
pip install pytest-cov
  1. Run tests: Run the below command from the root folder to run the tests
pytest
  1. Flake8 is also used to ensure code readability. Install flake8 using
pip install flake8

and run flake8 using

flake8 src
  1. Make a pull request after passing all tests
  2. More information can be found in developer notes in the documentation - https://pytoughreact.readthedocs.io/en/master/developer.html

Documentation

Documentation can be found here https://pytoughreact.readthedocs.io/en/latest/

License

MIT

Tests

Tests JOSS Article Dependabot GitHub contributors PyPI - Version PyPI - License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytoughreact-1.0.4.tar.gz (90.0 kB view hashes)

Uploaded Source

Built Distribution

pytoughreact-1.0.4-py3-none-any.whl (125.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page