27 description="test data",
30 patches: list of (patch_id, offset, size)
31 metadata_kind: "cell" or "vertex"
35 "# Peano patch file ",
39 f
"dimensions {dimensions}",
41 f
'begin {metadata_kind}-metadata "{name}"',
42 f
" number-of-unknowns {unknowns}",
43 f
" number-of-dofs-per-axis {dof}",
44 f
" description {description}",
46 if mapping
is not None:
47 lines.append(
" mapping " +
" ".join(str(x)
for x
in mapping))
48 lines.append(f
"end {metadata_kind}-metadata")
50 for patch_id, offset, size
in patches:
53 " offset " +
" ".join(str(x)
for x
in offset),
54 " size " +
" ".join(str(x)
for x
in size),
55 f
' begin {metadata_kind}-values "{name}"',
58 str(100 * patch_id + 10 * k + u)
59 for k
in range(dof**dimensions)
60 for u
in range(unknowns)
62 f
" end {metadata_kind}-values",
66 return "\n".join(lines) +
"\n"
71 snapshots: list of (timestamp, [file names])
73 lines = [
"# ",
"# Peano patch file ",
"# Version 0.2 ",
"# ",
"format ASCII",
""]
74 for timestamp, file_names
in snapshots:
75 lines += [
"begin dataset", f
" timestamp {timestamp:e}",
""]
76 lines += [f
' include "{file_name}"' for file_name
in file_names]
77 lines += [
"end dataset",
""]
78 return "\n".join(lines) +
"\n"
82 with open(file_name)
as f:
83 rows = list(csv.reader(f))
84 return rows[0], [[float(x)
for x
in row]
for row
in rows[1:]]
88 monkeypatch.chdir(tmp_path)
89 (tmp_path /
"data.peano-patch-file").write_text(content)
90 probe =
PointProbe(
"data.peano-patch-file", point,
"probe.csv", 0, 0)
91 probe.display_single_file()
99TWO_PATCHES_2D = [(1, (0.0, 0.0), (0.5, 0.5)), (2, (0.5, 0.0), (0.5, 0.5))]
103 content = patch_file(2,
"cell",
"Q", 3, 2, TWO_PATCHES_2D)
106 assert header == [
"time",
"Q_0",
"Q_1"]
107 assert rows == [[0.0, 270.0, 271.0]]
111 content = patch_file(2,
"cell",
"Q", 3, 1, TWO_PATCHES_2D)
114 assert rows == [[0.0, 200.0]]
118 content = patch_file(2,
"cell",
"Q", 3, 1, TWO_PATCHES_2D)
121 assert rows == [[0.0, 280.0]]
125 patches = [(1, (0.0, 0.0), (1.0, 1.0)), (2, (0.0, 0.0), (0.5, 0.5))]
126 content = patch_file(2,
"cell",
"Q", 2, 1, patches)
128 assert rows == [[0.0, 210.0]]
132 patches = [(1, (0.0, 0.0, 0.0), (1.0, 1.0, 1.0))]
133 content = patch_file(3,
"cell",
"Q", 2, 1, patches)
136 assert rows == [[0.0, 150.0]]
140 content = patch_file(2,
"cell",
"Q", 3, 1, TWO_PATCHES_2D)
142 assert rows == [[0.0, 270.0]]
147 axis = [0.0, 0.1, 1.0]
148 mapping = [c
for y
in axis
for x
in axis
for c
in (x, y)]
149 patches = [(1, (0.0, 0.0), (1.0, 1.0))]
150 content = patch_file(2,
"vertex",
"u", 3, 1, patches, mapping)
153 assert rows == [[0.0, 170.0]]
157 content = patch_file(2,
"cell",
"Q", 3, 1, TWO_PATCHES_2D)
159 assert rows[0][0] == 0.0
and math.isnan(rows[0][1])
163 mapping = [0.0, 0.0, 0.7, 0.0, 0.0, 1.0, 1.0, 1.0]
164 patches = [(1, (0.0, 0.0), (1.0, 1.0))]
165 content = patch_file(2,
"cell",
"Q", 1, 1, patches, mapping)
166 with pytest.raises(Exception, match=
"non-default mapping"):
171 monkeypatch.chdir(tmp_path)
173 for snapshot
in range(2):
174 for rank, (patch_id, offset, size)
in enumerate(TWO_PATCHES_2D):
175 (tmp_path / f
"s{snapshot}-r{rank}.peano-patch-file").write_text(
177 2,
"cell",
"Q", 3, 1, [(patch_id + 10 * snapshot, offset, size)]
181 (tmp_path /
"data.peano-patch-file").write_text(
184 (0.5, [
"s1-r0.peano-patch-file",
"s1-r1.peano-patch-file"]),
185 (0.0, [
"s0-r0.peano-patch-file",
"s0-r1.peano-patch-file"]),
189 probe =
PointProbe(
"data.peano-patch-file", (0.75, 0.45),
"probe.csv", 0, 10)
191 header, rows =
read_csv(
"probe.csv")
192 assert header == [
"time",
"Q_0"]
193 assert rows == [[0.0, 270.0], [0.5, 1270.0]]
199 monkeypatch.chdir(tmp_path)
200 output = tmp_path /
"output"
202 for snapshot
in range(2):
203 (output / f
"s{snapshot}.peano-patch-file").write_text(
204 patch_file(2,
"cell",
"Q", 3, 1, [(10 * snapshot, (0.0, 0.0), (1.0, 1.0))])
206 (output /
"data.peano-patch-file").write_text(
207 meta_file([(0.0, [
"./s0.peano-patch-file"]), (0.5, [
"s1.peano-patch-file"])])
210 os.path.join(
"output",
"data.peano-patch-file"), (0.5, 0.5),
"probe.csv", 0, 10
214 assert [row[0]
for row
in rows] == [0.0, 0.5]
215 assert rows[0][1] != rows[1][1]
219 content = patch_file(2,
"cell",
"Q", 3, 2, TWO_PATCHES_2D, description=
"h, hu")
221 assert header == [
"time",
"h",
"hu"]
222 assert rows == [[0.0, 270.0, 271.0]]
226 monkeypatch.chdir(tmp_path)
227 for name, (patch_id, offset, size)
in zip([
"A",
"B"], TWO_PATCHES_2D):
228 (tmp_path / f
"{name}.peano-patch-file").write_text(
230 2,
"cell", name, 3, 1, [(1, (0.0, 0.0), (1.0, 1.0))], description=
"h"
233 (tmp_path /
"data.peano-patch-file").write_text(
234 meta_file([(0.0, [
"A.peano-patch-file",
"B.peano-patch-file"])])
236 probe =
PointProbe(
"data.peano-patch-file", (0.5, 0.5),
"probe.csv", 0, 10)
239 assert header == [
"time",
"A_h",
"B_h"]
243 content = patch_file(
244 2,
"cell",
"Q", 3, 1, TWO_PATCHES_2D + [(3, (0.0, 0.5), (0.5, 0.5))]
246 (tmp_path /
"data.peano-patch-file").write_text(content)
248 str(tmp_path /
"data.peano-patch-file"),
255 patches = parser.unknown_attributes[
"Q"].cell_data
256 assert [patch.offset
for patch
in patches] == [(0.5, 0.0)]
Probe the data within a Peano patch file at one point over time.
test_cell_data_2d_picks_right_cell(tmp_path, monkeypatch)
test_named_unknowns_become_column_names(tmp_path, monkeypatch)
test_adaptive_mesh_takes_finest_patch(tmp_path, monkeypatch)
test_meta_file_in_other_directory(tmp_path, monkeypatch)
probe_single_file(tmp_path, monkeypatch, content, point)
test_meta_file_with_partial_files_and_multiple_snapshots(tmp_path, monkeypatch)
meta_file(snapshots)
snapshots: list of (timestamp, [file names])
test_point_outside_domain_yields_nan(tmp_path, monkeypatch)
test_vertex_data_nearest_dof_with_mapping(tmp_path, monkeypatch)
test_cell_data_3d(tmp_path, monkeypatch)
test_same_names_in_two_data_sets_are_prefixed(tmp_path, monkeypatch)
test_point_on_domain_boundary_takes_lower_patch(tmp_path, monkeypatch)
test_point_on_face_takes_upper_patch(tmp_path, monkeypatch)
test_cell_data_with_non_default_mapping_is_rejected(tmp_path, monkeypatch)
test_2d_data_ignores_z(tmp_path, monkeypatch)
test_patch_filter_skips_patches(tmp_path)