Peano
Loading...
Searching...
No Matches
probe-single-black-hole.py
Go to the documentation of this file.
1"""
2
3Extract a profile along a line from the checkpoints of the single black hole
4
5The checkpoints of single-black-hole.py are the snapshots of the patch file
6solution-CCZ4.peano-patch-file. The script samples one snapshot at points
7equidistantly distributed along a line from --start to --end with Peano's
8PointProbe and writes one csv file with the columns x, y, z, r (the distance
9to the puncture), followed by all unknowns found in the checkpoint. The
10default line is the x-axis shifted by half a volume in y and z, as the
11puncture itself sits on a volume face and the initial data is singular
12there.
13
14 python3 probe-single-black-hole.py --snapshot -1 --start -20 0.1 0.1 --end 20 0.1 0.1 --samples 400
15
16Peano's PointProbe takes the value of the volume or grid cell that contains
17the sampling point, i.e. it does not interpolate. It parses the patch files
18once per sampling point, so keep --samples moderate for large checkpoints.
19With --list, the script only prints the time stamps of the snapshots.
20
21"""
22
23import argparse
24import csv
25import math
26import os
27import sys
28import tempfile
29
31
32
34 parser = argparse.ArgumentParser(
35 description="Profile along a line through a single black hole checkpoint",
36 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
37 )
38 parser.add_argument(
39 "--directory",
40 default=".",
41 help="Directory holding the checkpoints, i.e. the output directory of single-black-hole.py.",
42 )
43 parser.add_argument(
44 "--file",
45 default="solution-CCZ4.peano-patch-file",
46 help="Meta file of the checkpoints within --directory.",
47 )
48 parser.add_argument(
49 "--snapshot",
50 type=int,
51 default=-1,
52 help="Index of the checkpoint (0 is the first one). Negative values count from the end, i.e. -1 is the latest checkpoint.",
53 )
54 parser.add_argument(
55 "--start",
56 type=float,
57 nargs=3,
58 default=[-20.0, 0.1, 0.1],
59 metavar=("X", "Y", "Z"),
60 help="Start of the line.",
61 )
62 parser.add_argument(
63 "--end",
64 type=float,
65 nargs=3,
66 default=[20.0, 0.1, 0.1],
67 metavar=("X", "Y", "Z"),
68 help="End of the line.",
69 )
70 parser.add_argument("--samples", type=int, default=200, help="Points along the line.")
71 parser.add_argument(
72 "--output",
73 default="profile.csv",
74 help="Name of the csv file with the profile.",
75 )
76 parser.add_argument(
77 "--list",
78 action="store_true",
79 help="Only list the time stamps of the checkpoints.",
80 )
81 arguments = parser.parse_args()
82 if arguments.samples < 2:
83 parser.error("--samples has to be at least 2")
84 return arguments
85
86
87def snapshot_range(arguments):
88 """! (start, end) of the PointProbe selecting the one snapshot requested"""
89 if arguments.snapshot < 0:
90 return arguments.snapshot, sys.maxsize
91 return arguments.snapshot, arguments.snapshot
92
93
94def list_snapshots(file_name):
96 file_name=file_name, point=[0.0, 0.0, 0.0], output_file=os.devnull, start=0, end=sys.maxsize
97 )
98 probe.read_metadata()
99 for i, snapshot in enumerate(probe.snapshots):
100 print(f"{i}: t={snapshot.timestamp}")
101
102
103def probe_line(arguments, file_name):
104 """!
105
106 Probe all sampling points and return the rows (x, y, z, r, time, unknowns...)
107 along with the header of the unknowns
108
109 """
110 start, end = snapshot_range(arguments)
111 rows = []
112 header = None
113 with tempfile.TemporaryDirectory() as scratch:
114 for i in range(arguments.samples):
115 lambda_ = i / (arguments.samples - 1)
116 point = [
117 a + lambda_ * (b - a) for a, b in zip(arguments.start, arguments.end)
118 ]
119 output = os.path.join(scratch, "probe.csv")
121 file_name=file_name, point=point, output_file=output, start=start, end=end
122 )
123 probe.display()
124 with open(output) as csv_file:
125 reader = csv.reader(csv_file)
126 header = next(reader)
127 values = next(reader)
128 rows.append(point + [math.sqrt(sum(x * x for x in point))] + values)
129 return ["x", "y", "z", "r"] + header, rows
130
131
132def main():
133 arguments = parse_arguments()
134 file_name = os.path.join(arguments.directory, arguments.file)
135 if arguments.list:
136 list_snapshots(file_name)
137 return
138
139 header, rows = probe_line(arguments, file_name)
140 with open(arguments.output, "w", newline="") as csv_file:
141 writer = csv.writer(csv_file)
142 writer.writerow(header)
143 writer.writerows(rows)
144 print(f"Wrote {len(rows)} sampling points (t={rows[0][4]}) into {arguments.output}")
145
146
147if __name__ == "__main__":
148 main()
Probe the data within a Peano patch file at one point over time.
Definition PointProbe.py:37
probe_line(arguments, file_name)
Probe all sampling points and return the rows (x, y, z, r, time, unknowns...) along with the header o...
snapshot_range(arguments)
(start, end) of the PointProbe selecting the one snapshot requested