Skip to content

Commit 26fbc28

Browse files
author
Jan Vogelsang
committed
Increment version number
1 parent 974140c commit 26fbc28

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

RELEASE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## Release History
2+
* 1.8.2
3+
* Added option to mask global slice and fixed csv and slice mask bugs
24
* 1.8.1
35
* Lots of improvements and convenience methods for obstructions
46
* 1.8.0

fdsreader/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
from incremental import Version
99

10-
__version__ = Version("fdsreader", 1, 8, 1)
10+
__version__ = Version("fdsreader", 1, 8, 2)
1111
__all__ = ["__version__"]

fdsreader/bndf/obstruction.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import math
22
import os
3-
from typing import List, Dict, Tuple, Union
3+
from typing import List, Dict, Tuple, Union, Sequence
44
from typing_extensions import Literal
55
import numpy as np
66

@@ -122,7 +122,7 @@ class Boundary:
122122
:ivar n_t: Total number of time steps for which output data has been written.
123123
"""
124124

125-
def __init__(self, quantity: Quantity, cell_centered: bool, times: np.ndarray, n_t: int, patches: List[Patch],
125+
def __init__(self, quantity: Quantity, cell_centered: bool, times: Sequence[float], n_t: int, patches: List[Patch],
126126
lower_bounds: np.ndarray, upper_bounds: np.ndarray):
127127
self.quantity = quantity
128128
self.cell_centered = cell_centered
@@ -215,7 +215,7 @@ def __init__(self, side_surfaces: Tuple, bound_indices: Tuple[int, int, int, int
215215
self.show_times = list()
216216

217217
def _add_patches(self, bid: int, cell_centered: bool, quantity: str, short_name: str, unit: str,
218-
patches: List[Patch], times: np.ndarray, n_t: int, lower_bounds: np.ndarray,
218+
patches: List[Patch], times: Sequence[float], n_t: int, lower_bounds: np.ndarray,
219219
upper_bounds: np.ndarray):
220220
if bid not in self._boundary_data:
221221
self._boundary_data[bid] = Boundary(Quantity(quantity, short_name, unit), cell_centered, times, n_t,
@@ -276,20 +276,28 @@ def _show(self, time: float):
276276

277277
@property
278278
def n_t(self):
279-
return next(iter(self._boundary_data.values())).n_t
279+
"""Returns the number of timesteps for which boundary data is available.
280+
"""
281+
if self.has_boundary_data:
282+
return next(iter(self._boundary_data.values())).n_t
283+
else:
284+
return 0
280285

281286
@property
282287
def times(self):
283-
return next(iter(self._boundary_data.values())).times
288+
"""Return all timesteps for which boundary data is available, if any.
289+
"""
290+
if self.has_boundary_data:
291+
return next(iter(self._boundary_data.values())).times
292+
else:
293+
return np.array([])
284294

285-
@property
286-
def visible_times(self) -> np.ndarray:
287-
"""Returns an ndarray containing all time steps when there is data available for the SubObstruction. Will return an
288-
empty list when no data is output at all.
295+
def get_visible_times(self, times: Sequence[float]) -> np.ndarray:
296+
"""Returns an ndarray filtering all time steps when theSubObstruction is visible/not hidden.
289297
"""
290298
ret = list()
291299
hidden = False
292-
for time in self.times:
300+
for time in times:
293301
if time in self.show_times:
294302
hidden = False
295303
if time in self.hide_times:
@@ -375,15 +383,20 @@ def orientations(self):
375383

376384
@property
377385
def n_t(self):
386+
"""Returns the number of timesteps for which boundary data is available.
387+
"""
378388
return next(iter(self._subobstructions.values())).n_t
379389

380390
@property
381391
def times(self):
392+
"""Return all timesteps for which boundary data is available, if any.
393+
"""
382394
return next(iter(self._subobstructions.values())).times
383395

384-
@property
385-
def visible_times(self):
386-
return next(iter(self._subobstructions.values())).visible_times
396+
def get_visible_times(self, times: Sequence[float]):
397+
"""Returns an ndarray filtering all time steps when theSubObstruction is visible/not hidden.
398+
"""
399+
return next(iter(self._subobstructions.values())).get_visible_times(times)
387400

388401
def get_coordinates(self, ignore_cell_centered: bool = False) -> Dict[
389402
int, Dict[Literal['x', 'y', 'z'], np.ndarray]]:
@@ -489,7 +502,7 @@ def get_boundary_data(self, quantity: Union[Quantity, str],
489502
def get_nearest_timestep(self, time: float, visible_only: bool = False) -> int:
490503
"""Calculates the nearest timestep for which data has been output for this obstruction.
491504
"""
492-
times = self.visible_times if visible_only else self.times
505+
times = self.get_visible_times(self.times) if visible_only else self.times
493506
idx = np.searchsorted(times, time, side="left")
494507
if time > 0 and (idx == len(times) or np.math.fabs(
495508
time - times[idx - 1]) < np.math.fabs(time - times[idx])):

fdsreader/fds_classes/mesh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ def get_obstruction_mask(self, times: Sequence[float], cell_centered=False) -> n
5757
x1, x2 = subobst.bound_indices['x']
5858
y1, y2 = subobst.bound_indices['y']
5959
z1, z2 = subobst.bound_indices['z']
60-
for t, _ in enumerate(subobst.visible_times(times)):
60+
for t, _ in enumerate(subobst.get_visible_times(times)):
6161
mask[t, x1:max(x2 + c, x1 + 1), y1:max(y2 + c, y1 + 1), z1:max(z2 + c, z1 + 1)] = False
6262
return mask
6363

6464
def get_obstruction_mask_slice(self, subslice):
65-
"""Marks all cells of a single slice which are blocked by an obstruction.
65+
"""Marks all cells of a single subslice which are blocked by an obstruction.
6666
6767
:returns: A 4-dimensional array with time as first and x,y,z as last dimensions. The array depends on time as
6868
obstructions may be hidden as specific points in time.
@@ -77,7 +77,7 @@ def get_obstruction_mask_slice(self, subslice):
7777
mask_indices[orientation] = slice(slc_index, slc_index + 1, 1)
7878
mask_indices = tuple(mask_indices)
7979

80-
return np.squeeze(self.get_obstruction_mask(subslice.times, cell_centered=cell_centered)[mask_indices])
80+
return self.get_obstruction_mask(subslice.times, cell_centered=cell_centered)[mask_indices]
8181

8282
def coordinate_to_index(self, coordinate: Tuple[float, ...],
8383
dimension: Tuple[Literal[1, 2, 3, 'x', 'y', 'z'], ...] = ('x', 'y', 'z'),

fdsreader/simulation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,8 @@ def _load_CPU_data(self) -> Dict[str, np.ndarray]:
995995
with open(file_path, 'r') as infile:
996996
keys = [name.replace('"', '').replace('\n', '').strip() for name in infile.readline().split(',')]
997997
values = np.loadtxt(file_path, delimiter=',', ndmin=2, skiprows=1)
998+
else:
999+
return dict()
9981000
data = self._transform_csv_data(keys, values)
9991001
data["Rank"] = data["Rank"].astype(int)
10001002
return data

fdsreader/slcf/slice.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,14 @@ def sort_subslices_cartesian(self):
471471
slices_cart.append([slc])
472472
return slices_cart
473473

474-
def to_global(self) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
474+
def to_global(self, masked: bool = False, fill: float = 0) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
475475
"""Creates a global numpy ndarray from all subslices (only tested for 2D-slices).
476476
Note: This method might create a sparse np-array that consumes lots of memory.
477+
Will create two global slices in cases where face-centered slices cut right through one
478+
or more mesh borders.
479+
480+
:param masked: Whether to apply the obstruction mask to the slice or not.
481+
:param fill: The fill value to use for masked slice entries. Only used when masked=True.
477482
"""
478483
subslice_sets = [dict(), dict()]
479484

@@ -564,6 +569,10 @@ def to_global(self) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
564569
if not self.cell_centered and mesh.coordinates[dim][-1] == global_max[dim]:
565570
slc_data = np.concatenate((slc_data, temp_data), axis=axis + 1)
566571

572+
if masked:
573+
mask = mesh.get_obstruction_mask_slice(slc)
574+
slc_data = np.where(mask, slc_data, fill)
575+
567576
grid[:, start_idx['x']: end_idx['x'], start_idx['y']: end_idx['y'],
568577
start_idx['z']: end_idx['z']] = slc_data.reshape(
569578
(self.n_t, end_idx['x'] - start_idx['x'], end_idx['y'] - start_idx['y'], end_idx['z'] - start_idx['z']))

0 commit comments

Comments
 (0)