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------------------------------------------------------------------------------
10License
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
32namespace Foam
33{
34namespace fa
35{
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 const fvPatch& p,
85 const dictionary& dict
86)
87:
88 PtrList<fa::option>(),
89 mesh_(p.boundaryMesh().mesh()),
90 patch_(p),
91 checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
92{
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
140bool 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// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: PtrList.H:73
virtual bool read()
Re-read model coefficients if they have changed.
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:577
void reset()
Reset to defaults.
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
List of finite volume options.
Definition: faOptionList.H:70
void reset(const dictionary &dict)
Reset the source list.
Definition: faOptionList.C:108
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: faOptionList.C:162
void checkApplied() const
Check that all sources have been applied.
Definition: faOptionList.C:68
bool readOptions(const dictionary &dict)
Read options dictionary.
Definition: faOptionList.C:54
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
Definition: faOptionList.C:140
static const dictionary & optionsDict(const dictionary &dict)
Return "options" sub-dictionary (if present) or return dict.
Definition: faOptionList.C:44
Base abstract class for handling finite area options (i.e. faOption).
Definition: faOption.H:134
const word & name() const noexcept
Return const access to the source name.
Definition: faOptionI.H:30
virtual void checkApplied() const
Check that the source has been applied.
Definition: faOption.C:132
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: faOption.C:126
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: faOptionIO.C:54
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: faOptionIO.C:32
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: faOptionIO.C:38
virtual void writeData(Ostream &) const
Write the source properties.
Definition: faOptionIO.C:44
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
@ LITERAL
String literal.
Definition: keyType.H:81
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
volScalarField & p
patchWriters resize(patchIds.size())
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict