import IPython
from IPython.display import HTML, display
This section deals with the module imports for this notebook. This section needs to complete for the notebook to work correctly.
My anaconda setup:
pip install openpnm or OpenPNM
import IPython
from IPython.display import HTML, display
import datetime
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
import scipy as sp
import pandas as pd
import pylab as plt
import matplotlib.mlab as mlab
%matplotlib notebook
import urllib.request
import os
import sys
import gzip
import zipfile
import shutil
try:
import OpenPNM as pnm
except Exception as ex:
print('OpenPNM is not installed. Please us pip or conda to install.')
print('='*50)
print(ex)
print('Notebook Executed:\t ' + str(datetime.datetime.now()))
print('='*80)
print('Python Version:')
print('-'*80)
print(sys.version)
print('-'*80)
print('OpenPNM Version:', pnm.__version__)
print('='*80)
# Generate a cubic network and define a simple sitik an ball geometry
pnm.clear()
cubic = {}
cubic['network'] = pnm.Network.Cubic(shape=[10, 10, 10], spacing=0.0001, name= 'cubic:TOP')
cubic['geo'] = pnm.Geometry.Stick_and_Ball(network=cubic['network'],
pores=cubic['network'].Ps, throats=cubic['network'].Ts,
name='cubic:GEO')
cubic['geo'].plot_histograms()
cubic['geo'].labels()
fig = pnm.Network.tools.plot_coordinates(network=cubic['geo'],pores=cubic['geo'].pores('internal'))
fig = pnm.Network.tools.plot_coordinates(network=cubic['geo'],pores=cubic['geo'].pores('left'),c='r',fig=fig)
fig = pnm.Network.tools.plot_coordinates(network=cubic['geo'],pores=cubic['geo'].pores('right'),c='g',fig=fig)
fig = pnm.Network.tools.plot_connections(network=cubic['network'])
fig = pnm.Network.tools.plot_coordinates(network=cubic['network'],pores=cubic['network'].pores('internal'), fig = fig)
fig = pnm.Network.tools.plot_coordinates(network=cubic['network'],pores=cubic['network'].pores('left'),c='r',fig=fig)
fig = pnm.Network.tools.plot_coordinates(network=cubic['network'],pores=cubic['network'].pores('right'),c='g',fig=fig)
# Define phases
cubic['Hg'] = pnm.Phases.Mercury(network=cubic['network'],name='cubic:phase:Hg')
cubic['Air'] = pnm.Phases.Air(network=cubic['network'],name='cubic:phase:Air')
cubic['phys'] = pnm.Physics.Standard(network=cubic['network'],
phase=cubic['Hg'], pores=cubic['network'].Ps, throats=cubic['network'].Ts,
name='cubic:PHYS')
# Setup MIP simulation
cubic['MIP'] = pnm.Algorithms.Drainage(network=cubic['network'],name='cubic:ALG:MIP')
cubic['MIP'].setup(invading_phase=cubic['Hg'], defending_phase=cubic['Air'])
cubic['MIP'].set_inlets(pores=cubic['network'].pores(['left']))
cubic['MIP'].run()
fig = cubic['MIP'].plot_drainage_curve();
df = pd.DataFrame.from_dict(cubic['MIP'].get_drainage_data())
df
plt.figure()
plt.plot(df.capillary_pressure,df.invading_phase_saturation,'ro-',label='Invading Phase')
plt.plot(df.capillary_pressure,df.defending_phase_saturation,'gx--',label='Defending Phase')
plt.legend()
plt.xlabel('Capillary Pressure $[Pa]$')
plt.ylabel('Saturation $[1]$')
plt.grid()
cubic['MIP'].return_results(Pc=cubic['MIP'].get_drainage_data()['capillary_pressure'][-1])
pnm.export_data(network=cubic['network'], filename='cubic_MIP')
df.to_csv('cubic_MIP.csv')
pnm.clear()
delaunay = {}
# Generate Geometry
delaunay['network'] = pnm.Network.Delaunay(num_pores=200, domain_size=[1.5e-4, 1.5e-4, 1.5e-4],name='Delaunay:TOP')
print("="*50,'\nOriginal Network Lables')
print(delaunay['network'].labels())
delaunay['network'].add_boundaries()
fig = pnm.Network.tools.plot_connections(network = delaunay['network']);
fig = pnm.Network.tools.plot_coordinates(network = delaunay['network'],fig=fig)
fig = pnm.Network.tools.plot_coordinates(network = delaunay['network'],fig=fig,
pores=delaunay['network'].pores('bottom_boundary'),c='r')
fig = pnm.Network.tools.plot_coordinates(network = delaunay['network'],fig=fig,
pores=delaunay['network'].pores('top_boundary'),c='g')
print("="*50,'\nNetwork lables after boundaries were added')
print(delaunay['network'].labels())
# Generate Geometry (Pore radii + fibre radii)
fibre_rad = 5e-6
Ps = delaunay['network'].pores()
Ts = delaunay['network'].find_neighbor_throats(pores=Ps, mode='intersection', flatten=True)
delaunay['geo'] = pnm.Geometry.Voronoi(network=delaunay['network'], pores=Ps, throats=Ts,
fibre_rad=fibre_rad, voxel_vol=True,
vox_len=1e-6, name='Delaunay:GEO')
#plot all pores in the Voronoi geometry
import OpenPNM.Utilities.vertexops as vo
fig = vo.plot_pore(delaunay['geo'], delaunay['geo'].pores())
#fig = pnm.Network.tools.plot_connections(network = vor,fig=fig)
fig = pnm.Network.tools.plot_coordinates(network = delaunay['network'],
fig=fig,pores=delaunay['network'].pores('boundary'),
c='g')
throats = delaunay['network'].find_neighbor_throats(pores=[0])
#plot all throats connected to the first pore in the network
fig = vo.plot_throat(delaunay['geo'], throats)