Loading...
Searching...
No Matches
sensitivityShapeESI.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2007-2023 PCOpt/NTUA
9 Copyright (C) 2013-2023 FOSS GP
10 Copyright (C) 2019-2020 OpenCFD Ltd.
11-------------------------------------------------------------------------------
12License
13 This file is part of OpenFOAM.
14
15 OpenFOAM is free software: you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 ESITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27
28\*---------------------------------------------------------------------------*/
29
30#include "boundaryFieldsFwd.H"
31#include "sensitivityShapeESI.H"
32#include "adjointSolver.H"
34#include "fvOptions.H"
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39namespace Foam
40{
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44defineTypeNameAndDebug(sensitivityShapeESI, 0);
46(
47 adjointSensitivity, sensitivityShapeESI, dictionary
48);
49
50
52{
54 {
55 eikonalSolver_->solve();
56 }
58 {
60 boundaryVectorField& meshMovementSens =
61 adjointMeshMovementSolver_->meshMovementSensitivities();
62 PtrList<objective>& functions =
64 for (const label patchI : geometryVariationIntegrationPatches())
65 {
66 const fvPatch& patch = mesh_.boundary()[patchI];
67 const scalarField& magSf = patch.magSf();
68 const vectorField& Sf = patch.Sf();
69 dxdbMult_()[patchI] = meshMovementSens[patchI]*magSf;
70 for (objective& func : functions)
71 {
72 if (func.hasDivDxDbMult())
73 {
74 Info<< func.objectiveName() << " " << patch.name() << endl;
75 dxdbDirectMult_()[patchI] +=
76 func.weight()
77 *func.divDxDbMultiplier().boundaryField()[patchI]
78 *Sf;
79 }
80 }
81 }
82 }
83 for (const label patchI : geometryVariationIntegrationPatches())
84 {
85 const vectorField& Sf = mesh_.boundary()[patchI].Sf();
86 dxdbMult_()[patchI] += Sf & gradDxDbMult_().boundaryField()[patchI];
87 }
88}
89
90
91// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92
93sensitivityShapeESI::sensitivityShapeESI
94(
95 const fvMesh& mesh,
96 const dictionary& dict,
97 adjointSolver& adjointSolver
98)
99:
100 ShapeSensitivitiesBase(mesh, dict, adjointSolver)
101{
103 // The boundary values of divDxDbMultiplier are stored in dxdbDirectMult
104 // after applying the Gauss divergence theorem.
105 // Allocate dxdbDirectMult if necessary
107 {
109 }
110 if (dict.getOrDefault<bool>("includeMeshMovement", true))
111 {
112 adjointMeshMovementSolver_.reset
113 (
114 new adjointMeshMovementSolver(mesh, dict, *this)
115 );
116 }
117}
118
119
120// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121
123{
125 {
126 bool includeMeshMovement =
127 dict.getOrDefault<bool>("includeMeshMovement", true);
128
129 if (includeMeshMovement)
130 {
131 if (adjointMeshMovementSolver_)
132 {
133 adjointMeshMovementSolver_->readDict(dict);
134 }
135 else
136 {
137 adjointMeshMovementSolver_.reset
138 (
139 new adjointMeshMovementSolver(mesh_, dict, *this)
140 );
141 }
142 }
143
144 return true;
145 }
146
147 return false;
148}
149
150
152(
153 autoPtr<designVariables>& designVars
154)
155{
157 if (designVars)
158 {
160 }
161}
162
163
164// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165
166} // End namespace Foam
167
168// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Useful typenames for fields defined only at the boundaries.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
bool hasMultiplier(bool(objective::*hasFunction)() const)
Check if any of the available objective has a certain multiplier, provided through a function object.
virtual bool readDict(const dictionary &dict)
Read dict if changed.
virtual const labelHashSet & geometryVariationIntegrationPatches() const
Return set of patches on which to compute direct sensitivities.
Class solving the adjoint grid dispalcement PDEs. Assumes the primal grid displacement PDE is a Lapla...
Abstract base class for adjoint-based sensitivities.
autoPtr< boundaryVectorField > dxdbDirectMult_
Multiplier of dCf/db, found in the objective function.
autoPtr< adjointEikonalSolver > eikonalSolver_
Adjoint eikonal equation solver.
adjointSolver & adjointSolver_
Reference to the underlaying adjoint solver.
autoPtr< boundaryVectorField > dxdbMult_
Multiplier of face dx/db.
autoPtr< adjointMeshMovementSolver > adjointMeshMovementSolver_
Adjoint grid displacement solver.
autoPtr< volTensorField > gradDxDbMult_
Multiplier of grad(dx/b).
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
Base class for adjoint solvers.
const objectiveManager & getObjectiveManager() const
Return a const reference to the objective manager.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition fvMesh.H:395
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
Definition objective.H:58
bool hasDivDxDbMult() const noexcept
Definition objectiveI.H:211
Class for computing sensitivity derivatives using the Enhanced Surface Integral (E-SI) formulation,...
void computeDxDbMult()
Compute dxdbMult from its various components.
virtual bool readDict(const dictionary &dict)
Read dict if changed.
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
const fvMesh & mesh_
Definition sensitivity.H:68
const fvMesh & mesh() const
Return reference to mesh.
const dictionary & dict() const
Return the construction dictionary.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
Field< vector > vectorField
Specialisation of Field<T> for vector.
autoPtr< typename GeometricField< Type, fvPatchField, volMesh >::Boundary > createZeroBoundaryPtr(const fvMesh &mesh, bool printAllocation=false)
volVectorField::Boundary boundaryVectorField
dictionary dict