4Compare whether initial states and states after 1 loop through box are identical
14parser = argparse.ArgumentParser(
16 Compare whether the particles are at the correct position.
17 The assumption is that particles move with a constant velocity
18 across periodic boundaries.
25 help=
".pvd file to read in",
26 default=
"./particles.pvd",
33 help=
"Number of dimensions to work with",
41 help=
"What end time to read in",
50 help=
"Threshold for comparison tolerance",
58 help=
"Box size in all dimensions.",
61args = parser.parse_args()
64comparison_tolerance = args.tolerance
71partData_0 = reader_0.load()
74partData_1 = reader_1.load()
76actual_end_time = reader_1.get_snapshot_time()
78coords_0 = partData_0.x[:, :ndim]
79vels_0 = partData_0.v[:, :ndim]
80ids_0 = partData_0.partid
81sort0 = np.argsort(ids_0)
82coords_0 = coords_0[sort0]
86coords_expect = coords_0 + actual_end_time * vels_0
87for dim
in range(ndim):
88 mask = coords_expect[:, dim] > boxsize
90 coords_expect[mask, dim] -= boxsize
91 mask = coords_expect[:, dim] > boxsize
93 mask = coords_expect[:, dim] < 0.0
95 coords_expect[mask, dim] += boxsize
96 mask = coords_expect[:, dim] < 0.0
99coords_1 = partData_1.x[:, :ndim]
100ids_1 = partData_1.partid
101sort1 = np.argsort(ids_1)
102coords_1 = coords_1[sort1]
106if coords_0.shape != coords_1.shape:
107 print(
"Error: coordinate arrays are not of equal length.")
108 print(
" coords_0.shape", coords_0.shape)
109 print(
" coords_1.shape", coords_1.shape)
115for i
in range(ids_0.shape[0]):
116 for n
in range(ndim):
117 diff = coords_expect[i, n] / coords_1[i, n] - 1.0
118 if abs(diff) > comparison_tolerance:
119 print(
"Error: Coordinates disagree.")
120 print(
" Particle ID: ", ids_0[i], ids_1[i])
121 print(
" Dimension: ", n)
122 print(
" Diff: ", diff)
123 print(
" Coords_0: ", coords_0[i])
124 print(
" Coords_1: ", coords_1[i])
125 print(
" Coords expect: ", coords_expect[i])
126 print(
"----------------------------")
129print(
"Finished with", errors,
"errors.")
Reads in particle fields from a single .vtu file, or all .vtu at a given snapshot time specified in t...