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-2023 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>
69 class calculatedFvsPatchField;
70 
71 template<class 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  dictionary,
125  (
126  const fvPatch& p,
128  const dictionary& dict
129  ),
130  (p, iF, dict)
131  );
132 
134  (
135  tmp,
137  patchMapper,
138  (
139  const fvsPatchField<Type>& ptf,
140  const fvPatch& p,
142  const fvPatchFieldMapper& m
143  ),
144  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
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  const bool valueRequired=true
172  );
173 
174  //- Construct by mapping the given fvsPatchField onto a new patch
176  (
177  const fvsPatchField<Type>&,
178  const fvPatch&,
180  const fvPatchFieldMapper&,
181  const bool mappingRequired=true
182  );
183 
184  //- Disallow copy without setting internal field reference
185  fvsPatchField(const fvsPatchField<Type>&) = delete;
186 
187  //- Disallow clone without setting internal field reference
189  {
190  // Temporarily reinstate the clone() function pending a rewrite of
191  // the mapping of surfaceFields in fvMeshDistribute
193  (
194  new fvsPatchField<Type>(*this, internalField_)
195  );
196 
197  // NotImplemented;
198  // return tmp<fvsPatchField<Type>>(nullptr);
199  }
200 
201  //- Copy constructor setting internal field reference
203  (
204  const fvsPatchField<Type>&,
206  );
207 
208  //- Construct and return a clone setting internal field reference
210  (
212  ) const
213  {
215  (
216  new fvsPatchField<Type>(*this, iF)
217  );
218  }
219 
220  //- Construct and return a clone onto a new patch
221  // setting internal field reference
223  (
224  const fvPatch& patch,
226  ) const
227  {
229  (
230  new fvsPatchField<Type>(patch, iF, *this)
231  );
232  }
233 
234 
235  // Selectors
236 
237  //- Return a pointer to a new patchField created on freestore given
238  // patch and internal field
239  // (does not set the patch field values)
241  (
242  const word&,
243  const fvPatch&,
245  );
246 
247  //- Return a pointer to a new patchField created on freestore given
248  // patch and internal field
249  // (does not set the patch field values)
250  // Allows override of constraint type
252  (
253  const word&,
254  const word& actualPatchType,
255  const fvPatch&,
257  );
258 
259  //- Return a pointer to a new patchField created on freestore from
260  // a given fvsPatchField mapped onto a new patch
262  (
263  const fvsPatchField<Type>&,
264  const fvPatch&,
266  const fvPatchFieldMapper&
267  );
268 
269  //- Return a pointer to a new patchField created on freestore
270  // from dictionary
272  (
273  const fvPatch&,
275  const dictionary&
276  );
277 
278  //- Return a pointer to a new calculatedFvsPatchField created on
279  // freestore without setting patchField values
281  (
282  const fvPatch&
283  );
284 
285  //- Return a pointer to a new calculatedFvsPatchField created on
286  // freestore without setting patchField values
287  template<class Type2>
289  (
290  const fvsPatchField<Type2>&
291  );
292 
293 
294  //- Destructor
295  virtual ~fvsPatchField<Type>()
296  {}
297 
298 
299  // Member Functions
300 
301  // Attributes
302 
303  //- Return the type of the calculated for of fvsPatchField
304  static const word& calculatedType();
305 
306  //- Return true if this patch field fixes a value.
307  // Needed to check if a level has to be specified while solving
308  // Poissons equations.
309  virtual bool fixesValue() const
310  {
311  return false;
312  }
313 
314  //- Return true if this patch field is coupled
315  virtual bool coupled() const
316  {
317  return false;
318  }
319 
320  //- Return true if this overrides the underlying constraint type
321  bool overridesConstraint() const
322  {
323  if (type() == patch_.type())
324  {
325  return false;
326  }
327 
328  typename patchConstructorTable::iterator patchTypeCstrIter
329  = patchConstructorTablePtr_->find(patch_.type());
330 
331  return
332  patchTypeCstrIter
333  != patchConstructorTablePtr_->end();
334  }
335 
336 
337  // Access
338 
339  //- Return local objectRegistry
340  const objectRegistry& db() const;
341 
342  //- Return patch
343  const fvPatch& patch() const
344  {
345  return patch_;
346  }
347 
348  //- Return dimensioned internal field reference
350  internalField() const
351  {
352  return internalField_;
353  }
354 
355  //- Return internal field reference
356  const Field<Type>& primitiveField() const
357  {
358  return internalField_;
359  }
360 
361 
362  // Evaluation functions
363 
364  //- Initialise return of the patchField on the opposite patch of a
365  // coupled patch
366  virtual void initPatchNeighbourField
367  (
368  const Pstream::commsTypes commsType
369  ) const
370  {}
371 
372  //- Return patchField on the opposite patch of a coupled patch
374  (
375  const Pstream::commsTypes commsType
376  ) const
377  {
379  return *this;
380  }
381 
382 
383  // Mapping functions
384 
385  //- Map the given fvsPatchField onto this fvsPatchField
386  virtual void map
387  (
388  const fvsPatchField<Type>&,
389  const fvPatchFieldMapper&
390  );
391 
392  //- Reset the fvsPatchField to the given fvsPatchField
393  // Used for mesh to mesh mapping
394  virtual void reset(const fvsPatchField<Type>&);
395 
396 
397  //- Write
398  virtual void write(Ostream&) const;
399 
400 
401  // Check
402 
403  //- Check fvsPatchField<Type> against given fvsPatchField<Type>
404  void check(const fvsPatchField<Type>&) const;
405 
406 
407  // Member Operators
408 
409  virtual void operator=(const UList<Type>&);
410 
411  virtual void operator=(const fvsPatchField<Type>&);
412  virtual void operator+=(const fvsPatchField<Type>&);
413  virtual void operator-=(const fvsPatchField<Type>&);
414  virtual void operator*=(const fvsPatchField<scalar>&);
415  virtual void operator/=(const fvsPatchField<scalar>&);
416 
417  virtual void operator+=(const Field<Type>&);
418  virtual void operator-=(const Field<Type>&);
419 
420  virtual void operator*=(const Field<scalar>&);
421  virtual void operator/=(const Field<scalar>&);
422 
423  virtual void operator=(const Type&);
424  virtual void operator+=(const Type&);
425  virtual void operator-=(const Type&);
426  virtual void operator*=(const scalar);
427  virtual void operator/=(const scalar);
428 
429 
430  // Force an assignment irrespective of form of patch
431 
432  virtual void operator==(const fvsPatchField<Type>&);
433  virtual void operator==(const Field<Type>&);
434  virtual void operator==(const Type&);
435 
436 
437  // Ostream operator
438 
439  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
440 };
441 
442 
443 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
444 
445 } // End namespace Foam
446 
447 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
448 
449 #ifdef NoRepository
450  #include "fvsPatchField.C"
451  #include "calculatedFvsPatchField.H"
452 #endif
453 
454 
455 #define makeFvsPatchField(fvsPatchTypeField) \
456  defineNamedTemplateTypeNameAndDebug(fvsPatchTypeField, 0); \
457  template<> \
458  int fvsPatchTypeField::disallowGenericFvsPatchField \
459  ( \
460  debug::debugSwitch("disallowGenericFvsPatchField", 0) \
461  ); \
462  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patch); \
463  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, patchMapper); \
464  defineTemplateRunTimeSelectionTable(fvsPatchTypeField, dictionary);
465 
466 
467 #define addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
468  addToRunTimeSelectionTable \
469  ( \
470  PatchTypeField, \
471  typePatchTypeField, \
472  patch \
473  ); \
474  addToRunTimeSelectionTable \
475  ( \
476  PatchTypeField, \
477  typePatchTypeField, \
478  patchMapper \
479  ); \
480  addToRunTimeSelectionTable \
481  ( \
482  PatchTypeField, \
483  typePatchTypeField, \
484  dictionary \
485  );
486 
487 
488 // For non-templated patch fields
489 #define makeFvsPatchTypeField(PatchTypeField, typePatchTypeField) \
490  defineTypeNameAndDebug(typePatchTypeField, 0); \
491  addToFvsPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField)
492 
493 
494 // For templated patch fields
495 #define makeTemplateFvsPatchTypeField(fieldType, type) \
496  defineNamedTemplateTypeNameAndDebug \
497  ( \
498  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
499  0 \
500  ); \
501  addToFvsPatchFieldRunTimeSelection \
502  ( \
503  CAT3(fvsPatch, CAPITALIZE(fieldType), Field), \
504  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field) \
505  )
506 
507 
508 #define makeFvsPatchFields(type) \
509  FOR_ALL_FIELD_TYPES(makeTemplateFvsPatchTypeField, type)
510 
511 
512 #define makeFvsPatchFieldTypeName(fieldType, type) \
513  defineNamedTemplateTypeNameAndDebug \
514  ( \
515  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field), \
516  0 \
517  );
518 
519 
520 #define makeFvsPatchFieldTypeNames(type) \
521  FOR_ALL_FIELD_TYPES(makeFvsPatchFieldTypeName, type)
522 
523 
524 #define makeFvsPatchTypeFieldTypedef(fieldType, type) \
525  typedef type##FvsPatchField<fieldType> \
526  CAT4(type, FvsPatch, CAPITALIZE(fieldType), Field);
527 
528 
529 #define makeFvsPatchTypeFieldTypedefs(type) \
530  FOR_ALL_FIELD_TYPES(makeFvsPatchTypeFieldTypedef, type)
531 
532 
533 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
534 
535 #endif
536 
537 // ************************************************************************* //
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:82
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:160
Foam::fvPatchFieldMapper.
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:82
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:35
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.
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 > &)
calculatedFvsPatchField< Type > Calculated
Definition: fvsPatchField.H:95
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.
virtual void map(const fvsPatchField< Type > &, const fvPatchFieldMapper &)
Map the given fvsPatchField onto this 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:353
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const ensightPart &)
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