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-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::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  // Private Data
209 
210  //- Reference to internal field
211  const DimensionedField<Type, surfaceMesh>& internalField_;
212 
213 protected:
215  // Protected Member Functions
216 
217  //- Read the "value" entry into \c *this.
218  // The reading can be optional (default), mandatory etc.
219  // \returns True on success
220  bool readValueEntry
221  (
222  const dictionary& dict,
224  );
225 
226  //- Write \c *this field as a "value" entry
227  void writeValueEntry(Ostream& os) const
228  {
229  Field<Type>::writeEntry("value", os);
230  }
231 
232 
233 public:
234 
235  //- The internal field type associated with the patch field
237 
238  //- The patch type for the patch field
239  typedef fvPatch Patch;
240 
241  //- Type for a \em calculated patch
243 
244 
245  // Declare run-time constructor selection tables
246 
248  (
249  tmp,
251  patch,
252  (
253  const fvPatch& p,
255  ),
256  (p, iF)
257  );
258 
260  (
261  tmp,
263  patchMapper,
264  (
265  const fvsPatchField<Type>& ptf,
266  const fvPatch& p,
268  const fvPatchFieldMapper& m
269  ),
270  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
271  );
272 
274  (
275  tmp,
277  dictionary,
278  (
279  const fvPatch& p,
281  const dictionary& dict
282  ),
283  (p, iF, dict)
284  );
285 
286 
287  // Constructors
288 
289  //- Construct from patch and internal field
291  (
292  const fvPatch&,
294  );
295 
296  //- Construct from patch, internal field and value
298  (
299  const fvPatch&,
301  const Type& value
302  );
303 
304  //- Construct from patch, internal field and patch field
306  (
307  const fvPatch&,
309  const Field<Type>& pfld
310  );
311 
312  //- Construct from patch, internal field and patch field
314  (
315  const fvPatch&,
317  Field<Type>&& pfld
318  );
319 
320  //- Construct from patch, internal field and dictionary
322  (
323  const fvPatch&,
325  const dictionary& dict,
328  );
329 
330  //- Construct, forwarding to readOption variant
332  (
333  const fvPatch& p,
335  const dictionary& dict,
336  const bool valueReqd
337  )
338  :
340  (
341  p, iF, dict,
342  (valueReqd? IOobjectOption::MUST_READ : IOobjectOption::NO_READ)
343  )
344  {}
345 
346  //- Construct by mapping the given fvsPatchField onto a new patch
348  (
349  const fvsPatchField<Type>&,
350  const fvPatch&,
352  const fvPatchFieldMapper&
353  );
354 
355  //- Construct as copy
357 
358  //- Construct as copy setting internal field reference
360  (
361  const fvsPatchField<Type>&,
363  );
364 
365  //- Construct and return a clone
366  virtual tmp<fvsPatchField<Type>> clone() const
367  {
368  return tmp<fvsPatchField<Type>>::New(*this);
369  }
370 
371  //- Construct and return a clone setting internal field reference
372  virtual tmp<fvsPatchField<Type>> clone
373  (
374  const DimensionedField<Type, surfaceMesh>& iF
375  ) const
376  {
377  return tmp<fvsPatchField<Type>>::New(*this, iF);
378  }
379 
380 
381  // Selectors
382 
383  //- Return a pointer to a new patchField created on freestore given
384  // patch and internal field
385  // (does not set the patch field values)
386  static tmp<fvsPatchField<Type>> New
387  (
388  const word& patchFieldType,
389  const fvPatch&,
390  const DimensionedField<Type, surfaceMesh>&
391  );
392 
393  //- Return a pointer to a new patchField created on freestore given
394  // patch and internal field
395  // (does not set the patch field values)
396  // Allows override of constraint type
398  (
399  const word& patchFieldType,
400  const word& actualPatchType,
401  const fvPatch&,
403  );
404 
405  //- Return a pointer to a new patchField created on freestore from
406  // a given fvsPatchField mapped onto a new patch
408  (
409  const fvsPatchField<Type>&,
410  const fvPatch&,
412  const fvPatchFieldMapper&
413  );
414 
415  //- Return a pointer to a new patchField created on freestore
416  // from dictionary
418  (
419  const fvPatch&,
421  const dictionary&
422  );
423 
424  //- Return a pointer to a new calculatedFvsPatchField created on
425  // freestore without setting patchField values
427  (
428  const fvPatch&
429  );
430 
431  //- Return a pointer to a new calculatedFvsPatchField created on
432  // freestore without setting patchField values
433  template<class Type2>
435  (
436  const fvsPatchField<Type2>&
437  );
439 
440  //- Destructor
441  virtual ~fvsPatchField() = default;
442 
443 
444  // Member Functions
445 
446  // Access
448  //- Return const-reference to the dimensioned internal field
450  const noexcept
451  {
452  return internalField_;
453  }
454 
455  //- Return const-reference to the internal field values
456  const Field<Type>& primitiveField() const noexcept
457  {
458  return internalField_;
459  }
460 
461 
462  // Mapping Functions
463 
464  //- Map (and resize as needed) from self given a mapping object
465  virtual void autoMap
466  (
467  const fvPatchFieldMapper&
468  );
469 
470  //- Reverse map the given fvsPatchField onto this fvsPatchField
471  virtual void rmap
472  (
473  const fvsPatchField<Type>&,
474  const labelList&
475  );
476 
477 
478  // Evaluation Functions
479 
480  //- Initialise the evaluation of the patch field
481  virtual void initEvaluate
482  (
483  const Pstream::commsTypes commsType =
485  )
486  {}
487 
488  //- Evaluate the patch field, sets Updated to false
489  virtual void evaluate
490  (
491  const Pstream::commsTypes commsType =
493  )
494  {}
495 
496  //- Initialise the evaluation of the patch field after a local
497  // operation
498  virtual void initEvaluateLocal
499  (
500  const Pstream::commsTypes commsType =
502  )
503  {}
504 
505  //- Evaluate the patch field after a local operation (e.g. *=)
506  virtual void evaluateLocal
507  (
508  const Pstream::commsTypes commsType =
510  )
511  {}
512 
513 
514  //- Write
515  virtual void write(Ostream& os) const;
516 
517  //- Check against given patch field
518  void check(const fvsPatchField<Type>&) const;
519 
520 
521  // Member Operators
522 
523  virtual void operator=(const UList<Type>&);
524 
525  virtual void operator=(const fvsPatchField<Type>&);
526  virtual void operator+=(const fvsPatchField<Type>&);
527  virtual void operator-=(const fvsPatchField<Type>&);
528  virtual void operator*=(const fvsPatchField<scalar>&);
529  virtual void operator/=(const fvsPatchField<scalar>&);
530 
531  virtual void operator+=(const Field<Type>&);
532  virtual void operator-=(const Field<Type>&);
533 
534  virtual void operator*=(const Field<scalar>&);
535  virtual void operator/=(const Field<scalar>&);
536 
537  virtual void operator=(const Type&);
538  virtual void operator+=(const Type&);
539  virtual void operator-=(const Type&);
540  virtual void operator*=(const scalar);
541  virtual void operator/=(const scalar);
542 
543 
544  // Force an assignment irrespective of form of patch
546  virtual void operator==(const fvsPatchField<Type>&);
547  virtual void operator==(const Field<Type>&);
548  virtual void operator==(const Type&);
549 
550  // Prevent automatic comparison rewriting (c++20)
551  bool operator!=(const fvsPatchField<Type>&) const = delete;
552  bool operator!=(const Field<Type>&) const = delete;
553  bool operator!=(const Type&) const = delete;
555 
556  // Ostream Operator
557 
558  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
559 };
560 
561 
562 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
563 
564 } // End namespace Foam
565 
566 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
567 
568 #ifdef NoRepository
569  #include "fvsPatchField.C"
570  #include "fvsPatchFieldNew.C"
571  #include "calculatedFvsPatchField.H"
572 #endif
573 
574 // Runtime selection macros
575 #include "fvsPatchFieldMacros.H"
576 
577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
578 
579 #endif
580 
581 // ************************************************************************* //
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.
"blocking" : (MPI_Bsend, MPI_Recv)
virtual ~fvsPatchField()=default
Destructor.
const DimensionedField< Type, surfaceMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
virtual void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field after a local operation (e.g. *=)
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
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 void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
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.
static tmp< fvsPatchField< Type > > NewCalculatedType(const fvPatch &)
Return a pointer to a new calculatedFvsPatchField created on.
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::blocking)
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.
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.
virtual void initEvaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field after a local.
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.
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.
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...
Definition: areaFieldsFwd.H:42
virtual void operator=(const UList< Type > &)
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].
Foam::calculatedFvsPatchField.
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.
bool updated() const noexcept
True if the boundary condition has already been updated. This is always true for fvsPatchField.
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
Construct and return a clone.
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.