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

fix more tests on Ubuntu

parent 01a56d31
Branches
Tags
1 merge request!135CI: Replace minimal-ubuntu job with ubuntu
Pipeline #21282 failed with stage
in 4 minutes and 25 seconds
...@@ -291,7 +291,10 @@ class Block(Node): ...@@ -291,7 +291,10 @@ class Block(Node):
self._nodes = nodes self._nodes = nodes
self.parent = None self.parent = None
for n in self._nodes: for n in self._nodes:
n.parent = self try:
n.parent = self
except AttributeError:
pass
@property @property
def args(self): def args(self):
......
...@@ -386,6 +386,13 @@ class CustomSympyPrinter(CCodePrinter): ...@@ -386,6 +386,13 @@ class CustomSympyPrinter(CCodePrinter):
return self._print(expr.args[0]) return self._print(expr.args[0])
elif isinstance(expr, fast_inv_sqrt): elif isinstance(expr, fast_inv_sqrt):
return "({})".format(self._print(1 / sp.sqrt(expr.args[0]))) return "({})".format(self._print(1 / sp.sqrt(expr.args[0])))
elif isinstance(expr, sp.Abs):
return "abs({})".format(self._print(expr.args[0]))
elif isinstance(expr, sp.Mod):
if expr.is_integer:
return "({} % {})".format(self._print(expr.args[0]), self._print(expr.args[1]))
else:
return "fmod({}, {})".format(self._print(expr.args[0]), self._print(expr.args[1]))
elif expr.func in infix_functions: elif expr.func in infix_functions:
return "(%s %s %s)" % (self._print(expr.args[0]), infix_functions[expr.func], self._print(expr.args[1])) return "(%s %s %s)" % (self._print(expr.args[0]), infix_functions[expr.func], self._print(expr.args[1]))
elif expr.func == int_power_of_2: elif expr.func == int_power_of_2:
......
...@@ -3,6 +3,8 @@ from tempfile import TemporaryDirectory ...@@ -3,6 +3,8 @@ from tempfile import TemporaryDirectory
import numpy as np import numpy as np
import pytest
from pystencils import Assignment, create_kernel from pystencils import Assignment, create_kernel
from pystencils.boundaries import BoundaryHandling, Neumann, add_neumann_boundary from pystencils.boundaries import BoundaryHandling, Neumann, add_neumann_boundary
from pystencils.datahandling import SerialDataHandling from pystencils.datahandling import SerialDataHandling
...@@ -83,5 +85,6 @@ def test_kernel_vs_copy_boundary(): ...@@ -83,5 +85,6 @@ def test_kernel_vs_copy_boundary():
np.testing.assert_almost_equal(python_copy_result, handling_result) np.testing.assert_almost_equal(python_copy_result, handling_result)
with TemporaryDirectory() as tmp_dir: with TemporaryDirectory() as tmp_dir:
pytest.importorskip('pyevtk')
boundary_handling.geometry_to_vtk(file_name=os.path.join(tmp_dir, 'test_output1'), ghost_layers=False) boundary_handling.geometry_to_vtk(file_name=os.path.join(tmp_dir, 'test_output1'), ghost_layers=False)
boundary_handling.geometry_to_vtk(file_name=os.path.join(tmp_dir, 'test_output2'), ghost_layers=True) boundary_handling.geometry_to_vtk(file_name=os.path.join(tmp_dir, 'test_output2'), ghost_layers=True)
...@@ -22,6 +22,7 @@ FIELD_SIZES = [(4, 3), (9, 3, 7)] ...@@ -22,6 +22,7 @@ FIELD_SIZES = [(4, 3), (9, 3, 7)]
def _generate_fields(dt=np.uint8, stencil_directions=1, layout='numpy'): def _generate_fields(dt=np.uint8, stencil_directions=1, layout='numpy'):
pytest.importorskip('pycuda')
field_sizes = FIELD_SIZES field_sizes = FIELD_SIZES
if stencil_directions > 1: if stencil_directions > 1:
field_sizes = [s + (stencil_directions,) for s in field_sizes] field_sizes = [s + (stencil_directions,) for s in field_sizes]
...@@ -44,7 +45,6 @@ def _generate_fields(dt=np.uint8, stencil_directions=1, layout='numpy'): ...@@ -44,7 +45,6 @@ def _generate_fields(dt=np.uint8, stencil_directions=1, layout='numpy'):
return fields return fields
@pytest.mark.gpu
def test_full_scalar_field(): def test_full_scalar_field():
"""Tests fully (un)packing a scalar field (from)to a GPU buffer.""" """Tests fully (un)packing a scalar field (from)to a GPU buffer."""
fields = _generate_fields() fields = _generate_fields()
...@@ -73,7 +73,6 @@ def test_full_scalar_field(): ...@@ -73,7 +73,6 @@ def test_full_scalar_field():
np.testing.assert_equal(src_arr, dst_arr) np.testing.assert_equal(src_arr, dst_arr)
@pytest.mark.gpu
def test_field_slice(): def test_field_slice():
"""Tests (un)packing slices of a scalar field (from)to a buffer.""" """Tests (un)packing slices of a scalar field (from)to a buffer."""
fields = _generate_fields() fields = _generate_fields()
...@@ -109,7 +108,6 @@ def test_field_slice(): ...@@ -109,7 +108,6 @@ def test_field_slice():
np.testing.assert_equal(src_arr[pack_slice], dst_arr[unpack_slice]) np.testing.assert_equal(src_arr[pack_slice], dst_arr[unpack_slice])
@pytest.mark.gpu
def test_all_cell_values(): def test_all_cell_values():
"""Tests (un)packing all cell values of the a field (from)to a buffer.""" """Tests (un)packing all cell values of the a field (from)to a buffer."""
num_cell_values = 7 num_cell_values = 7
...@@ -148,7 +146,6 @@ def test_all_cell_values(): ...@@ -148,7 +146,6 @@ def test_all_cell_values():
np.testing.assert_equal(src_arr, dst_arr) np.testing.assert_equal(src_arr, dst_arr)
@pytest.mark.gpu
def test_subset_cell_values(): def test_subset_cell_values():
"""Tests (un)packing a subset of cell values of the a field (from)to a buffer.""" """Tests (un)packing a subset of cell values of the a field (from)to a buffer."""
num_cell_values = 7 num_cell_values = 7
...@@ -190,7 +187,6 @@ def test_subset_cell_values(): ...@@ -190,7 +187,6 @@ def test_subset_cell_values():
np.testing.assert_equal(dst_arr, mask_arr.filled(int(0))) np.testing.assert_equal(dst_arr, mask_arr.filled(int(0)))
@pytest.mark.gpu
def test_field_layouts(): def test_field_layouts():
num_cell_values = 7 num_cell_values = 7
for layout_str in ['numpy', 'fzyx', 'zyxf', 'reverse_numpy']: for layout_str in ['numpy', 'fzyx', 'zyxf', 'reverse_numpy']:
......
...@@ -57,6 +57,9 @@ def test_complex_numbers(assignment, scalar_dtypes, target): ...@@ -57,6 +57,9 @@ def test_complex_numbers(assignment, scalar_dtypes, target):
print(code) print(code)
assert "Not supported" not in code assert "Not supported" not in code
if target == 'gpu':
pytest.importorskip('pycuda')
kernel = ast.compile() kernel = ast.compile()
assert kernel is not None assert kernel is not None
...@@ -100,6 +103,9 @@ def test_complex_numbers_64(assignment, target): ...@@ -100,6 +103,9 @@ def test_complex_numbers_64(assignment, target):
print(code) print(code)
assert "Not supported" not in code assert "Not supported" not in code
if target == 'gpu':
pytest.importorskip('pycuda')
kernel = ast.compile() kernel = ast.compile()
assert kernel is not None assert kernel is not None
...@@ -125,6 +131,7 @@ def test_complex_execution(dtype, target, with_complex_argument): ...@@ -125,6 +131,7 @@ def test_complex_execution(dtype, target, with_complex_argument):
}) })
if target == 'gpu': if target == 'gpu':
pytest.importorskip('pycuda')
from pycuda.gpuarray import zeros from pycuda.gpuarray import zeros
x_arr = zeros((20, 30), complex_dtype) x_arr = zeros((20, 30), complex_dtype)
y_arr = zeros((20, 30), complex_dtype) y_arr = zeros((20, 30), complex_dtype)
......
import sympy import sympy
import pytest
import pystencils import pystencils
from pystencils.astnodes import get_dummy_symbol from pystencils.astnodes import get_dummy_symbol
from pystencils.backends.cuda_backend import CudaSympyPrinter from pystencils.backends.cuda_backend import CudaSympyPrinter
...@@ -19,6 +21,7 @@ def test_cuda_known_functions(): ...@@ -19,6 +21,7 @@ def test_cuda_known_functions():
ast = pystencils.create_kernel(assignments, 'gpu') ast = pystencils.create_kernel(assignments, 'gpu')
print(pystencils.show_code(ast)) print(pystencils.show_code(ast))
pytest.importorskip('pycuda')
kernel = ast.compile() kernel = ast.compile()
assert(kernel is not None) assert(kernel is not None)
......
...@@ -3,6 +3,8 @@ from tempfile import TemporaryDirectory ...@@ -3,6 +3,8 @@ from tempfile import TemporaryDirectory
import numpy as np import numpy as np
import pytest
import pystencils as ps import pystencils as ps
from pystencils import create_data_handling, create_kernel from pystencils import create_data_handling, create_kernel
...@@ -128,6 +130,7 @@ def kernel_execution_jacobi(dh, target): ...@@ -128,6 +130,7 @@ def kernel_execution_jacobi(dh, target):
def vtk_output(dh): def vtk_output(dh):
pytest.importorskip('pyevtk')
dh.add_array('scalar_field') dh.add_array('scalar_field')
dh.add_array('vector_field', values_per_cell=dh.dim) dh.add_array('vector_field', values_per_cell=dh.dim)
dh.add_array('multiple_scalar_field', values_per_cell=9) dh.add_array('multiple_scalar_field', values_per_cell=9)
...@@ -223,6 +226,7 @@ def test_kernel_param(target): ...@@ -223,6 +226,7 @@ def test_kernel_param(target):
def test_vtk_output(): def test_vtk_output():
pytest.importorskip('pyevtk')
for domain_shape in [(4, 5), (3, 4, 5)]: for domain_shape in [(4, 5), (3, 4, 5)]:
dh = create_data_handling(domain_size=domain_shape, periodicity=True) dh = create_data_handling(domain_size=domain_shape, periodicity=True)
vtk_output(dh) vtk_output(dh)
......
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import pytest
pytest.importorskip('pycuda')
```
%% Cell type:code id: tags:
``` python
from pystencils.session import * from pystencils.session import *
sp.init_printing() sp.init_printing()
frac = sp.Rational frac = sp.Rational
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Phase-field simulation of dentritic solidification in 3D # Phase-field simulation of dentritic solidification in 3D
This notebook tests the model presented in the dentritic growth tutorial in 3D. This notebook tests the model presented in the dentritic growth tutorial in 3D.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
target = 'gpu' target = 'gpu'
gpu = target == 'gpu' gpu = target == 'gpu'
domain_size = (25, 25, 25) if 'is_test_run' in globals() else (300, 300, 300) domain_size = (25, 25, 25) if 'is_test_run' in globals() else (300, 300, 300)
dh = ps.create_data_handling(domain_size=domain_size, periodicity=True, default_target=target) dh = ps.create_data_handling(domain_size=domain_size, periodicity=True, default_target=target)
φ_field = dh.add_array('phi', latex_name='φ') φ_field = dh.add_array('phi', latex_name='φ')
φ_delta_field = dh.add_array('phidelta', latex_name='φ_D') φ_delta_field = dh.add_array('phidelta', latex_name='φ_D')
t_field = dh.add_array('T') t_field = dh.add_array('T')
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
ε, m, δ, j, θzero, α, γ, Teq, κ, τ = sp.symbols("ε m δ j θ_0 α γ T_eq κ τ") ε, m, δ, j, θzero, α, γ, Teq, κ, τ = sp.symbols("ε m δ j θ_0 α γ T_eq κ τ")
εb = sp.Symbol("\\bar{\\epsilon}") εb = sp.Symbol("\\bar{\\epsilon}")
discretize = ps.fd.Discretization2ndOrder(dx=0.03, dt=1e-5) discretize = ps.fd.Discretization2ndOrder(dx=0.03, dt=1e-5)
φ = φ_field.center φ = φ_field.center
T = t_field.center T = t_field.center
d = ps.fd.Diff d = ps.fd.Diff
def f(φ, m): def f(φ, m):
return φ**4 / 4 - (frac(1, 2) - m/3) * φ**3 + (frac(1,4)-m/2)*φ**2 return φ**4 / 4 - (frac(1, 2) - m/3) * φ**3 + (frac(1,4)-m/2)*φ**2
bulk_free_energy_density = f(φ, m) bulk_free_energy_density = f(φ, m)
interface_free_energy_density = ε ** 2 / 2 * (d(φ, 0) ** 2 + d(φ, 1) ** 2 + d(φ, 2) ** 2) interface_free_energy_density = ε ** 2 / 2 * (d(φ, 0) ** 2 + d(φ, 1) ** 2 + d(φ, 2) ** 2)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Here comes the major change, that has to be made for the 3D model: $\epsilon$ depends on the interface normal, which can not be computed simply as atan() as in the 2D case Here comes the major change, that has to be made for the 3D model: $\epsilon$ depends on the interface normal, which can not be computed simply as atan() as in the 2D case
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
n = sp.Matrix([d(φ, i) for i in range(3)]) n = sp.Matrix([d(φ, i) for i in range(3)])
nLen = sp.sqrt(sum(n_i**2 for n_i in n)) nLen = sp.sqrt(sum(n_i**2 for n_i in n))
n = n / nLen n = n / nLen
nVal = sum(n_i**4 for n_i in n) nVal = sum(n_i**4 for n_i in n)
σ = δ * nVal σ = δ * nVal
εVal = εb * (1 + σ) εVal = εb * (1 + σ)
εVal εVal
``` ```
%% Output %% Output
$\displaystyle \bar{\epsilon} \left(δ \left(\frac{{\partial_{0} {{φ}_{(0,0,0)}}}^{4}}{\left({\partial_{0} {{φ}_{(0,0,0)}}}^{2} + {\partial_{1} {{φ}_{(0,0,0)}}}^{2} + {\partial_{2} {{φ}_{(0,0,0)}}}^{2}\right)^{2}} + \frac{{\partial_{1} {{φ}_{(0,0,0)}}}^{4}}{\left({\partial_{0} {{φ}_{(0,0,0)}}}^{2} + {\partial_{1} {{φ}_{(0,0,0)}}}^{2} + {\partial_{2} {{φ}_{(0,0,0)}}}^{2}\right)^{2}} + \frac{{\partial_{2} {{φ}_{(0,0,0)}}}^{4}}{\left({\partial_{0} {{φ}_{(0,0,0)}}}^{2} + {\partial_{1} {{φ}_{(0,0,0)}}}^{2} + {\partial_{2} {{φ}_{(0,0,0)}}}^{2}\right)^{2}}\right) + 1\right)$ $\displaystyle \bar{\epsilon} \left(δ \left(\frac{{\partial_{0} {{φ}_{(0,0,0)}}}^{4}}{\left({\partial_{0} {{φ}_{(0,0,0)}}}^{2} + {\partial_{1} {{φ}_{(0,0,0)}}}^{2} + {\partial_{2} {{φ}_{(0,0,0)}}}^{2}\right)^{2}} + \frac{{\partial_{1} {{φ}_{(0,0,0)}}}^{4}}{\left({\partial_{0} {{φ}_{(0,0,0)}}}^{2} + {\partial_{1} {{φ}_{(0,0,0)}}}^{2} + {\partial_{2} {{φ}_{(0,0,0)}}}^{2}\right)^{2}} + \frac{{\partial_{2} {{φ}_{(0,0,0)}}}^{4}}{\left({\partial_{0} {{φ}_{(0,0,0)}}}^{2} + {\partial_{1} {{φ}_{(0,0,0)}}}^{2} + {\partial_{2} {{φ}_{(0,0,0)}}}^{2}\right)^{2}}\right) + 1\right)$
⎛ ⎛ 4 ⎛ ⎛ 4
⎜ ⎜ D(φ[0,0,0]) ⎜ ⎜ D(φ[0,0,0])
\bar{\epsilon}⋅⎜δ⋅⎜───────────────────────────────────────────── + ─────────── \bar{\epsilon}⋅⎜δ⋅⎜───────────────────────────────────────────── + ───────────
⎜ ⎜ 2 ⎜ ⎜ 2
⎜ ⎜⎛ 2 2 2⎞ ⎛ ⎜ ⎜⎛ 2 2 2⎞ ⎛
⎝ ⎝⎝D(φ[0,0,0]) + D(φ[0,0,0]) + D(φ[0,0,0]) ⎠ ⎝D(φ[0,0,0] ⎝ ⎝⎝D(φ[0,0,0]) + D(φ[0,0,0]) + D(φ[0,0,0]) ⎠ ⎝D(φ[0,0,0]
4 4 4 4
D(φ[0,0,0]) D(φ[0,0,0]) D(φ[0,0,0]) D(φ[0,0,0])
────────────────────────────────── + ───────────────────────────────────────── ────────────────────────────────── + ─────────────────────────────────────────
2 2
2 2 2⎞ ⎛ 2 2 2 2 2⎞ ⎛ 2 2
) + D(φ[0,0,0]) + D(φ[0,0,0]) ⎠ ⎝D(φ[0,0,0]) + D(φ[0,0,0]) + D(φ[0,0,0] ) + D(φ[0,0,0]) + D(φ[0,0,0]) ⎠ ⎝D(φ[0,0,0]) + D(φ[0,0,0]) + D(φ[0,0,0]
⎞ ⎞ ⎞ ⎞
⎟ ⎟ ⎟ ⎟
────⎟ + 1⎟ ────⎟ + 1⎟
2⎟ ⎟ 2⎟ ⎟
2⎞ ⎟ ⎟ 2⎞ ⎟ ⎟
) ⎠ ⎠ ⎠ ) ⎠ ⎠ ⎠
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def m_func(temperature): def m_func(temperature):
return (α / sp.pi) * sp.atan(γ * (Teq - temperature)) return (α / sp.pi) * sp.atan(γ * (Teq - temperature))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
substitutions = {m: m_func(T), substitutions = {m: m_func(T),
ε: εVal} ε: εVal}
fe_i = interface_free_energy_density.subs(substitutions) fe_i = interface_free_energy_density.subs(substitutions)
fe_b = bulk_free_energy_density.subs(substitutions) fe_b = bulk_free_energy_density.subs(substitutions)
μ_if = ps.fd.expand_diff_full(ps.fd.functional_derivative(fe_i, φ), functions=[φ]) μ_if = ps.fd.expand_diff_full(ps.fd.functional_derivative(fe_i, φ), functions=[φ])
μ_b = ps.fd.expand_diff_full(ps.fd.functional_derivative(fe_b, φ), functions=[φ]) μ_b = ps.fd.expand_diff_full(ps.fd.functional_derivative(fe_b, φ), functions=[φ])
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
dF_dφ = μ_b + sp.Piecewise((μ_if, nLen**2 > 1e-10), (0, True)) dF_dφ = μ_b + sp.Piecewise((μ_if, nLen**2 > 1e-10), (0, True))
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
parameters = { parameters = {
τ: 0.0003, τ: 0.0003,
κ: 1.8, κ: 1.8,
εb: 0.01, εb: 0.01,
δ: 0.3, δ: 0.3,
γ: 10, γ: 10,
j: 6, j: 6,
α: 0.9, α: 0.9,
Teq: 1.0, Teq: 1.0,
θzero: 0.2, θzero: 0.2,
sp.pi: sp.pi.evalf() sp.pi: sp.pi.evalf()
} }
parameters parameters
``` ```
%% Output %% Output
$\displaystyle \left\{ \pi : 3.14159265358979, \ T_{eq} : 1.0, \ \bar{\epsilon} : 0.01, \ j : 6, \ α : 0.9, \ γ : 10, \ δ : 0.3, \ θ_{0} : 0.2, \ κ : 1.8, \ τ : 0.0003\right\}$ $\displaystyle \left\{ \pi : 3.14159265358979, \ T_{eq} : 1.0, \ \bar{\epsilon} : 0.01, \ j : 6, \ α : 0.9, \ γ : 10, \ δ : 0.3, \ θ_{0} : 0.2, \ κ : 1.8, \ τ : 0.0003\right\}$
{π: 3.14159265358979, T_eq: 1.0, \bar{\epsilon}: 0.01, j: 6, α: 0.9, γ: 10, δ: {π: 3.14159265358979, T_eq: 1.0, \bar{\epsilon}: 0.01, j: 6, α: 0.9, γ: 10, δ:
0.3, θ₀: 0.2, κ: 1.8, τ: 0.0003} 0.3, θ₀: 0.2, κ: 1.8, τ: 0.0003}
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
dφ_dt = - dF_dφ / τ dφ_dt = - dF_dφ / τ
assignments = [ assignments = [
ps.Assignment(φ_delta_field.center, discretize(dφ_dt.subs(parameters))), ps.Assignment(φ_delta_field.center, discretize(dφ_dt.subs(parameters))),
] ]
φEqs = ps.simp.sympy_cse_on_assignment_list(assignments) φEqs = ps.simp.sympy_cse_on_assignment_list(assignments)
φEqs.append(ps.Assignment(φ, discretize(ps.fd.transient(φ) - φ_delta_field.center))) φEqs.append(ps.Assignment(φ, discretize(ps.fd.transient(φ) - φ_delta_field.center)))
temperatureEvolution = -ps.fd.transient(T) + ps.fd.diffusion(T, 1) + κ * φ_delta_field.center temperatureEvolution = -ps.fd.transient(T) + ps.fd.diffusion(T, 1) + κ * φ_delta_field.center
temperatureEqs = [ temperatureEqs = [
ps.Assignment(T, discretize(temperatureEvolution.subs(parameters))) ps.Assignment(T, discretize(temperatureEvolution.subs(parameters)))
] ]
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
temperatureEqs temperatureEqs
``` ```
%% Output %% Output
$\displaystyle \left[ {{T}_{(0,0,0)}} \leftarrow 0.0111111111111111 {{T}_{(-1,0,0)}} + 0.0111111111111111 {{T}_{(0,-1,0)}} + 0.0111111111111111 {{T}_{(0,0,-1)}} + 0.933333333333333 {{T}_{(0,0,0)}} + 0.0111111111111111 {{T}_{(0,0,1)}} + 0.0111111111111111 {{T}_{(0,1,0)}} + 0.0111111111111111 {{T}_{(1,0,0)}} + 1.8 \cdot 10^{-5} {{φ_D}_{(0,0,0)}}\right]$ $\displaystyle \left[ {{T}_{(0,0,0)}} \leftarrow 0.0111111111111111 {{T}_{(-1,0,0)}} + 0.0111111111111111 {{T}_{(0,-1,0)}} + 0.0111111111111111 {{T}_{(0,0,-1)}} + 0.933333333333333 {{T}_{(0,0,0)}} + 0.0111111111111111 {{T}_{(0,0,1)}} + 0.0111111111111111 {{T}_{(0,1,0)}} + 0.0111111111111111 {{T}_{(1,0,0)}} + 1.8 \cdot 10^{-5} {{φ_D}_{(0,0,0)}}\right]$
[T_C := 0.0111111111111111⋅T_W + 0.0111111111111111⋅T_S + 0.0111111111111111⋅T [T_C := 0.0111111111111111⋅T_W + 0.0111111111111111⋅T_S + 0.0111111111111111⋅T
_B + 0.933333333333333⋅T_C + 0.0111111111111111⋅T_T + 0.0111111111111111⋅T_N + _B + 0.933333333333333⋅T_C + 0.0111111111111111⋅T_T + 0.0111111111111111⋅T_N +
0.0111111111111111⋅T_E + 1.8e-5⋅phidelta_C] 0.0111111111111111⋅T_E + 1.8e-5⋅phidelta_C]
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
φ_kernel = ps.create_kernel(φEqs, cpu_openmp=4, target=target).compile() φ_kernel = ps.create_kernel(φEqs, cpu_openmp=4, target=target).compile()
temperatureKernel = ps.create_kernel(temperatureEqs, cpu_openmp=4, target=target).compile() temperatureKernel = ps.create_kernel(temperatureEqs, cpu_openmp=4, target=target).compile()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
def time_loop(steps): def time_loop(steps):
φ_sync = dh.synchronization_function(['phi'], target=target) φ_sync = dh.synchronization_function(['phi'], target=target)
temperature_sync = dh.synchronization_function(['T'], target=target) temperature_sync = dh.synchronization_function(['T'], target=target)
dh.all_to_gpu() dh.all_to_gpu()
for t in range(steps): for t in range(steps):
φ_sync() φ_sync()
dh.run_kernel(φ_kernel) dh.run_kernel(φ_kernel)
temperature_sync() temperature_sync()
dh.run_kernel(temperatureKernel) dh.run_kernel(temperatureKernel)
dh.all_to_cpu() dh.all_to_cpu()
def init(nucleus_size=np.sqrt(5)): def init(nucleus_size=np.sqrt(5)):
for b in dh.iterate(): for b in dh.iterate():
x, y, z = b.cell_index_arrays x, y, z = b.cell_index_arrays
x, y, z = x - b.shape[0] // 2, y - b.shape[1] // 2, z - b.shape[2] // 2 x, y, z = x - b.shape[0] // 2, y - b.shape[1] // 2, z - b.shape[2] // 2
b['phi'].fill(0) b['phi'].fill(0)
b['phi'][(x ** 2 + y ** 2 + z ** 2) < nucleus_size ** 2] = 1.0 b['phi'][(x ** 2 + y ** 2 + z ** 2) < nucleus_size ** 2] = 1.0
b['T'].fill(0.0) b['T'].fill(0.0)
def plot(slice_obj=ps.make_slice[:, :, 0.5]): def plot(slice_obj=ps.make_slice[:, :, 0.5]):
plt.subplot(1, 3, 1) plt.subplot(1, 3, 1)
plt.scalar_field(dh.gather_array('phi', slice_obj).squeeze()) plt.scalar_field(dh.gather_array('phi', slice_obj).squeeze())
plt.title("φ") plt.title("φ")
plt.colorbar() plt.colorbar()
plt.subplot(1, 3, 2) plt.subplot(1, 3, 2)
plt.title("T") plt.title("T")
plt.scalar_field(dh.gather_array('T', slice_obj).squeeze()) plt.scalar_field(dh.gather_array('T', slice_obj).squeeze())
plt.colorbar() plt.colorbar()
plt.subplot(1, 3, 3) plt.subplot(1, 3, 3)
plt.title("∂φ") plt.title("∂φ")
plt.scalar_field(dh.gather_array('phidelta', slice_obj).squeeze()) plt.scalar_field(dh.gather_array('phidelta', slice_obj).squeeze())
plt.colorbar() plt.colorbar()
``` ```
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
init() init()
plot() plot()
print(dh) print(dh)
``` ```
%% Output %% Output
Name| Inner (min/max)| WithGl (min/max) Name| Inner (min/max)| WithGl (min/max)
---------------------------------------------------- ----------------------------------------------------
T| ( 0, 0)| ( 0, 0) T| ( 0, 0)| ( 0, 0)
phi| ( 0, 1)| ( 0, 1) phi| ( 0, 1)| ( 0, 1)
phidelta| ( 0, 0)| ( 0, 0) phidelta| ( 0, 0)| ( 0, 0)
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
if 'is_test_run' in globals(): if 'is_test_run' in globals():
time_loop(2) time_loop(2)
assert np.isfinite(dh.max('phi')) assert np.isfinite(dh.max('phi'))
assert np.isfinite(dh.max('T')) assert np.isfinite(dh.max('T'))
assert np.isfinite(dh.max('phidelta')) assert np.isfinite(dh.max('phidelta'))
else: else:
from time import perf_counter from time import perf_counter
vtk_writer = dh.create_vtk_writer('dentritic_growth_large', ['phi']) vtk_writer = dh.create_vtk_writer('dentritic_growth_large', ['phi'])
last = perf_counter() last = perf_counter()
for i in range(300): for i in range(300):
time_loop(100) time_loop(100)
vtk_writer(i) vtk_writer(i)
print("Step ", i, perf_counter() - last, dh.max('phi')) print("Step ", i, perf_counter() - last, dh.max('phi'))
last = perf_counter() last = perf_counter()
``` ```
......
...@@ -17,6 +17,9 @@ def test_print_infinity(type, negative, target): ...@@ -17,6 +17,9 @@ def test_print_infinity(type, negative, target):
assignment = pystencils.Assignment(x.center, oo) assignment = pystencils.Assignment(x.center, oo)
ast = pystencils.create_kernel(assignment, data_type=type, target=target) ast = pystencils.create_kernel(assignment, data_type=type, target=target)
if target == 'gpu':
pytest.importorskip('pycuda')
ast.compile() ast.compile()
print(ast.compile().code) print(ast.compile().code)
import numpy as np import numpy as np
import pytest
import pystencils as ps import pystencils as ps
from pystencils.rng import PhiloxFourFloats, PhiloxTwoDoubles, AESNIFourFloats, AESNITwoDoubles from pystencils.rng import PhiloxFourFloats, PhiloxTwoDoubles, AESNIFourFloats, AESNITwoDoubles
...@@ -12,6 +14,9 @@ philox_reference = np.array([[[3576608082, 1252663339, 1987745383, 348040302], ...@@ -12,6 +14,9 @@ philox_reference = np.array([[[3576608082, 1252663339, 1987745383, 348040302],
def test_philox_double(): def test_philox_double():
for target in ('cpu', 'gpu'): for target in ('cpu', 'gpu'):
if target == 'gpu':
pytest.importorskip('pycuda')
dh = ps.create_data_handling((2, 2), default_ghost_layers=0, default_target=target) dh = ps.create_data_handling((2, 2), default_ghost_layers=0, default_target=target)
f = dh.add_array("f", values_per_cell=2) f = dh.add_array("f", values_per_cell=2)
...@@ -39,6 +44,9 @@ def test_philox_double(): ...@@ -39,6 +44,9 @@ def test_philox_double():
def test_philox_float(): def test_philox_float():
for target in ('cpu', 'gpu'): for target in ('cpu', 'gpu'):
if target == 'gpu':
pytest.importorskip('pycuda')
dh = ps.create_data_handling((2, 2), default_ghost_layers=0, default_target=target) dh = ps.create_data_handling((2, 2), default_ghost_layers=0, default_target=target)
f = dh.add_array("f", values_per_cell=4) f = dh.add_array("f", values_per_cell=4)
......
...@@ -3,7 +3,6 @@ python_files = test_*.py *_test.py scenario_*.py ...@@ -3,7 +3,6 @@ python_files = test_*.py *_test.py scenario_*.py
norecursedirs = *.egg-info .git .cache .ipynb_checkpoints htmlcov norecursedirs = *.egg-info .git .cache .ipynb_checkpoints htmlcov
addopts = --doctest-modules --durations=20 --cov-config pytest.ini addopts = --doctest-modules --durations=20 --cov-config pytest.ini
markers = markers =
gpu: test that require a gpu
kerncraft: tests depending on kerncraft kerncraft: tests depending on kerncraft
[run] [run]
......
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