def test_exact(): # Reference: Philip (1960) Table 1, No. 13 # https://doi.org/10.1071/PH600001 theta = fronts.solve(D="0.5*(1 - log(theta))", i=0, b=1) o = np.linspace(0, 20, 100) assert_allclose(theta(o=o), np.exp(-o), atol=1e-3)
def test_exact_solve(): o = np.linspace(0, 20, 100) D = fronts.inverse(o=o, samples=np.exp(-o)) theta = fronts.solve(D=D, b=1, i=0) assert_allclose(theta(o=o), np.exp(-o), atol=2e-3)
def test_HF135(): r = np.array([ 0., 0.0025, 0.005, 0.0075, 0.01, 0.0125, 0.015, 0.0175, 0.02, 0.0225, 0.025, 0.0275, 0.03, 0.0325, 0.035, 0.0375, 0.04, 0.0425, 0.045, 0.0475, 0.05 ]) t = 60 # Data obtained with the porousMultiphaseFoam toolbox, version 1906 # https://github.com/phorgue/porousMultiphaseFoam theta_pmf = np.array([ 0.945, 0.944845, 0.944188, 0.942814, 0.940517, 0.937055, 0.93214, 0.925406, 0.916379, 0.904433, 0.888715, 0.868016, 0.840562, 0.803597, 0.752494, 0.678493, 0.560999, 0.314848, 0.102755, 0.102755, 0.102755 ]) U_pmf = np.array([ 2.66135e-04, 2.66133e-04, 2.66111e-04, 2.66038e-04, 2.65869e-04, 2.65542e-04, 2.64975e-04, 2.64060e-04, 2.62644e-04, 2.60523e-04, 2.57404e-04, 2.52863e-04, 2.46269e-04, 2.36619e-04, 2.22209e-04, 1.99790e-04, 1.61709e-04, 7.64565e-05, -2.45199e-21, -7.35598e-21, 0.00000e+00 ]) epsilon = 1e-7 # Wetting of an HF135 membrane, Van Genuchten model # Data from Buser (PhD thesis, 2016) # http://hdl.handle.net/1773/38064 theta_range = (0.0473, 0.945) k = 5.50e-13 # m**2 alpha = 0.2555 # 1/m n = 2.3521 theta_i = 0.102755 # Computed from P0 theta_b = theta_range[1] - epsilon D = fronts.D.van_genuchten(n=n, alpha=alpha, k=k, theta_range=theta_range) theta = fronts.solve(D=D, i=theta_i, b=theta_b, itol=1e-7) assert_allclose(theta(r, t), theta_pmf, atol=1e-3) assert_allclose(theta.flux(r, t), U_pmf, atol=1e-6)
def test_badDb(): with pytest.raises(ValueError): theta = fronts.solve(D="theta", i=1, b=-1)
def test_badDi(): with pytest.raises(ValueError): theta = fronts.solve(D="theta", i=-0.1, b=1)
epsilon = 1e-7 # Wetting of an HF135 membrane, Van Genuchten model # Data from Buser (PhD thesis, 2016) # http://hdl.handle.net/1773/38064 theta_range = (0.0473, 0.945) k = 5.50e-13 # m**2 alpha = 0.2555 # 1/m n = 2.3521 theta_i = 0.102755 # Computed from P0 theta_b = theta_range[1] - epsilon D = van_genuchten(n=n, alpha=alpha, k=k, theta_range=theta_range) theta = solve(D=D, i=theta_i, b=theta_b, verbose=2) fig = plt.figure() fig.canvas.set_window_title("Water content plot") plt.title("Water content field at t={} {}".format(validation.t, validation.t_unit)) plt.plot(validation.r, theta(validation.r, validation.t), color='steelblue', label="Fronts") plt.plot(validation.r, validation.theta, color='sandybrown', label=validation.name) plt.xlabel("position [{}]".format(validation.r_unit))
epsilon = 1e-7 # Wetting of an HF135 membrane, Van Genuchten model # Data from Buser (PhD thesis, 2016) # http://hdl.handle.net/1773/38064 theta_range = (0.0473, 0.945) k = 5.50e-13 # m**2 alpha = 0.2555 # 1/m n = 2.3521 theta_i = 0.102755 # Computed from P0 theta_b = theta_range[1] - epsilon D_analytical = van_genuchten(n=n, alpha=alpha, k=k, theta_range=theta_range) analytical = solve(D=D_analytical, i=theta_i, b=theta_b) o = np.linspace(analytical.o[0], analytical.o[-1], 2000) theta = analytical(o=o) D_inverse = inverse(o=o, samples=theta) fig = plt.figure() fig.canvas.set_window_title("Diffusivity plot") plt.title("Diffusivity function") plt.plot(theta, D_analytical(theta), label="Analytical") plt.plot(theta, D_inverse(theta), label="Obtained with inverse()") plt.xlabel("water content [-]") plt.ylabel("diffusivity [{}**2/{}]".format(validation.r_unit,
# Data from Buser (PhD thesis, 2016) # http://hdl.handle.net/1773/38064 theta_range = (0.0473, 0.945) k = 5.50e-13 # m**2 alpha = 0.2555 # 1/m n = 2.3521 theta_i = 0.102755 # Computed from P0 theta_b = theta_range[1] - epsilon D = van_genuchten(n=n, alpha=alpha, k=k, theta_range=theta_range) print("----Starting solution----") coarse = solve(D=D, i=theta_i, b=theta_b, itol=5e-2, d_dob_bracket=(-1, 0), verbose=2) print() print("----Refined with solve()----") fine = solve(D=D, i=theta_i, b=theta_b, d_dob_bracket=coarse.d_dob_bracket, verbose=2) o_guess = fine.o guess = coarse(o=o_guess) print()
#!/usr/bin/env python """ This example solves a problem that has an exact solution (using `fronts.solve`) and compares the solutions. """ from __future__ import division, absolute_import, print_function import numpy as np import matplotlib.pyplot as plt from fronts import solve theta = solve(D="0.5*(1 - log(theta))", i=0, b=1, verbose=2) o = np.linspace(0, 20, 200) fig = plt.figure() fig.canvas.set_window_title("theta plot") plt.title("theta(o)") plt.plot(o, theta(o=o), color='steelblue', label="Fronts") plt.plot(o, np.exp(-o), color='sandybrown', label="Exact") plt.xlabel("o") plt.ylabel("theta") plt.grid(which='both') plt.legend() plt.show()
from __future__ import division, absolute_import, print_function import matplotlib.pyplot as plt from fronts import solve, inverse, o import validation D_inverse = inverse(o=o(validation.r, validation.t)[::5], samples=validation.theta[::5]) # Using only a fifth of the points so that it does not run too slow theta = solve(D=D_inverse, i=validation.theta[-1], b=validation.theta[0], itol=5e-3, verbose=2) fig = plt.figure() fig.canvas.set_window_title("Water content plot") plt.title("Water content field at t={} {}".format(validation.t, validation.t_unit)) plt.plot(validation.r, validation.theta, label="Original ({})".format(validation.name)) plt.plot(validation.r, theta(validation.r, validation.t), label="Reconstructed with inverse() and solve()") plt.xlabel("r [{}]".format(validation.r_unit))
#!/usr/bin/env python """Example of usage of `fronts.solve`.""" from __future__ import division, absolute_import, print_function import numpy as np import matplotlib.pyplot as plt from fronts import solve from fronts.D import power_law k = 4.0 ci = 0.1 cb = 1.0 c = solve(D=power_law(k=k), i=ci, b=cb, verbose=2) r = np.linspace(0, 10, 200) fig = plt.figure() fig.canvas.set_window_title("c plot") plt.title("c field") plt.plot(r, c(r, t=30), label="t=30") plt.plot(r, c(r, t=60), label="t=60") plt.xlabel("r") plt.ylabel("S") plt.grid(which='both') plt.legend() fig = plt.figure()
from __future__ import division, absolute_import, print_function import numpy as np import matplotlib.pyplot as plt from fronts import solve, inverse from fronts.D import power_law k = 4.0 D = power_law(k=k) c1i = 0.1 c1b = 1.0 c1 = solve(D, i=c1i, b=c1b, verbose=2) c2i = 1.0 c2b = 0.1 c2 = solve(D, i=c2i, b=c2b, verbose=2) # Reverse Sb and Si r = np.linspace(0, 30, 200) t = 60 fig = plt.figure() fig.canvas.set_window_title("c plot") plt.title("c field at t={}".format(t))
from fronts import solve from fronts.D import van_genuchten import validation epsilon = 1e-6 Ks = 25 # cm/h alpha = 0.01433 # 1/cm n = 1.506 theta_range = (0, 0.3308) D = van_genuchten(n=n, alpha=alpha, Ks=Ks, theta_range=theta_range) theta = solve(D=D, i=0.1003, b=0.3308 - epsilon, verbose=2) fig = plt.figure() fig.canvas.set_window_title("Water content plot") plt.title("Water content fields") for t, theta_ in zip(validation.t, validation.theta): plt.plot(validation.r, theta(validation.r, t), label="Fronts, t={} {}".format(t, validation.t_unit)) plt.plot(validation.r, theta_, label="{}, t={} {}".format(validation.name, t, validation.t_unit)) plt.xlabel("r [{}]".format(validation.r_unit)) plt.ylabel("water content [-]") plt.grid(which='both')