je-santos / MPLBM-UT

Library for performing multiphase simulations (based on the Shan-Chen model) in complicated geometries (i.e. porous media 3D images)
GNU General Public License v3.0
145 stars 56 forks source link
cfd fractures images lattice-boltzmann micro-ct mrt multiphase multiphase-flow palabos parallel permeability pore-network porous-media porous-media-flow reactive relative-permeability rock shan-chen tortuosity volumes

================================================================================ MPLBM-UT: MultiPhase and singlephase LBM library for permeable media analysis

.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.5203295.svg :target: https://doi.org/10.5281/zenodo.5203295 Check out our SoftwareX paper! <https://doi.org/10.1016/j.softx.2022.101097>_

MPLBM-UT supports the calculation of capillary pressure and relative permeability curves and single phase permeability of 3D binary images. The direct fluid flow simulation is performed using Palabos v2.2.1 and the pre-processing and post-processsing are done in python. We use the Shan-Chen model for the multiphase simulation and the BGK and MRT for the singlephase simulation.

We have tested all the above on a laptop and a supercomputer. If you have any issues, drop by our FAQ section <https://github.com/je-santos/MPLBM-UT/blob/master/README.rst#faq>_ . If you cannot find what you are looking for, open an issue.

################################################################################ Illustrations ################################################################################

.. figure:: /illustrations/purple_lbm.gif :align: right :alt: alternate text :figclass: align-right

Steady-state simulation: Non-wetting fluid (purple) traveling through a spherepack.

.. figure:: /illustrations/youtube.png :align: right :alt: alternate text :figclass: align-right :target: https://www.youtube.com/watch?v=cEBHl5T3dtU

MPLBM Youtube tutorial by `TuxRiders <https://www.youtube.com/@TuxRiders>`_.

.. figure:: /illustrations/Tropical_simulation.gif :align: right :alt: alternate text :figclass: align-right

Unsteady-state flow simulation: Showing capillary pressure increments with different colors.

.. figure:: /illustrations/single_phase.png :align: right :alt: alternate text :figclass: align-right

Single-phase simulation: Velocity magnitude in log scale.

################################################################################ Overview ################################################################################

This library provides tools to interact with the powerful palabos simulation engine. Its aim is to provide ready-to-go tools to compute relevant properties for permeable media. It includes scripts for creating efficient geometries for simulation, single and multiphase models with various boundary conditions, and extensive postprocesing tools. The Palabos backend makes the simulation engine flexible enought to be run on a single core of a personal computer or in hundreds of nodes of a supercomputer.

################################################################################ Requirements ################################################################################

################################################################################ Some Prerequisites ################################################################################ Some familiarity with the terminal, unix operating systems, and bash will be very useful. Here are a few things to keep in mind when running simulations:

################################################################################ Installation ################################################################################ The installation script will install/compile Palabos <src/>_, the one-phase simulation code <src/1-phase_LBM>_, the two-phase Shan-Chen code <src/2-phase_LBM>_, and the mplbm_utils python package </src/python/mplbm_utils>__. In the parent directory of the repo, run the installation script with the following command:

.. code-block:: bash

./Install.sh

################################################################################ Running a simulation ################################################################################ The examples <examples>__ are a great place to see how the code can be used in different ways. In general, each example has a Python script, input file, an input folder, and an output folder(s):

Please refer to the unsteady state example </examples/unsteady_rel_perm> and the steady state example </examples/steady_state_relperm> for complete end-to-end workflows.

An general overview of the main steps of a simulation is given below. These processes are automated by functions in the mplbm_utils </src/python/mplbm_utils>__ folder.


1) Parsing inputs

The input.yml files in each example contain all the input options for a simulation. parse_input_file.py </src/python/mplbm_utils/parse_input_file.py>__ parses the input file and stores the entries as a Python dicationary.

2) Pre-processing

This is necessary to create an efficient geometry for simulating with Palabos (.dat file) from the initial geometry file. create_geom_for_palabos.py </src/python/mplbm_utils/create_geom_for_palabos.py>__ uses the utilities found in pore_utils.py </src/python/mplbm_utils/pore_utils.py>__ to create the .dat file.

3) Run a simulation

The examples provide either a python file (2_phase_sim.py or 1_phase_sim.py) that provides the details of running a simualtion. Based on the user inputs, create_palabos_input_file.py </src/python/mplbm_utils/create_palabos_input_file.py>__ creates an XML file compatible with palabos, and then a bash file is created that contains all the necessary information to run either ShanChen <src/2-phase_LBM/>__ for 2-phase or one of the 1-phase permeability options <src/1-phase_LBM>_.

A relative permeability simulation is also possible after a 2-phase simulation. create_geom_for_rel_perm.py </src/python/mplbm_utils/create_geom_for_rel_perm.py>__ processes the resulting 2-phase geometries so realtive permeability can be calculated based on individual single phase simulations.

4) Post-processing

parse_palabos_output.py </src/python/mplbm_utils/parse_palabos_output.py>__ contains the functions necessary to parse and save palabos outputs as easy-to-use text files. create_geom_for_rel_perm.py </src/python/mplbm_utils/create_geom_for_rel_perm.py>__ also contains the methods to calculate fluid saturation after a 2-phase simulation.

5) Plotting and visualization

Plotting and visualization can be done using the various utilities provided in the examples <examples> folder, and the animation_and_plotting </src/python/animation_and_plotting> folder. The 3D visualization tools create iso-surfaces of the fluid density from the .vti files to visualize fluid interfaces. General plotting utilities are also available to create capillary pressure and realtive permeability curves. You can also view .vti files with Paraview <https://www.paraview.org/>_ and perform 2-3-4D visualization of fluid interfaces.

################################################################################ Numerical validations ################################################################################

################################################################################ Example description ################################################################################

################################################################################ FAQ ################################################################################

1. Why am I getting an error like "HYDU_create_process (./utils/launch/launch.c:69): execvp error on file ../../src/2-phase_LBM/ShanChen (No such file or directory)"?

| A- This is because the simulation code has not compiled correctly. To solve this, first try to again run

.. code-block:: bash

./Install.sh

If this does not work, you can open the bash terminal from the main folder and type following commands sequentially.

.. code-block:: bash

cd src unzip palabos-v2.2.1.zip cd 2-phase_LBM/build cmake .. make cd ../../1-phase_LBM/build cmake .. make


2. I am getting a segmentation error. What to do?

| A- Image dimensions are not correct, try switching the dimensions.


3. My image is loaded properly but it doesn't look right. What happened?

| A- This is likely because Palabos engine switches the X and Z coordinates. The inbuilt option to switch X and Z coordinates is available as

.. code-block:: bash

geom.swapXZ = true;

in all geometry creation files (for example line 26 <examples/unsteady_relperm_spherepack/create_geom_4_2phase.m>_.).


4. I have a SCons compilation error. What to do?

| A- SCons compilation error: Because of the palabos source code.

"../MultiphasePorousMediaPalabos-0.1.0/src/palabos-v2.0r0/src/gridRefinement/couplingInterfaceGenerator3D.h" line 145, "return dataProcessors;" should be "return *dataProcessors;".


5. Why am I seeing the same line printed multiple times? / Why is the code so slow?

| A- Probably MPI is not installed in your system, this could be solved by:

.. code-block:: bash

sudo apt-get install build-essential sudo apt-get install gfortran cd /tmp wget http://www.mpich.org/static/downloads/1.4.1/mpich2-1.4.1.tar.gz tar xzvf mpich2-1.4.1.tar.gz cd mpich2-1.4.1/ ./configure make sudo make install

Note that this process takes a few hours.


6. I am getting a Java Heap Memory error in Matlab. What to do?

| A- You need to change the JavaHeapMemory setting in Matlab:

If you're working on a remote system/cluster or supercomputer, the easiest way to do this is to find and change your matlab.prf file diretly.

You will find the matlab.prf in your user storage directory. It will be something like: [user home]/.matlab/[Matlab version]/matlab.prf

Once the file is open add the following line to the file: JavaMemHeapMax = [Java Memory Code] You will need to find the sepcific Java memory code that corresponds to the amount of RAM you need.

Or you can try this fix (If you are on a remote system, cluster, or supercomputer this may not work): https://www.mathworks.com/matlabcentral/answers/74296-change-java-heap-memory-settings-without-starting-matlab


7. I am getting an error related to the class auto_ptr

| A- This is because you are using a newer cpp compiler. Subsitute the auto_ptr with unique_ptr in the .cpp files

################################################################################ Author's Publications ################################################################################

  1. Bihani A., Daigle H., Santos J., Landry C., Prodanović M., Milliken K. (2019). H44B-06: Insight into the Sealing Capacity of Mudrocks determined using a Digital Rock Physics Workflow. AGU Fall Meeting, 9-13 December, San Francisco, USA.

  2. Santos, J. E., Prodanovic, M., Landry, C. J., & Jo, H. (2018, August 9). Determining the Impact of Mineralogy Composition for Multiphase Flow Through Hydraulically Induced Fractures. Unconventional Resources Technology Conference. doi:10.15530/URTEC-2018-2902986

  3. Landry, C. J., Karpyn, Z. T., and Ayala, O. (2014), Relative permeability of homogenous‐wet and mixed‐wet porous media as determined by pore‐scale lattice Boltzmann modeling, Water Resour. Res., 50, 3672– 3689, doi:10.1002/2013WR015148.

  4. Santos, J. E., Xu, D., Jo, H., Landry, C. J., Prodanović, M., & Pyrcz, M. J. (2020). PoreFlow-Net: A 3D convolutional neural network to predict fluid flow through porous media. Advances in Water Resources, 138, 103539.

  5. Gigliotti A., Hesse M., Prodanovic M., Pore-Scale Simulation of Two-Phase Melt Percolation During Core Formation in Planetesimals (Mar. 2021). LPSC, https://www.hou.usra.edu/meetings/lpsc2021/pdf/2328.pdf

  6. Gigliotti A. (2021, August 13), Two-phase percolation in texturally equilibrated porous media, http://dx.doi.org/10.26153/tsw/21533

  7. Santos, J. E., Pyrcz, M. J., & Prodanović, M. (2022). 3D Dataset of binary images: A collection of synthetically created digital rock images of complex media. Data in Brief, 107797.

################################################################################ External Publications ################################################################################

  1. Xu, R. et al (2020). Pore-scale study of water adsorption and subsequent methane transport in clay in the presence of wettability heterogeneity. Water Resources Research

  2. Jonathan B. Grunewald et al 2021 J. Electrochem. Soc. 168 024521

################################################################################ Bibliographic References ################################################################################

  1. Unsteady state simulation set-up: Pan, C., Hilpert, M., and Miller, C. T. ( 2004), Lattice‐Boltzmann simulation of two‐phase flow in porous media, Water Resour. Res., 40, W01501, https://doi.org/10.1029/2003WR002120.

  2. Contact angle approximation: Huang, H., Thorne, D. T., Schaap, M. G., & Sukop, M. C. (2007). Proposed approximation for contact angles in Shan-and-Chen-type multicomponent multiphase lattice Boltzmann models. Physical Review E - Statistical, Nonlinear, and Soft Matter Physics, 76(6), 1–6. https://doi.org/10.1103/PhysRevE.76.066701.

  3. Fluid flow model: Santos, J. E. (2018). Lattice-Boltzmann modeling of multiphase flow through rough heterogeneously wet fractures. University of Texas at Austin (Master thesis). https://repositories.lib.utexas.edu/handle/2152/69246.

################################################################################ Contributing ################################################################################

We welcome contributions. Find some ideas below:

################################################################################ Citing MPLBM-UT ################################################################################ Please cite our SoftwareX paper <https://doi.org/10.1016/j.softx.2022.101097>_:

Santos, J. E., Gigliotti, A., Bihani, A., Landry, C., Hesse, M. A., Pyrcz, M. J., & Prodanović, M. (2022). MPLBM-UT: Multiphase LBM library for permeable media analysis. SoftwareX, 18, 101097. https://doi.org/10.1016/j.softx.2022.101097