@yakovlev-i-a/dsh-openfoam-workbench 0.0.0-stage → 0.9.26
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.
- package/CHANGELOG.md +683 -0
- package/CORE.md +50 -0
- package/LICENSE +202 -0
- package/NOTICE +29 -0
- package/README.md +373 -2
- package/client.js +48 -0
- package/cordis.patch.yml +18 -0
- package/icon.png +0 -0
- package/lib/buildlib.js +42 -0
- package/lib/caselib.js +212 -0
- package/lib/core.js +47 -0
- package/lib/discover.js +139 -0
- package/lib/escalations.js +92 -0
- package/lib/explib.js +149 -0
- package/lib/impact.js +55 -0
- package/lib/index.js +109 -0
- package/lib/knowledge.js +108 -0
- package/lib/meshlib.js +375 -0
- package/lib/needs-input.js +32 -0
- package/lib/of-case.js +485 -0
- package/lib/of-engine.js +1061 -0
- package/lib/paperlib.js +200 -0
- package/lib/presentation.js +365 -0
- package/lib/registry.js +142 -0
- package/lib/routing-guard.js +126 -0
- package/lib/runtime.js +580 -0
- package/lib/scaffold-cht.js +318 -0
- package/lib/scaffold-compressible.js +171 -0
- package/lib/scaffold.js +355 -0
- package/lib/settings-schema.js +86 -0
- package/lib/skills.js +53 -0
- package/lib/tools/build.js +90 -0
- package/lib/tools/case.js +1082 -0
- package/lib/tools/env.js +592 -0
- package/lib/tools/experience.js +165 -0
- package/lib/tools/mesh.js +408 -0
- package/lib/tools/meta.js +95 -0
- package/lib/tools/papers.js +105 -0
- package/lib/tools/render.js +94 -0
- package/lib/tools/run.js +331 -0
- package/lib/versions.js +133 -0
- package/licenses/dsh-openfoam-doctor-MIT.txt +21 -0
- package/locale/en.json +6 -0
- package/locale/ru.json +6 -0
- package/package.json +44 -4
- package/skills/openfoam-analyze/SKILL.md +27 -0
- package/skills/openfoam-case-builder/SKILL.md +61 -0
- package/skills/openfoam-cht/SKILL.md +83 -0
- package/skills/openfoam-code-modify/SKILL.md +32 -0
- package/skills/openfoam-mesh-independence/SKILL.md +55 -0
- package/skills/openfoam-meshing/SKILL.md +30 -0
- package/skills/openfoam-paper-reproduction/SKILL.md +36 -0
- package/skills/openfoam-self-evolution/SKILL.md +21 -0
- package/skills/openfoam-solver-development/SKILL.md +61 -0
- package/skills/openfoam-stats/SKILL.md +46 -0
- package/skills/openfoam-viz/SKILL.md +35 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
// Multi-region (conjugate heat transfer) scaffold.
|
|
2
|
+
//
|
|
3
|
+
// The single-region scaffold writes one set of dictionaries; a CHT case needs a
|
|
4
|
+
// coherent set per region plus the glue that tells the solver which module runs
|
|
5
|
+
// where. Conventions follow the capabilities: org 14 uses `regionSolvers` +
|
|
6
|
+
// `foamMultiRun`, com v2606 uses `chtMultiRegionFoam` + `constant/regionProperties`.
|
|
7
|
+
import { classifyPatch } from './scaffold.js'
|
|
8
|
+
|
|
9
|
+
const BANNER = (cls, object) => `/*--------------------------------*- C++ -*----------------------------------*\\
|
|
10
|
+
| ========= | |
|
|
11
|
+
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
|
12
|
+
| \\\\ / O peration | |
|
|
13
|
+
| \\\\ / A nd | |
|
|
14
|
+
| \\\\/ M anipulation | |
|
|
15
|
+
\\*---------------------------------------------------------------------------*/
|
|
16
|
+
FoamFile
|
|
17
|
+
{
|
|
18
|
+
version 2.0;
|
|
19
|
+
format ascii;
|
|
20
|
+
class ${cls};
|
|
21
|
+
object ${object};
|
|
22
|
+
}
|
|
23
|
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
24
|
+
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
const isInterface = (name, region) => new RegExp('^(.*_to_' + region + '|' + region + '_to_.*)$').test(String(name))
|
|
28
|
+
|
|
29
|
+
/** Interface temperature condition: org names it coupledTemperature, com wants the
|
|
30
|
+
* compressible coupled baffle condition with the neighbour field and a kappa source. */
|
|
31
|
+
function interfaceT(caps, kind, value) {
|
|
32
|
+
if (caps.modular) {
|
|
33
|
+
return ` type coupledTemperature;\n value uniform ${value};`
|
|
34
|
+
}
|
|
35
|
+
const kappaMethod = kind === 'fluid' ? 'fluidThermo' : 'solidThermo'
|
|
36
|
+
return ` type compressible::turbulentTemperatureCoupledBaffleMixed;\n Tnbr T;\n kappaMethod ${kappaMethod};\n sampleMode nearestPatchFace;\n value uniform ${value};`
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Classify every patch of one region: interface, inlet, outlet, wall, other. */
|
|
40
|
+
function rolesOf(patches, region) {
|
|
41
|
+
return patches.map((p) => {
|
|
42
|
+
const interfacePatch = isInterface(p.name, region)
|
|
43
|
+
return {
|
|
44
|
+
...p,
|
|
45
|
+
interface: interfacePatch,
|
|
46
|
+
role: interfacePatch ? 'interface' : classifyPatch(p.name, p.type),
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function fluidFields({ caps, roles, Uinlet, Tinlet, pInitial }) {
|
|
52
|
+
const block = (name, body) => ` ${name}\n {\n${body}\n }`
|
|
53
|
+
const perPatch = (fn) => roles.map((r) => block(r.name, fn(r))).join('\n\n')
|
|
54
|
+
const U = perPatch((r) => {
|
|
55
|
+
// com's flowRateInletVelocity needs a flow rate, not a mean velocity: use a
|
|
56
|
+
// plain fixed value there so the recipe stays mechanism-agnostic.
|
|
57
|
+
if (r.role === 'inlet') return caps.modular
|
|
58
|
+
? ` type flowRateInletVelocity;\n meanVelocity constant ${Uinlet};\n value uniform (${Uinlet} 0 0);`
|
|
59
|
+
: ` type fixedValue;\n value uniform (${Uinlet} 0 0);`
|
|
60
|
+
if (r.role === 'outlet') return ' type pressureInletOutletVelocity;\n value uniform (0 0 0);'
|
|
61
|
+
if (r.role === 'interface') return ' type noSlip;'
|
|
62
|
+
return ' type noSlip;'
|
|
63
|
+
})
|
|
64
|
+
const p = perPatch((r) => (r.role === 'interface' || r.role === 'inlet'
|
|
65
|
+
? ` type calculated;\n value uniform ${pInitial};`
|
|
66
|
+
: ` type zeroGradient;`))
|
|
67
|
+
const pRgh = perPatch((r) => (r.role === 'outlet'
|
|
68
|
+
? ` type fixedValue;\n value uniform ${pInitial};`
|
|
69
|
+
: ` type fixedFluxPressure;\n value uniform ${pInitial};`))
|
|
70
|
+
const T = perPatch((r) => {
|
|
71
|
+
if (r.role === 'interface') return interfaceT(caps, 'fluid', Tinlet)
|
|
72
|
+
if (r.role === 'inlet') return ` type fixedValue;\n value uniform ${Tinlet};`
|
|
73
|
+
if (r.role === 'outlet') return ` type inletOutlet;\n inletValue uniform ${Tinlet};\n value uniform ${Tinlet};`
|
|
74
|
+
return ' type zeroGradient;'
|
|
75
|
+
})
|
|
76
|
+
return { U, p, pRgh, T }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Per-region dictionaries and the glue files for a CHT case. */
|
|
80
|
+
export function scaffoldCht({
|
|
81
|
+
caps,
|
|
82
|
+
regions,
|
|
83
|
+
Uinlet = 5,
|
|
84
|
+
Tinlet = 500,
|
|
85
|
+
Tsolid = 300,
|
|
86
|
+
pInitial = 1e5,
|
|
87
|
+
solid = { rho: 1000, Cv: 0.5, kappa: 50 },
|
|
88
|
+
endTime = 0.02,
|
|
89
|
+
deltaT = 1e-4,
|
|
90
|
+
writeInterval = 0.01,
|
|
91
|
+
} = {}) {
|
|
92
|
+
const warnings = []
|
|
93
|
+
const notes = []
|
|
94
|
+
const files = {}
|
|
95
|
+
const fluid = regions.filter((r) => r.kind === 'fluid')
|
|
96
|
+
const solidRegions = regions.filter((r) => r.kind === 'solid')
|
|
97
|
+
if (!fluid.length || !solidRegions.length) {
|
|
98
|
+
return { ok: false, error: 'a CHT case needs at least one fluid region and one solid region' }
|
|
99
|
+
}
|
|
100
|
+
const modular = Boolean(caps.modular)
|
|
101
|
+
|
|
102
|
+
for (const region of regions) {
|
|
103
|
+
const roles = rolesOf(region.patches, region.name)
|
|
104
|
+
const interfaces = roles.filter((r) => r.interface)
|
|
105
|
+
if (!interfaces.length) warnings.push(`region ${region.name} has no <region>_to_<other> interface patch`)
|
|
106
|
+
const hasOutlet = roles.some((r) => r.role === 'outlet')
|
|
107
|
+
if (region.kind === 'fluid' && !hasOutlet) warnings.push(`fluid region ${region.name} has no outlet patch`)
|
|
108
|
+
|
|
109
|
+
if (region.kind === 'fluid') {
|
|
110
|
+
const f = fluidFields({ caps, roles, Uinlet, Tinlet, pInitial })
|
|
111
|
+
const body = (text) => BANNER('volScalarField', 'T') // placeholder, replaced below
|
|
112
|
+
const boundary = (inner) => `boundaryField\n{\n${inner}\n\n #includeEtc "caseDicts/setConstraintTypes"\n}\n`
|
|
113
|
+
files[`0/${region.name}/U`] = BANNER('volVectorField', 'U') + `\ndimensions [0 1 -1 0 0 0 0];\n\ninternalField uniform (0 0 0);\n\n` + boundary(f.U)
|
|
114
|
+
files[`0/${region.name}/p`] = BANNER('volScalarField', 'p') + `\ndimensions [1 -1 -2 0 0 0 0];\n\ninternalField uniform ${pInitial};\n\n` + boundary(f.p)
|
|
115
|
+
files[`0/${region.name}/p_rgh`] = BANNER('volScalarField', 'p_rgh') + `\ndimensions [1 -1 -2 0 0 0 0];\n\ninternalField uniform ${pInitial};\n\n` + boundary(f.pRgh)
|
|
116
|
+
files[`0/${region.name}/T`] = BANNER('volScalarField', 'T') + `\ndimensions [0 0 0 1 0 0 0];\n\ninternalField uniform ${Tinlet};\n\n` + boundary(f.T)
|
|
117
|
+
const fluidThermo = caps.modular ? 'physicalProperties' : 'thermophysicalProperties'
|
|
118
|
+
// org modular solves internal energy (hePsiThermo); com's chtMultiRegionFoam
|
|
119
|
+
// reads a rho-thermo with enthalpy (heRhoThermo + sensibleEnthalpy).
|
|
120
|
+
const thermoType = caps.modular
|
|
121
|
+
? 'hePsiThermo;\n mixture pureMixture;\n transport const;\n thermo hConst;\n equationOfState perfectGas;\n specie specie;\n energy sensibleInternalEnergy;'
|
|
122
|
+
: 'heRhoThermo;\n mixture pureMixture;\n transport const;\n thermo hConst;\n equationOfState perfectGas;\n specie specie;\n energy sensibleEnthalpy;'
|
|
123
|
+
files[`constant/${region.name}/${fluidThermo}`] = BANNER('dictionary', fluidThermo) + `
|
|
124
|
+
thermoType
|
|
125
|
+
{
|
|
126
|
+
type ${thermoType}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
mixture
|
|
130
|
+
{
|
|
131
|
+
specie { molWeight 28.9; }
|
|
132
|
+
thermodynamics { Cp 1005; ${caps.modular ? 'hf' : 'Hf'} 0; }
|
|
133
|
+
transport { mu 1.8e-05; Pr 0.7; }
|
|
134
|
+
}
|
|
135
|
+
`
|
|
136
|
+
if (caps.modular) {
|
|
137
|
+
files[`constant/${region.name}/momentumTransport`] = BANNER('dictionary', 'momentumTransport') + '\nsimulationType laminar;\n'
|
|
138
|
+
files[`constant/${region.name}/thermophysicalTransport`] = BANNER('dictionary', 'thermophysicalTransport') + `
|
|
139
|
+
laminar
|
|
140
|
+
{
|
|
141
|
+
model unityLewisFourier;
|
|
142
|
+
}
|
|
143
|
+
`
|
|
144
|
+
} else {
|
|
145
|
+
files[`constant/${region.name}/turbulenceProperties`] = BANNER('dictionary', 'turbulenceProperties') + '\nsimulationType laminar;\n'
|
|
146
|
+
}
|
|
147
|
+
files[`constant/${region.name}/pRef`] = BANNER('dictionary', 'pRef') + `\ndimensions [1 -1 -2 0 0 0 0];\nvalue ${pInitial};\n`
|
|
148
|
+
files[`constant/${region.name}/g`] = BANNER('dictionary', 'g') + '\ndimensions [0 1 -2 0 0 0 0];\nvalue (0 0 0);\n'
|
|
149
|
+
files[`system/${region.name}/fvSchemes`] = BANNER('dictionary', 'fvSchemes') + `
|
|
150
|
+
ddtSchemes { default Euler; }
|
|
151
|
+
gradSchemes { default Gauss linear; }
|
|
152
|
+
divSchemes
|
|
153
|
+
{
|
|
154
|
+
default none;
|
|
155
|
+
div(phi,U) Gauss linearUpwind grad(U);
|
|
156
|
+
${caps.modular
|
|
157
|
+
? ` div(phi,e) Gauss upwind;
|
|
158
|
+
div(phi,K) Gauss upwind;
|
|
159
|
+
div(phi,Ekp) Gauss upwind;
|
|
160
|
+
div(phi,(p|rho)) Gauss upwind;`
|
|
161
|
+
: ` div(phi,h) Gauss upwind;
|
|
162
|
+
div(phi,K) Gauss upwind;
|
|
163
|
+
div(phid,p) Gauss upwind;`}
|
|
164
|
+
div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear;
|
|
165
|
+
}
|
|
166
|
+
laplacianSchemes { default Gauss linear corrected; }
|
|
167
|
+
interpolationSchemes { default linear; }
|
|
168
|
+
snGradSchemes { default corrected; }
|
|
169
|
+
`
|
|
170
|
+
files[`system/${region.name}/fvSolution`] = BANNER('dictionary', 'fvSolution') + `
|
|
171
|
+
solvers
|
|
172
|
+
{
|
|
173
|
+
p_rgh { solver GAMG; smoother GaussSeidel; tolerance 1e-7; relTol 0.01; }
|
|
174
|
+
p_rghFinal { $p_rgh; relTol 0; }
|
|
175
|
+
"(rho|U|e|h)" { solver PBiCGStab; preconditioner DILU; tolerance 1e-7; relTol 0.1; }
|
|
176
|
+
"(rho|U|e|h)Final" { solver PBiCGStab; preconditioner DILU; tolerance 1e-7; relTol 0; }
|
|
177
|
+
h { solver PBiCGStab; preconditioner DILU; tolerance 1e-7; relTol 0.1; }
|
|
178
|
+
hFinal { $h; relTol 0; }
|
|
179
|
+
}
|
|
180
|
+
PIMPLE { nCorrectors 2; nNonOrthogonalCorrectors 1; nOuterCorrectors 1; }
|
|
181
|
+
relaxationFactors { equations { ".*" 1; } }
|
|
182
|
+
`
|
|
183
|
+
} else {
|
|
184
|
+
const inner = roles.map((r) => ` ${r.name}\n {\n${interfaceT(caps, 'solid', Tsolid)}\n }`).join('\n\n')
|
|
185
|
+
files[`0/${region.name}/T`] = BANNER('volScalarField', 'T') + `\ndimensions [0 0 0 1 0 0 0];\n\ninternalField uniform ${Tsolid};\n\nboundaryField\n{\n${inner}\n}\n`
|
|
186
|
+
if (!caps.modular) {
|
|
187
|
+
// com's chtMultiRegionFoam reads a pressure field in every region
|
|
188
|
+
const calc = roles.map((r) => ` ${r.name}\n {\n type calculated;\n value uniform ${pInitial};\n }`).join('\n\n')
|
|
189
|
+
files[`0/${region.name}/p`] = BANNER('volScalarField', 'p') + `\ndimensions [1 -1 -2 0 0 0 0];\n\ninternalField uniform ${pInitial};\n\nboundaryField\n{\n${calc}\n}\n`
|
|
190
|
+
}
|
|
191
|
+
const solidThermo = caps.modular ? 'physicalProperties' : 'thermophysicalProperties'
|
|
192
|
+
const solidBody = caps.modular
|
|
193
|
+
? `thermoType
|
|
194
|
+
{
|
|
195
|
+
type heSolidThermo;
|
|
196
|
+
mixture pureMixture;
|
|
197
|
+
transport constIsoSolid;
|
|
198
|
+
thermo eConst;
|
|
199
|
+
equationOfState rhoConst;
|
|
200
|
+
specie specie;
|
|
201
|
+
energy sensibleInternalEnergy;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
mixture
|
|
205
|
+
{
|
|
206
|
+
specie { nMoles 1; molWeight 63.5; }
|
|
207
|
+
transport { kappa ${solid.kappa}; }
|
|
208
|
+
thermodynamics { hf 0; Cv ${solid.Cv}; }
|
|
209
|
+
equationOfState { rho ${solid.rho}; }
|
|
210
|
+
}
|
|
211
|
+
`
|
|
212
|
+
: `thermoType
|
|
213
|
+
{
|
|
214
|
+
type heSolidThermo;
|
|
215
|
+
mixture pureMixture;
|
|
216
|
+
transport constIso;
|
|
217
|
+
thermo hConst;
|
|
218
|
+
equationOfState rhoConst;
|
|
219
|
+
specie specie;
|
|
220
|
+
energy sensibleEnthalpy;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
mixture
|
|
224
|
+
{
|
|
225
|
+
specie { nMoles 1; molWeight 63.5; }
|
|
226
|
+
transport { kappa ${solid.kappa}; }
|
|
227
|
+
thermodynamics { Hf 0; Cp ${solid.Cv}; }
|
|
228
|
+
equationOfState { rho ${solid.rho}; }
|
|
229
|
+
}
|
|
230
|
+
`
|
|
231
|
+
files[`constant/${region.name}/${solidThermo}`] = BANNER('dictionary', solidThermo) + '\n' + solidBody
|
|
232
|
+
files[`system/${region.name}/fvSchemes`] = BANNER('dictionary', 'fvSchemes') + `
|
|
233
|
+
ddtSchemes { default Euler; }
|
|
234
|
+
gradSchemes { default Gauss linear; }
|
|
235
|
+
divSchemes { default none; }
|
|
236
|
+
laplacianSchemes { default Gauss linear corrected; }
|
|
237
|
+
interpolationSchemes { default linear; }
|
|
238
|
+
snGradSchemes { default corrected; }
|
|
239
|
+
`
|
|
240
|
+
files[`system/${region.name}/fvSolution`] = BANNER('dictionary', 'fvSolution') + `
|
|
241
|
+
solvers
|
|
242
|
+
{
|
|
243
|
+
"(h|e)" { solver PCG; preconditioner DIC; tolerance 1e-6; relTol 0.1; }
|
|
244
|
+
"(h|e)Final" { solver PCG; preconditioner DIC; tolerance 1e-6; relTol 0; }
|
|
245
|
+
h { solver PCG; preconditioner DIC; tolerance 1e-6; relTol 0.1; }
|
|
246
|
+
hFinal { $h; relTol 0; }
|
|
247
|
+
}
|
|
248
|
+
PIMPLE { nNonOrthogonalCorrectors 1; nOuterCorrectors 1; }
|
|
249
|
+
`
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Case-level glue: com reads constant/g at the case root.
|
|
254
|
+
files['constant/g'] = BANNER('dictionary', 'g') + '\ndimensions [0 1 -2 0 0 0 0];\nvalue (0 0 0);\n'
|
|
255
|
+
|
|
256
|
+
// Case-level glue.
|
|
257
|
+
const map = regions.map((r) => ` ${r.name} ${r.kind === 'fluid' ? 'fluid' : 'solid'};`).join('\n')
|
|
258
|
+
files['system/fvSolution'] = BANNER('dictionary', 'fvSolution') + `
|
|
259
|
+
solvers
|
|
260
|
+
{
|
|
261
|
+
p_rgh { solver GAMG; smoother GaussSeidel; tolerance 1e-7; relTol 0.01; }
|
|
262
|
+
p_rghFinal { $p_rgh; relTol 0; }
|
|
263
|
+
"(rho|U|e)" { solver PBiCGStab; preconditioner DILU; tolerance 1e-7; relTol 0.1; }
|
|
264
|
+
"(rho|U|e)Final" { solver PBiCGStab; preconditioner DILU; tolerance 1e-7; relTol 0; }
|
|
265
|
+
"(h|e)" { solver PCG; preconditioner DIC; tolerance 1e-6; relTol 0.1; }
|
|
266
|
+
"(h|e)Final" { solver PCG; preconditioner DIC; tolerance 1e-6; relTol 0; }
|
|
267
|
+
}
|
|
268
|
+
PIMPLE { nCorrectors 2; nNonOrthogonalCorrectors 1; nOuterCorrectors 1; }
|
|
269
|
+
relaxationFactors { equations { ".*" 1; } }
|
|
270
|
+
`
|
|
271
|
+
if (modular) {
|
|
272
|
+
files['system/regionSolvers'] = BANNER('dictionary', 'regionSolvers') + `\nregionSolvers\n{\n${map}\n}\n`
|
|
273
|
+
files['system/controlDict'] = BANNER('dictionary', 'controlDict') + `
|
|
274
|
+
#includeIfPresent "regionSolvers"
|
|
275
|
+
|
|
276
|
+
startFrom startTime;
|
|
277
|
+
startTime 0;
|
|
278
|
+
stopAt endTime;
|
|
279
|
+
endTime ${endTime};
|
|
280
|
+
deltaT ${deltaT};
|
|
281
|
+
writeControl runTime;
|
|
282
|
+
writeInterval ${writeInterval};
|
|
283
|
+
purgeWrite 0;
|
|
284
|
+
writeFormat ascii;
|
|
285
|
+
writePrecision 8;
|
|
286
|
+
writeCompression off;
|
|
287
|
+
timeFormat general;
|
|
288
|
+
timePrecision 6;
|
|
289
|
+
runTimeModifiable true;
|
|
290
|
+
`
|
|
291
|
+
} else {
|
|
292
|
+
const list = (kind) => regions.filter((r) => r.kind === kind).map((r) => r.name).join(' ')
|
|
293
|
+
files['constant/regionProperties'] = BANNER('dictionary', 'regionProperties') + `\nregions\n(\n fluid (${list('fluid')})\n solid (${list('solid')})\n);\n`
|
|
294
|
+
files['system/controlDict'] = BANNER('dictionary', 'controlDict') + `
|
|
295
|
+
application chtMultiRegionFoam;
|
|
296
|
+
|
|
297
|
+
startFrom startTime;
|
|
298
|
+
startTime 0;
|
|
299
|
+
stopAt endTime;
|
|
300
|
+
endTime ${endTime};
|
|
301
|
+
deltaT ${deltaT};
|
|
302
|
+
writeControl runTime;
|
|
303
|
+
writeInterval ${writeInterval};
|
|
304
|
+
purgeWrite 0;
|
|
305
|
+
writeFormat ascii;
|
|
306
|
+
writePrecision 8;
|
|
307
|
+
writeCompression off;
|
|
308
|
+
timeFormat general;
|
|
309
|
+
timePrecision 6;
|
|
310
|
+
runTimeModifiable true;
|
|
311
|
+
`
|
|
312
|
+
}
|
|
313
|
+
notes.push(modular
|
|
314
|
+
? 'org conventions: system/regionSolvers + foamMultiRun'
|
|
315
|
+
: 'com conventions: constant/regionProperties + chtMultiRegionFoam')
|
|
316
|
+
notes.push(`per-region 0/<region>/ fields were written under 0/ (no 0.orig round trip needed)`)
|
|
317
|
+
return { ok: true, files, warnings, notes, regions: regions.map((r) => ({ name: r.name, kind: r.kind, patches: rolesOf(r.patches, r.name).map((x) => ({ name: x.name, role: x.role })) })) }
|
|
318
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Compressible single-region scaffold.
|
|
2
|
+
//
|
|
3
|
+
// The family decides both the solver entry and the thermo/field layout:
|
|
4
|
+
// org 14 : application foamRun; solver fluid; hePsiThermo + internal energy,
|
|
5
|
+
// physicalProperties/momentumTransport/thermophysicalTransport, p + p_rgh
|
|
6
|
+
// com 2606: application rhoPimpleFoam; heRhoThermo + enthalpy,
|
|
7
|
+
// thermophysicalProperties/turbulenceProperties, p only
|
|
8
|
+
import { classifyPatch } from './scaffold.js'
|
|
9
|
+
|
|
10
|
+
const BANNER = (cls, object) => `/*--------------------------------*- C++ -*----------------------------------*\\
|
|
11
|
+
| ========= | |
|
|
12
|
+
| \\\\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
|
13
|
+
| \\\\ / O peration | |
|
|
14
|
+
| \\\\ / A nd | |
|
|
15
|
+
| \\\\/ M anipulation | |
|
|
16
|
+
\\*---------------------------------------------------------------------------*/
|
|
17
|
+
FoamFile
|
|
18
|
+
{
|
|
19
|
+
version 2.0;
|
|
20
|
+
format ascii;
|
|
21
|
+
class ${cls};
|
|
22
|
+
object ${object};
|
|
23
|
+
}
|
|
24
|
+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
25
|
+
|
|
26
|
+
`
|
|
27
|
+
|
|
28
|
+
/** Dictionaries and fields for a compressible single-region case. */
|
|
29
|
+
export function scaffoldCompressible({
|
|
30
|
+
caps,
|
|
31
|
+
patches = [],
|
|
32
|
+
Uinlet = 50,
|
|
33
|
+
Tinlet = 300,
|
|
34
|
+
pInitial = 1e5,
|
|
35
|
+
endTime = 0.006,
|
|
36
|
+
deltaT = 1e-5,
|
|
37
|
+
writeInterval = 100,
|
|
38
|
+
} = {}) {
|
|
39
|
+
const modular = Boolean(caps.modular)
|
|
40
|
+
const roles = patches.map((p) => ({ ...p, role: classifyPatch(p.name, p.type) }))
|
|
41
|
+
const warnings = []
|
|
42
|
+
if (!roles.some((r) => r.role === 'outlet')) warnings.push('no outlet patch: pressure has nowhere to leave')
|
|
43
|
+
if (!roles.some((r) => r.role === 'inlet')) warnings.push('no inlet patch: velocity/temperature have no fixed value')
|
|
44
|
+
|
|
45
|
+
const files = {}
|
|
46
|
+
const boundary = (entries) => `boundaryField\n{\n${entries.join('\n\n')}\n\n #includeEtc "caseDicts/setConstraintTypes"\n}\n`
|
|
47
|
+
const perPatch = (fn) => roles.map((r) => ` ${r.name}\n {\n${fn(r)}\n }`)
|
|
48
|
+
|
|
49
|
+
const U = boundary(perPatch((r) => {
|
|
50
|
+
if (r.role === 'inlet') return ` type fixedValue;\n value uniform (${Uinlet} 0 0);`
|
|
51
|
+
if (r.role === 'outlet') return ' type pressureInletOutletVelocity;\n value uniform (0 0 0);'
|
|
52
|
+
return ' type noSlip;'
|
|
53
|
+
}))
|
|
54
|
+
const p = boundary(perPatch((r) => {
|
|
55
|
+
return r.role === 'outlet'
|
|
56
|
+
? ` type waveTransmissive;\n field p;\n gamma 1.4;\n fieldInf ${pInitial};\n lInf 0.1;\n value uniform ${pInitial};`
|
|
57
|
+
: ' type zeroGradient;'
|
|
58
|
+
}))
|
|
59
|
+
const T = boundary(perPatch((r) => (r.role === 'inlet'
|
|
60
|
+
? ` type fixedValue;\n value uniform ${Tinlet};`
|
|
61
|
+
: ' type zeroGradient;')))
|
|
62
|
+
|
|
63
|
+
// The gas starts at rest and the inlet drives the flow; a uniform Uinlet inside
|
|
64
|
+
// the domain instantly would create an unphysical pressure wave.
|
|
65
|
+
files['0/U'] = BANNER('volVectorField', 'U') + `\ndimensions [0 1 -1 0 0 0 0];\n\ninternalField uniform (0 0 0);\n\n` + U
|
|
66
|
+
files['0/p'] = BANNER('volScalarField', 'p') + `\ndimensions [1 -1 -2 0 0 0 0];\n\ninternalField uniform ${pInitial};\n\n` + p
|
|
67
|
+
files['0/T'] = BANNER('volScalarField', 'T') + `\ndimensions [0 0 0 1 0 0 0];\n\ninternalField uniform ${Tinlet};\n\n` + T
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
const thermo = modular
|
|
71
|
+
? `thermoType
|
|
72
|
+
{
|
|
73
|
+
type hePsiThermo;
|
|
74
|
+
mixture pureMixture;
|
|
75
|
+
transport const;
|
|
76
|
+
thermo hConst;
|
|
77
|
+
equationOfState perfectGas;
|
|
78
|
+
specie specie;
|
|
79
|
+
energy sensibleInternalEnergy;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
mixture
|
|
83
|
+
{
|
|
84
|
+
specie { molWeight 28.9; }
|
|
85
|
+
thermodynamics { Cp 1005; hf 0; }
|
|
86
|
+
transport { mu 1.8e-05; Pr 0.7; }
|
|
87
|
+
}
|
|
88
|
+
`
|
|
89
|
+
: `thermoType
|
|
90
|
+
{
|
|
91
|
+
type heRhoThermo;
|
|
92
|
+
mixture pureMixture;
|
|
93
|
+
transport const;
|
|
94
|
+
thermo hConst;
|
|
95
|
+
equationOfState perfectGas;
|
|
96
|
+
specie specie;
|
|
97
|
+
energy sensibleEnthalpy;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
mixture
|
|
101
|
+
{
|
|
102
|
+
specie { molWeight 28.9; }
|
|
103
|
+
thermodynamics { Cp 1005; Hf 0; }
|
|
104
|
+
transport { mu 1.8e-05; Pr 0.7; }
|
|
105
|
+
}
|
|
106
|
+
`
|
|
107
|
+
const thermoName = modular ? 'physicalProperties' : 'thermophysicalProperties'
|
|
108
|
+
files[`constant/${thermoName}`] = BANNER('dictionary', thermoName) + '\n' + thermo
|
|
109
|
+
if (modular) {
|
|
110
|
+
files['constant/momentumTransport'] = BANNER('dictionary', 'momentumTransport') + '\nsimulationType laminar;\n'
|
|
111
|
+
files['constant/thermophysicalTransport'] = BANNER('dictionary', 'thermophysicalTransport') + '\nlaminar\n{\n model unityLewisFourier;\n}\n'
|
|
112
|
+
} else {
|
|
113
|
+
files['constant/turbulenceProperties'] = BANNER('dictionary', 'turbulenceProperties') + '\nsimulationType laminar;\n'
|
|
114
|
+
}
|
|
115
|
+
files['constant/g'] = BANNER('dictionary', 'g') + '\ndimensions [0 1 -2 0 0 0 0];\nvalue (0 0 0);\n'
|
|
116
|
+
if (modular) {
|
|
117
|
+
files['constant/pRef'] = BANNER('dictionary', 'pRef') + `\ndimensions [1 -1 -2 0 0 0 0];\nvalue ${pInitial};\n`
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
files['system/controlDict'] = BANNER('dictionary', 'controlDict') + `
|
|
121
|
+
application ${modular ? 'foamRun' : 'rhoPimpleFoam'};
|
|
122
|
+
${modular ? 'solver fluid;\n' : ''}
|
|
123
|
+
startFrom startTime;
|
|
124
|
+
startTime 0;
|
|
125
|
+
stopAt endTime;
|
|
126
|
+
endTime ${endTime};
|
|
127
|
+
deltaT ${deltaT};
|
|
128
|
+
writeControl runTime;
|
|
129
|
+
writeInterval ${writeInterval};
|
|
130
|
+
purgeWrite 0;
|
|
131
|
+
writeFormat ascii;
|
|
132
|
+
writePrecision 8;
|
|
133
|
+
writeCompression off;
|
|
134
|
+
timeFormat general;
|
|
135
|
+
timePrecision 6;
|
|
136
|
+
runTimeModifiable true;
|
|
137
|
+
`
|
|
138
|
+
files['system/fvSchemes'] = BANNER('dictionary', 'fvSchemes') + `
|
|
139
|
+
ddtSchemes { default Euler; }
|
|
140
|
+
gradSchemes { default Gauss linear; }
|
|
141
|
+
divSchemes
|
|
142
|
+
{
|
|
143
|
+
default none;
|
|
144
|
+
div(phi,U) Gauss linearUpwind grad(U);
|
|
145
|
+
${modular
|
|
146
|
+
? ` div(phi,e) Gauss upwind;
|
|
147
|
+
div(phi,K) Gauss upwind;
|
|
148
|
+
div(phi,Ekp) Gauss upwind;
|
|
149
|
+
div(phi,(p|rho)) Gauss upwind;`
|
|
150
|
+
: ` div(phi,h) Gauss upwind;
|
|
151
|
+
div(phi,K) Gauss upwind;
|
|
152
|
+
div(phid,p) Gauss upwind;`}
|
|
153
|
+
div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear;
|
|
154
|
+
}
|
|
155
|
+
laplacianSchemes { default Gauss linear corrected; }
|
|
156
|
+
interpolationSchemes { default linear; }
|
|
157
|
+
snGradSchemes { default corrected; }
|
|
158
|
+
`
|
|
159
|
+
files['system/fvSolution'] = BANNER('dictionary', 'fvSolution') + `
|
|
160
|
+
solvers
|
|
161
|
+
{
|
|
162
|
+
p { solver GAMG; smoother GaussSeidel; tolerance 1e-7; relTol 0.01; }
|
|
163
|
+
pFinal { $p; relTol 0; }
|
|
164
|
+
"(rho|U|${modular ? 'e' : 'h'})" { solver PBiCGStab; preconditioner DILU; tolerance 1e-7; relTol 0.1; }
|
|
165
|
+
"(rho|U|${modular ? 'e' : 'h'})Final" { solver PBiCGStab; preconditioner DILU; tolerance 1e-7; relTol 0; }
|
|
166
|
+
}
|
|
167
|
+
PIMPLE { nCorrectors 2; nNonOrthogonalCorrectors 1; nOuterCorrectors 1; }
|
|
168
|
+
relaxationFactors { equations { ".*" 1; } }
|
|
169
|
+
`
|
|
170
|
+
return { files, warnings, notes: [modular ? 'org: foamRun + fluid module (internal energy)' : 'com: rhoPimpleFoam (enthalpy thermo)'], roles }
|
|
171
|
+
}
|