foamlib 0.3.17__py3-none-any.whl → 0.3.19__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- foamlib/__init__.py +1 -1
- foamlib/_files/_files.py +133 -33
- {foamlib-0.3.17.dist-info → foamlib-0.3.19.dist-info}/METADATA +1 -1
- {foamlib-0.3.17.dist-info → foamlib-0.3.19.dist-info}/RECORD +7 -7
- {foamlib-0.3.17.dist-info → foamlib-0.3.19.dist-info}/WHEEL +1 -1
- {foamlib-0.3.17.dist-info → foamlib-0.3.19.dist-info}/LICENSE.txt +0 -0
- {foamlib-0.3.17.dist-info → foamlib-0.3.19.dist-info}/top_level.txt +0 -0
foamlib/__init__.py
CHANGED
foamlib/_files/_files.py
CHANGED
@@ -6,6 +6,7 @@ if sys.version_info >= (3, 9):
|
|
6
6
|
else:
|
7
7
|
from typing import Iterator, Mapping, MutableMapping, Sequence
|
8
8
|
|
9
|
+
from .._util import is_sequence
|
9
10
|
from ._base import FoamDict
|
10
11
|
from ._io import FoamFileIO
|
11
12
|
from ._serialization import Kind, dumpb
|
@@ -24,7 +25,7 @@ class FoamFile(
|
|
24
25
|
FoamFileIO,
|
25
26
|
):
|
26
27
|
"""
|
27
|
-
An OpenFOAM
|
28
|
+
An OpenFOAM data file.
|
28
29
|
|
29
30
|
Use as a mutable mapping (i.e., like a dict) to access and modify entries.
|
30
31
|
|
@@ -88,6 +89,78 @@ class FoamFile(
|
|
88
89
|
|
89
90
|
return ret
|
90
91
|
|
92
|
+
class Header(SubDict):
|
93
|
+
"""The header of an OpenFOAM file."""
|
94
|
+
|
95
|
+
@property
|
96
|
+
def version(self) -> float:
|
97
|
+
"""Alias of `self["version"]`."""
|
98
|
+
ret = self["version"]
|
99
|
+
if not isinstance(ret, float):
|
100
|
+
raise TypeError("version is not a float")
|
101
|
+
return ret
|
102
|
+
|
103
|
+
@version.setter
|
104
|
+
def version(self, data: float) -> None:
|
105
|
+
self["version"] = data
|
106
|
+
|
107
|
+
@property
|
108
|
+
def format(self) -> str:
|
109
|
+
"""Alias of `self["format"]`."""
|
110
|
+
ret = self["format"]
|
111
|
+
if not isinstance(ret, str):
|
112
|
+
raise TypeError("format is not a string")
|
113
|
+
return ret
|
114
|
+
|
115
|
+
@format.setter
|
116
|
+
def format(self, data: str) -> None:
|
117
|
+
self["format"] = data
|
118
|
+
|
119
|
+
@property
|
120
|
+
def class_(self) -> str:
|
121
|
+
"""Alias of `self["class"]`."""
|
122
|
+
ret = self["class"]
|
123
|
+
if not isinstance(ret, str):
|
124
|
+
raise TypeError("class is not a string")
|
125
|
+
return ret
|
126
|
+
|
127
|
+
@class_.setter
|
128
|
+
def class_(self, data: str) -> None:
|
129
|
+
self["class"] = data
|
130
|
+
|
131
|
+
@property
|
132
|
+
def location(self) -> str:
|
133
|
+
"""Alias of `self["location"]`."""
|
134
|
+
ret = self["location"]
|
135
|
+
if not isinstance(ret, str):
|
136
|
+
raise TypeError("location is not a string")
|
137
|
+
return ret
|
138
|
+
|
139
|
+
@location.setter
|
140
|
+
def location(self, data: str) -> None:
|
141
|
+
self["location"] = data
|
142
|
+
|
143
|
+
@property
|
144
|
+
def object(self) -> str:
|
145
|
+
"""Alias of `self["object"]`."""
|
146
|
+
ret = self["object"]
|
147
|
+
if not isinstance(ret, str):
|
148
|
+
raise TypeError("object is not a string")
|
149
|
+
return ret
|
150
|
+
|
151
|
+
@property
|
152
|
+
def header(self) -> Header:
|
153
|
+
"""Alias of `self["FoamFile"]`."""
|
154
|
+
ret = self["FoamFile"]
|
155
|
+
if not isinstance(ret, FoamFile.Header):
|
156
|
+
assert not isinstance(ret, FoamFile.SubDict)
|
157
|
+
raise TypeError("FoamFile is not a dictionary")
|
158
|
+
return ret
|
159
|
+
|
160
|
+
@header.setter
|
161
|
+
def header(self, data: FoamDict._Dict) -> None:
|
162
|
+
self["FoamFile"] = data
|
163
|
+
|
91
164
|
def __getitem__(
|
92
165
|
self, keywords: Union[str, Tuple[str, ...]]
|
93
166
|
) -> Union["FoamFile.Data", "FoamFile.SubDict"]:
|
@@ -99,7 +172,10 @@ class FoamFile(
|
|
99
172
|
value = parsed[keywords]
|
100
173
|
|
101
174
|
if value is ...:
|
102
|
-
|
175
|
+
if keywords == ("FoamFile",):
|
176
|
+
return FoamFile.Header(self, keywords)
|
177
|
+
else:
|
178
|
+
return FoamFile.SubDict(self, keywords)
|
103
179
|
else:
|
104
180
|
return value
|
105
181
|
|
@@ -108,30 +184,36 @@ class FoamFile(
|
|
108
184
|
return self.get(("FoamFile", "format"), None) == "binary"
|
109
185
|
|
110
186
|
def __setitem__(
|
111
|
-
self,
|
112
|
-
keywords: Union[str, Tuple[str, ...]],
|
113
|
-
data: "FoamFile._SetData",
|
114
|
-
*,
|
115
|
-
assume_field: bool = False,
|
116
|
-
assume_dimensions: bool = False,
|
187
|
+
self, keywords: Union[str, Tuple[str, ...]], data: "FoamFile._SetData"
|
117
188
|
) -> None:
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
189
|
+
with self:
|
190
|
+
if not isinstance(keywords, tuple):
|
191
|
+
keywords = (keywords,)
|
192
|
+
|
193
|
+
if not self and keywords[0] != "FoamFile":
|
194
|
+
self.header = {
|
195
|
+
"version": 2.0,
|
196
|
+
"format": "ascii",
|
197
|
+
"class": "dictionary",
|
198
|
+
"location": f'"{self.path.parent.name}"',
|
199
|
+
"object": self.path.name,
|
200
|
+
} # type: ignore [assignment]
|
201
|
+
|
202
|
+
kind = Kind.DEFAULT
|
203
|
+
if keywords == ("internalField",) or (
|
204
|
+
len(keywords) == 3
|
205
|
+
and keywords[0] == "boundaryField"
|
206
|
+
and keywords[2] == "value"
|
207
|
+
):
|
208
|
+
kind = (
|
209
|
+
Kind.BINARY_FIELD if self.header.format == "binary" else Kind.FIELD
|
210
|
+
)
|
211
|
+
elif keywords == ("dimensions",):
|
212
|
+
kind = Kind.DIMENSIONS
|
130
213
|
|
131
|
-
|
214
|
+
contents, parsed = self._read()
|
132
215
|
|
133
|
-
|
134
|
-
with self:
|
216
|
+
if isinstance(data, Mapping):
|
135
217
|
if isinstance(data, FoamDict):
|
136
218
|
data = data.as_dict()
|
137
219
|
|
@@ -147,16 +229,34 @@ class FoamFile(
|
|
147
229
|
|
148
230
|
for k, v in data.items():
|
149
231
|
self[(*keywords, k)] = v
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
self.
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
232
|
+
|
233
|
+
elif (
|
234
|
+
kind == Kind.FIELD or kind == Kind.BINARY_FIELD
|
235
|
+
) and self.header.class_ == "dictionary":
|
236
|
+
if not is_sequence(data):
|
237
|
+
class_ = "volScalarField"
|
238
|
+
elif (len(data) == 3 and not is_sequence(data[0])) or len(data[0]) == 3:
|
239
|
+
class_ = "volVectorField"
|
240
|
+
elif (len(data) == 6 and not is_sequence(data[0])) or len(data[0]) == 6:
|
241
|
+
class_ = "volSymmTensorField"
|
242
|
+
elif (len(data) == 9 and not is_sequence(data[0])) or len(data[0]) == 9:
|
243
|
+
class_ = "volTensorField"
|
244
|
+
else:
|
245
|
+
class_ = "volScalarField"
|
246
|
+
|
247
|
+
self.header.class_ = class_
|
248
|
+
self[keywords] = data
|
249
|
+
|
250
|
+
else:
|
251
|
+
start, end = parsed.entry_location(keywords, missing_ok=True)
|
252
|
+
|
253
|
+
self._write(
|
254
|
+
contents[:start]
|
255
|
+
+ b"\n"
|
256
|
+
+ dumpb({keywords[-1]: data}, kind=kind)
|
257
|
+
+ b"\n"
|
258
|
+
+ contents[end:]
|
259
|
+
)
|
160
260
|
|
161
261
|
def __delitem__(self, keywords: Union[str, Tuple[str, ...]]) -> None:
|
162
262
|
if not isinstance(keywords, tuple):
|
@@ -1,4 +1,4 @@
|
|
1
|
-
foamlib/__init__.py,sha256=
|
1
|
+
foamlib/__init__.py,sha256=6_yiMUG0LJCO6YJZrf7xrR_df9CNAX8P7l6VHXbYdIU,439
|
2
2
|
foamlib/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
|
3
3
|
foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
foamlib/_cases/__init__.py,sha256=xnQpR64EvFtCh07qnSz7kjQ1IhJXjRDwaZWwQGZhGv4,280
|
@@ -8,12 +8,12 @@ foamlib/_cases/_sync.py,sha256=CloQgd-93jxfSXIt7J5NxcAu3N_iF3eXMKO-NfNOgi4,4522
|
|
8
8
|
foamlib/_cases/_util.py,sha256=v6sHxHCEgagsVuup0S1xJW-x9py5xj3bUye8PiFfb3o,925
|
9
9
|
foamlib/_files/__init__.py,sha256=vDkPj8u8bX_I_m2YfeKvXBgwg8D1ufyFCfHGHKN3JPQ,140
|
10
10
|
foamlib/_files/_base.py,sha256=YA5a-i5HZuA3JslCD6r-DwZzpSA8r42dqSXef286Ako,2050
|
11
|
-
foamlib/_files/_files.py,sha256=
|
11
|
+
foamlib/_files/_files.py,sha256=23KmcPohpSA7qysIgdlU1BTZM8Hv3HcnCKuQe9lPIL8,14292
|
12
12
|
foamlib/_files/_io.py,sha256=hlcqQqU-1cdIbDc3YqxnMfxALo4SFAEcRIoZM2vMtnE,2083
|
13
13
|
foamlib/_files/_parsing.py,sha256=-IgvCOFMAERNOrpw2NaHtVXubBg4Ey6xR55bzEZb2B4,7696
|
14
14
|
foamlib/_files/_serialization.py,sha256=LCeaLWtNvkcs0dfowL7nViiByxw7U_fvgueVjFliipU,3462
|
15
|
-
foamlib-0.3.
|
16
|
-
foamlib-0.3.
|
17
|
-
foamlib-0.3.
|
18
|
-
foamlib-0.3.
|
19
|
-
foamlib-0.3.
|
15
|
+
foamlib-0.3.19.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
|
16
|
+
foamlib-0.3.19.dist-info/METADATA,sha256=K4T7r8iEJ5d9pWwhVSP9YWxLicbv3JpfwOl_habajAQ,5458
|
17
|
+
foamlib-0.3.19.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
|
18
|
+
foamlib-0.3.19.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
|
19
|
+
foamlib-0.3.19.dist-info/RECORD,,
|
File without changes
|
File without changes
|