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
44     plt.figure()
45     for i in range(-2, 3):
46         for j in range(-3, 4):
47             # j = i
48             add_rect(
49                 0.05 + i * box_size_x + shear_x * j,
50                 0.05 + j * box_size_y,
51                 box_size_x - 0.1,
52                 box_size_y - 0.1,
53             )
54
55             for part in parts:
56                 x, y, z = pav_func.f((part["x"], part["y"], 0.0), i, j, 0)
57
58                 plt.scatter(x, y, color=part["color"])
59     plt.title(f"Paving function: {pav_func_name}")
60     plt.xlabel("x")
61     plt.ylabel("y")
62
63     plt.figure()
64     for i in range(-2, 3):
65         for j in range(-3, 4):
66             add_rect(
67                 0.05 + i * box_size_x + shear_x * j,
68                 0.05 + j * box_size_y,
69                 box_size_x - 0.1,
70                 box_size_y - 0.1,
71             )
72
73             for part in parts:
74                 x, y, z = pav_func.f((part["x"], part["y"], 0.0), i, j, 0)
75
76                 x_2, y_2, z_2 = pav_func.f_inv((x, y, 0.0), i, j, 0)
77
78                 delta_x = x_2 - part["x"]
79                 delta_y = y_2 - part["y"]
80
81                 if abs(delta_x) > 1e-4 or abs(delta_y) > 1e-4:
82                     print("error")
83
84                 plt.scatter(x_2 + 0.1 * i, y_2 + 0.1 * j, color=part["color"])
85     plt.title(f"Paving function inverse: {pav_func_name}")
86     plt.xlabel("x")
87     plt.ylabel("y")

Testing the paving functions#

Periodic paving function

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

Periodic & reflective paving function

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

Fully reflective paving function

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

Periodic & reflective paving function with shear

130 plot_paving_function(
131     shamrock.math.paving_function_general_3d_shear_x(
132         (box_size_x, box_size_y, 0.0),
133         (box_size_x / 2.0, box_size_y / 2.0, 0.0),
134         False,
135         True,
136         True,
137         0.3,
138     ),
139     "reflective in x periodic in y with shear",
140     shear_x=0.3,
141 )
142
143 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.030 seconds)

Estimated memory usage: 71 MB

Gallery generated by Sphinx-Gallery