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-2022 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 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward declaration of classes
56 
57 class objectRegistry;
58 class dictionary;
59 class fvPatchFieldMapper;
60 class surfaceMesh;
61 
62 
63 // Forward declaration of friend functions and operators
64 
65 template<class Type>
66 class fvsPatchField;
67 
68 template<class Type>
70 
71 template<class Type>
72 Ostream& operator<<(Ostream&, const fvsPatchField<Type>&);
73 
74 
75 /*---------------------------------------------------------------------------*\
76  Class patch Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 template<class Type>
80 class fvsPatchField
81 :
82  public Field<Type>
83 {
84  // Private Data
85 
86  //- Reference to patch
87  const fvPatch& patch_;
88 
89  //- Reference to internal field
90  const DimensionedField<Type, surfaceMesh>& internalField_;
91 
92 
93 public:
94 
95  typedef fvPatch Patch;
97 
98 
99  //- Runtime type information
100  TypeName("fvsPatchField");
101 
102  //- Debug switch to disallow the use of genericFvsPatchField
103  static int disallowGenericFvsPatchField;
104 
105 
106  // Declare run-time constructor selection tables
107 
109  (
110  tmp,
112  patch,
113  (
114  const fvPatch& p,
116  ),
117  (p, iF)
118  );
119 
121  (
122  tmp,
124  patchMapper,
125  (
126  const fvsPatchField<Type>& ptf,
127  const fvPatch& p,
129  const fvPatchFieldMapper& m
130  ),
131  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
132  );
133 
135  (
136  tmp,
138  dictionary,
139  (
140  const fvPatch& p,
142  const dictionary& dict
143  ),
144  (p, iF, dict)
145  );
146 
147 
148  // Constructors
149 
150  //- Construct from patch and internal field
152  (
153  const fvPatch&,
155  );
156 
157  //- Construct from patch and internal field and patch field
159  (
160  const fvPatch&,
162  const Field<Type>&
163  );
164 
165  //- Construct from patch, internal field and dictionary
167  (
168  const fvPatch&,
170  const dictionary&
171  );
172 
173  //- Construct by mapping the given fvsPatchField onto a new patch
175  (
176  const fvsPatchField<Type>&,
177  const fvPatch&,
179  const fvPatchFieldMapper&
180  );
181 
182  //- Disallow copy without setting internal field reference
183  fvsPatchField(const fvsPatchField<Type>&) = delete;
184 
185  //- Disallow clone without setting internal field reference
187  {
188  // Temporarily reinstate the clone() function pending a rewrite of
189  // the mapping of surfaceFields in fvMeshDistribute
191  (
192  new fvsPatchField<Type>(*this, internalField_)
193  );
194 
195  // NotImplemented;
196  // return tmp<fvsPatchField<Type>>(nullptr);
197  }
198 
199  //- Copy constructor setting internal field reference
201  (
202  const fvsPatchField<Type>&,
204  );
205 
206  //- Construct and return a clone setting internal field reference
208  (
210  ) const
211  {
213  (
214  new fvsPatchField<Type>(*this, iF)
215  );
216  }
217 
218  //- Construct and return a clone onto a new patch
219  // setting internal field reference
221  (
222  const fvPatch& patch,
224  ) const
225  {
227  (
228  new fvsPatchField<Type>(patch, iF, *this)
229  );
230  }
231 
232 
233  // Selectors
234 
235  //- Return a pointer to a new patchField created on freestore given
236  // patch and internal field
237  // (does not set the patch field values)
239  (
240  const word&,
241  const fvPatch&,
243  );
244 
245  //- Return a pointer to a new patchField created on freestore given
246  // patch and internal field
247  // (does not set the patch field values)
248  // Allows override of constraint type
250  (
251  const word&,
252  const word& actualPatchType,
253  const fvPatch&,
255  );
256 
257  //- Return a pointer to a new patchField created on freestore from
258  // a given fvsPatchField mapped onto a new patch
260  (
261  const fvsPatchField<Type>&,
262  const fvPatch&,
264  const fvPatchFieldMapper&
265  );
266 
267  //- Return a pointer to a new patchField created on freestore
268  // from dictionary
270  (
271  const fvPatch&,
273  const dictionary&
274  );
275 
276  //- Return a pointer to a new calculatedFvsPatchField created on
277  // freestore without setting patchField values
279  (
280  const fvPatch&
281  );
282 
283  //- Return a pointer to a new calculatedFvsPatchField created on
284  // freestore without setting patchField values
285  template<class Type2>
287  (
288  const fvsPatchField<Type2>&
289  );
290 
291 
292  //- Destructor
293  virtual ~fvsPatchField<Type>()
294  {}
295 
296 
297  // Member Functions
298 
299  // Attributes
300 
301  //- Return the type of the calculated for of fvsPatchField
302  static const word& calculatedType();
303 
304  //- Return true if this patch field fixes a value.
305  // Needed to check if a level has to be specified while solving
306  // Poissons equations.
307  virtual bool fixesValue() const
308  {
309  return false;
310  }
311 
312  //- Return true if this patch field is coupled
313  virtual bool coupled() const
314  {
315  return false;
316  }
317 
318  //- Return true if this overrides the underlying constraint type
319  bool overridesConstraint() const
320  {
321  if (type() == patch_.type())
322  {
323  return false;
324  }
325 
326  typename patchConstructorTable::iterator patchTypeCstrIter
327  = patchConstructorTablePtr_->find(patch_.type());
328 
329  return
330  patchTypeCstrIter
331  != patchConstructorTablePtr_->end();
332  }
333 
334 
335  // Access
336 
337  //- Return local objectRegistry
338  const objectRegistry& db() const;
339 
340  //- Return patch
341  const fvPatch& patch() const
342  {
343  return patch_;
344  }
345 
346  //- Return dimensioned internal field reference
348  internalField() const
349  {
350  return internalField_;
351  }
352 
353  //- Return internal field reference
354  const Field<Type>& primitiveField() const
355  {
356  return internalField_;
357  }
358 
359 
360  // Evaluation functions
361 
362  //- Initialise return of the patchField on the opposite patch of a
363  // coupled patch
365  (
366  const Pstream::commsTypes commsType
367  ) const
368  {}
369 
370  //- Return patchField on the opposite patch of a coupled patch
372  (
373  const Pstream::commsTypes commsType
374  ) const
375  {
377  return *this;
378  }
379 
380 
381  // Mapping functions
382 
383  //- Map (and resize as needed) from self given a mapping object
384  // Used to update fields following mesh topology change
385  virtual void autoMap(const fvPatchFieldMapper&);
386 
387  //- Reverse map the given fvsPatchField onto this fvsPatchField
388  // Used to reconstruct fields
389  virtual void rmap(const fvsPatchField<Type>&, const labelList&);
390 
391  //- Reset the fvsPatchField to the given fvsPatchField
392  // Used for mesh to mesh mapping
393  virtual void reset(const fvsPatchField<Type>&);
394 
395 
396  //- Write
397  virtual void write(Ostream&) const;
398 
399 
400  // Check
401 
402  //- Check fvsPatchField<Type> against given fvsPatchField<Type>
403  void check(const fvsPatchField<Type>&) const;
404 
405 
406  // Member Operators
407 
408  virtual void operator=(const UList<Type>&);
409 
410  virtual void operator=(const fvsPatchField<Type>&);
411  virtual void operator+=(const fvsPatchField<Type>&);
412  virtual void operator-=(const fvsPatchField<Type>&);
413  virtual void operator*=(const fvsPatchField<scalar>&);
414  virtual void operator/=(const fvsPatchField<scalar>&);
415 
416  virtual void operator+=(const Field<Type>&);
417  virtual void operator-=(const Field<Type>&);
418 
419  virtual void operator*=(const Field<scalar>&);
420  virtual void operator/=(const Field<scalar>&);
421 
422  virtual void operator=(const Type&);
423  virtual void operator+=(const Type&);
424  virtual void operator-=(const Type&);
425  virtual void operator*=(const scalar);
426  virtual void operator/=(const scalar);
427 
428 
429  // Force an assignment irrespective of form of patch
430 
431  virtual void operator==(const fvsPatchField<Type>&);
432  virtual void operator==(const Field<Type>&);
433  virtual void operator==(const Type&);
434 
435 
436  // Ostream operator
437 
438  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
439 };
440 
441 
442 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
443 
444 } // End namespace Foam
445 
446 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
447 
448 #ifdef NoRepository
449  #include "fvsPatchField.C"
450  #include "calculatedFvsPatchField.H"
451 #endif
452 
454 #define makeFvsPatchField(fvsPatchTypeField) \
455  defineNamedTemplateTypeNameAndDebug(fvsPatchTypeField, 0); \
456  template<> \
457  int fvsPatchTypeField::disallowGenericFvsPatchField \
458  ( \
459  debug::debugSwitch("disallowGenericFvsPatchField", 0) \
460  ); \
461  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patch); \
462  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patchMapper); \
463  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, dictionary);
464 
466 #define addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
467  addToRunTimeSelectionTable \
468  ( \
469  PatchTypeField, \
470  typePatchTypeField, \
471  patch \
472  ); \
473  addToRunTimeSelectionTable \
474  ( \
475  PatchTypeField, \
476  typePatchTypeField, \
477  patchMapper \
478  ); \
479  addToRunTimeSelectionTable \
480  ( \
481  PatchTypeField, \
482  typePatchTypeField, \
483  dictionary \
484  );
485 
486 
487 // For non-templated patch fields
488 #define makeFvsPatchTypeField(PatchTypeField, typePatchTypeField) \
489  defineTypeNameAndDebug(typePatchTypeField, 0); \
490  addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
491 
492 
493 // For templated patch fields
494 #define makeTemplateFvsPatchTypeField(fieldType, type) \
495  defineNamedTemplateTypeNameAndDebug \
496  ( \
497  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
498  0 \
499  ); \
500  addToFvsPatchFieldRunTimeSelection \
501  ( \
502  CAT3(fvsPatch, CAPITALIZE(fieldType), Field), \
503  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field) \
504  )
505 
507 #define makeFvsPatchFields(type) \
508  FOR_ALL_FIELD_TYPES(makeTemplateFvsPatchTypeField, type)
509 
511 #define makeFvsPatchFieldTypeName(fieldType, type) \
512  defineNamedTemplateTypeNameAndDebug \
513  ( \
514  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
515  0 \
516  );
517 
519 #define makeFvsPatchFieldTypeNames(type) \
520  FOR_ALL_FIELD_TYPES(makeFvsPatchFieldTypeName, type)
521 
523 #define makeFvsPatchTypeFieldTypedef(fieldType, type) \
524  typedef type##FvsPatchField<fieldType> \
525  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field);
526 
528 #define makeFvsPatchTypeFieldTypedefs(type) \
529  FOR_ALL_FIELD_TYPES(makeFvsPatchTypeFieldTypedef, type)
530 
531 
532 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
533 
534 #endif
535 
536 // ************************************************************************* //
virtual void operator*=(const fvsPatchField< scalar > &)
virtual void reset(const fvsPatchField< Type > &)
Reset the fvsPatchField to the given fvsPatchField.
virtual bool fixesValue() const
Return true if this patch field fixes a value.
virtual void write(Ostream &) const
Write.
virtual tmp< Field< Type > > patchNeighbourField(const Pstream::commsTypes commsType) const
Return patchField on the opposite patch of a coupled patch.
TypeName("fvsPatchField")
Runtime type information.
const Field< Type > & primitiveField() const
Return internal field reference.
const objectRegistry & db() const
Return local objectRegistry.
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 any number of values (e...
Definition: dictionary.H:156
commsTypes
Types of communications.
Definition: UPstream.H:64
virtual void operator==(const fvsPatchField< Type > &)
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
static tmp< fvsPatchField< Type > > NewCalculatedType(const fvPatch &)
Return a pointer to a new calculatedFvsPatchField created on.
calculatedFvsPatchField< Type > Calculated
Definition: fvsPatchField.H:95
virtual void operator/=(const fvsPatchField< scalar > &)
static tmp< fvsPatchField< Type > > New(const word &, const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Return a pointer to a new patchField created on freestore given.
Pre-declare SubField and related Field type.
Definition: Field.H:56
tmp< fvsPatchField< Type > > clone() const
Disallow clone without setting internal field reference.
virtual bool coupled() const
Return true if this patch field is coupled.
A class for handling words, derived from string.
Definition: word.H:59
bool overridesConstraint() const
Return true if this overrides the underlying constraint type.
void check(const fvsPatchField< Type > &) const
Check fvsPatchField<Type> against given fvsPatchField<Type>
Foam::fvPatchFieldMapper.
declareRunTimeSelectionTable(tmp, fvsPatchField, patch,(const fvPatch &p, const DimensionedField< Type, surfaceMesh > &iF),(p, iF))
fvsPatchField(const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Construct from patch and internal field.
Definition: fvsPatchField.C:35
virtual void operator-=(const fvsPatchField< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual void rmap(const fvsPatchField< Type > &, const labelList &)
Reverse map the given fvsPatchField onto this fvsPatchField.
const fvPatch & patch() const
Return patch.
virtual void operator+=(const fvsPatchField< Type > &)
virtual void initPatchNeighbourField(const Pstream::commsTypes commsType) const
Initialise return of the patchField on the opposite patch of a.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void operator=(const UList< Type > &)
Foam::calculatedFvsPatchField.
const DimensionedField< Type, surfaceMesh > & internalField() const
Return dimensioned internal field reference.
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.
static const word & calculatedType()
Return the type of the calculated for of fvsPatchField.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:353
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
Definition: fvsPatchField.H:65
static int disallowGenericFvsPatchField
Debug switch to disallow the use of genericFvsPatchField.
Namespace for OpenFOAM.