Skip to content
Snippets Groups Projects
Select Git revision
  • 1ff42b84c567ccf513b30d45f10064e7f3b2a823
  • master default protected
  • v2.0-dev protected
  • zikeliml/Task-96-dotExporterForAST
  • zikeliml/124-rework-tutorials
  • fma
  • fhennig/v2.0-deprecations
  • holzer-master-patch-46757
  • 66-absolute-access-is-probably-not-copied-correctly-after-_eval_subs
  • gpu_bufferfield_fix
  • hyteg
  • vectorization_sqrt_fix
  • target_dh_refactoring
  • const_fix
  • improved_comm
  • gpu_liveness_opts
  • release/1.3.7 protected
  • release/1.3.6 protected
  • release/2.0.dev0 protected
  • release/1.3.5 protected
  • release/1.3.4 protected
  • release/1.3.3 protected
  • release/1.3.2 protected
  • release/1.3.1 protected
  • release/1.3 protected
  • release/1.2 protected
  • release/1.1.1 protected
  • release/1.1 protected
  • release/1.0.1 protected
  • release/1.0 protected
  • release/0.4.4 protected
  • last/Kerncraft
  • last/OpenCL
  • last/LLVM
  • release/0.4.3 protected
  • release/0.4.2 protected
36 results

test_vectorization_specific.py

Blame
  • test_plot.py 1.72 KiB
    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"))