24 Info <<
"Get ref data for field inversion...." << endl;
29 "field variables name to extract");
34 "field variables type");
39 "prescribe a specific time to extract data");
41 #include "setRootCase.H"
42 #include "createTime.H"
43 #include "createMesh.H"
46 if (
args.optionFound(
"refFieldName"))
48 refFieldName = word(
args.optionLookup(
"refFieldName")());
52 Info <<
"refFieldName not set! Exit." << endl;
57 if (
args.optionFound(
"refFieldType"))
59 refFieldType = word(
args.optionLookup(
"refFieldType")());
63 Info <<
"refFieldType not set! Exit." << endl;
68 if (
args.optionFound(
"time"))
70 time = readScalar(
args.optionLookup(
"time")());
73 Info <<
"Extract latestTime" << endl;
77 Info <<
"Extract time = " << time << endl;
82 Info <<
"time not set! Extract all time instances." << endl;
85 scalar endTime =
runTime.endTime().value();
86 scalar deltaT =
runTime.deltaT().value();
87 label nInstances = -1;
90 nInstances = round(endTime / deltaT);
97 Info <<
"Extracting field " << refFieldName << endl;
99 for (label n = 1; n < nInstances + 1; n++)
107 else if (time == 9999)
111 t = timeDirs.last().value();
120 if (refFieldName ==
"wallHeatFlux")
126 mesh.time().timeName(),
131 dimensionedScalar(
"wallHeatFluxData", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0),
137 mesh.time().timeName(),
139 IOobject::READ_IF_PRESENT,
142 dimensionedScalar(
"rho", dimensionSet(1, -3, 0, 0, 0, 0, 0), 1.0),
148 mesh.time().timeName(),
157 mesh.time().timeName(),
167 volScalarField alpha(
170 mesh.time().timeName(),
175 dimensionedScalar(
"alpha", dimensionSet(0, 2, -1, 0, 0, 0, 0), 0.0),
178 IOdictionary transportProperties(
180 "transportProperties",
181 mesh.time().constant(),
187 scalar nu = transportProperties.getScalar(
"nu");
188 scalar
Pr = transportProperties.getScalar(
"Pr");
189 scalar Cp = transportProperties.getScalar(
"Cp");
192 alpha[cellI] = nu /
Pr;
194 alpha.correctBoundaryConditions();
200 if (
mesh.boundaryMesh()[patchI].type() ==
"wall" &&
mesh.boundaryMesh()[patchI].size() > 0)
202 scalarField flux = Cp *
alphaEff.boundaryField()[patchI] *
T.boundaryField()[patchI].snGrad();
205 hfx.boundaryFieldRef()[patchI][faceI] = flux[faceI];
216 volScalarField alpha(
219 mesh.time().timeName(),
224 dimensionedScalar(
"alpha", dimensionSet(1, -1, -1, 0, 0, 0, 0), 0.0),
227 IOdictionary thermophysicalProperties(
229 "thermophysicalProperties",
230 mesh.time().constant(),
236 dictionary subDict = thermophysicalProperties.subDict(
"mixture").subDict(
"transport");
237 scalar
mu = subDict.getScalar(
"mu");
238 scalar
Pr = subDict.getScalar(
"Pr");
239 scalar Cp = thermophysicalProperties.subDict(
"mixture").subDict(
"thermodynamics").getScalar(
"Cp");
240 scalar molWeight = thermophysicalProperties.subDict(
"mixture").subDict(
"specie").getScalar(
"molWeight");
243 alpha[cellI] =
mu *
rho[cellI] /
Pr;
245 alpha.correctBoundaryConditions();
252 mesh.time().timeName(),
257 dimensionedScalar(
"he", dimensionSet(0, 0, 0, 0, 0, 0, 0), 0.0),
260 word energy = thermophysicalProperties.subDict(
"thermoType").getWord(
"energy");
261 if (energy ==
"sensibleInternalEnergy")
264 scalar RR = Foam::constant::thermodynamic::RR;
265 scalar R = RR / molWeight;
268 he[cellI] = (Cp - R) *
T[cellI];
272 forAll(
he.boundaryField()[patchI], faceI)
274 he.boundaryFieldRef()[patchI][faceI] = (Cp - R) *
T.boundaryField()[patchI][faceI];
277 he.correctBoundaryConditions();
279 else if (energy ==
"sensibleEnthalpy")
284 he[cellI] = Cp *
T[cellI];
288 forAll(
he.boundaryField()[patchI], faceI)
290 he.boundaryFieldRef()[patchI][faceI] = Cp *
T.boundaryField()[patchI][faceI];
293 he.correctBoundaryConditions();
297 FatalErrorIn(
"") <<
"energy type: " << energy <<
" not supported in thermophysicalProperties" << abort(FatalError);
302 if (
mesh.boundaryMesh()[patchI].type() ==
"wall" &&
mesh.boundaryMesh()[patchI].size() > 0)
304 scalarField flux =
alphaEff.boundaryField()[patchI] *
he.boundaryField()[patchI].snGrad();
307 hfx.boundaryFieldRef()[patchI][faceI] = flux[faceI];
315 else if (refFieldName ==
"wallShearStress")
320 volVectorField shear(
322 "wallShearStressData",
323 mesh.time().timeName(),
328 dimensionedVector(
"wallShearStressData", dimensionSet(0, 0, 0, 0, 0, 0, 0), vector::zero),
334 mesh.time().timeName(),
336 IOobject::READ_IF_PRESENT,
339 dimensionedScalar(
"rho", dimensionSet(1, -3, 0, 0, 0, 0, 0), 1.0),
345 mesh.time().timeName(),
354 mesh.time().timeName(),
363 mesh.time().timeName(),
368 dimensionedScalar(
"nu", dimensionSet(0, 2, -1, 0, 0, 0, 0), 0.0),
374 IOdictionary transportProperties(
376 "transportProperties",
377 mesh.time().constant(),
383 scalar nuRead = transportProperties.getScalar(
"nu");
388 nu.correctBoundaryConditions();
393 IOdictionary thermophysicalProperties(
395 "thermophysicalProperties",
396 mesh.time().constant(),
402 dictionary subDict = thermophysicalProperties.subDict(
"mixture").subDict(
"transport");
403 scalar
mu = subDict.getScalar(
"mu");
406 nu[cellI] =
mu *
rho[cellI];
408 nu.correctBoundaryConditions();
411 volScalarField nuEff(
"nuEff", nut + nu);
413 volSymmTensorField devRhoReff = (-
rho * nuEff) * dev(twoSymm(fvc::grad(
U)));
415 forAll(shear.boundaryField(), patchI)
417 vectorField& shearp = shear.boundaryFieldRef()[patchI];
418 const vectorField& Sfp =
mesh.Sf().boundaryField()[patchI];
419 const scalarField& magSfp =
mesh.magSf().boundaryField()[patchI];
420 const symmTensorField& Reffp = devRhoReff.boundaryField()[patchI];
422 shearp = (-Sfp / magSfp) & Reffp;
427 else if (refFieldType ==
"scalar")
429 volScalarField fieldRead(
432 mesh.time().timeName(),
438 fieldRead.rename(refFieldName +
"Data");
441 else if (refFieldType ==
"vector")
443 volVectorField fieldRead(
446 mesh.time().timeName(),
452 fieldRead.rename(refFieldName +
"Data");
457 Info <<
"refFieldName and type not supported!" << endl;
461 Info <<
"Finished!" << endl;