Skip to content

Commit fc8f5c2

Browse files
committed
Fix for reading in times of slices
1 parent 3deee21 commit fc8f5c2

2 files changed

Lines changed: 24 additions & 21 deletions

File tree

fdsreader/simulation.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def __init__(self, path: str):
175175
self.geom_data = GeometryCollection(self._geom_data)
176176
self.slices = SliceCollection(
177177
Slice(self.root_path, slice_data[0]["id"], slice_data[0]["cell_centered"],
178-
slice_data[0]["times"], slice_data[1:]) for slice_data in self._slices.values())
178+
slice_data[1:]) for slice_data in self._slices.values())
179179
self.geomslices = GeomSliceCollection(
180180
GeomSlice(self.root_path, slice_data[0]["id"],
181181
slice_data[0]["times"], slice_data[1:]) for slice_data in self._geomslices.values())
@@ -553,20 +553,9 @@ def _load_slice(self, smv_file: TextIO, line: str):
553553
short_name = smv_file.readline().strip()
554554
unit = smv_file.readline().strip()
555555

556-
file_path = os.path.join(self.root_path, filename)
557-
558-
if os.path.exists(file_path + ".bnd"):
559-
times = list()
560-
with open(file_path + ".bnd", 'r') as bnd_file:
561-
for line in bnd_file:
562-
times.append(float(line.split()[0]))
563-
times = np.array(times)
564-
else:
565-
times = None
566-
567556
if slice_index not in self._slices:
568557
self._slices[slice_index] = [
569-
{"cell_centered": cell_centered, "times": times, "id": slice_id}]
558+
{"cell_centered": cell_centered, "id": slice_id}]
570559
self._slices[slice_index].append(
571560
{"dimension": dimension, "extent": extent, "mesh": mesh, "filename": filename,
572561
"quantity": quantity, "short_name": short_name, "unit": unit})

fdsreader/slcf/slice.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ def _load_data(self, file_path: str, data_out: np.ndarray):
127127
else:
128128
data_out[t, :] = data
129129

130+
def _load_times(self) -> np.ndarray:
131+
# Read in (only) the times for which SLCF data is available
132+
n = self.dimension.size(cell_centered=False)
133+
dtype_data = fdtype.combine(fdtype.FLOAT, fdtype.new((('f', n),)))
134+
135+
file_path = os.path.join(self._parent_slice._root_path, self.filename)
136+
137+
n_t = (os.stat(file_path).st_size - self._offset) // dtype_data.itemsize
138+
times = np.empty(n_t)
139+
140+
with open(file_path, 'rb') as infile:
141+
infile.seek(self._offset)
142+
for t, data in enumerate(fdtype.read(infile, dtype_data, n_t)):
143+
times[t] = data[0][0]
144+
145+
return times
146+
130147
@property
131148
def data(self) -> np.ndarray:
132149
"""Method to lazy load the slice's data.
@@ -189,18 +206,11 @@ class Slice(np.lib.mixins.NDArrayOperatorsMixin):
189206
:ivar extent: :class:`Extent` object containing 3-dimensional extent information.
190207
"""
191208

192-
def __init__(self, root_path: str, slice_id: str, cell_centered: bool, times: np.ndarray,
209+
def __init__(self, root_path: str, slice_id: str, cell_centered: bool,
193210
multimesh_data: Collection[Dict]):
194211
self._root_path = root_path
195212
self.cell_centered = cell_centered
196213

197-
self.times = times
198-
199-
if times is not None:
200-
self.n_t = times.size
201-
else:
202-
self.n_t = -1
203-
204214
self.id = slice_id
205215

206216
# List of all subslices this slice consists of (one per mesh).
@@ -262,6 +272,10 @@ def __init__(self, root_path: str, slice_id: str, cell_centered: bool, times: np
262272
y_start, y_start if self.orientation == 2 else y_end,
263273
z_start, z_start if self.orientation == 3 else z_end)
264274

275+
# Read in the available time steps, using arbitrary the first sub-slice
276+
self.times = self.subslices[0]._load_times()
277+
self.n_t = len(self.times)
278+
265279
# If lazy loading has been disabled by the user, load the data instantaneously instead
266280
if not settings.LAZY_LOAD:
267281
for _, subslice in self._subslices.items():

0 commit comments

Comments
 (0)