adjointEikonalSolverIncompressible.H
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-2020 PCOpt/NTUA
9  Copyright (C) 2013-2020 FOSS GP
10  Copyright (C) 2019 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  FITNESS 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 Class
30  Foam::incompressible::adjointEikonalSolver
31 
32 Description
33  Solver of the adjoint to the eikonal PDE
34 
35  Reference:
36  \verbatim
37  For the development of the adjoint eikonal PDE and its boundary
38  conditions
39 
40  Papoutsis-Kiachagias, E. M., & Giannakoglou, K. C. (2014).
41  Continuous Adjoint Methods for Turbulent Flows, Applied to Shape
42  and Topology Optimization: Industrial Applications.
43  Archives of Computational Methods in Engineering, 23(2), 255-299.
44  http://doi.org/10.1007/s11831-014-9141-9
45  \endverbatim
46 
47  To be as consistent as possible, it is recommended to use the
48  advectionDiffusion wallDist method in fvSchemes, instead of the more widely
49  used meshWave
50 
51  Example of the adjointEikonalSolver specification in optimisationDict:
52  \verbatim
53  optimisation
54  {
55  sensitivities
56  {
57  includeDistance true;
58  adjointEikonalSolver
59  {
60  // epsilon should be the same as the one used
61  // in fvSchemes/wallDist/advectionDiffusionCoeffs
62  epsilon 0.1;
63  iters 1000;
64  tolerance 1e-6;
65  }
66  }
67  }
68  \endverbatim
69 
70  Example of the entries in fvSchemes:
71  \verbatim
72  divSchemes
73  {
74  .
75  .
76  // avoid bounded schemes since yPhi is not conservative
77  div(-yPhi,da) Gauss linearUpwind grad(da);
78  .
79  .
80  }
81  laplacianSchemes
82  {
83  .
84  .
85  laplacian(yWall,da) Gauss linear corrected;
86  .
87  .
88  }
89  \endverbatim
90 
91  Also, the solver specification and a relaxation factor for da are required
92  in fvSolution
93 
94  \verbatim
95  da
96  {
97  solver PBiCGStab;
98  preconditioner DILU;
99  tolerance 1e-9;
100  relTol 0.1;
101  }
102 
103  relaxationFactors
104  {
105  equations
106  {
107  .
108  .
109  da 0.5;
110  .
111  .
112  }
113  }
114  \endverbatim
115 
116 See also
117  Foam::patchDistMethod::advectionDiffusion
118  Foam::wallDist
119 
120 
121 SourceFiles
122  adjointEikonalSolver.C
123 
124 \*---------------------------------------------------------------------------*/
125 
126 #ifndef adjointEikonalSolverIncompressible_H
127 #define adjointEikonalSolverIncompressible_H
128 
129 #include "IOdictionary.H"
131 #include "createZeroField.H"
132 #include "boundaryFieldsFwd.H"
133 #include "RASModelVariables.H"
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 namespace Foam
138 {
139 
140 namespace incompressible
141 {
142 
143 /*---------------------------------------------------------------------------*\
144  Class adjointEikonalSolver Declaration
145 \*---------------------------------------------------------------------------*/
146 
148 {
149 private:
150 
151  // Private Member Functions
152 
153  //- No copy construct
155 
156  //- No copy assignment
157  void operator=(const adjointEikonalSolver&) = delete;
158 
159 
160 protected:
161 
162  // Protected data
163 
164  const fvMesh& mesh_;
165 
167 
169 
172 
174 
175  label nEikonalIters_;
176 
177  scalar tolerance_;
178 
179  scalar epsilon_;
180 
182 
184 
186 
187  //- Wall face sens w.r.t. (x,y.z)
189 
190 
191  // Protected functions
192 
193  //- Return the boundary condition types for da
194  wordList patchTypes() const;
195 
196  //- Compute convecting velocity
198 
199  //- Read options each time a new solution is found
200  void read();
201 
202 
203 
204 public:
205 
206  //- Runtime type information
207  TypeName("adjointEikonalSolver");
208 
209 
210  // Constructors
211 
212  //- Construct from components
214  (
215  const fvMesh& mesh,
216  const dictionary& dict,
217  const autoPtr<incompressible::RASModelVariables>& RASModelVars,
218  incompressibleAdjointVars& adjointVars,
219  const labelHashSet& sensitivityPatchIDs
220  );
221 
222  // Destructor
223 
224  virtual ~adjointEikonalSolver() = default;
225 
226 
227  // Member Functions
228 
229  //- Read dict if changed
230  virtual bool readDict(const dictionary& dict);
231 
232  //- Accumulate source term
233  void accumulateIntegrand(const scalar dt);
234 
235  //- Calculate the adjoint distance field
236  void solve();
237 
238  //- Reset source term
239  void reset();
240 
241  //- Return the sensitivity term depending on da
243 
244  //- Return the volume-based sensitivity term depending on da
246 
247  //- Return the adjoint distance field
248  const volScalarField& da();
249 
250  //- Return the distance field
251  const volScalarField& d();
252 
253  //- Return the gradient of the eikonal equation
255 };
256 
257 
258 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 
260 } // End namespace incompressible
261 } // End namespace Foam
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 #endif
266 
267 // ************************************************************************* //
Foam::incompressible::adjointEikonalSolver::nEikonalIters_
label nEikonalIters_
Definition: adjointEikonalSolverIncompressible.H:174
Foam::incompressible::adjointEikonalSolver::reset
void reset()
Reset source term.
Definition: adjointEikonalSolverIncompressible.C:232
Foam::incompressible::adjointEikonalSolver::getFISensitivityTerm
tmp< volTensorField > getFISensitivityTerm() const
Return the volume-based sensitivity term depending on da.
Definition: adjointEikonalSolverIncompressible.C:260
Foam::incompressible::adjointEikonalSolver::accumulateIntegrand
void accumulateIntegrand(const scalar dt)
Accumulate source term.
Definition: adjointEikonalSolverIncompressible.C:178
Foam::incompressible::adjointEikonalSolver::distanceSensitivities
boundaryVectorField & distanceSensitivities()
Return the sensitivity term depending on da.
Definition: adjointEikonalSolverIncompressible.C:239
Foam::incompressible::adjointEikonalSolver::~adjointEikonalSolver
virtual ~adjointEikonalSolver()=default
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::incompressible::adjointEikonalSolver::wallPatchIDs_
labelHashSet wallPatchIDs_
Definition: adjointEikonalSolverIncompressible.H:180
Foam::incompressible::adjointEikonalSolver::solve
void solve()
Calculate the adjoint distance field.
Definition: adjointEikonalSolverIncompressible.C:185
Foam::incompressible::adjointEikonalSolver::TypeName
TypeName("adjointEikonalSolver")
Runtime type information.
Foam::incompressible::adjointEikonalSolver::da_
volScalarField da_
Definition: adjointEikonalSolverIncompressible.H:182
Foam::HashSet< label, Hash< label > >
Foam::incompressible::adjointEikonalSolver::da
const volScalarField & da()
Return the adjoint distance field.
Definition: adjointEikonalSolverIncompressible.C:310
Foam::incompressibleAdjointVars
Class including all adjoint fields for incompressible flows.
Definition: incompressibleAdjointVars.H:52
Foam::incompressible::adjointEikonalSolver::sensitivityPatchIDs_
const labelHashSet & sensitivityPatchIDs_
Definition: adjointEikonalSolverIncompressible.H:172
Foam::incompressible::adjointEikonalSolver
Solver of the adjoint to the eikonal PDE.
Definition: adjointEikonalSolverIncompressible.H:146
Foam::incompressible::adjointEikonalSolver::patchTypes
wordList patchTypes() const
Return the boundary condition types for da.
Definition: adjointEikonalSolverIncompressible.C:48
RASModelVariables.H
createZeroField.H
Foam::incompressible::adjointEikonalSolver::dict_
dictionary dict_
Definition: adjointEikonalSolverIncompressible.H:165
Foam::incompressible::adjointEikonalSolver::tolerance_
scalar tolerance_
Definition: adjointEikonalSolverIncompressible.H:176
Foam::incompressible::adjointEikonalSolver::d
const volScalarField & d()
Return the distance field.
Foam::incompressible::adjointEikonalSolver::read
void read()
Read options each time a new solution is found.
Definition: adjointEikonalSolverIncompressible.C:65
Foam::incompressible::adjointEikonalSolver::computeYPhi
tmp< surfaceScalarField > computeYPhi()
Compute convecting velocity.
Definition: adjointEikonalSolverIncompressible.C:73
Foam::incompressible::adjointEikonalSolver::source_
volScalarField source_
Definition: adjointEikonalSolverIncompressible.H:184
Foam::incompressible::adjointEikonalSolver::gradEikonal
tmp< volVectorField > gradEikonal()
Return the gradient of the eikonal equation.
Definition: adjointEikonalSolverIncompressible.C:316
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::incompressible::adjointEikonalSolver::adjointTurbulence_
autoPtr< Foam::incompressibleAdjoint::adjointRASModel > & adjointTurbulence_
Definition: adjointEikonalSolverIncompressible.H:170
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::incompressible::adjointEikonalSolver::readDict
virtual bool readDict(const dictionary &dict)
Read dict if changed.
Definition: adjointEikonalSolverIncompressible.C:170
Foam::incompressible::adjointEikonalSolver::epsilon_
scalar epsilon_
Definition: adjointEikonalSolverIncompressible.H:178
incompressibleAdjointVars.H
IOdictionary.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::incompressible::adjointEikonalSolver::mesh_
const fvMesh & mesh_
Definition: adjointEikonalSolverIncompressible.H:163
Foam::GeometricField::Boundary
The boundary fields.
Definition: GeometricField.H:115
boundaryFieldsFwd.H
Useful typenames for fields defined only at the boundaries.
Foam::List< word >
Foam::incompressible::adjointEikonalSolver::RASModelVars_
const autoPtr< incompressible::RASModelVariables > & RASModelVars_
Definition: adjointEikonalSolverIncompressible.H:167
Foam::incompressible::adjointEikonalSolver::distanceSensPtr_
autoPtr< boundaryVectorField > distanceSensPtr_
Wall face sens w.r.t. (x,y.z)
Definition: adjointEikonalSolverIncompressible.H:187
Foam::GeometricField< scalar, fvPatchField, volMesh >