foamlib 0.1.7__tar.gz → 0.1.9__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.7 → foamlib-0.1.9}/PKG-INFO +1 -1
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib/__init__.py +1 -1
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib/_dictionaries.py +54 -46
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib.egg-info/PKG-INFO +1 -1
- {foamlib-0.1.7 → foamlib-0.1.9}/tests/test_dictionaries.py +21 -1
- {foamlib-0.1.7 → foamlib-0.1.9}/LICENSE.txt +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/README.md +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib/_cases.py +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib/_subprocesses.py +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib/py.typed +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib.egg-info/SOURCES.txt +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib.egg-info/dependency_links.txt +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib.egg-info/requires.txt +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/foamlib.egg-info/top_level.txt +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/pyproject.toml +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/setup.cfg +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/tests/test_basic.py +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/tests/test_flange.py +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/tests/test_flange_async.py +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/tests/test_pitz.py +0 -0
- {foamlib-0.1.7 → foamlib-0.1.9}/tests/test_pitz_async.py +0 -0
@@ -23,7 +23,19 @@ except ModuleNotFoundError:
|
|
23
23
|
else:
|
24
24
|
numpy = True
|
25
25
|
|
26
|
-
from pyparsing import
|
26
|
+
from pyparsing import (
|
27
|
+
Forward,
|
28
|
+
Group,
|
29
|
+
Keyword,
|
30
|
+
Literal,
|
31
|
+
OneOrMore,
|
32
|
+
Opt,
|
33
|
+
Word,
|
34
|
+
ZeroOrMore,
|
35
|
+
common,
|
36
|
+
identchars,
|
37
|
+
identbodychars,
|
38
|
+
)
|
27
39
|
|
28
40
|
FoamDimensionSet = namedtuple(
|
29
41
|
"FoamDimensionSet",
|
@@ -64,45 +76,42 @@ FoamValue = Union[
|
|
64
76
|
A value that can be stored in an OpenFOAM dictionary.
|
65
77
|
"""
|
66
78
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
+ Literal("
|
79
|
+
_YES = Keyword("yes").set_parse_action(lambda s, loc, tks: True)
|
80
|
+
_NO = Keyword("no").set_parse_action(lambda s, loc, tks: False)
|
81
|
+
_WORDS = OneOrMore(Word(identchars, identbodychars + "(),")).set_parse_action(
|
82
|
+
lambda s, loc, tks: " ".join(tks)
|
83
|
+
)
|
84
|
+
_VALUE = Forward()
|
85
|
+
_LIST = Opt(
|
86
|
+
Literal("List") + Literal("<") + common.identifier + Literal(">")
|
87
|
+
).suppress() + (
|
88
|
+
(
|
89
|
+
Opt(common.integer).suppress()
|
90
|
+
+ Literal("(").suppress()
|
91
|
+
+ Group(ZeroOrMore(_VALUE))
|
92
|
+
+ Literal(")").suppress()
|
93
|
+
)
|
94
|
+
| (
|
95
|
+
common.integer + Literal("{").suppress() + _VALUE + Literal("}").suppress()
|
96
|
+
).set_parse_action(lambda s, loc, tks: [tks[1]] * tks[0])
|
75
97
|
)
|
76
|
-
|
77
|
-
|
78
|
-
Keyword("nonuniform").suppress()
|
79
|
-
+ Literal("List<").suppress()
|
80
|
-
+ common.identifier.suppress()
|
81
|
-
+ Literal(">").suppress()
|
82
|
-
+ _list
|
98
|
+
_FIELD = (Keyword("uniform").suppress() + _VALUE) | (
|
99
|
+
Keyword("nonuniform").suppress() + _LIST
|
83
100
|
)
|
84
|
-
|
101
|
+
_DIMENSIONS = (
|
85
102
|
Literal("[").suppress() + common.number * 7 + Literal("]").suppress()
|
86
103
|
).set_parse_action(lambda s, loc, tks: FoamDimensionSet(*tks))
|
87
|
-
|
104
|
+
_DIMENSIONED = (common.identifier + _DIMENSIONS + _VALUE).set_parse_action(
|
88
105
|
lambda s, loc, tks: FoamDimensioned(tks[0], tks[1], tks[2].as_list())
|
89
106
|
)
|
90
107
|
|
91
|
-
|
92
|
-
|
93
|
-
| _nonuniform_field
|
94
|
-
| _list
|
95
|
-
| _dimensioned
|
96
|
-
| _dimensions
|
97
|
-
| common.number
|
98
|
-
| _yes
|
99
|
-
| _no
|
100
|
-
| common.identifier
|
108
|
+
_VALUE << (
|
109
|
+
_FIELD | _LIST | _DIMENSIONED | _DIMENSIONS | common.number | _YES | _NO | _WORDS
|
101
110
|
)
|
102
111
|
|
103
112
|
|
104
113
|
def _parse(value: str) -> FoamValue:
|
105
|
-
return cast(FoamValue,
|
114
|
+
return cast(FoamValue, _VALUE.parse_string(value, parse_all=True).as_list()[0])
|
106
115
|
|
107
116
|
|
108
117
|
def _serialize_bool(value: Any) -> str:
|
@@ -114,22 +123,24 @@ def _serialize_bool(value: Any) -> str:
|
|
114
123
|
raise TypeError(f"Not a bool: {type(value)}")
|
115
124
|
|
116
125
|
|
117
|
-
def
|
118
|
-
|
119
|
-
isinstance(
|
120
|
-
and not isinstance(
|
126
|
+
def _is_sequence(value: Any) -> bool:
|
127
|
+
return (
|
128
|
+
isinstance(value, Sequence)
|
129
|
+
and not isinstance(value, str)
|
121
130
|
or numpy
|
122
|
-
and isinstance(
|
123
|
-
)
|
124
|
-
|
131
|
+
and isinstance(value, np.ndarray)
|
132
|
+
)
|
133
|
+
|
134
|
+
|
135
|
+
def _serialize_list(value: Any) -> str:
|
136
|
+
if _is_sequence(value):
|
137
|
+
return f"({' '.join(_serialize(v) for v in value)})"
|
125
138
|
else:
|
126
|
-
raise TypeError(f"Not a valid sequence: {type(
|
139
|
+
raise TypeError(f"Not a valid sequence: {type(value)}")
|
127
140
|
|
128
141
|
|
129
142
|
def _serialize_field(value: Any) -> str:
|
130
|
-
if
|
131
|
-
return f"uniform {value}"
|
132
|
-
else:
|
143
|
+
if _is_sequence(value):
|
133
144
|
try:
|
134
145
|
s = _serialize_list(value)
|
135
146
|
except TypeError:
|
@@ -151,15 +162,12 @@ def _serialize_field(value: Any) -> str:
|
|
151
162
|
f"Unsupported sequence length for field: {len(value[0])}"
|
152
163
|
)
|
153
164
|
return f"nonuniform List<{kind}> {len(value)}{s}"
|
165
|
+
else:
|
166
|
+
return f"uniform {value}"
|
154
167
|
|
155
168
|
|
156
169
|
def _serialize_dimensions(value: Any) -> str:
|
157
|
-
if (
|
158
|
-
isinstance(value, Sequence)
|
159
|
-
and not isinstance(value, str)
|
160
|
-
or numpy
|
161
|
-
and isinstance(value, np.ndarray)
|
162
|
-
) and len(value) == 7:
|
170
|
+
if _is_sequence(value) and len(value) == 7:
|
163
171
|
return f"[{' '.join(str(v) for v in value)}]"
|
164
172
|
else:
|
165
173
|
raise TypeError(f"Not a valid dimension set: {type(value)}")
|
@@ -137,6 +137,18 @@ def test_internal_field(pitz: FoamCase) -> None:
|
|
137
137
|
|
138
138
|
pitz.clean()
|
139
139
|
|
140
|
+
p_arr = np.zeros(size)
|
141
|
+
U_arr = np.zeros((size, 3))
|
142
|
+
|
143
|
+
pitz[0]["p"].internal_field = p_arr
|
144
|
+
pitz[0]["U"].internal_field = U_arr
|
145
|
+
|
146
|
+
assert pitz[0]["p"].internal_field == pytest.approx(p_arr)
|
147
|
+
U = pitz[0]["U"].internal_field
|
148
|
+
assert isinstance(U, Sequence)
|
149
|
+
for u, u_arr in zip(U, U_arr):
|
150
|
+
assert u == pytest.approx(u_arr)
|
151
|
+
|
140
152
|
p_arr = np.arange(size) * 1e-6
|
141
153
|
U_arr = np.full((size, 3), [-1e-6, 1e-6, 0]) * np.arange(size)[:, np.newaxis]
|
142
154
|
|
@@ -144,9 +156,17 @@ def test_internal_field(pitz: FoamCase) -> None:
|
|
144
156
|
pitz[0]["U"].internal_field = U_arr
|
145
157
|
|
146
158
|
assert pitz[0]["p"].internal_field == pytest.approx(p_arr)
|
147
|
-
U = pitz[
|
159
|
+
U = pitz[0]["U"].internal_field
|
148
160
|
assert isinstance(U, Sequence)
|
149
161
|
for u, u_arr in zip(U, U_arr):
|
150
162
|
assert u == pytest.approx(u_arr)
|
151
163
|
|
152
164
|
pitz.run()
|
165
|
+
|
166
|
+
|
167
|
+
def test_fv_schemes(pitz: FoamCase) -> None:
|
168
|
+
div_schemes = pitz.fv_schemes["divSchemes"]
|
169
|
+
assert isinstance(div_schemes, FoamDictionary)
|
170
|
+
scheme = div_schemes["div(phi,U)"]
|
171
|
+
assert isinstance(scheme, str)
|
172
|
+
assert scheme == "bounded Gauss linearUpwind grad(U)"
|
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
|