sensitivityMultiple.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 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 "adjointSensitivity.H"
31 #include "sensitivityMultiple.H"
33 
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 defineTypeNameAndDebug(sensitivityMultiple, 0);
43 (
44  adjointSensitivity,
47 );
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 sensitivityMultiple::sensitivityMultiple
52 (
53  const fvMesh& mesh,
54  const dictionary& dict,
56 )
57 :
59  sensTypes_(this->dict().get<wordList>("sensitivityTypes")),
60  sens_(sensTypes_.size())
61 {
62  forAll(sensTypes_, sI)
63  {
64  sens_.set
65  (
66  sI,
68  (
69  mesh,
70  this->dict().subDict(sensTypes_[sI]),
72  )
73  );
74  sens_[sI].setSuffix(sensTypes_[sI]);
75  }
76 }
77 
78 
79 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
80 
81 bool sensitivityMultiple::readDict(const dictionary& dict)
82 {
84  {
85  forAll(sens_, sI)
86  {
87  sens_[sI].readDict(dict.subDict(sensTypes_[sI]));
88  }
89 
90  return true;
91  }
92 
93  return false;
94 }
95 
96 
97 void sensitivityMultiple::accumulateIntegrand(const scalar dt)
98 {
99  forAll(sens_, sI)
100  {
101  sens_[sI].accumulateIntegrand(dt);
102  }
103 }
104 
105 
107 (
108  autoPtr<designVariables>& designVars
109 )
110 {
111  forAll(sens_, sI)
112  {
113  sens_[sI].assembleSensitivities(designVars);
114  }
115 }
116 
117 
119 (
120  autoPtr<designVariables>& designVars
121 )
122 {
123  forAll(sens_, sI)
124  {
125  Info<< "Computing sensitivities " << sensTypes_[sI] << endl;
126  sens_[sI].calculateSensitivities(designVars);
127  }
128  write(type());
129 
130  return derivatives_;
131 }
132 
133 
135 {
137  {
138  sens_[sI].clearSensitivities();
139  }
140 }
141 
142 
143 void sensitivityMultiple::write(const word& baseName)
144 {
145  forAll(sens_, sI)
146  {
147  sens_[sI].write(sensTypes_[sI]);
148  }
149 }
150 
151 
152 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153 
154 } // End namespace Foam
155 
156 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
virtual void assembleSensitivities(autoPtr< designVariables > &designVars)
Assemble sensitivities.
dictionary dict
virtual void clearSensitivities()
Zero sensitivity fields and their constituents.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual void write(const word &baseName=word::null)
Write sensitivities to file.
Abstract base class for adjoint-based sensitivities.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Base class for adjoint solvers.
Definition: adjointSolver.H:53
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
const fvMesh & mesh() const
Return reference to mesh.
Definition: sensitivity.H:121
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
static autoPtr< adjointSensitivity > New(const fvMesh &mesh, const dictionary &dict, adjointSolver &adjointSolver)
Return a reference to the selected turbulence model.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
dynamicFvMesh & mesh
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Calculation of adjoint based sensitivities of multiple types.
virtual void accumulateIntegrand(const scalar dt)
Accumulate sensitivity integrands.
defineTypeNameAndDebug(combustionModel, 0)
virtual bool readDict(const dictionary &dict)
Read dict if changed.
const dictionary & dict() const
Return the construction dictionary.
Definition: sensitivity.H:129
virtual bool readDict(const dictionary &dict)
Read dictionary if changed.
scalarField derivatives_
The sensitivity derivative values.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const scalarField & calculateSensitivities(autoPtr< designVariables > &designVars)
Calculates sensitivities at wall surface points.
messageStream Info
Information stream (stdout output on master, null elsewhere)
PtrList< adjointSensitivity > sens_
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)