Simulating Single Phase Transport#

The point of an OpenPNM simulation is ultimately to compute some transport process. In this notebook we will cover the following subjects:

  • Defining conductance

  • Settings boundary conditions

Start by defining a network. We’ll use the Demo class which happens to include all the geometrical pore-scale models already.

import numpy as np
import openpnm as op
pn = op.network.Demo(shape=[5, 5, 1], spacing=5e-5)
print(pn)
══════════════════════════════════════════════════════════════════════════════
net : <openpnm.network.Demo at 0x7fdb9061b590>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Properties                                                   Valid Values
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.coords                                                       25 / 25
  3  throat.conns                                                      40 / 40
  4  pore.coordination_number                                          25 / 25
  5  pore.max_size                                                     25 / 25
  6  throat.spacing                                                    40 / 40
  7  pore.seed                                                         25 / 25
  8  pore.diameter                                                     25 / 25
  9  throat.max_size                                                   40 / 40
 10  throat.diameter                                                   40 / 40
 11  throat.cross_sectional_area                                       40 / 40
 12  throat.hydraulic_size_factors                                     40 / 40
 13  throat.diffusive_size_factors                                     40 / 40
 14  throat.lens_volume                                                40 / 40
 15  throat.length                                                     40 / 40
 16  throat.total_volume                                               40 / 40
 17  throat.volume                                                     40 / 40
 18  pore.volume                                                       25 / 25
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Labels                                                 Assigned Locations
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.surface                                                           16
  3  throat.surface                                                         16
  4  pore.left                                                               5
  5  pore.right                                                              5
  6  pore.front                                                              5
  7  pore.back                                                               5
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Define Phase Viscosity#

To fully illustrate the process of performing transport calculations, we’ll use an empty Phase object and add all the needed properties manually:

water = op.phase.Phase(network=pn)

Let’s assume that we are interested in pressure driven flow. This requires knowing the viscosity of the phase, so let’s add a pore-scale model for computing the viscosity of water:

water.add_model(propname='pore.viscosity',
                model=op.models.phase.viscosity.water_correlation)
print(water)
══════════════════════════════════════════════════════════════════════════════
phase_01 : <openpnm.phase.Phase at 0x7fdb46031590>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Properties                                                   Valid Values
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.temperature                                                  25 / 25
  3  pore.pressure                                                     25 / 25
  4  pore.viscosity                                                    25 / 25
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Labels                                                 Assigned Locations
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.all                                                               25
  3  throat.all                                                             40
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

And we can check the individual values to verify they make sense:

print(water['pore.viscosity'])
[0.00089319 0.00089319 0.00089319 0.00089319 0.00089319 0.00089319
 0.00089319 0.00089319 0.00089319 0.00089319 0.00089319 0.00089319
 0.00089319 0.00089319 0.00089319 0.00089319 0.00089319 0.00089319
 0.00089319 0.00089319 0.00089319 0.00089319 0.00089319 0.00089319
 0.00089319]

Basic Conductance Calculation#

Determining the conductance of the conduits between each pair of connected pores is the most important part of performing a simulation. The details of conductance models are covered elsewhere. For this demonstration will assume the very simplest case where all pressure loss occurs in the throats.

Recall the Hagan-Poiseuille equation for fluid flow through a cylindrical tube:

\[ Q = \frac{\pi R^4}{8 \mu L} \Delta P\]

where \(R\) and \(L\) are the radius and length of the throat, and \(\mu\) is the viscosity of the fluid. Together this prefactor can be referred to as the hydraulic conductance, \(g_h\), giving:

\[ Q = g_h \Delta P \]

So the aim is the compute values of \(g_h\) for each throat. We start by doing this manually:

R = pn['throat.diameter']/2
L = pn['throat.length']
mu = water['throat.viscosity']  # See ProTip below
water['throat.hydraulic_conductance'] = np.pi*R**4/(8*mu*L)
print(water['throat.hydraulic_conductance'])
[5.69063722e-16 5.93571296e-16 1.41796130e-14 7.89931970e-16
 1.35154457e-14 2.45089796e-15 2.37430157e-15 1.40110120e-14
 2.41359594e-14 2.47429009e-14 4.46545981e-14 3.88335458e-15
 2.42214091e-14 1.26490216e-14 1.68254815e-15 9.42049110e-16
 1.33455668e-14 1.39284009e-14 5.82319904e-14 6.23224821e-14
 1.46816923e-14 5.32442597e-16 2.75542131e-15 1.13906520e-14
 9.38295680e-16 1.43637221e-14 1.76425387e-14 2.63652422e-15
 1.43591162e-14 3.79839652e-15 3.63264664e-14 2.04719675e-14
 1.35382821e-14 2.05439513e-15 9.72520778e-16 4.15540805e-14
 1.25594086e-14 1.40288640e-14 2.03652948e-15 1.21299729e-15]

Tip

Phase can do auotmatic interpolation to get throat values The Phase class has a special ability to interpolate pore values to throats, and vice-versa. In PNM simulations all the balances are solved for each pore, so the thermodynamic properties like temperature, pressure, etc. are all defined on pores. Consequently, the physical properties are also defined in pores, like viscosity. However, as shown above we often want viscosity values in the throats. OpenPNM provides a shortcut for this, such that if you request a throat property that does not exist, it will attempt to fetch the pores values and do a linear interpolation of values to produce an array of throat values. There is also a function for this, water.interpolate_data('throat.viscosity'), but the water['throat.viscosity'] shortcut is very convenient. The automatic interpolation can be disabled in the phase.settings.

water.interpolate_data('throat.viscosity')
array([0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319])
water['throat.viscosity']
array([0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319,
       0.00089319, 0.00089319, 0.00089319, 0.00089319, 0.00089319])

Create Algorithm Object#

OpenPNM contains a variety of Algorithm classes in the openpnm.algorithms module. Let’s initialize a StokesFlow algorithm, since this simulates pressure driven flow through the network.

sf = op.algorithms.StokesFlow(network=pn, phase=water)
print(sf)
══════════════════════════════════════════════════════════════════════════════
stokes_01 : <openpnm.algorithms.StokesFlow at 0x7fdb46044220>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Properties                                                   Valid Values
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.bc.rate                                                       0 / 25
  3  pore.bc.value                                                      0 / 25
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Labels                                                 Assigned Locations
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.all                                                               25
  3  throat.all                                                             40
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Assign Boundary Conditions#

As can be seen in the print-out above there are predefined 'pore.bc' arrays, but they contain no valid values, meaning they are all nans. Once we set some boundary conditions, this will change. Let’s apply pressure BCs on one side of the network, and rate BCs on the other:

sf.set_value_BC(pores=pn.pores('left'), values=100_000)
sf.set_rate_BC(pores=pn.pores('right'), rates=1e-10)
print(sf)
══════════════════════════════════════════════════════════════════════════════
stokes_01 : <openpnm.algorithms.StokesFlow at 0x7fdb46044220>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Properties                                                   Valid Values
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.bc.rate                                                       5 / 25
  3  pore.bc.value                                                      5 / 25
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Labels                                                 Assigned Locations
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.all                                                               25
  3  throat.all                                                             40
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Tip

All boundary conditions are preceeded with ‘pore.bc’ All boundary conditions are stored as ‘pore.bc.’, which means that OpenPNM’s dictionary lookup tricks can be used to see all types and values of bc’s using: sf['pore.bc'] which will return a dict. This can be used as shown below:

print(sf['pore.bc'].keys())
dict_keys(['rate', 'value'])

Now we can see there are 5 valid values of each type. The sf algorithm will look for 'throat.hydraulic_conductance' on water by default, so we can just run:

soln = sf.run()
stokes_01 : Newton iterations:   0%|          | 0/100 [00:00<?, ?it/s]
                                                                      

The run method solves the mass balance around each pore and computes the pressure within each pore that is required to sustain the flow defined by the boundary conditions. The soln object that is returned is a dictionary with the key corresponding to the quantity that was solved for.

print(soln)
None

The reason for the dict format is to provide a consistent API for single components and multiphysics, where multiple different quanties might be solved for. However, these 'pore.pressure' values are also written to the dictionary of the algorithm object as well:

print(sf)
══════════════════════════════════════════════════════════════════════════════
stokes_01 : <openpnm.algorithms.StokesFlow at 0x7fdb46044220>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Properties                                                   Valid Values
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.bc.rate                                                       5 / 25
  3  pore.bc.value                                                      5 / 25
  4  pore.pressure                                                     25 / 25
  5  pore.initial_guess                                                25 / 25
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Labels                                                 Assigned Locations
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.all                                                               25
  3  throat.all                                                             40
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Finally we can look at how much pressure was required in the “right” pores to meet the required flow rate:

sf['pore.pressure'][pn.pores('right')]
array([139407.40218179, 144807.78631174, 150786.49964258, 153424.17738803,
       154745.22307077])

So we can see that 150 kPa was required to accomplish the requested flow.

Rigorous Conductance Calculation#

The above demonstration used a very simplistic conductance calculation. It was also stated that computing conductance is the most important part of doing a PNM simulation. To finish this notebook, we’ll look more closely at this process.

Manual Method#

Let’s print the network object again:

print(pn)
══════════════════════════════════════════════════════════════════════════════
net : <openpnm.network.Demo at 0x7fdb9061b590>
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Properties                                                   Valid Values
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.coords                                                       25 / 25
  3  throat.conns                                                      40 / 40
  4  pore.coordination_number                                          25 / 25
  5  pore.max_size                                                     25 / 25
  6  throat.spacing                                                    40 / 40
  7  pore.seed                                                         25 / 25
  8  pore.diameter                                                     25 / 25
  9  throat.max_size                                                   40 / 40
 10  throat.diameter                                                   40 / 40
 11  throat.cross_sectional_area                                       40 / 40
 12  throat.hydraulic_size_factors                                     40 / 40
 13  throat.diffusive_size_factors                                     40 / 40
 14  throat.lens_volume                                                40 / 40
 15  throat.length                                                     40 / 40
 16  throat.total_volume                                               40 / 40
 17  throat.volume                                                     40 / 40
 18  pore.volume                                                       25 / 25
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  #  Labels                                                 Assigned Locations
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
  2  pore.surface                                                           16
  3  throat.surface                                                         16
  4  pore.left                                                               5
  5  pore.right                                                              5
  6  pore.front                                                              5
  7  pore.back                                                               5
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Note the 'throat.hydraulic_size_factors' array. This is computed by a pore-scale model on the Demo network. This computation is more rigorous in the following ways:

  1. The conductance of each half pore and that throat is considered.

  2. The throat length is computed carefully by accounting for the ‘lens’ between the intersection of the spherical pore bodies and the cylindrical throat.

  3. The net cross-sectional area of the pores are computed by integrating between the pore center and the pore-throat intersection point

The conductance of each element in the conduit is returned as an Nt-by-3 array, where columns 1 and 3 contain the hydraulic conductance of the half pore on either end of the throat, and the column 1 contains the throat conductance.

pn['throat.hydraulic_size_factors']
array([[6.57495456e-17, 5.08282565e-19, 2.14631169e-17],
       [2.14631169e-17, 5.30172508e-19, 7.24699719e-17],
       [3.02168435e-16, 1.26651020e-17, 2.07766600e-16],
       [6.08344957e-17, 7.05560085e-19, 2.91519357e-17],
       [2.20811386e-16, 1.20718738e-17, 2.34526668e-16],
       [1.09303912e-16, 2.18911987e-18, 6.49954016e-17],
       [6.49954016e-17, 2.12070467e-18, 9.88045918e-17],
       [1.99937599e-16, 1.25145091e-17, 3.18366917e-16],
       [3.40370884e-16, 2.15580204e-17, 3.18237669e-16],
       [3.18237669e-16, 2.21001351e-17, 3.57346217e-16],
       [4.37771396e-16, 3.98850828e-17, 5.39562315e-16],
       [1.86311478e-16, 3.46857715e-18, 7.95471854e-17],
       [4.09730072e-16, 2.16343433e-17, 2.89940591e-16],
       [2.34940991e-16, 1.12979916e-17, 2.08328498e-16],
       [8.57791926e-17, 1.50283678e-18, 5.04852943e-17],
       [4.08112986e-17, 8.41429737e-19, 3.61379062e-17],
       [2.69154584e-16, 1.19201394e-17, 2.07279009e-16],
       [2.07279009e-16, 1.24407216e-17, 2.93538565e-16],
       [5.28885206e-16, 5.20122866e-17, 5.97821678e-16],
       [6.15494319e-16, 5.56658769e-17, 5.53892009e-16],
       [2.83374667e-16, 1.31135546e-17, 2.20811386e-16],
       [2.14631169e-17, 4.75572907e-19, 5.46040832e-17],
       [1.46407904e-16, 2.46111737e-18, 6.49954016e-17],
       [2.02698315e-16, 1.01740272e-17, 1.99937599e-16],
       [2.91519357e-17, 8.38077207e-19, 9.47639660e-17],
       [2.20811386e-16, 1.28295466e-17, 2.70431733e-16],
       [2.61014626e-16, 1.57581559e-17, 2.80375000e-16],
       [6.49954016e-17, 2.35491956e-18, 1.32796579e-16],
       [1.99937599e-16, 1.28254326e-17, 3.31469985e-16],
       [1.79095156e-16, 3.39269339e-18, 7.95471854e-17],
       [3.83448644e-16, 3.24464709e-17, 4.87544733e-16],
       [2.99782489e-16, 1.82853760e-17, 2.89940591e-16],
       [2.74132487e-16, 1.20922710e-17, 2.08328498e-16],
       [1.39766460e-16, 1.83496714e-18, 5.04852943e-17],
       [4.83941721e-17, 8.68646755e-19, 3.61379062e-17],
       [5.16443606e-16, 3.71157285e-17, 4.20512636e-16],
       [2.34194630e-16, 1.12179501e-17, 2.07279009e-16],
       [2.08328498e-16, 1.25304543e-17, 2.94460803e-16],
       [5.04852943e-17, 1.81900970e-18, 1.37589055e-16],
       [3.61379062e-17, 1.08343819e-18, 1.00075167e-16]])

This data is called the size factor because it is purely the geometrical information required for the computation of the hydraulic conductance. So the Hagan-Poisseiulle equation for each element is written as:

\[ Q = \frac{F_h}{\mu} \Delta P = g_h \Delta P\]

Note that both the \(\frac{\pi R^4}{8}\) term and \(L\) have been rolled into the \(F_h\) value.

The total conductance of the pore-throat-pore conduit can be found as the sum of three resistors in series. Since we have conductance values, we add the inverses, and invert again. The full expression for the hydraulic conductance between pores i and j, through throat k, is:

\[ Q = \bigg( \frac{\mu}{F_{h, i}} + \frac{\mu}{F_{h, k}} + \frac{\mu}{F_{h, j}} \bigg) ^ {-1} \Delta P \]

This can be computed by hand:

F_h = water['throat.hydraulic_size_factors']
water['throat.hydraulic_conductance'] = (mu * (1/F_h).sum(axis=1))**(-1)
water['throat.hydraulic_conductance']
array([5.51732554e-16, 5.75156334e-16, 1.28569846e-14, 7.62629173e-16,
       1.22185242e-14, 2.32597237e-15, 2.25246109e-15, 1.27153148e-14,
       2.13388852e-14, 2.18713938e-14, 3.83291215e-14, 3.65588157e-15,
       2.14839667e-14, 1.14749063e-14, 1.60657692e-15, 9.02431101e-16,
       1.21125675e-14, 1.26346036e-14, 4.91265654e-14, 5.23304777e-14,
       1.32786151e-14, 5.16499719e-16, 2.61257603e-15, 1.03449910e-14,
       9.04300811e-16, 1.29924612e-14, 1.58005636e-14, 2.50152829e-15,
       1.30201291e-14, 3.57801377e-15, 3.15561741e-14, 1.82124990e-14,
       1.22834614e-14, 1.95754487e-15, 9.33333461e-16, 3.58184390e-14,
       1.13967140e-14, 1.27222683e-14, 1.94093627e-15, 1.16543932e-15])
sf = op.algorithms.StokesFlow(network=pn, phase=water)
sf.set_value_BC(pores=pn.pores('left'), values=100_000)
sf.set_rate_BC(pores=pn.pores('right'), rates=1e-10)
soln = sf.run()
sf['pore.pressure'][pn.pores('right')]
stokes_02 : Newton iterations:   0%|          | 0/100 [00:00<?, ?it/s]
                                                                      

array([143616.47947512, 149395.42135024, 155834.13272055, 158903.68599765,
       160454.57896569])

As can be seen the numbers are about the same as with the simple case, but should be somewhat more correct. In fact, these above pressures are a bit higher, which is because the total conductance of the conduit is lower due to the inclusion of the pore body lengths into the total length, compared to above where only the throat length was included.

Pore-Scale Model Method#

Instead of computing the hydraulic conductance manually as done above, there is a pore-scale model available:

water.add_model(propname='throat.hydraulic_conductance',
                model=op.models.physics.hydraulic_conductance.generic_hydraulic)
sf = op.algorithms.StokesFlow(network=pn, phase=water)
sf.set_value_BC(pores=pn.pores('left'), values=100_000)
sf.set_rate_BC(pores=pn.pores('right'), rates=1e-10)
soln = sf.run()
sf['pore.pressure'][pn.pores('right')]
stokes_03 : Newton iterations:   0%|          | 0/100 [00:00<?, ?it/s]
                                                                      

array([143616.47947512, 149395.42135024, 155834.13272055, 158903.68599765,
       160454.57896569])

Which gives exactly the same result, without have to manually deal with the conductances-in-series calculation.