In [94]:
import os
os.sys.path.append("C:\\Users\\amin\\Documents\\Repos\\OpenPNM")
One of the main applications of OpenPNM
is simulating transport phenomena such as Fickian diffusion, advection diffusion, reactive transport, etc. In this example, we will learn how to perform advection diffusion on a Cubic
network. The algorithm works fine with every other network type, but for now we want to keep it simple. In OpenPNM
, we've implemented 4 different discretization schemes for the advection diffusion:
Depending on the Peclet regime, the results you get from these schemes might differ. To be on the safe side, either use Powerlaw
or the Exact
scheme.
In [95]:
import openpnm as op
net = op.network.Cubic(shape=[1, 10, 10], spacing=1e-4)
Next, we need to add a geometry to the generated network. A geometry contains information about size of the pores/throats in a network. OpenPNM
has tons of prebuilt geometries that represent the microstructure of different materials such as Toray090 carbon papers, sand stone, electrospun fibers, etc. For now, we stick to a sample geometry called StickAndBall
that assigns random values to pore/throat diameters.
In [96]:
geom = op.geometry.StickAndBall(network=net, pores=net.Ps, throats=net.Ts)
In [97]:
air = op.phases.Air(network=net)
Finally, we need to add a physics. A physics object contains information about the working fluid in the simulation that depend on the geometry of the network. A good example is diffusive conductance, which not only depends on the thermophysical properties of the working fluid, but also depends on the geometry of pores/throats.
In [98]:
phys_air = op.physics.Standard(network=net, phase=air, geometry=geom)
Note that the advection diffusion algorithm assumes that velocity field is given. Naturally, we solve Stokes flow inside a pore network model to obtain the pressure field, and eventually the velocity field. Therefore, we need to run the StokesFlow
algorithm prior to running our advection diffusion. There's a separate tutorial on how to run StokesFlow
in OpenPNM
, but here's a simple code snippet that does the job for us.
In [99]:
sf = op.algorithms.StokesFlow(network=net, phase=air)
sf.set_value_BC(pores=net.pores('left'), values=200.0)
sf.set_value_BC(pores=net.pores('right'), values=0.0)
sf.run();
It is essential that you attach the results from StokesFlow
(i.e. pressure field) to the corresponding phase, since the results from any algorithm in OpenPNM
are by default only attached to the algorithm object (in this case to sf
). Here's how you can update your phase:
In [100]:
air.update(sf.results())
Now that everything's set up, it's time to perform our advection diffusion simulation. For this purpose, we need to add corresponding algorithm to our simulation. As mentioned above, OpenPNM
supports 4 different discretizations, 3 of which are encapsulated in AdvectionDiffusion
and the one based on the exact solution is located in Dispersion
. First let's use AdvectionDiffusion
:
In [101]:
ad = op.algorithms.AdvectionDiffusion(network=net, phase=air)
Note that network
and phase
are required parameters for pretty much every algorithm we add, since we need to specify on which network and for which phase do we want to run the algorithm.
So far, we haven't mentioned how you specify the discretization. You can specify the discretization by modifying the settings
of our AdvectionDiffusion
algorithm. You can choose between upwind
, hybrid
and powerlaw
.
In [102]:
ad.settings.update({'s_scheme': 'powerlaw'})
In [103]:
inlet = net.pores('left')
outlet = net.pores(['right', 'top', 'bottom'])
ad.set_value_BC(pores=inlet, values=100.0)
ad.set_value_BC(pores=outlet, values=0.0)
set_value_BC
applies the so-called "Dirichlet" boundary condition to the specified pores. Note that unless you want to apply a single value to all of the specified pores (like we just did), you must pass a list (or ndarray
) as the values
parameter.
In [104]:
ad.run();
When an algorithm is successfully run, the results are attached to the same object. To access the results, you need to know the quantity for which the algorithm was solving. For instance, AdvectionDiffusion
solves for the quantity pore.concentration
, which is somewhat intuitive. However, if you ever forget it, or wanted to manually check the quantity, you can take a look at the algorithm settings
:
In [105]:
print(ad.settings)
Now that we know the quantity for which AdvectionDiffusion
was solved, let's take a look at the results:
In [106]:
c = ad['pore.concentration']
print(c)
In [107]:
print('Network shape:', net._shape)
c2d = c.reshape((net._shape))
In [108]:
import matplotlib.pyplot as plt
plt.imshow(c2d[0,:,:])
plt.title('Concentration (mol/m$^3$)')
plt.colorbar()
Out[108]: