cfdbender 0.4.2__tar.gz → 0.5.0__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 (104) hide show
  1. {cfdbender-0.4.2/src/cfdbender.egg-info → cfdbender-0.5.0}/PKG-INFO +3 -3
  2. {cfdbender-0.4.2 → cfdbender-0.5.0}/README.md +2 -2
  3. {cfdbender-0.4.2 → cfdbender-0.5.0}/pyproject.toml +1 -1
  4. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/__init__.py +1 -1
  5. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/adapter.py +17 -2
  6. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/executables.py +107 -4
  7. cfdbender-0.5.0/src/cfdbender/core/inputs_guide.py +139 -0
  8. cfdbender-0.5.0/src/cfdbender/core/longpath.py +106 -0
  9. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/matrix.py +32 -15
  10. cfdbender-0.5.0/src/cfdbender/core/mesh.py +125 -0
  11. cfdbender-0.5.0/src/cfdbender/core/neutral.py +170 -0
  12. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/plan.py +181 -32
  13. cfdbender-0.5.0/src/cfdbender/core/progress.py +41 -0
  14. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/registry.py +188 -29
  15. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/run.py +102 -28
  16. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/settings.py +23 -1
  17. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/workspace.py +35 -4
  18. cfdbender-0.5.0/src/cfdbender/matrix/_console.py +324 -0
  19. cfdbender-0.5.0/src/cfdbender/matrix/_journal.py +73 -0
  20. cfdbender-0.5.0/src/cfdbender/matrix/cli.py +522 -0
  21. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/matrix/collection.py +164 -23
  22. cfdbender-0.5.0/src/cfdbender/matrix/exports.py +265 -0
  23. cfdbender-0.5.0/src/cfdbender/matrix/post.py +52 -0
  24. cfdbender-0.5.0/src/cfdbender/matrix/products.py +119 -0
  25. cfdbender-0.5.0/src/cfdbender/matrix/queries.py +616 -0
  26. cfdbender-0.5.0/src/cfdbender/matrix/receipt.py +153 -0
  27. cfdbender-0.5.0/src/cfdbender/matrix/records.py +412 -0
  28. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/matrix/rerun.py +16 -1
  29. cfdbender-0.5.0/src/cfdbender/matrix/storage.py +562 -0
  30. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/matrix/submission.py +3 -1
  31. cfdbender-0.5.0/src/cfdbender/solvers/_host/_config.py +31 -0
  32. cfdbender-0.5.0/src/cfdbender/solvers/_host/_exe.py +88 -0
  33. cfdbender-0.5.0/src/cfdbender/solvers/_host/_ram.py +40 -0
  34. cfdbender-0.5.0/src/cfdbender/solvers/_host/_version.py +74 -0
  35. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/flightstream/__init__.py +3 -1
  36. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/flightstream/reader.py +1 -0
  37. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/mock/__init__.py +30 -6
  38. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/openfoam/__init__.py +45 -6
  39. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/openfoam/_config.py +144 -42
  40. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/openfoam/_execute.py +2 -1
  41. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/openfoam/_history.py +6 -5
  42. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/pyfr/__init__.py +28 -8
  43. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/pyfr/_config.py +22 -16
  44. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/pyfr/_execute.py +38 -15
  45. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/pyfr/_history.py +17 -5
  46. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/qprop/__init__.py +85 -23
  47. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/qprop/_config.py +26 -10
  48. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/qprop/_execute.py +45 -17
  49. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/qprop/_output.py +12 -2
  50. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/qprop/_polar.py +10 -4
  51. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/__init__.py +48 -11
  52. cfdbender-0.5.0/src/cfdbender/solvers/su2/_config.py +602 -0
  53. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/_execute.py +47 -18
  54. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/_history.py +90 -3
  55. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/_reference.py +2 -2
  56. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/xfoil/__init__.py +21 -2
  57. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/xfoil/_config.py +20 -7
  58. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/xfoil/_execute.py +6 -17
  59. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/xfoil/_polar.py +20 -7
  60. cfdbender-0.5.0/src/cfdbender/workspace/cli.py +180 -0
  61. {cfdbender-0.4.2 → cfdbender-0.5.0/src/cfdbender.egg-info}/PKG-INFO +3 -3
  62. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender.egg-info/SOURCES.txt +15 -0
  63. cfdbender-0.4.2/src/cfdbender/matrix/cli.py +0 -228
  64. cfdbender-0.4.2/src/cfdbender/matrix/exports.py +0 -122
  65. cfdbender-0.4.2/src/cfdbender/solvers/_host/_config.py +0 -10
  66. cfdbender-0.4.2/src/cfdbender/solvers/_host/_ram.py +0 -69
  67. cfdbender-0.4.2/src/cfdbender/solvers/su2/_config.py +0 -290
  68. cfdbender-0.4.2/src/cfdbender/workspace/cli.py +0 -99
  69. {cfdbender-0.4.2 → cfdbender-0.5.0}/LICENSE +0 -0
  70. {cfdbender-0.4.2 → cfdbender-0.5.0}/setup.cfg +0 -0
  71. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/_pyfs.py +0 -0
  72. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/__init__.py +0 -0
  73. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/flight.py +0 -0
  74. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/naming.py +0 -0
  75. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/core/results.py +0 -0
  76. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/geometry/__init__.py +0 -0
  77. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/geometry/blade_slicing.py +0 -0
  78. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/hpc/__init__.py +0 -0
  79. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/hpc/_plan.py +0 -0
  80. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/hpc/_profiles.py +0 -0
  81. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/hpc/_render.py +0 -0
  82. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/hpc/_submit.py +0 -0
  83. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/hpc/_walltime.py +0 -0
  84. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/matrix/__init__.py +0 -0
  85. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/matrix/selection.py +0 -0
  86. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/__init__.py +0 -0
  87. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/_host/__init__.py +0 -0
  88. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/_host/_execute.py +0 -0
  89. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/_host/_mesh.py +0 -0
  90. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/_host/_single.py +0 -0
  91. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/qprop/_prop.py +0 -0
  92. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/qprop/_sections.py +0 -0
  93. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/_pysu2_worker.py +0 -0
  94. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/_ram.py +0 -0
  95. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/_single.py +0 -0
  96. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/solvers/su2/routes.py +0 -0
  97. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/testing/__init__.py +0 -0
  98. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/workspace/__init__.py +0 -0
  99. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender/workspace/planning.py +0 -0
  100. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender.egg-info/dependency_links.txt +0 -0
  101. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender.egg-info/entry_points.txt +0 -0
  102. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender.egg-info/requires.txt +0 -0
  103. {cfdbender-0.4.2 → cfdbender-0.5.0}/src/cfdbender.egg-info/top_level.txt +0 -0
  104. {cfdbender-0.4.2 → cfdbender-0.5.0}/tests/test_import.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cfdbender
3
- Version: 0.4.2
3
+ Version: 0.5.0
4
4
  Summary: Solver-agnostic Python workspace for CFD studies (SU2 first)
5
5
  Author: Geovana Neves
6
6
  License-Expression: MIT
@@ -26,7 +26,7 @@ Dynamic: license-file
26
26
 
27
27
  # cfdbender
28
28
 
29
- cfdbender is an early Python project for CFD workspaces. Version 0.4.2 provides
29
+ cfdbender is an early Python project for CFD workspaces. Version 0.5.0 provides
30
30
  workspace initialization, named s/r/p matrices, read-only planning, local runs,
31
31
  neutral result collection, mock and SU2 adapters (the SU2 executable route and
32
32
  the pysu2 Python wrapper route, run in a child interpreter where the wrapper is
@@ -53,5 +53,5 @@ other solvers are on the roadmap. See the [OpenFOAM](docs/openfoam-workspaces.md
53
53
  [QPROP](docs/qprop-workspaces.md) workspace guides.
54
54
 
55
55
  See the [documentation site](https://nevesgeovana.github.io/cfdbender/) and
56
- the [workspace files](docs/workspace-files.md). This project is licensed under
56
+ the [workspace layout](docs/workspace-layout.md). This project is licensed under
57
57
  the MIT license.
@@ -1,6 +1,6 @@
1
1
  # cfdbender
2
2
 
3
- cfdbender is an early Python project for CFD workspaces. Version 0.4.2 provides
3
+ cfdbender is an early Python project for CFD workspaces. Version 0.5.0 provides
4
4
  workspace initialization, named s/r/p matrices, read-only planning, local runs,
5
5
  neutral result collection, mock and SU2 adapters (the SU2 executable route and
6
6
  the pysu2 Python wrapper route, run in a child interpreter where the wrapper is
@@ -27,5 +27,5 @@ other solvers are on the roadmap. See the [OpenFOAM](docs/openfoam-workspaces.md
27
27
  [QPROP](docs/qprop-workspaces.md) workspace guides.
28
28
 
29
29
  See the [documentation site](https://nevesgeovana.github.io/cfdbender/) and
30
- the [workspace files](docs/workspace-files.md). This project is licensed under
30
+ the [workspace layout](docs/workspace-layout.md). This project is licensed under
31
31
  the MIT license.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cfdbender"
7
- version = "0.4.2"
7
+ version = "0.5.0"
8
8
  description = "Solver-agnostic Python workspace for CFD studies (SU2 first)"
9
9
  readme = "README.md"
10
10
  authors = [{name = "Geovana Neves"}]
@@ -3,5 +3,5 @@
3
3
  Usage: ``import cfdbender as cb``.
4
4
  """
5
5
 
6
- __version__ = "0.4.2"
6
+ __version__ = "0.5.0"
7
7
  __all__ = ["__version__"]
@@ -18,7 +18,15 @@ from pathlib import Path
18
18
  from typing import Protocol, runtime_checkable
19
19
 
20
20
  from cfdbender.core.matrix import MatrixRow
21
- from cfdbender.core.plan import InputFiles, Point, RowInputs, RowRequirements, apply_variables
21
+ from cfdbender.core.mesh import resolve_setup_paths
22
+ from cfdbender.core.plan import (
23
+ InputFiles,
24
+ Point,
25
+ RowInputs,
26
+ RowRequirements,
27
+ apply_variables,
28
+ is_matrix_file,
29
+ )
22
30
  from cfdbender.core.results import Classification, ExecutionResult, NeutralResult
23
31
  from cfdbender.core.settings import read_init
24
32
 
@@ -46,6 +54,8 @@ class AdapterPoint:
46
54
  raise ValueError("init.toml solver differs from the planned solver")
47
55
  files = InputFiles(self.root)
48
56
  for name, digest in self.point.inputs_sha256.items():
57
+ if is_matrix_file(name):
58
+ continue # records of earlier plans carry it; a grown matrix is not stale
49
59
  if hashlib.sha256(files.read_bytes(name)).hexdigest() != digest:
50
60
  raise ValueError(f"input changed after planning: {name}; plan again")
51
61
 
@@ -73,7 +83,12 @@ def load_point(root: str | Path, point: Point, *, solver: str) -> AdapterPoint:
73
83
  target,
74
84
  point,
75
85
  solver,
76
- apply_variables(files.read_toml(f"inputs/setups/{point.setup_id}.toml"), point.variables),
86
+ resolve_setup_paths(
87
+ target,
88
+ apply_variables(
89
+ files.read_toml(f"inputs/setups/{point.setup_id}.toml"), point.variables
90
+ ),
91
+ ),
77
92
  files.read_toml(f"inputs/references/{point.reference_id}.toml"),
78
93
  files.read_toml(f"inputs/pproc/{point.post_id}.toml"),
79
94
  )
@@ -17,11 +17,13 @@ from the HPC profile's ``[builds]`` table instead; these files serve local runs.
17
17
  from __future__ import annotations
18
18
 
19
19
  import tomllib
20
- from collections.abc import Mapping
20
+ import warnings
21
+ from collections.abc import Iterable, Mapping
21
22
  from dataclasses import dataclass, replace
22
23
  from pathlib import Path
24
+ from typing import Any
23
25
 
24
- from cfdbender.core.adapter import AdapterPoint
26
+ from cfdbender.core.adapter import AdapterPoint, load_point
25
27
  from cfdbender.core.settings import WorkspaceError
26
28
 
27
29
  DECLARED = "inputs/executables.toml"
@@ -90,11 +92,80 @@ def bind_executable(point: AdapterPoint, adapter: object) -> AdapterPoint:
90
92
  solver = dict(table) if isinstance(table, Mapping) else {}
91
93
  solver.update(getattr(adapter, "BUILD_OPTIONS", {}))
92
94
  solver[keys["path"]] = found.path
93
- if found.launcher:
94
- solver[keys["launcher"]] = list(found.launcher)
95
+ solver[keys["launcher"]] = list(found.launcher)
95
96
  return replace(point, setup={**point.setup, "solver": solver})
96
97
 
97
98
 
99
+ def check_builds(root: Path, solver: str, adapter: object, builds: Iterable[str | None]) -> None:
100
+ """Judge at plan time the builds a local run will bind, as a run binds them.
101
+
102
+ A build nobody declares is warned when the workspace has no inputs/executables.toml
103
+ (a plan may be made here for a cluster) and refused when the file exists but lacks it.
104
+
105
+ Parameters
106
+ ----------
107
+ root : Path
108
+ Workspace root.
109
+ solver : str
110
+ The init.toml solver.
111
+ adapter : object
112
+ The workspace's adapter module; one without EXECUTABLE_KEYS binds nothing.
113
+ builds : iterable of str or None
114
+ The SOLVER_BUILD of every planned point.
115
+
116
+ Raises
117
+ ------
118
+ WorkspaceError
119
+ The workspace declares executables and a planned build is not among them.
120
+ """
121
+ if getattr(adapter, "EXECUTABLE_KEYS", None) is None:
122
+ return
123
+ for build in sorted({b for b in builds if b}):
124
+ if has_registry(root):
125
+ resolve_executable(root, solver, build)
126
+ else:
127
+ warnings.warn(
128
+ f"SOLVER_BUILD {build} is carried but no {DECLARED} declares it; a local run "
129
+ "uses the executable the setup names",
130
+ UserWarning,
131
+ stacklevel=2,
132
+ )
133
+
134
+
135
+ def check_local_executables(
136
+ root: Path, solver: str, adapter: object, points: Iterable[Any]
137
+ ) -> None:
138
+ """Refuse a local plan whose solver executable is not on this machine.
139
+
140
+ A local plan binds each point's build as a run does and asks the adapter's own
141
+ ``check_executable``, the check ``run`` makes first, so plan and run say the same sentence.
142
+ Nothing is launched and no host slot is taken. A plan made for a cluster does not call this.
143
+
144
+ Parameters
145
+ ----------
146
+ root : Path
147
+ Workspace root.
148
+ solver : str
149
+ The init.toml solver.
150
+ adapter : object
151
+ The workspace's adapter module; one without ``check_executable`` looks for nothing.
152
+ points : iterable of Point
153
+ The planned points.
154
+
155
+ Raises
156
+ ------
157
+ ValueError
158
+ The executable a point would run does not exist (the one missing-executable sentence).
159
+ WorkspaceError
160
+ A planned build is not declared.
161
+ """
162
+ check = getattr(adapter, "check_executable", None)
163
+ if check is None:
164
+ return
165
+ for point in points:
166
+ check(bind_executable(load_point(root, point, solver=solver), adapter))
167
+
168
+
98
169
  def has_registry(root: Path) -> bool:
99
170
  """Return True when the workspace declares inputs/executables.toml."""
100
171
  return (root / DECLARED).is_file()
@@ -155,3 +226,35 @@ def resolve_executable(root: Path, solver: str, build: str) -> Executable:
155
226
  launcher = entry.get("launcher", [])
156
227
  assert isinstance(launcher, list)
157
228
  return Executable(build, str(path), tuple(str(token) for token in launcher))
229
+
230
+
231
+ def build_mismatch(build: str | None, reported: str) -> str | None:
232
+ """Return a refusal when the row's SOLVER_BUILD differs from the version the solver printed.
233
+
234
+ A build equal to the reported version matches, and so does a build that
235
+ names an alias of it (``8.3.0-mpi`` for ``8.3.0``). A solver that did not
236
+ report a version (``unknown`` or empty) cannot be checked and is not refused.
237
+
238
+ Parameters
239
+ ----------
240
+ build : str or None
241
+ The row's SOLVER_BUILD, or None when the row states none.
242
+ reported : str
243
+ The version the adapter read from the solver.
244
+
245
+ Returns
246
+ -------
247
+ str or None
248
+ The message to record as the failure, or None when the point may stand.
249
+ """
250
+ seen = reported.strip()
251
+ if not build or not seen or seen.casefold() == "unknown":
252
+ return None
253
+ wanted = build.casefold()
254
+ if wanted == seen.casefold() or wanted.startswith(seen.casefold() + "-"):
255
+ return None
256
+ return (
257
+ f"SOLVER_BUILD mismatch: the row names {build!r} but the solver reported version "
258
+ f"{seen!r}; point SOLVER_BUILD at the executable of that build in "
259
+ f"{DECLARED}, or correct the row"
260
+ )
@@ -0,0 +1,139 @@
1
+ """The guide `cfd-workspace init` writes to inputs/INPUTS.md: what each input file holds.
2
+
3
+ Written once per workspace, for the solver the workspace is bound to. The files a user
4
+ writes are the matrix, one setup, one reference and one post-processing file; the guide
5
+ shows a working example of each, so nothing has to be copied from the test suite.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ HEADER = "POL | RUN | FLIGHT_CONDITION | SWEEP_VALUES | GEOMETRY | REF | SET | PPROC | WALLTIME"
11
+
12
+ #: Per solver: the example row's FLIGHT_CONDITION, SWEEP_VALUES and GEOMETRY cells, then the
13
+ #: setup (s001.toml), reference (r001.toml) and post (p001.toml) examples.
14
+ _EXAMPLES: dict[str, tuple[str, str, str, str, str, str]] = {
15
+ "mock": (
16
+ "MACH:0.2, ALPHA:sweep",
17
+ "0,2",
18
+ "model.dat",
19
+ '[mock]\noutcome = "converged"\niterations = 10\n',
20
+ 'area = 1.5\nlength = 1.0\nmoment_origin = [0, 0, 0]\naxis_system = "body"\n'
21
+ 'axis_directions = ["aft", "right", "up"]\n',
22
+ "history = true\n",
23
+ ),
24
+ "su2": (
25
+ "MACH:0.5, ALTFT:10000, ALPHA:sweep, BETA:0",
26
+ "0,2",
27
+ "model.su2",
28
+ 'iterations = 40\nSOLVER = "EULER"\n',
29
+ "area = 1.0\nlength = 1.0\nmoment_origin = [0, 0, 0]\n",
30
+ "history = true\n",
31
+ ),
32
+ "openfoam": (
33
+ "TASmps:10, REmi:0.6, ALPHA:sweep, BETA:0",
34
+ "0,4",
35
+ "model.msh",
36
+ 'application = "simpleFoam"\nturbulence = "laminar"\niterations = 400\n',
37
+ "area = 0.1\nlength = 1.0\nmoment_origin = [0, 0, 0]\n",
38
+ "history = true\n",
39
+ ),
40
+ "pyfr": (
41
+ "MACH:0.2, REmi:0.01, ALPHA:sweep, BETA:0",
42
+ "4",
43
+ "model.msh",
44
+ "order = 3\ntend = 3\nwindow_start = 0\n",
45
+ "",
46
+ "history = true\n",
47
+ ),
48
+ "xfoil": (
49
+ "MACH:0, REmi:1, ALPHA:sweep",
50
+ "0,2",
51
+ "-",
52
+ 'airfoil = "NACA 0012"\n',
53
+ "",
54
+ "",
55
+ ),
56
+ "qprop": (
57
+ "TASmps:20, RPM:6000, BETA07:30",
58
+ "-",
59
+ "blade.obj",
60
+ 'n_blades = 3\nn_sections = 5\nspacing = "cosine"\ncut = "plane"\nradius = 0.2\n',
61
+ "",
62
+ "",
63
+ ),
64
+ }
65
+
66
+ _MESH_NOTE = {
67
+ "mock": "any file; the mock only records its digest",
68
+ "su2": "an SU2 mesh (.su2)",
69
+ "openfoam": "a Gmsh .msh (format 2.2) the case is built around",
70
+ "pyfr": "a Gmsh .msh (format 4.1)",
71
+ "xfoil": "none: XFOIL reads the airfoil named in the setup; write - in the cell",
72
+ "qprop": "the blade OBJ (or name it in the setup as blade = ...)",
73
+ }
74
+
75
+
76
+ def guide_text(solver: str) -> str:
77
+ """Return inputs/INPUTS.md for a solver, or the generic guide for an unlisted one.
78
+
79
+ Parameters
80
+ ----------
81
+ solver : str
82
+ Registered solver name the workspace is bound to.
83
+ """
84
+ example = _EXAMPLES.get(solver)
85
+ lines = [
86
+ f"# Inputs of this workspace (solver: {solver})",
87
+ "",
88
+ "Everything the campaign reads lives under `inputs/`. A matrix row names the files",
89
+ "by id: `SET 001` reads `inputs/setups/s001.toml`, `REF 001` reads",
90
+ "`inputs/references/r001.toml`, `PPROC 001` reads `inputs/pproc/p001.toml`, and",
91
+ "GEOMETRY names a file in `inputs/mesh/`.",
92
+ "",
93
+ "| Folder | Holds |",
94
+ "|---|---|",
95
+ "| `inputs/matrices/` | `<name>.fs`: one row per simulation, columns separated by `\\|` |",
96
+ "| `inputs/setups/` | `s<id>.toml`: the solver setup |",
97
+ "| `inputs/references/` | `r<id>.toml`: reference area, length, moment origin |",
98
+ "| `inputs/pproc/` | `p<id>.toml`: what to extract after the run |",
99
+ "| `inputs/mesh/` | meshes and geometry files |",
100
+ "| `inputs/hpc/` | cluster profiles, only to submit instead of running here |",
101
+ "",
102
+ ]
103
+ if example is not None:
104
+ condition, sweep, geometry, setup, reference, post = example
105
+ reference = reference or "# this solver reads no reference keys; the file may be empty\n"
106
+ post = post or "# this solver reads no post-processing keys; the file may be empty\n"
107
+ lines += [
108
+ "## A first matrix, `inputs/matrices/first.fs`",
109
+ "",
110
+ "```text",
111
+ HEADER,
112
+ f"7001 | 1 | {condition} | {sweep} | {geometry} | 001 | 001 | 001 | 2h",
113
+ "```",
114
+ "",
115
+ f"GEOMETRY: {_MESH_NOTE[solver]}.",
116
+ "",
117
+ "FLIGHT_CONDITION is `KEY:value` pairs; the key that varies carries the word",
118
+ "`sweep` and SWEEP_VALUES lists its values. A key this package does not know is",
119
+ "refused with the accepted list.",
120
+ "",
121
+ "## `inputs/setups/s001.toml`",
122
+ "",
123
+ "```toml",
124
+ setup.rstrip(),
125
+ "```",
126
+ ]
127
+ lines += ["", "## `inputs/references/r001.toml`", "", "```toml", reference.rstrip(), "```"]
128
+ lines += ["", "## `inputs/pproc/p001.toml`", "", "```toml", post.rstrip(), "```", ""]
129
+ lines += [
130
+ "## Then",
131
+ "",
132
+ "```text",
133
+ "cfd-matrix plan first --workspace .",
134
+ "cfd-matrix run first --workspace . --local",
135
+ "cfd-matrix collect first --workspace .",
136
+ "```",
137
+ "",
138
+ ]
139
+ return "\n".join(lines)
@@ -0,0 +1,106 @@
1
+ """Long paths on Windows: file operations under sims/ beyond the 260-character limit.
2
+
3
+ A deep solver tree (an OpenFOAM case with processor and time folders) can pass the
4
+ 260-character limit of a Windows path, and an ordinary file operation then fails. The
5
+ extended-length spelling (a prefix of two backslashes, a question mark and a backslash on
6
+ the absolute path) lifts the limit. The helpers
7
+ here spell the path for the file operation only: names, relative paths and records are
8
+ always derived from the path as given. Elsewhere they return the path unchanged.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import os
14
+ import shutil
15
+ from collections.abc import Iterator
16
+ from pathlib import Path
17
+
18
+ _PREFIX = "\\\\?\\"
19
+
20
+
21
+ def extended_length(path: str | os.PathLike[str], *, windows: bool | None = None) -> str:
22
+ """Return ``path`` in the spelling a file operation accepts at any length.
23
+
24
+ Parameters
25
+ ----------
26
+ path : str or path-like
27
+ The path to spell.
28
+ windows : bool, optional
29
+ Whether to spell for Windows; defaults to whether this process runs on Windows.
30
+
31
+ Returns
32
+ -------
33
+ str
34
+ On Windows the absolute path behind the extended prefix (the UNC form for a
35
+ network path); an already extended path is unchanged. Elsewhere the path as given.
36
+ """
37
+ text = os.fspath(path)
38
+ if windows is None:
39
+ windows = os.name == "nt"
40
+ if not windows or not text or text.startswith(_PREFIX):
41
+ return text
42
+ absolute = text.replace("/", "\\")
43
+ if not (absolute.startswith("\\\\") or (len(absolute) > 2 and absolute[1:3] == ":\\")):
44
+ absolute = os.path.abspath(absolute)
45
+ if absolute.startswith("\\\\"):
46
+ return _PREFIX + "UNC\\" + absolute[2:]
47
+ return _PREFIX + absolute
48
+
49
+
50
+ def long_path(path: str | os.PathLike[str]) -> Path:
51
+ """Return ``path`` as a path any file operation accepts at any length."""
52
+ return Path(extended_length(path))
53
+
54
+
55
+ def plain(path: str | os.PathLike[str]) -> Path:
56
+ """Return a path without the extended prefix, the spelling names and records use."""
57
+ text = os.fspath(path)
58
+ if text.startswith(_PREFIX + "UNC\\"):
59
+ return Path("\\\\" + text[len(_PREFIX) + 4 :])
60
+ if text.startswith(_PREFIX):
61
+ return Path(text[len(_PREFIX) :])
62
+ return Path(text)
63
+
64
+
65
+ def iter_files(folder: str | os.PathLike[str]) -> Iterator[Path]:
66
+ """Yield every file under ``folder``, links not followed, at any depth.
67
+
68
+ The paths are in their plain spelling. A symbolic link or a junction is not entered
69
+ and a link to a file is not yielded, as ``Path.rglob`` plus ``is_symlink`` would do.
70
+ """
71
+ base = plain(extended_length(folder))
72
+ for current, folders, names in os.walk(extended_length(folder), followlinks=False):
73
+ here = plain(current)
74
+ folders[:] = [
75
+ name
76
+ for name in folders
77
+ if not (Path(current, name).is_symlink() or os.path.isjunction(Path(current, name)))
78
+ ]
79
+ for name in names:
80
+ if not Path(current, name).is_symlink():
81
+ yield base / here.relative_to(base) / name
82
+
83
+
84
+ def file_size(path: str | os.PathLike[str]) -> int:
85
+ """Return the size of one file, at any path length."""
86
+ return long_path(path).stat().st_size
87
+
88
+
89
+ def rmtree(path: str | os.PathLike[str]) -> None:
90
+ """Remove a folder tree, at any path length."""
91
+ shutil.rmtree(long_path(path))
92
+
93
+
94
+ def copytree(source: str | os.PathLike[str], target: str | os.PathLike[str]) -> None:
95
+ """Copy a folder tree, at any path length."""
96
+ shutil.copytree(long_path(source), long_path(target))
97
+
98
+
99
+ def copy2(source: str | os.PathLike[str], target: str | os.PathLike[str]) -> None:
100
+ """Copy one file and its metadata, at any path length."""
101
+ shutil.copy2(long_path(source), long_path(target))
102
+
103
+
104
+ def replace(source: str | os.PathLike[str], target: str | os.PathLike[str]) -> None:
105
+ """Rename a file or folder over ``target``, at any path length."""
106
+ os.replace(long_path(source), long_path(target))
@@ -100,10 +100,16 @@ def _number(text: str, label: str) -> float:
100
100
 
101
101
 
102
102
  def _artifact_id(text: str, prefix: str, label: str) -> str:
103
- code = text.removesuffix(".toml").removeprefix(prefix)
104
- if not code or not code.isascii() or not code.isdecimal():
105
- raise MatrixError(f"{label}: {text!r} must name {prefix}<digits>.toml")
106
- return prefix + code
103
+ name = text.removesuffix(".toml")
104
+ if name.isascii() and name.isdecimal():
105
+ return prefix + name
106
+ named = name.removeprefix(prefix)
107
+ if named and named != name and re.fullmatch("[A-Za-z0-9][A-Za-z0-9._-]*", named):
108
+ return name
109
+ raise MatrixError(
110
+ f"{label}: {text!r} must name {prefix}<digits> or {prefix}<name> "
111
+ f"(the file {prefix}<digits or name>.toml)"
112
+ )
107
113
 
108
114
 
109
115
  def _condition(
@@ -189,7 +195,7 @@ def _variables(text: str, label: str) -> Mapping[str, object]:
189
195
 
190
196
  def _row(cells: Mapping[str, str], number: int, path: Path) -> MatrixRow:
191
197
  pol = cells["POL"]
192
- label = f"{path.name} data row {number}, POL {pol!r}"
198
+ label = f"{path.as_posix()}, data row {number} (POL {pol})"
193
199
  if re.fullmatch("[A-Za-z0-9][A-Za-z0-9_-]*", pol) is None:
194
200
  raise MatrixError(f"{label}: POL must be a non-empty filename-safe identifier")
195
201
  if cells["RUN"] not in ("0", "1"):
@@ -286,17 +292,24 @@ def parse_matrix(data: bytes, source: Path, *, active_only: bool = True) -> tupl
286
292
  try:
287
293
  lines = data.decode("utf-8-sig").splitlines()
288
294
  except UnicodeError as error:
289
- raise MatrixError(f"{source}: cannot read UTF-8: {error}") from error
295
+ raise MatrixError(f"{source.as_posix()}: cannot read UTF-8: {error}") from error
290
296
  content = [
291
297
  line.strip()
292
298
  for line in lines
293
299
  if line.strip() and not line.lstrip().startswith("#") and set(line.strip()) - set("-:+| \t")
294
300
  ]
295
301
  if not content:
296
- raise MatrixError(f"{source}: missing matrix header: {', '.join(REQUIRED_COLUMNS)}")
302
+ raise MatrixError(
303
+ f"{source.as_posix()}: missing matrix header: {', '.join(REQUIRED_COLUMNS)}"
304
+ )
297
305
  header = [c.strip() for c in content[0].split("|")]
298
306
  if any(not c for c in header) or len(set(header)) != len(header):
299
- raise MatrixError(f"{source}: blank or duplicate matrix headers")
307
+ raise MatrixError(f"{source.as_posix()}: blank or duplicate matrix headers")
308
+ if len(header) == 1 and "," in header[0] and set(header[0].split(",")) & set(COLUMNS):
309
+ raise MatrixError(
310
+ f"{source.as_posix()}: columns are separated by |, not by commas "
311
+ "(POL | RUN | SET | ...)"
312
+ )
300
313
  missing = set(REQUIRED_COLUMNS) - set(header)
301
314
  unknown = set(header) - set(COLUMNS)
302
315
  if missing or unknown:
@@ -305,21 +318,25 @@ def parse_matrix(data: bytes, source: Path, *, active_only: bool = True) -> tupl
305
318
  for name in sorted(unknown)
306
319
  for close in [difflib.get_close_matches(name, COLUMNS, n=1)]
307
320
  ]
321
+ problems = []
322
+ if missing:
323
+ problems.append(f"missing columns: {', '.join(sorted(missing))}")
324
+ if hints:
325
+ problems.append(f"unsupported columns: {', '.join(hints)}")
326
+ raise MatrixError(f"{source.as_posix()}: {'; '.join(problems)}")
327
+ if {"SOLVER_BUILD", "FS_BUILD"} <= set(header):
308
328
  raise MatrixError(
309
- f"{source}: missing columns: {', '.join(sorted(missing)) or '(none)'}; "
310
- f"unsupported columns: {', '.join(hints) or '(none)'}"
329
+ f"{source.as_posix()}: SOLVER_BUILD and FS_BUILD name one column; keep one"
311
330
  )
312
- if {"SOLVER_BUILD", "FS_BUILD"} <= set(header):
313
- raise MatrixError(f"{source}: SOLVER_BUILD and FS_BUILD name one column; keep one")
314
331
  result: list[MatrixRow] = []
315
332
  seen: set[str] = set()
316
333
  for number, line in enumerate(content[1:], 1):
317
334
  fields = [c.strip() for c in line.split("|")]
318
335
  if len(fields) != len(header):
319
- raise MatrixError(f"{source}: data row {number} needs {len(header)} columns")
336
+ raise MatrixError(f"{source.as_posix()}, data row {number} needs {len(header)} columns")
320
337
  row = _row(dict(zip(header, fields, strict=True)), number, source)
321
338
  if row.pol.casefold() in seen:
322
- raise MatrixError(f"{source}: data row {number} repeats POL {row.pol!r}")
339
+ raise MatrixError(f"{source.as_posix()}, data row {number}: repeats POL {row.pol!r}")
323
340
  seen.add(row.pol.casefold())
324
341
  if row.run == 1 or not active_only:
325
342
  result.append(row)
@@ -350,5 +367,5 @@ def read_matrix(path: str | Path, *, active_only: bool = True) -> tuple[MatrixRo
350
367
  try:
351
368
  data = source.read_bytes()
352
369
  except OSError as error:
353
- raise MatrixError(f"{source}: cannot read: {error}") from error
370
+ raise MatrixError(f"{source.as_posix()}: cannot read: {error}") from error
354
371
  return parse_matrix(data, source, active_only=active_only)