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 
107 public:
108 
109  //- Debug switch to disallow the use of generic faPatchField
110  static int disallowGenericPatchField;
111 
112  //- Runtime type information
113  TypeName("faPatchField");
114 
115 
116  // Constructors
117 
118  //- Construct from patch
119  explicit faPatchFieldBase(const faPatch& p);
120 
121  //- Construct from patch and patch type
122  explicit faPatchFieldBase(const faPatch& p, const word& patchType);
123 
124  //- Construct from patch and dictionary
125  faPatchFieldBase(const faPatch& p, const dictionary& dict);
126 
127  //- Copy construct with new patch
128  faPatchFieldBase(const faPatchFieldBase& rhs, const faPatch& p);
129 
130  //- Copy construct
132 
133 
134  //- Destructor
135  virtual ~faPatchFieldBase() = default;
136 
137 
138  // Static Member Functions
139 
140  //- The type name for \c empty patch fields
141  static const word& emptyType() noexcept
142  {
144  }
145 
146  //- The type name for \c calculated patch fields
147  static const word& calculatedType() noexcept
148  {
150  }
151 
152  //- The type name for \c extrapolatedCalculated patch fields
153  //- combines \c zero-gradient and \c calculated
154  static const word& extrapolatedCalculatedType() noexcept
155  {
157  }
158 
159  //- The type name for \c zeroGradient patch fields
160  static const word& zeroGradientType() noexcept
161  {
163  }
164 
165 
166  // Member Functions
167 
168  // Attributes
169 
170  //- True if the patch field fixes a value.
171  // Needed to check if a level has to be specified while solving
172  // Poissons equations.
173  virtual bool fixesValue() const
174  {
175  return false;
176  }
177 
178  //- True if the patch field is coupled
179  virtual bool coupled() const
180  {
181  return false;
182  }
184 
185  // Access
186 
187  //- The associated objectRegistry
188  const objectRegistry& db() const;
189 
190  //- Return the patch
191  const faPatch& patch() const noexcept
192  {
193  return patch_;
194  }
195 
196  //- The optional patch type
197  const word& patchType() const noexcept
198  {
199  return patchType_;
200  }
201 
202  //- The optional patch type
203  word& patchType() noexcept
204  {
205  return patchType_;
206  }
208 
209  // Solution
210 
211  //- True if the boundary condition has already been updated
212  bool updated() const noexcept
213  {
214  return updated_;
215  }
216 
217  //- Set updated state
218  void setUpdated(bool state) noexcept
219  {
220  updated_ = state;
221  }
222 
223 
224  // Check
225 
226  //- Check that patches are identical
227  void checkPatch(const faPatchFieldBase& rhs) const;
228 };
229 
230 
231 /*---------------------------------------------------------------------------*\
232  Class faPatchField Declaration
233 \*---------------------------------------------------------------------------*/
234 
235 template<class Type>
236 class faPatchField
237 :
238  public faPatchFieldBase,
239  public Field<Type>
240 {
241  // Private Data
242 
243  //- Reference to internal field
244  const DimensionedField<Type, areaMesh>& internalField_;
245 
246 protected:
248  // Protected Member Functions
249 
250  //- Read the "value" entry into \c *this.
251  // The reading can be optional (default), mandatory etc.
252  // \returns True on success
253  bool readValueEntry
254  (
255  const dictionary& dict,
257  );
259  //- Write *this field as a "value" entry
260  void writeValueEntry(Ostream& os) const
261  {
262  Field<Type>::writeEntry("value", os);
263  }
264 
265  //- Assign the patch field from the internal field
267 
268 
269 public:
270 
271  //- The internal field type associated with the patch field
273 
274  //- The patch type for the patch field
275  typedef faPatch Patch;
276 
277  //- Type for a \em calculated patch
279 
280 
281  // Declare run-time constructor selection tables
282 
284  (
285  tmp,
286  faPatchField,
287  patch,
288  (
289  const faPatch& p,
291  ),
292  (p, iF)
293  );
294 
296  (
297  tmp,
298  faPatchField,
299  patchMapper,
300  (
301  const faPatchField<Type>& ptf,
302  const faPatch& p,
304  const faPatchFieldMapper& m
305  ),
306  (dynamic_cast<const faPatchFieldType&>(ptf), p, iF, m)
307  );
308 
310  (
311  tmp,
312  faPatchField,
313  dictionary,
314  (
315  const faPatch& p,
318  ),
319  (p, iF, dict)
320  );
321 
322 
323  // Constructors
324 
325  //- Construct from patch and internal field
327  (
328  const faPatch&,
330  );
331 
332  //- Construct from patch, internal field and value
334  (
335  const faPatch&,
337  const Type& value
338  );
339 
340  //- Construct from patch, internal field and patch field
342  (
343  const faPatch&,
345  const Field<Type>& pfld
346  );
347 
348  //- Construct from patch, internal field and patch field
350  (
351  const faPatch&,
353  Field<Type>&& pfld
354  );
355 
356  //- Construct from patch, internal field and dictionary.
357  // \note older versions have always treated "value" as optional
359  (
360  const faPatch&,
362  const dictionary& dict,
365  );
366 
367  //- Construct by mapping the given faPatchField onto a new patch
369  (
370  const faPatchField<Type>&,
371  const faPatch&,
373  const faPatchFieldMapper&
374  );
375 
376  //- Construct as copy
378 
379  //- Construct as copy setting internal field reference
381  (
382  const faPatchField<Type>&,
384  );
385 
386  //- Construct and return a clone
387  virtual tmp<faPatchField<Type>> clone() const
388  {
389  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this));
390  }
391 
392  //- Construct and return a clone setting internal field reference
394  (
396  ) const
397  {
398  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this, iF));
399  }
400 
401 
402  // Selectors
403 
404  //- Return a pointer to a new patchField created on freestore given
405  //- patch and internal field
406  // (does not set the patch field values)
407  static tmp<faPatchField<Type>> New
408  (
409  const word& patchFieldType,
410  const word& actualPatchType,
411  const faPatch&,
412  const DimensionedField<Type, areaMesh>&
413  );
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 faPatch&,
422  const DimensionedField<Type, areaMesh>&
423  );
424 
425  //- Return a pointer to a new patchField created on freestore from
426  //- a given faPatchField mapped onto a new patch
427  static tmp<faPatchField<Type>> New
428  (
429  const faPatchField<Type>&,
430  const faPatch&,
431  const DimensionedField<Type, areaMesh>&,
432  const faPatchFieldMapper&
433  );
434 
435  //- Return a pointer to a new patchField created on freestore
436  //- from dictionary
437  static tmp<faPatchField<Type>> New
438  (
439  const faPatch&,
440  const DimensionedField<Type, areaMesh>&,
441  const dictionary&
442  );
443 
444  //- Return a pointer to a new calculatedFaPatchField created on
445  //- freestore without setting patchField values
446  template<class AnyType>
447  static tmp<faPatchField<Type>> NewCalculatedType
448  (
449  const faPatchField<AnyType>& pf
450  );
451 
452 
453  //- Destructor
454  virtual ~faPatchField() = default;
455 
456 
457  // Member Functions
458 
459  // Access
460 
461  //- Return const-reference to the dimensioned internal field
462  const DimensionedField<Type, areaMesh>& internalField() const noexcept
463  {
464  return internalField_;
465  }
466 
467  //- Return const-reference to the internal field values
468  const Field<Type>& primitiveField() const noexcept
469  {
470  return internalField_;
471  }
472 
473 
474  // Mapping
475 
476  //- Map (and resize as needed) from self given a mapping object
477  virtual void autoMap
478  (
479  const faPatchFieldMapper&
480  );
481 
482  //- Reverse map the given faPatchField onto this faPatchField
483  virtual void rmap
484  (
485  const faPatchField<Type>&,
486  const labelList&
487  );
488 
489 
490  // Evaluation
491 
492  //- Return patch-normal gradient
493  virtual tmp<Field<Type>> snGrad() const;
494 
495  //- Return internal field next to patch
496  virtual tmp<Field<Type>> patchInternalField() const;
497 
498  //- Extract internal field next to patch
499  // \param [out] pfld The extracted patch field.
500  virtual void patchInternalField(Field<Type>& pfld) const;
501 
502  //- Return patchField on the opposite patch of a coupled patch
503  virtual tmp<Field<Type>> patchNeighbourField() const
504  {
506  return *this;
507  }
508 
509  //- Update the coefficients associated with the patch field
510  // Sets Updated to true
511  virtual void updateCoeffs();
512 
513  //- Initialise the evaluation of the patch field
514  virtual void initEvaluate
515  (
516  const Pstream::commsTypes commsType =
518  )
519  {}
520 
521  //- Evaluate the patch field, sets updated() to false
522  virtual void evaluate
523  (
524  const Pstream::commsTypes commsType =
526  );
527 
528  //- Initialise the evaluation of the patch field after a local
529  // operation
530  virtual void initEvaluateLocal
531  (
532  const Pstream::commsTypes commsType =
534  )
535  {}
536 
537  //- Evaluate the patch field after a local operation (e.g. *=)
538  virtual void evaluateLocal
539  (
540  const Pstream::commsTypes commsType =
542  )
543  {}
544 
545  //- Return the matrix diagonal coefficients corresponding to the
546  //- evaluation of the value of this patchField with given weights
547  virtual tmp<Field<Type>> valueInternalCoeffs
548  (
549  const tmp<Field<scalar>>&
550  ) const
551  {
553  return *this;
554  }
555 
556  //- Return the matrix source coefficients corresponding to the
557  //- evaluation of the value of this patchField with given weights
558  virtual tmp<Field<Type>> valueBoundaryCoeffs
559  (
560  const tmp<Field<scalar>>&
561  ) const
562  {
564  return *this;
565  }
566 
567  //- Return the matrix diagonal coefficients corresponding to the
568  //- evaluation of the gradient of this patchField
569  virtual tmp<Field<Type>> gradientInternalCoeffs() const
570  {
572  return *this;
573  }
574 
575  //- Return the matrix source coefficients corresponding to the
576  //- evaluation of the gradient of this patchField
577  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
578  {
580  return *this;
581  }
582 
583 
584  // Other
585 
586  //- Write
587  virtual void write(Ostream& os) const;
588 
589  //- Check against given patch field
590  void check(const faPatchField<Type>&) const;
591 
592 
593  // Member Operators
594 
595  virtual void operator=(const UList<Type>&);
596 
597  virtual void operator=(const faPatchField<Type>&);
598  virtual void operator+=(const faPatchField<Type>&);
599  virtual void operator-=(const faPatchField<Type>&);
600  virtual void operator*=(const faPatchField<scalar>&);
601  virtual void operator/=(const faPatchField<scalar>&);
602 
603  virtual void operator+=(const Field<Type>&);
604  virtual void operator-=(const Field<Type>&);
605 
606  virtual void operator*=(const Field<scalar>&);
607  virtual void operator/=(const Field<scalar>&);
608 
609  virtual void operator=(const Type&);
610  virtual void operator+=(const Type&);
611  virtual void operator-=(const Type&);
612  virtual void operator*=(const scalar);
613  virtual void operator/=(const scalar);
614 
615 
616  // Force an assignment irrespective of form of patch
617 
618  virtual void operator==(const faPatchField<Type>&);
619  virtual void operator==(const Field<Type>&);
620  virtual void operator==(const Type&);
621 
622  // Prevent automatic comparison rewriting (c++20)
623  bool operator!=(const faPatchField<Type>&) const = delete;
624  bool operator!=(const Field<Type>&) const = delete;
625  bool operator!=(const Type&) const = delete;
626 
627 
628  // Ostream Operator
629 
630  friend Ostream& operator<< <Type>(Ostream&, const faPatchField<Type>&);
631 };
632 
633 
634 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
635 
636 } // End namespace Foam
638 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
639 
640 #ifdef NoRepository
641  #include "faPatchField.C"
642  #include "faPatchFieldNew.C"
643  #include "calculatedFaPatchField.H"
644  #include "zeroGradientFaPatchField.H"
645 #endif
646 
647 // Runtime selection macros
648 #include "faPatchFieldMacros.H"
649 
650 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
651 
652 #endif
653 
654 // ************************************************************************* //
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:231
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:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: faPatchField.C:194
virtual void initEvaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field after a local.
Definition: faPatchField.H:658
virtual tmp< faPatchField< Type > > clone() const
Construct and return a clone.
Definition: faPatchField.H:471
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:564
static const word & extrapolatedCalculatedType() noexcept
The type name for extrapolatedCalculated patch fields combines zero-gradient and calculated.
Definition: faPatchField.H:183
Template invariant parts for faPatchField.
Definition: faPatchField.H:77
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: faPatchField.H:317
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:720
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:692
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: faPatchField.H:637
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:338
virtual ~faPatchField()=default
Destructor.
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: faPatchField.H:191
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:266
Macros for creating faPatchField types.
bool operator!=(const faPatchField< Type > &) const =delete
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:207
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:620
DimensionedField< Type, areaMesh > Internal
The internal field type associated with the patch field.
Definition: faPatchField.H:333
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the evaluation of the gradient of this patch...
Definition: faPatchField.H:704
const Field< Type > & primitiveField() const noexcept
Return const-reference to the internal field values.
Definition: faPatchField.H:572
const word & patchType() const noexcept
The optional patch type.
Definition: faPatchField.H:239
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:258
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:679
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
static int disallowGenericPatchField
Debug switch to disallow the use of generic faPatchField.
Definition: faPatchField.H:119
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:174
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:166
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:714
virtual void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field after a local operation (e.g. *=)
Definition: faPatchField.H:668
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:215
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:686
const word extrapolatedCalculatedType
A combined zero-gradient and calculated patch field type.
calculatedFaPatchField< Type > Calculated
Type for a calculated patch.
Definition: faPatchField.H:343
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.