58 const bool computeVectorFieldSize
65 const label patchSize = patch.size();
66 size += label(computeVectorFieldSize ? 3*patchSize : patchSize);
75 const label
iters(
dict().getOrDefault<label>(
"iters", 500));
76 const scalar tolerance(
dict().getOrDefault<scalar>(
"tolerance", 1.e-06));
82 Info<<
"Loaded the existing faMesh" <<
nl;
94 mesh_.time().caseSystem(),
101 if (
io.typeHeaderOk<IOdictionary>(
false))
103 Info<<
"Using system/faMeshDefinition" <<
nl;
104 faMeshDefinition = IOdictionary(
io);
108 Info<<
"No " <<
io.name() <<
" in " <<
io.path() <<
nl;
113 if (faMeshDefinition.empty())
125 if (
io.typeHeaderOk<IOdictionary>(
false))
127 Info<<
"Using system/finite-area/faMeshDefinition" <<
nl;
128 faMeshDefinition = IOdictionary(
io);
132 Info<<
"No " <<
io.name() <<
" in " <<
io.path() <<
nl;
139 if (faMeshDefinition.empty())
145 polyMeshPatches[i++] =
mesh_.boundary()[
patchID].name();
147 faMeshDefinition.add<
wordList>(
"polyMeshPatches", polyMeshPatches);
148 (void)faMeshDefinition.subDictOrAdd(
"boundary");
154 Info<<
"Create faMeshDefinition from sensitivity patches"
157 faMeshDefinition.writeEntry(
"faMeshDefinition",
Info);
161 aMeshPtr.reset(
new faMesh(
mesh_, faMeshDefinition));
163 faMesh& aMesh = *aMeshPtr;
168 const scalar Rphysical
171 <<
"Physical radius of the sensitivity smoothing "
172 << Rphysical <<
nl <<
endl;
184 volSurfaceMapping
vsm(aMesh);
189 aMesh.newIOobject(
"sens"),
202 for (label iter = 0; iter <
iters; ++iter)
204 Info<<
"Sensitivity smoothing iteration " << iter <<
endl;
216 const scalar residual(
mag(smoothEqn.solve().initialResidual()));
219 <<
"Max smoothSens " <<
gMax(
mag(smoothedSens)()) <<
endl;
225 if (residual < tolerance)
227 Info<<
"\n***Reached smoothing equation convergence limit, "
228 "iteration " << iter <<
"***\n\n";
247 vsm.mapToVolume(smoothedSensNormal, volSmoothedSens.boundaryFieldRef());
248 volSmoothedSens.write();
254 scalar averageArea(
gAverage(aMesh.
S().field()));
259 if (geometricD[iDir] == -1)
261 averageArea /=
bounds.span()[iDir];
264 scalar mult =
dict().getOrDefault<scalar>(
"meanRadiusMultiplier", 10);
266 return mult*
pow(averageArea, scalar(1)/scalar(
mesh_.nGeometricD() - 1));
272sensitivitySurface::sensitivitySurface
280 smoothSensitivities_(
dict.getOrDefault(
"smoothSensitivities", false)),
282 (
dict.getOrDefault<bool>(
"returnVectorField", true))
302 dict().getOrDefault<
bool>(
"returnVectorField",
true);
332 volPointInterpolationAdjoint interpolation(
mesh_);
333 interpolation.interpolateSensitivitiesField
337 label nPassedFaces(0);
341 tmp<vectorField> nf = patch.nf();
343 SubField<vector>(faceVecSens, patch.size(), nPassedFaces)
348 nPassedFaces += patch.size();
363 const fvPatch&
patch =
mesh_.boundary()[patchI];
367 const Vector<label>& sd =
mesh_.solutionD();
370 const label gfI = nPassedFaces + fI;
372 derivatives_[3*gfI ] = scalar(sd[0] == -1 ? 0 : fSens.x());
373 derivatives_[3*gfI + 1] = scalar(sd[1] == -1 ? 0 : fSens.y());
374 derivatives_[3*gfI + 2] = scalar(sd[2] == -1 ? 0 : fSens.z());
385 nPassedFaces +=
patch.size();
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
bool empty() const noexcept
True if the list is empty.
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
void normalise()
Normalise the field inplace. See notes in Field.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ NO_REGISTER
Do not request registration (bool: false).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
autoPtr< boundaryVectorField > wallFaceSensVecPtr_
Wall face sens w.r.t. (x,y.z).
labelHashSet sensitivityPatchIDs_
Patches on which to compute shape sensitivities.
autoPtr< pointBoundaryVectorField > wallPointSensVecPtr_
Wall point sens w.r.t. (x,y.z).
autoPtr< boundaryScalarField > wallFaceSensNormalPtr_
Wall face sens projected to normal.
autoPtr< boundaryVectorField > wallFaceSensNormalVecPtr_
Normal sens as vectors.
SubField is a Field obtained as a section of another Field, without its own allocation....
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
const Cmpt & x() const noexcept
Access to the vector x component.
const Cmpt & z() const noexcept
Access to the vector z component.
const Cmpt & y() const noexcept
Access to the vector y component.
Abstract base class for adjoint-based sensitivities.
scalarField derivatives_
The sensitivity derivative values.
word suffix_
Append this word to files related to the sensitivities.
Base class for adjoint solvers.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
void reset(T *p=nullptr) noexcept
Delete managed object and set to new given pointer.
A bounding box defined in terms of min/max extrema points.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
dictionary & subDictOrAdd(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary for manipulation.
void writeEntry(Ostream &os) const
Write sub-dictionary with its dictName as its header.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
SolverPerformance< Type > solve(const dictionary &)
Solve returning the solution statistics.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
const DimensionedField< scalar, areaMesh > & S() const
Return face areas.
static autoPtr< faMesh > TryNew(const word &areaName, const polyMesh &pMesh)
Read construction from polyMesh if all files are available.
static const word & prefix() noexcept
The prefix to the parent registry name: finite-area.
const areaVectorField & faceAreaNormals() const
Return face area normals.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Mesh data needed to do the Finite Volume discretisation.
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Abstract base class for volume field interpolation.
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
const boundBox & bounds() const noexcept
Return mesh bounding box.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
A patch is a list of labels that address the faces in the global face list.
label nPoints() const noexcept
Number of mesh points.
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Calculation of adjoint-based sensitivities at wall points using the E-SI formulation.
void read()
Read controls and update solver pointers if necessary.
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
Calculation of adjoint based sensitivities at wall faces.
void read()
Read controls and update solver pointers if necessary.
bool returnVectorField_
Return the complete vector of sensitivities.
scalar computeRadius(const faMesh &aMesh)
Compute the physical smoothing radius based on the average boundary face 'length'.
bool smoothSensitivities_
Smooth sensitivity derivatives based on a surface Laplace solver.
label computeFaceDerivativesSize(const bool computeVectorFieldSize)
Compute the size of the return field.
void smoothSensitivities()
Smooth sensitivity derivatives based on the computation of the 'Sobolev gradient'.
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
A class for managing temporary objects.
Interpolate from cell centres to points (vertices) using inverse distance weighting.
Volume to surface and surface to volume mapping.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
const volSurfaceMapping vsm(aMesh)
Calculate the matrix for the laplacian of the field.
Calculate the finiteArea matrix for implicit and explicit sources.
#define DebugInfo
Report an information message using Foam::Info.
Namespace for bounding specifications. At the moment, mostly for tables.
Namespace for handling debugging switches.
tmp< faMatrix< Type > > laplacian(const GeometricField< Type, faPatchField, areaMesh > &vf)
zeroField Sp(const Foam::zero, const GeometricField< Type, faPatchField, areaMesh > &)
A no-op source.
const std::string patch
OpenFOAM patch number as a std::string.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
List< word > wordList
List of word.
const dimensionSet dimless
Dimensionless.
List< label > labelList
A List of labels.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
const dimensionSet dimArea(sqr(dimLength))
messageStream Info
Information stream (stdout output on master, null elsewhere).
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
Ostream & endl(Ostream &os)
Add newline and flush stream.
GeometricField< vector, faPatchField, areaMesh > areaVectorField
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
GeometricField< scalar, faPatchField, areaMesh > areaScalarField
faMatrix< vector > faVectorMatrix
Field< vector > vectorField
Specialisation of Field<T> for vector.
static constexpr const zero Zero
Global zero (0).
autoPtr< typename GeometricField< Type, fvPatchField, volMesh >::Boundary > createZeroBoundaryPtr(const fvMesh &mesh, bool printAllocation=false)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Type gMax(const FieldField< Field, Type > &f)
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
constexpr char nl
The newline '\n' character (0x0a).
loopControl iters(runTime, aMesh.solutionDict(), "solution")
#define forAll(list, i)
Loop across all elements in list.