foamlib 0.9.2__py3-none-any.whl → 0.9.3__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/_parsing.py +3 -1
- foamlib/_files/_types.py +122 -6
- {foamlib-0.9.2.dist-info → foamlib-0.9.3.dist-info}/METADATA +1 -1
- {foamlib-0.9.2.dist-info → foamlib-0.9.3.dist-info}/RECORD +7 -7
- {foamlib-0.9.2.dist-info → foamlib-0.9.3.dist-info}/WHEEL +0 -0
- {foamlib-0.9.2.dist-info → foamlib-0.9.3.dist-info}/licenses/LICENSE.txt +0 -0
foamlib/__init__.py
CHANGED
foamlib/_files/_parsing.py
CHANGED
@@ -363,7 +363,9 @@ _FIELD = (Keyword("uniform", _IDENTBODYCHARS).suppress() + _TENSOR) | (
|
|
363
363
|
_DIRECTIVE = Word("#", _IDENTBODYCHARS)
|
364
364
|
_TOKEN = dbl_quoted_string | _DIRECTIVE | _IDENTIFIER
|
365
365
|
_DATA = Forward()
|
366
|
-
_KEYWORD_ENTRY = _keyword_entry_of(
|
366
|
+
_KEYWORD_ENTRY = _keyword_entry_of(
|
367
|
+
_TOKEN | _list_of(_IDENTIFIER), Opt(_DATA, default="")
|
368
|
+
)
|
367
369
|
_DICT = _dict_of(_TOKEN, _DATA)
|
368
370
|
_DATA_ENTRY = Forward()
|
369
371
|
_LIST_ENTRY = _DICT | _KEYWORD_ENTRY | _DATA_ENTRY
|
foamlib/_files/_types.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import sys
|
4
|
-
from typing import Dict, NamedTuple, Optional, Union
|
4
|
+
from typing import Any, Dict, NamedTuple, Optional, Union
|
5
5
|
|
6
6
|
import numpy as np
|
7
7
|
|
@@ -28,6 +28,47 @@ class DimensionSet(NamedTuple):
|
|
28
28
|
def __repr__(self) -> str:
|
29
29
|
return f"{type(self).__name__}({', '.join(f'{n}={v}' for n, v in zip(self._fields, self) if v != 0)})"
|
30
30
|
|
31
|
+
def __add__(self, other: DimensionSet) -> DimensionSet: # type: ignore[override]
|
32
|
+
if not isinstance(other, DimensionSet):
|
33
|
+
return NotImplemented
|
34
|
+
|
35
|
+
if self != other:
|
36
|
+
msg = f"Cannot add DimensionSet with different dimensions: {self} + {other}"
|
37
|
+
raise ValueError(msg)
|
38
|
+
|
39
|
+
return self
|
40
|
+
|
41
|
+
def __sub__(self, other: DimensionSet) -> DimensionSet:
|
42
|
+
if not isinstance(other, DimensionSet):
|
43
|
+
return NotImplemented
|
44
|
+
|
45
|
+
if self != other:
|
46
|
+
msg = f"Cannot subtract DimensionSet with different dimensions: {self} - {other}"
|
47
|
+
raise ValueError(msg)
|
48
|
+
|
49
|
+
return self
|
50
|
+
|
51
|
+
def __mul__(self, other: DimensionSet) -> DimensionSet: # type: ignore[override]
|
52
|
+
if not isinstance(other, DimensionSet):
|
53
|
+
return NotImplemented
|
54
|
+
|
55
|
+
return DimensionSet(*(a + b for a, b in zip(self, other)))
|
56
|
+
|
57
|
+
def __truediv__(self, other: DimensionSet) -> DimensionSet:
|
58
|
+
if not isinstance(other, DimensionSet):
|
59
|
+
return NotImplemented
|
60
|
+
|
61
|
+
return DimensionSet(*(a - b for a, b in zip(self, other)))
|
62
|
+
|
63
|
+
def __pow__(self, exponent: float) -> DimensionSet:
|
64
|
+
if not isinstance(exponent, (int, float)):
|
65
|
+
return NotImplemented
|
66
|
+
|
67
|
+
return DimensionSet(*(a * exponent for a in self))
|
68
|
+
|
69
|
+
def __bool__(self) -> bool:
|
70
|
+
return any(v != 0 for v in self)
|
71
|
+
|
31
72
|
|
32
73
|
Tensor = Union[
|
33
74
|
float,
|
@@ -61,16 +102,91 @@ class Dimensioned:
|
|
61
102
|
|
62
103
|
self.name = name
|
63
104
|
|
64
|
-
def
|
105
|
+
def __repr__(self) -> str:
|
106
|
+
if self.name is not None:
|
107
|
+
return (
|
108
|
+
f"{type(self).__name__}({self.value}, {self.dimensions}, {self.name})"
|
109
|
+
)
|
110
|
+
return f"{type(self).__name__}({self.value}, {self.dimensions})"
|
111
|
+
|
112
|
+
def __add__(self, other: Dimensioned | Tensor) -> Dimensioned:
|
113
|
+
if not isinstance(other, Dimensioned):
|
114
|
+
other = Dimensioned(other, DimensionSet())
|
115
|
+
|
116
|
+
return Dimensioned(
|
117
|
+
self.value + other.value, # type: ignore [arg-type]
|
118
|
+
self.dimensions + other.dimensions,
|
119
|
+
f"{self.name} + {other.name}"
|
120
|
+
if self.name is not None and other.name is not None
|
121
|
+
else None,
|
122
|
+
)
|
123
|
+
|
124
|
+
def __sub__(self, other: Dimensioned | Tensor) -> Dimensioned:
|
125
|
+
if not isinstance(other, Dimensioned):
|
126
|
+
other = Dimensioned(other, DimensionSet())
|
127
|
+
|
128
|
+
return Dimensioned(
|
129
|
+
self.value - other.value, # type: ignore [arg-type]
|
130
|
+
self.dimensions - other.dimensions,
|
131
|
+
f"{self.name} - {other.name}"
|
132
|
+
if self.name is not None and other.name is not None
|
133
|
+
else None,
|
134
|
+
)
|
135
|
+
|
136
|
+
def __mul__(self, other: Dimensioned | Tensor) -> Dimensioned:
|
137
|
+
if not isinstance(other, Dimensioned):
|
138
|
+
other = Dimensioned(other, DimensionSet())
|
139
|
+
|
140
|
+
return Dimensioned(
|
141
|
+
self.value * other.value, # type: ignore [arg-type]
|
142
|
+
self.dimensions * other.dimensions,
|
143
|
+
f"{self.name} * {other.name}"
|
144
|
+
if self.name is not None and other.name is not None
|
145
|
+
else None,
|
146
|
+
)
|
147
|
+
|
148
|
+
def __truediv__(self, other: Dimensioned | Tensor) -> Dimensioned:
|
65
149
|
if not isinstance(other, Dimensioned):
|
150
|
+
other = Dimensioned(other, DimensionSet())
|
151
|
+
|
152
|
+
return Dimensioned(
|
153
|
+
self.value / other.value, # type: ignore [arg-type]
|
154
|
+
self.dimensions / other.dimensions,
|
155
|
+
f"{self.name} / {other.name}"
|
156
|
+
if self.name is not None and other.name is not None
|
157
|
+
else None,
|
158
|
+
)
|
159
|
+
|
160
|
+
def __pow__(self, exponent: float) -> Dimensioned:
|
161
|
+
if not isinstance(exponent, (int, float)):
|
66
162
|
return NotImplemented
|
67
163
|
|
68
|
-
return (
|
69
|
-
self.
|
70
|
-
|
71
|
-
|
164
|
+
return Dimensioned(
|
165
|
+
self.value**exponent, # type: ignore [arg-type]
|
166
|
+
self.dimensions**exponent,
|
167
|
+
f"{self.name} ** {exponent}" if self.name is not None else None,
|
72
168
|
)
|
73
169
|
|
170
|
+
def __float__(self) -> float:
|
171
|
+
if self.dimensions:
|
172
|
+
msg = f"Cannot convert non-dimensionless Dimensioned object to float: {self.dimensions}"
|
173
|
+
raise ValueError(msg)
|
174
|
+
return float(self.value)
|
175
|
+
|
176
|
+
def __int__(self) -> int:
|
177
|
+
if self.dimensions:
|
178
|
+
msg = f"Cannot convert non-dimensionless Dimensioned object to int: {self.dimensions}"
|
179
|
+
raise ValueError(msg)
|
180
|
+
return int(self.value)
|
181
|
+
|
182
|
+
def __array__(
|
183
|
+
self, dtype: Any = None, *, copy: Any = None
|
184
|
+
) -> np.ndarray[tuple[()] | tuple[int], np.dtype[np.float64]]:
|
185
|
+
if self.dimensions:
|
186
|
+
msg = f"Cannot convert non-dimensionless Dimensioned object to array: {self.dimensions}"
|
187
|
+
raise ValueError(msg)
|
188
|
+
return np.array(self.value, dtype=dtype, copy=copy)
|
189
|
+
|
74
190
|
|
75
191
|
Field = Union[
|
76
192
|
float,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
foamlib/__init__.py,sha256=
|
1
|
+
foamlib/__init__.py,sha256=sKW9pgKveQO8QUcC-4ZGxJAHmRBBUsEZzFXumN9SXpY,452
|
2
2
|
foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
foamlib/_cases/__init__.py,sha256=_A1TTHuQfS9FH2_33lSEyLtOJZGFHZBco1tWJCVOHks,358
|
4
4
|
foamlib/_cases/_async.py,sha256=e4lGTcQBbFGwfG6SmJks5aa5LWd_0dy01kgKZWAgTGQ,11655
|
@@ -11,10 +11,10 @@ foamlib/_cases/_util.py,sha256=QCizfbuJdOCeF9ogU2R-y-iWX5kfaOA4U2W68t6QlOM,2544
|
|
11
11
|
foamlib/_files/__init__.py,sha256=q1vkjXnjnSZvo45jPAICpWeF2LZv5V6xfzAR6S8fS5A,96
|
12
12
|
foamlib/_files/_files.py,sha256=7Si-C-2O0h27Ga4bC0W-i6_PKq7B4K2Gg1tDGh8AZFo,22416
|
13
13
|
foamlib/_files/_io.py,sha256=BGbbm6HKxL2ka0YMCmHqZQZ1R4PPQlkvWWb4FHMAS8k,2217
|
14
|
-
foamlib/_files/_parsing.py,sha256=
|
14
|
+
foamlib/_files/_parsing.py,sha256=CWALQclNOXUlPylI98h2DxMNz5OE0KZf9Gioc9h3OWU,17659
|
15
15
|
foamlib/_files/_serialization.py,sha256=R9-oXYywZubevuPkYaTIAyM0_BfF9rC819j9AXOCcg8,6451
|
16
|
-
foamlib/_files/_types.py,sha256=
|
17
|
-
foamlib-0.9.
|
18
|
-
foamlib-0.9.
|
19
|
-
foamlib-0.9.
|
20
|
-
foamlib-0.9.
|
16
|
+
foamlib/_files/_types.py,sha256=BJaRzICgnl2SOI6Nc2f8F8fendqmIK8VAdeb5zroYm0,7254
|
17
|
+
foamlib-0.9.3.dist-info/METADATA,sha256=LCtjDlLD_fJaiEUyo847EcF1jbhXVufh2iJUa_ck_Ng,12906
|
18
|
+
foamlib-0.9.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
19
|
+
foamlib-0.9.3.dist-info/licenses/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
|
20
|
+
foamlib-0.9.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|