faOptionList.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) 2019-2020 OpenCFD Ltd.
9 ------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "faOptionList.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace fa
35 {
36  defineTypeNameAndDebug(optionList, 0);
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
42 
44 (
45  const dictionary& dict
46 ) const
47 {
48  if (dict.found("options"))
49  {
50  return dict.subDict("options");
51  }
52  else
53  {
54  return dict;
55  }
56 }
57 
58 
60 {
62 
63  bool allOk = true;
64  forAll(*this, i)
65  {
66  option& bs = this->operator[](i);
67  bool ok = bs.read(dict.subDict(bs.name()));
68  allOk = (allOk && ok);
69  }
70  return allOk;
71 }
72 
73 
75 {
76  if (mesh_.time().timeIndex() == checkTimeIndex_)
77  {
78  forAll(*this, i)
79  {
80  const option& bs = this->operator[](i);
81  bs.checkApplied();
82  }
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 (
91  const fvPatch& p,
92  const dictionary& dict
93 )
94 :
96  mesh_(p.boundaryMesh().mesh()),
97  patch_(p),
98  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
99 {
100  reset(optionsDict(dict));
101 }
102 
103 
105 :
106  PtrList<option>(),
107  mesh_(p.boundaryMesh().mesh()),
108  patch_(p),
109  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 {
117  // Count number of active faOptions
118  label count = 0;
119  for (const entry& dEntry : dict)
120  {
121  if (dEntry.isDict())
122  {
123  ++count;
124  }
125  }
126 
127  this->resize(count);
128 
129  count = 0;
130  for (const entry& dEntry : dict)
131  {
132  if (dEntry.isDict())
133  {
134  const word& name = dEntry.keyword();
135  const dictionary& sourceDict = dEntry.dict();
136 
137  this->set
138  (
139  count++,
140  option::New(name, sourceDict, patch_)
141  );
142  }
143  }
144 }
145 
146 
148 {
149  return readOptions(optionsDict(dict));
150 }
151 
152 
154 {
155  // Write list contents
156  forAll(*this, i)
157  {
158  os << nl;
159  this->operator[](i).writeHeader(os);
160  this->operator[](i).writeData(os);
161  this->operator[](i).writeFooter(os);
162  }
163 
164  // Check state of IOstream
165  return os.good();
166 }
167 
168 
169 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
170 
172 {
173  options.writeData(os);
174  return os;
175 }
176 
177 
178 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::fa::optionList::checkTimeIndex_
label checkTimeIndex_
Time index to check that all defined sources have been applied.
Definition: faOptionList.H:81
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fa::option::name
const word & name() const
Return const access to the source name.
Definition: faOptionI.H:30
faOptionList.H
Foam::fa::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: faOption.C:134
Foam::fa::optionList
List of finite volume options.
Definition: faOptionList.H:66
Foam::fa::option::New
static autoPtr< option > New(const word &name, const dictionary &dict, const fvPatch &patch)
Return a reference to the selected faOption model.
Definition: faOption.C:86
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fa::optionList::readOptions
bool readOptions(const dictionary &dict)
Read options dictionary.
Definition: faOptionList.C:59
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
resize
patchWriters resize(patchIds.size())
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::PtrList< option >
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::fa::optionList::optionList
optionList(const optionList &)=delete
No copy construct.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fa::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:54
Foam::fa::optionList::reset
void reset(const dictionary &dict)
Reset the source list.
Definition: faOptionList.C:115
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::fa::option
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:134
Foam::fa::defineTypeNameAndDebug
defineTypeNameAndDebug(faceSetOption, 0)
Foam::fa::optionList::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: faOptionList.C:147
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:275
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:62
Foam::fa::optionList::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: faOptionList.H:75
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::fa::optionList::checkApplied
void checkApplied() const
Check that all sources have been applied.
Definition: faOptionList.C:74
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:224
Foam::fa::optionList::writeData
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: faOptionList.C:153
Foam::fa::optionList::optionsDict
const dictionary & optionsDict(const dictionary &dict) const
Return the "options" sub-dictionary if present otherwise return dict.
Definition: faOptionList.C:44