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 -------------------------------------------------------------------------------
12 License
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"
33 #include "ShapeSensitivitiesBase.H"
34 #include "fvOptions.H"
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
46 (
48 );
49 
50 
52 {
53  if (eikonalSolver_)
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 
93 sensitivityShapeESI::sensitivityShapeESI
94 (
95  const fvMesh& mesh,
96  const dictionary& dict,
97  adjointSolver& adjointSolver
98 )
99 :
100  ShapeSensitivitiesBase(mesh, dict, adjointSolver)
101 {
102  dxdbMult_.reset(createZeroBoundaryPtr<vector>(mesh_));
103  // The boundary values of divDxDbMultiplier are stored in dxdbDirectMult
104  // after applying the Gauss divergence theorem.
105  // Allocate dxdbDirectMult if necessary
107  {
108  dxdbDirectMult_.reset(createZeroBoundaryPtr<vector>(mesh_));
109  }
110  if (dict.getOrDefault<bool>("includeMeshMovement", true))
111  {
113  (
114  new adjointMeshMovementSolver(mesh, dict, *this)
115  );
116  }
117 }
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
122 bool Foam::sensitivityShapeESI::readDict(const dictionary& dict)
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 {
156  computeDxDbMult();
157  if (designVars)
158  {
160  }
161 }
162 
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 } // End namespace Foam
167 
168 // ************************************************************************* //
const fvMesh & mesh_
Definition: sensitivity.H:68
dictionary dict
void computeDxDbMult()
Compute dxdbMult from its various components.
adjointSolver & adjointSolver_
Reference to the underlaying adjoint solver.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
Abstract base class for adjoint-based sensitivities.
PtrList< objective > & getObjectiveFunctions()
Return reference to objective functions.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
const fvMesh & mesh() const
Return reference to mesh.
Definition: sensitivity.H:121
Macros for easy insertion into run-time selection tables.
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
const objectiveManager & getObjectiveManager() const
Return a const reference to the objective manager.
dynamicFvMesh & mesh
autoPtr< volTensorField > gradDxDbMult_
Multiplier of grad(dx/b)
autoPtr< adjointMeshMovementSolver > adjointMeshMovementSolver_
Adjoint grid displacement solver.
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.
autoPtr< boundaryVectorField > dxdbDirectMult_
Multiplier of dCf/db, found in the objective function.
Abstract base class for objective functions. No point in making this runTime selectable since its chi...
Definition: objective.H:55
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
defineTypeNameAndDebug(combustionModel, 0)
Useful typenames for fields defined only at the boundaries.
const dictionary & dict() const
Return the construction dictionary.
Definition: sensitivity.H:129
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
const std::string patch
OpenFOAM patch number as a std::string.
bool hasDivDxDbMult() const noexcept
Definition: objectiveI.H:211
messageStream Info
Information stream (stdout output on master, null elsewhere)
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition: fvMesh.H:395
autoPtr< adjointEikonalSolver > eikonalSolver_
Adjoint eikonal equation solver.
Field< vector > vectorField
Specialisation of Field<T> for vector.
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...
bool hasMultiplier(bool(objective::*hasFunction)() const)
Check if any of the available objective has a certain multiplier, provided through a function object...
Namespace for OpenFOAM.
autoPtr< boundaryVectorField > dxdbMult_
Multiplier of face dx/db.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
Class for computing sensitivity derivatives using the Enhanced Surface Integral (E-SI) formulation...