Commit ebfd56e1 authored by Markus Holzer's avatar Markus Holzer
Browse files

fixed docstring bugs and expm1 optimisation

parent 35c029a0
......@@ -66,6 +66,7 @@ try:
if int(sympy_version[0]) <= 1 and int(sympy_version[1]) <= 4:
def hash_fun(self):
return hash((self.lhs, self.rhs))
Assignment.__hash__ = hash_fun
except Exception:
pass
......@@ -94,16 +95,19 @@ def assignment_from_stencil(stencil_array, input_field, output_field,
... [0, 6, 0]]
By default 'visual ordering is used - i.e. the stencil is applied as the nested lists are written down
>>> assignment_from_stencil(stencil, f, g, order='visual')
Assignment(g_C, 3*f_W + 6*f_S + 4*f_C + 2*f_N + 5*f_E)
>>> expected_output = Assignment(g[0, 0], 3*f[-1, 0] + 6*f[0, -1] + 4*f[0, 0] + 2*f[0, 1] + 5*f[1, 0])
>>> assignment_from_stencil(stencil, f, g, order='visual') == expected_output
True
'numpy' ordering uses the first coordinate of the stencil array for x offset, second for y offset etc.
>>> assignment_from_stencil(stencil, f, g, order='numpy')
Assignment(g_C, 2*f_W + 3*f_S + 4*f_C + 5*f_N + 6*f_E)
>>> expected_output = Assignment(g[0, 0], 2*f[-1, 0] + 3*f[0, -1] + 4*f[0, 0] + 5*f[0, 1] + 6*f[1, 0])
>>> assignment_from_stencil(stencil, f, g, order='numpy') == expected_output
True
You can also pass field accesses to apply the stencil at an already shifted position:
>>> assignment_from_stencil(stencil, f[1, 0], g[2, 0])
Assignment(g_2E, 3*f_C + 6*f_SE + 4*f_E + 2*f_NE + 5*f_2E)
>>> expected_output = Assignment(g[2, 0], 3*f[0, 0] + 6*f[1, -1] + 4*f[1, 0] + 2*f[1, 1] + 5*f[2, 0])
>>> assignment_from_stencil(stencil, f[1, 0], g[2, 0]) == expected_output
True
"""
from pystencils.field import Field
......
import itertools
import warnings
from collections import defaultdict
import numpy as np
......
......@@ -21,10 +21,13 @@ def diffusion(scalar, diffusion_coeff, idx=None):
Examples:
>>> f = Field.create_generic('f', spatial_dimensions=2)
>>> d = sp.Symbol("d")
>>> dx = sp.Symbol("dx")
>>> diffusion_term = diffusion(scalar=f, diffusion_coeff=sp.Symbol("d"))
>>> discretization = Discretization2ndOrder()
>>> discretization(diffusion_term)
(f_W*d + f_S*d - 4*f_C*d + f_N*d + f_E*d)/dx**2
>>> expected_output = ((f[-1, 0] + f[0, -1] - 4*f[0, 0] + f[0, 1] + f[1, 0]) * d) / dx**2
>>> sp.simplify(discretization(diffusion_term) - expected_output)
0
"""
if isinstance(scalar, Field):
first_arg = scalar.center
......@@ -313,8 +316,9 @@ def discretize_center(term, symbols_to_field_dict, dx, dim=3):
>>> term
x*x^Delta^0
>>> f = Field.create_generic('f', spatial_dimensions=3)
>>> discretize_center(term, { x: f }, dx=1, dim=3)
f_C*(-f_W/2 + f_E/2)
>>> expected_output = f[0, 0, 0] * (-f[-1, 0, 0]/2 + f[1, 0, 0]/2)
>>> sp.simplify(discretize_center(term, { x: f }, dx=1, dim=3) - expected_output)
0
"""
substitutions = {}
for symbols, field in symbols_to_field_dict.items():
......@@ -396,8 +400,10 @@ def discretize_divergence(vector_term, symbols_to_field_dict, dx):
>>> x, dx = sp.symbols("x dx")
>>> grad_x = grad(x, dim=3)
>>> f = Field.create_generic('f', spatial_dimensions=3)
>>> sp.simplify(discretize_divergence(grad_x, {x : f}, dx))
(f_W + f_S + f_B - 6*f_C + f_T + f_N + f_E)/dx**2
>>> expected_output = (f[-1, 0, 0] + f[0, -1, 0] + f[0, 0, -1] -
... 6*f[0, 0, 0] + f[0, 0, 1] + f[0, 1, 0] + f[1, 0, 0])/dx**2
>>> sp.simplify(discretize_divergence(grad_x, {x : f}, dx) - expected_output)
0
"""
dim = len(vector_term)
result = 0
......
%% Cell type:code id: tags:
``` python
from pystencils.session import *
from pystencils.fd.derivation import *
```
%% Cell type:markdown id: tags:
# 2D standard stencils
%% Cell type:code id: tags:
``` python
stencil = [(-1, 0), (1, 0), (0, -1), (0, 1), (0, 0)]
standard_2d_00 = FiniteDifferenceStencilDerivation((0,0), stencil)
f = ps.fields("f: [2D]")
standard_2d_00_res = standard_2d_00.get_stencil()
res = standard_2d_00_res.apply(f.center)
expected = f[-1, 0] - 2 * f[0, 0] + f[1, 0]
assert res == expected
```
%% Cell type:code id: tags:
``` python
assert standard_2d_00_res.accuracy == 2
assert not standard_2d_00_res.is_isotropic
standard_2d_00_res
```
%%%% Output: execute_result
Finite difference stencil of accuracy 2, isotropic error: False
%% Cell type:code id: tags:
``` python
standard_2d_00.get_stencil().as_array()
```
%%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGkAAABLCAYAAABz5qkHAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFRElEQVR4Ae1dUW7UMBDdRXyj0kqI7+0NlvYElBuUI5TegIoj0BtQToDaI7QngO4NyjdCoq24wPJe1rOysk5iB3vtJmPJtWM74/F7njixve50MpnM4W/hXe5quVy+d2VoWjwEptPpHaTNXBKB//S5lXGBOAvb7qd9ofFkCHyG5J2a9ENcHzNtCi+WtA/WlBSiUoCDdZGgy7oldaqGG8n4H/hH+H34bxCyQJjdDV03WtISfgbAJ00e+Ry3jiUfcZpn9SyVtFzhEHUj1vCAdDl5hkinQy/9gEIk8UoKI05r4vWlpOUIx6CbF0kAn2941w4SviNtDqDqg56jaLKkwevmS9JRA8S0Jrqm/FVu2r9NdQ9Gt06SLCu5b8F61pKXLGssunWSBIR3DcrSM23Q24izy6WKj0I3H5IE4LZxZ08KZQoHrZsPSW3WIj2Z30453Ch06yTJvGqTACHEJkN6cJaZirHo1kmSYYSv30KITZIQ53o9t8uljA9eN1+S+MF64ECaU0MLq0c7iiRPGoVuc8DoMy3EKaD6tNAD0uYgqXE6aRt50GFwuhFreMC3nNhLFUhrdW+Q+wnfJjNTilPpbyFk0XrXdjIHrZsuVWynEwXXAmNYL1X4jknBlegN8RBQkuJhmUySkpQM2niClaR4WCaTpCQlgzaeYCUpHpbJJClJyaCNJ1hJiodlMklKUjJo4wlWkuJhmUxSyNxdMiVSCzZ7Ibixk262CiZnh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jeD3cQkteM66rjkfwhPlf77AXKCegK8YeIjd7sJqRH2H65uDeOeUcgJoejpuuKr5YUw9ZHVtwQQM/hKrmMONz9xfbMxYjKDADDrw07ISCkefvNa1Mfw084RS5TSH10UNQngOCd3F4IyDWwEd/3lrkm9f57RUjY9RTOLPBGwc/f8Rj4iDR/pXgW1ldML61bMiQcDC+4PLB9dyDXKPuONOfAFn7i7ur0ISIgDmnT61HFIfXvSBK6dYG0MXdDIQiIJHLTEdrskkb7K+s21O9JXXTOXtcgZUcQd8AgxTXKXsMgZUcQd8AgxTXKXsMgZUcQd8AgxTXKXsMgZUcQd8AgxTXKXsMgZUcQdyB5WoimMMXBCUp7c2Rc17kaq+qW3JPQkL05ck76tIyEbkmQ0JC9OTKNyVwtKd2SIKHl4t/OOKeuXEZEt1RIfg2p6j6fP2Bo2j/bq/u3qe1ifItCQpf1K4ptry0b63Kotz4U36KQIA9XYxn8mTnLzf62gQvraaUH4VsKJC+w71E+H8bbYSZDumjfUiC19RZ/JtubIxfPTDHdopAw7vthzgMJ3fFnsPoDHWGjPj0U36KQnCDFv53RgxeORXRLhVT82xmF4XhzIrolQcKwYm+O9LJ3iKV06zLByufX7M2RHSC5qivrlgzJXaR7+Xue0n1LGu66nzz2CUkFDJKkmkq2DJKSsJJmDZKkmkq2DJKSsJJmw7u7O9wlVW3bPwOuKqKQh+6N/wyYzRES592abq0nrGRBXQE+4OPnQRca+weeGBF+hDwvIgAAAABJRU5ErkJggg==)
$\displaystyle \left[\begin{matrix}0 & 0 & 0\\1 & -2 & 1\\0 & 0 & 0\end{matrix}\right]$
⎡0 0 0⎤
⎢ ⎥
⎢1 -2 1⎥
⎢ ⎥
⎣0 0 0⎦
%% Cell type:markdown id: tags:
# 2D isotropic stencils
## second x-derivative
%% Cell type:code id: tags:
``` python
stencil = [(i, j) for i in (-1, 0, 1) for j in (-1, 0, 1)]
isotropic_2d_00 = FiniteDifferenceStencilDerivation((0,0), stencil)
isotropic_2d_00_res = isotropic_2d_00.get_stencil(isotropic=True)
assert isotropic_2d_00_res.is_isotropic
assert isotropic_2d_00_res.accuracy == 2
isotropic_2d_00_res
```
%%%% Output: execute_result
Finite difference stencil of accuracy 2, isotropic error: True
%% Cell type:code id: tags:
``` python
isotropic_2d_00_res.as_array()
```
%%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIIAAABNCAYAAABqvbycAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAH5ElEQVR4Ae2dT47kNBTGq0esUYsFQiyrN6x7NCeguUHPcAJmbtAtViwQGvXcoAchViygkThA96xYDswNZtiwQEjQrVkhsSh+X8oOSSpV5YrtxEnZ0qvYjmO/973n/3FltlgsZr40m82OoWvffFJ8PlXZQvP1Dhl2dgcHBzKAJyaDeeeMEnwwVdli8iVlLtbQlUst5dkT6LVL2rGlSVW2XfmSfqBWPUsn1RbhuUnMpXRvSl/2jB2BCwQ4bAjxgPCp4qqGcIFlZMU3kJpKEN2qotcc3YyMoDCEe7U7ObC3CGRD2FvV1wXPhlDHY29D2RD2VvV1wUMZQnM0Wi9l3KFUZQvKl5chMOqcQ5foWVMT+a+gs3Hrfcl9qrLF4usAsbWg9Ct0lKePSyPYl1+MSlNHLRoeeLUI+wLYPsiZDWEftOwgY3VlcWNymhGtU3s5NUFeGWx5GB41gHqxJVnz9mfw9aoa6SJrbFnEjwsfVb7b/K58OhuCa4ZtzPQVB493lHXft7xUZO2TD2dDqIKLpWqAqb2JT6rx8nPPbm7MCWrv4twoSLdH54w84vsv6A5ZVtbs+xAqNuY7GYJhZu37Bwa0S8AqNq8IXwGSmmrvWtoH2M0y4F+zKRnyDX4ZtsK9GgLlbnzng/uqeEEwt+8jzBHY6W0lCj6BVt4/UBxU5oN/57xdeYidDt61HlK+j4Ff44+z2OWuy5+yg2NOnpo+UuRiFmPWoJpjnfpsuWrcMib9389h8XvLJmCpW3hmw4ldq/h2wnynrmGb8AB11EijFkHul+VlVL9qATTmsSulki258U4ozIMaQoua1X8lB14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054BL6xrEx7W0IdiUxWO3RK175rSSVsXfPnYl3i8OV3Y9yi+cl1fKQ56BLtMM7oTEfZAg1M2aWgKIbVIPGdjQGMFPMyxwM1c53Ke1NTeKfswwYcvkHFxt8ATLJv4nYfcZKS9YkDu9MhfmgEaGnUswjgct5ZkN22VVJ+p9BDpIEEtvGdxTmXg1B1msfEUNmfAkoxx/Xws+Z1SMDySQP7/jC3KshgFaLcByzcxYFrvF/cjy8Mwrz/ZbivGUFJgyVf3Dxhuj2hlwwD2IIYqj8g8t2vXm9whVz74YghhaSkONh1TSTvILxFbwKH7gx3haed/RRTY07yqMV+cDc9hH4UYi2MKcq63qNu3Kk2hfXCueRwIFRczQMg+hqo109tXx1kERM8QOXs1qemId3nDAX//yCfpdhI94MQ6hW/6rc6gd3xZLUGA1tev+AxSMYbvyyiOpdLBvJJCGe8W8OFDi9Bf/INfnhHfXvC3NuUGTopP8B4bgV5RaoCpcAAAAASUVORK5CYII=)
$\displaystyle \left[\begin{matrix}\frac{1}{12} & - \frac{1}{6} & \frac{1}{12}\\\frac{5}{6} & - \frac{5}{3} & \frac{5}{6}\\\frac{1}{12} & - \frac{1}{6} & \frac{1}{12}\end{matrix}\right]$
⎡1/12 -1/6 1/12⎤
⎢ ⎥
⎢5/6 -5/3 5/6 ⎥
⎢ ⎥
⎣1/12 -1/6 1/12⎦
%% Cell type:code id: tags:
``` python
plt.figure(figsize=(2,2))
isotropic_2d_00_res.visualize()
```
%%%% Output: display_data
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAI8AAACYCAYAAADdsLqwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAATtklEQVR4nO2de3Bc1X2Av7Mr7UMP63Ul27JsMH4VQwK4YEwoxbQFvB4D42BioG54FM+E4iHBZIoJThMIEIq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0MDIGn0ifMvIDHCOP9ClB4EfoF0gFaqVPOaazHEORPuUk8DjG/kCiBIHNGShXL69gjEDtRNwYYdyz6jDyfPMyYBrpJTp4z4S/wBGEP1BOpH2JEx2kRjTRwQHpU0z7mJHwBxaRXqKDMHCCSPvGXMLHlSdHjlSYAjelcmSKnDw50ub/AXdP1nrcWkF9AAAAAElFTkSuQmCC)
%% Cell type:code id: tags:
``` python
expected_result = sp.Matrix([[1, -2, 1], [10, -20, 10], [1, -2, 1]]) / 12
assert expected_result[:] == isotropic_2d_00_res.as_array()[:]
expected_result = sp.Array([[1, -2, 1], [10, -20, 10], [1, -2, 1]]) / 12
assert expected_result == isotropic_2d_00_res.as_array()
```
%% Cell type:code id: tags:
``` python
type(isotropic_2d_00_res.as_array())
```
%%%% Output: execute_result
sympy.tensor.array.dense_ndim_array.MutableDenseNDimArray
%% Cell type:code id: tags:
``` python
type(expected_result)
```
%%%% Output: execute_result
sympy.matrices.dense.MutableDenseMatrix
%% Cell type:markdown id: tags:
## Isotropic laplacian
%% Cell type:code id: tags:
``` python
isotropic_2d_11 = FiniteDifferenceStencilDerivation((1,1), stencil)
isotropic_2d_11_res = isotropic_2d_11.get_stencil(isotropic=True)
iso_laplacian = isotropic_2d_00_res.as_array() + isotropic_2d_11_res.as_array()
iso_laplacian
```
%%%% Output: execute_result
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHoAAABNCAYAAABpJnDxAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAINklEQVR4Ae2dvY4cRRSFdy3HaDESIiCaJSBey0/g5Q0WExBjvwEWEaG15gkWiYAUWyIh8/IExg7IcYyQzFqIgGz5Tk9Vq7qnd6aqu3r61kxf6U7/d997Tv3X7Z7D6+vrg1Q5PDw84Zpzrv0s9dopz8fuc55/hC7QN+hjfHjH0rwMxfx2iofuYY/cNQKrGHEkX0CsCD5g+xmLX9G72rYqOTFX7lS27tJnyvFt5dxT9I/2fsvbshddeBtZ937X+/wxi0vsXYu586+LQ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2JQyY0xXBR6v8D0vOpx54AZn/AAAAAElFTkSuQmCC)
$\displaystyle \left[\begin{matrix}\frac{1}{6} & \frac{2}{3} & \frac{1}{6}\\\frac{2}{3} & - \frac{10}{3} & \frac{2}{3}\\\frac{1}{6} & \frac{2}{3} & \frac{1}{6}\end{matrix}\right]$
⎡1/6 2/3 1/6⎤
⎢ ⎥
⎢2/3 -10/3 2/3⎥
⎢ ⎥
⎣1/6 2/3 1/6⎦
%% Cell type:code id: tags:
``` python
expected_result = sp.Matrix([[1, 4, 1], [4, -20, 4], [1, 4, 1]]) / 6
assert iso_laplacian[:] == expected_result[:]
expected_result = sp.Array([[1, 4, 1], [4, -20, 4], [1, 4, 1]]) / 6
assert iso_laplacian == expected_result
```
%% Cell type:markdown id: tags:
# stencils for staggered fields
%% Cell type:code id: tags:
``` python
half = sp.Rational(1, 2)
fd_points_ex = (
(half, 0),
(-half, 0),
(half, 1),
(half, -1),
(-half, 1),
(-half, -1)
)
assert set(fd_points_ex) == set(FiniteDifferenceStaggeredStencilDerivation("E", 2).stencil)
fd_points_ey = (
(0, half),
(0, -half),
(-1,-half),
(-1, half),
(1, -half),
(1, half)
)
assert set(fd_points_ey) == set(FiniteDifferenceStaggeredStencilDerivation("N",2).stencil)
fd_points_c = (
(half, half),
(-half, -half),
(half, -half),
(-half, half)
)
assert set(fd_points_c) == set(FiniteDifferenceStaggeredStencilDerivation("NE",2).stencil)
assert len(FiniteDifferenceStaggeredStencilDerivation("E",3).points) == 10
assert len(FiniteDifferenceStaggeredStencilDerivation("NE",3).points) == 12
assert len(FiniteDifferenceStaggeredStencilDerivation("TNE",3).points) == 8
```
%% Cell type:code id: tags:
``` python
c = ps.fields("c: [2D]")
c3 = ps.fields("c3: [3D]")
assert FiniteDifferenceStaggeredStencilDerivation("E", 2, (0,)).apply(c.center) == c[1, 0] - c[0, 0]
assert FiniteDifferenceStaggeredStencilDerivation("W", 2, (0,)).apply(c.center) == c[0, 0] - c[-1, 0]
assert FiniteDifferenceStaggeredStencilDerivation("N", 2, (1,)).apply(c.center) == c[0, 1] - c[0, 0]
assert FiniteDifferenceStaggeredStencilDerivation("S", 2, (1,)).apply(c.center) == c[0, 0] - c[0, -1]
assert FiniteDifferenceStaggeredStencilDerivation("E", 3, (0,)).apply(c3.center) == c3[1, 0, 0] - c3[0, 0, 0]
assert FiniteDifferenceStaggeredStencilDerivation("W", 3, (0,)).apply(c3.center) == c3[0, 0, 0] - c3[-1, 0, 0]
assert FiniteDifferenceStaggeredStencilDerivation("N", 3, (1,)).apply(c3.center) == c3[0, 1, 0] - c3[0, 0, 0]
assert FiniteDifferenceStaggeredStencilDerivation("S", 3, (1,)).apply(c3.center) == c3[0, 0, 0] - c3[0, -1, 0]
assert FiniteDifferenceStaggeredStencilDerivation("T", 3, (2,)).apply(c3.center) == c3[0, 0, 1] - c3[0, 0, 0]
assert FiniteDifferenceStaggeredStencilDerivation("B", 3, (2,)).apply(c3.center) == c3[0, 0, 0] - c3[0, 0, -1]
assert FiniteDifferenceStaggeredStencilDerivation("S", 2, (0,)).apply(c.center) == \
(c[1, 0] + c[1, -1] - c[-1, 0] - c[-1, -1])/4
assert FiniteDifferenceStaggeredStencilDerivation("NE", 2, (0,)).apply(c.center) + \
FiniteDifferenceStaggeredStencilDerivation("NE", 2, (1,)).apply(c.center) == c[1, 1] - c[0, 0]
assert FiniteDifferenceStaggeredStencilDerivation("NE", 3, (0,)).apply(c3.center) + \
FiniteDifferenceStaggeredStencilDerivation("NE", 3, (1,)).apply(c3.center) == c3[1, 1, 0] - c3[0, 0, 0]
```
%% Cell type:code id: tags:
``` python
d = FiniteDifferenceStaggeredStencilDerivation("NE", 2, (0, 1))
assert d.apply(c.center) == c[0,0] + c[1,1] - c[1,0] - c[0,1]
d.visualize()
```
%%%% Output: display_data
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWwAAAFmCAYAAABJBKDfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0R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v3 = ps.fields("v(3): [3D]")
for i in range(*v3.index_shape):
assert FiniteDifferenceStaggeredStencilDerivation("E", 3, (0,)).apply(v3.center_vector[i]) == \
v3[1,0,0](i) - v3[0,0,0](i)
```
......
......@@ -11,8 +11,11 @@ def test_sympy_optimizations():
x, y, z = pystencils.fields('x, y, z: float32[2d]')
# Triggers Sympy's expm1 optimization
# Sympy's expm1 optimization is tedious to use and the behaviour is highly depended on the sympy version. In
# some cases the exp expression has to be encapsulated in brackets or multiplied with 1 or 1.0
# for sympy to work properly ...
assignments = pystencils.AssignmentCollection({
x[0, 0]: sp.exp(y[0, 0]) - 1
x[0, 0]: 1.0 * (sp.exp(y[0, 0]) - 1)
})
assignments = optimize_assignments(assignments, optims_pystencils_cpu)
......@@ -28,7 +31,7 @@ def test_evaluate_constant_terms():
for target in ('cpu', 'gpu'):
x, y, z = pystencils.fields('x, y, z: float32[2d]')
# Triggers Sympy's expm1 optimization
# Triggers Sympy's cos optimization
assignments = pystencils.AssignmentCollection({
x[0, 0]: -sp.cos(1) + y[0, 0]
})
......@@ -53,8 +56,6 @@ def test_do_not_evaluate_constant_terms():
x[0, 0]: -sp.cos(1) + y[0, 0]
})
optimize_assignments(assignments, optimizations)
ast = pystencils.create_kernel(assignments, target=target)
code = pystencils.get_code_str(ast)
assert 'cos(' in code
......
Markdown is supported
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