foamlib 0.1.12__tar.gz → 0.1.14__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.1.12
3
+ Version: 0.1.14
4
4
  Summary: A Python interface for interacting with OpenFOAM
5
5
  Author-email: "Gabriel S. Gerlero" <ggerlero@cimec.unl.edu.ar>
6
6
  Project-URL: Homepage, https://github.com/gerlero/foamlib
@@ -54,7 +54,7 @@ Requires-Dist: numpy<2,>=1; extra == "docs"
54
54
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
55
55
  [![PyPI](https://img.shields.io/pypi/v/foamlib)](https://pypi.org/project/foamlib/)
56
56
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/foamlib)](https://pypi.org/project/foamlib/)
57
-
57
+ [![Docker image](https://img.shields.io/badge/docker%20image-gerlero%2Ffoamlib-informational)](https://hub.docker.com/r/gerlero/foamlib/)
58
58
 
59
59
  **foamlib** provides a simple, modern and ergonomic Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
60
60
 
@@ -7,7 +7,7 @@
7
7
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
8
8
  [![PyPI](https://img.shields.io/pypi/v/foamlib)](https://pypi.org/project/foamlib/)
9
9
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/foamlib)](https://pypi.org/project/foamlib/)
10
-
10
+ [![Docker image](https://img.shields.io/badge/docker%20image-gerlero%2Ffoamlib-informational)](https://hub.docker.com/r/gerlero/foamlib/)
11
11
 
12
12
  **foamlib** provides a simple, modern and ergonomic Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
13
13
 
@@ -1,4 +1,4 @@
1
- __version__ = "0.1.12"
1
+ __version__ = "0.1.14"
2
2
 
3
3
  from ._cases import FoamCase, AsyncFoamCase, FoamTimeDirectory, FoamCaseBase
4
4
  from ._dictionaries import (
@@ -29,8 +29,10 @@ from pyparsing import (
29
29
  Keyword,
30
30
  Literal,
31
31
  Opt,
32
- ParseException,
32
+ QuotedString,
33
+ Word,
33
34
  common,
35
+ printables,
34
36
  )
35
37
 
36
38
  FoamDimensionSet = namedtuple(
@@ -50,17 +52,13 @@ FoamDimensionSet = namedtuple(
50
52
 
51
53
  @dataclass
52
54
  class FoamDimensioned:
53
- name: Optional[str] = None
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
- value: Union[int, float, Sequence[Union[int, float]]] = 0
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
- _VALUE = Forward()
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(_VALUE[...])
86
+ + Group(_ITEM[...])
85
87
  + Literal(")").suppress()
86
88
  )
87
89
  | (
88
- common.integer + Literal("{").suppress() + _VALUE + 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() + _VALUE) | (
93
+ _FIELD = (Keyword("uniform").suppress() + _ITEM) | (
92
94
  Keyword("nonuniform").suppress() + _LIST
93
95
  )
94
- _DIMENSIONS = (
95
- Literal("[").suppress() + common.number * 7 + Literal("]").suppress()
96
- ).set_parse_action(lambda s, loc, tks: FoamDimensionSet(*tks))
97
- _DIMENSIONED = (common.identifier + _DIMENSIONS + _VALUE).set_parse_action(
98
- lambda s, loc, tks: FoamDimensioned(tks[0], tks[1], tks[2].as_list())
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
- _VALUE << (_FIELD | _LIST | _DIMENSIONED | _DIMENSIONS | common.number | _YES | _NO)
103
+ _TOKENS = (QuotedString('"', unquote_results=False) | Word(printables))[
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
- try:
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
- return f"{value.name or 'unnamed'} {_serialize_dimensions(value.dimensions)} {_serialize(value.value)}"
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.1.12
3
+ Version: 0.1.14
4
4
  Summary: A Python interface for interacting with OpenFOAM
5
5
  Author-email: "Gabriel S. Gerlero" <ggerlero@cimec.unl.edu.ar>
6
6
  Project-URL: Homepage, https://github.com/gerlero/foamlib
@@ -54,7 +54,7 @@ Requires-Dist: numpy<2,>=1; extra == "docs"
54
54
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
55
55
  [![PyPI](https://img.shields.io/pypi/v/foamlib)](https://pypi.org/project/foamlib/)
56
56
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/foamlib)](https://pypi.org/project/foamlib/)
57
-
57
+ [![Docker image](https://img.shields.io/badge/docker%20image-gerlero%2Ffoamlib-informational)](https://hub.docker.com/r/gerlero/foamlib/)
58
58
 
59
59
  **foamlib** provides a simple, modern and ergonomic Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
60
60
 
@@ -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", FoamDimensionSet(mass=1, length=1, time=-2), [0, 0, -9.81]
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("g", [1, 1, -2, 0, 0, 0, 0], [0, 0, -9.81])
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", FoamDimensionSet(mass=1, length=1, time=-2), [0, 0, -9.81]
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