Paving functions#

This simple example shows how paving functions in Shamrock works

 9 import matplotlib.pyplot as plt
10 import numpy as np
11
12 import shamrock

Set box size

18 box_size_x = 2.0
19 box_size_y = 2.0

Particle set

24 parts = [
25     {"x": 0.1 * box_size_x, "y": 0.1 * box_size_y, "color": "blue"},
26     {"x": 0.7 * box_size_x, "y": 0.1 * box_size_y, "color": "red"},
27     {"x": 0.1 * box_size_x, "y": 0.7 * box_size_y, "color": "green"},
28     {"x": 0.7 * box_size_x, "y": 0.7 * box_size_y, "color": "black"},
29 ]

Utility to plot the paving function

36 def add_rect(x, y, w, h):
37     plt.gca().add_patch(
38         plt.Rectangle((x, y), w, h, alpha=0.5, fill=True, facecolor="grey", linewidth=2)
39     )
40
41
42 def plot_paving_function(pav_func, pav_func_name, shear_x=0.0):
43     plt.figure()
44     for i in range(-2, 3):
45         for j in range(-3, 4):
46             # j = i
47             add_rect(
48                 0.05 + i * box_size_x + shear_x * j,
49                 0.05 + j * box_size_y,
50                 box_size_x - 0.1,
51                 box_size_y - 0.1,
52             )
53
54             for part in parts:
55                 x, y, z = pav_func.f((part["x"], part["y"], 0.0), i, j, 0)
56
57                 plt.scatter(x, y, color=part["color"])
58     plt.title(f"Paving function: {pav_func_name}")
59     plt.xlabel("x")
60     plt.ylabel("y")
61
62     plt.figure()
63     for i in range(-2, 3):
64         for j in range(-3, 4):
65             add_rect(
66                 0.05 + i * box_size_x + shear_x * j,
67                 0.05 + j * box_size_y,
68                 box_size_x - 0.1,
69                 box_size_y - 0.1,
70             )
71
72             for part in parts:
73                 x, y, z = pav_func.f((part["x"], part["y"], 0.0), i, j, 0)
74
75                 x_2, y_2, z_2 = pav_func.f_inv((x, y, 0.0), i, j, 0)
76
77                 delta_x = x_2 - part["x"]
78                 delta_y = y_2 - part["y"]
79
80                 if abs(delta_x) > 1e-4 or abs(delta_y) > 1e-4:
81                     print("error")
82
83                 plt.scatter(x_2 + 0.1 * i, y_2 + 0.1 * j, color=part["color"])
84     plt.title(f"Paving function inverse: {pav_func_name}")
85     plt.xlabel("x")
86     plt.ylabel("y")

Testing the paving functions#

Periodic paving function

 96 plot_paving_function(
 97     shamrock.math.paving_function_general_3d(
 98         (box_size_x, box_size_y, 0.0), (box_size_x / 2.0, box_size_y / 2.0, 0.0), True, True, True
 99     ),
100     "Periodic box",
101 )
  • Paving function: Periodic box
  • Paving function inverse: Periodic box

Periodic & reflective paving function

107 plot_paving_function(
108     shamrock.math.paving_function_general_3d(
109         (box_size_x, box_size_y, 0.0), (box_size_x / 2.0, box_size_y / 2.0, 0.0), False, True, True
110     ),
111     "reflective in x periodic in y",
112 )
  • Paving function: reflective in x periodic in y
  • Paving function inverse: reflective in x periodic in y

Fully reflective paving function

118 plot_paving_function(
119     shamrock.math.paving_function_general_3d(
120         (box_size_x, box_size_y, 0.0), (box_size_x / 2.0, box_size_y / 2.0, 0.0), False, False, True
121     ),
122     "Fully reflective",
123 )
  • Paving function: Fully reflective
  • Paving function inverse: Fully reflective

Periodic & reflective paving function with shear

129 plot_paving_function(
130     shamrock.math.paving_function_general_3d_shear_x(
131         (box_size_x, box_size_y, 0.0),
132         (box_size_x / 2.0, box_size_y / 2.0, 0.0),
133         False,
134         True,
135         True,
136         0.3,
137     ),
138     "reflective in x periodic in y with shear",
139     shear_x=0.3,
140 )
141
142 plt.show()
  • Paving function: reflective in x periodic in y with shear
  • Paving function inverse: reflective in x periodic in y with shear

Total running time of the script: (0 minutes 5.402 seconds)

Estimated memory usage: 160 MB

Gallery generated by Sphinx-Gallery