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-2024 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  GeometricFieldSources(iF, static_cast<const HashPtrTable<Source>&>(mtf))
66 {}
67 
68 
69 template<class Type, class GeoMesh, template<class> class PrimitiveField>
70 template<template<class> class PrimitiveField2>
73 (
76 )
77 :
78  GeometricFieldSources(iF, static_cast<const HashPtrTable<Source>&>(mtf))
79 {}
80 
81 
82 template<class Type, class GeoMesh, template<class> class PrimitiveField>
85 (
87  const dictionary& dict
88 )
89 :
91  errorLocation_()
92 {
93  readField(iF, dict);
94 }
95 
96 
97 template<class Type, class GeoMesh, template<class> class PrimitiveField>
100 (
102  const HashTable<word>& types
103 )
104 :
105  HashPtrTable<Source>(),
106  errorLocation_()
107 {
108  forAllConstIter(typename HashTable<word>, types, iter)
109  {
110  this->set
111  (
112  iter.key(),
113  Source::New(iter(), iF).ptr()
114  );
115  }
116 }
117 
118 
119 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
120 
121 template<class Type, class GeoMesh, template<class> class PrimitiveField>
124 {}
125 
126 
127 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
128 
129 template<class Type, class GeoMesh, template<class> class PrimitiveField>
130 const Foam::HashPtrTable
131 <
133 >&
135 {
136  return *this;
137 }
138 
139 
140 template<class Type, class GeoMesh, template<class> class PrimitiveField>
142 <
144 >&
146 {
147  return *this;
148 }
149 
150 
151 template<class Type, class GeoMesh, template<class> class PrimitiveField>
154 {
155  HashTable<word> result;
156 
157  forAllConstIter(typename HashPtrTable<Source>, *this, iter)
158  {
159  result.insert(iter.key(), iter()->type());
160  }
161 
162  return result;
163 }
164 
165 
166 template<class Type, class GeoMesh, template<class> class PrimitiveField>
168 (
170  const dictionary& dict
171 )
172 {
173  this->clear();
174 
175  errorLocation_ = IOerrorLocation(dict);
176 
178  {
179  if (iter().isDict())
180  {
181  this->set
182  (
183  iter().keyword(),
184  Source::New(field, iter().dict()).ptr()
185  );
186  }
187  }
188 }
189 
190 
191 template<class Type, class GeoMesh, template<class> class PrimitiveField>
193 (
196 )
197 {
198  this->clear();
199 
200  errorLocation_ = mtf.errorLocation_;
201 
202  forAllConstIter(typename HashPtrTable<Source>, mtf, iter)
203  {
204  this->set(iter.key(), iter()->clone(field).ptr());
205  }
206 }
207 
208 
209 template<class Type, class GeoMesh, template<class> class PrimitiveField>
211 (
212  const word& keyword,
213  Ostream& os
214 ) const
215 {
216  os << keyword << nl << token::BEGIN_BLOCK << incrIndent << nl;
217 
218  forAllConstIter(typename HashPtrTable<Source>, *this, iter)
219  {
220  os << indent << iter.key() << nl
221  << indent << token::BEGIN_BLOCK << nl
222  << incrIndent << *iter() << decrIndent
223  << indent << token::END_BLOCK << endl;
224  }
225 
226  os << decrIndent << token::END_BLOCK << endl;
227 
228  // Check state of IOstream
229  os.check
230  (
231  "GeometricFieldSources<Type, GeoMesh, PrimitiveField>::"
232  "writeEntry(const word& keyword, Ostream& os) const"
233  );
234 }
235 
236 
237 // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
238 
239 template<class Type, class GeoMesh, template<class> class PrimitiveField>
240 const typename
243 (
244  const word& sourceName
245 ) const
246 {
247  typename HashPtrTable<Source>::const_iterator iter = this->find(sourceName);
248 
249  if (iter == this->end())
250  {
251  FatalIOErrorInFunction(errorLocation_)
252  << "Cannot find fieldSource entry for " << sourceName
253  << exit(FatalIOError);
254  }
255 
256  return **iter;
257 }
258 
259 
260 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
261 
262 template<class Type, class GeoMesh, template<class> class PrimitiveField>
263 Foam::Ostream& Foam::operator<<
264 (
265  Ostream& os,
267 )
268 {
269  typedef typename GeoMesh::template FieldSource<Type> Source;
270  os << static_cast<const HashPtrTable<Source>&>(bf);
271  return os;
272 }
273 
274 
275 // ************************************************************************* //
#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