fvsPatchField.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) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2024 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::fvsPatchField
29 
30 Description
31  An abstract base class with a fat-interface to all derived classes
32  covering all possible ways in which they might be used.
33 
34  The first level of derivation is to basic patchFields which cover
35  zero-gradient, fixed-gradient, fixed-value and mixed conditions.
36 
37  The next level of derivation covers all the specialised typed with
38  specific evaluation procedures, particularly with respect to specific
39  fields.
40 
41 SourceFiles
42  fvsPatchField.C
43  fvsPatchFieldNew.C
44 
45 \*---------------------------------------------------------------------------*/
46 
47 #ifndef Foam_fvsPatchField_H
48 #define Foam_fvsPatchField_H
49 
50 #include "fvPatch.H"
51 #include "DimensionedField.H"
52 #include "fieldTypes.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Forward Declarations
60 class dictionary;
61 class objectRegistry;
62 class fvPatchFieldMapper;
63 class surfaceMesh;
64 
65 template<class Type> class fvsPatchField;
66 template<class Type> class calculatedFvsPatchField;
67 
68 template<class Type>
69 Ostream& operator<<(Ostream&, const fvsPatchField<Type>&);
70 
71 
72 /*---------------------------------------------------------------------------*\
73  Class fvsPatchFieldBase Declaration
74 \*---------------------------------------------------------------------------*/
75 
76 //- Template invariant parts for fvsPatchField
78 {
79  // Private Data
80 
81  //- Reference to patch
82  const fvPatch& patch_;
83 
84 protected:
85 
86  // Protected Member Functions
87 
88  //- Read dictionary entries.
89  // Useful when initially constructed without a dictionary
90  virtual void readDict(const dictionary& dict);
91 
92  //- Set updated state. This is a no-op for fvsPatchField
93  void setUpdated(bool state) noexcept
94  {}
95 
96  //- Set matrix manipulated state. This is a no-op for fvsPatchField
97  void setManipulated(bool state) noexcept
98  {}
99 
100 
101 public:
102 
103  //- Debug switch to disallow the use of generic fvsPatchField
104  static int disallowGenericPatchField;
105 
106  //- Runtime type information
107  TypeName("fvsPatchField");
108 
109 
110  // Constructors
111 
112  //- Construct from patch
113  explicit fvsPatchFieldBase(const fvPatch& p);
114 
115  //- Construct from patch and dictionary (unused)
116  fvsPatchFieldBase(const fvPatch& p, const dictionary& dict);
117 
118  //- Copy construct with new patch
119  fvsPatchFieldBase(const fvsPatchFieldBase& rhs, const fvPatch& p);
120 
121  //- Copy construct
123 
124 
125  //- Destructor
126  virtual ~fvsPatchFieldBase() = default;
127 
128 
129  // Static Member Functions
130 
131  //- The type name for \c empty patch fields
132  static const word& emptyType() noexcept
133  {
135  }
136 
137  //- The type name for \c calculated patch fields
138  static const word& calculatedType() noexcept
139  {
141  }
142 
143 
144  // Member Functions
145 
146  // Attributes
147 
148  //- True if the patch field fixes a value.
149  // Needed to check if a level has to be specified while solving
150  // Poissons equations.
151  virtual bool fixesValue() const
152  {
153  return false;
154  }
155 
156  //- True if the patch field is coupled
157  virtual bool coupled() const
158  {
159  return false;
160  }
161 
163  // Access
164 
165  //- The associated objectRegistry
166  const objectRegistry& db() const;
167 
168  //- Return the patch
169  const fvPatch& patch() const noexcept
170  {
171  return patch_;
172  }
173 
174 
175  // Solution
176 
177  //- True if the boundary condition has already been updated.
178  //- This is always true for fvsPatchField
179  bool updated() const noexcept
180  {
181  return true;
182  }
183 
184  //- True if the matrix has already been manipulated
185  bool manipulatedMatrix() const noexcept
186  {
187  return false;
188  }
189 
190 
191  // Check
192 
193  //- Check that patches are identical
194  void checkPatch(const fvsPatchFieldBase& rhs) const;
195 };
196 
197 
198 /*---------------------------------------------------------------------------*\
199  Class fvsPatchField Declaration
200 \*---------------------------------------------------------------------------*/
201 
202 template<class Type>
203 class fvsPatchField
204 :
205  public fvsPatchFieldBase,
206  public Field<Type>
207 {
208 public:
209 
210  // Public Data Types
211 
212  //- The patch type for the patch field
213  typedef fvPatch Patch;
215  //- The value_type for the patch field
216  typedef Type value_type;
217 
218  //- The internal field type associated with the patch field
220 
221  //- Type for a \em calculated patch
223 
224 
225 private:
226 
227  // Private Data
228 
229  //- Reference to internal field
230  const DimensionedField<Type, surfaceMesh>& internalField_;
231 
232 
233 protected:
234 
235  // Protected Member Functions
236 
237  //- Read the "value" entry into \c *this.
238  // The reading can be optional (default), mandatory etc.
239  // \returns True on success
240  bool readValueEntry
241  (
242  const dictionary& dict,
244  );
245 
246  //- Write \c *this field as a "value" entry
247  void writeValueEntry(Ostream& os) const
248  {
249  Field<Type>::writeEntry("value", os);
250  }
251 
252 
253 public:
255  // Declare run-time constructor selection tables
256 
258  (
261  patch,
262  (
263  const fvPatch& p,
265  ),
266  (p, iF)
267  );
268 
270  (
271  tmp,
273  patchMapper,
274  (
275  const fvsPatchField<Type>& ptf,
276  const fvPatch& p,
278  const fvPatchFieldMapper& m
279  ),
280  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
281  );
282 
284  (
285  tmp,
287  dictionary,
288  (
289  const fvPatch& p,
291  const dictionary& dict
292  ),
293  (p, iF, dict)
294  );
295 
296 
297  // Constructors
298 
299  //- Construct from patch and internal field
301  (
302  const fvPatch&,
304  );
305 
306  //- Construct from patch, internal field and value
308  (
309  const fvPatch&,
311  const Type& value
312  );
313 
314  //- Construct from patch, internal field and patch field
316  (
317  const fvPatch&,
319  const Field<Type>& pfld
320  );
321 
322  //- Construct from patch, internal field and patch field
324  (
325  const fvPatch&,
327  Field<Type>&& pfld
328  );
329 
330  //- Construct from patch, internal field and dictionary
332  (
333  const fvPatch&,
335  const dictionary& dict,
338  );
339 
340  //- Construct, forwarding to readOption variant
342  (
343  const fvPatch& p,
345  const dictionary& dict,
346  const bool needValue
347  )
348  :
350  (
351  p, iF, dict,
352  (needValue? IOobjectOption::MUST_READ : IOobjectOption::NO_READ)
353  )
354  {}
355 
356  //- Construct by mapping the given fvsPatchField onto a new patch
358  (
359  const fvsPatchField<Type>&,
360  const fvPatch&,
362  const fvPatchFieldMapper&
363  );
364 
365  //- Construct as copy
367 
368  //- Construct as copy setting internal field reference
370  (
371  const fvsPatchField<Type>&,
373  );
374 
375  //- Clone patch field with its own internal field reference
376  virtual tmp<fvsPatchField<Type>> clone() const
377  {
379  (
380  new fvsPatchField<Type>(*this, this->internalField_)
381  );
382  }
383 
384  //- Clone with an internal field reference
385  virtual tmp<fvsPatchField<Type>> clone
386  (
387  const DimensionedField<Type, surfaceMesh>& iF
388  ) const
389  {
390  return tmp<fvsPatchField<Type>>
391  (
392  new fvsPatchField<Type>(*this, iF)
393  );
394  }
395 
396 
397  // Factory Methods
398 
399  //- Clone a patch field, optionally with internal field reference etc.
400  template<class DerivedPatchField, class... Args>
401  static tmp<fvsPatchField<Type>> Clone
402  (
403  const DerivedPatchField& pf,
404  Args&&... args
405  )
406  {
407  return tmp<fvsPatchField<Type>>
408  (
409  new DerivedPatchField(pf, std::forward<Args>(args)...)
410  );
411  }
412 
413  //- Return a pointer to a new patchField created on freestore given
414  // patch and internal field
415  // (does not set the patch field values)
417  (
418  const word& patchFieldType,
419  const fvPatch&,
421  );
422 
423  //- Return a pointer to a new patchField created on freestore given
424  // patch and internal field
425  // (does not set the patch field values)
426  // Allows override of constraint type
428  (
429  const word& patchFieldType,
430  const word& actualPatchType,
431  const fvPatch&,
433  );
434 
435  //- Return a pointer to a new patchField created on freestore from
436  // a given fvsPatchField mapped onto a new patch
438  (
439  const fvsPatchField<Type>&,
440  const fvPatch&,
442  const fvPatchFieldMapper&
443  );
444 
445  //- Return a pointer to a new patchField created on freestore
446  // from dictionary
448  (
449  const fvPatch&,
451  const dictionary&
452  );
453 
454  //- Return a pointer to a new calculatedFvsPatchField created on
455  // freestore without setting patchField values
457  (
458  const fvPatch& p
459  );
460 
461  //- Return a pointer to a new calculatedFvsPatchField created on
462  // freestore without setting patchField values
463  template<class AnyType>
465  (
466  const fvsPatchField<AnyType>& pf
467  );
468 
469 
470  //- Destructor
471  virtual ~fvsPatchField() = default;
472 
473 
474  // Member Functions
475 
476  // Access
477 
478  //- Return const-reference to the dimensioned internal field
480  const noexcept
481  {
482  return internalField_;
483  }
484 
485  //- Return const-reference to the internal field values
486  const Field<Type>& primitiveField() const noexcept
487  {
488  return internalField_;
489  }
490 
491 
492  // Mapping Functions
493 
494  //- Map (and resize as needed) from self given a mapping object
495  virtual void autoMap
496  (
497  const fvPatchFieldMapper&
498  );
499 
500  //- Reverse map the given fvsPatchField onto this fvsPatchField
501  virtual void rmap
502  (
503  const fvsPatchField<Type>&,
504  const labelList&
505  );
506 
507 
508  // Evaluation Functions
509 
510  //- Initialise the evaluation of the patch field
511  virtual void initEvaluate
512  (
513  const Pstream::commsTypes commsType =
515  )
516  {}
517 
518  //- Evaluate the patch field, sets Updated to false
519  virtual void evaluate
520  (
521  const Pstream::commsTypes commsType =
523  )
524  {}
525 
526  //- Initialise the evaluation of the patch field after a local
527  // operation
528  virtual void initEvaluateLocal
529  (
530  const Pstream::commsTypes commsType =
532  )
533  {}
534 
535  //- Evaluate the patch field after a local operation (e.g. *=)
536  virtual void evaluateLocal
537  (
538  const Pstream::commsTypes commsType =
540  )
541  {}
542 
543 
544  //- Write the patch "type"
545  virtual void write(Ostream& os) const;
546 
547  //- Check against given patch field
548  void check(const fvsPatchField<Type>&) const;
549 
550 
551  // Member Operators
552 
553  virtual void operator=(const UList<Type>&);
554 
555  virtual void operator=(const fvsPatchField<Type>&);
556  virtual void operator+=(const fvsPatchField<Type>&);
557  virtual void operator-=(const fvsPatchField<Type>&);
558  virtual void operator*=(const fvsPatchField<scalar>&);
559  virtual void operator/=(const fvsPatchField<scalar>&);
560 
561  virtual void operator+=(const Field<Type>&);
562  virtual void operator-=(const Field<Type>&);
563 
564  virtual void operator*=(const Field<scalar>&);
565  virtual void operator/=(const Field<scalar>&);
566 
567  virtual void operator=(const Type&);
568  virtual void operator+=(const Type&);
569  virtual void operator-=(const Type&);
570  virtual void operator*=(const scalar);
571  virtual void operator/=(const scalar);
572 
573 
574  // Force an assignment irrespective of form of patch
575 
576  virtual void operator==(const fvsPatchField<Type>&);
577  virtual void operator==(const Field<Type>&);
578  virtual void operator==(const Type&);
580  // Prevent automatic comparison rewriting (c++20)
581  bool operator!=(const fvsPatchField<Type>&) const = delete;
582  bool operator!=(const Field<Type>&) const = delete;
583  bool operator!=(const Type&) const = delete;
584 
585 
586  // Ostream Operator
587 
588  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
589 };
590 
591 
592 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
593 
594 } // End namespace Foam
595 
596 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
597 
598 #ifdef NoRepository
599  #include "fvsPatchField.C"
600  #include "fvsPatchFieldNew.C"
601  #include "calculatedFvsPatchField.H"
602 #endif
603 
604 // Runtime selection macros
605 #include "fvsPatchFieldMacros.H"
606 
607 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
608 
609 #endif
610 
611 // ************************************************************************* //
virtual void operator*=(const fvsPatchField< scalar > &)
void setManipulated(bool state) noexcept
Set matrix manipulated state. This is a no-op for fvsPatchField.
dictionary dict
static const word & emptyType() noexcept
The type name for empty patch fields.
virtual ~fvsPatchField()=default
Destructor.
const DimensionedField< Type, surfaceMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
commsTypes
Communications types.
Definition: UPstream.H:77
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
static tmp< fvsPatchField< Type > > Clone(const DerivedPatchField &pf, Args &&... args)
Clone a patch field, optionally with internal field reference etc.
virtual void initEvaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Initialise the evaluation of the patch field after a local.
const Field< Type > & primitiveField() const noexcept
Return const-reference to the internal field values.
static int disallowGenericPatchField
Debug switch to disallow the use of generic fvsPatchField.
virtual void operator==(const fvsPatchField< Type > &)
bool operator!=(const fvsPatchField< Type > &) const =delete
TypeName("fvsPatchField")
Runtime type information.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
const objectRegistry & db() const
The associated objectRegistry.
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:720
static const word & calculatedType() noexcept
The type name for calculated patch fields.
const fvPatch & patch() const noexcept
Return the patch.
DimensionedField< Type, surfaceMesh > Internal
The internal field type associated with the patch field.
calculatedFvsPatchField< Type > Calculated
Type for a calculated patch.
const word calculatedType
A calculated patch field type.
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
Definition: fvsPatchField.C:32
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field, sets Updated to false.
virtual void operator/=(const fvsPatchField< scalar > &)
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
void check(const fvsPatchField< Type > &) const
Check against given patch field.
static tmp< fvsPatchField< Type > > NewCalculatedType(const fvPatch &p)
Return a pointer to a new calculatedFvsPatchField created on.
A FieldMapper for finite-volume patch fields.
declareRunTimeSelectionTable(tmp, fvsPatchField, patch,(const fvPatch &p, const DimensionedField< Type, surfaceMesh > &iF),(p, iF))
fvsPatchFieldBase(const fvPatch &p)
Construct from patch.
fvsPatchField(const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Construct from patch and internal field.
Definition: fvsPatchField.C:65
virtual void readDict(const dictionary &dict)
Read dictionary entries.
void checkPatch(const fvsPatchFieldBase &rhs) const
Check that patches are identical.
Macros for creating fvsPatchField types.
virtual void operator-=(const fvsPatchField< Type > &)
fvPatch Patch
The patch type for the patch field.
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
virtual ~fvsPatchFieldBase()=default
Destructor.
const word emptyType
An empty patch field type.
OBJstream os(runTime.globalPath()/outputName)
virtual void rmap(const fvsPatchField< Type > &, const labelList &)
Reverse map the given fvsPatchField onto this fvsPatchField.
virtual bool coupled() const
True if the patch field is coupled.
virtual void write(Ostream &os) const
Write the patch "type".
Template invariant parts for fvsPatchField.
Definition: fvsPatchField.H:74
virtual void operator+=(const fvsPatchField< Type > &)
bool manipulatedMatrix() const noexcept
True if the matrix has already been manipulated.
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Initialise the evaluation of the patch field.
Type value_type
The value_type for the patch field.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void operator=(const UList< Type > &)
virtual void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field after a local operation (e.g. *=)
void setUpdated(bool state) noexcept
Set updated state. This is a no-op for fvsPatchField.
Definition: fvsPatchField.H:97
Reading is optional [identical to READ_IF_PRESENT].
This boundary condition is not designed to be evaluated; it is assumed that the value is assigned via...
List< label > labelList
A List of labels.
Definition: List.H:62
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Registry of regIOobjects.
"buffered" : (MPI_Bsend, MPI_Recv)
bool updated() const noexcept
True if the boundary condition has already been updated. This is always true for fvsPatchField.
Foam::argList args(argc, argv)
An abstract base class with a fat-interface to all derived classes covering all possible ways in whic...
virtual bool fixesValue() const
True if the patch field fixes a value.
virtual tmp< fvsPatchField< Type > > clone() const
Clone patch field with its own internal field reference.
Namespace for OpenFOAM.
static tmp< fvsPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, surfaceMesh > &)
Return a pointer to a new patchField created on freestore given.
readOption
Enumeration defining read preferences.