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-------------------------------------------------------------------------------
11License
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
34namespace Foam
35{
36namespace fv
37{
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{
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
136bool 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// ************************************************************************* //
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
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
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
List of finite volume options.
Definition: fvOptionList.H:72
void reset(const dictionary &dict)
Reset the source list.
Definition: fvOptionList.C:104
virtual bool writeData(Ostream &os) const
Write data to Ostream.
Definition: fvOptionList.C:158
void checkApplied() const
Check that all sources have been applied.
Definition: fvOptionList.C:70
bool readOptions(const dictionary &dict)
Read options dictionary.
Definition: fvOptionList.C:56
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
Definition: fvOptionList.C:136
static const dictionary & optionsDict(const dictionary &dict)
Return "options" sub-dictionary (if present) or return dict.
Definition: fvOptionList.C:46
Base abstract class for handling finite volume options (i.e. fvOption).
Definition: fvOption.H:127
const word & name() const noexcept
Return const access to the source name.
Definition: fvOptionI.H:31
virtual void checkApplied() const
Check that the source has been applied.
Definition: fvOption.C:131
virtual label applyToField(const word &fieldName) const
Return index of field name if found in fieldNames list.
Definition: fvOption.C:125
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition: fvOptionIO.C:55
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition: fvOptionIO.C:33
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition: fvOptionIO.C:39
virtual void writeData(Ostream &) const
Write the source properties.
Definition: fvOptionIO.C:45
@ 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
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
labelList fv(nPoints)
dictionary dict
Foam::surfaceFields.