-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathexample.py
More file actions
95 lines (83 loc) · 2.56 KB
/
example.py
File metadata and controls
95 lines (83 loc) · 2.56 KB
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
import openpnm as op
from openpnm.models.physics import source_terms
from openpnm.models import collections
import matplotlib.pyplot as plt
op.visualization.set_mpl_style()
ws = op.Workspace()
ws.settings["default_solver"] = "ScipySpsolve"
ws.clear()
pn = op.network.Cubic(shape=[25, 25, 1], spacing=1e-4)
# Create domain
Ps = pn.coords[:, 0] < 13e-4
Ts = pn.find_neighbor_throats(pores=Ps, asmask=True)
pn["pore.domain1"] = Ps
pn["throat.domain1"] = Ts
# Create domain2
Ps = pn.coords[:, 0] >= 13e-4
Ts = pn.find_neighbor_throats(pores=Ps, mode="xnor", asmask=True)
pn["pore.domain2"] = Ps
pn["throat.domain2"] = Ts
# Add network/geometry models to both domains
pn.add_model_collection(collections.geometry.cones_and_cylinders, domain="domain1")
pn.add_model_collection(collections.geometry.pyramids_and_cuboids, domain="domain2")
# FIXME: Must regenerate network models, otherwise, phase models will complain
pn.regenerate_models()
# Create phase and add phase/physics models
air = op.phase.Air(network=pn, name="air")
air.add_model_collection(collections.physics.standard)
air.regenerate_models()
# Add a nonlinear reaction
air["pore.reaction_sites"] = False
air["pore.reaction_sites"][[310, 212, 113]] = True
air.add_model(
propname="pore.reaction1",
model=source_terms.power_law,
X="pore.concentration",
A1=-1,
A2=2,
A3=0,
domain="reaction_sites",
regen_mode="deferred",
)
air.add_model(
propname="pore.reaction2",
model=source_terms.power_law,
X="pore.concentration",
A1=-1,
A2=2,
A3=0,
domain="reaction_sites",
regen_mode="deferred",
)
# Run Fickian diffusion with reaction
rxn = op.algorithms.FickianDiffusion(network=pn, phase=air)
rxn.set_value_BC(pores=pn.pores("left"), values=1)
rxn.set_source(pores=air.pores("reaction_sites"), propname="pore.reaction1")
rxn.run()
# Run Fickian diffusion with reaction
rxn2 = op.algorithms.FickianDiffusion(network=pn, phase=air)
rxn2.set_value_BC(pores=pn.pores("left"), values=1)
rxn2.set_source(pores=air.pores("reaction_sites"), propname="pore.reaction2")
rxn2.run()
# Plot concentration profile
fig, ax = plt.subplots()
ax = op.visualization.plot_coordinates(
network=pn,
ax=ax,
color_by=rxn2['pore.concentration'],
size_by=pn['pore.diameter'],
s=75,
ec='k',
linewidth=0.5,
)
ax = op.visualization.plot_connections(
network=pn,
ax=ax,
zorder=0,
color_by=pn['throat.diameter'],
linewidth=1.5,
alpha=0.5,
)
ax.axis(False)
fig.colorbar(ax.collections[0], label='pore.concentration')
fig.colorbar(ax.collections[1], label='throat.diameter')