<commit_before>import openpnm as op
import scipy as sp
import pytest


class GenericTransportTest:

    def setup_class(self):
        self.net = op.network.Cubic(shape=[9, 9, 9])
        self.geo = op.geometry.StickAndBall(network=self.net,
                                            pores=self.net.Ps,
                                            throats=self.net.Ts)
        self.phase = op.phases.Air(network=self.net)
        self.phase['pore.mole_fraction'] = 0
        self.phys = op.physics.GenericPhysics(network=self.net,
                                              phase=self.phase,
                                              geometry=self.geo)
        self.phys['throat.diffusive_conductance'] = 1.0

    def test_continuity_BC(self):
        alg = op.algorithms.FickianDiffusion(network=self.net,
                                             phase=self.phase)
        alg.settings['conductance'] = 'throat.diffusive_conductance'
        alg.settings['quantity'] = 'pore.mole_fraction'
        xyz = self.net["pore.coords"]
        left_interface = (xyz[:, 1] < 5) & (xyz[:, 1] > 4)
        right_interface = (xyz[:, 1] < 6) & (xyz[:, 1] > 5)
        alg.set_continuity_BC(ps1=left_interface, ps2=right_interface, K12=2.0)
        alg.set_value_BC(pores=self.net.pores('left'), values=1.0)
        alg.set_value_BC(pores=self.net.pores('right'), values=0.0)
        alg.run()
        x = alg["pore.mole_fraction"]
        x_LI = sp.unique(sp.around(x[left_interface], decimals=3))
        x_RI = sp.unique(sp.around(x[right_interface], decimals=3))
        assert sp.all(x_LI == 2.0*x_RI)

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


if __name__ == '__main__':

    t = GenericTransportTest()
    t.setup_class()
    for item in t.__dir__():
        if item.startswith('test'):
            print('running test: '+item)
            t.__getattribute__(item)()
    self = t<commit_msg>Add more rigorous test for continuity_BC; tests one to many partitioning<commit_after>from numpy.testing import assert_approx_equal
import openpnm as op
import scipy as sp
import pytest


class GenericTransportTest:

    def setup_class(self):
        self.net = op.network.Cubic(shape=[9, 9, 9])
        self.geo = op.geometry.StickAndBall(network=self.net,
                                            pores=self.net.Ps,
                                            throats=self.net.Ts)
        self.phase = op.phases.Air(network=self.net)
        self.phase['pore.mole_fraction'] = 0
        self.phys = op.physics.GenericPhysics(network=self.net,
                                              phase=self.phase,
                                              geometry=self.geo)
        self.phys['throat.diffusive_conductance'] = 1.0

    def test_continuity_BC_one_on_one(self):
        alg = op.algorithms.FickianDiffusion(network=self.net,
                                             phase=self.phase)
        alg.settings['conductance'] = 'throat.diffusive_conductance'
        alg.settings['quantity'] = 'pore.mole_fraction'
        xyz = self.net["pore.coords"]
        left_interface = (xyz[:, 1] < 5) & (xyz[:, 1] > 4)
        right_interface = (xyz[:, 1] < 6) & (xyz[:, 1] > 5)
        alg.set_continuity_BC(ps1=left_interface, ps2=right_interface, K12=2.0)
        alg.set_value_BC(pores=self.net.pores('left'), values=1.0)
        alg.set_value_BC(pores=self.net.pores('right'), values=0.0)
        alg.run()
        x = alg["pore.mole_fraction"]
        x_LI = sp.unique(sp.around(x[left_interface], decimals=3))
        x_RI = sp.unique(sp.around(x[right_interface], decimals=3))
        assert sp.all(x_LI == 2.0*x_RI)

    def test_continuity_BC_one_to_many(self):
        alg = op.algorithms.FickianDiffusion(network=self.net,
                                             phase=self.phase)
        alg.settings['conductance'] = 'throat.diffusive_conductance'
        alg.settings['quantity'] = 'pore.mole_fraction'
        alg.set_continuity_BC(ps1=253, ps2=[172, 244, 252], K12=2.0)
        alg.set_continuity_BC(ps1=[525, 533, 543], ps2=534, K12=3.4)
        alg.set_value_BC(pores=self.net.pores('left'), values=1.0)
        alg.set_value_BC(pores=self.net.pores('right'), values=0.0)
        alg.run()
        x = alg["pore.mole_fraction"]
        x1 = sp.unique(sp.around(x[[172, 244, 252]], decimals=10))[0]
        x2 = sp.unique(sp.around(x[[525, 533, 543]], decimals=10))[0]
        assert_approx_equal(x1, x[253]/2.0)
        assert_approx_equal(x2, x[534]*3.4)

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


if __name__ == '__main__':

    t = GenericTransportTest()
    t.setup_class()
    for item in t.__dir__():
        if item.startswith('test'):
            print('running test: '+item)
            t.__getattribute__(item)()
    self = t
{'fraction_non_alphanumeric': 0.13556519942136805, 'fraction_numerical': 0.027691671833023353, 'mean_word_length': 2.120567375886525, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3098199', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1574, 'n_words': 251}