foamlib 0.1.7__py3-none-any.whl → 0.1.8__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/_dictionaries.py +43 -43
- {foamlib-0.1.7.dist-info → foamlib-0.1.8.dist-info}/METADATA +1 -1
- foamlib-0.1.8.dist-info/RECORD +10 -0
- foamlib-0.1.7.dist-info/RECORD +0 -10
- {foamlib-0.1.7.dist-info → foamlib-0.1.8.dist-info}/LICENSE.txt +0 -0
- {foamlib-0.1.7.dist-info → foamlib-0.1.8.dist-info}/WHEEL +0 -0
- {foamlib-0.1.7.dist-info → foamlib-0.1.8.dist-info}/top_level.txt +0 -0
foamlib/__init__.py
CHANGED
foamlib/_dictionaries.py
CHANGED
@@ -64,45 +64,46 @@ FoamValue = Union[
|
|
64
64
|
A value that can be stored in an OpenFOAM dictionary.
|
65
65
|
"""
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
_YES = Keyword("yes").set_parse_action(lambda s, loc, tks: True)
|
68
|
+
_NO = Keyword("no").set_parse_action(lambda s, loc, tks: False)
|
69
|
+
_VALUE = Forward()
|
70
|
+
_LIST = Opt(
|
71
|
+
Literal("List") + Literal("<") + common.identifier + Literal(">")
|
72
|
+
).suppress() + (
|
73
|
+
(
|
74
|
+
Opt(common.integer).suppress()
|
75
|
+
+ Literal("(").suppress()
|
76
|
+
+ Group(ZeroOrMore(_VALUE))
|
77
|
+
+ Literal(")").suppress()
|
78
|
+
)
|
79
|
+
| (
|
80
|
+
common.integer + Literal("{").suppress() + _VALUE + Literal("}").suppress()
|
81
|
+
).set_parse_action(lambda s, loc, tks: [tks[1]] * tks[0])
|
75
82
|
)
|
76
|
-
|
77
|
-
|
78
|
-
Keyword("nonuniform").suppress()
|
79
|
-
+ Literal("List<").suppress()
|
80
|
-
+ common.identifier.suppress()
|
81
|
-
+ Literal(">").suppress()
|
82
|
-
+ _list
|
83
|
+
_FIELD = (Keyword("uniform").suppress() + _VALUE) | (
|
84
|
+
Keyword("nonuniform").suppress() + _LIST
|
83
85
|
)
|
84
|
-
|
86
|
+
_DIMENSIONS = (
|
85
87
|
Literal("[").suppress() + common.number * 7 + Literal("]").suppress()
|
86
88
|
).set_parse_action(lambda s, loc, tks: FoamDimensionSet(*tks))
|
87
|
-
|
89
|
+
_DIMENSIONED = (common.identifier + _DIMENSIONS + _VALUE).set_parse_action(
|
88
90
|
lambda s, loc, tks: FoamDimensioned(tks[0], tks[1], tks[2].as_list())
|
89
91
|
)
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
| _dimensions
|
93
|
+
_VALUE << (
|
94
|
+
_FIELD
|
95
|
+
| _LIST
|
96
|
+
| _DIMENSIONED
|
97
|
+
| _DIMENSIONS
|
97
98
|
| common.number
|
98
|
-
|
|
99
|
-
|
|
99
|
+
| _YES
|
100
|
+
| _NO
|
100
101
|
| common.identifier
|
101
102
|
)
|
102
103
|
|
103
104
|
|
104
105
|
def _parse(value: str) -> FoamValue:
|
105
|
-
return cast(FoamValue,
|
106
|
+
return cast(FoamValue, _VALUE.parse_string(value, parse_all=True).as_list()[0])
|
106
107
|
|
107
108
|
|
108
109
|
def _serialize_bool(value: Any) -> str:
|
@@ -114,22 +115,24 @@ def _serialize_bool(value: Any) -> str:
|
|
114
115
|
raise TypeError(f"Not a bool: {type(value)}")
|
115
116
|
|
116
117
|
|
117
|
-
def
|
118
|
-
|
119
|
-
isinstance(
|
120
|
-
and not isinstance(
|
118
|
+
def _is_sequence(value: Any) -> bool:
|
119
|
+
return (
|
120
|
+
isinstance(value, Sequence)
|
121
|
+
and not isinstance(value, str)
|
121
122
|
or numpy
|
122
|
-
and isinstance(
|
123
|
-
)
|
124
|
-
|
123
|
+
and isinstance(value, np.ndarray)
|
124
|
+
)
|
125
|
+
|
126
|
+
|
127
|
+
def _serialize_list(value: Any) -> str:
|
128
|
+
if _is_sequence(value):
|
129
|
+
return f"({' '.join(_serialize(v) for v in value)})"
|
125
130
|
else:
|
126
|
-
raise TypeError(f"Not a valid sequence: {type(
|
131
|
+
raise TypeError(f"Not a valid sequence: {type(value)}")
|
127
132
|
|
128
133
|
|
129
134
|
def _serialize_field(value: Any) -> str:
|
130
|
-
if
|
131
|
-
return f"uniform {value}"
|
132
|
-
else:
|
135
|
+
if _is_sequence(value):
|
133
136
|
try:
|
134
137
|
s = _serialize_list(value)
|
135
138
|
except TypeError:
|
@@ -151,15 +154,12 @@ def _serialize_field(value: Any) -> str:
|
|
151
154
|
f"Unsupported sequence length for field: {len(value[0])}"
|
152
155
|
)
|
153
156
|
return f"nonuniform List<{kind}> {len(value)}{s}"
|
157
|
+
else:
|
158
|
+
return f"uniform {value}"
|
154
159
|
|
155
160
|
|
156
161
|
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:
|
162
|
+
if _is_sequence(value) and len(value) == 7:
|
163
163
|
return f"[{' '.join(str(v) for v in value)}]"
|
164
164
|
else:
|
165
165
|
raise TypeError(f"Not a valid dimension set: {type(value)}")
|
@@ -0,0 +1,10 @@
|
|
1
|
+
foamlib/__init__.py,sha256=Lq8PsAvbE-bdL4D_1TWlLVltS9_14AhRrY0xq_u-bZE,550
|
2
|
+
foamlib/_cases.py,sha256=Q5c8vPzKT5coOy4q_H6s5gHgEArhLHByh6GSvDVCRdY,20683
|
3
|
+
foamlib/_dictionaries.py,sha256=71E0IMfU4sxjxsHJ7-_kUyuZX6olU31OLKxFhoEvC0s,12903
|
4
|
+
foamlib/_subprocesses.py,sha256=5vqdQvpN_2v4GgDqxi-s88NGhZ6doFxkh0XY89ZWuHA,1926
|
5
|
+
foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
foamlib-0.1.8.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
|
7
|
+
foamlib-0.1.8.dist-info/METADATA,sha256=lTbuF5eCAj3Nce2vHZGBS6xoQPzorYG_GMp5iogXo_A,4526
|
8
|
+
foamlib-0.1.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
9
|
+
foamlib-0.1.8.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
|
10
|
+
foamlib-0.1.8.dist-info/RECORD,,
|
foamlib-0.1.7.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
foamlib/__init__.py,sha256=4M78qiB1De99KYGW79G2QuvIQxP54HQ9fNaVeRcf-eo,550
|
2
|
-
foamlib/_cases.py,sha256=Q5c8vPzKT5coOy4q_H6s5gHgEArhLHByh6GSvDVCRdY,20683
|
3
|
-
foamlib/_dictionaries.py,sha256=IVq2dTEhSGKUVgBEIttk4NotE1FxQ5igY99rjPw-EcI,12871
|
4
|
-
foamlib/_subprocesses.py,sha256=5vqdQvpN_2v4GgDqxi-s88NGhZ6doFxkh0XY89ZWuHA,1926
|
5
|
-
foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
foamlib-0.1.7.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
|
7
|
-
foamlib-0.1.7.dist-info/METADATA,sha256=tMiYqlMCkMvqhKrtKdnSZckprsZwIhX_guIOFqsljac,4526
|
8
|
-
foamlib-0.1.7.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
9
|
-
foamlib-0.1.7.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
|
10
|
-
foamlib-0.1.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|