nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: PMEAL/OpenPNM
Pull request #1431 (2020-03-11 14:18:21)

Hotfix: bug in _run_generic caused A and b not to get rebuilt even when cache_A/b set to False


Patch:
diff --git a/openpnm/algorithms/GenericTransport.py b/openpnm/algorithms/GenericTransport.py
index cd79ce703..b3f68eb7c 100644
--- a/openpnm/algorithms/GenericTransport.py
+++ b/openpnm/algorithms/GenericTransport.py
@@ -511,10 +511,14 @@ class GenericTransport(GenericAlgorithm):
         self._run_generic(x0)
 
     def _run_generic(self, x0):
+        self._build_A()
+        self._build_b()
         self._apply_BCs()
-        x0 = np.zeros_like(self.b)
+        if x0 is None:
+            x0 = np.zeros(self.Np, dtype=float)
         x_new = self._solve(x0=x0)
-        self[self.settings['quantity']] = x_new
+        quantity = self.settings['quantity']
+        self[quantity] = x_new
 
     def _solve(self, A=None, b=None, x0=None):
         r"""


Test patch:
diff --git a/tests/unit/algorithms/GenericTransportTest.py b/tests/unit/algorithms/GenericTransportTest.py
index 5f2fa1bc4..e46637fa8 100644
--- a/tests/unit/algorithms/GenericTransportTest.py
+++ b/tests/unit/algorithms/GenericTransportTest.py
@@ -153,18 +153,18 @@ class GenericTransportTest:
         alg.set_rate_BC(pores=self.net.pores('bottom'), values=1)
         alg.set_value_BC(pores=self.net.pores('top'), values=0)
         alg.settings["cache_A"] = True
-        alg._build_A()
-        x = alg._A.mean()
+        alg.run()
+        x_before = alg["pore.mole_fraction"].mean()
         self.phys["throat.diffusive_conductance"][1] = 50.0
-        alg._build_A()
-        y = alg._A.mean()
+        alg.run()
+        x_after = alg["pore.mole_fraction"].mean()
         # When cache_A is True, A is not recomputed, hence x == y
-        assert x == y
+        assert x_before == x_after
         alg.settings["cache_A"] = False
-        alg._build_A()
-        y = alg._A.mean()
+        alg.run()
+        x_after = alg["pore.mole_fraction"].mean()
         # When cache_A is False, A must be recomputed, hence x!= y
-        assert x != y
+        assert x_before != x_after
         # Revert back changes to objects
         self.setup_class()