foamlib 0.6.1__py3-none-any.whl → 0.6.3__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 CHANGED
@@ -1,21 +1,23 @@
1
1
  """A Python interface for interacting with OpenFOAM."""
2
2
 
3
- __version__ = "0.6.1"
3
+ __version__ = "0.6.3"
4
4
 
5
5
  from ._cases import (
6
6
  AsyncFoamCase,
7
7
  CalledProcessError,
8
8
  FoamCase,
9
9
  FoamCaseBase,
10
+ FoamCaseRunBase,
10
11
  )
11
12
  from ._files import FoamFieldFile, FoamFile, FoamFileBase
12
13
 
13
14
  __all__ = [
14
- "FoamCase",
15
15
  "AsyncFoamCase",
16
- "FoamCaseBase",
16
+ "CalledProcessError",
17
17
  "FoamFile",
18
+ "FoamCase",
19
+ "FoamCaseRunBase",
18
20
  "FoamFieldFile",
21
+ "FoamCaseBase",
19
22
  "FoamFileBase",
20
- "CalledProcessError",
21
23
  ]
@@ -1,11 +1,13 @@
1
1
  from ._async import AsyncFoamCase
2
2
  from ._base import FoamCaseBase
3
+ from ._run import FoamCaseRunBase
3
4
  from ._subprocess import CalledProcessError
4
5
  from ._sync import FoamCase
5
6
 
6
7
  __all__ = [
7
- "FoamCaseBase",
8
- "FoamCase",
9
8
  "AsyncFoamCase",
9
+ "FoamCaseBase",
10
+ "FoamCaseRunBase",
10
11
  "CalledProcessError",
12
+ "FoamCase",
11
13
  ]
foamlib/_cases/_async.py CHANGED
@@ -3,7 +3,7 @@ import multiprocessing
3
3
  import os
4
4
  import sys
5
5
  from contextlib import asynccontextmanager
6
- from typing import Any, Callable, Optional, TypeVar, Union
6
+ from typing import Any, Callable, Optional, TypeVar, Union, overload
7
7
 
8
8
  if sys.version_info >= (3, 9):
9
9
  from collections.abc import (
@@ -23,6 +23,8 @@ else:
23
23
 
24
24
  import aioshutil
25
25
 
26
+ from .._files import FoamFieldFile
27
+ from ._base import FoamCaseBase
26
28
  from ._run import FoamCaseRunBase
27
29
  from ._subprocess import run_async
28
30
  from ._util import ValuedGenerator, awaitableasynccontextmanager
@@ -42,9 +44,25 @@ class AsyncFoamCase(FoamCaseRunBase):
42
44
  :param path: The path to the case directory.
43
45
  """
44
46
 
47
+ class TimeDirectory(FoamCaseRunBase.TimeDirectory):
48
+ @property
49
+ def _case(self) -> "AsyncFoamCase":
50
+ return AsyncFoamCase(self.path.parent)
51
+
52
+ async def cell_centers(self) -> FoamFieldFile:
53
+ """Write and return the cell centers."""
54
+ calls = ValuedGenerator(self._cell_centers_calls())
55
+
56
+ for coro in calls:
57
+ await coro
58
+
59
+ return calls.value
60
+
45
61
  max_cpus = multiprocessing.cpu_count()
46
62
  """
47
- Maximum number of CPUs to use for running `AsyncFoamCase`s concurrently. Defaults to the number of CPUs on the system.
63
+ Maximum number of CPUs to use for running instances of `AsyncFoamCase` concurrently.
64
+
65
+ Defaults to the number of CPUs on the system.
48
66
  """
49
67
 
50
68
  _reserved_cpus = 0
@@ -106,6 +124,23 @@ class AsyncFoamCase(FoamCaseRunBase):
106
124
  for coro in self._clean_calls(check=check):
107
125
  await coro
108
126
 
127
+ @overload
128
+ def __getitem__(
129
+ self, index: Union[int, float, str]
130
+ ) -> "AsyncFoamCase.TimeDirectory": ...
131
+
132
+ @overload
133
+ def __getitem__(self, index: slice) -> Sequence["AsyncFoamCase.TimeDirectory"]: ...
134
+
135
+ def __getitem__(
136
+ self, index: Union[int, slice, float, str]
137
+ ) -> Union["AsyncFoamCase.TimeDirectory", Sequence["AsyncFoamCase.TimeDirectory"]]:
138
+ ret = super().__getitem__(index)
139
+ if isinstance(ret, FoamCaseBase.TimeDirectory):
140
+ return AsyncFoamCase.TimeDirectory(ret)
141
+ else:
142
+ return [AsyncFoamCase.TimeDirectory(r) for r in ret]
143
+
109
144
  async def run(
110
145
  self,
111
146
  cmd: Optional[Union[Sequence[Union[str, "os.PathLike[str]"]], str]] = None,
foamlib/_cases/_base.py CHANGED
@@ -40,6 +40,10 @@ class FoamCaseBase(Sequence["FoamCaseBase.TimeDirectory"]):
40
40
  def __init__(self, path: Union["os.PathLike[str]", str]):
41
41
  self.path = Path(path).absolute()
42
42
 
43
+ @property
44
+ def _case(self) -> "FoamCaseBase":
45
+ return FoamCaseBase(self.path.parent)
46
+
43
47
  @property
44
48
  def time(self) -> float:
45
49
  """The time that corresponds to this directory."""
@@ -58,7 +62,7 @@ class FoamCaseBase(Sequence["FoamCaseBase.TimeDirectory"]):
58
62
 
59
63
  def __contains__(self, obj: object) -> bool:
60
64
  if isinstance(obj, FoamFieldFile):
61
- return obj.path.parent == self.path
65
+ return obj.path.parent == self.path and obj.path.is_file()
62
66
  elif isinstance(obj, str):
63
67
  return (self.path / obj).is_file() or (
64
68
  self.path / f"{obj}.gz"
foamlib/_cases/_run.py CHANGED
@@ -40,11 +40,34 @@ if sys.version_info >= (3, 11):
40
40
  else:
41
41
  from typing_extensions import Self
42
42
 
43
+ from .._files import FoamFieldFile
43
44
  from ._base import FoamCaseBase
44
45
  from ._subprocess import DEVNULL, STDOUT
45
46
 
46
47
 
47
48
  class FoamCaseRunBase(FoamCaseBase):
49
+ class TimeDirectory(FoamCaseBase.TimeDirectory):
50
+ @abstractmethod
51
+ def cell_centers(
52
+ self,
53
+ ) -> Union[FoamFieldFile, Coroutine[None, None, FoamFieldFile]]:
54
+ raise NotImplementedError
55
+
56
+ @property
57
+ @abstractmethod
58
+ def _case(self) -> "FoamCaseRunBase":
59
+ raise NotImplementedError
60
+
61
+ def _cell_centers_calls(self) -> Generator[Any, None, FoamFieldFile]:
62
+ ret = self["C"]
63
+
64
+ if ret not in self:
65
+ yield self._case.run(
66
+ ["postProcess", "-func", "writeCellCentres", "-time", self.name]
67
+ )
68
+
69
+ return ret
70
+
48
71
  def __delitem__(self, key: Union[int, float, str]) -> None:
49
72
  shutil.rmtree(self[key].path)
50
73
 
@@ -177,7 +200,7 @@ class FoamCaseRunBase(FoamCaseBase):
177
200
 
178
201
  return script
179
202
 
180
- def __run_script(self, *, parallel: Optional[bool] = None) -> Optional[Path]:
203
+ def __run_script(self, *, parallel: Optional[bool]) -> Optional[Path]:
181
204
  """Return the path to the (All)run script, or None if no run script is found."""
182
205
  run = self.path / "run"
183
206
  run_parallel = self.path / "run-parallel"
@@ -263,7 +286,7 @@ class FoamCaseRunBase(FoamCaseBase):
263
286
 
264
287
  return type(self)(dst)
265
288
 
266
- def _clean_calls(self, *, check: bool = False) -> Generator[Any, None, None]:
289
+ def _clean_calls(self, *, check: bool) -> Generator[Any, None, None]:
267
290
  script_path = self.__clean_script()
268
291
 
269
292
  if script_path is not None:
@@ -299,10 +322,10 @@ class FoamCaseRunBase(FoamCaseBase):
299
322
  self,
300
323
  cmd: Optional[Union[Sequence[Union[str, "os.PathLike[str]"]], str]] = None,
301
324
  *,
302
- parallel: Optional[bool] = None,
303
- cpus: Optional[int] = None,
304
- check: bool = True,
305
- log: bool = True,
325
+ parallel: Optional[bool],
326
+ cpus: Optional[int],
327
+ check: bool,
328
+ log: bool,
306
329
  ) -> Generator[Any, None, None]:
307
330
  if cmd is not None:
308
331
  if parallel:
foamlib/_cases/_sync.py CHANGED
@@ -3,13 +3,7 @@ import shutil
3
3
  import sys
4
4
  from pathlib import Path
5
5
  from types import TracebackType
6
- from typing import (
7
- Any,
8
- Callable,
9
- Optional,
10
- Type,
11
- Union,
12
- )
6
+ from typing import Any, Callable, Optional, Type, Union, overload
13
7
 
14
8
  if sys.version_info >= (3, 9):
15
9
  from collections.abc import Collection, Sequence
@@ -21,6 +15,8 @@ if sys.version_info >= (3, 11):
21
15
  else:
22
16
  from typing_extensions import Self
23
17
 
18
+ from .._files import FoamFieldFile
19
+ from ._base import FoamCaseBase
24
20
  from ._run import FoamCaseRunBase
25
21
  from ._subprocess import run_sync
26
22
  from ._util import ValuedGenerator
@@ -37,6 +33,22 @@ class FoamCase(FoamCaseRunBase):
37
33
  :param path: The path to the case directory.
38
34
  """
39
35
 
36
+ class TimeDirectory(FoamCaseRunBase.TimeDirectory):
37
+ @property
38
+ def _case(self) -> "FoamCase":
39
+ return FoamCase(self.path.parent)
40
+
41
+ def cell_centers(self) -> FoamFieldFile:
42
+ """Write and return the cell centers."""
43
+ calls = ValuedGenerator(self._cell_centers_calls())
44
+
45
+ for _ in calls:
46
+ pass
47
+
48
+ print(calls.value)
49
+
50
+ return calls.value
51
+
40
52
  def __init__(self, path: Union["os.PathLike[str]", str] = Path()):
41
53
  super().__init__(path)
42
54
 
@@ -67,6 +79,23 @@ class FoamCase(FoamCaseRunBase):
67
79
  ) -> None:
68
80
  shutil.copytree(src, dest, symlinks=symlinks, ignore=ignore)
69
81
 
82
+ @overload
83
+ def __getitem__(
84
+ self, index: Union[int, float, str]
85
+ ) -> "FoamCase.TimeDirectory": ...
86
+
87
+ @overload
88
+ def __getitem__(self, index: slice) -> Sequence["FoamCase.TimeDirectory"]: ...
89
+
90
+ def __getitem__(
91
+ self, index: Union[int, slice, float, str]
92
+ ) -> Union["FoamCase.TimeDirectory", Sequence["FoamCase.TimeDirectory"]]:
93
+ ret = super().__getitem__(index)
94
+ if isinstance(ret, FoamCaseBase.TimeDirectory):
95
+ return FoamCase.TimeDirectory(ret)
96
+ else:
97
+ return [FoamCase.TimeDirectory(r) for r in ret]
98
+
70
99
  def __enter__(self) -> Self:
71
100
  return self
72
101
 
@@ -105,7 +134,9 @@ class FoamCase(FoamCaseRunBase):
105
134
  :param check: If True, raise a CalledProcessError if any command returns a non-zero exit code.
106
135
  :param log: If True, log the command output to a file.
107
136
  """
108
- for _ in self._run_calls(cmd=cmd, parallel=parallel, check=check):
137
+ for _ in self._run_calls(
138
+ cmd=cmd, parallel=parallel, cpus=cpus, check=check, log=log
139
+ ):
109
140
  pass
110
141
 
111
142
  def block_mesh(self, *, check: bool = True) -> None:
foamlib/_files/_io.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import gzip
2
+ import os
2
3
  import sys
3
4
  from copy import deepcopy
4
5
  from pathlib import Path
@@ -19,7 +20,7 @@ from ._parsing import Parsed
19
20
 
20
21
 
21
22
  class FoamFileIO:
22
- def __init__(self, path: Union[str, Path]) -> None:
23
+ def __init__(self, path: Union["os.PathLike[str]", str]) -> None:
23
24
  self.path = Path(path).absolute()
24
25
 
25
26
  self.__contents: Optional[bytes] = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.6.1
3
+ Version: 0.6.3
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
@@ -0,0 +1,21 @@
1
+ foamlib/__init__.py,sha256=NChr4kydPt4FTxbO3l08Wo5RiKAPgfjfQsBsePeLjGo,436
2
+ foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ foamlib/_cases/__init__.py,sha256=eZXDwGfW_vNHx3pP2kwG1Z0NUUtnjUmvaSRdSGeWcVo,293
4
+ foamlib/_cases/_async.py,sha256=v-oMQffE0tj6MSCiCKeIAOnDKBoQGCru59SmyULlO-c,7585
5
+ foamlib/_cases/_base.py,sha256=4VWsu22VockyKgU_5tnSMeNrAkMgBKwZo2KGkV65rRQ,6739
6
+ foamlib/_cases/_run.py,sha256=oDE4FoLanS8XyPbCdr3gvKTkMcovDv4hBca2CTm-6qQ,12964
7
+ foamlib/_cases/_subprocess.py,sha256=GTmHWy1LRD9ujpXJfSTXU2bf87GncpIA0VOR1rQW2fg,3633
8
+ foamlib/_cases/_sync.py,sha256=1KssR__g9vR7JWCL0a0o3wa7U6YsJ1XUzK6YnKkMQ50,5873
9
+ foamlib/_cases/_util.py,sha256=GNndpqw3Jg_S-Hxzl5vwRgD0czcTNb9NYHMhcfBoMBg,1493
10
+ foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
11
+ foamlib/_files/_base.py,sha256=zaFDjLE6jB7WtGWk8hfKusjLtlGu6CZV16AHJpRUibs,1929
12
+ foamlib/_files/_files.py,sha256=DxM5JmXv19PJrqlKNwuP6SsB0nye6aN1hiPwble7fFM,15657
13
+ foamlib/_files/_io.py,sha256=T8vTEmJDidL03qeX1PUJFND-_vaF0AuC_0lE_zxLz7Q,2447
14
+ foamlib/_files/_parsing.py,sha256=DzgJ53QnohRQyLXn2zOs52RIQ7bJ_fS_S2Z7rmRyVK4,9023
15
+ foamlib/_files/_serialization.py,sha256=pb8_cIVgRhGS_ZV2p3x8p5_lK1SS6xzQHscAYYuOgFY,3407
16
+ foamlib/_files/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
17
+ foamlib-0.6.3.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
18
+ foamlib-0.6.3.dist-info/METADATA,sha256=xn_MMu25aIOdq1LCNKkXjb2-qn1v-FxE07BUCH87rU0,6338
19
+ foamlib-0.6.3.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
20
+ foamlib-0.6.3.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
21
+ foamlib-0.6.3.dist-info/RECORD,,
@@ -1,21 +0,0 @@
1
- foamlib/__init__.py,sha256=BVCe7vPVevu5BHTZMwbL8VQEQCStIT_j_p_4bGfVW1A,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=8x8Mkql6XPzMjH4t-NszAEDx4gpjNPnQiWxFkHrcFJU,6436
5
- foamlib/_cases/_base.py,sha256=1CUkkK4afBxDgP79dmho97WJdj-GLgYhnrCSf_52Eao,6604
6
- foamlib/_cases/_run.py,sha256=0xu5V3qvWnXYJvOh0GV8DM1gOiNc65frWJF3mviHPOM,12307
7
- foamlib/_cases/_subprocess.py,sha256=GTmHWy1LRD9ujpXJfSTXU2bf87GncpIA0VOR1rQW2fg,3633
8
- foamlib/_cases/_sync.py,sha256=PzwciC4kFfenlG0XOtbBMxd9EuQBChwxZGA3RDlmWXM,4752
9
- foamlib/_cases/_util.py,sha256=GNndpqw3Jg_S-Hxzl5vwRgD0czcTNb9NYHMhcfBoMBg,1493
10
- foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
11
- foamlib/_files/_base.py,sha256=zaFDjLE6jB7WtGWk8hfKusjLtlGu6CZV16AHJpRUibs,1929
12
- foamlib/_files/_files.py,sha256=DxM5JmXv19PJrqlKNwuP6SsB0nye6aN1hiPwble7fFM,15657
13
- foamlib/_files/_io.py,sha256=uSh5XlgukwJkQSLELa4mshRD2aTajNk5vr_ZsBImSeU,2423
14
- foamlib/_files/_parsing.py,sha256=DzgJ53QnohRQyLXn2zOs52RIQ7bJ_fS_S2Z7rmRyVK4,9023
15
- foamlib/_files/_serialization.py,sha256=pb8_cIVgRhGS_ZV2p3x8p5_lK1SS6xzQHscAYYuOgFY,3407
16
- foamlib/_files/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
17
- foamlib-0.6.1.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
18
- foamlib-0.6.1.dist-info/METADATA,sha256=wCN0T5tNyAtSUx5k8ehwqjX05fJDV_vBbw4j-pTqNbI,6338
19
- foamlib-0.6.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
20
- foamlib-0.6.1.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
21
- foamlib-0.6.1.dist-info/RECORD,,