# toughio
![license](https://img.shields.io/badge/license-MIT-green)
[![version](https://img.shields.io/pypi/v/toughio.svg?style=flat)](https://pypi.org/project/toughio)
![black](https://img.shields.io/badge/style-black-black)

[TOUGH](https://tough.lbl.gov/) (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``**](https://numpy.org/): vectorized calculation of N-dimensional arrays,

* [**``meshio``**](https://github.com/nschloe/meshio): input/output for many mesh formats,

* [**``pyvista``**](https://github.com/pyvista/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 wrong 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

* Create simple 2D or 3D structured meshes similarly to TOUGH's built-in *MESHMAKER*,

* Import mesh generated by external softwares (e.g. [FLAC3D](https://www.itascacg.com/software/flac3d), [Gmsh](http://gmsh.info/), [LaGriT](https://meshing.lanl.gov/)) and write the corresponding *MESH* file for TOUGH **assuming [conformity](https://www.quora.com/What-is-non-conformal-mesh-in-CFD)** (and optionally write initial condition file *INCON*),

* Easily add initial conditions, boundary conditions or other physical properties using the convenient class ``toughio.Mesh``,

* Define simulation parameters for TOUGH using the popular and more human-readable [JSON](http://json.org/) standard and write the corresponding input file for TOUGH,

* Import outputs of a TOUGH simulation into Python,

* Visualize results directly in Python using [**``pyvista``**](https://github.com/pyvista/pyvista) or export the results to another format supported by [**``meshio``**](https://github.com/nschloe/meshio) (e.g. VTK, Tecplot...).


## Installation

The recommended way to install **``toughio``** and all its dependencies is through the Python Package Index:

```bash
pip install toughio[full] --user
```

Otherwise, clone and extract the package, then run from the package location:

```bash
pip install .[full]
```