Repository: PMEAL/OpenPNM
Pull request #400 (2015-06-22 18:46:38)

No more develop branch
@jgostick and I spoke and we've decided that maintaining a `develop` branch is an unnecessary moving pierce to working on OpenPNM. From now on, contributions to OpenPNM will go as follows:
* Create a new branch off of master
* Make changes and open a PR against master
* Code review and then merge into master

The `master` branch will act as what we will call OpenPNM-edge meaning that it will represent the absolute latest state of the package. Once we believe `master` is in the condition we want it to be in for a release, we will tag that state on the master branch, and build/release it to PyPi.

cc/ @PMEAL/openpnm-core 


Patch:
diff --git a/.travis.yml b/.travis.yml
index ebc0c5cd8..b97570c9d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,7 +20,7 @@ install:
   - python setup.py install
 
 script:
-    - py.test -v --pep8 --cov=. --cov-config=.coveragerc
+    - ./bin/test pep8 cov
 
 after_success:
     - coveralls
diff --git a/OpenPNM/Physics/models/multiphase.py b/OpenPNM/Physics/models/multiphase.py
index 9edc07edb..377ebc9f3 100644
--- a/OpenPNM/Physics/models/multiphase.py
+++ b/OpenPNM/Physics/models/multiphase.py
@@ -48,22 +48,22 @@ def conduit_conductance(physics, phase, network, throat_conductance,
     calculated.
 
     """
-    throats = phase.throats(physics.name)
+    throats = phase.Ts
     if mode == 'loose':
-        closed_conduits = -sp.array(phase[throat_occupancy], dtype=bool)
+        closed_conduits = ~sp.array(phase[throat_occupancy], dtype=bool)
     else:
-        throats_closed = -sp.array(phase[throat_occupancy], dtype=bool)
+        throats_closed = ~sp.array(phase[throat_occupancy], dtype=bool)
         connected_pores = network.find_connected_pores(throats)
         pores_1 = connected_pores[:, 0]
         pores_2 = connected_pores[:, 1]
-        pores_1_closed = -sp.array(phase[pore_occupancy][pores_1], dtype=bool)
-        pores_2_closed = -sp.array(phase[pore_occupancy][pores_2], dtype=bool)
+        pores_1_closed = ~sp.array(phase[pore_occupancy][pores_1], dtype=bool)
+        pores_2_closed = ~sp.array(phase[pore_occupancy][pores_2], dtype=bool)
         if mode == 'medium':
             closed_conduits = throats_closed | (pores_1_closed & pores_2_closed)
 
         if mode == 'strict':
             closed_conduits = pores_1_closed | throats_closed | pores_2_closed
-    open_conduits = -closed_conduits
+    open_conduits = ~closed_conduits
     throat_value = phase[throat_conductance]
     value = throat_value*open_conduits + throat_value*closed_conduits*factor
     value = value[phase.throats(physics.name)]
@@ -96,7 +96,7 @@ def late_pore_filling(physics, phase, network, Pc, Swp_star=0.2, eta=3,
 
 
     """
-    pores = phase.pores(physics.name)
+    pores = phase.Ps
     prop = phase[throat_capillary_pressure]
     neighborTs = network.find_neighbor_throats(pores, flatten=False)
     Pc_star = sp.array([sp.amin(prop[row]) for row in neighborTs])
@@ -105,5 +105,5 @@ def late_pore_filling(physics, phase, network, Pc, Swp_star=0.2, eta=3,
         values = Swp*phase[pore_occupancy]*(Pc_star < Pc)
     else:
         values = (1-Swp)*(1-phase[pore_occupancy])*(Pc_star < Pc)
-    values = values[phase.throats(physics.name)]
+    values = values[phase.pores(physics.name)]
     return values
diff --git a/OpenPNM/Postprocessing/Plots.py b/OpenPNM/Postprocessing/Plots.py
index eab2be8a0..978f99901 100644
--- a/OpenPNM/Postprocessing/Plots.py
+++ b/OpenPNM/Postprocessing/Plots.py
@@ -43,7 +43,7 @@ def profiles(network, fig=None, values=None, bins=[10, 10, 10]):
         ax[n].plot(xaxis, yaxis, 'bo-')
         ax[n].set_xlabel(xlab[n])
         ax[n].set_ylabel('Slice Value')
-    fig.show()
+    return fig
 
 
 def porosity_profile(network, fig=None, axis=2):
@@ -107,7 +107,7 @@ def porosity_profile(network, fig=None, axis=2):
     _plt.plot(xaxis, yaxis, 'bo-')
     _plt.xlabel(xlab)
     _plt.ylabel('Porosity')
-    fig.show()
+    return fig
 
 
 def saturation_profile(network, phase, fig=None, axis=2):
@@ -179,7 +179,7 @@ def saturation_profile(network, phase, fig=None, axis=2):
     _plt.plot(xaxis, yaxis, 'bo-')
     _plt.xlabel(xlab)
     _plt.ylabel('Saturation')
-    fig.show()
+    return fig
 
 
 def distributions(net, fig=None, throat_diameter='throat.diameter',
@@ -235,7 +235,7 @@ def distributions(net, fig=None, throat_diameter='throat.diameter',
     ax4.set_xlabel('Throat Length')
     ax4.set_ylabel('Frequency')
     ax4.ticklabel_format(style='sci', axis='x', scilimits=(0, 0))
-    fig.show()
+    return fig
 
 
 def pore_size_distribution(network, fig=None):
@@ -266,7 +266,7 @@ def pore_size_distribution(network, fig=None):
     _plt.semilogx(xaxis, yaxis, 'b.-')
     _plt.xlabel('Pore & Throat Diameter (m)')
     _plt.ylabel('Cumulative Volume (m^3)')
-    fig.show()
+    return fig
 
 
 def drainage_curves(inv_alg, fig=None, Pc='inv_Pc', sat='inv_sat',
@@ -358,4 +358,4 @@ def drainage_curves(inv_alg, fig=None, Pc='inv_Pc', sat='inv_sat',
     ax4.grid(True)
     ax5.grid(True)
     ax6.grid(True)
-    fig.show()
+    return fig
diff --git a/README.rst b/README.rst
index 11bc471dd..91dcfcad6 100644
--- a/README.rst
+++ b/README.rst
@@ -1,10 +1,14 @@
 OpenPNM
 =======
+.. image:: https://badge.fury.io/py/openpnm.svg
+   :target: http://badge.fury.io/py/openpnm
 
 .. image:: https://travis-ci.org/PMEAL/OpenPNM.svg?branch=develop
    :target: https://travis-ci.org/PMEAL/OpenPNM
-.. image:: https://coveralls.io/repos/PMEAL/OpenPNM/badge.svg
+
+.. image:: https://coveralls.io/repos/PMEAL/OpenPNM/badge.svg?branch=develop
    :target: https://coveralls.io/r/PMEAL/OpenPNM
+
 .. image:: https://badges.gitter.im/Join%20Chat.svg
    :alt: Join the chat at https://gitter.im/PMEAL/OpenPNM
    :target: https://gitter.im/PMEAL/OpenPNM?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
diff --git a/bin/build b/bin/build
deleted file mode 100755
index 7ae583b31..000000000
--- a/bin/build
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/env python3
-
-import subprocess
-
-subprocess.call(['python3', 'setup.py', 'sdist'])
diff --git a/bin/publish b/bin/publish
index cc588cb58..a7cdaa815 100755
--- a/bin/publish
+++ b/bin/publish
@@ -6,20 +6,9 @@ import subprocess
 
 VERSION = OpenPNM.__version__
 
+response = input('Are you sure you want to publish version ' + VERSION +
+                 ' of OpenPNM? (y/n): ')
 
-def publish():
-    subprocess.call(['python3', 'setup.py', 'upload', '-r', 'pypi'])
+if response is 'y':
+    subprocess.call(['python3', 'setup.py', 'sdist', 'upload', '-r', 'pypi'])
     print('Done.')
-
-pwd = os.getcwd()
-egg_info = os.path.join(pwd, 'OpenPNM.egg-info')
-dist = os.path.join(pwd, 'dist')
-
-if os.path.isdir(egg_info) and os.path.isdir(dist):
-    response = input('Are you sure you want to publish version ' + VERSION +
-                     ' of OpenPNM? (y/n): ')
-    if response is 'y':
-        publish()
-else:
-    print('There is no build of OpenPNM present, run ./bin/build,'
-          ' and try again.')


Test patch:
diff --git a/bin/test b/bin/test
index c659839a8..2e281b3d3 100755
--- a/bin/test
+++ b/bin/test
@@ -1,14 +1,18 @@
 #!/usr/bin/env python3
 
 import sys
-import subprocess
+import pytest
 
-command = ['py.test']
+args = ['-v']
 
 if 'pep8' in sys.argv:
-    command.append('--pep8')
+    args.append('--pep8')
 
 if 'cov' in sys.argv:
-    command.extend(['--cov-report=term-missing', '--cov=.', '--cov-config=.coveragerc'])
+    args.extend(['--cov-report=term-missing',
+                 '--cov=OpenPNM',
+                 '--cov-config=.coveragerc',
+                 '--no-cov-on-fail'])
 
-subprocess.call(command)
+exit_code = pytest.main(args)
+exit(exit_code)
diff --git a/pytest.ini b/pytest.ini
index b9f2fb9c3..47202a058 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -12,7 +12,6 @@ pep8ignore =
 
 addopts =
     --doctest-modules
-    --strict
     --ignore=setup.py
     --ignore=run_script.py
     --ignore=test_requirements.txt
diff --git a/test/unit/Physics/models/MultiPhaseTest.py b/test/unit/Physics/models/MultiPhaseTest.py
index 93b629a7f..a730a0ca9 100644
--- a/test/unit/Physics/models/MultiPhaseTest.py
+++ b/test/unit/Physics/models/MultiPhaseTest.py
@@ -1,3 +1,99 @@
+import OpenPNM
+import scipy as sp
+import OpenPNM.Physics.models as pm
+
+
 class MultiPhaseTest:
-    def test_conduit_conductance(self):
+    def setup_class(self):
+        self.net = OpenPNM.Network.Cubic(shape=[3, 3, 3])
+        self.phase = OpenPNM.Phases.GenericPhase(network=self.net)
+        self.phase['pore.occupancy'] = sp.ones(self.net.Np)
+        self.phase['throat.occupancy'] = sp.ones(self.net.Nt)
+        p = sp.arange(7, 10)
+        t = self.net.find_neighbor_throats(p)
+        self.phase['pore.occupancy'][p] = 0.
+        self.phase['throat.occupancy'][t] = 0.
+        Ps1 = sp.arange(10)
+        Ts1 = self.net.find_neighbor_throats(Ps1)
+        self.phys1 = OpenPNM.Physics.GenericPhysics(network=self.net,
+                                                    phase=self.phase,
+                                                    pores=Ps1, throats=Ts1)
+        Ps2 = sp.arange(10, self.net.Np)
+        Ts2 = self.net.Ts[~sp.in1d(self.net.Ts, Ts1)]
+        self.phys2 = OpenPNM.Physics.GenericPhysics(network=self.net,
+                                                    phase=self.phase,
+                                                    pores=Ps2, throats=Ts2)
+        self.phys1['throat.capillary_pressure'] = 5000
+        self.phys1['throat.diffusive_conductance'] = 2
+        self.phys2['throat.capillary_pressure'] = 5000
+        self.phys2['throat.diffusive_conductance'] = 3
+
+    def test_conduit_conductance_strict(self):
+        self.phase['pore.occupancy'][[19, 25]] = 0
+        t1 = self.net.Ts[self.phase['throat.occupancy'] == 0]
+        t2 = self.net.Ts[~sp.in1d(self.net.Ts, t1)]
+        self.phys1.models.add(propname='throat.cond_conductance',
+                              throat_conductance='throat.diffusive_conductance',
+                              model=pm.multiphase.conduit_conductance,
+                              mode='strict', factor=0)
+        self.phys2.models.add(propname='throat.cond_conductance',
+                              throat_conductance='throat.diffusive_conductance',
+                              model=pm.multiphase.conduit_conductance,
+                              mode='strict', factor=0)
+        assert ~sp.all(self.phase['throat.cond_conductance'] == 0)
+        assert sp.all(self.phase['throat.cond_conductance'][t1] == 0)
+        assert ~sp.all(self.phase['throat.cond_conductance'][t2] != 0)
+
+    def test_conduit_conductance_medium(self):
+        self.phase['pore.occupancy'][[19, 25]] = 0
+        self.phase['pore.occupancy'][6] = 0
+        t1 = self.net.Ts[self.phase['throat.occupancy'] == 0.]
+        t2 = self.net.find_connecting_throat(6, 7)[0]
+        t3 = self.net.Ts[~sp.in1d(self.net.Ts, sp.concatenate((t1, t2)))]
+        self.phys1.models.add(propname='throat.cond_conductance',
+                              throat_conductance='throat.diffusive_conductance',
+                              model=pm.multiphase.conduit_conductance,
+                              mode='medium', factor=0)
+        self.phys2.models.add(propname='throat.cond_conductance',
+                              throat_conductance='throat.diffusive_conductance',
+                              model=pm.multiphase.conduit_conductance,
+                              mode='medium', factor=0)
+        assert sp.all(self.phase['throat.cond_conductance'][t1] == 0)
+        assert self.phase['throat.cond_conductance'][t2] == 0
+        assert sp.all(self.phase['throat.cond_conductance'][t3] != 0)
+
+    def test_conduit_conductance_loose(self):
+        self.phase['pore.occupancy'][[19, 20]] = 0
+        t1 = self.net.Ts[self.phase['throat.occupancy'] == 0]
+        t2 = self.net.Ts[~sp.in1d(self.net.Ts, t1)]
+        self.phys1.models.add(propname='throat.cond_conductance',
+                              throat_conductance='throat.diffusive_conductance',
+                              model=pm.multiphase.conduit_conductance,
+                              mode='loose', factor=0)
+        self.phys2.models.add(propname='throat.cond_conductance',
+                              throat_conductance='throat.diffusive_conductance',
+                              model=pm.multiphase.conduit_conductance,
+                              mode='loose', factor=0)
+        assert sp.all(self.phase['throat.cond_conductance'][t1] == 0)
+        assert sp.all(self.phase['throat.cond_conductance'][t2] != 0)
+
+    def test_late_throat_filling(self):
         pass
+
+    def test_late_pore_filling(self):
+
+        self.phys1.models.add(propname='pore.late_p',
+                              model=pm.multiphase.late_pore_filling,
+                              wetting_phase=True, Pc=5500)
+        self.phys2.models.add(propname='pore.late_p',
+                              model=pm.multiphase.late_pore_filling,
+                              wetting_phase=True, Pc=5500)
+        self.phys1.models.add(propname='pore.late_p_n',
+                              model=pm.multiphase.late_pore_filling,
+                              Pc=5500)
+        self.phys2.models.add(propname='pore.late_p_n',
+                              model=pm.multiphase.late_pore_filling,
+                              Pc=5500)
+        p = self.phase['pore.occupancy'] == 0
+        assert sp.allclose(self.phase['pore.late_p'][~p], 0.15026296)
+        assert sp.allclose(self.phase['pore.late_p_n'][p], 0.84973704)