Commit 7b4c3f2d authored by Martin Bauer's avatar Martin Bauer
Browse files

Refactoring of plotting and stencil plotting

- stencil plotting & transformation now in ps.stencil
- additional documentation & notebooks
parent 0998f2e1
Pipeline #15208 passed with stage
in 3 minutes and 34 seconds
import sympy as sp
import pystencils as ps
from pystencils.astnodes import LoopOverCoordinate
from pystencils.stencils import stencil_coefficients
from pystencils.fd.spatial import fd_stencils_standard, fd_stencils_isotropic, discretize_spatial
from pystencils.fd import diff
......@@ -22,7 +21,7 @@ def test_spatial_2d_unit_sum():
for term in terms:
for scheme in schemes:
discretized = discretize_spatial(term, dx=h, stencil=scheme)
_, coefficients = stencil_coefficients(discretized)
_, coefficients = ps.stencil.coefficients(discretized)
assert sum(coefficients) == 0
......@@ -38,7 +37,7 @@ def test_spatial_1d_unit_sum():
for term in terms:
for scheme in schemes:
discretized = discretize_spatial(term, dx=h, stencil=scheme)
_, coefficients = stencil_coefficients(discretized)
_, coefficients = ps.stencil.coefficients(discretized)
assert sum(coefficients) == 0
......
import os
from tempfile import TemporaryDirectory
import numpy as np
import pystencils.plot as plt
def example_scalar_field(t=0):
x, y = np.meshgrid(np.linspace(0, 2 * np.pi, 100), np.linspace(0, 2 * np.pi, 100))
z = np.cos(x + 0.1 * t) * np.sin(y + 0.1 * t) + 0.1 * x * y
return z
def example_vector_field(t=0, shape=(40, 40)):
result = np.empty(shape + (2,))
x, y = np.meshgrid(np.linspace(0, 2 * np.pi, shape[0]), np.linspace(0, 2 * np.pi, shape[1]))
result[..., 0] = np.cos(x + 0.1 * t) * np.sin(y + 0.1 * t) + 0.01 * x * y
result[..., 1] = np.cos(0.001 * y)
return result
def test_animation():
t = 0
def run_scalar():
nonlocal t
t += 1
return example_scalar_field(t)
def run_vec():
nonlocal t
t += 1
return example_vector_field(t)
plt.clf()
plt.cla()
with TemporaryDirectory() as tmp_dir:
ani = plt.vector_field_magnitude_animation(run_vec, interval=1, frames=2)
ani.save(os.path.join(tmp_dir, "animation1.avi"))
ani = plt.vector_field_animation(run_vec, interval=1, frames=2, rescale=True)
ani.save(os.path.join(tmp_dir, "animation2.avi"))
ani = plt.vector_field_animation(run_vec, interval=1, frames=2, rescale=False)
ani.save(os.path.join(tmp_dir, "animation3.avi"))
ani = plt.scalar_field_animation(run_scalar, interval=1, frames=2, rescale=True)
ani.save(os.path.join(tmp_dir, "animation4.avi"))
ani = plt.scalar_field_animation(run_scalar, interval=1, frames=2, rescale=False)
ani.save(os.path.join(tmp_dir, "animation5.avi"))
ani = plt.surface_plot_animation(run_scalar, frames=2)
ani.save(os.path.join(tmp_dir, "animation6.avi"))
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