diff --git a/README.rst b/README.rst index 4c109da..49d5886 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/doc/index.rst b/doc/index.rst index 0e1e950..c250402 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -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 diff --git a/fluidfoam/_version.py b/fluidfoam/_version.py index e5b9f25..982f027 100644 --- a/fluidfoam/_version.py +++ b/fluidfoam/_version.py @@ -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" diff --git a/fluidfoam/readof.py b/fluidfoam/readof.py index b578c81..53adc01 100644 --- a/fluidfoam/readof.py +++ b/fluidfoam/readof.py @@ -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: @@ -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( @@ -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( @@ -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]