Skip to content

Commit

Permalink
overloaded getitem on transport to return empty dict if pore.source i…
Browse files Browse the repository at this point in the history
…s requested
  • Loading branch information
jgostick committed Nov 5, 2022
1 parent d1526eb commit 31f6b26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 9 additions & 0 deletions openpnm/algorithms/_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def __init__(self, phase, name='trans_?', **kwargs):
self._pure_b = None
self.soln = {}

def __getitem__(self, key):
try:
return super().__getitem__(key)
except KeyError:
if key == 'pore.source':
return {}
else:
raise KeyError(key)

@property
def x(self):
"""Shortcut to the solution currently stored on the algorithm."""
Expand Down
9 changes: 8 additions & 1 deletion tests/unit/algorithms/GenericTransportTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_rate_multiple_values(self):

def test_x0_is_nan(self):
alg = op.algorithms.Transport(network=self.net,
phase=self.phase)
phase=self.phase)
alg.settings['conductance'] = 'throat.diffusive_conductance'
alg.settings['quantity'] = 'pore.mole_fraction'
alg.set_value_BC(pores=self.net.pores('top'), values=1)
Expand All @@ -367,6 +367,13 @@ def test_x0_is_nan(self):
with pytest.raises(Exception):
alg.run(x0=x0)

def test_get_source_list(self):
alg = op.algorithms.Transport(network=self.net,
phase=self.phase)
assert alg['pore.source'] == {}
with pytest.raises(KeyError):
alg['pore.source_blah'] == {}

def teardown_class(self):
ws = op.Workspace()
ws.clear()
Expand Down

0 comments on commit 31f6b26

Please sign in to comment.