Skip to content
Snippets Groups Projects
Commit d7527773 authored by Michael Kuron's avatar Michael Kuron :mortar_board:
Browse files

more tests skipped if depenencies missing

parent a8636b7f
Branches
1 merge request!1Update fluctuating LB test
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
import numpy as np import numpy as np
import sympy as sp import sympy as sp
import pytest
from lbmpy.creationfunctions import update_with_default_parameters from lbmpy.creationfunctions import update_with_default_parameters
from lbmpy.relaxationrates import ( from lbmpy.relaxationrates import (
relaxation_rate_from_lattice_viscosity, relaxation_rate_from_magic_number) relaxation_rate_from_lattice_viscosity, relaxation_rate_from_magic_number)
...@@ -212,6 +214,7 @@ def create_full_parameter_study(): ...@@ -212,6 +214,7 @@ def create_full_parameter_study():
def test_shear_wave(): def test_shear_wave():
pytest.importorskip('pycuda')
params = { params = {
'l_0': 32, 'l_0': 32,
'u_0': 0.096, 'u_0': 0.096,
......
import pytest
from lbmpy.creationfunctions import create_lb_method from lbmpy.creationfunctions import create_lb_method
from lbmpy.methods.creationfunctions import compare_moment_based_lb_methods from lbmpy.methods.creationfunctions import compare_moment_based_lb_methods
from lbmpy.moments import ( from lbmpy.moments import (
...@@ -6,6 +8,7 @@ from lbmpy.stencils import get_stencil ...@@ -6,6 +8,7 @@ from lbmpy.stencils import get_stencil
def test_moment_comparison_table(): def test_moment_comparison_table():
pytest.importorskip('ipy_table')
new = create_lb_method(stencil='D3Q19', maxwellian_moments=True) new = create_lb_method(stencil='D3Q19', maxwellian_moments=True)
old = create_lb_method(stencil='D3Q19', maxwellian_moments=False) old = create_lb_method(stencil='D3Q19', maxwellian_moments=False)
...@@ -25,6 +28,7 @@ def test_moment_comparison_table(): ...@@ -25,6 +28,7 @@ def test_moment_comparison_table():
def test_moment_equality_table(): def test_moment_equality_table():
pytest.importorskip('ipy_table')
d3q19 = get_stencil('D3Q19') d3q19 = get_stencil('D3Q19')
table1 = moment_equality_table(d3q19, max_order=3) table1 = moment_equality_table(d3q19, max_order=3)
assert len(table1.array) == 5 assert len(table1.array) == 5
......
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import pytest
pytest.importorskip('pycuda')
```
%% Cell type:code id: tags:
``` python
from lbmpy.session import * from lbmpy.session import *
from lbmpy.phasefield.n_phase_boyer import * from lbmpy.phasefield.n_phase_boyer import *
from lbmpy.phasefield.kerneleqs import * from lbmpy.phasefield.kerneleqs import *
from lbmpy.phasefield.contact_angle_circle_fitting import * from lbmpy.phasefield.contact_angle_circle_fitting import *
from scipy.ndimage.filters import gaussian_filter from scipy.ndimage.filters import gaussian_filter
from pystencils.simp import sympy_cse_on_assignment_list from pystencils.simp import sympy_cse_on_assignment_list
one = sp.sympify(1) one = sp.sympify(1)
import pyximport import pyximport
pyximport.install(language_level=3) pyximport.install(language_level=3)
from lbmpy.phasefield.simplex_projection import simplex_projection_2d # NOQA from lbmpy.phasefield.simplex_projection import simplex_projection_2d # NOQA
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Simulation arbitrary surface tension case # Simulation arbitrary surface tension case
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
n = 4 n = 4
dx, dt = 1, 1 dx, dt = 1, 1
mobility = 2e-3 mobility = 2e-3
domain_size = (150, 150) domain_size = (150, 150)
ε = one * 4 ε = one * 4
penalty_factor = 0 penalty_factor = 0
stabilization_factor = 10 stabilization_factor = 10
κ = (one, one/2, one/3, one/4) κ = (one, one/2, one/3, one/4)
sigma_factor = one / 15 sigma_factor = one / 15
σ = sp.ImmutableDenseMatrix(n, n, lambda i,j: sigma_factor* (κ[i] + κ[j]) if i != j else 0 ) σ = sp.ImmutableDenseMatrix(n, n, lambda i,j: sigma_factor* (κ[i] + κ[j]) if i != j else 0 )
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
dh = create_data_handling(domain_size, periodicity=True, default_target='gpu') dh = create_data_handling(domain_size, periodicity=True, default_target='gpu')
c = dh.add_array('c', values_per_cell=n) c = dh.add_array('c', values_per_cell=n)
c_tmp = dh.add_array_like('c_tmp', 'c') c_tmp = dh.add_array_like('c_tmp', 'c')
μ = dh.add_array('mu', values_per_cell=n) μ = dh.add_array('mu', values_per_cell=n)
cvec = c.center_vector cvec = c.center_vector
μvec = μ.center_vector μvec = μ.center_vector
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
α, _ = diffusion_coefficients(σ) α, _ = diffusion_coefficients(σ)
f = lambda c: c**2 * ( 1 - c ) **2 f = lambda c: c**2 * ( 1 - c ) **2
a, b = compute_ab(f) a, b = compute_ab(f)
capital_f = capital_f0(cvec, σ) + correction_g(cvec, σ) + stabilization_factor * stabilization_term(cvec, α) capital_f = capital_f0(cvec, σ) + correction_g(cvec, σ) + stabilization_factor * stabilization_term(cvec, α)
f_bulk = free_energy_bulk(capital_f, b, ε) + penalty_factor * (one - sum(cvec)) f_bulk = free_energy_bulk(capital_f, b, ε) + penalty_factor * (one - sum(cvec))
f_if = free_energy_interfacial(cvec, σ, a, ε) f_if = free_energy_interfacial(cvec, σ, a, ε)
f = f_bulk + f_if f = f_bulk + f_if
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#f_bulk #f_bulk
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
μ_assignments = mu_kernel(f, cvec, c, μ) μ_assignments = mu_kernel(f, cvec, c, μ)
μ_assignments = [Assignment(a.lhs, a.rhs.doit()) for a in μ_assignments] μ_assignments = [Assignment(a.lhs, a.rhs.doit()) for a in μ_assignments]
μ_assignments = sympy_cse_on_assignment_list(μ_assignments) μ_assignments = sympy_cse_on_assignment_list(μ_assignments)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
discretize = fd.Discretization2ndOrder(dx=dx, dt=dt) discretize = fd.Discretization2ndOrder(dx=dx, dt=dt)
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def lapl(e): def lapl(e):
return sum(ps.fd.diff(e, d, d) for d in range(dh.dim)) return sum(ps.fd.diff(e, d, d) for d in range(dh.dim))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
rhs = α * μvec rhs = α * μvec
discretized_rhs = [discretize(fd.expand_diff_full( lapl(mobility * rhs_i) + fd.transient(cvec[i], idx=i), functions=μvec)) discretized_rhs = [discretize(fd.expand_diff_full( lapl(mobility * rhs_i) + fd.transient(cvec[i], idx=i), functions=μvec))
for i, rhs_i in enumerate(rhs)] for i, rhs_i in enumerate(rhs)]
c_assignments = [Assignment(lhs, rhs) c_assignments = [Assignment(lhs, rhs)
for lhs, rhs in zip(c_tmp.center_vector, discretized_rhs)] for lhs, rhs in zip(c_tmp.center_vector, discretized_rhs)]
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#c_assignments #c_assignments
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
μ_sync = dh.synchronization_function(μ.name) μ_sync = dh.synchronization_function(μ.name)
c_sync = dh.synchronization_function(c.name) c_sync = dh.synchronization_function(c.name)
optimization = {'cpu_openmp': 4, 'cpu_vectorize_info': None} optimization = {'cpu_openmp': 4, 'cpu_vectorize_info': None}
μ_kernel = create_kernel(μ_assignments, target=dh.default_target, **optimization).compile() μ_kernel = create_kernel(μ_assignments, target=dh.default_target, **optimization).compile()
c_kernel = create_kernel(c_assignments, target=dh.default_target, **optimization).compile() c_kernel = create_kernel(c_assignments, target=dh.default_target, **optimization).compile()
def set_c(slice_obj, values): def set_c(slice_obj, values):
for block in dh.iterate(slice_obj): for block in dh.iterate(slice_obj):
arr = block[c.name] arr = block[c.name]
arr[..., : ] = values arr[..., : ] = values
def smooth(): def smooth():
for block in dh.iterate(ghost_layers=True): for block in dh.iterate(ghost_layers=True):
c_arr = block[c.name] c_arr = block[c.name]
for i in range(n): for i in range(n):
gaussian_filter(c_arr[..., i], sigma=2, output=c_arr[..., i]) gaussian_filter(c_arr[..., i], sigma=2, output=c_arr[..., i])
def time_loop(steps): def time_loop(steps):
dh.all_to_gpu() dh.all_to_gpu()
for t in range(steps): for t in range(steps):
c_sync() c_sync()
dh.run_kernel(μ_kernel) dh.run_kernel(μ_kernel)
μ_sync() μ_sync()
dh.run_kernel(c_kernel) dh.run_kernel(c_kernel)
dh.swap(c.name, c_tmp.name) dh.swap(c.name, c_tmp.name)
#simplex_projection_2d(dh.cpu_arrays[c.name]) #simplex_projection_2d(dh.cpu_arrays[c.name])
dh.all_to_cpu() dh.all_to_cpu()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
set_c(make_slice[:, :], [0, 0, 0, 0]) set_c(make_slice[:, :], [0, 0, 0, 0])
set_c(make_slice[:, 0.5:], [1, 0, 0, 0]) set_c(make_slice[:, 0.5:], [1, 0, 0, 0])
set_c(make_slice[:, :0.5], [0, 1, 0, 0]) set_c(make_slice[:, :0.5], [0, 1, 0, 0])
set_c(make_slice[0.3:0.7, 0.3:0.7], [0, 0, 1, 0]) set_c(make_slice[0.3:0.7, 0.3:0.7], [0, 0, 1, 0])
smooth() smooth()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
#dh.load_all('n_phases_state_size200_stab10.npz') #dh.load_all('n_phases_state_size200_stab10.npz')
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
plt.phase_plot(dh.gather_array(c.name)) plt.phase_plot(dh.gather_array(c.name))
``` ```
%% Output %% Output
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
neumann_angles_from_surface_tensions(lambda i, j: float(σ[i, j])) neumann_angles_from_surface_tensions(lambda i, j: float(σ[i, j]))
``` ```
%% Output %% Output
$\displaystyle \left[ 146.44269023807928, \ 117.81813928465394, \ 95.73917047726678\right]$ $\displaystyle \left[ 146.44269023807928, \ 117.81813928465394, \ 95.73917047726678\right]$
[146.44269023807928, 117.81813928465394, 95.73917047726678] [146.44269023807928, 117.81813928465394, 95.73917047726678]
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import time import time
for i in range(10): for i in range(10):
start = time.perf_counter() start = time.perf_counter()
time_loop(1_000) time_loop(1_000)
end = time.perf_counter() end = time.perf_counter()
try: try:
print(i, end - start, liquid_lens_neumann_angles(dh.gather_array(c.name))) print(i, end - start, liquid_lens_neumann_angles(dh.gather_array(c.name)))
except Exception: except Exception:
print(i, end - start, "none found") print(i, end - start, "none found")
``` ```
%% Output %% Output
0 0.30607624700132874 [83.97888710273061, 100.48794346625529, 175.5331694310141] 0 0.30607624700132874 [83.97888710273061, 100.48794346625529, 175.5331694310141]
1 0.2600655169990205 [83.73094685534376, 100.65854574856168, 175.6105073960945] 1 0.2600655169990205 [83.73094685534376, 100.65854574856168, 175.6105073960945]
2 0.2601136189987301 [83.49914818603683, 100.82173327601079, 175.67911853795226] 2 0.2601136189987301 [83.49914818603683, 100.82173327601079, 175.67911853795226]
3 0.25987518599868054 [83.31519592224448, 100.94468140501989, 175.74012267273554] 3 0.25987518599868054 [83.31519592224448, 100.94468140501989, 175.74012267273554]
4 0.2651959220020217 [83.14239972296966, 101.06100094405181, 175.79659933297853] 4 0.2651959220020217 [83.14239972296966, 101.06100094405181, 175.79659933297853]
5 0.25910847799968906 [82.984481834461, 101.16731750637399, 175.8482006591651] 5 0.25910847799968906 [82.984481834461, 101.16731750637399, 175.8482006591651]
6 0.259863024999504 [82.84781128433397, 101.2570276449976, 175.89516107066834] 6 0.259863024999504 [82.84781128433397, 101.2570276449976, 175.89516107066834]
7 0.2606479199966998 [82.7456965110742, 101.31687551766585, 175.93742797125986] 7 0.2606479199966998 [82.7456965110742, 101.31687551766585, 175.93742797125986]
8 0.25991897900166805 [82.67010885583116, 101.35099855297112, 175.97889259119805] 8 0.25991897900166805 [82.67010885583116, 101.35099855297112, 175.97889259119805]
9 0.2590353729974595 [75.9000280154447, 108.9652166787719, 175.1347553057833] 9 0.2590353729974595 [75.9000280154447, 108.9652166787719, 175.1347553057833]
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
plt.subplot(1,3,1) plt.subplot(1,3,1)
t = dh.gather_array(c.name, make_slice[25, :]).squeeze() t = dh.gather_array(c.name, make_slice[25, :]).squeeze()
plt.plot(t); plt.plot(t);
plt.subplot(1,3,2) plt.subplot(1,3,2)
plt.phase_plot(dh.gather_array(c.name), linewidth=1) plt.phase_plot(dh.gather_array(c.name), linewidth=1)
plt.subplot(1,3,3) plt.subplot(1,3,3)
plt.scalar_field(dh.gather_array(μ.name)[:, :, 2]) plt.scalar_field(dh.gather_array(μ.name)[:, :, 2])
plt.colorbar(); plt.colorbar();
``` ```
%% Output %% Output
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
assert not np.isnan(dh.max(c.name)) assert not np.isnan(dh.max(c.name))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
t = dh.gather_array(c.name, make_slice[25, 55:90]).squeeze() t = dh.gather_array(c.name, make_slice[25, 55:90]).squeeze()
plt.hlines(0.5, 0, 30) plt.hlines(0.5, 0, 30)
plt.plot(t); plt.plot(t);
``` ```
%% Output %% Output
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment