foamlib 0.4.3__py3-none-any.whl → 0.5.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.
@@ -29,6 +29,7 @@ from pyparsing import (
29
29
  Word,
30
30
  c_style_comment,
31
31
  common,
32
+ counted_array,
32
33
  cpp_style_comment,
33
34
  identchars,
34
35
  printables,
@@ -42,12 +43,13 @@ def _list_of(entry: ParserElement) -> ParserElement:
42
43
  Literal("List") + Literal("<") + common.identifier + Literal(">")
43
44
  ).suppress() + (
44
45
  (
45
- Opt(common.integer).suppress()
46
- + (
47
- Literal("(").suppress()
48
- + Group((entry)[...], aslist=True)
49
- + Literal(")").suppress()
50
- )
46
+ counted_array(entry, common.integer + Literal("(").suppress())
47
+ + Literal(")").suppress()
48
+ ).set_parse_action(lambda tks: [tks.as_list()])
49
+ | (
50
+ Literal("(").suppress()
51
+ + Group((entry)[...], aslist=True)
52
+ + Literal(")").suppress()
51
53
  )
52
54
  | (
53
55
  common.integer + Literal("{").suppress() + entry + Literal("}").suppress()
@@ -76,54 +78,59 @@ def _keyword_entry_of(
76
78
  return keyword_entry
77
79
 
78
80
 
79
- _binary_contents = Forward()
80
-
81
-
82
- def _binary_field_parse_action(tks: ParseResults) -> None:
83
- global _binary_contents
84
-
85
- kind, count = tks
86
- if kind == "scalar":
87
- elsize = 1
88
- elif kind == "vector":
89
- elsize = 3
90
- elif kind == "symmTensor":
91
- elsize = 6
92
- elif kind == "tensor":
93
- elsize = 9
94
-
95
- def unpack(
96
- tks: ParseResults,
97
- ) -> Sequence[Union[Sequence[float], Sequence[Sequence[float]]]]:
98
- bytes_ = tks[0].encode("latin-1")
99
-
100
- arr = array.array("d", bytes_)
81
+ def _unpack_binary_field(
82
+ tks: ParseResults,
83
+ ) -> Sequence[Union[Sequence[float], Sequence[Sequence[float]]]]:
84
+ elsize = len(tks[0]) // 8
101
85
 
102
- if elsize != 1:
103
- all = [arr[i : i + elsize].tolist() for i in range(0, len(arr), elsize)]
104
- else:
105
- all = arr.tolist()
86
+ arr = array.array("d", "".join(tks).encode("latin-1"))
106
87
 
107
- return [all]
88
+ all: Union[Sequence[float], Sequence[Sequence[float]]]
108
89
 
109
- _binary_contents <<= CharsNotIn(exact=count * elsize * 8).set_parse_action(unpack)
90
+ if elsize != 1:
91
+ all = [arr[i : i + elsize].tolist() for i in range(0, len(arr), elsize)]
92
+ else:
93
+ all = arr.tolist()
110
94
 
111
- tks.clear() # type: ignore [no-untyped-call]
95
+ return [all]
112
96
 
113
97
 
114
98
  _BINARY_FIELD = (
115
- (
116
- Keyword("nonuniform").suppress()
117
- + Literal("List").suppress()
118
- + Literal("<").suppress()
119
- + common.identifier
120
- + Literal(">").suppress()
121
- + common.integer
122
- + Literal("(").suppress()
123
- ).set_parse_action(_binary_field_parse_action, call_during_try=True)
124
- + _binary_contents
99
+ Keyword("nonuniform").suppress()
100
+ + Literal("List").suppress()
101
+ + Literal("<").suppress()
102
+ + (
103
+ counted_array(
104
+ CharsNotIn(exact=8),
105
+ Literal("scalar").suppress()
106
+ + Literal(">").suppress()
107
+ + common.integer
108
+ + Literal("(").suppress(),
109
+ )
110
+ | counted_array(
111
+ CharsNotIn(exact=8 * 3),
112
+ Literal("vector").suppress()
113
+ + Literal(">").suppress()
114
+ + common.integer
115
+ + Literal("(").suppress(),
116
+ )
117
+ | counted_array(
118
+ CharsNotIn(exact=8 * 6),
119
+ Literal("symmTensor").suppress()
120
+ + Literal(">").suppress()
121
+ + common.integer
122
+ + Literal("(").suppress(),
123
+ )
124
+ | counted_array(
125
+ CharsNotIn(exact=8 * 9),
126
+ Literal("tensor").suppress()
127
+ + Literal(">").suppress()
128
+ + common.integer
129
+ + Literal("(").suppress(),
130
+ )
131
+ )
125
132
  + Literal(")").suppress()
126
- )
133
+ ).set_parse_action(_unpack_binary_field)
127
134
 
128
135
 
129
136
  _SWITCH = (
@@ -8,8 +8,8 @@ if sys.version_info >= (3, 9):
8
8
  else:
9
9
  from typing import Mapping
10
10
 
11
- from .._util import is_sequence
12
11
  from ._base import FoamFileBase
12
+ from ._util import is_sequence
13
13
 
14
14
  try:
15
15
  import numpy as np
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.4.3
3
+ Version: 0.5.0
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
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.9
19
19
  Classifier: Programming Language :: Python :: 3.10
20
20
  Classifier: Programming Language :: Python :: 3.11
21
21
  Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
22
23
  Classifier: Topic :: Scientific/Engineering
23
24
  Classifier: Topic :: Software Development
24
25
  Classifier: Typing :: Typed
@@ -67,9 +68,9 @@ Requires-Dist: mypy <2,>=1 ; extra == 'typing'
67
68
 
68
69
  It offers the following classes:
69
70
 
70
- * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser. Supports both ASCII and binary field formats.
71
- * [`FoamCase`](https://foamlib.readthedocs.io/en/stable/#foamlib.FoamCase): a class for manipulating, executing and accessing the results of OpenFOAM cases.
72
- * [`AsyncFoamCase`](https://foamlib.readthedocs.io/en/stable/#foamlib.AsyncFoamCase): variant of `FoamCase` with asynchronous methods for running multiple cases at once.
71
+ * [`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 both ASCII and binary field formats.
72
+ * [`FoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.FoamCase): a class for manipulating, executing and accessing the results of OpenFOAM cases.
73
+ * [`AsyncFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncFoamCase): variant of `FoamCase` with asynchronous methods for running multiple cases at once.
73
74
 
74
75
  ## Get started
75
76
 
@@ -123,6 +124,14 @@ my_pitz.clean()
123
124
  my_pitz.control_dict["writeInterval"] = 10
124
125
  ```
125
126
 
127
+ ### Make multiple file reads and writes in a single go
128
+
129
+ ```python
130
+ with my_pitz.fv_schemes as f:
131
+ f["gradSchemes"]["default"] = f["divSchemes"]["default"]
132
+ f["snGradSchemes"]["default"] = "uncorrected"
133
+ ```
134
+
126
135
  ### Run a case asynchronously
127
136
 
128
137
  ```python
@@ -131,7 +140,6 @@ from foamlib import AsyncFoamCase
131
140
 
132
141
  async def run_case():
133
142
  my_pitz_async = AsyncFoamCase(my_pitz)
134
-
135
143
  await my_pitz_async.run()
136
144
 
137
145
  asyncio.run(run_case())
@@ -0,0 +1,21 @@
1
+ foamlib/__init__.py,sha256=VR4c4hlAQ8I180EqNsDls6vyYKbnOScayXFOr2fKAEk,392
2
+ foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ foamlib/_cases/__init__.py,sha256=C0mpRu7c-X-4uVMKmVrZhwIyhBNyvUoCv0o-BQ72RC0,236
4
+ foamlib/_cases/_async.py,sha256=QVZaYJCOaUgt0_xI_cYsZAJcdfpdZoYnh5dojTjMX08,7816
5
+ foamlib/_cases/_base.py,sha256=1CUkkK4afBxDgP79dmho97WJdj-GLgYhnrCSf_52Eao,6604
6
+ foamlib/_cases/_recipes.py,sha256=UTFnVuTvEf-9wn-Fr30a9wOOmyOxvWeDhbqBhdtbhzA,9692
7
+ foamlib/_cases/_subprocess.py,sha256=CfUy_LrqLnMLR9FHINqInCd3soN6eYvonwZ30epiLu8,2234
8
+ foamlib/_cases/_sync.py,sha256=JQAkKXwgdhR_drGy7gadun1XPGjNddKR7Y07HK-TpoA,5964
9
+ foamlib/_cases/_util.py,sha256=4jlv8pe2Ro1-ZtpY5DtR2B1Vpbj84SlqH_HzwGYPoH4,861
10
+ foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
11
+ foamlib/_files/_base.py,sha256=zaFDjLE6jB7WtGWk8hfKusjLtlGu6CZV16AHJpRUibs,1929
12
+ foamlib/_files/_files.py,sha256=6Fdrc0lksFK99i1a6wEsBi-BtYgSQnUc5s10h2LQ9ew,16091
13
+ foamlib/_files/_io.py,sha256=f_tYI7AqaFsQ8mtK__fEoIUqpYb3YmrI8X5D8updmNM,2084
14
+ foamlib/_files/_parsing.py,sha256=8V2CKZ45mKE3f9fP8lAfexIdhPGrq7elIZkpBkkGB6Q,8773
15
+ foamlib/_files/_serialization.py,sha256=pb8_cIVgRhGS_ZV2p3x8p5_lK1SS6xzQHscAYYuOgFY,3407
16
+ foamlib/_files/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
17
+ foamlib-0.5.0.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
18
+ foamlib-0.5.0.dist-info/METADATA,sha256=pecBt-ku69uh-HjSN02M40tCqhT22L-sZ9Fcf6AezwM,5759
19
+ foamlib-0.5.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
20
+ foamlib-0.5.0.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
21
+ foamlib-0.5.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.2)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,19 +0,0 @@
1
- foamlib/__init__.py,sha256=EfoThBRk5flPnxHT6JVA0jF01z42YT0I3RxCZR3fPp8,446
2
- foamlib/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
3
- foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- foamlib/_cases/__init__.py,sha256=xnQpR64EvFtCh07qnSz7kjQ1IhJXjRDwaZWwQGZhGv4,280
5
- foamlib/_cases/_async.py,sha256=ehmAedDepDXaRdf8f0IznxDMYAQxoUWSIxbhxG_17Rw,6035
6
- foamlib/_cases/_base.py,sha256=JrYJplmXV84qwgerdVSCHz2rCI-KWB4IvTBPMkYpecw,12657
7
- foamlib/_cases/_sync.py,sha256=CloQgd-93jxfSXIt7J5NxcAu3N_iF3eXMKO-NfNOgi4,4522
8
- foamlib/_cases/_util.py,sha256=v6sHxHCEgagsVuup0S1xJW-x9py5xj3bUye8PiFfb3o,925
9
- foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
10
- foamlib/_files/_base.py,sha256=zaFDjLE6jB7WtGWk8hfKusjLtlGu6CZV16AHJpRUibs,1929
11
- foamlib/_files/_files.py,sha256=-3mDRIsaQaxHF74q0Zfzlrhfieb7w_EPOFScSx8wRPE,16245
12
- foamlib/_files/_io.py,sha256=f_tYI7AqaFsQ8mtK__fEoIUqpYb3YmrI8X5D8updmNM,2084
13
- foamlib/_files/_parsing.py,sha256=ZDEnMdLfTCn82I5E-IOv-PxGv4w7N2Nvtc4NX7-m0MA,8383
14
- foamlib/_files/_serialization.py,sha256=3yb9fgjCpDoRfZoLsbZaIFrkZ3vGBzleFRw6IbaZuuY,3408
15
- foamlib-0.4.3.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
16
- foamlib-0.4.3.dist-info/METADATA,sha256=M-Cy5LK8xxGL-jEtA7jZ0p5y_7iZ-Co6yTePRg1czb0,5457
17
- foamlib-0.4.3.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
18
- foamlib-0.4.3.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
19
- foamlib-0.4.3.dist-info/RECORD,,
File without changes