SIBaseIncompressible.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 
30 #include "SIBaseIncompressible.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 
38 namespace incompressible
39 {
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
44 
45 
46 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
47 
48 void SIBase::read()
49 {
52  dict().getOrDefault<bool>("includeObjectiveContribution", true);
54  dict().getOrDefault<bool>("writeSensitivityMap", false);
55 
56  // If includeObjective is set to true both here and in the surface
57  // sensitivities, set the one in the latter to false to avoid double
58  // contributions
59  bool surfSensIncludeObjective(surfaceSensitivity_.getIncludeObjective());
60  if (includeObjective_ && surfSensIncludeObjective)
61  {
63  << "includeObjectiveContribution set to true in both "
64  << "surfaceSensitivities and the parameterization options" << nl
65  << "This will lead to double contributions " << nl
66  << "Disabling the former"
67  << endl;
69  }
70 
71  // Make sure surface area is included in the sensitivity map
73 }
74 
75 
76 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
77 
78 SIBase::SIBase
79 (
80  const fvMesh& mesh,
81  const dictionary& dict,
83 )
84 :
86  surfaceSensitivity_
87  (
88  mesh,
89  // Ideally, subOrEmptyDict would be used.
90  // Since we need a recursive search in shapeSensitivities though
91  // and the dict returned by subOrEmptyDict (if found)
92  // does not know its parent, optionalSubDict is used
93  dict.optionalSubDict("surfaceSensitivities"),
95  ),
96  includeObjective_(true),
97  writeSensitivityMap_(true)
98 {
99  read();
100 }
101 
102 
103 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
104 
105 bool SIBase::readDict(const dictionary& dict)
106 {
108  {
110  (
111  dict.optionalSubDict("surfaceSensitivities")
112  );
113 
114  return true;
115  }
116 
117  return false;
118 }
119 
120 
121 void SIBase::accumulateIntegrand(const scalar dt)
122 {
123  // Accumulate multiplier of dxFace/db
125 
126  // Accumulate direct sensitivities
127  if (includeObjective_)
128  {
130  }
131 
132  // Accumulate sensitivities due to boundary conditions
134 }
135 
136 
138 {
141 }
142 
145 {
146  return surfaceSensitivity_;
147 }
148 
149 
150 void SIBase::write(const word& baseName)
151 {
152  shapeSensitivities::write(baseName);
154  {
155  surfaceSensitivity_.write(baseName);
156  }
157 }
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace incompressible
163 } // End namespace Foam
164 
165 // ************************************************************************* //
dictionary dict
virtual bool readDict(const dictionary &dict)
Read dict if changed.
void setIncludeObjective(const bool includeObjective)
Set includeObjective bool.
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
Definition: sensitivity.C:56
defineTypeNameAndDebug(adjointEikonalSolver, 0)
virtual void accumulateDirectSensitivityIntegrand(const scalar dt)
Accumulate direct sensitivities.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
virtual void write(const word &baseName=word::null)
Write sensitivity map.
virtual void write(const word &baseName=word::null)
Write sensitivity maps.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
bool includeObjective_
Whether to include direct sensitivities or not.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
Base class for adjoint solvers.
Definition: adjointSolver.H:51
virtual void write(const word &baseName=word::null)
Write sensitivity fields.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
void read()
Read controls and update solver pointers if necessary.
Macros for easy insertion into run-time selection tables.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:127
Base class for incompressibleAdjoint solvers.
const dictionary & dict() const
Return the construction dictionary.
Definition: sensitivity.C:50
void setIncludeSurfaceArea(const bool includeSurfaceArea)
Set includeSurfaceArea bool.
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:572
dynamicFvMesh & mesh
Base class for Surface Integral-based sensitivity derivatives.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool readDict(const dictionary &dict)
Read dict if changed.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
void read()
Read options from dict.
#define WarningInFunction
Report a warning using Foam::Warning.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
Calculation of adjoint based sensitivities at wall faces.
bool getIncludeObjective() const
Get access to the includeObjective bool.
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...
sensitivitySurface surfaceSensitivity_
Surface sensitivities.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
const sensitivitySurface & getSurfaceSensitivities() const
Return reference to underlaying surface sensitivities.
bool writeSensitivityMap_
Write sensitivity map upon write.
Namespace for OpenFOAM.
virtual void accumulateBCSensitivityIntegrand(const scalar dt)
Accumulate sensitivities enamating from the boundary conditions.