fvOptionList.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) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "fvOptionList.H"
30 #include "surfaceFields.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace fv
37 {
38  defineTypeNameAndDebug(optionList, 0);
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
44 
46 (
47  const dictionary& dict
48 )
49 {
50  return dict.optionalSubDict("options", keyType::LITERAL);
51 }
52 
53 
54 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
55 
57 {
59 
60  bool allOk = true;
61  for (fv::option& opt : *this)
62  {
63  bool ok = opt.read(dict.subDict(opt.name()));
64  allOk = (allOk && ok);
65  }
66  return allOk;
67 }
68 
69 
71 {
72  if (mesh_.time().timeIndex() == checkTimeIndex_)
73  {
74  for (const fv::option& opt : *this)
75  {
76  opt.checkApplied();
77  }
78  }
79 }
80 
81 
82 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
83 
85 :
86  PtrList<fv::option>(),
87  mesh_(mesh),
88  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
89 {
91 }
92 
93 
95 :
96  PtrList<fv::option>(),
97  mesh_(mesh),
98  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
99 {}
100 
101 
102 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
103 
105 {
106  // Count number of active fvOptions
107  label count = 0;
108  for (const entry& dEntry : dict)
109  {
110  if (dEntry.isDict())
111  {
112  ++count;
113  }
114  }
115 
116  this->resize(count);
117 
118  count = 0;
119  for (const entry& dEntry : dict)
120  {
121  if (dEntry.isDict())
122  {
123  const word& name = dEntry.keyword();
124  const dictionary& sourceDict = dEntry.dict();
125 
126  this->set
127  (
128  count++,
129  option::New(name, sourceDict, mesh_)
130  );
131  }
132  }
133 }
134 
135 
136 bool Foam::fv::optionList::appliesToField(const word& fieldName) const
137 {
138  for (const fv::option& source : *this)
139  {
140  const label fieldi = source.applyToField(fieldName);
141 
142  if (fieldi != -1)
143  {
144  return true;
145  }
146  }
147 
148  return false;
149 }
150 
151 
153 {
154  return readOptions(optionsDict(dict));
155 }
156 
157 
159 {
160  // Write list contents
161  for (const fv::option& opt : *this)
162  {
163  os << nl;
164  opt.writeHeader(os);
165  opt.writeData(os);
166  opt.writeFooter(os);
167  }
168 
169  // Check state of IOstream
170  return os.good();
171 }
172 
173 
174 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
175 
177 {
178  options.writeData(os);
179  return os;
180 }
181 
182 
183 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::fv::option::name
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:31
Foam::fv::optionList::appliesToField
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
Definition: fvOptionList.C:136
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:65
Foam::fv::optionList::optionList
optionList(const optionList &)=delete
No copy construct.
Foam::fv::option::checkApplied
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:131
Foam::fv::optionList::mesh_
const fvMesh & mesh_
Reference to the mesh database.
Definition: fvOptionList.H:78
Foam::fv::optionList::reset
void reset(const dictionary &dict)
Reset the source list.
Definition: fvOptionList.C:104
surfaceFields.H
Foam::surfaceFields.
Foam::fv::optionList::checkTimeIndex_
label checkTimeIndex_
Time index to check that all defined sources have been applied.
Definition: fvOptionList.H:81
Foam::fv::option::writeData
virtual void writeData(Ostream &) const
Write the source properties.
Definition: fvOptionIO.C:45
Foam::fv::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.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
resize
patchWriters resize(patchIds.size())
Foam::fv::option
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:126
fvOptionList.H
Foam::fv::optionList::readOptions
bool readOptions(const dictionary &dict)
Read options dictionary.
Definition: fvOptionList.C:56
Foam::fv::optionList::checkApplied
void checkApplied() const
Check that all sources have been applied.
Definition: fvOptionList.C:70
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:59
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:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fv::option::writeHeader
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: fvOptionIO.C:33
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::fv::option::New
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected fvOption model.
Definition: fvOption.C:82
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::fv::option::read
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:55
fv
labelList fv(nPoints)
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::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::fv::defineTypeNameAndDebug
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::fv::optionList
List of finite volume options.
Definition: fvOptionList.H:69
Foam::fv::optionList::read
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fvOptionList.C:152
Foam::fv::optionList::optionsDict
static const dictionary & optionsDict(const dictionary &dict)
Return "options" sub-dictionary (if present) or return dict.
Definition: fvOptionList.C:46
Foam::fv::option::writeFooter
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: fvOptionIO.C:39
Foam::fv::optionList::writeData
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: fvOptionList.C:158