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  //- Optional patch type
85  // Used to allow specified boundary conditions to be applied
86  // to constraint patches by providing the constraint
87  // patch type as 'patchType'
88  word patchType_;
89 
90 
91 protected:
92 
93  // Protected Member Functions
94 
95  //- Read dictionary entries.
96  // Useful when initially constructed without a dictionary
97  virtual void readDict(const dictionary& dict);
98 
99 
100 public:
101 
102  //- Debug switch to disallow the use of generic fvsPatchField
103  static int disallowGenericPatchField;
104 
105  //- Runtime type information
106  TypeName("fvsPatchField");
107 
108 
109  // Constructors
111  //- Construct from patch
112  explicit fvsPatchFieldBase(const fvPatch& p);
113 
114  //- Construct from patch and dictionary (unused)
115  fvsPatchFieldBase(const fvPatch& p, const dictionary& dict);
116 
117  //- Copy construct with new patch
118  fvsPatchFieldBase(const fvsPatchFieldBase& rhs, const fvPatch& p);
119 
120  //- Copy construct
122 
123 
124  //- Destructor
125  virtual ~fvsPatchFieldBase() = default;
126 
127 
128  // Static Member Functions
129 
130  //- The type name for \c empty patch fields
131  static const word& emptyType() noexcept
132  {
134  }
135 
136  //- The type name for \c calculated patch fields
137  static const word& calculatedType() noexcept
138  {
140  }
141 
142 
143  // Member Functions
144 
145  // Attributes
146 
147  //- True if the value of the patch field is altered by assignment
148  virtual bool assignable() const
149  {
150  return true;
151  }
153  //- True if the patch field fixes a value.
154  // Needed to check if a level has to be specified while solving
155  // Poissons equations.
156  virtual bool fixesValue() const
157  {
158  return false;
159  }
161  //- True if the patch field is coupled
162  virtual bool coupled() const
163  {
164  return false;
165  }
166 
167 
168  // Access
169 
170  //- The associated objectRegistry
171  const objectRegistry& db() const;
172 
173  //- Return the patch
174  const fvPatch& patch() const noexcept
175  {
176  return patch_;
177  }
178 
179  //- The optional patch type
180  const word& patchType() const noexcept
181  {
182  return patchType_;
183  }
185  //- The optional patch type
187  {
188  return patchType_;
189  }
190 
191  //- True if the type does not correspond to the constraint type
192  virtual bool constraintOverride() const
193  {
194  return !patchType_.empty() && patchType_ != type();
195  }
196 
197 
198  // Solution
199 
200  //- True if the boundary condition has already been updated.
201  //- This is always true for fvsPatchField
202  bool updated() const noexcept
203  {
204  return true;
205  }
206 
207  //- Set updated state. This is a no-op for fvsPatchField
208  void setUpdated(bool state) noexcept
209  {}
210 
211  //- True if the matrix has already been manipulated
212  //- Always false for fvsPatchField
213  bool manipulatedMatrix() const noexcept
214  {
215  return false;
216  }
217 
218  //- Set matrix manipulated state.
219  //- This is a no-op for fvsPatchField
220  void setManipulated(bool state) noexcept
221  {}
222 
223 
224  // Check
225 
226  //- Check that patches are identical
227  void checkPatch(const fvsPatchFieldBase& rhs) const;
228 };
229 
230 
231 /*---------------------------------------------------------------------------*\
232  Class fvsPatchField Declaration
233 \*---------------------------------------------------------------------------*/
234 
235 template<class Type>
236 class fvsPatchField
237 :
238  public fvsPatchFieldBase,
239  public Field<Type>
240 {
241 public:
242 
243  // Public Data Types
245  //- The patch type for the patch field
246  typedef fvPatch Patch;
247 
248  //- The value_type for the patch field
249  typedef Type value_type;
250 
251  //- The component type for patch field
253 
254  //- The internal field type associated with the patch field
256 
257  //- Type for a \em calculated patch
260 
261 private:
262 
263  // Private Data
264 
265  //- Reference to internal field
266  const DimensionedField<Type, surfaceMesh>& internalField_;
267 
269 protected:
270 
271  // Protected Member Functions
272 
273  //- Read the "value" entry into \c *this.
274  // The reading can be optional (default), mandatory etc.
275  // \returns True on success
276  bool readValueEntry
277  (
278  const dictionary& dict,
280  );
281 
282  //- Write \c *this field as a "value" entry
283  void writeValueEntry(Ostream& os) const
284  {
285  Field<Type>::writeEntry("value", os);
286  }
287 
288 
289 public:
290 
291  // Declare run-time constructor selection tables
292 
294  (
295  tmp,
297  patch,
298  (
299  const fvPatch& p,
301  ),
302  (p, iF)
303  );
304 
306  (
307  tmp,
309  patchMapper,
310  (
311  const fvsPatchField<Type>& ptf,
312  const fvPatch& p,
314  const fvPatchFieldMapper& m
315  ),
316  (dynamic_cast<const fvsPatchFieldType&>(ptf), p, iF, m)
317  );
320  (
321  tmp,
323  dictionary,
324  (
325  const fvPatch& p,
327  const dictionary& dict
328  ),
329  (p, iF, dict)
330  );
331 
332 
333  // Constructors
334 
335  //- Construct from patch and internal field
337  (
338  const fvPatch&,
340  );
341 
342  //- Construct from patch, internal field and value
344  (
345  const fvPatch&,
347  const Type& value
348  );
349 
350  //- Construct from patch, internal field and patch field
352  (
353  const fvPatch&,
355  const Field<Type>& pfld
356  );
357 
358  //- Construct from patch, internal field and patch field
360  (
361  const fvPatch&,
363  Field<Type>&& pfld
364  );
365 
366  //- Construct from patch, internal field and dictionary
368  (
369  const fvPatch&,
371  const dictionary& dict,
374  );
375 
376  //- Construct, forwarding to readOption variant
378  (
379  const fvPatch& p,
381  const dictionary& dict,
382  const bool needValue
383  )
384  :
386  (
387  p, iF, dict,
388  (needValue? IOobjectOption::MUST_READ : IOobjectOption::NO_READ)
389  )
390  {}
391 
392  //- Construct by mapping the given fvsPatchField onto a new patch
394  (
395  const fvsPatchField<Type>&,
396  const fvPatch&,
398  const fvPatchFieldMapper&
399  );
400 
401  //- Construct as copy
403 
404  //- Construct as copy setting internal field reference
406  (
407  const fvsPatchField<Type>&,
409  );
410 
411  //- Clone patch field with its own internal field reference
412  virtual tmp<fvsPatchField<Type>> clone() const
413  {
415  (
416  new fvsPatchField<Type>(*this, this->internalField_)
417  );
418  }
419 
420  //- Clone with an internal field reference
421  virtual tmp<fvsPatchField<Type>> clone
422  (
423  const DimensionedField<Type, surfaceMesh>& iF
424  ) const
425  {
426  return tmp<fvsPatchField<Type>>
427  (
428  new fvsPatchField<Type>(*this, iF)
429  );
430  }
431 
432 
433  // Factory Methods
434 
435  //- Clone a patch field, optionally with internal field reference etc.
436  template<class DerivedPatchField, class... Args>
437  static tmp<fvsPatchField<Type>> Clone
438  (
439  const DerivedPatchField& pf,
440  Args&&... args
441  )
442  {
443  return tmp<fvsPatchField<Type>>
444  (
445  new DerivedPatchField(pf, std::forward<Args>(args)...)
446  );
447  }
448 
449  //- Return a pointer to a new patchField created on freestore given
450  // patch and internal field
451  // (does not set the patch field values)
452  static tmp<fvsPatchField<Type>> New
453  (
454  const word& patchFieldType,
455  const fvPatch&,
456  const DimensionedField<Type, surfaceMesh>&
457  );
458 
459  //- Return a pointer to a new patchField created on freestore given
460  // patch and internal field
461  // (does not set the patch field values)
462  // Allows override of constraint type
464  (
465  const word& patchFieldType,
466  const word& actualPatchType,
467  const fvPatch&,
469  );
470 
471  //- Return a pointer to a new patchField created on freestore from
472  // a given fvsPatchField mapped onto a new patch
474  (
475  const fvsPatchField<Type>&,
476  const fvPatch&,
478  const fvPatchFieldMapper&
479  );
480 
481  //- Return a pointer to a new patchField created on freestore
482  // from dictionary
484  (
485  const fvPatch&,
487  const dictionary&
488  );
489 
490  //- Return a pointer to a new calculatedFvsPatchField created on
491  // freestore without setting patchField values
493  (
494  const fvPatch& p
495  );
496 
497  //- Return a pointer to a new calculatedFvsPatchField created on
498  // freestore without setting patchField values
499  template<class AnyType>
501  (
502  const fvsPatchField<AnyType>& pf
503  );
504 
505 
506  //- Destructor
507  virtual ~fvsPatchField() = default;
508 
509 
510  // Member Functions
512  // Access
513 
514  //- Return const-reference to the dimensioned internal field
516  const noexcept
517  {
518  return internalField_;
519  }
520 
521  //- Return const-reference to the internal field values
522  const Field<Type>& primitiveField() const noexcept
523  {
524  return internalField_;
525  }
526 
527 
528  // Mapping Functions
530  //- Map (and resize as needed) from self given a mapping object
531  virtual void autoMap
532  (
533  const fvPatchFieldMapper&
534  );
535 
536  //- Reverse map the given fvsPatchField onto this fvsPatchField
537  virtual void rmap
538  (
539  const fvsPatchField<Type>&,
540  const labelList&
541  );
542 
543 
544  // Evaluation Functions
545 
546  //- Initialise the evaluation of the patch field
547  virtual void initEvaluate
548  (
549  const Pstream::commsTypes commsType =
551  )
552  {}
553 
554  //- Evaluate the patch field, sets Updated to false
555  virtual void evaluate
556  (
557  const Pstream::commsTypes commsType =
559  )
560  {}
561 
562  //- Initialise the evaluation of the patch field after a local
563  // operation
564  virtual void initEvaluateLocal
565  (
566  const Pstream::commsTypes commsType =
568  )
569  {}
570 
571  //- Evaluate the patch field after a local operation (e.g. *=)
572  virtual void evaluateLocal
573  (
574  const Pstream::commsTypes commsType =
576  )
577  {}
578 
579 
580  //- Write the patch "type"
581  virtual void write(Ostream& os) const;
582 
583  //- Check against given patch field
584  void check(const fvsPatchField<Type>&) const;
585 
586 
587  // Member Operators
588 
589  virtual void operator=(const UList<Type>&);
590 
591  virtual void operator=(const fvsPatchField<Type>&);
592  virtual void operator+=(const fvsPatchField<Type>&);
593  virtual void operator-=(const fvsPatchField<Type>&);
594  virtual void operator*=(const fvsPatchField<scalar>&);
595  virtual void operator/=(const fvsPatchField<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 fvsPatchField<Type>&);
613  virtual void operator==(const Field<Type>&);
614  virtual void operator==(const Type&);
615 
616  // Prevent automatic comparison rewriting (c++20)
617  bool operator!=(const fvsPatchField<Type>&) const = delete;
618  bool operator!=(const Field<Type>&) const = delete;
619  bool operator!=(const Type&) const = delete;
620 
621 
622  // Ostream Operator
623 
624  friend Ostream& operator<< <Type>(Ostream&, const fvsPatchField<Type>&);
625 };
626 
627 
628 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
629 
630 } // End namespace Foam
631 
632 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
633 
634 #ifdef NoRepository
635  #include "fvsPatchField.C"
636  #include "fvsPatchFieldNew.C"
638 #endif
639 
640 // Runtime selection macros
641 #include "fvsPatchFieldMacros.H"
642 
643 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
644 
645 #endif
646 
647 // ************************************************************************* //
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 bool assignable() const
True if the value of the patch field is altered by assignment.
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
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:61
const objectRegistry & db() const
The associated objectRegistry.
pTraits< Type >::cmptType cmptType
The component type for patch field.
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:754
static const word & calculatedType() noexcept
The type name for calculated patch fields.
const fvPatch & patch() const noexcept
Return the patch.
const word & patchType() const noexcept
The optional patch type.
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.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:801
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:63
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))
virtual bool constraintOverride() const
True if the type does not correspond to the constraint type.
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: scalarImpl.H:255
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 Always false for fvsPatchField.
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.
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...
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.