[SolutionArray] Disable problematic methods for Interface

This commit is contained in:
Ingmar Schoegl 2024-06-27 08:11:33 +02:00 committed by Ray Speth
parent 0445e01e98
commit dd56a70401
2 changed files with 18 additions and 4 deletions

View File

@ -1429,8 +1429,13 @@ def _make_functions():
return np.empty(self.shape + (self._phase.n_reactions,))
# Factory for creating read-only properties
def make_prop(name, get_container, doc_source):
def make_prop(name, get_container, doc_source, block_interface=False):
def getter(self):
if block_interface and isinstance(self._phase, Interface):
# used to block Interface methods that require synchronized updates of
# linked phases
raise NotImplementedError(
"Method not implemented for SolutionArray containing Interface.")
v = get_container(self)
for loc, index in enumerate(self._indices):
self._set_loc(loc)
@ -1455,13 +1460,13 @@ def _make_functions():
for name in SolutionArray._n_total_species:
setattr(SolutionArray, name,
make_prop(name, empty_total_species, Solution))
make_prop(name, empty_total_species, Solution, True))
for name in SolutionArray._n_species2:
setattr(SolutionArray, name, make_prop(name, empty_species2, Solution))
setattr(SolutionArray, name, make_prop(name, empty_species2, Solution, True))
for name in SolutionArray._n_reactions:
setattr(SolutionArray, name, make_prop(name, empty_reactions, Solution))
setattr(SolutionArray, name, make_prop(name, empty_reactions, Solution, True))
# Factory for creating wrappers for functions which return a value
def caller(name, get_container):

View File

@ -305,6 +305,15 @@ class TestSolutionArray(utilities.CanteraTest):
assert arr(*spc).Y.shape == (siz, 2)
assert arr(*spc).net_production_rates.shape == (siz, 2)
def test_interface_wdot(self):
gas = ct.Solution("ptcombust.yaml", "gas", transport_model=None)
surf = ct.Interface("ptcombust.yaml", "Pt_surf", [gas])
arr = ct.SolutionArray(surf, shape=1)
with self.assertRaisesRegex(NotImplementedError, "containing Interface"):
arr.net_production_rates
arr = ct.SolutionArray(gas, shape=1)
assert arr.net_production_rates.size == gas.n_species
class TestSolutionArrayInfo(utilities.CanteraTest):
""" Test SolutionArray summary output """