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 -------------------------------------------------------------------------------
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 
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 namespace incompressible
39 {
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 defineTypeNameAndDebug(shapeOptimisation, 0);
45 (
46  optimisationType,
47  shapeOptimisation,
48  dictionary
49 );
50 
51 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
52 
54 {
55  // Communicate the movement to optMeshMovement
56  optMeshMovement_->setCorrection(correction);
57 
58  if (updateGeometry_)
59  {
60  // Update the mesh
61  optMeshMovement_->moveMesh();
62 
63  if (writeEachMesh_)
64  {
65  Info<< " Writing new mesh points " << endl;
67  (
68  IOobject
69  (
70  "points",
73  mesh_,
76  false
77  ),
78  mesh_.points()
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 
119 shapeOptimisation::shapeOptimisation
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  (
142  mesh_.boundaryMesh().patchSet
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 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::incompressible::shapeOptimisation::storeDesignVariables
virtual void storeDesignVariables()
Store design variables, as the starting point for line search.
Definition: shapeOptimisationIncompressible.C:183
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::incompressible::defineTypeNameAndDebug
defineTypeNameAndDebug(adjointEikonalSolver, 0)
Foam::incompressible::optimisationType::write
virtual void write()
Write useful quantities to files.
Definition: optimisationTypeIncompressible.C:321
Foam::optMeshMovement::New
static autoPtr< optMeshMovement > New(fvMesh &mesh, const dictionary &dict, const labelList &patchIDs)
Definition: optMeshMovement.C:93
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:321
Foam::incompressible::optimisationType
Abstract base class for optimisation methods.
Definition: optimisationTypeIncompressible.H:58
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::correction
tmp< fvMatrix< Type > > correction(const fvMatrix< Type > &)
Foam::HashSet< label, Hash< label > >
Foam::incompressible::shapeOptimisation::optMeshMovement_
autoPtr< optMeshMovement > optMeshMovement_
Definition: shapeOptimisationIncompressible.H:70
Foam::incompressible::shapeOptimisation::updateGeometry_
bool updateGeometry_
Definition: shapeOptimisationIncompressible.H:73
Foam::polyMesh::pointsInstance
const fileName & pointsInstance() const
Return the current instance directory for points.
Definition: polyMesh.C:846
Foam::incompressible::shapeOptimisation::write
virtual void write()
Write useful quantities to files.
Definition: shapeOptimisationIncompressible.C:195
Foam::incompressible::addToRunTimeSelectionTable
addToRunTimeSelectionTable(adjointSensitivity, sensitivityBezier, dictionary)
Foam::Field< scalar >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
adjointSolverManagers
PtrList< adjointSolverManager > & adjointSolverManagers
Definition: createFields.H:8
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
Foam::incompressible::optimisationType::mesh_
fvMesh & mesh_
Definition: optimisationTypeIncompressible.H:64
Foam::incompressible::shapeOptimisation::resetDesignVariables
virtual void resetDesignVariables()
Store design variables, as the starting point for line search.
Definition: shapeOptimisationIncompressible.C:189
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
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
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
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::shapeOptimisation::updateDesignVariables
virtual void updateDesignVariables(scalarField &correction)
Update the design variables given their correction.
Definition: shapeOptimisationIncompressible.C:53
Foam::incompressible::shapeOptimisation::writeEachMesh_
bool writeEachMesh_
Definition: shapeOptimisationIncompressible.H:72
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
shapeOptimisationIncompressible.H
Shape optimisation support library.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::incompressible::optimisationType::updateMethod_
autoPtr< updateMethod > updateMethod_
Definition: optimisationTypeIncompressible.H:67
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::incompressible::shapeOptimisation::computeEta
virtual void computeEta(scalarField &correction)
Compute eta if not set in the first step.
Definition: shapeOptimisationIncompressible.C:87
Foam::IOobject::NO_READ
Definition: IOobject.H:188
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328