Skip to content

Commit 7cf968d

Browse files
committed
Fix for reading BNDF times
1 parent fc8f5c2 commit 7cf968d

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

fdsreader/simulation.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -619,25 +619,8 @@ def _load_boundary_data(self, smv_file: TextIO, line: str, cell_centered: bool):
619619
patches = dict()
620620
mesh_patches = dict()
621621

622-
if os.path.exists(file_path + ".bnd"):
623-
times = list()
624-
lower_bounds = list()
625-
upper_bounds = list()
626-
with open(file_path + ".bnd", 'r') as bnd_file:
627-
for line in bnd_file:
628-
splits = line.split()
629-
times.append(float(splits[0]))
630-
lower_bounds.append(float(splits[1]))
631-
upper_bounds.append(float(splits[2]))
632-
times = np.array(times)
633-
lower_bounds = np.array(lower_bounds, dtype=np.float32)
634-
upper_bounds = np.array(upper_bounds, dtype=np.float32)
635-
n_t = times.shape[0]
636-
else:
637-
times = None
638-
n_t = -1
639-
lower_bounds = np.array([0.0], dtype=np.float32)
640-
upper_bounds = np.array([np.float32(-1e33)], dtype=np.float32)
622+
lower_bounds = np.array([np.float32(+1e33)], dtype=np.float32)
623+
upper_bounds = np.array([np.float32(-1e33)], dtype=np.float32)
641624

642625
with open(file_path, 'rb') as infile:
643626
# Offset of the binary file to the end of the file header.
@@ -651,6 +634,24 @@ def _load_boundary_data(self, smv_file: TextIO, line: str, cell_centered: bool):
651634
offset += fdtype.INT.itemsize + dtype_patches.itemsize * n_patches
652635
patch_offset = fdtype.FLOAT.itemsize
653636

637+
# Determine the size of the data block for all patches
638+
patches_data_bytes = 0
639+
for patch_info in patch_infos:
640+
patch_info = patch_info[0]
641+
extent, dimension = self._indices_to_extent(patch_info[:6], mesh)
642+
patches_data_bytes += fdtype.new((('f', str(dimension.shape(cell_centered=False))),)).itemsize
643+
644+
# Time info
645+
time_bytes = fdtype.FLOAT.itemsize
646+
n_t = (os.stat(file_path).st_size - offset) // (time_bytes + patches_data_bytes)
647+
648+
times = list()
649+
for _ in range(n_t):
650+
time = fdtype.read(infile, fdtype.FLOAT, 1)[0][0][0]
651+
times.append(time)
652+
offset += time_bytes + patches_data_bytes
653+
infile.seek(offset)
654+
654655
for patch_info in patch_infos:
655656
patch_info = patch_info[0]
656657

0 commit comments

Comments
 (0)