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-------------------------------------------------------------------------------
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
44
45
46// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
47
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
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
105bool SIBase::readDict(const dictionary& dict)
106{
107 if (sensitivity::readDict(dict))
108 {
110 (
111 dict.optionalSubDict("surfaceSensitivities")
112 );
113
114 return true;
115 }
116
117 return false;
118}
119
120
121void SIBase::accumulateIntegrand(const scalar dt)
122{
123 // Accumulate multiplier of dxFace/db
125
126 // Accumulate direct sensitivities
128 {
130 }
131
132 // Accumulate sensitivities due to boundary conditions
134}
135
136
138{
141}
142
143
145{
146 return surfaceSensitivity_;
147}
148
149
150void SIBase::write(const word& baseName)
151{
154 {
155 surfaceSensitivity_.write(baseName);
156 }
157}
158
159
160// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161
162} // End namespace incompressible
163} // End namespace Foam
164
165// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Base class for adjoint solvers.
Definition: adjointSolver.H:60
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
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:577
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
virtual bool write()
Write the output fields.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
Base class for incompressibleAdjoint solvers.
Base class for Surface Integral-based sensitivity derivatives.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
sensitivitySurface surfaceSensitivity_
Surface sensitivities.
const sensitivitySurface & getSurfaceSensitivities() const
Return reference to underlaying surface sensitivities.
bool writeSensitivityMap_
Write sensitivity map upon write.
void read()
Read options from dict.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
bool includeObjective_
Whether to include direct sensitivities or not.
Calculation of adjoint based sensitivities at wall faces.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
void setIncludeSurfaceArea(const bool includeSurfaceArea)
Set includeSurfaceArea bool.
virtual void write(const word &baseName=word::null)
Write sensitivity maps.
void setIncludeObjective(const bool includeObjective)
Set includeObjective bool.
virtual bool readDict(const dictionary &dict)
Read dict if changed.
void read()
Read controls and update solver pointers if necessary.
bool getIncludeObjective() const
Get access to the includeObjective bool.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
virtual void accumulateBCSensitivityIntegrand(const scalar dt)
Accumulate sensitivities enamating from the boundary conditions.
virtual void accumulateDirectSensitivityIntegrand(const scalar dt)
Accumulate direct sensitivities.
const dictionary & dict() const
Return the construction dictionary.
Definition: sensitivity.C:57
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict