From 28981a2338486e4d57c715b833585929cfe4d053 Mon Sep 17 00:00:00 2001 From: Anthony Marcozzi Date: Tue, 18 Jun 2024 09:32:33 -0600 Subject: [PATCH] Update reading initial boundary data from .bf instead of deprecated .bnd --- fdsreader/simulation.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/fdsreader/simulation.py b/fdsreader/simulation.py index fc896f4..2af62bb 100644 --- a/fdsreader/simulation.py +++ b/fdsreader/simulation.py @@ -630,27 +630,12 @@ def _load_boundary_data(self, smv_file: TextIO, line: str, cell_centered: bool): patches = dict() mesh_patches = dict() - if os.path.exists(file_path + ".bnd"): - times = list() - lower_bounds = list() - upper_bounds = list() - with open(file_path + ".bnd", 'r') as bnd_file: - for line in bnd_file: - splits = line.split() - times.append(float(splits[0])) - lower_bounds.append(float(splits[1])) - upper_bounds.append(float(splits[2])) - times = np.array(times) - lower_bounds = np.array(lower_bounds, dtype=np.float32) - upper_bounds = np.array(upper_bounds, dtype=np.float32) - n_t = times.shape[0] - else: - times = None - n_t = -1 - lower_bounds = np.array([0.0], dtype=np.float32) - upper_bounds = np.array([np.float32(-1e33)], dtype=np.float32) + lower_bounds = np.array([np.float32(1e32)], dtype=np.float32) + upper_bounds = np.array([np.float32(-1e33)], dtype=np.float32) + file_size_bytes = os.stat(file_path).st_size with open(file_path, 'rb') as infile: + # Offset of the binary file to the end of the file header. offset = 3 * fdtype.new((('c', 30),)).itemsize infile.seek(offset) @@ -662,6 +647,22 @@ def _load_boundary_data(self, smv_file: TextIO, line: str, cell_centered: bool): offset += fdtype.INT.itemsize + dtype_patches.itemsize * n_patches patch_offset = fdtype.FLOAT.itemsize + time_bytes = fdtype.FLOAT.itemsize + patch_data_bytes = 0 + for patch_info in patch_infos: + patch_info = patch_info[0] + extent, dimension = self._indices_to_extent(patch_info[:6], mesh) + patch_data_bytes += fdtype.new((('f', str(dimension.shape(cell_centered=False))),)).itemsize + + n_t = (file_size_bytes - offset) // (time_bytes + n_patches * patch_data_bytes) + + times = [] + for _ in range(n_t): + time = fdtype.read(infile, fdtype.FLOAT, 1)[0][0][0] + times.append(time) + offset += time_bytes + patch_data_bytes + infile.seek(offset) + for patch_info in patch_infos: patch_info = patch_info[0]