foamlib 0.3.17__tar.gz → 0.3.18__tar.gz

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.
Files changed (24) hide show
  1. {foamlib-0.3.17 → foamlib-0.3.18}/PKG-INFO +1 -1
  2. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/__init__.py +1 -1
  3. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_files/_files.py +129 -29
  4. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib.egg-info/PKG-INFO +1 -1
  5. {foamlib-0.3.17 → foamlib-0.3.18}/LICENSE.txt +0 -0
  6. {foamlib-0.3.17 → foamlib-0.3.18}/README.md +0 -0
  7. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_cases/__init__.py +0 -0
  8. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_cases/_async.py +0 -0
  9. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_cases/_base.py +0 -0
  10. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_cases/_sync.py +0 -0
  11. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_cases/_util.py +0 -0
  12. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_files/__init__.py +0 -0
  13. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_files/_base.py +0 -0
  14. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_files/_io.py +0 -0
  15. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_files/_parsing.py +0 -0
  16. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_files/_serialization.py +0 -0
  17. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/_util.py +0 -0
  18. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib/py.typed +0 -0
  19. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib.egg-info/SOURCES.txt +0 -0
  20. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib.egg-info/dependency_links.txt +0 -0
  21. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib.egg-info/requires.txt +0 -0
  22. {foamlib-0.3.17 → foamlib-0.3.18}/foamlib.egg-info/top_level.txt +0 -0
  23. {foamlib-0.3.17 → foamlib-0.3.18}/pyproject.toml +0 -0
  24. {foamlib-0.3.17 → foamlib-0.3.18}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.3.17
3
+ Version: 0.3.18
4
4
  Summary: A Python interface for interacting with OpenFOAM
5
5
  Author-email: "Gabriel S. Gerlero" <ggerlero@cimec.unl.edu.ar>
6
6
  Project-URL: Homepage, https://github.com/gerlero/foamlib
@@ -1,6 +1,6 @@
1
1
  """A Python interface for interacting with OpenFOAM."""
2
2
 
3
- __version__ = "0.3.17"
3
+ __version__ = "0.3.18"
4
4
 
5
5
  from ._cases import (
6
6
  AsyncFoamCase,
@@ -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 dictionary file.
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,74 @@ 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) -> "FoamFile.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
+
91
160
  def __getitem__(
92
161
  self, keywords: Union[str, Tuple[str, ...]]
93
162
  ) -> Union["FoamFile.Data", "FoamFile.SubDict"]:
@@ -99,7 +168,10 @@ class FoamFile(
99
168
  value = parsed[keywords]
100
169
 
101
170
  if value is ...:
102
- return FoamFile.SubDict(self, keywords)
171
+ if keywords == ("FoamFile",):
172
+ return FoamFile.Header(self, keywords)
173
+ else:
174
+ return FoamFile.SubDict(self, keywords)
103
175
  else:
104
176
  return value
105
177
 
@@ -115,23 +187,23 @@ class FoamFile(
115
187
  assume_field: bool = False,
116
188
  assume_dimensions: bool = False,
117
189
  ) -> None:
118
- if not isinstance(keywords, tuple):
119
- keywords = (keywords,)
120
-
121
- kind = Kind.DEFAULT
122
- if keywords == ("internalField",) or (
123
- len(keywords) == 3
124
- and keywords[0] == "boundaryField"
125
- and keywords[2] == "value"
126
- ):
127
- kind = Kind.BINARY_FIELD if self._binary else Kind.FIELD
128
- elif keywords == ("dimensions",):
129
- kind = Kind.DIMENSIONS
130
-
131
- contents, parsed = self._read()
132
-
133
- if isinstance(data, Mapping):
134
- with self:
190
+ with self:
191
+ if not isinstance(keywords, tuple):
192
+ keywords = (keywords,)
193
+
194
+ kind = Kind.DEFAULT
195
+ if keywords == ("internalField",) or (
196
+ len(keywords) == 3
197
+ and keywords[0] == "boundaryField"
198
+ and keywords[2] == "value"
199
+ ):
200
+ kind = Kind.BINARY_FIELD if self._binary else Kind.FIELD
201
+ elif keywords == ("dimensions",):
202
+ kind = Kind.DIMENSIONS
203
+
204
+ contents, parsed = self._read()
205
+
206
+ if isinstance(data, Mapping):
135
207
  if isinstance(data, FoamDict):
136
208
  data = data.as_dict()
137
209
 
@@ -147,16 +219,44 @@ class FoamFile(
147
219
 
148
220
  for k, v in data.items():
149
221
  self[(*keywords, k)] = v
150
- else:
151
- start, end = parsed.entry_location(keywords, missing_ok=True)
152
-
153
- self._write(
154
- contents[:start]
155
- + b"\n"
156
- + dumpb({keywords[-1]: data}, kind=kind)
157
- + b"\n"
158
- + contents[end:]
159
- )
222
+
223
+ elif not self and keywords[0] != "FoamFile":
224
+ self["FoamFile"] = {
225
+ "version": 2.0,
226
+ "format": "ascii",
227
+ "class": "dictionary",
228
+ "location": f'"{self.path.parent.name}"',
229
+ "object": self.path.name,
230
+ }
231
+ self[keywords] = data
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.3.17
3
+ Version: 0.3.18
4
4
  Summary: A Python interface for interacting with OpenFOAM
5
5
  Author-email: "Gabriel S. Gerlero" <ggerlero@cimec.unl.edu.ar>
6
6
  Project-URL: Homepage, https://github.com/gerlero/foamlib
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes