Skip to content

Commit

Permalink
fix ambiguous 1d/2d/3d dump parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleveland committed Jan 31, 2025
1 parent 637b718 commit 36b22f3
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 7 deletions.
12 changes: 12 additions & 0 deletions tests/example_1d_dump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
keys: time cell_id x y z density temperature pressure

time: 1.0

cell_id: 1 2 3 4
x: 1 2 3 4 5
y: 1 1 1 1 1
z: 1 1 1 1 1
density: 1.1 1.1 1.1 1.1 1.1
temperature: 3.1 3.1 3.1 3.1 3.1
pressure: 5.1 5.1 5.1 5.1 5.1

10 changes: 10 additions & 0 deletions tests/example_1d_dump_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
keys: time cell_id x y z density temperature pressure

time: 2.0

cell_id: 1 2 3 4 5
x: 1 2 3 4 5
density: 1.2 1.2 1.2 1.2 1.2
temperature: 3.2 3.2 3.2 3.2 3.2
pressure: 5.2 5.2 5.2 5.2 5.2

10 changes: 10 additions & 0 deletions tests/example_1d_dump_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
keys: time cell_id x y z density temperature pressure

time: 3.0

cell_id: 1 2 3 4 5
x: 1 2 3 4 5
density: 1.3 1.3 1.3 1.3 1.3
temperature: 3.3 3.3 3.3 3.3 3.3
pressure: 5.3 5.3 5.3 5.3 5.3

12 changes: 12 additions & 0 deletions tests/example_2d_dump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
keys: time cell_id x y z density temperature pressure

time: 1.0

cell_id: 1 2 3 4 5 6 7 8 9 10
x: 1 2 3 4 5 1 2 3 4 5
y: 1 1 1 1 1 2 2 2 2 2
z: 1 1 1 1 1 1 1 1 1 1
density: 1.1 1.1 1.1 1.1 1.1 2.1 2.1 2.1 2.1 2.1
temperature: 3.1 3.1 3.1 3.1 3.1 4.1 4.1 4.1 4.1 4.1
pressure: 5.1 5.1 5.1 5.1 5.1 6.1 6.1 6.1 6.1 6.1

11 changes: 11 additions & 0 deletions tests/example_2d_dump_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
keys: time cell_id x y z density temperature pressure

time: 2.0

cell_id: 1 2 3 4 5 6 7 8 9 10
x: 1 2 3 4 5 1 2 3 4 5
y: 1 1 1 1 1 2 2 2 2 2
density: 1.2 1.2 1.2 1.2 1.2 2.2 2.2 2.2 2.2 2.2
temperature: 3.2 3.2 3.2 3.2 3.2 4.2 4.2 4.2 4.2 4.2
pressure: 5.2 5.2 5.2 5.2 5.2 6.2 6.2 6.2 6.2 6.2

12 changes: 12 additions & 0 deletions tests/example_2d_dump_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
keys: time cell_id x y z density temperature pressure

time: 3.0

cell_id: 1 2 3 4 5 6 7 8 9 10
x: 1 2 3 4 5 1 2 3 4 5
y: 1 1 1 1 1 2 2 2 2 2
z: 1 1 1 1 1 1 1 1 1 1
density: 1.3 1.3 1.3 1.3 1.3 2.3 2.3 2.3 2.3 2.3
temperature: 3.3 3.3 3.3 3.3 3.3 4.3 4.3 4.3 4.3 4.3
pressure: 5.3 5.3 5.3 5.3 5.3 6.3 6.3 6.3 6.3 6.3

Binary file modified tests/gold_dumps.p
Binary file not shown.
Binary file modified tests/gold_line_data.p
Binary file not shown.
Binary file modified tests/gold_sub_dumps.p
Binary file not shown.
31 changes: 24 additions & 7 deletions tests/test_dump_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,32 +502,49 @@ def test_line_series(self):
# initialize my test dump parser
dump_parser = my_test_opppy_dump_parser()

data = []
data3d = []
filename = dir_path + "example_dump.txt"
# extract all data from the example dump file
data.append(dump_parser.build_data_dictionary(filename))
data3d.append(dump_parser.build_data_dictionary(filename))
filename = dir_path + "example_dump2.txt"
data.append(dump_parser.build_data_dictionary(filename))
data3d.append(dump_parser.build_data_dictionary(filename))
filename = dir_path + "example_dump3.txt"
data.append(dump_parser.build_data_dictionary(filename))
data3d.append(dump_parser.build_data_dictionary(filename))
data2d = []
filename = dir_path + "example_2d_dump.txt"
# extract all data from the example dump file
data2d.append(dump_parser.build_data_dictionary(filename))
filename = dir_path + "example_2d_dump_2.txt"
data2d.append(dump_parser.build_data_dictionary(filename))
filename = dir_path + "example_2d_dump_3.txt"
data2d.append(dump_parser.build_data_dictionary(filename))
data1d = []
filename = dir_path + "example_1d_dump.txt"
# extract all data from the example dump file
data1d.append(dump_parser.build_data_dictionary(filename))
filename = dir_path + "example_1d_dump_2.txt"
data1d.append(dump_parser.build_data_dictionary(filename))
filename = dir_path + "example_1d_dump_3.txt"
data1d.append(dump_parser.build_data_dictionary(filename))


check_data = {}
# extract a 1D data value
tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x'], [1.0], [5.0], npts=5 )
tracer_t, tracer_grid = extract_series_line(data1d,'time',"temperature",['x'], [1.0], [5.0], npts=5 )
check_data['time1'] = np.array([t[0] for t in tracer_t['time']])
for i in range(len(check_data['time1'])):
check_data['temperature1'+str(i)] = tracer_grid[i]['temperature']
check_data['x1'+str(i)] = tracer_grid[i]['distance']

print(tracer_t, tracer_grid)
tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x','y'], [5.0, 1.0], [5.0, 2.0], npts=5 )
tracer_t, tracer_grid = extract_series_line(data2d,'time',"temperature",['x','y'], [5.0, 1.0], [5.0, 2.0], npts=5 )
check_data['time2'] = np.array([t[0] for t in tracer_t['time']])
for i in range(len(check_data['time2'])):
check_data['temperature2'+str(i)] = tracer_grid[i]['temperature']
check_data['x2'+str(i)] = tracer_grid[i]['distance']

print(tracer_t, tracer_grid)
tracer_t, tracer_grid = extract_series_line(data,'time',"temperature",['x','y','z'], [5.0, 1.0, 1.2], [5.0, 2.0, 1.75], npts=5 )
tracer_t, tracer_grid = extract_series_line(data3d,'time',"temperature",['x','y','z'], [5.0, 1.0, 1.2], [5.0, 2.0, 1.75], npts=5 )
check_data['time3'] = np.array([t[0] for t in tracer_t['time']])
for i in range(len(check_data['time3'])):
check_data['temperature3'+str(i)] = tracer_grid[i]['temperature']
Expand Down

0 comments on commit 36b22f3

Please sign in to comment.