fvOptionAdjointList.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-2019 PCOpt/NTUA
9  Copyright (C) 2013-2019 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 "fvOptionAdjointList.H"
31 #include "surfaceFields.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace fv
38 {
39  defineTypeNameAndDebug(optionAdjointList, 0);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45 
47 (
48  const dictionary& dict
49 ) const
50 {
51  if (dict.found("optionAdjoints"))
52  {
53  return dict.subDict("optionAdjoints");
54  }
55  else
56  {
57  return dict;
58  }
59 }
60 
61 
63 {
65 
66  bool allOk = true;
67  forAll(*this, i)
68  {
69  optionAdjoint& bs = this->operator[](i);
70  bool ok = bs.read(dict.subDict(bs.name()));
71  allOk = (allOk && ok);
72  }
73  return allOk;
74 }
75 
76 
78 {
79  if (mesh_.time().timeIndex() == checkTimeIndex_)
80  {
81  forAll(*this, i)
82  {
83  const optionAdjoint& bs = this->operator[](i);
84  bs.checkApplied();
85  }
86  }
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
91 
92 Foam::fv::optionAdjointList::optionAdjointList
93 (
94  const fvMesh& mesh,
95  const dictionary& dict
96 )
97 :
99  mesh_(mesh),
100  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
101 {
102  reset(optionAdjointsDict(dict));
103 }
104 
105 
106 Foam::fv::optionAdjointList::optionAdjointList(const fvMesh& mesh)
107 :
109  mesh_(mesh),
110  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
111 {}
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
117 {
118  label count = 0;
120  {
121  // safety:
122  if (iter().isDict())
123  {
124  count++;
125  }
126  }
127 
128  this->setSize(count);
129  label i = 0;
131  {
132  if (iter().isDict())
133  {
134  const word& name = iter().keyword();
135  const dictionary& sourceDict = iter().dict();
136 
137  this->set
138  (
139  i++,
140  optionAdjoint::New(name, sourceDict, mesh_)
141  );
142  }
143  }
144 }
145 
146 
148 {
149  return readOptionAdjoints(optionAdjointsDict(dict));
150 }
151 
152 
154 {
155  // Write list contents
156  forAll(*this, i)
157  {
158  os << nl;
159  this->operator[](i).writeData(os);
160  }
161 
162  // Check state of IOstream
163  return os.good();
164 }
165 
166 
167 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
168 
169 namespace Foam
170 {
171  Ostream& operator<<
172  (
173  Ostream& os,
174  const fv::optionAdjointList& optionAdjoints
175  )
176  {
177  optionAdjoints.writeData(os);
178  return os;
179  }
180 }
181 
182 
183 // ************************************************************************* //
setSize
points setSize(newPointi)
Foam::fv::optionAdjointList::optionAdjointsDict
const dictionary & optionAdjointsDict(const dictionary &dict) const
Definition: fvOptionAdjointList.C:47
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fv::option::name
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:30
Foam::fv::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:120
Foam::fv::optionAdjointList::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOptionAdjointList.H:79
surfaceFields.H
Foam::surfaceFields.
Foam::fv::optionAdjointList
Definition: fvOptionAdjointList.H:59
fvOptionAdjointList.H
forAllConstIter
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object.
Definition: stdFoam.H:338
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fv::optionAdjointList::checkApplied
void checkApplied() const
Check that all sources have been applied.
Definition: fvOptionAdjointList.C:77
Foam::fv::optionAdjoint
Similar to fv::option but with additional functionality to contribute to the sensitivity deriavtives.
Definition: fvOptionAdjoint.H:58
Foam::PtrList< optionAdjoint >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:84
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fv::optionAdjointList::readOptionAdjoints
bool readOptionAdjoints(const dictionary &dict)
Read optionAdjoints dictionary.
Definition: fvOptionAdjointList.C:62
Foam::fv::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:55
fv
labelList fv(nPoints)
Foam::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(option, 0)
Foam::fv::optionAdjointList::reset
void reset(const dictionary &dict)
Reset the source list.
Definition: fvOptionAdjointList.C:116
Foam::fv::optionAdjoint::New
static autoPtr< optionAdjoint > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected fvOption model.
Definition: fvOptionAdjoint.C:61
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:246
Foam::fv::optionAdjointList::writeData
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: fvOptionAdjointList.C:153
Foam::fv::optionAdjointList::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fvOptionAdjointList.C:147
Foam::fv::optionAdjointList::checkTimeIndex_
label checkTimeIndex_
Time index to check that all defined sources have been applied.
Definition: fvOptionAdjointList.H:82
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::TimeState::timeIndex
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:36
Foam::IOstream::good
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:216