Skip to content

Commit

Permalink
support Single Precision OpenFOAM output
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrilleBonamy committed Apr 16, 2024
1 parent 25b70fd commit d29cd2d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ What is this repository for?
----------------------------

* Openfoam Tools
* Version : 0.2.5
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2212plus
* Version : 0.2.6
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2312plus
* Supported Python Versions : >= 3.8

Documentation and Examples
Expand Down
4 changes: 2 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ What is this repository for?
----------------------------

* Openfoam Tools
* Version : 0.2.5
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2212plus
* Version : 0.2.6
* Supported OpenFoam Versions : 2.4.0, 4.1 to 9, v1712plus to v2312plus
* Supported Python Versions : >= 3.8

Deployment instructions
Expand Down
2 changes: 1 addition & 1 deletion fluidfoam/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
'a' or 'alpha' means alpha version (internal testing),
'b' or 'beta' means beta version (external testing).
"""
__version__ = "0.2.5"
__version__ = "0.2.6"
56 changes: 41 additions & 15 deletions fluidfoam/readof.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ def __init__(

try:
self.is_ascii = self.header[b"format"] == b"ascii"
self.is_SP = b"scalar=32" in self.header[b"arch"]
self.noheader = False
except KeyError:
self.is_ascii = True
self.is_SP = False
self.noheader = True

for line in self.lines_stripped:
Expand Down Expand Up @@ -289,12 +291,20 @@ def _parse_data(self, boundary, datatype, precision=15):
nb_numbers = 6 * nb_pts
elif self.type_data == "tensor":
nb_numbers = 9 * nb_pts
self.values = np.array(
struct.unpack(
"{}d".format(nb_numbers),
data[: nb_numbers * struct.calcsize("d")],
if self.is_SP:
self.values = np.array(
struct.unpack(
"{}f".format(nb_numbers),
data[: nb_numbers * struct.calcsize("f")],
)
)
else:
self.values = np.array(
struct.unpack(
"{}d".format(nb_numbers),
data[: nb_numbers * struct.calcsize("d")],
)
)
)
else:
if self.type_data == "scalar":
self.values = np.array(
Expand Down Expand Up @@ -386,12 +396,20 @@ def _nearest_data(self, boundary, precision):
nb_numbers = 6 * nb_pts
elif self.type_data == "tensor":
nb_numbers = 9 * nb_pts
values = np.array(
struct.unpack(
"{}d".format(nb_numbers),
data[: nb_numbers * struct.calcsize("d")],
if self.is_SP:
values = np.array(
struct.unpack(
"{}f".format(nb_numbers),
data[: nb_numbers * struct.calcsize("f")],
)
)
else:
values = np.array(
struct.unpack(
"{}d".format(nb_numbers),
data[: nb_numbers * struct.calcsize("d")],
)
)
)
else:
if self.type_data == "scalar":
values = np.array(
Expand Down Expand Up @@ -498,12 +516,20 @@ def _parse_points(self, precision):
if not self.is_ascii:
nb_numbers = 3 * self.nb_pts
data = b"\n(".join(data.split(b"\n(")[1:])
self.values = np.array(
struct.unpack(
"{}d".format(nb_numbers),
data[: nb_numbers * struct.calcsize("d")],
if self.is_SP:
self.values = np.array(
struct.unpack(
"{}f".format(nb_numbers),
data[: nb_numbers * struct.calcsize("f")],
)
)
else:
self.values = np.array(
struct.unpack(
"{}d".format(nb_numbers),
data[: nb_numbers * struct.calcsize("d")],
)
)
)
else:
lines = data.split(b"\n(")
lines = [line.split(b")")[0] for line in lines]
Expand Down

0 comments on commit d29cd2d

Please sign in to comment.