foamlib 0.6.2__tar.gz → 0.6.3__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 (26) hide show
  1. {foamlib-0.6.2 → foamlib-0.6.3}/PKG-INFO +1 -1
  2. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/__init__.py +6 -4
  3. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_cases/__init__.py +4 -2
  4. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_cases/_async.py +37 -2
  5. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_cases/_base.py +5 -1
  6. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_cases/_run.py +23 -0
  7. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_cases/_sync.py +36 -7
  8. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_files/_io.py +2 -1
  9. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib.egg-info/PKG-INFO +1 -1
  10. {foamlib-0.6.2 → foamlib-0.6.3}/LICENSE.txt +0 -0
  11. {foamlib-0.6.2 → foamlib-0.6.3}/README.md +0 -0
  12. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_cases/_subprocess.py +0 -0
  13. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_cases/_util.py +0 -0
  14. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_files/__init__.py +0 -0
  15. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_files/_base.py +0 -0
  16. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_files/_files.py +0 -0
  17. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_files/_parsing.py +0 -0
  18. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_files/_serialization.py +0 -0
  19. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/_files/_util.py +0 -0
  20. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib/py.typed +0 -0
  21. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib.egg-info/SOURCES.txt +0 -0
  22. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib.egg-info/dependency_links.txt +0 -0
  23. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib.egg-info/requires.txt +0 -0
  24. {foamlib-0.6.2 → foamlib-0.6.3}/foamlib.egg-info/top_level.txt +0 -0
  25. {foamlib-0.6.2 → foamlib-0.6.3}/pyproject.toml +0 -0
  26. {foamlib-0.6.2 → foamlib-0.6.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.6.2
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
@@ -1,21 +1,23 @@
1
1
  """A Python interface for interacting with OpenFOAM."""
2
2
 
3
- __version__ = "0.6.2"
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
  ]
@@ -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,
@@ -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"
@@ -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
 
@@ -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
 
@@ -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.2
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes