GeometricFieldSources.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "GeometricFieldSources.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type, class GeoMesh>
32 :
34  errorLocation_()
35 {}
36 
37 
38 template<class Type, class GeoMesh>
40 (
42  const HashPtrTable<Source>& mtf
43 )
44 :
45  HashPtrTable<Source>(mtf.capacity()),
46  errorLocation_()
47 {
48  forAllConstIter(typename HashPtrTable<Source>, mtf, iter)
49  {
50  this->set(iter.key(), iter()->clone(iF).ptr());
51  }
52 }
53 
54 
55 template<class Type, class GeoMesh>
57 (
58  const DimensionedField<Type, GeoMesh>& iF,
59  const GeometricFieldSources<Type, GeoMesh>& mtf
60 )
61 :
62  GeometricFieldSources(iF, static_cast<const HashPtrTable<Source>&>(mtf))
63 {}
64 
65 
66 template<class Type, class GeoMesh>
68 (
69  const DimensionedField<Type, GeoMesh>& iF,
70  const dictionary& dict
71 )
72 :
73  HashPtrTable<Source>(),
74  errorLocation_()
75 {
76  readField(iF, dict);
77 }
78 
79 
80 template<class Type, class GeoMesh>
82 (
83  const DimensionedField<Type, GeoMesh>& iF,
84  const HashTable<word>& types
85 )
86 :
87  HashPtrTable<Source>(),
88  errorLocation_()
89 {
90  forAllConstIter(typename HashTable<word>, types, iter)
91  {
92  this->set
93  (
94  iter.key(),
95  Source::New(iter(), iF).ptr()
96  );
97  }
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
102 
103 template<class Type, class GeoMesh>
106 {}
107 
108 
109 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
110 
111 template<class Type, class GeoMesh>
112 const Foam::HashPtrTable
113 <
115 >&
117 {
118  return *this;
119 }
120 
121 
122 template<class Type, class GeoMesh>
124 <
126 >&
128 {
129  return *this;
130 }
131 
132 
133 template<class Type, class GeoMesh>
136 {
137  HashTable<word> result;
138 
139  forAllConstIter(typename HashPtrTable<Source>, *this, iter)
140  {
141  result.insert(iter.key(), iter()->type());
142  }
143 
144  return result;
145 }
146 
147 
148 template<class Type, class GeoMesh>
150 (
151  const DimensionedField<Type, GeoMesh>& field,
152  const dictionary& dict
153 )
154 {
155  this->clear();
156 
157  errorLocation_ = IOerrorLocation(dict);
158 
160  {
161  if (iter().isDict())
162  {
163  this->set
164  (
165  iter().keyword(),
166  Source::New(field, iter().dict()).ptr()
167  );
168  }
169  }
170 }
171 
172 
173 template<class Type, class GeoMesh>
175 (
177 )
178 {
179  this->clear();
180 
181  if (mtf.empty()) return;
182 
184  (**mtf.HashPtrTable<Source>::begin()).internalField();
185 
186  errorLocation_ = mtf.errorLocation_;
187 
188  forAllConstIter(typename HashPtrTable<Source>, mtf, iter)
189  {
190  this->set(iter.key(), iter()->clone(iF).ptr());
191  }
192 }
193 
194 
195 template<class Type, class GeoMesh>
197 (
198  const word& keyword,
199  Ostream& os
200 ) const
201 {
202  os << keyword << nl << token::BEGIN_BLOCK << incrIndent << nl;
203 
204  forAllConstIter(typename HashPtrTable<Source>, *this, iter)
205  {
206  os << indent << iter.key() << nl
207  << indent << token::BEGIN_BLOCK << nl
208  << incrIndent << *iter() << decrIndent
209  << indent << token::END_BLOCK << endl;
210  }
211 
212  os << decrIndent << token::END_BLOCK << endl;
213 
214  // Check state of IOstream
215  os.check
216  (
217  "GeometricFieldSources<Type, GeoMesh>::"
218  "writeEntry(const word& keyword, Ostream& os) const"
219  );
220 }
221 
222 
223 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
224 
225 template<class Type, class GeoMesh>
228 (
229  const word& sourceName
230 ) const
231 {
232  typename HashPtrTable<Source>::const_iterator iter = this->find(sourceName);
233 
234  if (iter == this->end())
235  {
236  FatalIOErrorInFunction(errorLocation_)
237  << "Cannot find fieldSource entry for " << sourceName
238  << exit(FatalIOError);
239  }
240 
241  return **iter;
242 }
243 
244 
245 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
246 
247 template<class Type, class GeoMesh>
248 Foam::Ostream& Foam::operator<<
249 (
250  Ostream& os,
252 )
253 {
254  typedef typename GeoMesh::template FieldSource<Type> Source;
255  os << static_cast<const HashPtrTable<Source>&>(bf);
256  return os;
257 }
258 
259 
260 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Part of a geometric field used for setting the values associated with optional sources.
void readField(const Internal &field, const dictionary &dict)
Read the sources.
void writeEntry(const word &keyword, Ostream &os) const
Write sources as dictionary entry.
GeoMesh::template FieldSource< Type > Source
Type of the field source of which this field sources is composed.
HashTable< word > types() const
Return a map from the source name to the field source type.
const HashPtrTable< Source > & table() const
Access the underlying field table.
void reset(const GeometricFieldSources &)
Reset the boundary field contents to the given field.
A HashTable specialisation for hashing pointers.
Definition: HashPtrTable.H:67
An STL-conforming const_iterator.
Definition: HashTable.H:498
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
Definition: HashTableI.H:80
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
@ BEGIN_BLOCK
Definition: token.H:113
@ END_BLOCK
Definition: token.H:114
A class for handling words, derived from string.
Definition: word.H:62
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
tUEqn clear()
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:241
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:234
T clone(const T &t)
Definition: List.H:55
IOerror FatalIOError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
static const char nl
Definition: Ostream.H:266
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict