shapeOptimisationIncompressible.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-2020 PCOpt/NTUA
9 Copyright (C) 2013-2020 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 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
32
33// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34
35namespace Foam
36{
37
38namespace incompressible
39{
40
41// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42
45(
49);
50
51// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
52
54{
55 // Communicate the movement to optMeshMovement
56 optMeshMovement_->setCorrection(correction);
57
59 {
60 // Update the mesh
61 optMeshMovement_->moveMesh();
62
64 {
65 Info<< " Writing new mesh points " << endl;
67 (
69 (
70 "points",
73 mesh_,
76 false
77 ),
79 );
80 points.write();
81 }
82 }
83}
84
85
87(
89)
90{
91 if (!updateMethod_->initialEtaSet())
92 {
93 // In the unlikely event that eta is not set and the line search step
94 // is not 1, multiply with it
95 // if (lineSearch_) correction *= lineSearch_->step();
96
97 // Compute eta based on desirable mesh movement size
98 scalar eta = optMeshMovement_->computeEta(correction);
99 correction *= eta;
100
101 // Update eta known by the optimisation method and inform it that is
102 // has been set
103 updateMethod_->setStep(eta);
104 updateMethod_->initialEtaSet() = true;
105
106 // If a backtracking should be made at the first optimisation cycle,
107 // the direction of the subsequent line searches of the same cycle
108 // should also be scaled with the newly computed eta. We do this by
109 // changing the line search step. This will happen only at the first
110 // optimisation cycle since the updated value of eta will be included
111 // in the line search direction in all subsequent optimisation cycles
112 //correction *= eta;
113 }
114}
115
116
117// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118
120(
121 fvMesh& mesh,
122 const dictionary& dict,
124)
125:
127 optMeshMovement_(nullptr),
128 writeEachMesh_
129 (
130 dict.subDict("optimisationType").
131 getOrDefault<bool>("writeEachMesh", false)
132 ),
133 updateGeometry_
134 (
135 dict.subDict("optimisationType").
136 getOrDefault<bool>("updateGeometry", true)
137 )
138{
139 // Note: to be updated
141 (
143 (
144 dict_.subDict("sensitivities").get<wordRes>("patches")
145 )
146 );
147 if (patches.empty())
148 {
150 << "There is no patch on which to compute sensitivities. "
151 << "Check optimisationDict \n"
152 << endl;
153 }
154 labelList sensitivityPatchIDs = patches.toc();
155 optMeshMovement_.reset
156 (
158 (
159 mesh_,
160 dict_.subDict("meshMovement"),
161 sensitivityPatchIDs
162 ).ptr()
163 );
164
165 // Sanity checks: at least one of eta or maxAllowedDisplacement must be set
166 if
167 (
168 !updateMethod_->initialEtaSet()
169 && !optMeshMovement_().maxAllowedDisplacementSet()
170 )
171 {
173 << "Neither eta (updateMethod) "
174 << "nor maxAllowedDisplacement (meshMovement) have been set"
175 << nl
176 << exit(FatalError);
177 }
178}
179
180
181// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
182
184{
185 optMeshMovement_->storeDesignVariables();
186}
187
188
190{
191 optMeshMovement_->resetDesignVariables();
192}
193
194
196{
198 updateMethod_->writeCorrection();
199}
200
201
202// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203
204} // End namespace incompressible
205} // End namespace Foam
206
207// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
Definition: UPtrListI.H:113
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Abstract base class for optimisation methods.
virtual void write()
Write useful quantities to files.
Calculates shape sensitivities using the adjoint approach, computes boundaryMesh movement and propaga...
virtual void resetDesignVariables()
Store design variables, as the starting point for line search.
virtual void computeEta(scalarField &correction)
Compute eta if not set in the first step.
virtual void write()
Write useful quantities to files.
virtual void storeDesignVariables()
Store design variables, as the starting point for line search.
virtual void updateDesignVariables()=0
Update design variables.
labelHashSet patchSet(const UList< wordRe > &patchNames, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:860
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1083
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:324
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
bool
Definition: EEqn.H:20
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const pointField & points
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
Shape optimisation support library.
PtrList< adjointSolverManager > & adjointSolverManagers
Definition: createFields.H:8