forked from PMEAL/OpenPNM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_script.py
103 lines (91 loc) · 4.74 KB
/
run_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import OpenPNM
print('-----> Using OpenPNM version: '+OpenPNM.__version__)
ctrl = OpenPNM.Base.Controller()
#==============================================================================
'''Build Topological Network'''
#==============================================================================
pn = OpenPNM.Network.Cubic(shape=[5,6,7],spacing=0.0001,name='net')
pn.add_boundaries()
#==============================================================================
'''Build Geometry'''
#==============================================================================
Ps = pn.pores('boundary',mode='not')
Ts = pn.find_neighbor_throats(pores=Ps,mode='intersection',flatten=True)
geom = OpenPNM.Geometry.Toray090(network=pn,pores=Ps,throats=Ts)
Ps = pn.pores('boundary')
Ts = pn.find_neighbor_throats(pores=Ps,mode='not_intersection')
boun = OpenPNM.Geometry.Boundary(network=pn,pores=Ps,throats=Ts)
#==============================================================================
'''Build Phases'''
#==============================================================================
air = OpenPNM.Phases.Air(network=pn,name='air')
air['pore.Dac'] = 1e-7 # Add custom properties directly
water = OpenPNM.Phases.Water(network=pn,name='water')
#==============================================================================
'''Build Physics'''
#==============================================================================
Ps = pn.pores()
Ts = pn.throats()
phys_water = OpenPNM.Physics.Standard(network=pn,phase=water,pores=Ps,throats=Ts)
phys_air = OpenPNM.Physics.Standard(network=pn,phase=air,pores=Ps,throats=Ts)
#Add some additional models to phys_air
phys_air.models.add(model=OpenPNM.Physics.models.diffusive_conductance.bulk_diffusion,
propname='throat.gdiff_ac',
pore_diffusivity='pore.Dac')
#==============================================================================
'''Begin Simulations'''
#==============================================================================
'''Perform a Drainage Experiment (OrdinaryPercolation)'''
#------------------------------------------------------------------------------
OP_1 = OpenPNM.Algorithms.OrdinaryPercolation(network=pn,invading_phase=water,defending_phase=air)
Ps = pn.pores(labels=['bottom_boundary'])
OP_1.run(inlets=Ps)
OP_1.return_results(Pc=7000)
#------------------------------------------------------------------------------
'''Perform Invasion Percolation'''
#------------------------------------------------------------------------------
inlets = pn.pores('bottom_boundary')
outlets = pn.pores('top_boundary')
IP_1 = OpenPNM.Algorithms.InvasionPercolation(network=pn,name='IP_1')
IP_1.run(phase=water,inlets=inlets)
IP_1.apply_flow(flowrate=1e-15)
IP_1.return_results()
#------------------------------------------------------------------------------
'''Perform Fickian Diffusion'''
#------------------------------------------------------------------------------
alg = OpenPNM.Algorithms.FickianDiffusion(network=pn,phase=air)
# Assign Dirichlet boundary conditions to top and bottom surface pores
BC1_pores = pn.pores('right_boundary')
alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=0.6, pores=BC1_pores)
BC2_pores = pn.pores('left_boundary')
alg.set_boundary_conditions(bctype='Dirichlet', bcvalue=0.4, pores=BC2_pores)
#Add new model to air's physics that accounts for water occupancy
phys_air.models.add(model=OpenPNM.Physics.models.multiphase.conduit_conductance,
propname='throat.conduit_diffusive_conductance',
throat_conductance='throat.diffusive_conductance',
throat_occupancy='throat.occupancy',
pore_occupancy='pore.occupancy',
mode='strict',
factor=0)
#Use desired diffusive_conductance in the diffusion calculation (conductance for the dry network or water-filled network)
alg.run(conductance='throat.diffusive_conductance')
alg.return_results()
Deff = alg.calc_eff_diffusivity()
try:
# this creates a time step x num_pores, which is what the animated object needs
inv_seq = water['pore.IP_inv_seq'].squeeze()
history = []
for i in sorted(set(inv_seq)):
history.append( (inv_seq != 0) & (inv_seq < i) )
# try to perofrm an animated 3D rendering
from OpenPNM.Postprocessing.Graphics import Scene, Wires
wires = Wires(pn['pore.coords'], pn['throat.conns'], history)
scene = Scene()
scene.add_actors([wires])
scene.play()
except Exception as e:
pass
#------------------------------------------------------------------------------
'''Export to VTK'''
#------------------------------------------------------------------------------
ctrl.export()