Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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"
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)
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
86 PtrList<fv::option>(),
87 mesh_(mesh),
88 checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
89{}
90
91
93:
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
134bool 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;
144 }
145
146 return false;
147}
148
151{
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
174Foam::Ostream& Foam::operator<<(Ostream& os, const fv::optionList& options)
175{
176 options.writeData(os);
177 return os;
178}
179
180
181// ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
const fv::option * set(const label i) const
Definition PtrList.H:171
constexpr PtrList() noexcept
Definition PtrListI.H:29
label count() const noexcept
Definition UPtrList.H:890
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
List of finite volume options.
void reset(const dictionary &dict)
Reset the source list.
const fvMesh & mesh_
Reference to the mesh database.
virtual bool writeData(Ostream &os) const
Write data to Ostream.
void checkApplied() const
Check that all sources have been applied.
bool readOptions(const dictionary &dict)
Read options dictionary.
virtual bool read(const dictionary &dict)
Read dictionary.
label checkTimeIndex_
Time index to check that all defined sources have been applied.
optionList(const optionList &)=delete
No copy construct.
tmp< fvMatrix< Type > > source(GeometricField< Type, fvPatchField, volMesh > &field, const word &fieldName, const dimensionSet &ds)
Return source for equation with specified name and dimensions.
bool appliesToField(const word &fieldName) const
Return whether there is something to apply to the field.
static const dictionary & optionsDict(const dictionary &dict)
Return "options" sub-dictionary (if present) or return dict.
Base abstract class for handling finite volume options (i.e. fvOption).
Definition fvOption.H:124
const word & name() const noexcept
Return const access to the source name.
Definition fvOptionI.H:24
static autoPtr< option > New(const word &name, const dictionary &dict, const fvMesh &mesh)
Return a reference to the selected fvOption model.
Definition fvOption.C:78
virtual void checkApplied() const
Check that the source has been applied.
Definition fvOption.C:127
virtual bool read(const dictionary &dict)
Read source dictionary.
Definition fvOptionIO.C:48
virtual void writeHeader(Ostream &) const
Write the source header information.
Definition fvOptionIO.C:26
virtual void writeFooter(Ostream &) const
Write the source footer information.
Definition fvOptionIO.C:32
virtual void writeData(Ostream &) const
Write the source properties.
Definition fvOptionIO.C:38
@ LITERAL
String literal.
Definition keyType.H:82
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
patchWriters resize(patchIds.size())
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
auto & name
Namespace for finite-volume.
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
Foam::surfaceFields.