foamlib 0.7.0__tar.gz → 0.7.1__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.
Files changed (27) hide show
  1. {foamlib-0.7.0 → foamlib-0.7.1}/PKG-INFO +11 -5
  2. {foamlib-0.7.0 → foamlib-0.7.1}/README.md +10 -4
  3. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/__init__.py +1 -1
  4. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_files/_parsing.py +79 -34
  5. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib.egg-info/PKG-INFO +11 -5
  6. {foamlib-0.7.0 → foamlib-0.7.1}/LICENSE.txt +0 -0
  7. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/__init__.py +0 -0
  8. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/_async.py +0 -0
  9. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/_base.py +0 -0
  10. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/_run.py +0 -0
  11. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/_slurm.py +0 -0
  12. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/_subprocess.py +0 -0
  13. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/_sync.py +0 -0
  14. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_cases/_util.py +0 -0
  15. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_files/__init__.py +0 -0
  16. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_files/_files.py +0 -0
  17. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_files/_io.py +0 -0
  18. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_files/_serialization.py +0 -0
  19. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_files/_types.py +0 -0
  20. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/_files/_util.py +0 -0
  21. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib/py.typed +0 -0
  22. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib.egg-info/SOURCES.txt +0 -0
  23. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib.egg-info/dependency_links.txt +0 -0
  24. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib.egg-info/requires.txt +0 -0
  25. {foamlib-0.7.0 → foamlib-0.7.1}/foamlib.egg-info/top_level.txt +0 -0
  26. {foamlib-0.7.0 → foamlib-0.7.1}/pyproject.toml +0 -0
  27. {foamlib-0.7.0 → foamlib-0.7.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.7.0
3
+ Version: 0.7.1
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
@@ -69,13 +69,19 @@ Requires-Dist: foamlib[docs]; extra == "dev"
69
69
  [![Docker](https://github.com/gerlero/foamlib/actions/workflows/docker.yml/badge.svg)](https://github.com/gerlero/foamlib/actions/workflows/docker.yml)
70
70
  [![Docker image](https://img.shields.io/badge/docker%20image-microfluidica%2Ffoamlib-0085a0)](https://hub.docker.com/r/microfluidica/foamlib/)
71
71
 
72
- ## 👋 Basics
72
+ **foamlib** provides a simple, modern, ergonomic and fast Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
73
+
74
+ <p align="center">
75
+ <img alt="benchmark" src="https://github.com/gerlero/foamlib/raw/main/benchmark.png" height="250">
76
+ <br>
77
+ <i>Parsing a </i>volVectorField<i> with 200k cells.</i>
78
+ </p>
73
79
 
74
- **foamlib** provides a simple, modern and ergonomic Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
80
+ ## 👋 Basics
75
81
 
76
- It offers the following Python classes:
82
+ **foamlib** offers the following Python classes:
77
83
 
78
- * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser. Supports ASCII and binary field formats (with or without compression).
84
+ * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser and in-place editor. Supports ASCII and binary field formats (with or without compression).
79
85
  * [`FoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.FoamCase): a class for configuring, running, and accessing the results of OpenFOAM cases.
80
86
  * [`AsyncFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncFoamCase): variant of `FoamCase` with asynchronous methods for running multiple cases at once.
81
87
  * [`AsyncSlurmFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncSlurmFoamCase): subclass of `AsyncFoamCase` used for running cases on a Slurm cluster.
@@ -14,13 +14,19 @@
14
14
  [![Docker](https://github.com/gerlero/foamlib/actions/workflows/docker.yml/badge.svg)](https://github.com/gerlero/foamlib/actions/workflows/docker.yml)
15
15
  [![Docker image](https://img.shields.io/badge/docker%20image-microfluidica%2Ffoamlib-0085a0)](https://hub.docker.com/r/microfluidica/foamlib/)
16
16
 
17
- ## 👋 Basics
17
+ **foamlib** provides a simple, modern, ergonomic and fast Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
18
+
19
+ <p align="center">
20
+ <img alt="benchmark" src="https://github.com/gerlero/foamlib/raw/main/benchmark.png" height="250">
21
+ <br>
22
+ <i>Parsing a </i>volVectorField<i> with 200k cells.</i>
23
+ </p>
18
24
 
19
- **foamlib** provides a simple, modern and ergonomic Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
25
+ ## 👋 Basics
20
26
 
21
- It offers the following Python classes:
27
+ **foamlib** offers the following Python classes:
22
28
 
23
- * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser. Supports ASCII and binary field formats (with or without compression).
29
+ * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser and in-place editor. Supports ASCII and binary field formats (with or without compression).
24
30
  * [`FoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.FoamCase): a class for configuring, running, and accessing the results of OpenFOAM cases.
25
31
  * [`AsyncFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncFoamCase): variant of `FoamCase` with asynchronous methods for running multiple cases at once.
26
32
  * [`AsyncSlurmFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncSlurmFoamCase): subclass of `AsyncFoamCase` used for running cases on a Slurm cluster.
@@ -1,6 +1,6 @@
1
1
  """A Python interface for interacting with OpenFOAM."""
2
2
 
3
- __version__ = "0.7.0"
3
+ __version__ = "0.7.1"
4
4
 
5
5
  from ._cases import (
6
6
  AsyncFoamCase,
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import array
4
+ import re
4
5
  import sys
5
6
  from typing import Tuple, Union, cast
6
7
 
@@ -28,10 +29,10 @@ from pyparsing import (
28
29
  ParserElement,
29
30
  ParseResults,
30
31
  QuotedString,
32
+ Regex,
31
33
  Word,
32
34
  common,
33
35
  counted_array,
34
- cpp_style_comment,
35
36
  identchars,
36
37
  printables,
37
38
  )
@@ -56,6 +57,59 @@ def _list_of(entry: ParserElement) -> ParserElement:
56
57
  )
57
58
 
58
59
 
60
+ def _counted_tensor_list(*, size: int, ignore: Regex) -> ParserElement:
61
+ float_pattern = r"[+-]?((\d+\.?\d*(e[+-]?\d+)?)|nan|inf(inity)?)"
62
+ ignore_pattern = rf"(?:{ignore.re.pattern}|\s)+"
63
+
64
+ if size == 1:
65
+ tensor_pattern = float_pattern
66
+ tensor = common.ieee_float
67
+ else:
68
+ tensor_pattern = rf"\((?:{ignore_pattern})?(?:{float_pattern}{ignore_pattern}){{{size - 1}}}{float_pattern}(?:{ignore_pattern})?\)"
69
+ tensor = (
70
+ Literal("(").suppress()
71
+ + Group(common.ieee_float[size], aslist=True)
72
+ + Literal(")").suppress()
73
+ )
74
+
75
+ list_ = Forward()
76
+
77
+ def count_parse_action(tks: ParseResults) -> None:
78
+ nonlocal list_
79
+ length = tks[0]
80
+ assert isinstance(length, int)
81
+
82
+ list_ <<= Regex(
83
+ rf"\((?:{ignore_pattern})?(?:{tensor_pattern}{ignore_pattern}){{{length - 1}}}{tensor_pattern}(?:{ignore_pattern})?\)",
84
+ re.IGNORECASE,
85
+ )
86
+
87
+ count = common.integer.add_parse_action(count_parse_action)
88
+
89
+ def list_parse_action(
90
+ tks: ParseResults,
91
+ ) -> list[list[float]] | list[list[list[float]]]:
92
+ values = (
93
+ re.sub(ignore.re, " ", tks[0]).replace("(", " ").replace(")", " ").split()
94
+ )
95
+
96
+ if size == 1:
97
+ return [[float(v) for v in values]]
98
+
99
+ return [
100
+ [
101
+ [float(v) for v in values[i : i + size]]
102
+ for i in range(0, len(values), size)
103
+ ]
104
+ ]
105
+
106
+ list_.add_parse_action(list_parse_action)
107
+
108
+ return (count.suppress() + list_) | (
109
+ common.integer + Literal("{").suppress() + tensor + Literal("}").suppress()
110
+ ).set_parse_action(lambda tks: [[tks[1]] * tks[0]])
111
+
112
+
59
113
  def _keyword_entry_of(
60
114
  keyword: ParserElement,
61
115
  data_entries: ParserElement,
@@ -96,6 +150,9 @@ def _unpack_binary_field(
96
150
  return [values]
97
151
 
98
152
 
153
+ # https://github.com/pyparsing/pyparsing/pull/584
154
+ _COMMENT = Regex(r"(?:/\*(?:[^*]|\*(?!/))*\*/)|(?://(?:\\\n|[^\n])*)")
155
+
99
156
  _IDENTCHARS = identchars + "$"
100
157
  _IDENTBODYCHARS = (
101
158
  printables.replace(";", "")
@@ -124,7 +181,7 @@ _DIMENSIONS = (
124
181
  _TENSOR = common.ieee_float | (
125
182
  Literal("(").suppress()
126
183
  + Group(
127
- common.ieee_float[9] | common.ieee_float[6] | common.ieee_float[3], aslist=True
184
+ common.ieee_float[3] | common.ieee_float[6] | common.ieee_float[9], aslist=True
128
185
  )
129
186
  + Literal(")").suppress()
130
187
  )
@@ -145,7 +202,7 @@ _FIELD = (Keyword("uniform", _IDENTBODYCHARS).suppress() + _TENSOR) | (
145
202
  Literal("scalar").suppress()
146
203
  + Literal(">").suppress()
147
204
  + (
148
- _list_of(common.ieee_float)
205
+ _counted_tensor_list(size=1, ignore=_COMMENT)
149
206
  | (
150
207
  (
151
208
  (
@@ -169,11 +226,7 @@ _FIELD = (Keyword("uniform", _IDENTBODYCHARS).suppress() + _TENSOR) | (
169
226
  Literal("vector").suppress()
170
227
  + Literal(">").suppress()
171
228
  + (
172
- _list_of(
173
- Literal("(").suppress()
174
- + Group(common.ieee_float[3], aslist=True)
175
- + Literal(")").suppress()
176
- )
229
+ _counted_tensor_list(size=3, ignore=_COMMENT)
177
230
  | (
178
231
  (
179
232
  (
@@ -194,14 +247,10 @@ _FIELD = (Keyword("uniform", _IDENTBODYCHARS).suppress() + _TENSOR) | (
194
247
  )
195
248
  )
196
249
  | (
197
- Literal("vector").suppress()
250
+ Literal("symmTensor").suppress()
198
251
  + Literal(">").suppress()
199
252
  + (
200
- _list_of(
201
- Literal("(").suppress()
202
- + Group(common.ieee_float[6], aslist=True)
203
- + Literal(")").suppress()
204
- )
253
+ _counted_tensor_list(size=6, ignore=_COMMENT)
205
254
  | (
206
255
  (
207
256
  (
@@ -225,11 +274,7 @@ _FIELD = (Keyword("uniform", _IDENTBODYCHARS).suppress() + _TENSOR) | (
225
274
  Literal("tensor").suppress()
226
275
  + Literal(">").suppress()
227
276
  + (
228
- _list_of(
229
- Literal("(").suppress()
230
- + Group(common.ieee_float[9], aslist=True)
231
- + Literal(")").suppress()
232
- )
277
+ _counted_tensor_list(size=9, ignore=_COMMENT)
233
278
  | (
234
279
  (
235
280
  (
@@ -254,8 +299,12 @@ _FIELD = (Keyword("uniform", _IDENTBODYCHARS).suppress() + _TENSOR) | (
254
299
  )
255
300
  _TOKEN = QuotedString('"', unquote_results=False) | _IDENTIFIER
256
301
  DATA = Forward()
257
- KEYWORD = _TOKEN | _list_of(_IDENTIFIER).set_parse_action(
258
- lambda tks: "(" + " ".join(tks[0]) + ")"
302
+ KEYWORD = (
303
+ _TOKEN
304
+ | _list_of(_IDENTIFIER)
305
+ .set_parse_action(lambda tks: "(" + " ".join(tks[0]) + ")")
306
+ .ignore(_COMMENT)
307
+ .parse_with_tabs()
259
308
  )
260
309
  _KEYWORD_ENTRY = Dict(Group(_keyword_entry_of(KEYWORD, DATA)), asdict=True)
261
310
  _DATA_ENTRY = Forward()
@@ -264,25 +313,20 @@ _LIST = _list_of(_LIST_ENTRY)
264
313
  _NUMBER = common.signed_integer ^ common.ieee_float
265
314
  _DATA_ENTRY <<= _FIELD | _LIST | _DIMENSIONED | _DIMENSIONS | _NUMBER | _SWITCH | _TOKEN
266
315
 
267
- DATA <<= _DATA_ENTRY[1, ...].set_parse_action(
268
- lambda tks: tuple(tks) if len(tks) > 1 else [tks[0]]
316
+ DATA <<= (
317
+ _DATA_ENTRY[1, ...]
318
+ .set_parse_action(lambda tks: tuple(tks) if len(tks) > 1 else [tks[0]])
319
+ .ignore(_COMMENT)
320
+ .parse_with_tabs()
269
321
  )
270
322
 
271
323
  _FILE = (
272
324
  Dict(
273
325
  Group(_keyword_entry_of(KEYWORD, Opt(DATA, default=""), located=True))[...]
274
- + Opt(
275
- Group(
276
- Located(
277
- _DATA_ENTRY[1, ...].set_parse_action(
278
- lambda tks: [None, tuple(tks) if len(tks) > 1 else tks[0]]
279
- )
280
- )
281
- )
282
- )
326
+ + Opt(Group(Located(DATA.copy().add_parse_action(lambda tks: ["", tks[0]]))))
283
327
  + Group(_keyword_entry_of(KEYWORD, Opt(DATA, default=""), located=True))[...]
284
328
  )
285
- .ignore(cpp_style_comment)
329
+ .ignore(_COMMENT)
286
330
  .ignore(Literal("#include") + ... + LineEnd()) # type: ignore [no-untyped-call]
287
331
  .parse_with_tabs()
288
332
  )
@@ -317,7 +361,8 @@ class Parsed(Mapping[Tuple[str, ...], Union[DataEntry, EllipsisType]]):
317
361
  end = parse_result.locn_end
318
362
  assert isinstance(end, int)
319
363
  keyword, *data = item
320
- if keyword is None:
364
+ assert isinstance(keyword, str)
365
+ if not keyword:
321
366
  assert not _keywords
322
367
  assert len(data) == 1
323
368
  assert not isinstance(data[0], ParseResults)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.7.0
3
+ Version: 0.7.1
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
@@ -69,13 +69,19 @@ Requires-Dist: foamlib[docs]; extra == "dev"
69
69
  [![Docker](https://github.com/gerlero/foamlib/actions/workflows/docker.yml/badge.svg)](https://github.com/gerlero/foamlib/actions/workflows/docker.yml)
70
70
  [![Docker image](https://img.shields.io/badge/docker%20image-microfluidica%2Ffoamlib-0085a0)](https://hub.docker.com/r/microfluidica/foamlib/)
71
71
 
72
- ## 👋 Basics
72
+ **foamlib** provides a simple, modern, ergonomic and fast Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
73
+
74
+ <p align="center">
75
+ <img alt="benchmark" src="https://github.com/gerlero/foamlib/raw/main/benchmark.png" height="250">
76
+ <br>
77
+ <i>Parsing a </i>volVectorField<i> with 200k cells.</i>
78
+ </p>
73
79
 
74
- **foamlib** provides a simple, modern and ergonomic Python interface for interacting with [OpenFOAM](https://www.openfoam.com).
80
+ ## 👋 Basics
75
81
 
76
- It offers the following Python classes:
82
+ **foamlib** offers the following Python classes:
77
83
 
78
- * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser. Supports ASCII and binary field formats (with or without compression).
84
+ * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser and in-place editor. Supports ASCII and binary field formats (with or without compression).
79
85
  * [`FoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.FoamCase): a class for configuring, running, and accessing the results of OpenFOAM cases.
80
86
  * [`AsyncFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncFoamCase): variant of `FoamCase` with asynchronous methods for running multiple cases at once.
81
87
  * [`AsyncSlurmFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncSlurmFoamCase): subclass of `AsyncFoamCase` used for running cases on a Slurm cluster.
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