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 {
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 :
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 
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:67
Foam::fa::option::writeFooter
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: faOptionIO.C:38
Foam::fa::optionList::checkTimeIndex_
label checkTimeIndex_
Time index to check that all defined sources have been applied.
Definition: faOptionList.H:80
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::fa::optionList::optionsDict
static const dictionary & optionsDict(const dictionary &dict)
Return "options" sub-dictionary (if present) or return dict.
Definition: faOptionList.C:44
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::fa::option::name
const word & name() const noexcept
Return const access to the source name.
Definition: faOptionI.H:30
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
faOptionList.H
Foam::fa::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: faOption.C:131
Foam::fa::optionList
List of finite volume options.
Definition: faOptionList.H:65
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:83
Foam::fa::defineTypeNameAndDebug
defineTypeNameAndDebug(limitVelocity, 0)
Foam::fa::optionList::readOptions
bool readOptions(const dictionary &dict)
Read options dictionary.
Definition: faOptionList.C:54
Foam::fa::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: faOption.C:125
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::TimeState::timeIndex
label timeIndex() const noexcept
Return current time index.
Definition: TimeStateI.H:37
Foam::fa::option::writeData
virtual void writeData(Ostream &) const
Write the source properties.
Definition: faOptionIO.C:44
resize
patchWriters resize(patchIds.size())
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
Foam::PtrList< fa::option >
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::fa::option::writeHeader
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: faOptionIO.C:32
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
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::optionList::appliesToField
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
Definition: faOptionList.C:140
Foam::fa::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:54
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)
Reset the source list.
Definition: faOptionList.C:108
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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:133
Foam::fa::optionList::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: faOptionList.C:156
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
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:74
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:68
Foam::fa::optionList::writeData
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: faOptionList.C:162