foamlib 0.1.12__tar.gz → 0.1.13__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.
- {foamlib-0.1.12 → foamlib-0.1.13}/PKG-INFO +1 -1
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib/__init__.py +1 -1
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib/_dictionaries.py +30 -22
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib.egg-info/PKG-INFO +1 -1
- {foamlib-0.1.12 → foamlib-0.1.13}/tests/test_dictionaries.py +12 -3
- {foamlib-0.1.12 → foamlib-0.1.13}/LICENSE.txt +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/README.md +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib/_cases.py +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib/_subprocesses.py +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib/py.typed +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib.egg-info/SOURCES.txt +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib.egg-info/dependency_links.txt +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib.egg-info/requires.txt +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/foamlib.egg-info/top_level.txt +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/pyproject.toml +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/setup.cfg +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/tests/test_basic.py +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/tests/test_flange.py +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/tests/test_flange_async.py +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/tests/test_pitz.py +0 -0
- {foamlib-0.1.12 → foamlib-0.1.13}/tests/test_pitz_async.py +0 -0
@@ -29,8 +29,10 @@ from pyparsing import (
|
|
29
29
|
Keyword,
|
30
30
|
Literal,
|
31
31
|
Opt,
|
32
|
-
|
32
|
+
QuotedString,
|
33
|
+
Word,
|
33
34
|
common,
|
35
|
+
identbodychars,
|
34
36
|
)
|
35
37
|
|
36
38
|
FoamDimensionSet = namedtuple(
|
@@ -50,17 +52,13 @@ FoamDimensionSet = namedtuple(
|
|
50
52
|
|
51
53
|
@dataclass
|
52
54
|
class FoamDimensioned:
|
53
|
-
|
55
|
+
value: Union[int, float, Sequence[Union[int, float]]] = 0
|
54
56
|
dimensions: Union[FoamDimensionSet, Sequence[Union[int, float]]] = (
|
55
57
|
FoamDimensionSet()
|
56
58
|
)
|
57
|
-
|
59
|
+
name: Optional[str] = None
|
58
60
|
|
59
61
|
def __post_init__(self) -> None:
|
60
|
-
if self.name is not None and not isinstance(self.name, str) and self.value == 0:
|
61
|
-
self.value = self.name
|
62
|
-
self.name = None
|
63
|
-
|
64
62
|
if not isinstance(self.dimensions, FoamDimensionSet):
|
65
63
|
self.dimensions = FoamDimensionSet(*self.dimensions)
|
66
64
|
|
@@ -74,38 +72,43 @@ A value that can be stored in an OpenFOAM dictionary.
|
|
74
72
|
|
75
73
|
_YES = Keyword("yes").set_parse_action(lambda s, loc, tks: True)
|
76
74
|
_NO = Keyword("no").set_parse_action(lambda s, loc, tks: False)
|
77
|
-
|
75
|
+
_DIMENSIONS = (
|
76
|
+
Literal("[").suppress() + common.number * 7 + Literal("]").suppress()
|
77
|
+
).set_parse_action(lambda s, loc, tks: FoamDimensionSet(*tks))
|
78
|
+
_TOKEN = common.identifier | QuotedString('"', unquote_results=False)
|
79
|
+
_ITEM = Forward()
|
78
80
|
_LIST = Opt(
|
79
81
|
Literal("List") + Literal("<") + common.identifier + Literal(">")
|
80
82
|
).suppress() + (
|
81
83
|
(
|
82
84
|
Opt(common.integer).suppress()
|
83
85
|
+ Literal("(").suppress()
|
84
|
-
+ Group(
|
86
|
+
+ Group(_ITEM[...])
|
85
87
|
+ Literal(")").suppress()
|
86
88
|
)
|
87
89
|
| (
|
88
|
-
common.integer + Literal("{").suppress() +
|
90
|
+
common.integer + Literal("{").suppress() + _ITEM + Literal("}").suppress()
|
89
91
|
).set_parse_action(lambda s, loc, tks: [tks[1]] * tks[0])
|
90
92
|
)
|
91
|
-
_FIELD = (Keyword("uniform").suppress() +
|
93
|
+
_FIELD = (Keyword("uniform").suppress() + _ITEM) | (
|
92
94
|
Keyword("nonuniform").suppress() + _LIST
|
93
95
|
)
|
94
|
-
|
95
|
-
|
96
|
-
)
|
97
|
-
|
98
|
-
|
96
|
+
_DIMENSIONED = (Opt(common.identifier) + _DIMENSIONS + _ITEM).set_parse_action(
|
97
|
+
lambda s, loc, tks: FoamDimensioned(*reversed(tks.as_list()))
|
98
|
+
)
|
99
|
+
_ITEM <<= (
|
100
|
+
_FIELD | _LIST | _DIMENSIONED | _DIMENSIONS | common.number | _YES | _NO | _TOKEN
|
99
101
|
)
|
100
102
|
|
101
|
-
|
103
|
+
_TOKENS = (Word(identbodychars + "(),") | QuotedString('"', unquote_results=False))[
|
104
|
+
1, ...
|
105
|
+
].set_parse_action(lambda s, loc, tks: " ".join(tks))
|
106
|
+
|
107
|
+
_VALUE = _ITEM ^ _TOKENS
|
102
108
|
|
103
109
|
|
104
110
|
def _parse(value: str) -> FoamValue:
|
105
|
-
|
106
|
-
return cast(FoamValue, _VALUE.parse_string(value, parse_all=True).as_list()[0])
|
107
|
-
except ParseException:
|
108
|
-
return value
|
111
|
+
return cast(FoamValue, _VALUE.parse_string(value, parse_all=True).as_list()[0])
|
109
112
|
|
110
113
|
|
111
114
|
def _serialize_bool(value: Any) -> str:
|
@@ -169,7 +172,12 @@ def _serialize_dimensions(value: Any) -> str:
|
|
169
172
|
|
170
173
|
def _serialize_dimensioned(value: Any) -> str:
|
171
174
|
if isinstance(value, FoamDimensioned):
|
172
|
-
|
175
|
+
if value.name is not None:
|
176
|
+
return f"{value.name} {_serialize_dimensions(value.dimensions)} {_serialize(value.value)}"
|
177
|
+
else:
|
178
|
+
return (
|
179
|
+
f"{_serialize_dimensions(value.dimensions)} {_serialize(value.value)}"
|
180
|
+
)
|
173
181
|
else:
|
174
182
|
raise TypeError(f"Not a valid dimensioned value: {type(value)}")
|
175
183
|
|
@@ -32,7 +32,12 @@ def test_parse() -> None:
|
|
32
32
|
]
|
33
33
|
assert _parse("[1 1 -2 0 0 0 0]") == FoamDimensionSet(mass=1, length=1, time=-2)
|
34
34
|
assert _parse("g [1 1 -2 0 0 0 0] (0 0 -9.81)") == FoamDimensioned(
|
35
|
-
"g",
|
35
|
+
name="g",
|
36
|
+
dimensions=FoamDimensionSet(mass=1, length=1, time=-2),
|
37
|
+
value=[0, 0, -9.81],
|
38
|
+
)
|
39
|
+
assert _parse("[1 1 -2 0 0 0 0] 9.81") == FoamDimensioned(
|
40
|
+
dimensions=FoamDimensionSet(mass=1, length=1, time=-2), value=9.81
|
36
41
|
)
|
37
42
|
assert (
|
38
43
|
_parse("hex (0 1 2 3 4 5 6 7) (1 1 1) simpleGrading (1 1 1)")
|
@@ -88,9 +93,13 @@ def test_write_read(tmp_path: Path) -> None:
|
|
88
93
|
sd["nestedList"] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
89
94
|
assert sd["nestedList"] == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
90
95
|
|
91
|
-
sd["g"] = FoamDimensioned(
|
96
|
+
sd["g"] = FoamDimensioned(
|
97
|
+
name="g", dimensions=[1, 1, -2, 0, 0, 0, 0], value=[0, 0, -9.81]
|
98
|
+
)
|
92
99
|
assert sd["g"] == FoamDimensioned(
|
93
|
-
"g",
|
100
|
+
name="g",
|
101
|
+
dimensions=FoamDimensionSet(mass=1, length=1, time=-2),
|
102
|
+
value=[0, 0, -9.81],
|
94
103
|
)
|
95
104
|
|
96
105
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|