@yakovlev-i-a/dsh-openfoam-workbench 0.0.0-stage → 0.9.27

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 (56) hide show
  1. package/CHANGELOG.md +692 -0
  2. package/CORE.md +50 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +29 -0
  5. package/README.md +373 -2
  6. package/client.js +48 -0
  7. package/cordis.patch.yml +18 -0
  8. package/icon.png +0 -0
  9. package/lib/buildlib.js +42 -0
  10. package/lib/caselib.js +212 -0
  11. package/lib/core.js +47 -0
  12. package/lib/discover.js +139 -0
  13. package/lib/escalations.js +92 -0
  14. package/lib/explib.js +149 -0
  15. package/lib/impact.js +55 -0
  16. package/lib/index.js +109 -0
  17. package/lib/knowledge.js +108 -0
  18. package/lib/meshlib.js +375 -0
  19. package/lib/needs-input.js +32 -0
  20. package/lib/of-case.js +485 -0
  21. package/lib/of-engine.js +1061 -0
  22. package/lib/paperlib.js +200 -0
  23. package/lib/presentation.js +365 -0
  24. package/lib/registry.js +142 -0
  25. package/lib/routing-guard.js +126 -0
  26. package/lib/runtime.js +580 -0
  27. package/lib/scaffold-cht.js +318 -0
  28. package/lib/scaffold-compressible.js +171 -0
  29. package/lib/scaffold.js +355 -0
  30. package/lib/settings-schema.js +86 -0
  31. package/lib/skills.js +53 -0
  32. package/lib/tools/build.js +90 -0
  33. package/lib/tools/case.js +1082 -0
  34. package/lib/tools/env.js +592 -0
  35. package/lib/tools/experience.js +165 -0
  36. package/lib/tools/mesh.js +408 -0
  37. package/lib/tools/meta.js +95 -0
  38. package/lib/tools/papers.js +105 -0
  39. package/lib/tools/render.js +94 -0
  40. package/lib/tools/run.js +331 -0
  41. package/lib/versions.js +133 -0
  42. package/licenses/dsh-openfoam-doctor-MIT.txt +21 -0
  43. package/locale/en.json +6 -0
  44. package/locale/ru.json +6 -0
  45. package/package.json +44 -4
  46. package/skills/openfoam-analyze/SKILL.md +27 -0
  47. package/skills/openfoam-case-builder/SKILL.md +61 -0
  48. package/skills/openfoam-cht/SKILL.md +83 -0
  49. package/skills/openfoam-code-modify/SKILL.md +32 -0
  50. package/skills/openfoam-mesh-independence/SKILL.md +55 -0
  51. package/skills/openfoam-meshing/SKILL.md +30 -0
  52. package/skills/openfoam-paper-reproduction/SKILL.md +36 -0
  53. package/skills/openfoam-self-evolution/SKILL.md +21 -0
  54. package/skills/openfoam-solver-development/SKILL.md +61 -0
  55. package/skills/openfoam-stats/SKILL.md +46 -0
  56. package/skills/openfoam-viz/SKILL.md +35 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bushizhanghan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "OpenFOAM Workbench",
4
+ "description": "OpenFOAM workbench for DeepSeek Harness: case inspection, solver development, meshing, durable runs, off-screen renders, paper reproduction and an experience library \u2014 plus 11 on-demand CFD skills."
5
+ }
6
+ }
package/locale/ru.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "OpenFOAM Workbench",
4
+ "description": "Рабочее место OpenFOAM для DeepSeek Harness: инспекция кейсов, разработка солверов, сетки, durable-запуски, off-screen рендер, воспроизведение статей и библиотека опыта — плюс 10 CFD-скиллов по запросу."
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@yakovlev-i-a/dsh-openfoam-workbench",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.9.27",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "OpenFOAM workbench for DeepSeek Harness: 65 tools (env, solvers, meshing, multi-region runs, renders, papers, experience) and 11 on-demand CFD skills.",
7
+ "main": "lib/index.js",
8
+ "exports": {
9
+ ".": "./lib/index.js",
10
+ "./locale/*.json": "./locale/*.json",
11
+ "./icon": "./icon.png",
12
+ "./client": "./client.js",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "client.js",
17
+ "lib",
18
+ "skills",
19
+ "cordis.patch.yml",
20
+ "locale/*.json",
21
+ "icon.png",
22
+ "README.md",
23
+ "CHANGELOG.md",
24
+ "CORE.md",
25
+ "LICENSE",
26
+ "NOTICE",
27
+ "licenses"
28
+ ],
29
+ "dsh": {
30
+ "bundle": {
31
+ "patch": "./cordis.patch.yml"
32
+ },
33
+ "client": {
34
+ "platform": "web",
35
+ "immediately": true,
36
+ "inject": []
37
+ }
38
+ },
39
+ "license": "Apache-2.0",
40
+ "engines": {
41
+ "dsh": ">=0.2.2-rc.1"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ }
46
+ }
@@ -0,0 +1,27 @@
1
+ ---
2
+ name: openfoam-analyze
3
+ description: Cross-case quantitative analysis — collect case results, build a QoI table (cases × metrics), find trends and correlations, compute RMSE/MAE against reference data, and write an analysis JSON. Use when comparing a parameter sweep or several cases.
4
+ ---
5
+
6
+ # openfoam-analyze
7
+
8
+ ## When to use
9
+ - a parameter sweep / several cases
10
+ - "which case is best?", "does the QoI trend with Re / expansion ratio?"
11
+ - comparing against DNS or experimental reference
12
+
13
+ ## Recipe
14
+ 1. **Collect cases**: for each case dir read the solver/params (`controlDict`, `0/`, `postProcessing/`) and the run status (log reaches `End`, no FATAL). Exclude failed / REVISE cases and record the reason.
15
+ 2. **Pick 3–6 metrics** for the topic: BFS → `Cf`, `x_reattach`, `Cp`; channel → `Cf`, friction factor, centerline `U` RMSE; bluff body / airfoil → `Cd`, `Cl`, wake decay.
16
+ 3. **Compute per-case values** from `postProcessing/*` (forces, wallShearStress, probes) and boundary fields (see `openfoam-stats` for the extraction patterns).
17
+ 4. **QoI table**: rows = cases, columns = metrics; optionally write `metrics.csv`.
18
+ 5. **Trends**: sort by the sweep axis; note monotone trends; Pearson `r` with the sweep axis and with every other metric; keep `|r| ≥ 0.7` and `n ≥ 3`.
19
+ 6. **Reference comparison** (if available): `RMSE = sqrt(mean((sim-ref)^2))`, `MAE = mean(|sim-ref|)`, Pearson `r`. Never invent reference data.
20
+ 7. **Write `analysis.json`**: `{cases_included, cases_excluded, metrics, trends, correlations, conclusions, best_case}`.
21
+
22
+ ## Tools
23
+ `openfoam_residual_series`, `openfoam_log`, `openfoam_patch_diff`, `openfoam_run`, `bash` + `python3` (numpy/pandas/scipy). See `openfoam-stats` for Cf/Cp/force extraction.
24
+
25
+ ## Anti-hallucination
26
+ - every metric carries units and `n_samples`; below the threshold (typically 5) it is invalid.
27
+ - never rank on a metric computed from a failed or non-converged case.
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: openfoam-case-builder
3
+ description: Set up and run an OpenFOAM case from a tutorial — find a matching case, inspect it, list every tunable item, edit one at a time, run blockMesh/checkMesh/solver and verify. Use when the user wants to run or adapt a case they have or want to find.
4
+ ---
5
+
6
+ # openfoam-case-builder
7
+
8
+ ## When to use
9
+ - "run this case", "set up a case", "find a tutorial for X"
10
+ - adapting an existing case (BCs, schemes, time step, solver choice)
11
+
12
+ ## Step 0 — detect the distribution
13
+ `openfoam_version_info` / `openfoam_list_solvers` report `distribution`:
14
+ - **OpenFOAM.org (v10+, modular):** `solver <module>;` in `system/controlDict`,
15
+ run with `foamRun` (e.g. `solver incompressibleFluid;`). There is no solver
16
+ executable. Module names are in `applications/modules/`.
17
+ - **OpenFOAM.com (ESI):** `application <solver>;`, run the solver executable
18
+ (e.g. `simpleFoam`).
19
+ `openfoam_inspect_case` and `openfoam_case_probe_facts` accept both keys — read
20
+ what the case actually has, do not assume `application` or `solver`.
21
+
22
+ ## Step 1 — intent
23
+ Ask: "Do you already have a case (give me the path), or should I find a tutorial
24
+ by keywords?"
25
+
26
+ ## Step 2 — case selection
27
+ - Has a case → go to step 3.
28
+ - Else `openfoam_find_tutorial(query)` → 8–12 candidates → numbered list →
29
+ the user picks → `openfoam_clone_tutorial(tutorial_path, dest)`.
30
+
31
+ ## Step 3 — inspect
32
+ `openfoam_inspect_case(casePath)` (it already includes the recursive file
33
+ listing — do not list directories one by one). Then:
34
+ a. list every tunable item (BC / properties / mesh / solver / dt / write
35
+ frequency) as `todo` items;
36
+ b. for each item give one recommended default + 2–4 alternatives.
37
+
38
+ ## Step 4 — one item at a time
39
+ Ask one item, wait, apply with `edit`, mark the todo done, move on. Never fire
40
+ 5 questions at once.
41
+
42
+ ## Step 5 — run + verify
43
+ Pre-flight `openfoam_check(casePath)` (silent failures) → `blockMesh` →
44
+ `checkMesh` → solver via `openfoam_run_solver_async` → `openfoam_residual_series`
45
+ → `openfoam_render`. Do **not** poll immediately after starting; tell the user the
46
+ runId and let the monitor refresh.
47
+
48
+ ## Run validity (before declaring success)
49
+ - **Pre-flight**: if a stale half-finished run is in the case dir, archive it (`<case>.stale_<ts>`) and start fresh; do not clobber without asking.
50
+ - **Allrun audit** (when the case ships an `Allrun`): confirm it actually runs a flow solver to completion — `foamRun` (solver module named in controlDict) counts, `runApplication`/`runParallel` count, a commented-out solver line is BROKEN. Fix only the solver invocation, keep pre-solver setup, provide a serial fallback.
51
+ - **Runtime triage** on failure/stall: classify `divergence` / `mesh` / `bc` / `allrun_bug` / `of_version` / `oom` / `code_mod_source_bug` / `other`, and decide whether the fix belongs in the harness (Allrun/runner) or the model (physics).
52
+ - **CFL-aware retry** (numerical failures only, max 3 tries): `adjustTimeStep yes;`, `maxCo 0.5–1.0` (start 0.7), bound `maxDeltaT` (~10× initial), keep `endTime`/physics unchanged. Do not jump dt aggressively or silently downgrade physics.
53
+ - **Honest status**: `success` only when the solver log ends with `End` AND no `FOAM FATAL ERROR` in any `log.*`. Never claim success over a FATAL log.
54
+
55
+ ## Discipline
56
+ - Keep answers short, prefer numbered lists.
57
+ - Do not edit before the request is clear.
58
+
59
+ - No case yet (own geometry, incompressible laminar): `openfoam_case_scaffold`
60
+ writes controlDict/fvSchemes/fvSolution/constant/0 from the case patches
61
+ (org: `foamRun` + `incompressibleFluid`; com: `simpleFoam`), then blockMesh.
@@ -0,0 +1,83 @@
1
+ ---
2
+ name: openfoam-cht
3
+ description: Set up, run and verify a multi-region conjugate-heat-transfer case (foamMultiRun / chtMultiRegionFoam) — regions, per-region dictionaries and checkMesh, MPI run, progress/ETA and per-region renders. Use when the case has regionSolvers in system/controlDict or constant/<region>/polyMesh.
4
+ ---
5
+
6
+ # openfoam-cht
7
+
8
+ ## When to use
9
+ - `system/controlDict` has `regionSolvers { fluid ...; solid ...; }`
10
+ - the mesh lives in `constant/<region>/polyMesh`, not `constant/polyMesh`
11
+ - CHT tasks: conjugate heat transfer, cooled walls, combustion gas + solid, electronics cooling
12
+
13
+ ## Step 0 — which flavour is this case?
14
+ - **OpenFOAM.org (14+)**: `regionSolvers { fluid fluid; solid solid; }` in
15
+ `system/controlDict`; mesh regions are exactly those names; run `foamMultiRun`.
16
+ - **OpenFOAM.com (v25xx/v26xx)**: `constant/regionProperties` groups MESH regions:
17
+ `regions ( fluid (bottomAir topAir) solid (heater leftSolid) );` — the
18
+ parenthesised names are the mesh regions (`constant/<r>/polyMesh`, `0/<r>`),
19
+ `fluid`/`solid` are only solver groups. One application runs everything
20
+ (`chtMultiRegionSimpleFoam`, `chtMultiRegionFoam`), and initial fields usually
21
+ live in `0.orig/` until `restore0Dir` copies them to `0/`.
22
+ - `openfoam_inspect_case` reports `regionGroups` for the com layout, and
23
+ `openfoam_read_dict("0/<region>/<field>")` falls back to `0.orig/`.
24
+ - `openfoam_run("restore0Dir")` (or `restore0Dir -processor`) does the copy the
25
+ plugin-side way; it is a shell helper in OpenFOAM, not an executable.
26
+
27
+ ## Step 1 — read the case as regions, not as one mesh
28
+ `openfoam_inspect_case` → `regions`, `regionSolvers`, per-region `fields`/`patches`;
29
+ `openfoam_case_probe_facts` → `region_governing` (e.g. fluid compressible multicomponent,
30
+ solid solid mechanics) and `compressible`.
31
+
32
+ A single `patches: []` or `fields: ["fluid","solid"]` means the tool looked at the case
33
+ root: never conclude that the case is broken, switch to the region view.
34
+
35
+ ## Step 2 — dictionaries per region
36
+ - `openfoam_read_dict(casePath, file="fluid/fvSchemes")` or `region="fluid"`;
37
+ `system/fluid/...`, `constant/fluid/...`, `0/fluid/T` are accepted as written.
38
+ - Global `system/controlDict`: region list, time controls, `libs`.
39
+ - Region files: `system/<r>/fvSchemes`, `system/<r>/fvSolution`, `constant/<r>/*`.
40
+ - Change a control on a live case with `openfoam_dict_set` (atomic, keeps a `.bak`);
41
+ e.g. `file="fluid/fvSchemes", entry="ddtSchemes", value="..."` — check the top-level
42
+ shape first, the tool reports the entries it found.
43
+
44
+ ## Step 3 — mesh per region
45
+ - `openfoam_mesh_verify` runs `checkMesh -region <r>` for **every** region and takes the
46
+ verdict from checkMesh itself (`Mesh OK.` / `Failed N mesh checks.`).
47
+ - `checkMesh -allRegions` does not exist in OpenFOAM.org — one call per region is the only
48
+ honest one; `openfoam_mesh_verify(casePath, region="solid")` narrows it.
49
+ - A failing region: read `logTail`, do not re-run the whole case.
50
+
51
+ ## Step 4 — decompose, then run under MPI
52
+ - `openfoam_run(casePath, "decomposePar -allRegions -force")` — without `-allRegions` only
53
+ the first region is decomposed.
54
+ - `openfoam_run_solver_async(casePath, "mpirun -np 5 foamMultiRun")`. The synchronous
55
+ `openfoam_run` refuses `mpirun` on purpose: a production run must not be killed by a
56
+ tool timeout.
57
+ - `openfoam_run_progress(log_path)` → t, steps, s/step, ETA, state;
58
+ `openfoam_solver_status(run_id)` → process state; `openfoam_solver_stop(run_id)` to stop.
59
+
60
+ ## Step 5 — verify before reporting
61
+ - `openfoam_solve_verify(log_path)` → `RUNNING` is a state, not a failure; `RERUN` only on
62
+ real divergence/errors; the residual floor comes from the last complete time step.
63
+ - `openfoam_render(case_path, field="T")` renders every region; `region="solid"` narrows it;
64
+ an unknown field returns the available list. Confirm with `read_image` that the frame is
65
+ the physics you expect (uniform colour at t≈0 is data, not a bug).
66
+ - Long runs: report `t / endTime`, s/step and ETA instead of "still running".
67
+
68
+ ## Pitfalls
69
+ - **One `.foam` file at the case root** opens all regions in ParaView; a second one is noise.
70
+ - **`localEuler` in a solid region** fails: `solid solver does not support LTS, use
71
+ 'steadyState' ddtScheme`. Keep `Euler`/`steadyState` per region.
72
+ - **Interface patches**: `mappedWall` needs matching `patchToPatch`; org-14 wants
73
+ `sampleMode nearest`, not the com name `nearestPatchFace`.
74
+ - **`symmetry` vs `symmetryPlane`**: org-14 expects `symmetryPlane` for flat faces.
75
+ - **Timings are load-dependent**: s/step on a busy desktop can be 4–5× the idle value;
76
+ never quote a throughput without saying when it was measured.
77
+ - **`writeInterval` on a live run**: lowering it (via `openfoam_dict_set`, `runTimeModifiable on`)
78
+ writes a snapshot without a restart, then restore it.
79
+
80
+ ## Exit criteria
81
+ - `openfoam_mesh_verify`: PASS in every region;
82
+ - `openfoam_solve_verify`: RUNNING with ETA, or finished with decision `PROCEED`;
83
+ - `openfoam_render` + `read_image`: both regions visible, the field is the one you claim.
@@ -0,0 +1,32 @@
1
+ ---
2
+ name: openfoam-code-modify
3
+ description: Implement a small custom OpenFOAM model (viscosity/turbulence/source/fvOption) as a case-local compiled library under customModels/<Class>, built with wmake libso and activated by case dictionaries. Use for "implement a model", "add a source term", "custom viscosity".
4
+ ---
5
+
6
+ # openfoam-code-modify
7
+
8
+ ## When to use
9
+ - "implement a turbulence/viscosity model", "add a source term", "custom fvOption"
10
+ - **Not** for new transported fields or solver edits — those are out of scope; return to the user.
11
+
12
+ ## Hard rules
13
+ - Never edit `$WM_PROJECT_DIR`, `$FOAM_SRC`, or any installation directory.
14
+ - All code goes in `<case>/customModels/<ClassName>/`.
15
+ - Build case-local: `wmake libso` with `LIB = lib<ClassName>` (bare relative name, so the `.so` lands inside the case).
16
+ - Activate via `system/controlDict` `libs ("customModels/<ClassName>/lib<ClassName>.so");`
17
+ plus one dictionary: `constant/momentumTransport` or `constant/fvModels`.
18
+
19
+ ## Recipe
20
+ 1. `openfoam_inspect_case` — solver, fields, model, cell zones.
21
+ 2. `openfoam_read_source` — pull the parent class header/signatures (never guess the API).
22
+ 3. Write `<Class>.H`, `<Class>.C`, `Make/files`, `Make/options`.
23
+ 4. `wmake libso`; on failure read the **tail** of `build.log`, fix the specific line, retry.
24
+ 5. Activate, then smoke: `openfoam_dry_compile` / a short run, verify the log ends in `End`.
25
+
26
+ ## Pitfalls
27
+ - A bare `lib<Class>.so` in `controlDict.libs` resolves through the global search path — the case becomes non-portable. Use the case-relative path.
28
+ - Copying a `.so` from another case breaks reproducibility.
29
+ - Over-scoping (new field, solver edit) — stop and return to the user.
30
+
31
+ ## Verify
32
+ - `lib<Class>.so` exists **and** the case application reaches `End`
@@ -0,0 +1,55 @@
1
+ ---
2
+ name: openfoam-mesh-independence
3
+ description: Mesh-independence study before production runs — per physics group, run a baseline and a refined mesh (10% near-wall, 5% away-from-wall), compare QoIs against a 5% threshold, escalate to Richardson/GCI if needed, then lock the selected mesh. Use before bulk runs or when convergence must be justified.
4
+ ---
5
+
6
+ # openfoam-mesh-independence
7
+
8
+ ## When to use
9
+ - before production/bulk runs ("is this mesh good enough?")
10
+ - a reviewer asks for a mesh-independence statement
11
+ - a QoI moves when the mesh is refined
12
+
13
+ ## Group cases by physics
14
+ Cases sharing solver + turbulence model + custom library form one physics group → **one mesh study per group**, not per sweep value. A different y+ target (wall function vs low-Re) is a different group.
15
+
16
+ ## STEP A — reference scales and QoIs
17
+ For each group:
18
+ 1. Choose `L_ref` (chord, diameter, body height, hydraulic diameter, gap) and state why.
19
+ 2. List 3–6 QoIs: Cf, Cp, pressure drop, lift/drag/moments, x_reattach/x_separation, y+_max, mass flow, heat flux/Nusselt.
20
+
21
+ ## STEP B — build one refined mesh
22
+ - **Near-wall**: reduce wall-adjacent cell size ~10% (including first-layer thickness and layer-stack scaling); keep layer count and growth ratio ~same; keep y+ inside the target range.
23
+ - **Away-from-wall**: reduce core/wake cell size ~5%.
24
+ - Preserve topology, domain extent, blocking and meshing method.
25
+ - No prism layers? Define near-wall as cells within `d_w <= 0.05*L_ref` of a no-slip wall.
26
+
27
+ ## STEP C — run both, identical settings
28
+ Same solver/models/BCs/reference values/schemes/relaxation/dt/convergence criteria; **only the mesh changes**.
29
+ - Steady: converged by BOTH residual reduction and stabilization of integral quantities.
30
+ - Unsteady: transients decayed; same averaging window and procedure.
31
+
32
+ ## STEP D — monitor and compare
33
+ Report for both meshes: cell count, y+ statistics, checkMesh metrics (skewness, non-orthogonality, aspect ratio), and QoIs at probes/lines/planes (Cf, Cp, heat flux, lift/drag, pressure loss, mass flow).
34
+
35
+ ## STEP E — quantify
36
+ `delta_pct = 100 * |QoI_refined - QoI_baseline| / |QoI_baseline|`
37
+ - all QoIs < 5% (wall-bounded < 10%), y+ in range, refined mesh quality OK → **select baseline**.
38
+ - one QoI slightly over → run a second refinement.
39
+ - strong or monotone divergence → 3 meshes + Richardson:
40
+ ```
41
+ r = (cells_fine / cells_coarse) ** (1 / N_dim)
42
+ p = log((f_med - f_coarse) / (f_fine - f_med)) / log(r)
43
+ f_exact = f_fine + (f_fine - f_med) / (r**p - 1)
44
+ GCI_fine = 1.25 * |(f_fine - f_med) / f_fine| / (r**p - 1)
45
+ ```
46
+ Accept `GCI_fine < 5%` (validation) or `< 10%` (exploratory); safety factor 1.25 for 3 levels.
47
+ - still > 10% after two refinements → **stop and warn**: usually physics/numerics, not mesh.
48
+
49
+ ## Tools
50
+ `openfoam_mesh_verify` (checkMesh + metrics), `openfoam_run` (blockMesh/snappy/solver), `openfoam_residual_series`, `openfoam_check`, `openfoam_patch_diff`, `openfoam_render`. QoI extraction: `bash` + `python3` (see `openfoam-stats`).
51
+
52
+ ## Pitfalls
53
+ - Re-doing the study per sweep value (waste) — the gate runs once per group; sweep cases inherit the locked mesh.
54
+ - Refining a mesh before the physics/requirements are settled → the mesh is selected against the wrong physics.
55
+ - A single-level comparison never proves mesh-independence.
@@ -0,0 +1,30 @@
1
+ ---
2
+ name: openfoam-meshing
3
+ description: Go from STL geometry to an OpenFOAM mesh — inspect/render the STL, generate blockMeshDict + snappyHexMeshDict, compute the first-layer thickness from y+, run blockMesh/snappy and verify the mesh. Use for external/internal flow meshing and snappy cases.
4
+ ---
5
+
6
+ # openfoam-meshing
7
+
8
+ ## When to use
9
+ - "mesh this STL", "external flow", "airfoil/car/building", "snappyHexMesh"
10
+ - keys: STL, blockMesh, snappy, boundary layers, y+
11
+
12
+ ## Recipe
13
+ 1. `openfoam_stl_inspect(stl_path)` — triangles, bbox, watertightness, seeds.
14
+ 2. `openfoam_stl_render(stl_path)` — check normals/watertightness visually.
15
+ 3. `openfoam_compute_first_layer(U_ref, L_ref, y_plus_target)` — get the first-layer thickness.
16
+ 4. `openfoam_mesh_plan(casePath, stl_path, domain=..., first_layer_thickness=...)` —
17
+ `domain.type` is mandatory (external/internal/box).
18
+ 5. `blockMesh` → `openfoam_mesh_verify(casePath)`.
19
+ 6. `snappyHexMesh -overwrite` → `openfoam_mesh_verify(casePath)`.
20
+ 7. `openfoam_patch_diff` — confirm inlet/outlet/walls were cut out.
21
+ 8. `openfoam_mesh_stl_check` — Hausdorff fit to the original STL.
22
+
23
+ ## Pitfalls
24
+ - Missing `domain.type` → the wrong computational domain.
25
+ - `nNonOrthogonalCorrectors 0` on a skewed mesh → false convergence.
26
+ - After 3 failed snappy attempts, downgrade: `strategy=coarsen` → `minimal` → `box_stl`.
27
+
28
+ ## Verify
29
+ - `openfoam_mesh_verify` pass=true (checkMesh + visual)
30
+ - `openfoam_mesh_stl_check` pass=true
@@ -0,0 +1,36 @@
1
+ ---
2
+ name: openfoam-paper-reproduction
3
+ description: Reproduce a paper or implant its algorithm in OpenFOAM — extract the algorithm contract, probe the case, audit mismatches, then implement. Use for "reproduce this paper", "implant this algorithm", "add the drag model from the paper".
4
+ ---
5
+
6
+ # openfoam-paper-reproduction
7
+
8
+ ## When to use
9
+ - paper reproduction, algorithm implantation, adding a model from literature
10
+
11
+ ## Four-step method (mandatory)
12
+ 1. `openfoam_algo_extract_contract(source_file, algorithm_name)` — inputs/outputs/
13
+ equations/governing_type/assumptions. **No** `write` of new source before this.
14
+ 2. `openfoam_case_probe_facts(case_path)` — real facts: solver, phases, turbulence,
15
+ dimensions, patches, fields. **No** BC/property edits before this.
16
+ 3. `openfoam_algo_case_audit(contract, case_facts)` — mismatches. Non-empty → stop
17
+ and resolve or report; do not proceed.
18
+ 4. Controlled implantation: find reference → read → clone/write → compile.
19
+
20
+ ## Verify (before calling it a reproduction)
21
+ - `openfoam_solver_build` exits 0 and a short run reaches `End` (no FATAL);
22
+ - the step-4 audit still passes — a non-empty mismatch list means **not done**;
23
+ - a QoI from the paper matches within its stated tolerance, or the delta is reported;
24
+ - `openfoam_render` the result and judge it with `read_image`.
25
+
26
+ ## Literature workflow
27
+ 1. `openfoam_paper_search` → the user picks a number.
28
+ 2. `openfoam_paper_fetch(id, download=true)` → PDF.
29
+ 3. `openfoam_read_paper(path, focus=...)` → sections.
30
+ 4. `read_image` for figures/tables/formulas that carry numbers.
31
+ 5. Split into 5–15 todo items, then implement.
32
+
33
+ ## Pitfalls
34
+ - Writing new source without the contract → rework.
35
+ - Editing BCs without probing the case → wrong physics.
36
+ - Proceeding while the audit says pass:false.
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: openfoam-self-evolution
3
+ description: After a verified OpenFOAM task, distil the reusable lesson into an experience card; before a long task, recall verified recipes. Use to grow the local experience library and avoid repeating known mistakes.
4
+ ---
5
+
6
+ # openfoam-self-evolution
7
+
8
+ ## When to use
9
+ - before a long task: `openfoam_experience_recall(query)`
10
+ - after a task passed its `*_verify`: propose `openfoam_experience_save(...)`
11
+
12
+ ## Rules
13
+ - Only save verified work (a `*_verify` pass or a clean run). Do not save unverified.
14
+ - Card = recipe (3–10 steps) + key_params + pitfalls + triggers.
15
+ - `openfoam_experience_export` / `openfoam_experience_import` to share.
16
+ - Distillation (`analyzeTrajectory`/`draftFromTrajectory`) turns a verified
17
+ trajectory into a draft skill; the user reviews before it joins `skills/`.
18
+
19
+ ## Pitfalls
20
+ - Saving noise (failed/aborted runs) pollutes the library.
21
+ - Dedup is by `content_hash`; resaving the same recipe bumps hits, not files.
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: openfoam-solver-development
3
+ description: Clone, modify, build and smoke-test an OpenFOAM solver — copy a native solver into the workspace, rewrite Make/files to EXE, inspect the main loop, build with wmake and validate with -help. Use when the user wants a custom solver or to change a solver main loop.
4
+ ---
5
+
6
+ # openfoam-solver-development
7
+
8
+ ## When to use
9
+ - "new solver", "clone solver", "modify the main loop", "change UEqn/pEqn"
10
+ - keys: CreateFields, UEqn, pEqn, simpleControl/pimpleControl, CorrectPhi, Make/files, EXE
11
+
12
+ ## OpenFOAM.org vs OpenFOAM.com — check this first
13
+
14
+ `openfoam_version_info` and `openfoam_list_solvers` report the distribution.
15
+
16
+ **OpenFOAM.org (v10+): modular solvers.** The solver is a *class* selected in
17
+ `system/controlDict` by `solver <name>;` and run by `foamRun` (single region) or
18
+ `foamMultiRun` (multi-region / CHT). There is no `simpleFoam`/`interFoam`
19
+ executable. Customisation paths: implement a model as a case-local library (see
20
+ `openfoam-code-modify`), subclass a module (e.g. `incompressibleFluid`) under
21
+ `applications/modules/<name>`, or write a new module — build with `wmake libso`.
22
+ Supersession map (old → modular): `simpleFoam`/`pisoFoam`/`pimpleFoam` →
23
+ `incompressibleFluid`; `reactingFoam`/`buoyantReactingFoam` → `multicomponentFluid`;
24
+ `rhoSimpleFoam`/`rhoPimpleFoam`/`buoyantFoam` → `fluid`; `multiphaseEulerFoam` →
25
+ `multiphaseEuler`; `interFoam` → `incompressibleVoF`; `compressibleInterFoam`/
26
+ `cavitatingFoam` → `compressibleVoF`; `rhoCentralFoam` → `shockFluid`;
27
+ `XiFoam` → `XiFluid`.
28
+
29
+ **OpenFOAM.com (ESI): application solvers.** Each solver is a standalone
30
+ executable selected by `application <name>;` in `system/controlDict`. Clone the
31
+ solver source and build with `wmake` (EXE target).
32
+
33
+ Never mix the two: a `.org` case with `solver incompressibleFluid` will not run on
34
+ `.com`, and `simpleFoam` is not an executable on `.org` v10+.
35
+
36
+ ## Recipe
37
+ 1. `openfoam_find_source(query, kind="solver")` — find the closest native solver in the same family.
38
+ 2. `openfoam_read_source` — read the main `.C`, `createFields.H`, `Make/files`, `Make/options`.
39
+ 3. `openfoam_clone_solver(source, dest, new_name)` — copy into the workspace; never edit `$FOAM_APP`/`$FOAM_SRC`.
40
+ 4. Check `Make/files`: exactly one main `.C` and `EXE = $(FOAM_USER_APPBIN)/<name>`.
41
+ 5. Inventory `createFields.H`, IOobject flags, thermo/turbulence, `fvModels`/`fvConstraints`.
42
+ 6. Map the loop: `UEqn`/`pEqn`, `simpleControl`/`pimpleControl`, `nOuterCorrectors`, `CorrectPhi`, all `solve()`s.
43
+ 7. `openfoam_dry_compile(modulePath)` for the first error, then `openfoam_solver_build`.
44
+ 8. `openfoam_solver_smoke` — `-help` and a short copied case.
45
+
46
+ ## Key parameters
47
+ - EXE target: `EXE = $(FOAM_USER_APPBIN)/<name>`
48
+ - build: `wmake -j` for an EXE, `wmake libso` only for a LIB target
49
+ - source access: `openfoam_read_source` (not `read` — the general tool cannot see `/opt/openfoam*`)
50
+
51
+ ## Pitfalls
52
+ - `wmake libso` builds a library, not a solver executable.
53
+ - Leaving `EXE = $(FOAM_APPBIN)/...` writes into the system installation.
54
+ - Editing `/opt/openfoam*` in place breaks rollback — copy first.
55
+ - `.org` vs `.com` differ in headers/APIs — check the installed version first.
56
+
57
+ ## Verify
58
+ - `openfoam_dry_compile` success and `wmake -j` exit 0
59
+ - `<name> -help` starts without missing-library errors
60
+ - `ldd` resolves custom libraries from the user directory
61
+ - cloned tutorial: blockMesh → checkMesh → solver completes
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: openfoam-stats
3
+ description: Numerical analysis patterns for OpenFOAM run outputs — Cf/Cp and wall-shear extraction, drag/lift, residual plateau, QoI drift, Richardson/GCI, two-extractor agreement — plus the anti-patterns that cause silent-zero results. Use when post-processing a run or judging convergence.
4
+ ---
5
+
6
+ # openfoam-stats
7
+
8
+ A reference of compact patterns. Compose them into a `python3` snippet, run via `bash`, and persist the result as JSON next to the case. Requires only `numpy`/`scipy`.
9
+
10
+ ## Pattern 1 — Cf from wallShearStress
11
+ Source: `postProcessing/wallShearStress/<time>/wallShearStress.dat` (function object). `Cf = |tau_w| / (0.5 * rho * U_inf^2)`. Do **not** finite-difference cell-center fields.
12
+
13
+ ## Pattern 2 — Drag / lift from forceCoeffs
14
+ Source: `postProcessing/forceCoeffs/<time>/forceCoeffs.dat` (columns: Time Cd Cs Cl Cm...). Time-average the last 30% (post-transient); report `Cd_mean/std`, `Cl_mean/std`, Strouhal if the Cl FFT is meaningful.
15
+
16
+ ## Pattern 3 — Residual plateau
17
+ Parse `Solving for <field>, Initial residual = …, Final residual = …`. Tail 10%: converged if `(max-min)/max < 0.05`. Report `final`, `tail_max`, `tail_min`.
18
+
19
+ ## Pattern 4 — QoI drift (transient)
20
+ Last 10% of a QoI history: `drift = (q[-1]-q[0]) / mean(|q|)`; converged if `|drift| < 5%` (1% for strict steady-state).
21
+
22
+ ## Pattern 5 — Richardson / GCI (3 meshes)
23
+ ```
24
+ r = (cells_fine/cells_coarse) ** (1/N_dim)
25
+ p = log((f_med - f_coarse)/(f_fine - f_med)) / log(r)
26
+ f_exact = f_fine + (f_fine - f_med)/(r**p - 1)
27
+ GCI_fine = 1.25 * |(f_fine - f_med)/f_fine| / (r**p - 1)
28
+ ```
29
+ Accept `GCI_fine < 5%` (validation) / `< 10%` (exploratory). Reference: ASME V&V 20 / Roache / Celik.
30
+
31
+ ## Pattern 6 — Two-extractor agreement
32
+ Compare two independent reads (log parse vs function-object / PyVista): `rel = |A-B|/max(|A|,|B|,eps)`; bind the comparator only if `rel < 0.5`. Catches gross blind spots, tolerates methodological differences.
33
+
34
+ ## Anti-patterns (silent zeros)
35
+ - `cloudOutputProperties.massInjected` — cumulative bookkeeping, constant by design → ratio metrics ~0/1. Use the live droplet mass from `log.<solver>` (`Current mass in system`).
36
+ - `cloud:rhoTrans_*` — transient source written sparsely; often zero at write times. Use live mass or integrated species mass.
37
+ - Cell-center finite-difference for `wallShearStress` — poor accuracy; use the function object.
38
+ - Reading `0/<field>` as "the latest" — read the largest non-zero time directory.
39
+ - Treating any cumulative bookkeeping field as a per-step measurement.
40
+
41
+ ## Anti-hallucination
42
+ - Every result carries explicit units and `n_samples`; below the threshold (typically 5) it is invalid — don't rank on it.
43
+ - If a snippet fails or returns NaN/inf, write `<pattern>_failed.json` with the error, never a fake number.
44
+
45
+ ## Tools
46
+ `openfoam_residual_series`, `openfoam_log`, `openfoam_post_verify`, `openfoam_render`; `bash` + `python3` for the snippets.
@@ -0,0 +1,35 @@
1
+ ---
2
+ name: openfoam-viz
3
+ description: Generate diagnostic and publication figures from an OpenFOAM case — mesh overview, |U|/p contours, streamlines, y+ map, residual/probe histories — with publication styling (horizontal colorbar, readable fonts, aspect, zoom). Use when you need to see or present a run's flow field.
4
+ ---
5
+
6
+ # openfoam-viz
7
+
8
+ ## Figures to make (per case)
9
+ - mesh overview (full domain + zoomed near-wall)
10
+ - `|U|` contour and `p` contour at the latest non-zero time
11
+ - streamlines on a midplane
12
+ - y+ map on no-slip walls
13
+ - residual history (matplotlib)
14
+ - probe/line traces or forceCoeffs history, if configured
15
+
16
+ ## Key rule: what needs GL
17
+ - **No GL needed**: residual history, probe/forceCoeffs/QoI history → `python3` + `matplotlib`/`numpy` on `log.<solver>` and `postProcessing/*`. Always available, even headless.
18
+ - **Needs GL**: field contours, streamlines, mesh views → `openfoam_render` (pvpython). ParaView 6.x renders off-screen headless (no DISPLAY); legacy 5.x GLX builds need xvfb or an OSMesa/EGL build.
19
+ - Fallback when GL is unavailable: `foamToVTK` the case and hand the VTK files to the user, or plot line/probe data with matplotlib.
20
+
21
+ ## Styling (publication quality)
22
+ - horizontal colorbar: `position_y ≈ 0.05`, `height ≈ 0.04`, `width ≈ 0.5` — never vertical/default.
23
+ - fonts: title ≥ 16, labels/ticks ≥ 14.
24
+ - window: `(1600, 900)` for wide/channel geometry, `(1600, 1200)` for tall/square.
25
+ - zoomed-feature plots: `camera.zoom(1.5–2.5)` after setting the view.
26
+ - one colormap per field across the whole set, and identical `clim` across cases in one comparison panel.
27
+
28
+ ## Data hygiene
29
+ - plot the latest **non-zero** time, not `0/`.
30
+ - decimate very large meshes for visualization only (never for QoIs).
31
+ - never plot a field that does not exist at that time.
32
+ - never invent reference data — skip the comparison series if no reference exists.
33
+
34
+ ## Tools
35
+ `openfoam_render` (pvpython), `openfoam_residual_series`, `openfoam_log`, `bash` + `python3` (matplotlib/numpy), `read_image` to judge the rendered PNGs.