faPatchField.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2019-2023 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::faPatchField
29 
30 Description
31  faPatchField<Type> abstract base class. This class gives a fat-interface
32  to all derived classes covering all possible ways in which they might be
33  used. The first level of derivation is to basic patchFields which cover
34  zero-gradient, fixed-gradient, fixed-value and mixed conditions. The next
35  level of derivation covers all the specialised typed with specific
36  evaluation procedures, particularly with respect to specific fields.
37 
38 Author
39  Zeljko Tukovic, FMENA
40  Hrvoje Jasak, Wikki Ltd.
41 
42 SourceFiles
43  faPatchField.C
44  faPatchFieldBase.C
45  faPatchFieldNew.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef Foam_faPatchField_H
50 #define Foam_faPatchField_H
51 
52 #include "faPatch.H"
53 #include "DimensionedField.H"
54 #include "fieldTypes.H"
55 #include "scalarField.H"
56 
57 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
58 
59 namespace Foam
60 {
61 
62 // Forward Declarations
63 class dictionary;
64 class objectRegistry;
65 class faPatchFieldMapper;
66 class areaMesh;
67 
68 template<class Type> class faPatchField;
69 template<class Type> class calculatedFaPatchField;
70 template<class Type> class zeroGradientFaPatchField;
71 
72 template<class Type>
73 Ostream& operator<<(Ostream&, const faPatchField<Type>&);
74 
75 /*---------------------------------------------------------------------------*\
76  Class faPatchFieldBase Declaration
77 \*---------------------------------------------------------------------------*/
78 
79 //- Template invariant parts for faPatchField
80 class faPatchFieldBase
81 {
82  // Private Data
83 
84  //- Reference to patch
85  const faPatch& patch_;
86 
87  //- Update index used so that updateCoeffs is called only once during
88  //- the construction of the matrix
89  bool updated_;
90 
91  //- Optional patch type
92  // Used to allow specified boundary conditions to be applied
93  // to constraint patches by providing the constraint
94  // patch type as 'patchType'
95  word patchType_;
96 
97 
98 protected:
99 
100  // Protected Member Functions
101 
102  //- Read dictionary entries.
103  // Useful when initially constructed without a dictionary
104  virtual void readDict(const dictionary& dict);
105 
106  //- Set updated state
107  void setUpdated(bool state) noexcept
108  {
109  updated_ = state;
110  }
111 
112  //- Set matrix manipulated state. Currently a no-op for faPatchField.
113  void setManipulated(bool state) noexcept
114  {}
115 
117 public:
118 
119  //- Debug switch to disallow the use of generic faPatchField
120  static int disallowGenericPatchField;
121 
122  //- Runtime type information
123  TypeName("faPatchField");
125 
126  // Constructors
127 
128  //- Construct from patch
129  explicit faPatchFieldBase(const faPatch& p);
130 
131  //- Construct from patch and patch type
132  explicit faPatchFieldBase(const faPatch& p, const word& patchType);
134  //- Construct from patch and dictionary
135  faPatchFieldBase(const faPatch& p, const dictionary& dict);
136 
137  //- Copy construct with new patch
138  faPatchFieldBase(const faPatchFieldBase& rhs, const faPatch& p);
139 
140  //- Copy construct
142 
143 
144  //- Destructor
145  virtual ~faPatchFieldBase() = default;
146 
147 
148  // Static Member Functions
149 
150  //- The type name for \c empty patch fields
151  static const word& emptyType() noexcept
152  {
154  }
155 
156  //- The type name for \c calculated patch fields
157  static const word& calculatedType() noexcept
158  {
160  }
161 
162  //- The type name for \c extrapolatedCalculated patch fields
163  //- combines \c zero-gradient and \c calculated
164  static const word& extrapolatedCalculatedType() noexcept
165  {
167  }
168 
169  //- The type name for \c zeroGradient patch fields
170  static const word& zeroGradientType() noexcept
171  {
173  }
174 
175 
176  // Member Functions
177 
178  // Attributes
179 
180  //- True if the patch field fixes a value.
181  // Needed to check if a level has to be specified while solving
182  // Poissons equations.
183  virtual bool fixesValue() const
184  {
185  return false;
186  }
187 
188  //- True if the patch field is coupled
189  virtual bool coupled() const
190  {
191  return false;
192  }
193 
194 
195  // Access
196 
197  //- The associated objectRegistry
198  const objectRegistry& db() const;
199 
200  //- Return the patch
201  const faPatch& patch() const noexcept
202  {
203  return patch_;
204  }
206  //- The optional patch type
207  const word& patchType() const noexcept
208  {
209  return patchType_;
210  }
211 
212  //- The optional patch type
214  {
215  return patchType_;
216  }
217 
218 
219  // Solution
220 
221  //- True if the boundary condition has already been updated
222  bool updated() const noexcept
223  {
224  return updated_;
225  }
226 
227  //- True if the matrix has already been manipulated.
228  //- Currently ignored (always false) for faPatchField
230  {
231  return false;
232  }
233 
234 
235  // Check
236 
237  //- Check that patches are identical
238  void checkPatch(const faPatchFieldBase& rhs) const;
239 };
240 
241 
242 /*---------------------------------------------------------------------------*\
243  Class faPatchField Declaration
244 \*---------------------------------------------------------------------------*/
246 template<class Type>
247 class faPatchField
248 :
249  public faPatchFieldBase,
250  public Field<Type>
251 {
252  // Private Data
254  //- Reference to internal field
255  const DimensionedField<Type, areaMesh>& internalField_;
256 
257 protected:
258 
259  // Protected Member Functions
260 
261  //- Read the "value" entry into \c *this.
262  // The reading can be optional (default), mandatory etc.
263  // \returns True on success
264  bool readValueEntry
265  (
266  const dictionary& dict,
268  );
269 
270  //- Write *this field as a "value" entry
271  void writeValueEntry(Ostream& os) const
272  {
273  Field<Type>::writeEntry("value", os);
274  }
275 
276  //- Assign the patch field from the internal field
277  void extrapolateInternal();
278 
279 
280 public:
282  //- The internal field type associated with the patch field
284 
285  //- The patch type for the patch field
286  typedef faPatch Patch;
287 
288  //- Type for a \em calculated patch
290 
291 
292  // Declare run-time constructor selection tables
293 
295  (
296  tmp,
297  faPatchField,
298  patch,
299  (
300  const faPatch& p,
302  ),
303  (p, iF)
304  );
305 
307  (
308  tmp,
309  faPatchField,
310  patchMapper,
311  (
312  const faPatchField<Type>& ptf,
313  const faPatch& p,
315  const faPatchFieldMapper& m
316  ),
317  (dynamic_cast<const faPatchFieldType&>(ptf), p, iF, m)
318  );
319 
321  (
322  tmp,
323  faPatchField,
324  dictionary,
325  (
326  const faPatch& p,
328  const dictionary& dict
329  ),
330  (p, iF, dict)
331  );
333 
334  // Constructors
335 
336  //- Construct from patch and internal field
338  (
339  const faPatch&,
341  );
342 
343  //- Construct from patch, internal field and value
345  (
346  const faPatch&,
348  const Type& value
349  );
350 
351  //- Construct from patch, internal field and patch field
353  (
354  const faPatch&,
356  const Field<Type>& pfld
357  );
359  //- Construct from patch, internal field and patch field
361  (
362  const faPatch&,
364  Field<Type>&& pfld
365  );
366 
367  //- Construct from patch, internal field and dictionary.
368  // \note older versions have always treated "value" as optional
370  (
371  const faPatch&,
373  const dictionary& dict,
376  );
377 
378  //- Construct by mapping the given faPatchField onto a new patch
380  (
381  const faPatchField<Type>&,
382  const faPatch&,
384  const faPatchFieldMapper&
385  );
386 
387  //- Construct as copy
389 
390  //- Construct as copy setting internal field reference
392  (
393  const faPatchField<Type>&,
395  );
396 
397  //- Construct and return a clone
398  virtual tmp<faPatchField<Type>> clone() const
399  {
400  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this));
401  }
402 
403  //- Construct and return a clone setting internal field reference
405  (
407  ) const
408  {
409  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this, iF));
410  }
411 
412 
413  // Selectors
414 
415  //- Return a pointer to a new patchField created on freestore given
416  //- patch and internal field
417  // (does not set the patch field values)
418  static tmp<faPatchField<Type>> New
419  (
420  const word& patchFieldType,
421  const word& actualPatchType,
422  const faPatch&,
423  const DimensionedField<Type, areaMesh>&
424  );
425 
426  //- Return a pointer to a new patchField created on freestore given
427  //- patch and internal field
428  // (does not set the patch field values)
429  static tmp<faPatchField<Type>> New
430  (
431  const word& patchFieldType,
432  const faPatch&,
433  const DimensionedField<Type, areaMesh>&
434  );
435 
436  //- Return a pointer to a new patchField created on freestore from
437  //- a given faPatchField mapped onto a new patch
438  static tmp<faPatchField<Type>> New
439  (
440  const faPatchField<Type>&,
441  const faPatch&,
442  const DimensionedField<Type, areaMesh>&,
443  const faPatchFieldMapper&
444  );
445 
446  //- Return a pointer to a new patchField created on freestore
447  //- from dictionary
448  static tmp<faPatchField<Type>> New
449  (
450  const faPatch&,
451  const DimensionedField<Type, areaMesh>&,
452  const dictionary&
453  );
454 
455  //- Return a pointer to a new calculatedFaPatchField created on
456  //- freestore without setting patchField values
457  template<class AnyType>
458  static tmp<faPatchField<Type>> NewCalculatedType
459  (
460  const faPatchField<AnyType>& pf
461  );
462 
463 
464  //- Destructor
465  virtual ~faPatchField() = default;
466 
467 
468  // Member Functions
469 
470  // Access
471 
472  //- Return const-reference to the dimensioned internal field
473  const DimensionedField<Type, areaMesh>& internalField() const noexcept
474  {
475  return internalField_;
476  }
477 
478  //- Return const-reference to the internal field values
479  const Field<Type>& primitiveField() const noexcept
480  {
481  return internalField_;
482  }
483 
484 
485  // Mapping
487  //- Map (and resize as needed) from self given a mapping object
488  virtual void autoMap
489  (
490  const faPatchFieldMapper&
491  );
492 
493  //- Reverse map the given faPatchField onto this faPatchField
494  virtual void rmap
495  (
496  const faPatchField<Type>&,
497  const labelList&
498  );
499 
500 
501  // Evaluation
502 
503  //- Return patch-normal gradient
504  virtual tmp<Field<Type>> snGrad() const;
505 
506  //- Return internal field next to patch
507  virtual tmp<Field<Type>> patchInternalField() const;
508 
509  //- Extract internal field next to patch
510  // \param [out] pfld The extracted patch field.
511  virtual void patchInternalField(Field<Type>& pfld) const;
512 
513  //- Return patchField on the opposite patch of a coupled patch
514  virtual tmp<Field<Type>> patchNeighbourField() const
515  {
517  return *this;
518  }
519 
520  //- Update the coefficients associated with the patch field
521  // Sets Updated to true
522  virtual void updateCoeffs();
523 
524  //- Initialise the evaluation of the patch field
525  virtual void initEvaluate
526  (
527  const Pstream::commsTypes commsType =
529  )
530  {}
531 
532  //- Evaluate the patch field, sets updated() to false
533  virtual void evaluate
534  (
535  const Pstream::commsTypes commsType =
537  );
538 
539  //- Return the matrix diagonal coefficients corresponding to the
540  //- evaluation of the value of this patchField with given weights
541  virtual tmp<Field<Type>> valueInternalCoeffs
542  (
543  const tmp<Field<scalar>>&
544  ) const
545  {
547  return *this;
548  }
549 
550  //- Return the matrix source coefficients corresponding to the
551  //- evaluation of the value of this patchField with given weights
552  virtual tmp<Field<Type>> valueBoundaryCoeffs
553  (
554  const tmp<Field<scalar>>&
555  ) const
556  {
558  return *this;
559  }
560 
561  //- Return the matrix diagonal coefficients corresponding to the
562  //- evaluation of the gradient of this patchField
563  virtual tmp<Field<Type>> gradientInternalCoeffs() const
564  {
566  return *this;
567  }
568 
569  //- Return the matrix source coefficients corresponding to the
570  //- evaluation of the gradient of this patchField
571  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
572  {
574  return *this;
575  }
576 
577 
578  // Other
580  //- Write
581  virtual void write(Ostream& os) const;
582 
583  //- Check against given patch field
584  void check(const faPatchField<Type>&) const;
585 
586 
587  // Member Operators
588 
589  virtual void operator=(const UList<Type>&);
590 
591  virtual void operator=(const faPatchField<Type>&);
592  virtual void operator+=(const faPatchField<Type>&);
593  virtual void operator-=(const faPatchField<Type>&);
594  virtual void operator*=(const faPatchField<scalar>&);
595  virtual void operator/=(const faPatchField<scalar>&);
596 
597  virtual void operator+=(const Field<Type>&);
598  virtual void operator-=(const Field<Type>&);
599 
600  virtual void operator*=(const Field<scalar>&);
601  virtual void operator/=(const Field<scalar>&);
602 
603  virtual void operator=(const Type&);
604  virtual void operator+=(const Type&);
605  virtual void operator-=(const Type&);
606  virtual void operator*=(const scalar);
607  virtual void operator/=(const scalar);
608 
609 
610  // Force an assignment irrespective of form of patch
611 
612  virtual void operator==(const faPatchField<Type>&);
613  virtual void operator==(const Field<Type>&);
614  virtual void operator==(const Type&);
615 
616 
617  // Ostream Operator
618 
619  friend Ostream& operator<< <Type>(Ostream&, const faPatchField<Type>&);
620 };
621 
622 
623 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
624 
625 } // End namespace Foam
626 
627 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
628 
629 #ifdef NoRepository
630  #include "faPatchField.C"
631  #include "faPatchFieldNew.C"
632  #include "calculatedFaPatchField.H"
633  #include "zeroGradientFaPatchField.H"
634 #endif
636 // Runtime selection macros
637 #include "faPatchFieldMacros.H"
638 
639 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
640 
641 #endif
642 
643 // ************************************************************************* //
virtual void operator+=(const faPatchField< Type > &)
Definition: faPatchField.C:289
virtual void autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: faPatchField.C:216
static tmp< faPatchField< Type > > New(const word &patchFieldType, const word &actualPatchType, const faPatch &, const DimensionedField< Type, areaMesh > &)
Return a pointer to a new patchField created on freestore given patch and internal field...
dictionary dict
faPatchFieldBase(const faPatch &p)
Construct from patch.
TypeName("faPatchField")
Runtime type information.
virtual void operator-=(const faPatchField< Type > &)
Definition: faPatchField.C:300
"blocking" : (MPI_Bsend, MPI_Recv)
const faPatch & patch() const noexcept
Return the patch.
Definition: faPatchField.H:245
const word zeroGradientType
A zeroGradient patch field type.
void check(const faPatchField< Type > &) const
Check against given patch field.
Definition: faPatchField.C:187
virtual void write(Ostream &os) const
Write.
Definition: faPatchField.C:253
commsTypes
Communications types.
Definition: UPstream.H:74
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: faPatchField.C:194
virtual tmp< faPatchField< Type > > clone() const
Construct and return a clone.
Definition: faPatchField.H:486
virtual void readDict(const dictionary &dict)
Read dictionary entries.
declareRunTimeSelectionTable(tmp, faPatchField, patch,(const faPatch &p, const DimensionedField< Type, areaMesh > &iF),(p, iF))
const DimensionedField< Type, areaMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
Definition: faPatchField.H:579
static const word & extrapolatedCalculatedType() noexcept
The type name for extrapolatedCalculated patch fields combines zero-gradient and calculated.
Definition: faPatchField.H:197
Template invariant parts for faPatchField.
Definition: faPatchField.H:77
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: faPatchField.H:332
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:720
void setManipulated(bool state) noexcept
Set matrix manipulated state. Currently a no-op for faPatchField.
Definition: faPatchField.H:124
void extrapolateInternal()
Assign the patch field from the internal field.
Definition: faPatchField.C:60
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< Field< scalar >> &) const
Return the matrix source coefficients corresponding to the evaluation of the value of this patchField...
Definition: faPatchField.H:685
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: faPatchField.H:652
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
faPatch Patch
The patch type for the patch field.
Definition: faPatchField.H:353
virtual ~faPatchField()=default
Destructor.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: faPatchField.H:205
const objectRegistry & db() const
The associated objectRegistry.
const word calculatedType
A calculated patch field type.
void setUpdated(bool state) noexcept
Set updated state.
Definition: faPatchField.H:116
bool manipulatedMatrix() const noexcept
True if the matrix has already been manipulated. Currently ignored (always false) for faPatchField...
Definition: faPatchField.H:281
Macros for creating faPatchField types.
virtual void operator/=(const faPatchField< scalar > &)
Definition: faPatchField.C:322
virtual bool fixesValue() const
True if the patch field fixes a value.
Definition: faPatchField.H:221
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual tmp< Field< Type > > patchNeighbourField() const
Return patchField on the opposite patch of a coupled patch.
Definition: faPatchField.H:635
DimensionedField< Type, areaMesh > Internal
The internal field type associated with the patch field.
Definition: faPatchField.H:348
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the evaluation of the gradient of this patch...
Definition: faPatchField.H:697
const Field< Type > & primitiveField() const noexcept
Return const-reference to the internal field values.
Definition: faPatchField.H:587
const word & patchType() const noexcept
The optional patch type.
Definition: faPatchField.H:253
static tmp< faPatchField< Type > > NewCalculatedType(const faPatchField< AnyType > &pf)
Return a pointer to a new calculatedFaPatchField created on freestore without setting patchField valu...
bool updated() const noexcept
True if the boundary condition has already been updated.
Definition: faPatchField.H:272
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< Field< scalar >> &) const
Return the matrix diagonal coefficients corresponding to the evaluation of the value of this patchFie...
Definition: faPatchField.H:672
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
static int disallowGenericPatchField
Debug switch to disallow the use of generic faPatchField.
Definition: faPatchField.H:133
const word emptyType
An empty patch field type.
OBJstream os(runTime.globalPath()/outputName)
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
static const word & calculatedType() noexcept
The type name for calculated patch fields.
Definition: faPatchField.H:188
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch.
Definition: faPatchField.C:202
void checkPatch(const faPatchFieldBase &rhs) const
Check that patches are identical.
static const word & emptyType() noexcept
The type name for empty patch fields.
Definition: faPatchField.H:180
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
Definition: faPatchField.C:224
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets updated() to false.
Definition: faPatchField.C:241
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the evaluation of the gradient of this patchFi...
Definition: faPatchField.H:707
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: faPatchField.C:234
virtual void operator=(const UList< Type > &)
Definition: faPatchField.C:268
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual bool coupled() const
True if the patch field is coupled.
Definition: faPatchField.H:229
virtual void operator==(const faPatchField< Type > &)
Definition: faPatchField.C:423
Reading is optional [identical to READ_IF_PRESENT].
virtual ~faPatchFieldBase()=default
Destructor.
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
A FieldMapper for finite-area patch fields.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:666
const word extrapolatedCalculatedType
A combined zero-gradient and calculated patch field type.
calculatedFaPatchField< Type > Calculated
Type for a calculated patch.
Definition: faPatchField.H:358
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
Definition: faPatchField.C:30
Namespace for OpenFOAM.
faPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
Definition: faPatchField.C:70
virtual void operator*=(const faPatchField< scalar > &)
Definition: faPatchField.C:311
readOption
Enumeration defining read preferences.