25 const word objFuncName,
26 const word objFuncPart,
27 const dictionary& objFuncDict)
37 daTurb_(
daModel.getDATurbulenceModel())
81 const labelList& objFuncFaceSources,
82 const labelList& objFuncCellSources,
83 scalarList& objFuncFaceValues,
84 scalarList& objFuncCellValues,
108 forAll(objFuncCellValues, idxI)
110 objFuncCellValues[idxI] = 0.0;
115 const objectRegistry& db =
mesh_.thisDb();
120 const volScalarField betaFieldInversion_ = db.lookupObject<volScalarField>(
stateName_);
122 forAll(objFuncCellSources, idxI)
124 const label& cellI = objFuncCellSources[idxI];
125 objFuncCellValues[idxI] =
scale_ * (sqr(betaFieldInversion_[cellI] - 1.0));
126 objFuncValue += objFuncCellValues[idxI];
129 reduce(objFuncValue, sumOp<scalar>());
133 objFuncValue =
weight_ * objFuncValue;
136 else if (
data_ ==
"UData")
140 const volVectorField state = db.lookupObject<volVectorField>(
stateName_);
141 const volVectorField stateRef = db.lookupObject<volVectorField>(
stateRefName_);
142 forAll(objFuncCellSources, idxI)
144 const label& cellI = objFuncCellSources[idxI];
145 scalar stateRefCell(mag(stateRef[cellI]));
146 if (stateRefCell < 1e16)
148 objFuncCellValues[idxI] = (sqr(mag(
scale_ * state[cellI] - stateRef[cellI])));
149 objFuncValue += objFuncCellValues[idxI];
154 reduce(objFuncValue, sumOp<scalar>());
158 objFuncValue =
weight_ * objFuncValue;
161 else if (
data_ ==
"USingleComponentData")
165 scalarList velocityCompt;
166 objFuncDict_.readEntry<scalarList>(
"velocityComponent", velocityCompt);
167 vector velocityComponent_;
168 velocityComponent_[0] = velocityCompt[0];
169 velocityComponent_[1] = velocityCompt[1];
170 velocityComponent_[2] = velocityCompt[2];
173 const volVectorField state = db.lookupObject<volVectorField>(
stateName_);
176 const volScalarField stateRef = db.lookupObject<volScalarField>(
stateRefName_);
178 forAll(objFuncCellSources, idxI)
180 const label& cellI = objFuncCellSources[idxI];
181 if (stateRef[cellI] < 1e16)
183 vector URANS(state[cellI]);
184 scalar UData(stateRef[cellI]);
185 objFuncCellValues[idxI] = (sqr(
scale_ * (URANS & velocityComponent_) - UData));
186 objFuncValue += objFuncCellValues[idxI];
191 reduce(objFuncValue, sumOp<scalar>());
195 objFuncValue =
weight_ * objFuncValue;
199 else if (
data_ ==
"pData")
205 const volScalarField& state = db.lookupObject<volScalarField>(
stateName_);
208 const volScalarField& stateRef = db.lookupObject<volScalarField>(
stateRefName_);
210 forAll(objFuncCellSources, idxI)
212 const label& cellI = objFuncCellSources[idxI];
213 if (stateRef[cellI] < 1e16)
215 objFuncCellValues[idxI] = (sqr(
scale_ * state[cellI]- stateRef[cellI]));
216 objFuncValue += objFuncCellValues[idxI];
221 reduce(objFuncValue, sumOp<scalar>());
225 objFuncValue =
weight_ * objFuncValue;
228 else if (
data_ ==
"surfacePressureData")
233 const volScalarField surfacePressureRef = db.lookupObject<volScalarField>(
stateRefName_);
234 const volScalarField&
p = db.lookupObject<volScalarField>(
stateName_);
236 wordList patchNames_;
237 objFuncDict_.readEntry<wordList>(
"patchNames", patchNames_);
239 bool nonZeroPRefFlag_;
240 objFuncDict_.readEntry<
bool>(
"nonZeroPRef", nonZeroPRefFlag_);
243 if (nonZeroPRefFlag_ ==
true)
245 scalarList pRefCoords;
246 objFuncDict_.readEntry<scalarList>(
"pRefCoords", pRefCoords);
248 pRefCoords_[0] = pRefCoords[0];
249 pRefCoords_[1] = pRefCoords[1];
250 pRefCoords_[2] = pRefCoords[2];
253 label cellID =
mesh_.findCell(pRefCoords_);
259 reduce(pRef_, maxOp<scalar>());
264 label patchI =
mesh_.boundaryMesh().findPatchID(patchNames_[cI]);
265 const fvPatch& patch =
mesh_.boundary()[patchI];
268 scalar bSurfacePressure =
scale_ * (
p.boundaryField()[patchI][faceI] - pRef_);
269 scalar bSurfacePressureRef = surfacePressureRef.boundaryField()[patchI][faceI];
270 if (bSurfacePressureRef < 1e16)
272 objFuncValue += sqr(bSurfacePressure - bSurfacePressureRef);
277 reduce(objFuncValue, sumOp<scalar>());
280 objFuncValue =
weight_ * objFuncValue;
283 else if(
data_ ==
"surfaceFrictionData")
287 wordList patchNames_;
288 objFuncDict_.readEntry<wordList>(
"patchNames", patchNames_);
297 volScalarField& surfaceFriction =
const_cast<volScalarField&
>(db.lookupObject<volScalarField>(
stateName_));
298 const volScalarField surfaceFrictionRef = db.lookupObject<volScalarField>(
stateRefName_);
302 volSymmTensorField::Boundary bReff = Reff().boundaryField();
303 const surfaceVectorField::Boundary& Sfp =
mesh_.Sf().boundaryField();
304 const surfaceScalarField::Boundary& magSfp =
mesh_.magSf().boundaryField();
308 label patchI =
mesh_.boundaryMesh().findPatchID(patchNames_[cI]);
309 const fvPatch& patch =
mesh_.boundary()[patchI];
312 scalar bSurfaceFrictionRef = surfaceFrictionRef.boundaryField()[patchI][faceI];
315 vector normal = -Sfp[patchI][faceI] / magSfp[patchI][faceI];
318 vector wss = normal & bReff[patchI][faceI];
321 scalar bSurfaceFriction =
scale_ * (wss & wssDir_);
323 surfaceFriction.boundaryFieldRef()[patchI][faceI] = bSurfaceFriction;
327 if (bSurfaceFrictionRef < 1e16)
330 objFuncValue += sqr(bSurfaceFriction - bSurfaceFrictionRef);
336 reduce(objFuncValue, sumOp<scalar>());
340 objFuncValue =
weight_ * objFuncValue;
343 else if(
data_ ==
"aeroCoeffData")
349 forceDir_[0] = dir[0];
350 forceDir_[1] = dir[1];
351 forceDir_[2] = dir[2];
352 scalar aeroCoeffRef_;
353 objFuncDict_.readEntry<scalar>(
"aeroCoeffRef", aeroCoeffRef_);
354 wordList patchNames_;
355 objFuncDict_.readEntry<wordList>(
"patchNames", patchNames_);
357 const volScalarField&
p = db.lookupObject<volScalarField>(
"p");
358 const surfaceVectorField::Boundary& Sfb =
mesh_.Sf().boundaryField();
360 const volSymmTensorField::Boundary& devRhoReffb = tdevRhoReff().boundaryField();
362 vector forces(vector::zero);
364 scalar aeroCoeff(0.0);
369 label patchI =
mesh_.boundaryMesh().findPatchID(patchNames_[cI]);
372 const fvPatch& patch =
mesh_.boundary()[patchI];
375 vectorField fN(Sfb[patchI] *
p.boundaryField()[patchI]);
378 vectorField fT(Sfb[patchI] & devRhoReffb[patchI]);
382 forces.x() = fN[faceI].x() + fT[faceI].x();
383 forces.y() = fN[faceI].y() + fT[faceI].y();
384 forces.z() = fN[faceI].z() + fT[faceI].z();
385 aeroCoeff +=
scale_ * (forces & forceDir_);
389 reduce(aeroCoeff, sumOp<scalar>());
392 objFuncValue += sqr(aeroCoeff - aeroCoeffRef_);
397 objFuncValue =
weight_ * objFuncValue;
400 else if (
data_ ==
"surfaceFrictionDataModified")
412 wordList patchNames_;
413 objFuncDict_.readEntry<wordList>(
"patchNames", patchNames_);
416 volScalarField& surfaceFriction =
const_cast<volScalarField&
>(db.lookupObject<volScalarField>(
stateName_));
417 const volScalarField& surfaceFrictionRef = db.lookupObject<volScalarField>(
stateRefName_);
420 const volVectorField&
U = db.lookupObject<volVectorField>(
"U");
421 tmp<volTensorField> gradU = fvc::grad(
U);
422 const volTensorField::Boundary& bGradU = gradU().boundaryField();
424 const surfaceVectorField::Boundary& Sfp =
mesh_.Sf().boundaryField();
425 const surfaceScalarField::Boundary& magSfp =
mesh_.magSf().boundaryField();
429 label patchI =
mesh_.boundaryMesh().findPatchID(patchNames_[cI]);
430 const fvPatch& patch =
mesh_.boundary()[patchI];
434 vector normal = -Sfp[patchI][faceI] / magSfp[patchI][faceI];
438 vector tangent(normal.y(), -normal.x(), 0.0);
441 tensor fGradU = bGradU[patchI][faceI];
450 tensor fGradUT = fGradU.T();
460 scalar bSurfaceFriction =
scale_ * (tangent & (fGradUT & normal));
462 surfaceFriction.boundaryFieldRef()[patchI][faceI] = bSurfaceFriction;
466 scalar bSurfaceFrictionRef = surfaceFrictionRef.boundaryField()[patchI][faceI];
468 if (bSurfaceFrictionRef < 1e16)
471 objFuncValue += sqr(bSurfaceFriction - bSurfaceFrictionRef);
477 reduce(objFuncValue, sumOp<scalar>());
481 objFuncValue =
weight_ * objFuncValue;
486 FatalErrorIn(
"") <<
"dataType: " <<
data_
487 <<
" not supported for field inversion! "
488 <<
"Available options are: UData, pData, surfacePressureData, surfaceFrictionData, aeroCoeffData, and surfaceFrictionDataPeriodicHill."
489 << abort(FatalError);