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-2025 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, template<class> class PrimitiveField>
33 :
35  errorLocation_()
36 {}
37 
38 
39 template<class Type, class GeoMesh, template<class> class PrimitiveField>
42 (
44  const HashPtrTable<Source>& mtf
45 )
46 :
47  HashPtrTable<Source>(mtf.capacity()),
48  errorLocation_()
49 {
50  forAllConstIter(typename HashPtrTable<Source>, mtf, iter)
51  {
52  this->set(iter.key(), iter()->clone(iF).ptr());
53  }
54 }
55 
56 
57 template<class Type, class GeoMesh, template<class> class PrimitiveField>
60 (
63 )
64 :
65  HashPtrTable<Source>(mtf.capacity()),
66  errorLocation_(mtf.errorLocation_)
67 {
68  forAllConstIter(typename HashPtrTable<Source>, mtf, iter)
69  {
70  this->set(iter.key(), iter()->clone(iF).ptr());
71  }
72 }
73 
74 
75 template<class Type, class GeoMesh, template<class> class PrimitiveField>
76 template<template<class> class PrimitiveField2>
79 (
82 )
83 :
84  HashPtrTable<Source>(mtf.capacity()),
85  errorLocation_(mtf.errorLocation_)
86 {
87  forAllConstIter(typename HashPtrTable<Source>, mtf, iter)
88  {
89  this->set(iter.key(), iter()->clone(iF).ptr());
90  }
91 }
92 
93 
94 template<class Type, class GeoMesh, template<class> class PrimitiveField>
97 (
99  const dictionary& dict
100 )
101 :
102  HashPtrTable<Source>(),
103  errorLocation_()
104 {
105  readField(iF, dict);
106 }
107 
108 
109 template<class Type, class GeoMesh, template<class> class PrimitiveField>
112 (
114  const HashTable<word>& types
115 )
116 :
117  HashPtrTable<Source>(),
118  errorLocation_()
119 {
120  forAllConstIter(typename HashTable<word>, types, iter)
121  {
122  this->set
123  (
124  iter.key(),
125  Source::New(iter(), iF).ptr()
126  );
127  }
128 }
129 
130 
131 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 
133 template<class Type, class GeoMesh, template<class> class PrimitiveField>
136 {}
137 
138 
139 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
140 
141 template<class Type, class GeoMesh, template<class> class PrimitiveField>
142 const Foam::HashPtrTable
143 <
145 >&
147 {
148  return *this;
149 }
150 
151 
152 template<class Type, class GeoMesh, template<class> class PrimitiveField>
154 <
156 >&
158 {
159  return *this;
160 }
161 
162 
163 template<class Type, class GeoMesh, template<class> class PrimitiveField>
166 {
167  HashTable<word> result;
168 
169  forAllConstIter(typename HashPtrTable<Source>, *this, iter)
170  {
171  result.insert(iter.key(), iter()->type());
172  }
173 
174  return result;
175 }
176 
177 
178 template<class Type, class GeoMesh, template<class> class PrimitiveField>
180 (
182  const dictionary& dict
183 )
184 {
185  this->clear();
186 
187  errorLocation_ = IOerrorLocation(dict);
188 
190  {
191  if (iter().isDict())
192  {
193  this->set
194  (
195  iter().keyword(),
196  Source::New(field, iter().dict()).ptr()
197  );
198  }
199  }
200 }
201 
202 
203 template<class Type, class GeoMesh, template<class> class PrimitiveField>
205 (
208 )
209 {
210  this->clear();
211 
212  errorLocation_ = mtf.errorLocation_;
213 
214  forAllConstIter(typename HashPtrTable<Source>, mtf, iter)
215  {
216  this->set(iter.key(), iter()->clone(field).ptr());
217  }
218 }
219 
220 
221 template<class Type, class GeoMesh, template<class> class PrimitiveField>
223 (
224  const word& keyword,
225  Ostream& os
226 ) const
227 {
228  os << keyword << nl << token::BEGIN_BLOCK << incrIndent << nl;
229 
230  forAllConstIter(typename HashPtrTable<Source>, *this, iter)
231  {
232  os << indent << iter.key() << nl
233  << indent << token::BEGIN_BLOCK << nl
234  << incrIndent << *iter() << decrIndent
235  << indent << token::END_BLOCK << endl;
236  }
237 
238  os << decrIndent << token::END_BLOCK << endl;
239 
240  // Check state of IOstream
241  os.check
242  (
243  "GeometricFieldSources<Type, GeoMesh, PrimitiveField>::"
244  "writeEntry(const word& keyword, Ostream& os) const"
245  );
246 }
247 
248 
249 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
250 
251 template<class Type, class GeoMesh, template<class> class PrimitiveField>
252 const typename
255 (
256  const word& sourceName
257 ) const
258 {
259  typename HashPtrTable<Source>::const_iterator iter = this->find(sourceName);
260 
261  if (iter == this->end())
262  {
263  FatalIOErrorInFunction(errorLocation_)
264  << "Cannot find fieldSource entry for " << sourceName
265  << exit(FatalIOError);
266  }
267 
268  return **iter;
269 }
270 
271 
272 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
273 
274 template<class Type, class GeoMesh, template<class> class PrimitiveField>
275 Foam::Ostream& Foam::operator<<
276 (
277  Ostream& os,
279 )
280 {
281  typedef typename GeoMesh::template FieldSource<Type> Source;
282  os << static_cast<const HashPtrTable<Source>&>(bf);
283  return os;
284 }
285 
286 
287 // ************************************************************************* //
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:476
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.
const HashPtrTable< Source > & table() const
Access the underlying field table.
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.
friend class GeometricFieldSources
Declare friendship with other geometric field sources.
void reset(const Internal &, 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
An STL-conforming hash table.
Definition: HashTable.H:127
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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:242
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:235
T clone(const T &t)
Definition: List.H:55
IOerror FatalIOError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:228
static const char nl
Definition: Ostream.H:267
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