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-2026 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 fvMesh;
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, fvMesh>& 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 time
171  const Time& time() const;
172 
173  //- Return the internal field reference
175 
176  //- Return the source value
178  (
179  const fvSource& model,
181  ) const = 0;
182 
183  //- Return the source value
185  (
186  const fvSource& model,
187  const scalarField& source,
188  const labelUList& cells
189  ) const;
190 
191  //- Return the internal coefficient
193  (
194  const fvSource& model,
196  ) const = 0;
197 
198  //- Return the internal coefficient
200  (
201  const fvSource& model,
202  const scalarField& source,
203  const labelUList& cells
204  ) const;
205 
206  //- Return the source coefficient
208  (
209  const fvSource& model,
211  ) const;
212 
213  //- Return the source coefficient
215  (
216  const fvSource& model,
217  const scalarField& source,
218  const labelUList& cells
219  ) const;
220 
221  //- Return the value
223  (
224  const fvSource& model,
226  ) const;
227 
228  //- Return the value
230  (
231  const fvSource& model,
232  const scalarField& source,
233  const labelUList& cells
234  ) const;
235 
236  //- Lookup and return another field source
237  template<class OtherType>
239  (
240  const word& name,
241  const fvSource& model
242  ) const;
243 
244  //- Lookup and return the value of another field source
245  template<class OtherType>
247  (
248  const word& name,
249  const fvSource& model,
251  ) const;
252 
253  //- Lookup and return the value of another field source
254  template<class OtherType>
256  (
257  const word& name,
258  const fvSource& model,
259  const scalarField& source,
260  const labelUList& cells
261  ) const;
262 
263  //- Write
264  virtual void write(Ostream&) const;
265 
266 
267  //- Ostream operator
268  friend Ostream& operator<< <Type>(Ostream&, const fvFieldSource<Type>&);
269 };
270 
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 } // End namespace Foam
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #ifdef NoRepository
279  #include "fvFieldSource.C"
280 #endif
281 
282 
283 #define makeFvFieldSource(fvTypeFieldSource) \
284  defineNamedTemplateTypeNameAndDebug(fvTypeFieldSource, 0); \
285  template<> \
286  int fvTypeFieldSource::disallowGenericFvFieldSource \
287  ( \
288  debug::debugSwitch("disallowGenericFvFieldSource", 0) \
289  ); \
290  defineTemplateRunTimeSelectionTable(fvTypeFieldSource, null); \
291  defineTemplateRunTimeSelectionTable(fvTypeFieldSource, dictionary)
292 
293 
294 #define addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource) \
295  addToRunTimeSelectionTable \
296  ( \
297  TypeFieldSource, \
298  typeTypeFieldSource, \
299  dictionary \
300  )
301 
302 
303 #define addNullConstructableToFieldSourceRunTimeSelection( \
304  TypeFieldSource, typeTypeFieldSource) \
305  addToRunTimeSelectionTable \
306  ( \
307  TypeFieldSource, \
308  typeTypeFieldSource, \
309  null \
310  ); \
311  addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource)
312 
313 
314 #define makeTypeFieldSource(TypeFieldSource, typeTypeFieldSource) \
315  defineTypeNameAndDebug(typeTypeFieldSource, 0); \
316  addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource)
317 
318 
319 #define makeNullConstructableTypeFieldSource( \
320  TypeFieldSource, typeTypeFieldSource) \
321  defineTypeNameAndDebug(typeTypeFieldSource, 0); \
322  addNullConstructableToFieldSourceRunTimeSelection \
323  ( \
324  TypeFieldSource, \
325  typeTypeFieldSource \
326  )
327 
328 
329 #define makeTemplateTypeFieldSource(fieldType, type) \
330  defineNamedTemplateTypeNameAndDebug \
331  ( \
332  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
333  0 \
334  ); \
335  addToFieldSourceRunTimeSelection \
336  ( \
337  CAT3(fv, CAPITALIZE(fieldType), FieldSource), \
338  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource) \
339  );
340 
341 
342 #define makeNullConstructableTemplateTypeFieldSource(fieldType, type) \
343  defineNamedTemplateTypeNameAndDebug \
344  ( \
345  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
346  0 \
347  ); \
348  addNullConstructableToFieldSourceRunTimeSelection \
349  ( \
350  CAT3(fv, CAPITALIZE(fieldType), FieldSource), \
351  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource) \
352  );
353 
354 
355 #define makeFieldSources(type) \
356  FOR_ALL_FIELD_TYPES(makeTemplateTypeFieldSource, type)
357 
358 
359 #define makeNullConstructableFieldSources(type) \
360  FOR_ALL_FIELD_TYPES(makeNullConstructableTemplateTypeFieldSource, type)
361 
362 
363 #define makeFieldSourceTypeName(fieldType, type) \
364  defineNamedTemplateTypeNameAndDebug \
365  ( \
366  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
367  0 \
368  );
369 
370 
371 #define makeFieldSourceTypeNames(type) \
372  FOR_ALL_FIELD_TYPES(makeFieldSourceTypeName, type)
373 
374 
375 #define makeTypeFieldSourceTypedef(fieldType, type) \
376  typedef type##FvFieldSource<fieldType> \
377  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource);
378 
379 
380 #define makeTypeFieldSourceTypedefs(type) \
381  FOR_ALL_FIELD_TYPES(makeTypeFieldSourceTypedef, type)
382 
383 
384 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
385 
386 #endif
387 
388 // ************************************************************************* //
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
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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.
const DimensionedField< Type, fvMesh > & internalField() const
Return the internal field reference.
virtual tmp< DimensionedField< Type, fvMesh > > sourceCoeff(const fvSource &model, const DimensionedField< scalar, fvMesh > &source) const
Return the source coefficient.
static autoPtr< fvFieldSource< Type > > New(const word &fieldSourceType, const DimensionedField< Type, fvMesh > &)
Return a pointer to a new field source.
Definition: fvFieldSource.C:72
const Time & time() const
Return time.
virtual void write(Ostream &) const
Write.
TypeName("fvFieldSource")
Runtime type information.
fvFieldSource(const DimensionedField< Type, fvMesh > &)
Construct from internal field.
Definition: fvFieldSource.C:34
virtual tmp< DimensionedField< Type, fvMesh > > sourceValue(const fvSource &model, const DimensionedField< scalar, fvMesh > &source) const =0
Return the source value.
const objectRegistry & db() const
Return the local object registry.
static int disallowGenericFvFieldSource
Debug switch to disallow the use of genericFvFieldSource.
Definition: fvFieldSource.H:78
declareRunTimeSelectionTable(autoPtr, fvFieldSource, null,(const DimensionedField< Type, fvMesh > &iF),(iF))
Select given internal field.
const fvFieldSource< OtherType > & fieldSource(const word &name, const fvSource &model) const
Lookup and return another field source.
tmp< DimensionedField< Type, fvMesh > > value(const fvSource &model, const DimensionedField< scalar, fvMesh > &source) const
Return the value.
virtual ~fvFieldSource()
Destructor.
virtual tmp< DimensionedField< scalar, fvMesh > > internalCoeff(const fvSource &model, const DimensionedField< scalar, fvMesh > &source) const =0
Return the internal coefficient.
Base class for finite volume sources.
Definition: fvSource.H:53
Registry of regIOobjects.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
const cellShapeList & cells
Namespace for OpenFOAM.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
dictionary dict