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-2021 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 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
42 
44 (
45  const dictionary& dict
46 )
47 {
48  return dict.optionalSubDict("options", keyType::LITERAL);
49 }
50 
51 
52 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
53 
55 {
56  checkTimeIndex_ = mesh_.time().timeIndex() + 2;
57 
58  bool allOk = true;
59  for (fa::option& opt : *this)
60  {
61  bool ok = opt.read(dict.subDict(opt.name()));
62  allOk = (allOk && ok);
63  }
64  return allOk;
65 }
66 
67 
69 {
70  if (mesh_.time().timeIndex() == checkTimeIndex_)
71  {
72  for (const fa::option& opt : *this)
73  {
74  opt.checkApplied();
75  }
76  }
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
83 (
84  const fvPatch& p,
85  const dictionary& dict
86 )
87 :
88  PtrList<fa::option>(),
89  mesh_(p.boundaryMesh().mesh()),
90  patch_(p),
91  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
92 {
93  reset(optionsDict(dict));
94 }
95 
96 
98 :
99  PtrList<fa::option>(),
100  mesh_(p.boundaryMesh().mesh()),
101  patch_(p),
102  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
107 
109 {
110  // Count number of active faOptions
111  label count = 0;
112  for (const entry& dEntry : dict)
113  {
114  if (dEntry.isDict())
115  {
116  ++count;
117  }
118  }
119 
120  this->resize(count);
121 
122  count = 0;
123  for (const entry& dEntry : dict)
124  {
125  if (dEntry.isDict())
126  {
127  const word& name = dEntry.keyword();
128  const dictionary& sourceDict = dEntry.dict();
129 
130  this->set
131  (
132  count++,
133  option::New(name, sourceDict, patch_)
134  );
135  }
136  }
137 }
138 
139 
140 bool Foam::fa::optionList::appliesToField(const word& fieldName) const
141 {
142  for (const fa::option& source : *this)
143  {
144  const label fieldi = source.applyToField(fieldName);
145 
146  if (fieldi != -1)
147  {
148  return true;
149  }
150  }
151 
152  return false;
153 }
154 
155 
157 {
158  return readOptions(optionsDict(dict));
159 }
160 
161 
163 {
164  // Write list contents
165  for (const fa::option& opt : *this)
166  {
167  os << nl;
168  opt.writeHeader(os);
169  opt.writeData(os);
170  opt.writeFooter(os);
171  }
172 
173  // Check state of IOstream
174  return os.good();
175 }
176 
177 
178 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
179 
180 Foam::Ostream& Foam::operator<<(Ostream& os, const fa::optionList& options)
181 {
182  options.writeData(os);
183  return os;
184 }
185 
186 
187 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:63
Foam::fa::option::writeFooter
virtual void writeFooter(Ostream &) const
Definition: faOptionIO.C:31
Foam::fa::optionList::checkTimeIndex_
label checkTimeIndex_
Definition: faOptionList.H:74
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::fa::optionList::optionsDict
static const dictionary & optionsDict(const dictionary &dict)
Definition: faOptionList.C:37
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Definition: BitOps.C:30
Foam::fa::option::name
const word & name() const noexcept
Definition: faOptionI.H:23
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
faOptionList.H
Foam::fa::option::checkApplied
virtual void checkApplied() const
Definition: faOption.C:124
Foam::fa::optionList
List of finite volume options.
Definition: faOptionList.H:59
Foam::fa::option::New
static autoPtr< option > New(const word &name, const dictionary &dict, const fvPatch &patch)
Definition: faOption.C:76
Foam::fa::defineTypeNameAndDebug
defineTypeNameAndDebug(limitVelocity, 0)
Foam::fa::optionList::readOptions
bool readOptions(const dictionary &dict)
Definition: faOptionList.C:47
Foam::fa::option::applyToField
virtual label applyToField(const word &fieldName) const
Definition: faOption.C:118
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Definition: boundaryPatch.C:76
Foam::TimeState::timeIndex
label timeIndex() const noexcept
Definition: TimeStateI.H:30
Foam::fa::option::writeData
virtual void writeData(Ostream &) const
Definition: faOptionIO.C:37
resize
patchWriters resize(patchIds.size())
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Foam::PtrList< fa::option >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fa::option::writeHeader
virtual void writeHeader(Ostream &) const
Definition: faOptionIO.C:25
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fa::optionList::optionList
optionList(const optionList &)=delete
Foam
Definition: atmBoundaryLayer.C:26
Foam::fa::optionList::appliesToField
bool appliesToField(const word &fieldName) const
Definition: faOptionList.C:133
Foam::fa::option::read
virtual bool read(const dictionary &dict)
Definition: faOptionIO.C:47
reset
meshPtr reset(new Foam::fvMesh(Foam::IOobject(regionName, runTime.timeName(), runTime, Foam::IOobject::MUST_READ), false))
Foam::fa::optionList::reset
void reset(const dictionary &dict)
Definition: faOptionList.C:101
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Definition: BitOps.H:75
Foam::fa::option
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:129
Foam::fa::optionList::read
virtual bool read(const dictionary &dict)
Definition: faOptionList.C:149
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::fvMesh::time
const Time & time() const
Definition: fvMesh.H:276
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:58
Foam::fa::optionList::mesh_
const fvMesh & mesh_
Definition: faOptionList.H:68
Foam::keyType::LITERAL
@ LITERAL
String literal.
Definition: keyType.H:79
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::fa::optionList::checkApplied
void checkApplied() const
Definition: faOptionList.C:61
Foam::fa::optionList::writeData
virtual bool writeData(Ostream &os) const
Definition: faOptionList.C:155