Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing conductance shape from Nt by 1 to Nt by 2 for ALL conductance models #2849

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
508 changes: 315 additions & 193 deletions examples/tutorials/08_simulating_transport.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions openpnm/algorithms/_advection_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
C12 = network.conns[throats]
P12 = phase[self.settings['pressure']][C12]
gh = phase[self.settings['hydraulic_conductance']][throats]
# Special treatment when gh is not Nt by 1
if gh.size == 2 * len(throats):
gh = gh[:, 0] # assumes hydraulic conductance is symmetric

Check warning on line 86 in openpnm/algorithms/_advection_diffusion.py

View check run for this annotation

Codecov / codecov/patch

openpnm/algorithms/_advection_diffusion.py#L86

Added line #L86 was not covered by tests
Q12 = -gh * np.diff(P12, axis=1).squeeze()
Qp = np.zeros(self.Np)
np.add.at(Qp, C12[:, 0], -Q12)
Expand Down
5 changes: 3 additions & 2 deletions openpnm/models/physics/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ def _poisson_conductance(phase,
g1 = D1 * F1
gt = Dt * Ft
g2 = D2 * F2
return 1 / (1 / g1 + 1 / gt + 1 / g2)
G = 1 / (1 / g1 + 1 / gt + 1 / g2)
else:
# Otherwise, i.e., the size factor for the entire conduit is only known
F = network[size_factors]
return Dt * F
G = Dt * F
return vstack((G, G)).T


def _get_key_props(phase=None,
Expand Down
3 changes: 3 additions & 0 deletions openpnm/models/physics/ad_dif_conductance/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def ad_dif(
else:
raise Exception(f"Shape of {throat_diffusive_conductance} must either"
r" be (Nt,1) or (Nt,2)")
# Special treatment when gh is not Nt by 1
if gh.size == 2 * network.Nt:
gh = gh[:, 0] # assumes hydraulic conductance is symmetric

Qij = -gh * _np.diff(P[cn], axis=1).squeeze()
Qij = _np.append(Qij, -Qij)
Expand Down
2 changes: 1 addition & 1 deletion openpnm/models/physics/diffusive_conductance/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ def taylor_aris_diffusion(phase,
gtot = 1 / (1/g1 + 1/gt + 1/g2)
else:
gtot = Dt * (1 + Pet**2 / 192) * F
return gtot
return _np.vstack((gtot, gtot)).T
6 changes: 4 additions & 2 deletions openpnm/models/physics/hydraulic_conductance/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def generic_hydraulic(
g1 = F1 / mu1
gt = Ft / mut
g2 = F2 / mu2
return 1 / (1/g1 + 1/gt + 1/g2)
G = 1 / (1/g1 + 1/gt + 1/g2)
return _np.vstack((G, G)).T


@_doctxt
Expand Down Expand Up @@ -203,4 +204,5 @@ def valvatne_blunt(
gt = kt * At**2 * Gt / mu_t
value = L1 / gp[conns[:, 0]] + Lt / gt + L2 / gp[conns[:, 1]]

return 1 / value
G = 1 / value
return _np.vstack((G, G)).T
10 changes: 10 additions & 0 deletions tests/unit/models/physics/DiffusiveConductanceTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import openpnm as op
from numpy.testing import assert_allclose
import openpnm.models.physics.diffusive_conductance as diffusive_conductance


class DiffusiveConductanceTest:
Expand Down Expand Up @@ -120,6 +121,15 @@ def test_taylor_aris_diffusion(self):
desired = np.array([0.121193, 0.126131, 0.118578])
assert_allclose(actual, desired, rtol=1e-5)

def test_conductance_shape(self):
available_models = [
getattr(diffusive_conductance, model_name)
for model_name in dir(diffusive_conductance)
if callable(getattr(diffusive_conductance, model_name))
]
for model in available_models:
G = model(phase=self.phase)
assert_allclose(G.shape, (self.net.Nt, 2), rtol=0)

if __name__ == '__main__':

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/models/physics/ElectricalConductanceTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from numpy.testing import assert_allclose
import openpnm.models.physics.electrical_conductance as electrical_conductance

import openpnm as op

Expand Down Expand Up @@ -29,6 +30,15 @@ def test_series_resistors(self):
actual = np.mean(self.phase['throat.electrical_conductance'])
assert_allclose(actual, desired=0.091205, rtol=1e-5)

def test_conductance_shape(self):
available_models = [
getattr(electrical_conductance, model_name)
for model_name in dir(electrical_conductance)
if callable(getattr(electrical_conductance, model_name))
]
for model in available_models:
G = model(phase=self.phase)
assert_allclose(G.shape, (self.net.Nt, 2), rtol=0)

if __name__ == '__main__':

Expand Down
12 changes: 11 additions & 1 deletion tests/unit/models/physics/HydraulicConductanceTest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import openpnm as op
import numpy as np
from numpy.testing import assert_allclose
import openpnm.models.physics.hydraulic_conductance as hydraulic_conductance


class HydraulicConductanceTest:
Expand Down Expand Up @@ -53,7 +54,16 @@ def test_valvatne_blunt(self):
actual = self.phase['throat.valvatne_conductance'].mean()
desired = 6198.347107
assert_allclose(actual, desired=desired)


def test_conductance_shape(self):
available_models = [
getattr(hydraulic_conductance, model_name)
for model_name in dir(hydraulic_conductance)
if callable(getattr(hydraulic_conductance, model_name))
]
for model in available_models:
G = model(phase=self.phase)
assert_allclose(G.shape, (self.net.Nt, 2), rtol=0)

if __name__ == '__main__':

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/models/physics/ThermalConductanceTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from numpy.testing import assert_allclose
import openpnm.models.physics.thermal_conductance as thermal_conductance

import openpnm as op

Expand Down Expand Up @@ -28,6 +29,16 @@ def test_series_resistors(self):
actual = self.phase['throat.thermal_conductance'].mean()
desired = 1 / (1/(0.4*0.5) + 1/(0.2*0.5) + 1/(0.3*0.5))
assert_allclose(actual, desired)

def test_conductance_shape(self):
available_models = [
getattr(thermal_conductance, model_name)
for model_name in dir(thermal_conductance)
if callable(getattr(thermal_conductance, model_name))
]
for model in available_models:
G = model(phase=self.phase)
assert_allclose(G.shape, (self.net.Nt, 2), rtol=0)


if __name__ == '__main__':
Expand Down