Pre- and post-processing Python library for TOUGH
Project description
TOUGH (Transport Of Unsaturated Groundwater and Heat) is a general purpose numerical simulation software designed for fluid and heat flows of multiphase, multicomponent fluid mixtures in porous and fractured media developed at Lawrence Berkeley National Laboratory. It solves mass and energy balance equations that describe fluid and heat flow in multiphase and multicomponent systems. TOUGH handles all types of multiphase and multicomponent flow systems since the governing equations for fluid and heat flow have the same mathematical form. The nature and properties of fluid mixtures are described by thermophysical variables (e.g., density, viscosity, enthalpy) which are provided by an equation-of-state (EOS) module.
toughio is an open-source library that provides tools to facilitate pre- and post-processing for TOUGH using the latest Python standards. It aims to make setting up of a TOUGH simulation user-friendly by relying on existing well-established Python packages:
numpy: vectorized calculation of N-dimensional arrays,
meshio: input/output for many mesh formats,
pyvista: 3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK).
Note that the results of a TOUGH simulation are sensitive to the quality of the mesh (ideally, it should satisfy the orthogonality condition). A mesh that contains too many ill-shaped cells can potentially lead to unexpected results although the simulation converged successfully. toughio does not verify the quality of the mesh which is left to the discretion of the user.
Features
Meshing:
Create simple 2D cylindric or 2D/3D structured meshes similarly to TOUGH’s built-in MESHMAKER,
Import mesh generated by external softwares (e.g., Abaqus, FLAC3D, Gmsh, LaGriT),
Export imported or generated mesh to a MESH file for TOUGH assuming conformity (and optionally write initial condition file INCON).
Pre-processing:
Easily add initial conditions, boundary conditions or other physical properties (e.g., porosity, permeability) using the convenient class toughio.Mesh,
Import previous TOUGH simulation input file into Python or define simulation parameters in a human-readable and JSONable dictionary,
Export simulation parameters dictionary to a TOUGH input file.
Post-processing:
Installation
The recommended way to install toughio and all its dependencies is through the Python Package Index:
pip install toughio[full] --user
Otherwise, clone and extract the package, then run from the package location:
pip install .[full] --user
To test the integrity of the installed package, check out this repository and run:
git lfs pull
pytest
Documentation
Refer to the online documentation for detailed description of the API and examples.
Alternatively, the documentation can be built using Sphinx:
pip install -r doc/requirements.txt
sphinx-build -b html doc/source doc/build
Note that some sample files are stored with LFS, so you may have to run the following command beforehand:
git lfs pull
Usage
In Python, to read a mesh and write the corresponding TOUGH MESH file (without any pre-processing), simply do
import toughio
mesh = toughio.read_mesh(
filename,
file_format="flac3d", # Optional, inferred from file extension otherwise
)
mesh.write_tough() # Write MESH file
Parameters of a TOUGH simulation can be defined as a dictionary with specific keywords following the JSON standard, for instance
parameters = {
"title": "Sample title",
"eos": "eco2n",
"isothermal": False,
"default": { # Default rock properties
"density": 2600.0,
"porosity": 0.1,
# "permeability", "conductivity", "specific_heat"...
},
"rocks": {
"shale": { # To overwrite default rock properties
"capillarity": {
"id": 1,
"parameters": [0.0, 0.0, 1.0],
},
# same keywords as in "default"
},
# other materials
},
"options": {
"n_cycle": 100,
"t_max": 3.0 * 365.25 * 24.0 * 3600.0,
# "t_ini", "t_steps", "t_step_max", "gravity", "eps1", "eps2"...
},
# "extra_options", "selections", "solver", "generators"...
}
toughio.write_input("INFILE", parameters)
TOUGH simulation output can also be imported into Python as a list of namedtuple (type, format, time, labels, data)
output = toughio.read_output(filename)
toughio is mainly intended to be used as a Python scripting library for TOUGH. Nevertheless, several utility command line scripts are available for users who are not familiar with Python. From a console or terminal, the user can execute the following scripts:
toughio-co2tab: copy file CO2TAB to the target directory,
toughio-export: export TOUGH simulation results to a file for visualization (VTK, VTU, Tecplot or XDMF),
toughio-extract: extract results from TOUGH main output file and reformat as a TOUGH3 element or connection output file (mostly useful for TOUGH2 output before calling toughio-export),
toughio-merge: merge input file, GENER and/or MESH and/or INCON into a single file,
toughio-save2incon: convert a SAVE file to an INCON file (mostly useful to automatically restart a simulation and reset the counters).
Contributing
Please refer to the Contributing Guidelines to see how you can help. This project is released with a Code of Conduct which you agree to abide by when contributing.
Notice
toughio Copyright (c) 2022, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved. If you have questions about your rights to use or distribute this software, please contact Berkeley Lab’s Intellectual Property Office at IPO@lbl.gov.
This Software was developed under funding from the U.S. Department of Energy and the U.S. Government consequently retains certain rights. As such, the U.S. Government has been granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the Software to reproduce, distribute copies to the public, prepare derivative works, and perform publicly and display publicly, and to permit others to do so.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file toughio-1.15.1.tar.gz
.
File metadata
- Download URL: toughio-1.15.1.tar.gz
- Upload date:
- Size: 320.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fac348fc13115b92b408b91bcf2433ff75390858f91b0b2471ad966551d13a0 |
|
MD5 | cb0112796008781a1dea16382feb1efc |
|
BLAKE2b-256 | eae78cdc940aa85a9fdf100b4518b1815a165874d5a96e3bf48d72d5a213d43a |
File details
Details for the file toughio-1.15.1-py3-none-any.whl
.
File metadata
- Download URL: toughio-1.15.1-py3-none-any.whl
- Upload date:
- Size: 363.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 109fdf211db4b0d41220210a6df93986d9f249169f709577872401b6b96a7c25 |
|
MD5 | a69d2cebdc440b885ef70b1d323035af |
|
BLAKE2b-256 | d89a0ea8195aa539ef2f79ab519cdf563aaeeca8862269c18f4d9e8837ad3cb5 |