fvsPatchField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::fvsPatchField
29 
30 Description
31  An abstract base class with a fat-interface to all derived classes
32  covering all possible ways in which they might be used.
33 
34  The first level of derivation is to basic patchFields which cover
35  zero-gradient, fixed-gradient, fixed-value and mixed conditions.
36 
37  The next level of derivation covers all the specialised typed with
38  specific evaluation procedures, particularly with respect to specific
39  fields.
40 
41 SourceFiles
42  fvsPatchField.C
43  fvsPatchFieldNew.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef Foam_fvsPatchField_H
48 #define Foam_fvsPatchField_H
49 
50 #include "fvPatch.H"
51 #include "DimensionedField.H"
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 
55 namespace Foam
56 {
57 
58 // Forward Declarations
59 class objectRegistry;
60 class dictionary;
61 class fvPatchFieldMapper;
62 class surfaceMesh;
63 
64 template<class Type> class fvsPatchField;
65 template<class Type> class calculatedFvsPatchField;
66 
67 template<class Type>
68 Ostream& operator<<(Ostream&, const fvsPatchField<Type>&);
69 
70 
71 /*---------------------------------------------------------------------------*\
72  Class fvsPatchFieldBase Declaration
73 \*---------------------------------------------------------------------------*/
74 
75 //- Template invariant parts for fvsPatchField
77 {
78  // Private Data
79 
80  //- Reference to patch
81  const fvPatch& patch_;
82 
83 protected:
84 
85  // Protected Member Functions
86 
87  //- Read dictionary entries.
88  // Useful when initially constructed without a dictionary
89  virtual void readDict(const dictionary& dict);
90 
91 
92 public:
93 
94  //- Debug switch to disallow the use of generic fvsPatchField
95  static int disallowGenericPatchField;
96 
97  //- Runtime type information
98  TypeName("fvsPatchField");
99 
100 
101  // Constructors
102 
103  //- Construct from patch
104  explicit fvsPatchFieldBase(const fvPatch& p);
105 
106  //- Construct from patch and dictionary (unused)
107  fvsPatchFieldBase(const fvPatch& p, const dictionary& dict);
108 
109  //- Copy construct with new patch
110  fvsPatchFieldBase(const fvsPatchFieldBase& rhs, const fvPatch& p);
111 
112  //- Copy construct
114 
115 
116  //- Destructor
117  virtual ~fvsPatchFieldBase() = default;
118 
119 
120  // Member Functions
121 
122  // Access
123 
124  //- The associated objectRegistry
125  const objectRegistry& db() const;
126 
127  //- Return the patch
128  const fvPatch& patch() const noexcept
129  {
130  return patch_;
131  }
132 
133 
134  // Check
135 
136  //- Check that patches are identical
137  void checkPatch(const fvsPatchFieldBase& rhs) const;
138 };
139 
140 
141 /*---------------------------------------------------------------------------*\
142  Class fvsPatchField Declaration
143 \*---------------------------------------------------------------------------*/
144 
145 template<class Type>
146 class fvsPatchField
147 :
149  public Field<Type>
150 {
151  // Private Data
152 
153  //- Reference to internal field
154  const DimensionedField<Type, surfaceMesh>& internalField_;
155 
156 
157 public:
158 
159  //- The internal field type associated with the patch field
161 
162  //- The patch type for the patch field
163  typedef fvPatch Patch;
164 
165  //- Type for a \em calculated patch
167 
168 
169  // Declare run-time constructor selection tables
170 
172  (
173  tmp,
175  patch,
176  (
177  const fvPatch& p,
179  ),
180  (p, iF)
181  );
182 
184  (
185  tmp,
187  patchMapper,
188  (
189  const fvsPatchField<Type>& ptf,
190  const fvPatch& p,
192  const fvPatchFieldMapper& m
193  ),
194  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
195  );
198  (
199  tmp,
201  dictionary,
202  (
203  const fvPatch& p,
205  const dictionary& dict
206  ),
207  (p, iF, dict)
208  );
209 
210 
211  // Constructors
212 
213  //- Construct from patch and internal field
215  (
216  const fvPatch&,
218  );
219 
220  //- Construct from patch and internal field and patch field
222  (
223  const fvPatch&,
225  const Field<Type>&
226  );
227 
228  //- Construct from patch, internal field and dictionary
230  (
231  const fvPatch&,
233  const dictionary&,
234  const bool valueRequired=true
235  );
236 
237  //- Construct by mapping the given fvsPatchField onto a new patch
239  (
240  const fvsPatchField<Type>&,
241  const fvPatch&,
243  const fvPatchFieldMapper&
244  );
245 
246  //- Construct as copy
248 
249  //- Construct as copy setting internal field reference
251  (
252  const fvsPatchField<Type>&,
254  );
255 
256  //- Construct and return a clone
257  virtual tmp<fvsPatchField<Type>> clone() const
258  {
259  return tmp<fvsPatchField<Type>>::New(*this);
260  }
261 
262  //- Construct and return a clone setting internal field reference
264  (
266  ) const
267  {
268  return tmp<fvsPatchField<Type>>::New(*this, iF);
269  }
270 
271 
272  // Selectors
273 
274  //- Return a pointer to a new patchField created on freestore given
275  // patch and internal field
276  // (does not set the patch field values)
277  static tmp<fvsPatchField<Type>> New
278  (
279  const word& patchFieldType,
280  const fvPatch&,
281  const DimensionedField<Type, surfaceMesh>&
282  );
283 
284  //- Return a pointer to a new patchField created on freestore given
285  // patch and internal field
286  // (does not set the patch field values)
287  // Allows override of constraint type
288  static tmp<fvsPatchField<Type>> New
289  (
290  const word& patchFieldType,
291  const word& actualPatchType,
292  const fvPatch&,
293  const DimensionedField<Type, surfaceMesh>&
294  );
295 
296  //- Return a pointer to a new patchField created on freestore from
297  // a given fvsPatchField mapped onto a new patch
298  static tmp<fvsPatchField<Type>> New
299  (
300  const fvsPatchField<Type>&,
301  const fvPatch&,
303  const fvPatchFieldMapper&
304  );
305 
306  //- Return a pointer to a new patchField created on freestore
307  // from dictionary
309  (
310  const fvPatch&,
312  const dictionary&
313  );
314 
315  //- Return a pointer to a new calculatedFvsPatchField created on
316  // freestore without setting patchField values
318  (
319  const fvPatch&
320  );
321 
322  //- Return a pointer to a new calculatedFvsPatchField created on
323  // freestore without setting patchField values
324  template<class Type2>
326  (
327  const fvsPatchField<Type2>&
328  );
329 
330 
331  //- Destructor
332  virtual ~fvsPatchField() = default;
333 
334 
335  // Member Functions
336 
337  //- The type name for calculated patch fields
338  static const word& calculatedType();
339 
340 
341  // Attributes
342 
343  //- True if this patch field fixes a value.
344  // Needed to check if a level has to be specified while solving
345  // Poissons equations.
346  virtual bool fixesValue() const
347  {
348  return false;
349  }
350 
351  //- True if this patch field is coupled
352  virtual bool coupled() const
353  {
354  return false;
355  }
356 
357 
358  // Access
359 
360  //- Return dimensioned internal field reference
361  const DimensionedField<Type, surfaceMesh>& internalField()
362  const noexcept
363  {
364  return internalField_;
365  }
366 
367  //- Return internal field reference
368  const Field<Type>& primitiveField() const noexcept
369  {
370  return internalField_;
371  }
372 
373 
374  // Mapping Functions
375 
376  //- Map (and resize as needed) from self given a mapping object
377  virtual void autoMap
378  (
379  const fvPatchFieldMapper&
380  );
381 
382  //- Reverse map the given fvsPatchField onto this fvsPatchField
383  virtual void rmap
384  (
385  const fvsPatchField<Type>&,
386  const labelList&
387  );
388 
389 
390  //- Write
391  virtual void write(Ostream&) const;
392 
393 
394  // Check
395 
396  //- Check fvsPatchField<Type> against given fvsPatchField<Type>
397  void check(const fvsPatchField<Type>&) const;
398 
399 
400  // Member Operators
401 
402  virtual void operator=(const UList<Type>&);
403 
404  virtual void operator=(const fvsPatchField<Type>&);
405  virtual void operator+=(const fvsPatchField<Type>&);
406  virtual void operator-=(const fvsPatchField<Type>&);
407  virtual void operator*=(const fvsPatchField<scalar>&);
408  virtual void operator/=(const fvsPatchField<scalar>&);
409 
410  virtual void operator+=(const Field<Type>&);
411  virtual void operator-=(const Field<Type>&);
412 
413  virtual void operator*=(const Field<scalar>&);
414  virtual void operator/=(const Field<scalar>&);
415 
416  virtual void operator=(const Type&);
417  virtual void operator+=(const Type&);
418  virtual void operator-=(const Type&);
419  virtual void operator*=(const scalar);
420  virtual void operator/=(const scalar);
421 
422 
423  // Force an assignment irrespective of form of patch
424 
425  virtual void operator==(const fvsPatchField<Type>&);
426  virtual void operator==(const Field<Type>&);
427  virtual void operator==(const Type&);
428 
429 
430  // Ostream Operator
431 
432  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
433 };
434 
435 
436 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
437 
438 } // End namespace Foam
439 
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
441 
442 #ifdef NoRepository
443  #include "fvsPatchField.C"
444  #include "calculatedFvsPatchField.H"
445 #endif
446 
447 
448 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
449 // Runtime selection macros
450 
451 #define makeFvsPatchTypeFieldTypeName(type) \
452  \
453 defineNamedTemplateTypeNameAndDebug(type, 0);
454 
455 #define makeFvsPatchFieldsTypeName(type) \
456  \
457 makeFvsPatchTypeFieldTypeName(type##FvsPatchScalarField); \
458 makeFvsPatchTypeFieldTypeName(type##FvsPatchVectorField); \
459 makeFvsPatchTypeFieldTypeName(type##FvsPatchSphericalTensorField); \
460 makeFvsPatchTypeFieldTypeName(type##FvsPatchSymmTensorField); \
461 makeFvsPatchTypeFieldTypeName(type##FvsPatchTensorField);
462 
463 #define makeFvsPatchTypeField(PatchTypeField, typePatchTypeField) \
464  \
465 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
466  \
467 addToRunTimeSelectionTable \
468 ( \
469  PatchTypeField, typePatchTypeField, patch \
470 ); \
471  \
472 addToRunTimeSelectionTable \
473 ( \
474  PatchTypeField, \
475  typePatchTypeField, \
476  patchMapper \
477 ); \
478  \
479 addToRunTimeSelectionTable \
480 ( \
481  PatchTypeField, typePatchTypeField, dictionary \
482 );
483 
484 
485 #define makeFvsPatchFields(type) \
486  \
487 makeFvsPatchTypeField(fvsPatchScalarField, type##FvsPatchScalarField); \
488 makeFvsPatchTypeField(fvsPatchVectorField, type##FvsPatchVectorField); \
489 makeFvsPatchTypeField \
490 ( \
491  fvsPatchSphericalTensorField, \
492  type##FvsPatchSphericalTensorField \
493 ); \
494 makeFvsPatchTypeField(fvsPatchSymmTensorField, type##FvsPatchSymmTensorField); \
495 makeFvsPatchTypeField(fvsPatchTensorField, type##FvsPatchTensorField);
496 
497 
498 #define makeFvsPatchTypeFieldTypedefs(type) \
499  \
500 typedef type##FvsPatchField<scalar> type##FvsPatchScalarField; \
501 typedef type##FvsPatchField<vector> type##FvsPatchVectorField; \
502 typedef type##FvsPatchField<sphericalTensor> \
503  type##FvsPatchSphericalTensorField; \
504 typedef type##FvsPatchField<symmTensor> type##FvsPatchSymmTensorField; \
505 typedef type##FvsPatchField<tensor> type##FvsPatchTensorField;
506 
507 
508 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
509 
510 #endif
511 
512 // ************************************************************************* //
virtual void operator*=(const fvsPatchField< scalar > &)
dictionary dict
virtual bool fixesValue() const
True if this patch field fixes a value.
virtual void write(Ostream &) const
Write.
virtual ~fvsPatchField()=default
Destructor.
const DimensionedField< Type, surfaceMesh > & internalField() const noexcept
Return dimensioned internal field reference.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const Field< Type > & primitiveField() const noexcept
Return internal field reference.
static int disallowGenericPatchField
Debug switch to disallow the use of generic fvsPatchField.
Definition: fvsPatchField.H:99
virtual void operator==(const fvsPatchField< Type > &)
TypeName("fvsPatchField")
Runtime type information.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:68
const objectRegistry & db() const
The associated objectRegistry.
const fvPatch & patch() const noexcept
Return the patch.
static tmp< fvsPatchField< Type > > NewCalculatedType(const fvPatch &)
Return a pointer to a new calculatedFvsPatchField created on.
DimensionedField< Type, surfaceMesh > Internal
The internal field type associated with the patch field.
calculatedFvsPatchField< Type > Calculated
Type for a calculated patch.
virtual void operator/=(const fvsPatchField< scalar > &)
Generic templated field type.
Definition: Field.H:61
virtual bool coupled() const
True if this patch field is coupled.
A class for handling words, derived from Foam::string.
Definition: word.H:63
void check(const fvsPatchField< Type > &) const
Check fvsPatchField<Type> against given fvsPatchField<Type>
A FieldMapper for finite-volume patch fields.
declareRunTimeSelectionTable(tmp, fvsPatchField, patch,(const fvPatch &p, const DimensionedField< Type, surfaceMesh > &iF),(p, iF))
fvsPatchFieldBase(const fvPatch &p)
Construct from patch.
fvsPatchField(const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Construct from patch and internal field.
Definition: fvsPatchField.C:32
virtual void readDict(const dictionary &dict)
Read dictionary entries.
void checkPatch(const fvsPatchFieldBase &rhs) const
Check that patches are identical.
virtual void operator-=(const fvsPatchField< Type > &)
fvPatch Patch
The patch type for the patch field.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
const direction noexcept
Definition: Scalar.H:258
virtual ~fvsPatchFieldBase()=default
Destructor.
virtual void rmap(const fvsPatchField< Type > &, const labelList &)
Reverse map the given fvsPatchField onto this fvsPatchField.
Template invariant parts for fvsPatchField.
Definition: fvsPatchField.H:73
virtual void operator+=(const fvsPatchField< Type > &)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual void operator=(const UList< Type > &)
Foam::calculatedFvsPatchField.
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
static const word & calculatedType()
The type name for calculated patch fields.
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
virtual tmp< fvsPatchField< Type > > clone() const
Construct and return a clone.
Namespace for OpenFOAM.
static tmp< fvsPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Return a pointer to a new patchField created on freestore given.