fvsPatchField.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) 2011-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 Class
25  Foam::fvsPatchField
26 
27 Description
28  An abstract base class with a fat-interface to all derived classes
29  covering all possible ways in which they might be used.
30 
31  The first level of derivation is to basic patchFields which cover
32  zero-gradient, fixed-gradient, fixed-value and mixed conditions.
33 
34  The next level of derivation covers all the specialised typed with
35  specific evaluation procedures, particularly with respect to specific
36  fields.
37 
38 SourceFiles
39  fvsPatchField.C
40  fvsPatchFieldNew.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef fvsPatchField_H
45 #define fvsPatchField_H
46 
47 #include "fvPatch.H"
48 #include "DimensionedField.H"
49 #include "fvPatchFieldMapperFwd.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 // Forward declaration of classes
57 
58 class objectRegistry;
59 class dictionary;
60 class fieldMapper;
61 class surfaceMesh;
62 
63 
64 // Forward declaration of friend functions and operators
65 
66 template<class Type>
67 class fvsPatchField;
68 
69 template<class Type>
70 class calculatedFvsPatchField;
71 
72 template<class Type>
74 
75 
76 /*---------------------------------------------------------------------------*\
77  Class patch Declaration
78 \*---------------------------------------------------------------------------*/
79 
80 template<class Type>
81 class fvsPatchField
82 :
83  public Field<Type>
84 {
85  // Private Data
86 
87  //- Reference to patch
88  const fvPatch& patch_;
89 
90  //- Reference to internal field
91  const DimensionedField<Type, surfaceMesh>& internalField_;
92 
93 
94 public:
95 
96  typedef fvPatch Patch;
98 
99 
100  //- Runtime type information
101  TypeName("fvsPatchField");
102 
103  //- Debug switch to disallow the use of genericFvsPatchField
104  static int disallowGenericFvsPatchField;
105 
106 
107  // Declare run-time constructor selection tables
108 
110  (
111  tmp,
113  patch,
114  (
115  const fvPatch& p,
117  ),
118  (p, iF)
119  );
120 
122  (
123  tmp,
125  dictionary,
126  (
127  const fvPatch& p,
129  const dictionary& dict
130  ),
131  (p, iF, dict)
132  );
133 
135  (
136  tmp,
138  patchMapper,
139  (
140  const fvsPatchField<Type>& ptf,
141  const fvPatch& p,
143  const fieldMapper& m
144  ),
145  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
146  );
147 
148 
149  // Constructors
150 
151  //- Construct from patch and internal field
153  (
154  const fvPatch&,
156  );
157 
158  //- Construct from patch and internal field and patch field
160  (
161  const fvPatch&,
163  const Field<Type>&
164  );
165 
166  //- Construct from patch, internal field and dictionary
168  (
169  const fvPatch&,
171  const dictionary&,
172  const bool valueRequired=true
173  );
174 
175  //- Construct by mapping the given fvsPatchField onto a new patch
177  (
178  const fvsPatchField<Type>&,
179  const fvPatch&,
181  const fieldMapper&,
182  const bool mappingRequired=true
183  );
184 
185  //- Disallow copy without setting internal field reference
186  fvsPatchField(const fvsPatchField<Type>&) = delete;
187 
188  //- Disallow clone without setting internal field reference
190  {
191  // Temporarily reinstate the clone() function pending a rewrite of
192  // the mapping of surfaceFields in fvMeshDistribute
194  (
195  new fvsPatchField<Type>(*this, internalField_)
196  );
197 
198  // NotImplemented;
199  // return tmp<fvsPatchField<Type>>(nullptr);
200  }
201 
202  //- Copy constructor setting internal field reference
204  (
205  const fvsPatchField<Type>&,
207  );
208 
209  //- Construct and return a clone setting internal field reference
211  (
213  ) const
214  {
216  (
217  new fvsPatchField<Type>(*this, iF)
218  );
219  }
220 
221  //- Construct and return a clone onto a new patch
222  // setting internal field reference
224  (
225  const fvPatch& patch,
227  ) const
228  {
230  (
231  new fvsPatchField<Type>(patch, iF, *this)
232  );
233  }
234 
235 
236  // Selectors
237 
238  //- Return a pointer to a new patchField created on freestore given
239  // patch and internal field
240  // (does not set the patch field values)
242  (
243  const word&,
244  const fvPatch&,
246  );
247 
248  //- Return a pointer to a new patchField created on freestore given
249  // patch and internal field
250  // (does not set the patch field values)
251  // Allows override of constraint type
253  (
254  const word&,
255  const word& actualPatchType,
256  const fvPatch&,
258  );
259 
260  //- Return a pointer to a new patchField created on freestore from
261  // a given fvsPatchField mapped onto a new patch
263  (
264  const fvsPatchField<Type>&,
265  const fvPatch&,
267  const fieldMapper&
268  );
269 
270  //- Return a pointer to a new patchField created on freestore
271  // from dictionary
273  (
274  const fvPatch&,
276  const dictionary&
277  );
278 
279  //- Return a pointer to a new calculatedFvsPatchField created on
280  // freestore without setting patchField values
282  (
283  const fvPatch&
284  );
285 
286  //- Return a pointer to a new calculatedFvsPatchField created on
287  // freestore without setting patchField values
288  template<class Type2>
290  (
291  const fvsPatchField<Type2>&
292  );
293 
294 
295  //- Destructor
296  virtual ~fvsPatchField()
297  {}
298 
299 
300  // Member Functions
301 
302  // Attributes
303 
304  //- Return the type of the calculated for of fvsPatchField
305  static const word& calculatedType();
306 
307  //- Return true if this patch field fixes a value.
308  // Needed to check if a level has to be specified while solving
309  // Poissons equations.
310  virtual bool fixesValue() const
311  {
312  return false;
313  }
314 
315  //- Return true if this patch field is coupled
316  virtual bool coupled() const
317  {
318  return false;
319  }
320 
321  //- Return true if this overrides the underlying constraint type
322  bool overridesConstraint() const
323  {
324  if (type() == patch_.type())
325  {
326  return false;
327  }
328 
329  typename patchConstructorTable::iterator patchTypeCstrIter
330  = patchConstructorTablePtr_->find(patch_.type());
331 
332  return
333  patchTypeCstrIter
334  != patchConstructorTablePtr_->end();
335  }
336 
337 
338  // Access
339 
340  //- Return local objectRegistry
341  const objectRegistry& db() const;
342 
343  //- Return patch
344  const fvPatch& patch() const
345  {
346  return patch_;
347  }
348 
349  //- Return dimensioned internal field reference
351  internalField() const
352  {
353  return internalField_;
354  }
355 
356  //- Return internal field reference
357  const Field<Type>& primitiveField() const
358  {
359  return internalField_;
360  }
361 
362 
363  // Evaluation functions
364 
365  //- Initialise return of the patchField on the opposite patch of a
366  // coupled patch
367  virtual void initPatchNeighbourField
368  (
369  const Pstream::commsTypes commsType
370  ) const
371  {}
372 
373  //- Return patchField on the opposite patch of a coupled patch
375  (
376  const Pstream::commsTypes commsType
377  ) const
378  {
380  return *this;
381  }
382 
383 
384  // Mapping functions
385 
386  //- Map the given fvsPatchField onto this fvsPatchField
387  virtual void map(const fvsPatchField<Type>&, const fieldMapper&);
388 
389  //- Reset the fvsPatchField to the given fvsPatchField
390  // Used for mesh to mesh mapping
391  virtual void reset(const fvsPatchField<Type>&);
392 
393 
394  //- Write
395  virtual void write(Ostream&) const;
396 
397 
398  // Check
399 
400  //- Check fvsPatchField<Type> against given fvsPatchField<Type>
401  void check(const fvsPatchField<Type>&) const;
402 
403 
404  // Member Operators
405 
406  virtual void operator=(const UList<Type>&);
407 
408  virtual void operator=(const fvsPatchField<Type>&);
409  virtual void operator+=(const fvsPatchField<Type>&);
410  virtual void operator-=(const fvsPatchField<Type>&);
411  virtual void operator*=(const fvsPatchField<scalar>&);
412  virtual void operator/=(const fvsPatchField<scalar>&);
413 
414  virtual void operator+=(const Field<Type>&);
415  virtual void operator-=(const Field<Type>&);
416 
417  virtual void operator*=(const Field<scalar>&);
418  virtual void operator/=(const Field<scalar>&);
419 
420  virtual void operator=(const Type&);
421  virtual void operator+=(const Type&);
422  virtual void operator-=(const Type&);
423  virtual void operator*=(const scalar);
424  virtual void operator/=(const scalar);
425 
426 
427  // Force an assignment irrespective of form of patch
428 
429  virtual void operator==(const fvsPatchField<Type>&);
430  virtual void operator==(const Field<Type>&);
431  virtual void operator==(const Type&);
432 
433 
434  // Ostream operator
435 
436  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
437 };
438 
439 
440 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
441 
442 } // End namespace Foam
443 
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
445 
446 #ifdef NoRepository
447  #include "fvsPatchField.C"
448  #include "calculatedFvsPatchField.H"
449 #endif
450 
451 
452 #define makeFvsPatchField(fvsPatchTypeField) \
453  defineNamedTemplateTypeNameAndDebug(fvsPatchTypeField, 0); \
454  template<> \
455  int fvsPatchTypeField::disallowGenericFvsPatchField \
456  ( \
457  debug::debugSwitch("disallowGenericFvsPatchField", 0) \
458  ); \
459  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patch); \
460  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patchMapper); \
461  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, dictionary);
462 
463 
464 #define addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
465  addToRunTimeSelectionTable \
466  ( \
467  PatchTypeField, \
468  typePatchTypeField, \
469  patch \
470  ); \
471  addToRunTimeSelectionTable \
472  ( \
473  PatchTypeField, \
474  typePatchTypeField, \
475  patchMapper \
476  ); \
477  addToRunTimeSelectionTable \
478  ( \
479  PatchTypeField, \
480  typePatchTypeField, \
481  dictionary \
482  );
483 
484 
485 // For non-templated patch fields
486 #define makeFvsPatchTypeField(PatchTypeField, typePatchTypeField) \
487  defineTypeNameAndDebug(typePatchTypeField, 0); \
488  addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
489 
490 
491 // For templated patch fields
492 #define makeTemplateFvsPatchTypeField(fieldType, type) \
493  defineNamedTemplateTypeNameAndDebug \
494  ( \
495  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
496  0 \
497  ); \
498  addToFvsPatchFieldRunTimeSelection \
499  ( \
500  CAT3(fvsPatch, CAPITALIZE(fieldType), Field), \
501  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field) \
502  )
503 
504 
505 #define makeFvsPatchFields(type) \
506  FOR_ALL_FIELD_TYPES(makeTemplateFvsPatchTypeField, type)
507 
508 
509 #define makeFvsPatchFieldTypeName(fieldType, type) \
510  defineNamedTemplateTypeNameAndDebug \
511  ( \
512  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
513  0 \
514  );
515 
516 
517 #define makeFvsPatchFieldTypeNames(type) \
518  FOR_ALL_FIELD_TYPES(makeFvsPatchFieldTypeName, type)
519 
520 
521 #define makeFvsPatchTypeFieldTypedef(fieldType, type) \
522  typedef type##FvsPatchField<fieldType> \
523  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field);
524 
525 
526 #define makeFvsPatchTypeFieldTypedefs(type) \
527  FOR_ALL_FIELD_TYPES(makeFvsPatchTypeFieldTypedef, type)
528 
529 
530 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
531 
532 #endif
533 
534 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:83
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
commsTypes
Types of communications.
Definition: UPstream.H:65
Foam::calculatedFvsPatchField.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:83
virtual bool fixesValue() const
Return true if this patch field fixes a value.
virtual void write(Ostream &) const
Write.
virtual bool coupled() const
Return true if this patch field is coupled.
virtual void reset(const fvsPatchField< Type > &)
Reset the fvsPatchField to the given fvsPatchField.
virtual void operator==(const fvsPatchField< Type > &)
fvsPatchField(const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Construct from patch and internal field.
Definition: fvsPatchField.C:36
const Field< Type > & primitiveField() const
Return internal field reference.
declareRunTimeSelectionTable(tmp, fvsPatchField, patch,(const fvPatch &p, const DimensionedField< Type, surfaceMesh > &iF),(p, iF))
const objectRegistry & db() const
Return local objectRegistry.
static tmp< fvsPatchField< Type > > NewCalculatedType(const fvPatch &)
Return a pointer to a new calculatedFvsPatchField created on.
virtual void operator=(const UList< Type > &)
TypeName("fvsPatchField")
Runtime type information.
virtual void map(const fvsPatchField< Type > &, const fieldMapper &)
Map the given fvsPatchField onto this fvsPatchField.
const DimensionedField< Type, surfaceMesh > & internalField() const
Return dimensioned internal field reference.
virtual void operator-=(const fvsPatchField< Type > &)
tmp< fvsPatchField< Type > > clone() const
Disallow clone without setting internal field reference.
virtual void operator/=(const fvsPatchField< scalar > &)
bool overridesConstraint() const
Return true if this overrides the underlying constraint type.
virtual tmp< Field< Type > > patchNeighbourField(const Pstream::commsTypes commsType) const
Return patchField on the opposite patch of a coupled patch.
virtual void operator+=(const fvsPatchField< Type > &)
virtual ~fvsPatchField()
Destructor.
calculatedFvsPatchField< Type > Calculated
Definition: fvsPatchField.H:96
void check(const fvsPatchField< Type > &) const
Check fvsPatchField<Type> against given fvsPatchField<Type>
const fvPatch & patch() const
Return patch.
virtual void initPatchNeighbourField(const Pstream::commsTypes commsType) const
Initialise return of the patchField on the opposite patch of a.
static tmp< fvsPatchField< Type > > New(const word &, const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Return a pointer to a new patchField created on freestore given.
static int disallowGenericFvsPatchField
Debug switch to disallow the use of genericFvsPatchField.
virtual void operator*=(const fvsPatchField< scalar > &)
static const word & calculatedType()
Return the type of the calculated for of fvsPatchField.
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.
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
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
volScalarField & p