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-2022 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 {
58  checkTimeIndex_ = mesh_.time().timeIndex() + 2;
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 {}
90 
91 
93 :
95 {
96  reset(optionsDict(dict));
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 {
104  // Count number of active fvOptions
105  label count = 0;
106  for (const entry& dEntry : dict)
107  {
108  if (dEntry.isDict())
109  {
110  ++count;
111  }
112  }
113 
114  this->resize(count);
115 
116  count = 0;
117  for (const entry& dEntry : dict)
118  {
119  if (dEntry.isDict())
120  {
121  const word& name = dEntry.keyword();
122  const dictionary& sourceDict = dEntry.dict();
123 
124  this->set
125  (
126  count++,
127  option::New(name, sourceDict, mesh_)
128  );
129  }
130  }
131 }
132 
133 
134 bool Foam::fv::optionList::appliesToField(const word& fieldName) const
135 {
136  for (const fv::option& source : *this)
137  {
138  const label fieldi = source.applyToField(fieldName);
139 
140  if (fieldi != -1)
141  {
142  return true;
143  }
144  }
145 
146  return false;
147 }
148 
151 {
152  return readOptions(optionsDict(dict));
153 }
154 
155 
157 {
158  // Write list contents
159  for (const fv::option& opt : *this)
160  {
161  os << nl;
162  opt.writeHeader(os);
163  opt.writeData(os);
164  opt.writeFooter(os);
165  }
166 
167  // Check state of IOstream
168  return os.good();
169 }
170 
171 
172 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
173 
174 Foam::Ostream& Foam::operator<<(Ostream& os, const fv::optionList& options)
175 {
176  options.writeData(os);
177  return os;
178 }
179 
180 
181 // ************************************************************************* //
Foam::surfaceFields.
bool readOptions(const dictionary &dict)
Read options dictionary.
Definition: fvOptionList.C:49
dictionary dict
patchWriters resize(patchIds.size())
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
defineTypeNameAndDebug(atmAmbientTurbSource, 0)
optionList(const optionList &)=delete
No copy construct.
static const dictionary & optionsDict(const dictionary &dict)
Return "options" sub-dictionary (if present) or return dict.
Definition: fvOptionList.C:39
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected fvOption model.
Definition: fvOption.C:75
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
labelList fv(nPoints)
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: fvOptionIO.C:32
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:124
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:48
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:24
String literal.
Definition: keyType.H:82
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
Definition: fvOptionList.C:127
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
void reset(const dictionary &dict)
Reset the source list.
Definition: fvOptionList.C:95
void checkApplied() const
Check that all sources have been applied.
Definition: fvOptionList.C:63
OBJstream os(runTime.globalPath()/outputName)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual void writeData(Ostream &) const
Write the source properties.
Definition: fvOptionIO.C:38
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: fvOptionIO.C:26
List of finite volume options.
Definition: fvOptionList.H:63
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: fvOptionList.C:149
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:123
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: fvOptionList.C:143