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-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 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
175  (
176  const fvSource& model,
178  ) const = 0;
179 
180  //- Return the source value
182  (
183  const fvSource& model,
184  const scalarField& source,
185  const labelUList& cells
186  ) const;
187 
188  //- Return the internal coefficient
190  (
191  const fvSource& model,
193  ) const = 0;
194 
195  //- Return the internal coefficient
197  (
198  const fvSource& model,
199  const scalarField& source,
200  const labelUList& cells
201  ) const;
202 
203  //- Return the source coefficient
205  (
206  const fvSource& model,
208  ) const;
209 
210  //- Return the source coefficient
212  (
213  const fvSource& model,
214  const scalarField& source,
215  const labelUList& cells
216  ) const;
217 
218  //- Return the value
220  (
221  const fvSource& model,
223  ) const;
224 
225  //- Return the value
227  (
228  const fvSource& model,
229  const scalarField& source,
230  const labelUList& cells
231  ) const;
232 
233  //- Lookup and return another field source
234  template<class OtherType>
236  (
237  const word& name,
238  const fvSource& model
239  ) const;
240 
241  //- Lookup and return the value of another field source
242  template<class OtherType>
244  (
245  const word& name,
246  const fvSource& model,
248  ) const;
249 
250  //- Lookup and return the value of another field source
251  template<class OtherType>
253  (
254  const word& name,
255  const fvSource& model,
256  const scalarField& source,
257  const labelUList& cells
258  ) const;
259 
260  //- Write
261  virtual void write(Ostream&) const;
262 
263 
264  //- Ostream operator
265  friend Ostream& operator<< <Type>(Ostream&, const fvFieldSource<Type>&);
266 };
267 
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 } // End namespace Foam
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 #ifdef NoRepository
276  #include "fvFieldSource.C"
277 #endif
278 
279 
280 #define makeFvFieldSource(fvTypeFieldSource) \
281  defineNamedTemplateTypeNameAndDebug(fvTypeFieldSource, 0); \
282  template<> \
283  int fvTypeFieldSource::disallowGenericFvFieldSource \
284  ( \
285  debug::debugSwitch("disallowGenericFvFieldSource", 0) \
286  ); \
287  defineTemplateRunTimeSelectionTable(fvTypeFieldSource, null); \
288  defineTemplateRunTimeSelectionTable(fvTypeFieldSource, dictionary)
289 
290 
291 #define addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource) \
292  addToRunTimeSelectionTable \
293  ( \
294  TypeFieldSource, \
295  typeTypeFieldSource, \
296  dictionary \
297  )
298 
299 
300 #define addNullConstructableToFieldSourceRunTimeSelection( \
301  TypeFieldSource, typeTypeFieldSource) \
302  addToRunTimeSelectionTable \
303  ( \
304  TypeFieldSource, \
305  typeTypeFieldSource, \
306  null \
307  ); \
308  addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource)
309 
310 
311 #define makeTypeFieldSource(TypeFieldSource, typeTypeFieldSource) \
312  defineTypeNameAndDebug(typeTypeFieldSource, 0); \
313  addToFieldSourceRunTimeSelection(TypeFieldSource, typeTypeFieldSource)
314 
315 
316 #define makeNullConstructableTypeFieldSource( \
317  TypeFieldSource, typeTypeFieldSource) \
318  defineTypeNameAndDebug(typeTypeFieldSource, 0); \
319  addNullConstructableToFieldSourceRunTimeSelection \
320  ( \
321  TypeFieldSource, \
322  typeTypeFieldSource \
323  )
324 
325 
326 #define makeTemplateTypeFieldSource(fieldType, type) \
327  defineNamedTemplateTypeNameAndDebug \
328  ( \
329  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
330  0 \
331  ); \
332  addToFieldSourceRunTimeSelection \
333  ( \
334  CAT3(fv, CAPITALIZE(fieldType), FieldSource), \
335  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource) \
336  );
337 
338 
339 #define makeNullConstructableTemplateTypeFieldSource(fieldType, type) \
340  defineNamedTemplateTypeNameAndDebug \
341  ( \
342  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
343  0 \
344  ); \
345  addNullConstructableToFieldSourceRunTimeSelection \
346  ( \
347  CAT3(fv, CAPITALIZE(fieldType), FieldSource), \
348  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource) \
349  );
350 
351 
352 #define makeFieldSources(type) \
353  FOR_ALL_FIELD_TYPES(makeTemplateTypeFieldSource, type)
354 
355 
356 #define makeNullConstructableFieldSources(type) \
357  FOR_ALL_FIELD_TYPES(makeNullConstructableTemplateTypeFieldSource, type)
358 
359 
360 #define makeFieldSourceTypeName(fieldType, type) \
361  defineNamedTemplateTypeNameAndDebug \
362  ( \
363  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource), \
364  0 \
365  );
366 
367 
368 #define makeFieldSourceTypeNames(type) \
369  FOR_ALL_FIELD_TYPES(makeFieldSourceTypeName, type)
370 
371 
372 #define makeTypeFieldSourceTypedef(fieldType, type) \
373  typedef type##FvFieldSource<fieldType> \
374  CAT4(type, Fv, CAPITALIZE(fieldType), FieldSource);
375 
376 
377 #define makeTypeFieldSourceTypedefs(type) \
378  FOR_ALL_FIELD_TYPES(makeTypeFieldSourceTypedef, type)
379 
380 
381 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
382 
383 #endif
384 
385 // ************************************************************************* //
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 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.
virtual tmp< DimensionedField< scalar, volMesh > > internalCoeff(const fvSource &model, const DimensionedField< scalar, volMesh > &source) const =0
Return the internal coefficient.
virtual tmp< DimensionedField< Type, volMesh > > sourceValue(const fvSource &model, const DimensionedField< scalar, volMesh > &source) const =0
Return the source value.
virtual void write(Ostream &) const
Write.
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 &model) 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:80
virtual tmp< DimensionedField< Type, volMesh > > sourceCoeff(const fvSource &model, const DimensionedField< scalar, volMesh > &source) const
Return the source coefficient.
virtual ~fvFieldSource()
Destructor.
tmp< DimensionedField< Type, volMesh > > value(const fvSource &model, const DimensionedField< scalar, volMesh > &source) const
Return the 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
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