|
1 | 1 | import numpy as np
|
2 | 2 | import logging
|
3 |
| -from copy import deepcopy |
4 | 3 | from openpnm.phase import Phase
|
5 |
| -from openpnm.models.collections.phase import liquid_mixture, gas_mixture |
| 4 | +from openpnm.models.collections.phase import liquid_mixture |
| 5 | +from openpnm.models.collections.phase import gas_mixture, binary_gas_mixture |
6 | 6 | from openpnm.models.phase.mixtures import mole_summation
|
7 |
| -from openpnm.utils import HealthDict, PrintableList, SubDict |
| 7 | +from openpnm.utils import HealthDict |
8 | 8 | from openpnm.utils import Docorator, Workspace
|
9 | 9 |
|
10 | 10 |
|
|
15 | 15 |
|
16 | 16 | __all__ = [
|
17 | 17 | 'Mixture',
|
18 |
| - 'GasMixture', |
| 18 | + 'BinaryGasMixture', |
| 19 | + 'MultiGasMixture', |
19 | 20 | 'LiquidMixture',
|
20 | 21 | ]
|
21 | 22 |
|
22 | 23 |
|
23 | 24 | class MixtureSettings:
|
24 |
| - r""" |
25 |
| - The following settings are specific to Mixture objects |
26 |
| -
|
27 |
| - Parameters |
28 |
| - ---------- |
29 |
| - components : list of strings |
30 |
| - The names of each pure component object that constitute the mixture |
31 |
| -
|
32 |
| - """ |
33 |
| - components = [] |
| 25 | + ... |
34 | 26 |
|
35 | 27 |
|
36 | 28 | @docstr.get_sections(base='Mixture', sections=['Parameters'])
|
@@ -64,10 +56,21 @@ def __getitem__(self, key):
|
64 | 56 | if key.split('.')[-1] in self.components.keys():
|
65 | 57 | comp = self.project[key.split('.')[-1]]
|
66 | 58 | vals = comp[key.rsplit('.', maxsplit=1)[0]]
|
| 59 | + elif key.endswith('*'): |
| 60 | + key = key[:-1] |
| 61 | + if key.endswith('.'): |
| 62 | + key = key[:-1] |
| 63 | + vals = self._get_comp_vals(key) |
67 | 64 | else:
|
68 | 65 | raise KeyError(key)
|
69 | 66 | return vals
|
70 | 67 |
|
| 68 | + def _get_comp_vals(self, propname): |
| 69 | + vals = {} |
| 70 | + for comp in self.components.keys(): |
| 71 | + vals[comp] = self[propname + '.' + comp] |
| 72 | + return vals |
| 73 | + |
71 | 74 | def __str__(self):
|
72 | 75 | horizontal_rule = '―' * 78
|
73 | 76 | temp = super().__str__().split(horizontal_rule)
|
@@ -101,8 +104,13 @@ def _set_comps(self, components):
|
101 | 104 | def add_comp(self, component, mole_fraction=0.0):
|
102 | 105 | self['pore.mole_fraction.' + component.name] = mole_fraction
|
103 | 106 |
|
104 |
| - def remove_comp(self, compname): |
105 |
| - del self['pore.mole_fraction.' + compname] |
| 107 | + def remove_comp(self, component): |
| 108 | + if hasattr(component, 'name'): |
| 109 | + component = component.name |
| 110 | + try: |
| 111 | + del self['pore.mole_fraction.' + component] |
| 112 | + except KeyError: |
| 113 | + pass |
106 | 114 |
|
107 | 115 | def check_mixture_health(self):
|
108 | 116 | r"""
|
@@ -133,6 +141,7 @@ def check_mixture_health(self):
|
133 | 141 |
|
134 | 142 |
|
135 | 143 | class LiquidMixture(Mixture):
|
| 144 | + |
136 | 145 | def __init__(self, **kwargs):
|
137 | 146 | super().__init__(**kwargs)
|
138 | 147 | self.models.update(liquid_mixture())
|
@@ -171,10 +180,6 @@ def x(self, compname=None, x=None):
|
171 | 180 |
|
172 | 181 |
|
173 | 182 | class GasMixture(Mixture):
|
174 |
| - def __init__(self, **kwargs): |
175 |
| - super().__init__(**kwargs) |
176 |
| - self.models.update(gas_mixture()) |
177 |
| - self.regenerate_models() |
178 | 183 |
|
179 | 184 | def y(self, compname=None, y=None):
|
180 | 185 | r"""
|
@@ -208,13 +213,80 @@ def y(self, compname=None, y=None):
|
208 | 213 | self['pore.mole_fraction.' + compname] = y
|
209 | 214 |
|
210 | 215 |
|
| 216 | +class MultiGasMixture(GasMixture): |
| 217 | + |
| 218 | + def __init__(self, **kwargs): |
| 219 | + super().__init__(**kwargs) |
| 220 | + self.models.clear() |
| 221 | + self.models.update(gas_mixture()) |
| 222 | + self.regenerate_models() |
| 223 | + |
| 224 | +class BinaryGasMixture(GasMixture): |
| 225 | + |
| 226 | + def __init__(self, **kwargs): |
| 227 | + super().__init__(**kwargs) |
| 228 | + self.models.clear() |
| 229 | + self.models.update(binary_gas_mixture()) |
| 230 | + self.regenerate_models() |
| 231 | + |
| 232 | + def add_comp(self, component, mole_fraction=0.0): |
| 233 | + if len(self['pore.mole_fraction'].keys()) >= 2: |
| 234 | + raise Exception("Binary mixtures cannot have more than 2 components" |
| 235 | + + ", remove one first") |
| 236 | + super().add_component(component=component, mole_fraction=mole_fraction) |
| 237 | + |
| 238 | + |
211 | 239 | if __name__ == '__main__':
|
212 | 240 | import openpnm as op
|
213 | 241 | pn = op.network.Demo()
|
214 | 242 | o2 = op.phase.GasByName(network=pn, species='o2', name='pure_O2')
|
215 | 243 | n2 = op.phase.GasByName(network=pn, species='n2', name='pure_N2')
|
216 |
| - air = op.phase.GasMixture(network=pn, components=[o2, n2]) |
| 244 | + air = op.phase.BinaryGasMixture(network=pn, components=[o2, n2], name='air') |
217 | 245 | air.y(o2.name, 0.21)
|
218 | 246 | air['pore.mole_fraction.pure_N2'] = 0.79
|
219 | 247 | air.regenerate_models()
|
220 | 248 | print(air)
|
| 249 | + |
| 250 | + ch4 = op.phase.GasByName(network=pn, species='ch4', name='methane') |
| 251 | + h2 = op.phase.GasByName(network=pn, species='h2', name='hydrogen') |
| 252 | + h2o = op.phase.GasByName(network=pn, species='h2o', name='water') |
| 253 | + co2 = op.phase.GasByName(network=pn, species='co2', name='co2') |
| 254 | + syngas = op.phase.MultiGasMixture(network=pn, components=[ch4, h2, h2o, co2], |
| 255 | + name='syngas') |
| 256 | + syngas.y(h2.name, 0.25) |
| 257 | + syngas.y(ch4.name, 0.25) |
| 258 | + syngas.y(h2o.name, 0.25) |
| 259 | + syngas.y(co2.name, 0.25) |
| 260 | + syngas.regenerate_models() |
| 261 | + print(syngas) |
| 262 | + |
| 263 | + |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | + |
| 268 | + |
| 269 | + |
| 270 | + |
| 271 | + |
| 272 | + |
| 273 | + |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
0 commit comments