cfdbender 0.4.2__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.
- cfdbender/__init__.py +7 -0
- cfdbender/_pyfs.py +92 -0
- cfdbender/core/__init__.py +13 -0
- cfdbender/core/adapter.py +148 -0
- cfdbender/core/executables.py +157 -0
- cfdbender/core/flight.py +346 -0
- cfdbender/core/matrix.py +354 -0
- cfdbender/core/naming.py +172 -0
- cfdbender/core/plan.py +463 -0
- cfdbender/core/registry.py +735 -0
- cfdbender/core/results.py +117 -0
- cfdbender/core/run.py +150 -0
- cfdbender/core/settings.py +92 -0
- cfdbender/core/workspace.py +93 -0
- cfdbender/geometry/__init__.py +1 -0
- cfdbender/geometry/blade_slicing.py +355 -0
- cfdbender/hpc/__init__.py +21 -0
- cfdbender/hpc/_plan.py +266 -0
- cfdbender/hpc/_profiles.py +305 -0
- cfdbender/hpc/_render.py +271 -0
- cfdbender/hpc/_submit.py +96 -0
- cfdbender/hpc/_walltime.py +301 -0
- cfdbender/matrix/__init__.py +1 -0
- cfdbender/matrix/cli.py +228 -0
- cfdbender/matrix/collection.py +251 -0
- cfdbender/matrix/exports.py +122 -0
- cfdbender/matrix/rerun.py +126 -0
- cfdbender/matrix/selection.py +62 -0
- cfdbender/matrix/submission.py +272 -0
- cfdbender/solvers/__init__.py +47 -0
- cfdbender/solvers/_host/__init__.py +1 -0
- cfdbender/solvers/_host/_config.py +10 -0
- cfdbender/solvers/_host/_execute.py +52 -0
- cfdbender/solvers/_host/_mesh.py +62 -0
- cfdbender/solvers/_host/_ram.py +69 -0
- cfdbender/solvers/_host/_single.py +63 -0
- cfdbender/solvers/flightstream/__init__.py +114 -0
- cfdbender/solvers/flightstream/reader.py +191 -0
- cfdbender/solvers/mock/__init__.py +273 -0
- cfdbender/solvers/openfoam/__init__.py +201 -0
- cfdbender/solvers/openfoam/_config.py +410 -0
- cfdbender/solvers/openfoam/_execute.py +162 -0
- cfdbender/solvers/openfoam/_history.py +158 -0
- cfdbender/solvers/pyfr/__init__.py +118 -0
- cfdbender/solvers/pyfr/_config.py +196 -0
- cfdbender/solvers/pyfr/_execute.py +127 -0
- cfdbender/solvers/pyfr/_history.py +88 -0
- cfdbender/solvers/qprop/__init__.py +303 -0
- cfdbender/solvers/qprop/_config.py +259 -0
- cfdbender/solvers/qprop/_execute.py +269 -0
- cfdbender/solvers/qprop/_output.py +64 -0
- cfdbender/solvers/qprop/_polar.py +98 -0
- cfdbender/solvers/qprop/_prop.py +81 -0
- cfdbender/solvers/qprop/_sections.py +193 -0
- cfdbender/solvers/su2/__init__.py +210 -0
- cfdbender/solvers/su2/_config.py +290 -0
- cfdbender/solvers/su2/_execute.py +196 -0
- cfdbender/solvers/su2/_history.py +117 -0
- cfdbender/solvers/su2/_pysu2_worker.py +25 -0
- cfdbender/solvers/su2/_ram.py +13 -0
- cfdbender/solvers/su2/_reference.py +79 -0
- cfdbender/solvers/su2/_single.py +3 -0
- cfdbender/solvers/su2/routes.py +61 -0
- cfdbender/solvers/xfoil/__init__.py +171 -0
- cfdbender/solvers/xfoil/_config.py +144 -0
- cfdbender/solvers/xfoil/_execute.py +227 -0
- cfdbender/solvers/xfoil/_polar.py +88 -0
- cfdbender/testing/__init__.py +301 -0
- cfdbender/workspace/__init__.py +1 -0
- cfdbender/workspace/cli.py +99 -0
- cfdbender/workspace/planning.py +38 -0
- cfdbender-0.4.2.dist-info/METADATA +57 -0
- cfdbender-0.4.2.dist-info/RECORD +77 -0
- cfdbender-0.4.2.dist-info/WHEEL +5 -0
- cfdbender-0.4.2.dist-info/entry_points.txt +3 -0
- cfdbender-0.4.2.dist-info/licenses/LICENSE +21 -0
- cfdbender-0.4.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Solver-neutral coefficients with explicit reference values and iteration evidence.
|
|
2
|
+
|
|
3
|
+
Classification describes numerical termination, separately from process exit.
|
|
4
|
+
Axis directions describe positive x, y and z in the stated axis system.
|
|
5
|
+
Reference area and length use square metres and metres; moment origin uses metres.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
from collections.abc import Mapping
|
|
12
|
+
from dataclasses import asdict, dataclass
|
|
13
|
+
from typing import Literal
|
|
14
|
+
|
|
15
|
+
Classification = Literal["converged", "iteration_limit", "failed"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class References:
|
|
20
|
+
"""Dimensional reference values and positive axis directions for coefficients."""
|
|
21
|
+
|
|
22
|
+
area: float
|
|
23
|
+
length: float
|
|
24
|
+
moment_origin: tuple[float, float, float]
|
|
25
|
+
axis_system: str
|
|
26
|
+
axis_directions: tuple[str, str, str]
|
|
27
|
+
|
|
28
|
+
def __post_init__(self) -> None:
|
|
29
|
+
"""Refuse absent axes and invalid dimensional references."""
|
|
30
|
+
if not math.isfinite(self.area) or self.area <= 0:
|
|
31
|
+
raise ValueError("reference area must be finite and positive")
|
|
32
|
+
if not math.isfinite(self.length) or self.length <= 0:
|
|
33
|
+
raise ValueError("reference length must be finite and positive")
|
|
34
|
+
if len(self.moment_origin) != 3 or not all(map(math.isfinite, self.moment_origin)):
|
|
35
|
+
raise ValueError("moment_origin must contain three finite coordinates")
|
|
36
|
+
if not self.axis_system.strip():
|
|
37
|
+
raise ValueError("axis_system must be explicit")
|
|
38
|
+
if len(self.axis_directions) != 3 or not all(s.strip() for s in self.axis_directions):
|
|
39
|
+
raise ValueError("axis_directions must describe positive x, y and z")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True)
|
|
43
|
+
class Coefficient:
|
|
44
|
+
"""One dimensionless force or moment coefficient about an explicit axis."""
|
|
45
|
+
|
|
46
|
+
value: float
|
|
47
|
+
axis: Literal["x", "y", "z"]
|
|
48
|
+
kind: Literal["force", "moment"]
|
|
49
|
+
|
|
50
|
+
def __post_init__(self) -> None:
|
|
51
|
+
"""Refuse non-finite values and ambiguous axes."""
|
|
52
|
+
if not math.isfinite(self.value):
|
|
53
|
+
raise ValueError("coefficient value must be finite")
|
|
54
|
+
if self.axis not in ("x", "y", "z") or self.kind not in ("force", "moment"):
|
|
55
|
+
raise ValueError("coefficient axis and kind must be explicit")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True)
|
|
59
|
+
class Iteration:
|
|
60
|
+
"""One solver iteration, its residual and the solver's convergence evidence."""
|
|
61
|
+
|
|
62
|
+
iteration: int
|
|
63
|
+
residual: float
|
|
64
|
+
converged: bool = False
|
|
65
|
+
|
|
66
|
+
def __post_init__(self) -> None:
|
|
67
|
+
"""Refuse malformed iteration evidence."""
|
|
68
|
+
if type(self.iteration) is not int or self.iteration < 1:
|
|
69
|
+
raise ValueError("iteration must be a positive integer")
|
|
70
|
+
if not math.isfinite(self.residual) or self.residual < 0:
|
|
71
|
+
raise ValueError("residual must be finite and non-negative")
|
|
72
|
+
if type(self.converged) is not bool:
|
|
73
|
+
raise ValueError("converged must be a boolean")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@dataclass(frozen=True)
|
|
77
|
+
class ExecutionResult:
|
|
78
|
+
"""Process outcome and history; exit_code zero alone proves no convergence."""
|
|
79
|
+
|
|
80
|
+
exit_code: int
|
|
81
|
+
history: tuple[Iteration, ...]
|
|
82
|
+
iteration_limit: int
|
|
83
|
+
solver_version: str
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@dataclass(frozen=True)
|
|
87
|
+
class NeutralResult:
|
|
88
|
+
"""Collected coefficients, references, iteration history and termination class."""
|
|
89
|
+
|
|
90
|
+
coefficients: Mapping[str, Coefficient]
|
|
91
|
+
references: References
|
|
92
|
+
history: tuple[Iteration, ...]
|
|
93
|
+
classification: Classification
|
|
94
|
+
solver_version: str
|
|
95
|
+
|
|
96
|
+
def __post_init__(self) -> None:
|
|
97
|
+
"""Refuse undocumented successful results."""
|
|
98
|
+
if self.classification not in ("converged", "iteration_limit", "failed"):
|
|
99
|
+
raise ValueError("unknown classification")
|
|
100
|
+
if not self.solver_version.strip():
|
|
101
|
+
raise ValueError("solver_version must be explicit")
|
|
102
|
+
if self.classification != "failed" and not self.coefficients:
|
|
103
|
+
raise ValueError("successful results must carry coefficient columns")
|
|
104
|
+
if self.classification == "converged" and (
|
|
105
|
+
not self.history or not self.history[-1].converged
|
|
106
|
+
):
|
|
107
|
+
raise ValueError("converged requires iteration evidence")
|
|
108
|
+
|
|
109
|
+
def to_dict(self) -> dict[str, object]:
|
|
110
|
+
"""Return JSON-ready neutral data, retaining coefficient axes and references."""
|
|
111
|
+
return {
|
|
112
|
+
"coefficients": {key: asdict(value) for key, value in self.coefficients.items()},
|
|
113
|
+
"references": asdict(self.references),
|
|
114
|
+
"history": [asdict(value) for value in self.history],
|
|
115
|
+
"classification": self.classification,
|
|
116
|
+
"solver_version": self.solver_version,
|
|
117
|
+
}
|
cfdbender/core/run.py
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Execute injected adapters point by point, preserving each outcome in runs.json.
|
|
2
|
+
|
|
3
|
+
Preflight every selected point before writing. A failed execution is recorded
|
|
4
|
+
and the next point runs; an unexpected programming error propagates, leaving
|
|
5
|
+
RUNNING evidence rather than pretending the solver failed. A recorded point
|
|
6
|
+
refuses overwrite here; cfd-matrix run --resume and --force-rerun decide, before
|
|
7
|
+
this runs, which points to skip and which to archive and register again.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import ctypes
|
|
13
|
+
import sys
|
|
14
|
+
from collections.abc import Callable
|
|
15
|
+
from dataclasses import replace
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from cfdbender.core.adapter import SolverAdapter, load_point
|
|
19
|
+
from cfdbender.core.executables import bind_executable
|
|
20
|
+
from cfdbender.core.plan import RunPlan, workspace_path
|
|
21
|
+
from cfdbender.core.registry import RegistryError, RunRecord, RunRegistry
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def check_available_ram() -> None:
|
|
25
|
+
"""Refuse local work if available memory cannot be measured above 0.5 GiB.
|
|
26
|
+
|
|
27
|
+
Windows uses GlobalMemoryStatusEx; Linux reads MemAvailable from procfs.
|
|
28
|
+
No solver or optional monitoring dependency is imported.
|
|
29
|
+
|
|
30
|
+
Raises
|
|
31
|
+
------
|
|
32
|
+
RegistryError
|
|
33
|
+
Available memory is unknown or below the required floor.
|
|
34
|
+
"""
|
|
35
|
+
if sys.platform == "win32":
|
|
36
|
+
|
|
37
|
+
class MemoryStatus(ctypes.Structure):
|
|
38
|
+
_fields_ = [("length", ctypes.c_ulong), ("load", ctypes.c_ulong)] + [
|
|
39
|
+
(name, ctypes.c_ulonglong)
|
|
40
|
+
for name in (
|
|
41
|
+
"total",
|
|
42
|
+
"available",
|
|
43
|
+
"page",
|
|
44
|
+
"free_page",
|
|
45
|
+
"virtual",
|
|
46
|
+
"free_virtual",
|
|
47
|
+
"ext",
|
|
48
|
+
)
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
status = MemoryStatus()
|
|
52
|
+
status.length = ctypes.sizeof(status)
|
|
53
|
+
if not ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(status)):
|
|
54
|
+
raise RegistryError("cannot measure free RAM; local run refused")
|
|
55
|
+
available = status.available
|
|
56
|
+
else:
|
|
57
|
+
try:
|
|
58
|
+
line = next(
|
|
59
|
+
line
|
|
60
|
+
for line in Path("/proc/meminfo").read_text().splitlines()
|
|
61
|
+
if line.startswith("MemAvailable:")
|
|
62
|
+
)
|
|
63
|
+
available = int(line.split()[1]) * 1024
|
|
64
|
+
except (OSError, StopIteration, ValueError, IndexError) as error:
|
|
65
|
+
raise RegistryError("cannot measure free RAM; local run refused") from error
|
|
66
|
+
if available < 0.5 * 2**30:
|
|
67
|
+
raise RegistryError(f"free RAM {available / 2**30:.3f} GiB is below the 0.5 GiB floor")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def execute_plan(
|
|
71
|
+
plan: RunPlan,
|
|
72
|
+
adapter: SolverAdapter,
|
|
73
|
+
*,
|
|
74
|
+
check_ram: Callable[[], None] = check_available_ram,
|
|
75
|
+
) -> tuple[RunRecord, ...]:
|
|
76
|
+
"""Run every point locally, recording failures and continuing to the next point.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
plan : RunPlan
|
|
81
|
+
Validated plan, including the adapter's validate_row hook and input digests.
|
|
82
|
+
adapter : SolverAdapter
|
|
83
|
+
Injected adapter; core never discovers or imports a solver.
|
|
84
|
+
check_ram : callable, optional
|
|
85
|
+
Guard called before writing, before every point and throughout adapter execution.
|
|
86
|
+
|
|
87
|
+
Returns
|
|
88
|
+
-------
|
|
89
|
+
tuple of RunRecord
|
|
90
|
+
Completed records, including failed points and their diagnoses.
|
|
91
|
+
|
|
92
|
+
Raises
|
|
93
|
+
------
|
|
94
|
+
RegistryError
|
|
95
|
+
A recorded point, changed input, existing output or threatened memory floor.
|
|
96
|
+
"""
|
|
97
|
+
check_ram()
|
|
98
|
+
registry = RunRegistry(plan.root)
|
|
99
|
+
previous = {r.point_id: r for r in registry.read()}
|
|
100
|
+
prepared = []
|
|
101
|
+
for point in plan.points:
|
|
102
|
+
recorded = previous.get(point.point_id)
|
|
103
|
+
if recorded is not None:
|
|
104
|
+
if recorded.status != "PLANNED":
|
|
105
|
+
raise RegistryError(f"point {point.point_id!r} already recorded {recorded.status}")
|
|
106
|
+
if (
|
|
107
|
+
recorded.point != point
|
|
108
|
+
or recorded.matrix != plan.matrix
|
|
109
|
+
or recorded.solver != plan.solver
|
|
110
|
+
):
|
|
111
|
+
raise RegistryError(
|
|
112
|
+
f"point {point.point_id!r}: registered proposal differs; plan again"
|
|
113
|
+
)
|
|
114
|
+
for name in (point.directory, *point.outputs):
|
|
115
|
+
if workspace_path(plan.root, name).exists():
|
|
116
|
+
raise RegistryError(f"{name}: existing output; refusing overwrite")
|
|
117
|
+
# A row's SOLVER_BUILD selects its executable here, refusing an undeclared build.
|
|
118
|
+
prepared.append(bind_executable(load_point(plan.root, point, solver=plan.solver), adapter))
|
|
119
|
+
missing = tuple(p for p in plan.points if p.point_id not in previous)
|
|
120
|
+
if missing:
|
|
121
|
+
registry.record(replace(plan, points=missing))
|
|
122
|
+
completed = []
|
|
123
|
+
for context in prepared:
|
|
124
|
+
check_ram()
|
|
125
|
+
registry.transition(context.point.point_id, "RUNNING")
|
|
126
|
+
error = None
|
|
127
|
+
try:
|
|
128
|
+
result = adapter.execute(context, check_ram=check_ram)
|
|
129
|
+
classification = adapter.classify(result)
|
|
130
|
+
if classification not in ("converged", "iteration_limit", "failed"):
|
|
131
|
+
raise ValueError(f"unknown classification {classification!r}")
|
|
132
|
+
if classification == "failed":
|
|
133
|
+
error = f"FAILED_EXECUTION: exit code {result.exit_code}; numerical evidence failed"
|
|
134
|
+
elif any(
|
|
135
|
+
not workspace_path(plan.root, name).is_file() for name in context.point.outputs
|
|
136
|
+
):
|
|
137
|
+
classification = "failed"
|
|
138
|
+
error = "FAILED_INCOMPLETE_OUTPUT: missing declared output"
|
|
139
|
+
except (OSError, ValueError) as failure:
|
|
140
|
+
classification = "failed"
|
|
141
|
+
error = f"FAILED_EXECUTION: {failure}"
|
|
142
|
+
completed.append(
|
|
143
|
+
registry.transition(
|
|
144
|
+
context.point.point_id,
|
|
145
|
+
"COMPLETED",
|
|
146
|
+
classification=classification,
|
|
147
|
+
error=error,
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
return tuple(completed)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Read the workspace's single solver declaration without importing adapters."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
import tomllib
|
|
7
|
+
from collections.abc import Collection, Mapping
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WorkspaceError(ValueError):
|
|
13
|
+
"""A workspace declaration or layout cannot be used as requested."""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@dataclass(frozen=True)
|
|
17
|
+
class WorkspaceConfig:
|
|
18
|
+
"""Validated root declaration of one solver.
|
|
19
|
+
|
|
20
|
+
Attributes
|
|
21
|
+
----------
|
|
22
|
+
schema_version : int
|
|
23
|
+
Supported declaration format, currently 1.
|
|
24
|
+
solver : str
|
|
25
|
+
Registered solver name supplied by the composing application.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
schema_version: int
|
|
29
|
+
solver: str
|
|
30
|
+
solver_options: Mapping[str, object] = field(default_factory=dict)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _validate(
|
|
34
|
+
values: Mapping[str, object], source: Path, available_solvers: Collection[str]
|
|
35
|
+
) -> WorkspaceConfig:
|
|
36
|
+
def refuse(problem: str) -> WorkspaceError:
|
|
37
|
+
choices = ", ".join(sorted(available_solvers)) or "(none)"
|
|
38
|
+
return WorkspaceError(f"{source}: {problem}; available solvers: {choices}")
|
|
39
|
+
|
|
40
|
+
unknown = set(values) - {"schema_version", "solver"}
|
|
41
|
+
if unknown:
|
|
42
|
+
raise refuse(f"unknown keys: {', '.join(sorted(unknown))}")
|
|
43
|
+
version = values.get("schema_version")
|
|
44
|
+
if type(version) is not int or version != 1:
|
|
45
|
+
raise refuse("schema_version must be the integer 1")
|
|
46
|
+
solver = values.get("solver")
|
|
47
|
+
solver_options: dict[str, object] = {}
|
|
48
|
+
if isinstance(solver, dict):
|
|
49
|
+
solver_options = {k: v for k, v in solver.items() if k != "name"}
|
|
50
|
+
for key, value in solver_options.items():
|
|
51
|
+
if type(value) not in (str, int, float, bool) or (
|
|
52
|
+
type(value) is float and not math.isfinite(value)
|
|
53
|
+
):
|
|
54
|
+
raise refuse(f"solver option {key} must be a finite scalar")
|
|
55
|
+
solver = solver.get("name")
|
|
56
|
+
if not isinstance(solver, str) or not solver:
|
|
57
|
+
raise refuse("solver must be a non-empty string")
|
|
58
|
+
if solver not in available_solvers:
|
|
59
|
+
raise refuse(f"unknown solver {solver!r}")
|
|
60
|
+
return WorkspaceConfig(schema_version=version, solver=solver, solver_options=solver_options)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def read_init(root: str | Path, *, available_solvers: Collection[str]) -> WorkspaceConfig:
|
|
64
|
+
"""Read and validate init.toml at a workspace root.
|
|
65
|
+
|
|
66
|
+
Parameters
|
|
67
|
+
----------
|
|
68
|
+
root : str or Path
|
|
69
|
+
Workspace root, resolved once against the current directory.
|
|
70
|
+
available_solvers : Collection[str]
|
|
71
|
+
Registered solver names, passed as data by the application.
|
|
72
|
+
|
|
73
|
+
Returns
|
|
74
|
+
-------
|
|
75
|
+
WorkspaceConfig
|
|
76
|
+
The validated declaration; no adapter is loaded.
|
|
77
|
+
|
|
78
|
+
Raises
|
|
79
|
+
------
|
|
80
|
+
WorkspaceError
|
|
81
|
+
If the file cannot be read, is malformed, or declares unsupported values.
|
|
82
|
+
"""
|
|
83
|
+
source = Path(root).resolve() / "init.toml"
|
|
84
|
+
try:
|
|
85
|
+
values = tomllib.loads(source.read_text(encoding="utf-8"))
|
|
86
|
+
except (OSError, UnicodeError, tomllib.TOMLDecodeError) as error:
|
|
87
|
+
choices = ", ".join(sorted(available_solvers)) or "(none)"
|
|
88
|
+
problem = "invalid TOML" if isinstance(error, tomllib.TOMLDecodeError) else "cannot read"
|
|
89
|
+
raise WorkspaceError(
|
|
90
|
+
f"{source}: {problem}: {error}; available solvers: {choices}"
|
|
91
|
+
) from error
|
|
92
|
+
return _validate(values, source, available_solvers)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Create the empty campaign layout without importing a solver adapter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Collection
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from cfdbender.core.settings import WorkspaceError, _validate
|
|
10
|
+
|
|
11
|
+
INPUT_KINDS = (
|
|
12
|
+
"geometries",
|
|
13
|
+
"references",
|
|
14
|
+
"setups",
|
|
15
|
+
"pproc",
|
|
16
|
+
"profiles",
|
|
17
|
+
"freestreams",
|
|
18
|
+
"calibrations",
|
|
19
|
+
"hpc",
|
|
20
|
+
"fsi",
|
|
21
|
+
"matrices",
|
|
22
|
+
"management",
|
|
23
|
+
)
|
|
24
|
+
#: The input folders the solver adapters of this package read. The other kinds
|
|
25
|
+
#: belong to the FlightStream layout and stay in a mock workspace.
|
|
26
|
+
SOLVER_INPUT_KINDS = ("geometries", "references", "setups", "pproc", "hpc", "matrices")
|
|
27
|
+
_LIBRARY_SOLVERS = frozenset({"su2", "openfoam", "pyfr", "xfoil", "qprop"})
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def input_kinds(solver: str) -> tuple[str, ...]:
|
|
31
|
+
"""Return the input folders a new workspace of this solver is created with.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
solver : str
|
|
36
|
+
Registered solver name.
|
|
37
|
+
|
|
38
|
+
Returns
|
|
39
|
+
-------
|
|
40
|
+
tuple of str
|
|
41
|
+
Folder names under inputs/, in creation order.
|
|
42
|
+
"""
|
|
43
|
+
return SOLVER_INPUT_KINDS if solver in _LIBRARY_SOLVERS else INPUT_KINDS
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def init_workspace(root: str | Path, *, solver: str, available_solvers: Collection[str]) -> Path:
|
|
47
|
+
"""Create a workspace and bind it to one registered solver.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
root : str or Path
|
|
52
|
+
Campaign root to create or complete, resolved once.
|
|
53
|
+
solver : str
|
|
54
|
+
Exact registered solver name to put in init.toml.
|
|
55
|
+
available_solvers : Collection[str]
|
|
56
|
+
Names passed as data by the application, without loading adapters.
|
|
57
|
+
|
|
58
|
+
Returns
|
|
59
|
+
-------
|
|
60
|
+
Path
|
|
61
|
+
The absolute workspace root.
|
|
62
|
+
|
|
63
|
+
Raises
|
|
64
|
+
------
|
|
65
|
+
WorkspaceError
|
|
66
|
+
If init.toml already exists, the solver is unknown, or a layout path is a file.
|
|
67
|
+
OSError
|
|
68
|
+
If the filesystem cannot create the workspace.
|
|
69
|
+
"""
|
|
70
|
+
target = Path(root).resolve()
|
|
71
|
+
declaration = target / "init.toml"
|
|
72
|
+
if declaration.exists() or declaration.is_symlink():
|
|
73
|
+
raise WorkspaceError(f"{declaration} already exists; choose a new workspace root")
|
|
74
|
+
config = _validate({"schema_version": 1, "solver": solver}, declaration, available_solvers)
|
|
75
|
+
folders = [
|
|
76
|
+
target,
|
|
77
|
+
target / "inputs",
|
|
78
|
+
*(target / "inputs" / kind for kind in input_kinds(config.solver)),
|
|
79
|
+
*(target / name for name in ("sims", "post", "archive")),
|
|
80
|
+
]
|
|
81
|
+
for folder in folders:
|
|
82
|
+
if folder.exists() and not folder.is_dir():
|
|
83
|
+
raise WorkspaceError(f"{folder}: not a directory")
|
|
84
|
+
for folder in folders:
|
|
85
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
86
|
+
# Exclusive creation protects the one-solver binding from an overlapping init.
|
|
87
|
+
with declaration.open("x", encoding="utf-8", newline="\n") as stream:
|
|
88
|
+
stream.write(f"schema_version = 1\nsolver = {json.dumps(config.solver)}\n")
|
|
89
|
+
# This machine's executable paths stay out of version control.
|
|
90
|
+
ignore = target / "inputs" / ".gitignore"
|
|
91
|
+
if not ignore.exists():
|
|
92
|
+
ignore.write_text("executables.local.toml\n", encoding="utf-8", newline="\n")
|
|
93
|
+
return target
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Solver-neutral geometry helpers that depend on nothing outside the standard library."""
|