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>
73 class slicedFvsPatchField;
74 
75 template<class Type>
77 
78 
79 /*---------------------------------------------------------------------------*\
80  Class patch Declaration
81 \*---------------------------------------------------------------------------*/
82 
83 template<class Type>
84 class fvsPatchField
85 :
86  public Field<Type>
87 {
88  // Private Data
89 
90  //- Reference to patch
91  const fvPatch& patch_;
92 
93  //- Reference to internal field
94  const DimensionedField<Type, surfaceMesh>& internalField_;
95 
96 
97 public:
98 
99  // Public Typedefs
100 
101  //- The patch type
102  typedef fvPatch Patch;
103 
104  //- The calculated patch field type
106 
107  //- The sliced patch field type
109 
110 
111  //- Runtime type information
112  TypeName("fvsPatchField");
113 
114 
115  //- Debug switch to disallow the use of genericFvsPatchField
116  static int disallowGenericFvsPatchField;
117 
118 
119  // Declare run-time constructor selection tables
120 
122  (
123  tmp,
125  patch,
126  (
127  const fvPatch& p,
129  ),
130  (p, iF)
131  );
132 
134  (
135  tmp,
137  dictionary,
138  (
139  const fvPatch& p,
141  const dictionary& dict
142  ),
143  (p, iF, dict)
144  );
145 
147  (
148  tmp,
150  patchMapper,
151  (
152  const fvsPatchField<Type>& ptf,
153  const fvPatch& p,
155  const fieldMapper& m
156  ),
157  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
158  );
159 
160 
161  // Constructors
162 
163  //- Construct from patch and internal field
165  (
166  const fvPatch&,
168  );
169 
170  //- Construct from patch and internal field and patch field
172  (
173  const fvPatch&,
175  const Field<Type>&
176  );
177 
178  //- Construct from patch, internal field and dictionary
180  (
181  const fvPatch&,
183  const dictionary&,
184  const bool valueRequired=true
185  );
186 
187  //- Construct by mapping the given fvsPatchField onto a new patch
189  (
190  const fvsPatchField<Type>&,
191  const fvPatch&,
193  const fieldMapper&,
194  const bool mappingRequired=true
195  );
196 
197  //- Disallow copy without setting internal field reference
198  fvsPatchField(const fvsPatchField<Type>&) = delete;
199 
200  //- Disallow clone without setting internal field reference
202  {
203  // Temporarily reinstate the clone() function pending a rewrite of
204  // the mapping of surfaceFields in fvMeshDistribute
206  (
207  new fvsPatchField<Type>(*this, internalField_)
208  );
209 
210  // NotImplemented;
211  // return tmp<fvsPatchField<Type>>(nullptr);
212  }
213 
214  //- Copy constructor setting internal field reference
216  (
217  const fvsPatchField<Type>&,
219  );
220 
221  //- Construct and return a clone setting internal field reference
223  (
225  ) const
226  {
228  (
229  new fvsPatchField<Type>(*this, iF)
230  );
231  }
232 
233  //- Construct and return a clone onto a new patch
234  // setting internal field reference
236  (
237  const fvPatch& patch,
239  ) const
240  {
242  (
243  new fvsPatchField<Type>(patch, iF, *this)
244  );
245  }
246 
247 
248  // Selectors
249 
250  //- Return a pointer to a new patchField created on freestore given
251  // patch and internal field
252  // (does not set the patch field values)
254  (
255  const word&,
256  const fvPatch&,
258  );
259 
260  //- Return a pointer to a new patchField created on freestore given
261  // patch and internal field
262  // (does not set the patch field values)
263  // Allows override of constraint type
265  (
266  const word&,
267  const word& actualPatchType,
268  const fvPatch&,
270  );
271 
272  //- Return a pointer to a new patchField created on freestore from
273  // a given fvsPatchField mapped onto a new patch
275  (
276  const fvsPatchField<Type>&,
277  const fvPatch&,
279  const fieldMapper&
280  );
281 
282  //- Return a pointer to a new patchField created on freestore
283  // from dictionary
285  (
286  const fvPatch&,
288  const dictionary&
289  );
290 
291  //- Return a pointer to a new calculatedFvsPatchField created on
292  // freestore without setting patchField values
294  (
295  const fvPatch&
296  );
297 
298  //- Return a pointer to a new calculatedFvsPatchField created on
299  // freestore without setting patchField values
300  template<class Type2>
302  (
303  const fvsPatchField<Type2>&
304  );
305 
306 
307  //- Destructor
308  virtual ~fvsPatchField()
309  {}
310 
311 
312  // Member Functions
313 
314  // Attributes
315 
316  //- Return the type of the calculated for of fvsPatchField
317  static const word& calculatedType();
318 
319  //- Return true if this patch field fixes a value.
320  // Needed to check if a level has to be specified while solving
321  // Poissons equations.
322  virtual bool fixesValue() const
323  {
324  return false;
325  }
326 
327  //- Return true if this patch field is coupled
328  virtual bool coupled() const
329  {
330  return false;
331  }
332 
333  //- Return true if this overrides the underlying constraint type
334  bool overridesConstraint() const
335  {
336  if (type() == patch_.type())
337  {
338  return false;
339  }
340 
341  typename patchConstructorTable::iterator patchTypeCstrIter
342  = patchConstructorTablePtr_->find(patch_.type());
343 
344  return
345  patchTypeCstrIter
346  != patchConstructorTablePtr_->end();
347  }
348 
349 
350  // Access
351 
352  //- Return local objectRegistry
353  const objectRegistry& db() const;
354 
355  //- Return patch
356  const fvPatch& patch() const
357  {
358  return patch_;
359  }
360 
361  //- Return dimensioned internal field reference
363  internalField() const
364  {
365  return internalField_;
366  }
367 
368  //- Return internal field reference
369  const Field<Type>& primitiveField() const
370  {
371  return internalField_;
372  }
373 
374 
375  // Evaluation functions
376 
377  //- Initialise return of the patchField on the opposite patch of a
378  // coupled patch
379  virtual void initPatchNeighbourField
380  (
381  const Pstream::commsTypes commsType
382  ) const
383  {}
384 
385  //- Return patchField on the opposite patch of a coupled patch
387  (
388  const Pstream::commsTypes commsType
389  ) const
390  {
392  return *this;
393  }
394 
395 
396  // Mapping functions
397 
398  //- Map the given fvsPatchField onto this fvsPatchField
399  virtual void map(const fvsPatchField<Type>&, const fieldMapper&);
400 
401  //- Reset the fvsPatchField to the given fvsPatchField
402  // Used for mesh to mesh mapping
403  virtual void reset(const fvsPatchField<Type>&);
404 
405 
406  //- Write
407  virtual void write(Ostream&) const;
408 
409 
410  // Check
411 
412  //- Check fvsPatchField<Type> against given fvsPatchField<Type>
413  void check(const fvsPatchField<Type>&) const;
414 
415 
416  // Member Operators
417 
418  virtual void operator=(const UList<Type>&);
419 
420  virtual void operator=(const fvsPatchField<Type>&);
421  virtual void operator+=(const fvsPatchField<Type>&);
422  virtual void operator-=(const fvsPatchField<Type>&);
423  virtual void operator*=(const fvsPatchField<scalar>&);
424  virtual void operator/=(const fvsPatchField<scalar>&);
425 
426  virtual void operator+=(const Field<Type>&);
427  virtual void operator-=(const Field<Type>&);
428 
429  virtual void operator*=(const Field<scalar>&);
430  virtual void operator/=(const Field<scalar>&);
431 
432  virtual void operator=(const Type&);
433  virtual void operator+=(const Type&);
434  virtual void operator-=(const Type&);
435  virtual void operator*=(const scalar);
436  virtual void operator/=(const scalar);
437 
438 
439  // Force an assignment irrespective of form of patch
440 
441  virtual void operator==(const fvsPatchField<Type>&);
442  virtual void operator==(const Field<Type>&);
443  virtual void operator==(const Type&);
444 
445 
446  // Ostream operator
447 
448  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
449 };
450 
451 
452 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
453 
454 } // End namespace Foam
455 
456 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
457 
458 #ifdef NoRepository
459  #include "fvsPatchField.C"
460  #include "calculatedFvsPatchField.H"
461 #endif
462 
463 
464 #define makeFvsPatchField(fvsPatchTypeField) \
465  defineNamedTemplateTypeNameAndDebug(fvsPatchTypeField, 0); \
466  template<> \
467  int fvsPatchTypeField::disallowGenericFvsPatchField \
468  ( \
469  debug::debugSwitch("disallowGenericFvsPatchField", 0) \
470  ); \
471  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patch); \
472  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patchMapper); \
473  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, dictionary);
474 
475 
476 #define addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
477  addToRunTimeSelectionTable \
478  ( \
479  PatchTypeField, \
480  typePatchTypeField, \
481  patch \
482  ); \
483  addToRunTimeSelectionTable \
484  ( \
485  PatchTypeField, \
486  typePatchTypeField, \
487  patchMapper \
488  ); \
489  addToRunTimeSelectionTable \
490  ( \
491  PatchTypeField, \
492  typePatchTypeField, \
493  dictionary \
494  );
495 
496 
497 // For non-templated patch fields
498 #define makeFvsPatchTypeField(PatchTypeField, typePatchTypeField) \
499  defineTypeNameAndDebug(typePatchTypeField, 0); \
500  addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
501 
502 
503 // For templated patch fields
504 #define makeTemplateFvsPatchTypeField(fieldType, type) \
505  defineNamedTemplateTypeNameAndDebug \
506  ( \
507  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
508  0 \
509  ); \
510  addToFvsPatchFieldRunTimeSelection \
511  ( \
512  CAT3(fvsPatch, CAPITALIZE(fieldType), Field), \
513  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field) \
514  )
515 
516 
517 #define makeFvsPatchFields(type) \
518  FOR_ALL_FIELD_TYPES(makeTemplateFvsPatchTypeField, type)
519 
520 
521 #define makeFvsPatchFieldTypeName(fieldType, type) \
522  defineNamedTemplateTypeNameAndDebug \
523  ( \
524  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
525  0 \
526  );
527 
528 
529 #define makeFvsPatchFieldTypeNames(type) \
530  FOR_ALL_FIELD_TYPES(makeFvsPatchFieldTypeName, type)
531 
532 
533 #define makeFvsPatchTypeFieldTypedef(fieldType, type) \
534  typedef type##FvsPatchField<fieldType> \
535  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field);
536 
537 
538 #define makeFvsPatchTypeFieldTypedefs(type) \
539  FOR_ALL_FIELD_TYPES(makeFvsPatchTypeFieldTypedef, type)
540 
541 
542 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
543 
544 #endif
545 
546 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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:86
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.
fvPatch Patch
The patch type.
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.
slicedFvsPatchField< Type > Sliced
The sliced patch field type.
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
The calculated patch field type.
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.
Specialisation of fvsPatchField which creates the underlying fvsPatchField as a slice of the given co...
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