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-2022 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  PtrList<fa::option>(),
85  mesh_(mesh),
86  checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
87 {}
88 
89 
91 :
92  Foam::fa::optionList(mesh)
93 {
94  reset(optionsDict(dict));
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 {
102  // Count number of active faOptions
103  label count = 0;
104  for (const entry& dEntry : dict)
105  {
106  if (dEntry.isDict())
107  {
108  ++count;
109  }
110  }
111 
112  this->resize(count);
113 
114  count = 0;
115  for (const entry& dEntry : dict)
116  {
117  if (dEntry.isDict())
118  {
119  const word& name = dEntry.keyword();
120  const dictionary& sourceDict = dEntry.dict();
121 
122  this->set
123  (
124  count++,
125  option::New(name, sourceDict, mesh_)
126  );
127  }
128  }
129 }
130 
131 
132 bool Foam::fa::optionList::appliesToField(const word& fieldName) const
133 {
134  for (const fa::option& source : *this)
135  {
136  const label fieldi = source.applyToField(fieldName);
137 
138  if (fieldi != -1)
139  {
140  return true;
141  }
142  }
143 
144  return false;
145 }
146 
149 {
150  return readOptions(optionsDict(dict));
151 }
152 
153 
155 {
156  // Write list contents
157  for (const fa::option& opt : *this)
158  {
159  os << nl;
160  opt.writeHeader(os);
161  opt.writeData(os);
162  opt.writeFooter(os);
163  }
164 
165  // Check state of IOstream
166  return os.good();
167 }
168 
169 
170 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
171 
172 Foam::Ostream& Foam::operator<<(Ostream& os, const fa::optionList& options)
173 {
174  options.writeData(os);
175  return os;
176 }
177 
178 
179 // ************************************************************************* //
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
void reset(const dictionary &dict)
Reset the source list.
Definition: faOptionList.C:93
List of finite volume options.
Definition: faOptionList.H:61
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
Definition: faOptionList.C:125
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
static const dictionary & optionsDict(const dictionary &dict)
Return "options" sub-dictionary (if present) or return dict.
Definition: faOptionList.C:37
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:129
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual void checkApplied() const
Check that the source has been applied.
Definition: faOption.C:124
defineTypeNameAndDebug(limitHeight, 0)
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: faOptionIO.C:31
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:47
String literal.
Definition: keyType.H:82
const word & name() const noexcept
Return const access to the source name.
Definition: faOptionI.H:23
optionList(const optionList &)=delete
No copy construct.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected faOption model.
Definition: faOption.C:75
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: faOptionIO.C:25
virtual void writeData(Ostream &) const
Write the source properties.
Definition: faOptionIO.C:37
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 bool writeData(Ostream &os) const
Write data to Ostream.
Definition: faOptionList.C:147
virtual bool read(const dictionary &dict)
Read dictionary.
Definition: faOptionList.C:141
bool readOptions(const dictionary &dict)
Read options dictionary.
Definition: faOptionList.C:47
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
void checkApplied() const
Check that all sources have been applied.
Definition: faOptionList.C:61