40 namespace incompressible
105 sensitivityPatchIDs_,
121 distanceSensPtr.
reset(createZeroBoundaryPtr<vector>(
mesh_));
124 for (
const label patchI : sensitivityPatchIDs_)
126 distanceSensPtr()[patchI] = sens[patchI];
130 autoPtr<boundaryVectorField> meshMovementSensPtr(
nullptr);
134 meshMovementSensPtr.reset(createZeroBoundaryPtr<vector>(
mesh_));
137 for (
const label patchI : sensitivityPatchIDs_)
139 meshMovementSensPtr()[patchI] = sens[patchI];
145 for (
const label patchI : sensitivityPatchIDs_)
148 tmp<vectorField> tnf =
patch.nf();
178 for (
const label patchI : sensitivityPatchIDs_)
184 vectorField& pointPatchSens = wallPointSensVecPtr_()[patchI];
204 const label patchStartIndex =
patch.start();
213 const labelList& pointFaces = patchPointFaces[ppI];
216 label localFaceIndex = pointFaces[pfI];
217 label globalFaceIndex = patchStartIndex + localFaceIndex;
218 const face& faceI = faces[globalFaceIndex];
225 if (faceI[facePointI] == meshPoints[ppI])
235 const tensor& deltaCf = deltaNormals[0];
236 pointPatchSens[ppI] += facePatchSens[localFaceIndex] & deltaCf;
244 const tensor& deltaSf = deltaNormals[1];
245 pointPatchSens[ppI] +=
246 dSfdbMultPatch[localFaceIndex] & deltaSf;
249 const tensor& deltaNf = deltaNormals[2];
250 pointPatchSens[ppI] +=
251 dnfdbMultPatch[localFaceIndex] & deltaNf;
265 for (
const label patchI : sensitivityPatchIDs_)
281 const labelList& pointFaces = patchPointFaces[ppI];
284 const label localFaceIndex = pointFaces[pfI];
287 pointNormals[meshPoints[ppI]] += nf[localFaceIndex];
288 pointMagSf[meshPoints[ppI]] += magSf[localFaceIndex];
333 sensitivitySurfacePoints::sensitivitySurfacePoints
342 includeSurfaceArea_(false),
343 includePressureTerm_(false),
344 includeGradStressTerm_(false),
345 includeTransposeStresses_(false),
346 useSnGradInTranposeStresses_(false),
347 includeDivTerm_(false),
348 includeDistance_(false),
349 includeMeshMovement_(false),
350 includeObjective_(false),
351 eikonalSolver_(nullptr),
352 meshMovementSolver_(nullptr),
361 wallPointSensVecPtr_.reset(createZeroBoundaryPointFieldPtr<vector>(
mesh_));
362 wallPointSensNormalPtr_.reset
364 createZeroBoundaryPointFieldPtr<scalar>(
mesh_)
366 wallPointSensNormalVecPtr_.reset
368 createZeroBoundaryPointFieldPtr<vector>(
mesh_)
372 label nTotalPoints(0);
373 for (
const label patchI : sensitivityPatchIDs_)
377 reduce(nTotalPoints, sumOp<label>());
431 adjointTurbulence->wallShapeSensitivities();
437 <<
" Calculating adjoint sensitivity. " <<
endl;
439 tmp<volScalarField> tnuEff = adjointTurbulence->nuEff();
454 for (
const label patchI : sensitivityPatchIDs_)
457 tmp<vectorField> tnf =
patch.nf();
460 (Uab & tnf)*gradp.boundaryField()[patchI]*dt;
471 tmp<volTensorField> tgradU =
480 if (isA<wallFvPatch>(
patch))
483 gradUbf[patchI] = tnf*
U.boundaryField()[patchI].snGrad();
487 tmp<volSymmTensorField> tstress = nuEff*
twoSymm(tgradU);
489 autoPtr<volVectorField> ptemp
492 for (label idir = 0; idir < pTraits<vector>::nComponents; ++idir)
496 for (
const label patchI : sensitivityPatchIDs_)
499 tmp<vectorField> tnf =
patch.nf();
504 *(gradStressDir.boundaryField()[patchI] & tnf)
514 tmp<volTensorField> tgradUa =
fvc::grad(Ua);
516 tgradUa.cref().boundaryField();
517 for (
const label patchI : sensitivityPatchIDs_)
520 tmp<vectorField> tnf =
patch.nf();
526 : (gradUabf[patchI] & nf)
529 nuEff.boundaryField()[patchI]
530 *(gradUaNf &
U.boundaryField()[patchI].snGrad())*tnf;
536 for (
const label patchI : sensitivityPatchIDs_)
539 tmp<vectorField> tnf =
patch.nf();
554 &
U.boundaryField()[patchI].snGrad()
556 * nuEff.boundaryField()[patchI]
563 scalar(1./3.)*nuEff.boundaryField()[patchI]
566 &
U.boundaryField()[patchI].snGrad()
578 &
U.boundaryField()[patchI].snGrad()
589 const scalar wei = functions[funcI].weight();
592 wei*functions[funcI].dxdbDirectMultiplier(patchI);
596 wei*dt*functions[funcI].dSdbMultiplier(patchI);
598 wei*dt*functions[funcI].dndbMultiplier(patchI);
609 + adjointTMsensitivities[patchI]
641 for (
const label patchI : sensitivityPatchIDs_)
646 const label globaPointI = meshPoints[ppI];
647 pointSensGlobal[globaPointI] +=
648 wallPointSensVecPtr_()[patchI][ppI];
662 for (
const label patchI : sensitivityPatchIDs_)
666 wallPointSensVecPtr_()[patchI].map(pointSensGlobal, meshPoints);
671 for (
const label patchI : sensitivityPatchIDs_)
682 vectorField patchPointNormals(pointNormals, meshPoints);
683 patchPointNormals /=
mag(patchPointNormals) + VSMALL;
686 wallPointSensVecPtr_()[patchI] /=
689 wallPointSensNormalPtr_()[patchI] =
690 wallPointSensVecPtr_()[patchI]
692 wallPointSensNormalVecPtr_()[patchI] =
693 wallPointSensNormalPtr_()[patchI]
709 3*wallPointSensNormalVecPtr_()[patchI].size()
712 forAll(wallPointSensNormalVecPtr_()[patchI], ptI)
714 patchScalarSens[3*ptI] =
715 wallPointSensNormalVecPtr_()[patchI][ptI].x();
716 patchScalarSens[3*ptI + 1] =
717 wallPointSensNormalVecPtr_()[patchI][ptI].y();
718 patchScalarSens[3*ptI + 2] =
719 wallPointSensNormalVecPtr_()[patchI][ptI].z();
723 forAll(procPatchSens, procI)
725 const scalarField& procSens = procPatchSens[procI];
Solver of the adjoint to the Laplace grid displacement equation.
GeometricField< symmTensor, fvPatchField, volMesh > volSymmTensorField
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
void size(const label n)
Older name for setAddressableSize.
bool includeGradStressTerm_
Include the term containing the grad of the stress at the boundary.
const incompressibleVars & primalVars_
void setSuffix(const word &suffix)
Set suffix.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
defineTypeNameAndDebug(adjointEikonalSolver, 0)
fvPatchField< vector > fvPatchVectorField
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
virtual void additionalSensitivityMapTerms(boundaryVectorField &sensitivityMap, const labelHashSet &patchIDs, const scalar dt)
Terms to be added to the sensitivity map, depending on the adjoint solver.
A face is a list of labels corresponding to mesh vertices.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label nPoints() const noexcept
Number of mesh points.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
autoPtr< boundaryVectorField > dSfdbMult_
Multipliers of d(Sf)/db and d(nf)/db.
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
GeometricField< tensor, fvPatchField, volMesh > volTensorField
dimensionedSymmTensor sqr(const dimensionedVector &dv)
volVectorField::Boundary boundaryVectorField
Ostream & endl(Ostream &os)
Add newline and flush stream.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
Differentiation of the mesh data structure.
void unzipRow(const FieldField< Field, SymmTensor< Cmpt >> &input, const direction idx, FieldField< Field, Vector< Cmpt >> &result)
Extract a symmTensor field field row (x,y,z) == (0,1,2)
vectorField makeFaceCentresAndAreas_d(const pointField &p, const pointField &p_d)
Given a face and the points to be moved in the normal direction, find faceArea, faceCentre and unitVe...
bool includeTransposeStresses_
Include the transpose part of the adjoint stresses.
Base class for adjoint solvers.
incompressibleAdjointSolver & adjointSolver_
GeometricBoundaryField< tensor, fvPatchField, volMesh > Boundary
Type of boundary fields.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
GeometricField< vector, fvPatchField, volMesh > volVectorField
List< labelList > labelListList
List of labelList.
addToRunTimeSelectionTable(adjointSensitivity, sensitivityBezier, dictionary)
Macros for easy insertion into run-time selection tables.
dimensionedSymmTensor twoSymm(const dimensionedSymmTensor &dt)
objectiveManager & objectiveManager_
Base class for incompressibleAdjoint solvers.
virtual const pointField & points() const
Return raw points.
#define forAll(list, i)
Loop across all elements in list.
void finalisePointSensitivities()
Converts face sensitivities to point sensitivities and adds the ones directly computed in points (i...
virtual void assembleSensitivities()
Assemble sensitivities.
autoPtr< adjointMeshMovementSolver > meshMovementSolver_
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
static void allGatherList(List< T > &values, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Gather data, but keep individual values separate. Uses linear/tree communication. ...
const dictionary & dict() const
Return the construction dictionary.
pointField points(const UList< point > &pts) const
Return the points corresponding to this face.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
bool includeDivTerm_
Include the term from the deviatoric part of the stresses.
const volScalarField & pa() const
Return const reference to pressure.
autoPtr< typename GeometricField< Type, fvPatchField, volMesh >::Boundary > createZeroBoundaryPtr(const fvMesh &mesh, bool printAllocation=false)
bool useSnGradInTranposeStresses_
Use snGrad in the transpose part of the adjoint stresses.
static const Identity< scalar > I
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
A class for handling words, derived from Foam::string.
Abstract base class for adjoint-based sensitivities in incompressible flows.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
const volVectorField & Ua() const
Return const reference to velocity.
const volScalarField & p() const
Return const reference to pressure.
static const word null
An empty word.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
const autoPtr< incompressibleAdjoint::adjointRASModel > & adjointTurbulence() const
Return const reference to the adjointRASModel.
virtual const faceList & faces() const
Return raw faces.
const word & solverName() const
Return solver name.
#define DebugInfo
Report an information message using Foam::Info.
const volVectorField & U() const
Return const reference to velocity.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
autoPtr< boundaryVectorField > wallFaceSens_
The face-based part of the sensitivities.
bool includeSurfaceArea_
Include surface area in sens computation.
autoPtr< adjointEikonalSolver > eikonalSolver_
void write()
Write sensitivity fields.
void finaliseFaceMultiplier()
Add terms related to post-processing PDEs (i.e. adjoint Eikonal, adjoint mesh movement) and add local...
const autoPtr< incompressible::RASModelVariables > & RASModelVariables() const
Return const reference to the turbulence model variables.
void read()
Read controls and update solver pointers if necessary.
bool includeDistance_
Include distance variation in sens computation.
bool includePressureTerm_
Include the adjoint pressure term in sens computation.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
void clearSensitivities()
Zero sensitivity fields and their constituents.
Mesh data needed to do the Finite Volume discretisation.
Calculation of adjoint based sensitivities at wall points.
bool includeObjective_
Include terms directly emerging from the objective function.
const std::string patch
OpenFOAM patch number as a std::string.
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
bool includeMeshMovement_
Include mesh movement variation in sens computation.
Internal & ref(const bool updateAccessTime=true)
Same as internalFieldRef()
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
virtual bool readDict(const dictionary &dict)
Read dict if changed.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
List< label > labelList
A List of labels.
void setSuffixName()
Set suffix name for sensitivity fields.
incompressibleAdjointVars & adjointVars_
static tmp< GeometricField< tensor, fvPatchField, volMesh > > New(const word &name, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=fvPatchField< tensor >::calculatedType())
Return tmp field from name, mesh, dimensions and patch type.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
autoPtr< boundaryVectorField > dnfdbMult_
Tensor of scalars, i.e. Tensor<scalar>.
const Boundary & boundaryField() const noexcept
Return const-reference to the boundary field.
void constructGlobalPointNormalsAndAreas(vectorField &pointNormals, scalarField &pointMagSf)
Construct globally correct point normals and point areas.
Solver of the adjoint to the eikonal PDE.
static constexpr const zero Zero
Global zero (0)
const dimensionSet dimVelocity