fvFieldSource.H
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 Class
25  Foam::fvFieldSource
26 
27 Description
28  Base class for finite-volume field sources
29 
30 SourceFiles
31  fvFieldSource.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef fvFieldSource_H
36 #define fvFieldSource_H
37 
38 #include "DimensionedField.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of classes
46 class volMesh;
47 class dictionary;
48 class fvSource;
49 
50 template<class Type>
51 class fvFieldSource;
52 
53 // Forward declaration of friend functions and operators
54 template<class Type>
56 
57 /*---------------------------------------------------------------------------*\
58  Class fvFieldSource Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type>
62 class fvFieldSource
63 {
64  // Private Data
65 
66  //- Optional list of libraries required for this field source value
67  fileNameList libs_;
68 
69  //- Reference to internal field
70  const DimensionedField<Type, volMesh>& internalField_;
71 
72 
73 public:
74 
75  //- Runtime type information
76  TypeName("fvFieldSource");
77 
78  //- Debug switch to disallow the use of genericFvFieldSource
80 
81 
82  // Declare run-time constructor selection tables
83 
84  //- Select given internal field
86  (
87  autoPtr,
89  null,
91  (iF)
92  );
93 
94  //- Select given internal field and dictionary
96  (
97  autoPtr,
99  dictionary,
100  (
102  const dictionary& dict
103  ),
104  (iF, dict)
105  );
106 
107 
108  // Constructors
109 
110  //- Construct from internal field
112 
113  //- Construct from internal field and dictionary
115  (
117  const dictionary&
118  );
119 
120  //- Disallow copy without setting internal field reference
121  fvFieldSource(const fvFieldSource<Type>&) = delete;
122 
123  //- Disallow clone without setting internal field reference
125  {
127  return autoPtr<fvFieldSource<Type>>(nullptr);
128  }
129 
130  //- Copy constructor setting internal field reference
132  (
133  const fvFieldSource<Type>&,
135  );
136 
137  //- Construct and return a clone setting internal field reference
139  (
141  ) const = 0;
142 
143 
144  // Selectors
145 
146  //- Return a pointer to a new field source
148  (
149  const word& fieldSourceType,
151  );
152 
153  //- Return a pointer to a new field source created from a dictionary
155  (
157  const dictionary&
158  );
159 
160 
161  //- Destructor
162  virtual ~fvFieldSource();
163 
164 
165  // Member Functions
166 
167  //- Return the local object registry
168  const objectRegistry& db() const;
169 
170  //- Return the internal field reference
172 
173  //- Return the source value
174  virtual tmp<Field<Type>> sourceValue(const fvSource&) const = 0;
175 
176  //- Return the internal coefficient
177  virtual tmp<scalarField> internalCoeff(const fvSource&) const = 0;
178 
179  //- Return the source coefficient
180  tmp<Field<Type>> sourceCoeff(const fvSource&) const;
181 
182  //- Return the value
183  tmp<Field<Type>> value(const fvSource&) const;
184 
185  //- Lookup and return another field source
186  template<class OtherType>
188  (
189  const word& name,
190  const fvSource&
191  ) const;
192 
193  //- Lookup and return the value of another field source
194  template<class OtherType>
196  (
197  const word& name,
198  const fvSource&
199  ) const;
200 
201  //- Write
202  virtual void write(Ostream&) const;
203 
204 
205  //- Ostream operator
206  friend Ostream& operator<< <Type>(Ostream&, const fvFieldSource<Type>&);
207 };
208 
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 } // End namespace Foam
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #ifdef NoRepository
217  #include "fvFieldSource.C"
218 #endif
219 
220 
221 #define makeFvFieldSource(fvTypeFieldSource) \
222  defineNamedTemplateTypeNameAndDebug(fvTypeFieldSource, 0); \
223  template<> \
224  int fvTypeFieldSource::disallowGenericFvFieldSource \
225  ( \
226  debug::debugSwitch("disallowGenericFvFieldSource", 0) \
227  ); \
228  defineTemplateRunTimeSelectionTable(fvTypeFieldSource, null); \
229  defineTemplateRunTimeSelectionTable(fvTypeFieldSource, dictionary)
230 
231 
232 #define addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource) \
233  addToRunTimeSelectionTable \
234  ( \
235  TypeFieldSource, \
236  typeTypeFieldSource, \
237  dictionary \
238  )
239 
240 
241 #define addNullConstructableToFieldSourceRunTimeSelection( \
242  TypeFieldSource, typeTypeFieldSource) \
243  addToRunTimeSelectionTable \
244  ( \
245  TypeFieldSource, \
246  typeTypeFieldSource, \
247  null \
248  ); \
249  addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource)
250 
251 
252 #define makeTypeFieldSource(TypeFieldSource, typeTypeFieldSource) \
253  defineTypeNameAndDebug(typeTypeFieldSource, 0); \
254  addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource)
255 
256 
257 #define makeNullConstructableTypeFieldSource( \
258  TypeFieldSource, typeTypeFieldSource) \
259  defineTypeNameAndDebug(typeTypeFieldSource, 0); \
260  addNullConstructableToFieldSourceRunTimeSelection \
261  ( \
262  TypeFieldSource, \
263  typeTypeFieldSource \
264  )
265 
266 
267 #define makeTemplateTypeFieldSource(fieldType, type) \
268  defineNamedTemplateTypeNameAndDebug \
269  ( \
270  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
271  0 \
272  ); \
273  addToFieldSourceRunTimeSelection \
274  ( \
275  CAT3(fv, CAPITALIZE(fieldType), FieldSource), \
276  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource) \
277  );
278 
279 
280 #define makeNullConstructableTemplateTypeFieldSource(fieldType, type) \
281  defineNamedTemplateTypeNameAndDebug \
282  ( \
283  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
284  0 \
285  ); \
286  addNullConstructableToFieldSourceRunTimeSelection \
287  ( \
288  CAT3(fv, CAPITALIZE(fieldType), FieldSource), \
289  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource) \
290  );
291 
292 
293 #define makeFieldSources(type) \
294  FOR_ALL_FIELD_TYPES(makeTemplateTypeFieldSource, type)
295 
296 
297 #define makeNullConstructableFieldSources(type) \
298  FOR_ALL_FIELD_TYPES(makeNullConstructableTemplateTypeFieldSource, type)
299 
300 
301 #define makeFieldSourceTypeName(fieldType, type) \
302  defineNamedTemplateTypeNameAndDebug \
303  ( \
304  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
305  0 \
306  );
307 
308 
309 #define makeFieldSourceTypeNames(type) \
310  FOR_ALL_FIELD_TYPES(makeFieldSourceTypeName, type)
311 
312 
313 #define makeTypeFieldSourceTypedef(fieldType, type) \
314  typedef type##FvFieldSource<fieldType> \
315  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource);
316 
317 
318 #define makeTypeFieldSourceTypedefs(type) \
319  FOR_ALL_FIELD_TYPES(makeTypeFieldSourceTypedef, type)
320 
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #endif
325 
326 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Base class for finite-volume field sources.
Definition: fvFieldSource.H:62
autoPtr< fvFieldSource< Type > > clone() const
Disallow clone without setting internal field reference.
virtual void write(Ostream &) const
Write.
tmp< Field< Type > > value(const fvSource &) const
Return the value.
TypeName("fvFieldSource")
Runtime type information.
fvFieldSource(const DimensionedField< Type, volMesh > &)
Construct from internal field.
Definition: fvFieldSource.C:34
declareRunTimeSelectionTable(autoPtr, fvFieldSource, null,(const DimensionedField< Type, volMesh > &iF),(iF))
Select given internal field.
const objectRegistry & db() const
Return the local object registry.
static int disallowGenericFvFieldSource
Debug switch to disallow the use of genericFvFieldSource.
Definition: fvFieldSource.H:78
const fvFieldSource< OtherType > & fieldSource(const word &name, const fvSource &) const
Lookup and return another field source.
static autoPtr< fvFieldSource< Type > > New(const word &fieldSourceType, const DimensionedField< Type, volMesh > &)
Return a pointer to a new field source.
Definition: fvFieldSource.C:72
virtual tmp< scalarField > internalCoeff(const fvSource &) const =0
Return the internal coefficient.
virtual ~fvFieldSource()
Destructor.
tmp< Field< Type > > sourceCoeff(const fvSource &) const
Return the source coefficient.
virtual tmp< Field< Type > > sourceValue(const fvSource &) const =0
Return the source value.
const DimensionedField< Type, volMesh > & internalField() const
Return the internal field reference.
Base class for finite volume sources.
Definition: fvSource.H:52
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
Namespace for OpenFOAM.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
dictionary dict