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 -------------------------------------------------------------------------------
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 "fvOptionList.H"
29 #include "surfaceFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace fv
36 {
37  defineTypeNameAndDebug(optionList, 0);
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43 
45 (
46  const dictionary& dict
47 ) const
48 {
49  if (dict.found("options"))
50  {
51  return dict.subDict("options");
52  }
53  else
54  {
55  return dict;
56  }
57 }
58 
59 
61 {
63 
64  bool allOk = true;
65  forAll(*this, i)
66  {
67  option& bs = this->operator[](i);
68  bool ok = bs.read(dict.subDict(bs.name()));
69  allOk = (allOk && ok);
70  }
71  return allOk;
72 }
73 
74 
76 {
77  if (mesh_.time().timeIndex() == checkTimeIndex_)
78  {
79  forAll(*this, i)
80  {
81  const option& bs = this->operator[](i);
82  bs.checkApplied();
83  }
84  }
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 
91 :
92  PtrList<option>(),
93  mesh_(mesh),
94  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
95 {
97 }
98 
99 
101 :
102  PtrList<option>(),
103  mesh_(mesh),
104  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
105 {}
106 
107 
108 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
109 
111 {
112  // Count number of active fvOptions
113  label count = 0;
114  for (const entry& dEntry : dict)
115  {
116  if (dEntry.isDict())
117  {
118  ++count;
119  }
120  }
121 
122  this->resize(count);
123 
124  count = 0;
125  for (const entry& dEntry : dict)
126  {
127  if (dEntry.isDict())
128  {
129  const word& name = dEntry.keyword();
130  const dictionary& sourceDict = dEntry.dict();
131 
132  this->set
133  (
134  count++,
135  option::New(name, sourceDict, mesh_)
136  );
137  }
138  }
139 }
140 
141 
142 bool Foam::fv::optionList::appliesToField(const word& fieldName) const
143 {
144  forAll(*this, i)
145  {
146  const option& source = this->operator[](i);
147 
148  label fieldi = source.applyToField(fieldName);
149 
150  if (fieldi != -1)
151  {
152  return true;
153  }
154  }
155 
156  return false;
157 }
158 
159 
161 {
162  return readOptions(optionsDict(dict));
163 }
164 
165 
167 {
168  // Write list contents
169  forAll(*this, i)
170  {
171  os << nl;
172  this->operator[](i).writeHeader(os);
173  this->operator[](i).writeData(os);
174  this->operator[](i).writeFooter(os);
175  }
176 
177  // Check state of IOstream
178  return os.good();
179 }
180 
181 
182 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
183 
185 {
186  options.writeData(os);
187  return os;
188 }
189 
190 
191 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::fv::optionList::appliesToField
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
Definition: fvOptionList.C:142
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::fv::optionList::optionsDict
const dictionary & optionsDict(const dictionary &dict) const
Return the "options" sub-dictionary if present otherwise return dict.
Definition: fvOptionList.C:45
Foam::fv::option::name
const word & name() const
Return const access to the source name.
Definition: fvOptionI.H:30
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:122
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:110
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
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::fv::option::applyToField
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:116
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::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:60
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::fv::optionList::checkApplied
void checkApplied() const
Check that all sources have been applied.
Definition: fvOptionList.C:75
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
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:83
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:73
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: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::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:275
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::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::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:160
Foam::fv::optionList::writeData
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: fvOptionList.C:166