24 const word functionName)
38 if (
mode_ ==
"surface")
42 reduce(size, sumOp<label>());
45 FatalErrorIn(
"") <<
"surface mode is used but patchToFace is not set!"
50 if (
mode_ ==
"probePoint")
62 IOdictionary transportProperties(
64 "transportProperties",
65 mesh.time().constant(),
71 Cp_ = readScalar(transportProperties.lookup(
"Cp"));
85 scalar endTime =
mesh_.time().endTime().value();
86 scalar deltaT =
mesh_.time().deltaT().value();
87 label nTimeSteps = round(endTime / deltaT);
89 word checkRefDataFolder;
90 label nRefValueInstances;
94 checkRefDataFolder = Foam::name(endTime);
95 nRefValueInstances = nTimeSteps;
100 checkRefDataFolder = Foam::name(0);
101 nRefValueInstances = 1;
108 volScalarField varData(
113 IOobject::READ_IF_PRESENT,
116 dimensionedScalar(
"dummy", dimensionSet(0, 0, 0, 0, 0, 0, 0), 1e16),
119 if (gSumMag(varData) > 1e16)
126 volVectorField varData(
131 IOobject::READ_IF_PRESENT,
134 dimensionedVector(
"dummy", dimensionSet(0, 0, 0, 0, 0, 0, 0), {1e16, 1e16, 1e16}),
137 if (mag(gSumCmptMag(varData)) > 1e16)
144 FatalErrorIn(
"") <<
"varType " <<
varType_ <<
" not supported!"
145 <<
"Options are: scalar or vector"
146 << abort(FatalError);
153 Info <<
"**************************************************************************** " << endl;
154 Info <<
"* WARNING! Can't find data files or can't find valid * " << endl;
155 Info <<
"* values in data files for the variance function " <<
varName_ <<
" * " << endl;
156 Info <<
"**************************************************************************** " << endl;
168 for (label n = 0; n < nRefValueInstances; n++)
173 scalar t = (n + 1) * deltaT;
174 timeName = Foam::name(t);
178 timeName = Foam::name(0);
181 volScalarField varData(
192 if (
mode_ ==
"probePoint")
208 else if (
mode_ ==
"surface")
216 refValue_[n].append(varData.boundaryField()[patchI][faceI]);
220 else if (
mode_ ==
"field")
231 FatalErrorIn(
"") <<
"mode " <<
mode_ <<
" not supported!"
232 <<
"Options are: probePoint, field, or surface"
233 << abort(FatalError);
239 for (label n = 0; n < nRefValueInstances; n++)
244 scalar t = (n + 1) * deltaT;
245 timeName = Foam::name(t);
249 timeName = Foam::name(0);
252 volVectorField varData(
263 if (
mode_ ==
"probePoint")
277 refValue_[n].append(varData[cellI][compI]);
283 else if (
mode_ ==
"surface")
295 refValue_[n].append(varData.boundaryField()[patchI][faceI][compI]);
300 else if (
mode_ ==
"field")
308 refValue_[n].append(varData[cellI][compI]);
315 FatalErrorIn(
"") <<
"mode " <<
mode_ <<
" not supported!"
316 <<
"Options are: probePoint, field, or surface"
317 << abort(FatalError);
324 Info <<
"Find " <<
nRefPoints_ <<
" reference points for variance of " <<
varName_ << endl;
327 FatalErrorIn(
"") <<
"varData field exists but one can not find any valid data!"
328 << abort(FatalError);
342 scalar functionValue = 0.0;
347 const objectRegistry& db =
mesh_.thisDb();
352 timeIndex =
mesh_.time().timeIndex();
371 const vectorField& SfB =
mesh_.Sf().boundaryField()[patchI];
372 const scalarField& magSfB =
mesh_.magSf().boundaryField()[patchI];
373 const symmTensorField& ReffB = devRhoReff.boundaryField()[patchI];
375 vectorField shearB = (-SfB / magSfB) & ReffB;
380 scalar varDif = (shearB[faceI][compI] -
refValue_[timeIndex - 1][pointI]);
381 functionValue +=
scale_ * varDif * varDif;
386 else if (
varName_ ==
"wallHeatFlux")
391 const volScalarField&
T =
mesh_.thisDb().lookupObject<volScalarField>(
"T");
393 const volScalarField::Boundary& TBf =
T.boundaryField();
394 const volScalarField::Boundary& alphaEffBf =
alphaEff.boundaryField();
404 scalarField hfx =
Cp_ * alphaEffBf[patchI] * TBf[patchI].snGrad();
406 scalar varDif = (hfx[faceI] -
refValue_[timeIndex - 1][pointI]);
407 functionValue +=
scale_ * varDif * varDif;
415 fluidThermo& thermo_(
const_cast<fluidThermo&
>(
416 mesh_.thisDb().lookupObject<fluidThermo>(
"thermophysicalProperties")));
417 volScalarField&
he = thermo_.he();
418 const volScalarField::Boundary& heBf =
he.boundaryField();
420 const volScalarField::Boundary& alphaEffBf =
alphaEff.boundaryField();
430 scalarField hfx = alphaEffBf[patchI] * heBf[patchI].snGrad();
432 scalar varDif = (hfx[faceI] -
refValue_[timeIndex - 1][pointI]);
433 functionValue +=
scale_ * varDif * varDif;
442 const volScalarField& var = db.lookupObject<volScalarField>(
varName_);
444 if (
mode_ ==
"probePoint")
449 scalar varDif = (var[cellI] -
refValue_[timeIndex - 1][idxI]);
450 functionValue +=
scale_ * varDif * varDif;
453 else if (
mode_ ==
"surface")
462 scalar varDif = (var.boundaryField()[patchI][faceI] -
refValue_[timeIndex - 1][pointI]);
463 functionValue +=
scale_ * varDif * varDif;
467 else if (
mode_ ==
"field")
472 scalar varDif = (var[cellI] -
refValue_[timeIndex - 1][cellI]);
473 functionValue +=
scale_ * varDif * varDif;
479 const volVectorField& var = db.lookupObject<volVectorField>(
varName_);
481 if (
mode_ ==
"probePoint")
490 scalar varDif = (var[cellI][compI] -
refValue_[timeIndex - 1][pointI]);
491 functionValue +=
scale_ * varDif * varDif;
496 else if (
mode_ ==
"surface")
508 scalar varDif = (var.boundaryField()[patchI][faceI][compI] -
refValue_[timeIndex - 1][pointI]);
509 functionValue +=
scale_ * varDif * varDif;
514 else if (
mode_ ==
"field")
523 scalar varDif = (var[cellI][compI] -
refValue_[timeIndex - 1][pointI]);
524 functionValue +=
scale_ * varDif * varDif;
532 FatalErrorIn(
"") <<
"varType " <<
varType_ <<
" not supported!"
533 <<
"Options are: scalar or vector"
534 << abort(FatalError);
538 reduce(functionValue, sumOp<scalar>());
546 return functionValue;