Go to the documentation of this file.
46 namespace incompressible
72 createZeroBoundaryPointFieldPtr<vector>(
mesh_)
76 createZeroBoundaryPointFieldPtr<vector>(
mesh_)
80 for (
const label patchI : sensitivityPatchIDs_)
91 for (
auto& fun : functions)
93 dSdbMultiplierTot += fun.weight()*fun.dSdbMultiplier(patchI);
94 dndbMultiplierTot += fun.weight()*fun.dndbMultiplier(patchI);
105 const label patchStartIndex =
patch.start();
113 const labelList& pointFaces = patchPointFaces[ppI];
114 for (label localFaceIndex : pointFaces)
116 label globalFaceIndex = patchStartIndex + localFaceIndex;
117 const face& faceI = faces[globalFaceIndex];
123 if (faceI[facePointI] == meshPoints[ppI])
134 const tensor& deltaSf = deltaNormals[1];
136 dSdbMultiplierTot[localFaceIndex] & deltaSf;
139 const tensor& deltaNf = deltaNormals[2];
141 dndbMultiplierTot[localFaceIndex] & deltaNf;
149 for (
const label patchI : sensitivityPatchIDs_)
155 const label globaPointI = meshPoints[ppI];
156 dSdbGlobal[globaPointI] += pointSensdSdb()[patchI][ppI];
157 dndbGlobal[globaPointI] += pointSensdndb()[patchI][ppI];
170 for (
const label patchI : sensitivityPatchIDs_)
175 pointSensdSdb()[patchI].map(dSdbGlobal, meshPoints);
176 pointSensdndb()[patchI].map(dndbGlobal, meshPoints);
182 patchInter.pointToFaceInterpolate(pointSensdSdb()[patchI])
189 patchInter.pointToFaceInterpolate(pointSensdndb()[patchI]);
193 wallFaceSensVecPtr_()[patchI] += dSdbFace + dndbFace;
223 const label
iters(
dict().getOrDefault<label>(
"iters", 500));
224 const scalar tolerance(
dict().getOrDefault<scalar>(
"tolerance", 1.
e-06));
245 Info<<
"Reading the already constructed faMesh" <<
endl;
263 if (faMeshDefinitionDict.typeHeaderOk<
IOdictionary>(
false))
265 Info<<
"Reading faMeshDefinition from system " <<
endl;
272 Info<<
"Constructing faMeshDefinition from sensitivity patches"
274 wordList polyMeshPatches(sensitivityPatchIDs_.size());
276 for (
const label
patchID : sensitivityPatchIDs_)
280 faMeshDefinition.
add<
wordList>(
"polyMeshPatches", polyMeshPatches);
291 const scalar Rphysical
294 <<
"Physical radius of the sensitivity smoothing "
295 << Rphysical <<
nl <<
endl;
327 vsm.mapToSurface<scalar>(wallFaceSensNormalPtr_());
332 for (label iter = 0; iter <
iters; ++iter)
334 Info<<
"Sensitivity smoothing iteration " << iter <<
endl;
346 const scalar residual(
mag(smoothEqn.
solve().initialResidual()));
349 <<
"Max smoothSens " <<
gMax(
mag(smoothedSens)()) <<
endl;
355 if (residual < tolerance)
357 Info<<
"\n***Reached smoothing equation convergence limit, "
358 "iteration " << iter <<
"***\n\n";
368 "smoothedSurfaceSens" + surfaceFieldSuffix_,
379 vsm.mapToVolume(smoothedSens, volSmoothedSens.boundaryFieldRef());
380 volSmoothedSens.write();
391 if (geometricD[iDir] == -1)
393 averageArea /= bounds.
span()[iDir];
404 sensitivitySurface::sensitivitySurface
422 includeSurfaceArea_(
false),
423 includePressureTerm_(
false),
424 includeGradStressTerm_(
false),
425 includeTransposeStresses_(
false),
426 useSnGradInTranposeStresses_(
false),
427 includeDivTerm_(
false),
428 includeDistance_(
false),
429 includeMeshMovement_(
false),
430 includeObjective_(
false),
431 writeGeometricInfo_(
false),
432 smoothSensitivities_(
false),
433 eikonalSolver_(
nullptr),
434 meshMovementSolver_(
nullptr),
436 nfOnPatchPtr_(
nullptr),
437 SfOnPatchPtr_(
nullptr),
438 CfOnPatchPtr_(
nullptr)
444 wallFaceSensVecPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
445 wallFaceSensNormalPtr_.reset(createZeroBoundaryPtr<scalar>(mesh_));
446 wallFaceSensNormalVecPtr_.reset(createZeroBoundaryPtr<vector>(mesh_));
449 if (writeGeometricInfo_)
458 mesh.time().timeName(),
475 mesh.time().timeName(),
492 mesh.time().timeName(),
504 computeDerivativesSize();
562 sensitivityPatchIDs_,
594 for (
const label patchI : sensitivityPatchIDs_)
613 Info<<
" Calculating auxiliary quantities " <<
endl;
627 if (isA<wallFvPatch>(
patch))
632 nf*
U.boundaryField()[patchI].snGrad();
641 createZeroFieldPtr<vector>(
mesh_,
"stressX", stress.dimensions())
645 createZeroFieldPtr<vector>(
mesh_,
"stressY", stress.dimensions())
649 createZeroFieldPtr<vector>(
mesh_,
"stressZ", stress.dimensions())
652 stressXPtr().replace(0, stress.
component(0));
653 stressXPtr().replace(1, stress.
component(1));
654 stressXPtr().replace(2, stress.
component(2));
656 stressYPtr().replace(0, stress.
component(3));
657 stressYPtr().replace(1, stress.
component(4));
658 stressYPtr().replace(2, stress.
component(5));
660 stressZPtr().replace(0, stress.
component(6));
661 stressZPtr().replace(1, stress.
component(7));
662 stressZPtr().replace(2, stress.
component(8));
681 adjointTurbulence->wallShapeSensitivities();
684 <<
" Calculating adjoint sensitivity. " <<
endl;
688 for (
const label patchI : sensitivityPatchIDs_)
711 &
U.boundaryField()[patchI].snGrad()
713 * nuEff.boundaryField()[patchI]
724 (gradUa.boundaryField()[patchI] & nf)
728 nuEff.boundaryField()[patchI]
729 *(gradUaNf &
U.boundaryField()[patchI].snGrad())
736 scalar(1./3.)*nuEff.boundaryField()[patchI]
739 &
U.boundaryField()[patchI].snGrad()
753 gradStressTerm = - ((Uab & nf)*gradp.
boundaryField()[patchI]);
769 &
U.boundaryField()[patchI].snGrad()
783 functions[funcI].weight()
785 functions[funcI].dxdbDirectMultiplier(patchI)
791 wallFaceSensVecPtr_()[patchI] +=
796 + adjointTMsensitivities[patchI]
812 for (
const label patchI : sensitivityPatchIDs_)
832 distanceSensPtr.
reset(createZeroBoundaryPtr<vector>(
mesh_));
835 for (
const label patchI : sensitivityPatchIDs_)
837 distanceSensPtr()[patchI] = sens[patchI];
845 meshMovementSensPtr.
reset(createZeroBoundaryPtr<vector>(
mesh_));
848 for (
const label patchI : sensitivityPatchIDs_)
850 meshMovementSensPtr()[patchI] = sens[patchI];
856 label nPassedFaces(0);
857 for (
const label patchI : sensitivityPatchIDs_)
866 wallFaceSensVecPtr_()[patchI] += distanceSensPtr()[patchI];
872 wallFaceSensVecPtr_()[patchI] += meshMovementSensPtr()[patchI];
877 wallFaceSensVecPtr_()[patchI] *=
patch.magSf();
880 wallFaceSensNormalPtr_()[patchI] = wallFaceSensVecPtr_()[patchI] & nf;
881 wallFaceSensNormalVecPtr_()[patchI] =
882 wallFaceSensNormalPtr_()[patchI] * nf;
887 = wallFaceSensNormalPtr_()[patchI][fI];
889 nPassedFaces +=
patch.size();
const dictionary & dict() const
Return the construction dictionary.
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
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.
A special matrix type and solver, designed for finite area solutions of scalar equations....
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)
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
tmp< faMatrix< Type > > laplacian(const GeometricField< Type, faPatchField, areaMesh > &vf)
Type gAverage(const FieldField< Field, Type > &f)
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
virtual const fileName & dbDir() const
Override the objectRegistry dbDir for a single-region case.
bool read(const char *buf, int32_t &val)
Same as readInt32.
static word timeName(const scalar t, const int precision=precision_)
autoPtr< adjointEikonalSolver > eikonalSolver_
fileName caseSystem() const
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
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.
void smoothSensitivities()
const volScalarField & p() const
Return const reference to pressure.
Calculate the matrix for implicit and explicit sources.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
Class including all adjoint fields for incompressible flows.
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
label nPoints() const noexcept
Number of mesh points.
#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_
volSurfaceMapping vsm(aMesh)
Solver of the adjoint to the eikonal PDE.
vector span() const
The bounding box span (from minimum to maximum)
bool includeGradStressTerm_
Include the term containing the grad of the stress at the boundary.
Ostream & printExecutionTime(OSstream &os) const
Print the elapsed ExecutionTime (cpu-time), ClockTime.
tmp< faMatrix< Type > > Sp(const areaScalarField &sp, const GeometricField< Type, faPatchField, areaMesh > &vf)
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.
const dimensionSet dimArea(sqr(dimLength))
void computeDerivativesSize()
Compute the number of faces on sensitivityPatchIDs_.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
messageStream Info
Information stream (stdout output on master, null elsewhere)
scalar computeRadius(const faMesh &aMesh)
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.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
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_
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
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_
loopControl iters(runTime, aMesh.solutionDict(), "solution")
Mesh data needed to do the Finite Volume discretisation.
bool includeDistance_
Include distance variation in sens computation.
incompressibleVars & primalVars_
word findInstance(const fileName &dir, const word &name=word::null, const IOobject::readOption rOpt=IOobject::MUST_READ, const word &stopInstance=word::null) const
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field.
bool includeTransposeStresses_
Include the transpose part of the adjoint stresses.
const boundBox & bounds() const
Return mesh bounding box.
void reset(autoPtr< T > &&other) noexcept
Delete managed object and set to new given pointer.
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.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
#define DebugInfo
Report an information message using Foam::Info.
Interpolation class within a primitive patch. Allows interpolation from points to faces and vice vers...
T & ref()
Return reference to the managed object without nullptr checking.
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.
Volume to surface and surface to volume mapping.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Solver of the adjoint to the Laplace grid displacement equation.
static word meshSubDir
The mesh sub-directory name (usually "faMesh")
void clearSensitivities()
Zero sensitivity fields and their constituents.
pointField points(const UList< point > &pts) const
Return the points corresponding to this face.
const dimensionedScalar e
Elementary charge.
autoPtr< volVectorField > CfOnPatchPtr_
static const word null
An empty word.
Calculate the matrix for the laplacian of the field.
A bounding box defined in terms of min/max extrema points.
Finite area mesh. Used for 2-D non-Euclidian finite area method.
const Time & time() const
Return the top-level database.
static const Vector< scalar > zero
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
A face is a list of labels corresponding to mesh vertices.
bool smoothSensitivities_
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.
Type gMax(const FieldField< Field, Type > &f)
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
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.
const dimensionSet dimless
Dimensionless.
autoPtr< volVectorField > SfOnPatchPtr_
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
objectiveManager & objectiveManager_