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));
77 autoPtr<faMesh> aMeshPtr(
nullptr);
97 Info<<
"Reading the already constructed faMesh" <<
endl;
98 aMeshPtr.reset(
new faMesh(
mesh_));
105 IOobject faMeshDefinitionDict
115 if (faMeshDefinitionDict.typeHeaderOk<IOdictionary>(
false))
117 Info<<
"Reading faMeshDefinition from system " <<
endl;
118 faMeshDefinition = IOdictionary(faMeshDefinitionDict);
124 Info<<
"Constructing faMeshDefinition from sensitivity patches" 132 faMeshDefinition.add<
wordList>(
"polyMeshPatches", polyMeshPatches);
133 (void)faMeshDefinition.subDictOrAdd(
"boundary");
138 aMeshPtr.reset(
new faMesh(
mesh_, faMeshDefinition));
140 faMesh& aMesh = aMeshPtr.ref();
144 const scalar Rphysical
147 <<
"Physical radius of the sensitivity smoothing " 148 << Rphysical <<
nl <<
endl;
160 volSurfaceMapping
vsm(aMesh);
185 for (label iter = 0; iter <
iters; ++iter)
187 Info<<
"Sensitivity smoothing iteration " << iter <<
endl;
199 const scalar residual(
mag(smoothEqn.solve().initialResidual()));
202 <<
"Max smoothSens " <<
gMax(
mag(smoothedSens)()) <<
endl;
208 if (residual < tolerance)
210 Info<<
"\n***Reached smoothing equation convergence limit, " 211 "iteration " << iter <<
"***\n\n";
225 "smoothedSurfaceSens" +
suffix_,
237 vsm.mapToVolume(smoothedSensNormal, volSmoothedSens.boundaryFieldRef());
238 volSmoothedSens.write();
244 scalar averageArea(
gAverage(aMesh.
S().field()));
249 if (geometricD[iDir] == -1)
251 averageArea /= bounds.
span()[iDir];
262 sensitivitySurface::sensitivitySurface
270 smoothSensitivities_(
dict.getOrDefault(
"smoothSensitivities", false)),
272 (
dict.getOrDefault<bool>(
"returnVectorField", true))
322 volPointInterpolationAdjoint interpolation(
mesh_);
323 interpolation.interpolateSensitivitiesField
327 label nPassedFaces(0);
331 tmp<vectorField> nf =
patch.nf();
333 SubField<vector>(faceVecSens,
patch.size(), nPassedFaces)
338 nPassedFaces +=
patch.size();
360 const label gfI = nPassedFaces + fI;
362 derivatives_[3*gfI ] = scalar(sd[0] == -1 ? 0 : fSens.x());
363 derivatives_[3*gfI + 1] = scalar(sd[1] == -1 ? 0 : fSens.y());
364 derivatives_[3*gfI + 2] = scalar(sd[2] == -1 ? 0 : fSens.z());
375 nPassedFaces +=
patch.size();
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
autoPtr< pointBoundaryVectorField > wallPointSensVecPtr_
Wall point sens w.r.t. (x,y.z)
const volSurfaceMapping vsm(aMesh)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
word findInstance(const fileName &dir, const word &name=word::null, IOobjectOption::readOption rOpt=IOobjectOption::MUST_READ, const word &stopInstance=word::null) const
Return time instance (location) of dir that contains the file name (eg, used in reading mesh data)...
label nPoints() const noexcept
Number of mesh points.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
labelHashSet sensitivityPatchIDs_
Patches on which to compute shape sensitivities.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
const Vector< label > & solutionD() const
Return the vector of solved-for directions in mesh.
constexpr char nl
The newline '\n' character (0x0a)
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
const DimensionedField< scalar, areaMesh > & S() const
Return face areas.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
autoPtr< boundaryVectorField > wallFaceSensNormalVecPtr_
Normal sens as vectors.
Base class for adjoint solvers.
A bounding box defined in terms of min/max extrema points.
void read()
Read controls and update solver pointers if necessary.
virtual const fileName & dbDir() const
Override the objectRegistry dbDir for a single-region case.
faMatrix< vector > faVectorMatrix
Ignore writing from objectRegistry::writeObject()
const dimensionSet dimless
Dimensionless.
const Time & time() const
Return the top-level database.
autoPtr< boundaryVectorField > wallFaceSensVecPtr_
Wall face sens w.r.t. (x,y.z)
labelList faceLabels(nFaceLabels)
autoPtr< boundaryScalarField > wallFaceSensNormalPtr_
Wall face sens projected to normal.
label nGeometricD() const
Return the number of valid geometric dimensions in the mesh.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
tmp< faMatrix< Type > > laplacian(const GeometricField< Type, faPatchField, areaMesh > &vf)
fileName caseSystem() const
Return the system name for the case, which is ../system() for parallel runs.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
label size() const noexcept
The number of elements in table.
zeroField Sp(const Foam::zero, const GeometricField< Type, faPatchField, areaMesh > &)
A no-op source.
const dimensionedScalar e
Elementary charge.
IOList< label > labelIOList
IO for a List of label.
void setSize(const label n)
Alias for resize()
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Reading is optional [identical to LAZY_READ].
void smoothSensitivities()
Smooth sensitivity derivatives based on the computation of the 'Sobolev gradient'.
scalar computeRadius(const faMesh &aMesh)
Compute the physical smoothing radius based on the average boundary face 'length'.
Calculate the matrix for the laplacian of the field.
#define DebugInfo
Report an information message using Foam::Info.
Calculate the finiteArea matrix for implicit and explicit sources.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
void normalise()
Normalise the field inplace. See notes in Field.
Type gMax(const FieldField< Field, Type > &f)
defineTypeNameAndDebug(combustionModel, 0)
bool smoothSensitivities_
Smooth sensitivity derivatives based on a surface Laplace solver.
Ostream & printExecutionTime(OSstream &os) const
Print the elapsed ExecutionTime (cpu-time), ClockTime.
word suffix_
Append this word to files related to the sensitivities.
const dictionary & dict() const
Return the construction dictionary.
dimensionedScalar pow(const dimensionedScalar &ds, const dimensionedScalar &expt)
List< word > wordList
List of word.
static word meshSubDir
The mesh sub-directory name (usually "faMesh")
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
label computeFaceDerivativesSize(const bool computeVectorFieldSize)
Compute the size of the return field.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Type gAverage(const FieldField< Field, Type > &f)
scalarField derivatives_
The sensitivity derivative values.
Mesh data needed to do the Finite Volume discretisation.
loopControl iters(runTime, aMesh.solutionDict(), "solution")
const std::string patch
OpenFOAM patch number as a std::string.
bool returnVectorField_
Return the complete vector of sensitivities.
vector span() const
The bounding box span (from minimum to maximum)
messageStream Info
Information stream (stdout output on master, null elsewhere)
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
const boundBox & bounds() const noexcept
Return mesh bounding box.
Field< vector > vectorField
Specialisation of Field<T> for vector.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
void read()
Read controls and update solver pointers if necessary.
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...
A patch is a list of labels that address the faces in the global face list.
GeometricField< vector, faPatchField, areaMesh > areaVectorField
Calculation of adjoint-based sensitivities at wall points using the E-SI formulation.
const dimensionSet dimArea(sqr(dimLength))
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
static constexpr const zero Zero
Global zero (0)