foamlib 0.2.9__py3-none-any.whl → 0.3.0__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 +5 -3
- foamlib/_cases.py +20 -32
- foamlib/_files/__init__.py +9 -0
- foamlib/{_dictionaries → _files}/_base.py +9 -11
- foamlib/_files/_fields.py +158 -0
- foamlib/_files/_files.py +203 -0
- foamlib/_files/_io.py +73 -0
- foamlib/_files/_parsing.py +195 -0
- foamlib/_files/_serialization.py +156 -0
- {foamlib-0.2.9.dist-info → foamlib-0.3.0.dist-info}/METADATA +1 -1
- foamlib-0.3.0.dist-info/RECORD +16 -0
- foamlib/_dictionaries/__init__.py +0 -8
- foamlib/_dictionaries/_files.py +0 -422
- foamlib/_dictionaries/_parsing.py +0 -198
- foamlib/_dictionaries/_serialization.py +0 -129
- foamlib-0.2.9.dist-info/RECORD +0 -14
- {foamlib-0.2.9.dist-info → foamlib-0.3.0.dist-info}/LICENSE.txt +0 -0
- {foamlib-0.2.9.dist-info → foamlib-0.3.0.dist-info}/WHEEL +0 -0
- {foamlib-0.2.9.dist-info → foamlib-0.3.0.dist-info}/top_level.txt +0 -0
@@ -1,129 +0,0 @@
|
|
1
|
-
import sys
|
2
|
-
from contextlib import suppress
|
3
|
-
|
4
|
-
if sys.version_info >= (3, 9):
|
5
|
-
from collections.abc import Mapping
|
6
|
-
else:
|
7
|
-
from typing import Mapping
|
8
|
-
|
9
|
-
from .._util import is_sequence
|
10
|
-
from ._base import FoamDictionaryBase
|
11
|
-
|
12
|
-
|
13
|
-
def _serialize_switch(value: FoamDictionaryBase._SetValue) -> str:
|
14
|
-
if value is True:
|
15
|
-
return "yes"
|
16
|
-
elif value is False:
|
17
|
-
return "no"
|
18
|
-
else:
|
19
|
-
raise TypeError(f"Not a bool: {type(value)}")
|
20
|
-
|
21
|
-
|
22
|
-
def _serialize_list(
|
23
|
-
value: FoamDictionaryBase._SetValue,
|
24
|
-
) -> str:
|
25
|
-
if is_sequence(value):
|
26
|
-
return f"({' '.join(_serialize_value(v) for v in value)})"
|
27
|
-
else:
|
28
|
-
raise TypeError(f"Not a valid sequence: {type(value)}")
|
29
|
-
|
30
|
-
|
31
|
-
def _serialize_field(
|
32
|
-
value: FoamDictionaryBase._SetValue,
|
33
|
-
) -> str:
|
34
|
-
if is_sequence(value):
|
35
|
-
try:
|
36
|
-
s = _serialize_list(value)
|
37
|
-
except TypeError:
|
38
|
-
raise TypeError(f"Not a valid field: {type(value)}") from None
|
39
|
-
else:
|
40
|
-
if not is_sequence(value[0]) and len(value) < 10:
|
41
|
-
return f"uniform {s}"
|
42
|
-
else:
|
43
|
-
if not is_sequence(value[0]):
|
44
|
-
kind = "scalar"
|
45
|
-
elif len(value[0]) == 3:
|
46
|
-
kind = "vector"
|
47
|
-
elif len(value[0]) == 6:
|
48
|
-
kind = "symmTensor"
|
49
|
-
elif len(value[0]) == 9:
|
50
|
-
kind = "tensor"
|
51
|
-
else:
|
52
|
-
raise TypeError(
|
53
|
-
f"Unsupported sequence length for field: {len(value[0])}"
|
54
|
-
)
|
55
|
-
return f"nonuniform List<{kind}> {len(value)}{s}"
|
56
|
-
else:
|
57
|
-
return f"uniform {value}"
|
58
|
-
|
59
|
-
|
60
|
-
def _serialize_dimensions(
|
61
|
-
value: FoamDictionaryBase._SetValue,
|
62
|
-
) -> str:
|
63
|
-
if is_sequence(value) and len(value) == 7:
|
64
|
-
return f"[{' '.join(str(v) for v in value)}]"
|
65
|
-
else:
|
66
|
-
raise TypeError(f"Not a valid dimension set: {type(value)}")
|
67
|
-
|
68
|
-
|
69
|
-
def _serialize_dimensioned(
|
70
|
-
value: FoamDictionaryBase._SetValue,
|
71
|
-
) -> str:
|
72
|
-
if isinstance(value, FoamDictionaryBase.Dimensioned):
|
73
|
-
if value.name is not None:
|
74
|
-
return f"{value.name} {_serialize_dimensions(value.dimensions)} {_serialize_value(value.value)}"
|
75
|
-
else:
|
76
|
-
return f"{_serialize_dimensions(value.dimensions)} {_serialize_value(value.value)}"
|
77
|
-
else:
|
78
|
-
raise TypeError(f"Not a valid dimensioned value: {type(value)}")
|
79
|
-
|
80
|
-
|
81
|
-
def _serialize_value(
|
82
|
-
value: FoamDictionaryBase._SetValue,
|
83
|
-
*,
|
84
|
-
assume_field: bool = False,
|
85
|
-
assume_dimensions: bool = False,
|
86
|
-
) -> str:
|
87
|
-
if isinstance(value, FoamDictionaryBase.DimensionSet) or assume_dimensions:
|
88
|
-
with suppress(TypeError):
|
89
|
-
return _serialize_dimensions(value)
|
90
|
-
|
91
|
-
if assume_field:
|
92
|
-
with suppress(TypeError):
|
93
|
-
return _serialize_field(value)
|
94
|
-
|
95
|
-
with suppress(TypeError):
|
96
|
-
return _serialize_dimensioned(value)
|
97
|
-
|
98
|
-
with suppress(TypeError):
|
99
|
-
return _serialize_list(value)
|
100
|
-
|
101
|
-
with suppress(TypeError):
|
102
|
-
return _serialize_switch(value)
|
103
|
-
|
104
|
-
with suppress(TypeError):
|
105
|
-
return _serialize_dictionary(value)
|
106
|
-
|
107
|
-
return str(value)
|
108
|
-
|
109
|
-
|
110
|
-
def _serialize_dictionary(
|
111
|
-
value: FoamDictionaryBase._SetValue,
|
112
|
-
) -> str:
|
113
|
-
if isinstance(value, Mapping):
|
114
|
-
return "\n".join(serialize_entry(k, v) for k, v in value.items())
|
115
|
-
else:
|
116
|
-
raise TypeError(f"Not a valid dictionary: {type(value)}")
|
117
|
-
|
118
|
-
|
119
|
-
def serialize_entry(
|
120
|
-
keyword: str,
|
121
|
-
value: FoamDictionaryBase._SetValue,
|
122
|
-
*,
|
123
|
-
assume_field: bool = False,
|
124
|
-
assume_dimensions: bool = False,
|
125
|
-
) -> str:
|
126
|
-
try:
|
127
|
-
return f"{keyword}\n{{\n{_serialize_dictionary(value)}\n}}"
|
128
|
-
except TypeError:
|
129
|
-
return f"{keyword} {_serialize_value(value, assume_field=assume_field, assume_dimensions=assume_dimensions)};"
|
foamlib-0.2.9.dist-info/RECORD
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
foamlib/__init__.py,sha256=xipBAyZhJ9168-UsgVjKmQdIbtsqDB3a3sLY93n3sBY,344
|
2
|
-
foamlib/_cases.py,sha256=SjDTVauOlcrtyvnt5uxWGSu2RYZ0lhKRmvMnuRnRuzI,20973
|
3
|
-
foamlib/_util.py,sha256=PBTpBwt_j1GXASncSDZUR8pH2u_h8UyJXm8GeFKebTY,2552
|
4
|
-
foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
foamlib/_dictionaries/__init__.py,sha256=vxGpA7uaEbJwKFGOYdLFR6R9jcUj_HW60YzZBMjNXRo,160
|
6
|
-
foamlib/_dictionaries/_base.py,sha256=0GkUmj268EmrGfB553JGLuNM6xq8DTIYK2NdN1rvFYU,1836
|
7
|
-
foamlib/_dictionaries/_files.py,sha256=P-FzR3Db6T_WQDh_RF07aLgyp0UUJxxD3i7_WBk1CMM,13048
|
8
|
-
foamlib/_dictionaries/_parsing.py,sha256=kzpuY_KlvkyMXIamxVwVvYSMpMY5sXCbIZ2ARNdWJtg,5512
|
9
|
-
foamlib/_dictionaries/_serialization.py,sha256=tbg63f0Nro89iqN2fsEnRzVPoxOVxYDZA4H9YhUiGtw,3776
|
10
|
-
foamlib-0.2.9.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
|
11
|
-
foamlib-0.2.9.dist-info/METADATA,sha256=GAw9nlyxHbi7XxpJEIKIjLPal8j__tcNOaurCoG6PJQ,4650
|
12
|
-
foamlib-0.2.9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
13
|
-
foamlib-0.2.9.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
|
14
|
-
foamlib-0.2.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|