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.GenericGeometry(network=self.net,
                                               pores=self.net.Ps,
                                               throats=self.net.Ts)
        self.phase = op.phases.GenericPhase(network=self.net)
        self.phys = op.physics.GenericPhysics(network=self.net,
                                              phase=self.phase,
                                              geometry=self.geo)
        self.phys['throat.diffusive_conductance'] = 1e-15
        self.phys['pore.A'] = -1e-10
        self.phys['pore.k'] = 2
        mod = op.models.physics.generic_source_term.standard_kinetics
        self.phys.add_model(propname='pore.reaction',
                            model=mod,
                            prefactor='pore.A',
                            exponent='pore.k',
                            quantity='pore.concentration',
                            regen_mode='normal')

    def test_one_value_one_source(self):
        rt = op.algorithms.ReactiveTransport(network=self.net,
                                             phase=self.phase)
        rt.settings.update({'conductance': 'throat.diffusive_conductance',
                            'quantity': 'pore.concentration'})
        rt.set_source(pores=self.net.pores('bottom'), propname='pore.reaction')
        rt.set_value_BC(pores=self.net.pores('top'), values=1.0)
        rt.run()
        x = [0.0011, 0.1260, 0.2508, 0.3757, 0.5006, 0.6254, 0.7503, 0.8751, 1.0]
        y = sp.unique(sp.around(rt['pore.concentration'], decimals=4))
        assert sp.all(x == y)

    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

@@ -1757,16 +1757,745 @@
  == y)%0A%0A
+    def test_source_not_override_BCs(self):%0A        rt = op.algorithms.ReactiveTransport(network=self.net,%0A                                             phase=self.phase)%0A        rt.settings.update(%7B'conductance': 'throat.diffusive_conductance',%0A                            'quantity': 'pore.concentration'%7D)%0A        rt.set_value_BC(pores=self.net.pores('left'), values=1.0)%0A        rt.set_value_BC(pores=self.net.pores('right'), values=0.5)%0A        rt.set_source(pores=self.net.Ps, propname='pore.reaction')%0A        rt.run()%0A        yleft = rt%5B'pore.concentration'%5D%5Bself.net.pores('left')%5D.mean()%0A        yright = rt%5B'pore.concentration'%5D%5Bself.net.pores('right')%5D.mean()%0A        assert yleft == 1.0%0A        assert yright == 0.5%0A%0A
     def 

Add test to make sure set_source doesn't override Dirichlet BCs