Go to the documentation of this file.
40 namespace incompressible
66 createZeroBoundaryPointFieldPtr<vector>(
mesh_)
70 createZeroBoundaryPointFieldPtr<vector>(
mesh_)
74 for (
const label patchI : sensitivityPatchIDs_)
88 functions[funcI].weight()
89 *functions[funcI].dSdbMultiplier(patchI);
91 functions[funcI].weight()
92 *functions[funcI].dndbMultiplier(patchI);
103 const label patchStartIndex =
patch.start();
111 const labelList& pointFaces = patchPointFaces[ppI];
114 label localFaceIndex = pointFaces[pfI];
115 label globalFaceIndex = patchStartIndex + localFaceIndex;
116 const face& faceI = faces[globalFaceIndex];
122 if (faceI[facePointI] == meshPoints[ppI])
131 const tensor& deltaSf = deltaNormals[1];
133 dSdbMultiplierTot[localFaceIndex] & deltaSf;
136 const tensor& deltaNf = deltaNormals[2];
138 dndbMultiplierTot[localFaceIndex] & deltaNf;
146 for (
const label patchI : sensitivityPatchIDs_)
152 const label globaPointI = meshPoints[ppI];
153 dSdbGlobal[globaPointI] += pointSensdSdb()[patchI][ppI];
154 dndbGlobal[globaPointI] += pointSensdndb()[patchI][ppI];
167 for (
const label patchI : sensitivityPatchIDs_)
172 pointSensdSdb()[patchI].map(dSdbGlobal, meshPoints);
173 pointSensdndb()[patchI].map(dndbGlobal, meshPoints);
179 patchInter.pointToFaceInterpolate(pointSensdSdb()[patchI])
186 patchInter.pointToFaceInterpolate(pointSensdndb()[patchI]);
190 wallFaceSensVecPtr_()[patchI] += dSdbFace + dndbFace;
219 sensitivitySurface::sensitivitySurface
237 includeSurfaceArea_(
false),
238 includePressureTerm_(
false),
239 includeGradStressTerm_(
false),
240 includeTransposeStresses_(
false),
241 useSnGradInTranposeStresses_(
false),
242 includeDivTerm_(
false),
243 includeDistance_(
false),
244 includeMeshMovement_(
false),
245 includeObjective_(
false),
246 writeGeometricInfo_(
false),
247 eikonalSolver_(
nullptr),
248 meshMovementSolver_(
nullptr),
250 nfOnPatchPtr_(
nullptr),
251 SfOnPatchPtr_(
nullptr),
252 CfOnPatchPtr_(
nullptr)
258 wallFaceSensVecPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
259 wallFaceSensNormalPtr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
260 wallFaceSensNormalVecPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
263 if (writeGeometricInfo_)
272 mesh.time().timeName(),
289 mesh.time().timeName(),
306 mesh.time().timeName(),
318 computeDerivativesSize();
374 sensitivityPatchIDs_,
406 for (
const label patchI : sensitivityPatchIDs_)
425 Info<<
" Calculating auxiliary quantities " <<
endl;
439 if (isA<wallFvPatch>(
patch))
444 nf*
U.boundaryField()[patchI].snGrad();
453 createZeroFieldPtr<vector>(
mesh_,
"stressX", stress.dimensions())
457 createZeroFieldPtr<vector>(
mesh_,
"stressY", stress.dimensions())
461 createZeroFieldPtr<vector>(
mesh_,
"stressZ", stress.dimensions())
464 stressXPtr().replace(0, stress.
component(0));
465 stressXPtr().replace(1, stress.
component(1));
466 stressXPtr().replace(2, stress.
component(2));
468 stressYPtr().replace(0, stress.
component(3));
469 stressYPtr().replace(1, stress.
component(4));
470 stressYPtr().replace(2, stress.
component(5));
472 stressZPtr().replace(0, stress.
component(6));
473 stressZPtr().replace(1, stress.
component(7));
474 stressZPtr().replace(2, stress.
component(8));
493 adjointTurbulence->wallShapeSensitivities();
496 <<
" Calculating adjoint sensitivity. " <<
endl;
500 for (
const label patchI : sensitivityPatchIDs_)
523 &
U.boundaryField()[patchI].snGrad()
525 * nuEff.boundaryField()[patchI]
536 (gradUa.boundaryField()[patchI] & nf)
540 nuEff.boundaryField()[patchI]
541 *(gradUaNf &
U.boundaryField()[patchI].snGrad())
548 scalar(1./3.)*nuEff.boundaryField()[patchI]
551 &
U.boundaryField()[patchI].snGrad()
565 gradStressTerm = - ((Uab & nf)*gradp.
boundaryField()[patchI]);
581 &
U.boundaryField()[patchI].snGrad()
595 functions[funcI].weight()
597 functions[funcI].dxdbDirectMultiplier(patchI)
603 wallFaceSensVecPtr_()[patchI] +=
608 + adjointTMsensitivities[patchI]
624 for (
const label patchI : sensitivityPatchIDs_)
644 distanceSensPtr.
reset(createZeroBoundaryPtr<vector>(
mesh_));
647 for (
const label patchI : sensitivityPatchIDs_)
649 distanceSensPtr()[patchI] = sens[patchI];
657 meshMovementSensPtr.
reset(createZeroBoundaryPtr<vector>(
mesh_));
660 for (
const label patchI : sensitivityPatchIDs_)
662 meshMovementSensPtr()[patchI] = sens[patchI];
668 label nPassedFaces(0);
669 for (
const label patchI : sensitivityPatchIDs_)
678 wallFaceSensVecPtr_()[patchI] += distanceSensPtr()[patchI];
684 wallFaceSensVecPtr_()[patchI] += meshMovementSensPtr()[patchI];
689 wallFaceSensVecPtr_()[patchI] *=
patch.magSf();
692 wallFaceSensNormalPtr_()[patchI] = wallFaceSensVecPtr_()[patchI] & nf;
693 wallFaceSensNormalVecPtr_()[patchI] =
694 wallFaceSensNormalPtr_()[patchI] * nf;
699 = wallFaceSensNormalPtr_()[patchI][fI];
701 nPassedFaces +=
patch.size();
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.
class for managing incompressible objective functions.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
virtual void assembleSensitivities()
Assemble sensitivities.
tmp< GeometricField< cmptType, PatchField, GeoMesh > > component(const direction) const
Return a component of the field.
const word & solverName() const
Return solver name.
bool includePressureTerm_
Include the adjoint pressure term in sens computation.
bool includeObjective_
Include terms directly emerging from the objective function.
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.
defineTypeNameAndDebug(adjointEikonalSolver, 0)
A class for managing temporary objects.
static constexpr const zero Zero
Global zero (0)
bool read(const char *buf, int32_t &val)
Same as readInt32.
autoPtr< adjointEikonalSolver > eikonalSolver_
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual void write(const word &baseName=word::null)
Write sensitivity maps.
A simple single-phase transport model based on viscosityModel.
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.
autoPtr< adjointMeshMovementSolver > meshMovementSolver_
Solver of the adjoint to the eikonal PDE.
bool includeGradStressTerm_
Include the term containing the grad of the stress at the boundary.
addToRunTimeSelectionTable(adjointSensitivity, sensitivityBezier, dictionary)
void write()
Write sensitivity fields.
Abstract base class for adjoint-based sensitivities in incompressible flows.
bool includeDivTerm_
Include the term from the deviatoric part of the stresses.
void computeDerivativesSize()
Compute the number of faces on sensitivityPatchIDs_.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
messageStream Info
Information stream (uses stdout - output is on the master only)
bool writeGeometricInfo_
Write geometric info for use by external programs.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
const singlePhaseTransportModel & laminarTransport() const
Return const reference to transport model.
bool useSnGradInTranposeStresses_
Use snGrad in the transpose part of the adjoint stresses.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const volScalarField & pa() const
Return const reference to pressure.
autoPtr< adjointEikonalSolver > & getAdjointEikonalSolver()
Get adjoint eikonal solver.
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.
autoPtr< volVectorField > nfOnPatchPtr_
const volVectorField & Ua() const
Return const reference to velocity.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
bool includeSurfaceArea_
Include surface area in sens computation.
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.
bool includeDistance_
Include distance variation in sens computation.
incompressibleVars & primalVars_
bool includeTransposeStresses_
Include the transpose part of the adjoint stresses.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void read()
Read controls and update solver pointers if necessary.
virtual const faceList & faces() const
Return raw faces.
#define DebugInfo
Report an information message using Foam::Info.
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
virtual tmp< volScalarField > nu() const
Return the laminar viscosity.
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.
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.
autoPtr< volVectorField > CfOnPatchPtr_
static const word null
An empty word.
static const Vector< Cmpt > zero
A face is a list of labels corresponding to mesh vertices.
bool includeMeshMovement_
Include mesh movement variation in sens computation.
void setSuffixName()
Set suffix name for sensitivity fields.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
void setSuffix(const word &suffix)
Set suffix.
virtual bool readDict(const dictionary &dict)
Read dict if changed.
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.
autoPtr< volVectorField > SfOnPatchPtr_
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
objectiveManager & objectiveManager_