Go to the documentation of this file.
39 namespace incompressible
48 sensitivitySurfacePoints,
102 sensitivityPatchIDs_,
118 distanceSensPtr.
reset(createZeroBoundaryPtr<vector>(
mesh_));
121 for (
const label patchI : sensitivityPatchIDs_)
123 distanceSensPtr()[patchI] = sens[patchI];
131 meshMovementSensPtr.
reset(createZeroBoundaryPtr<vector>(
mesh_));
134 for (
const label patchI : sensitivityPatchIDs_)
136 meshMovementSensPtr()[patchI] = sens[patchI];
142 for (
const label patchI : sensitivityPatchIDs_)
175 for (
const label patchI : sensitivityPatchIDs_)
181 vectorField& pointPatchSens = wallPointSensVecPtr_()[patchI];
201 const label patchStartIndex =
patch.start();
210 const labelList& pointFaces = patchPointFaces[ppI];
213 label localFaceIndex = pointFaces[pfI];
214 label globalFaceIndex = patchStartIndex + localFaceIndex;
215 const face& faceI = faces[globalFaceIndex];
222 if (faceI[facePointI] == meshPoints[ppI])
232 const tensor& deltaCf = deltaNormals[0];
233 pointPatchSens[ppI] += facePatchSens[localFaceIndex] & deltaCf;
241 const tensor& deltaSf = deltaNormals[1];
242 pointPatchSens[ppI] +=
243 dSfdbMultPatch[localFaceIndex] & deltaSf;
246 const tensor& deltaNf = deltaNormals[2];
247 pointPatchSens[ppI] +=
248 dnfdbMultPatch[localFaceIndex] & deltaNf;
262 for (
const label patchI : sensitivityPatchIDs_)
278 const labelList& pointFaces = patchPointFaces[ppI];
281 const label localFaceIndex = pointFaces[pfI];
284 pointNormals[meshPoints[ppI]] += nf[localFaceIndex];
285 pointMagSf[meshPoints[ppI]] += magSf[localFaceIndex];
330 sensitivitySurfacePoints::sensitivitySurfacePoints
350 includeSurfaceArea_(
false),
351 includePressureTerm_(
false),
352 includeGradStressTerm_(
false),
353 includeTransposeStresses_(
false),
354 includeDivTerm_(
false),
355 includeDistance_(
false),
356 includeMeshMovement_(
false),
357 includeObjective_(
false),
358 eikonalSolver_(
nullptr),
359 meshMovementSolver_(
nullptr),
360 wallFaceSens_(createZeroBoundaryPtr<vector>(mesh_)),
361 dSfdbMult_(createZeroBoundaryPtr<vector>(mesh_)),
362 dnfdbMult_(createZeroBoundaryPtr<vector>(mesh_))
368 wallPointSensVecPtr_.reset(createZeroBoundaryPointFieldPtr<vector>(mesh_));
369 wallPointSensNormalPtr_.reset
371 createZeroBoundaryPointFieldPtr<scalar>(mesh_)
373 wallPointSensNormalVecPtr_.reset
375 createZeroBoundaryPointFieldPtr<vector>(mesh_)
379 label nTotalPoints(0);
380 for (
const label patchI : sensitivityPatchIDs_)
382 label
nPoints = mesh_.boundaryMesh()[patchI].nPoints();
426 <<
" Calculating auxilary quantities " <<
endl;
438 if (isA<wallFvPatch>(
patch))
443 nf*
U.boundaryField()[patchI].snGrad();
452 createZeroFieldPtr<vector>(
mesh_,
"stressX", stress.dimensions())
456 createZeroFieldPtr<vector>(
mesh_,
"stressY", stress.dimensions())
460 createZeroFieldPtr<vector>(
mesh_,
"stressZ", stress.dimensions())
463 stressXPtr().replace(0, stress.
component(0));
464 stressXPtr().replace(1, stress.
component(1));
465 stressXPtr().replace(2, stress.
component(2));
467 stressYPtr().replace(0, stress.
component(3));
468 stressYPtr().replace(1, stress.
component(4));
469 stressYPtr().replace(2, stress.
component(5));
471 stressZPtr().replace(0, stress.
component(6));
472 stressZPtr().replace(1, stress.
component(7));
473 stressZPtr().replace(2, stress.
component(8));
493 adjointTurbulence->wallShapeSensitivities();
499 <<
" Calculating adjoint sensitivity. " <<
endl;
503 for (
const label patchI : sensitivityPatchIDs_)
521 &
U.boundaryField()[patchI].snGrad()
523 * nuEff.boundaryField()[patchI]
536 gradStressTerm = (-((Uab & nf)*gradp.
boundaryField()[patchI]));
548 nuEff.boundaryField()[patchI]
554 &
U.boundaryField()[patchI].snGrad()
562 scalar(1./3.)*nuEff.boundaryField()[patchI]
565 &
U.boundaryField()[patchI].snGrad()
577 &
U.boundaryField()[patchI].snGrad()
588 const scalar wei = functions[funcI].weight();
591 wei*functions[funcI].dxdbDirectMultiplier(patchI);
595 wei*dt*functions[funcI].dSdbMultiplier(patchI);
597 wei*dt*functions[funcI].dndbMultiplier(patchI);
609 + adjointTMsensitivities[patchI]
637 for (
const label patchI : sensitivityPatchIDs_)
642 const label globaPointI = meshPoints[ppI];
643 pointSensGlobal[globaPointI] +=
644 wallPointSensVecPtr_()[patchI][ppI];
658 for (
const label patchI : sensitivityPatchIDs_)
662 wallPointSensVecPtr_()[patchI].map(pointSensGlobal, meshPoints);
667 for (
const label patchI : sensitivityPatchIDs_)
678 vectorField patchPointNormals(pointNormals, meshPoints);
679 patchPointNormals /=
mag(patchPointNormals) + VSMALL;
682 wallPointSensVecPtr_()[patchI] /=
685 wallPointSensNormalPtr_()[patchI] =
686 wallPointSensVecPtr_()[patchI]
688 wallPointSensNormalVecPtr_()[patchI] =
689 wallPointSensNormalPtr_()[patchI]
705 3*wallPointSensNormalVecPtr_()[patchI].size()
708 forAll(wallPointSensNormalVecPtr_()[patchI], ptI)
710 patchScalarSens[3*ptI] =
711 wallPointSensNormalVecPtr_()[patchI][ptI].x();
712 patchScalarSens[3*ptI + 1] =
713 wallPointSensNormalVecPtr_()[patchI][ptI].y();
714 patchScalarSens[3*ptI + 2] =
715 wallPointSensNormalVecPtr_()[patchI][ptI].z();
720 forAll(procPatchSens, procI)
722 const scalarField& procSens = procPatchSens[procI];
727 nPassedDVs += procSens.size();
autoPtr< boundaryVectorField > wallFaceSens_
The face-based part of the sensitivities.
const dictionary & dict() const
Return the construction dictionary.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
virtual const pointField & points() const
Return raw points.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
class for managing incompressible objective functions.
bool includeTransposeStresses_
Include the transpose part of the adjoint stresses.
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
const word & solverName() const
Return solver name.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Differentiation of the mesh data structure.
pointField points(const UList< point > &points) const
Return the points corresponding to this face.
A class for handling words, derived from Foam::string.
autoPtr< boundaryVectorField > dnfdbMult_
defineTypeNameAndDebug(adjointEikonalSolver, 0)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
A class for managing temporary objects.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
static constexpr const zero Zero
Global zero (0)
void constructGlobalPointNormalsAndAreas(vectorField &pointNormals, scalarField &pointMagSf)
Construct globally correct point normals and point areas.
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
bool read(const char *buf, int32_t &val)
Same as readInt32.
bool includePressureTerm_
Include the adjoint pressure term in sens computation.
autoPtr< adjointMeshMovementSolver > meshMovementSolver_
autoPtr< boundaryVectorField > dSfdbMult_
Multipliers of d(Sf)/db and d(nf)/db.
void read()
Read controls and update solver pointers if necessary.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const volScalarField & p() const
Return const reference to pressure.
Class including all adjoint fields for incompressible flows.
#define forAll(list, i)
Loop across all elements in list.
const autoPtr< incompressible::RASModelVariables > & RASModelVariables() const
Return const reference to the turbulence model variables.
bool includeDivTerm_
Include the term from the deviatoric part of the stresses.
Solver of the adjoint to the eikonal PDE.
addToRunTimeSelectionTable(adjointSensitivity, sensitivityBezier, dictionary)
void write()
Write sensitivity fields.
Abstract base class for adjoint-based sensitivities in incompressible flows.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
autoPtr< adjointEikonalSolver > eikonalSolver_
A patch is a list of labels that address the faces in the global face list.
virtual bool readDict(const dictionary &dict)
Read dict if changed.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const volScalarField & pa() const
Return const reference to pressure.
const volVectorField & U() const
Return const reference to velocity.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
bool includeMeshMovement_
Include mesh movement variation in sens computation.
const volVectorField & Ua() const
Return const reference to velocity.
bool includeSurfaceArea_
Include surface area in sens computation.
bool includeObjective_
Include terms directly emerging from the objective function.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Macros for easy insertion into run-time selection tables.
vectorField makeFaceCentresAndAreas_d(const pointField &p, const pointField &p_d)
incompressibleAdjointVars & adjointVars_
Mesh data needed to do the Finite Volume discretisation.
incompressibleVars & primalVars_
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
bool includeDistance_
Include distance variation in sens computation.
virtual const faceList & faces() const
Return raw faces.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
bool includeGradStressTerm_
Include the term containing the grad of the stress at the boundary.
#define DebugInfo
Report an information message using Foam::Info.
const std::string patch
OpenFOAM patch number as a std::string.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Return const reference to the adjointRASModel.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Solver of the adjoint to the Laplace grid displacement equation.
void clearSensitivities()
Zero sensitivity fields and their constituents.
label nPoints() const
Number of mesh points.
static const word null
An empty word.
void setSuffixName()
Set suffix name for sensitivity fields.
static const Vector< scalar > zero
A face is a list of labels corresponding to mesh vertices.
void setSize(const label newSize)
Alias for resize(const label)
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
void setSuffix(const word &suffix)
Set suffix.
fv::IOoptionListAdjoint fvOptionsAdjoint(mesh)
void finaliseFaceMultiplier()
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
void finalisePointSensitivities()
virtual void assembleSensitivities()
Assemble sensitivities.
Base class for solution control classes.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
objectiveManager & objectiveManager_