faePatchField.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-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::faePatchField
29 
30 Description
31  faePatchField<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  faePatchField.C
44  faePatchFieldBase.C
45  faePatchFieldNew.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef Foam_faePatchField_H
50 #define Foam_faePatchField_H
51 
52 #include "faPatch.H"
53 #include "DimensionedField.H"
54 #include "fieldTypes.H"
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 
58 namespace Foam
59 {
60 
61 // Forward Declarations
62 class dictionary;
63 class objectRegistry;
64 class faPatchFieldMapper;
65 class edgeMesh;
66 
67 template<class Type> class faePatchField;
68 template<class Type> class calculatedFaePatchField;
69 
70 template<class Type>
71 Ostream& operator<<(Ostream&, const faePatchField<Type>&);
72 
73 
74 /*---------------------------------------------------------------------------*\
75  Class faePatchFieldBase Declaration
76 \*---------------------------------------------------------------------------*/
77 
78 //- Template invariant parts for faePatchField
80 {
81  // Private Data
82 
83  //- Reference to patch
84  const faPatch& patch_;
85 
86 protected:
87 
88  // Protected Member Functions
89 
90  //- Read dictionary entries.
91  // Useful when initially constructed without a dictionary
92  virtual void readDict(const dictionary& dict);
93 
94  //- Set updated state. This is a no-op for faePatchField
95  void setUpdated(bool state) noexcept
96  {}
97 
98  //- Set matrix manipulated state. This is a no-op for faePatchField
99  void setManipulated(bool state) noexcept
100  {}
101 
102 
103 public:
104 
105  //- Debug switch to disallow the use of generic faePatchField
106  static int disallowGenericPatchField;
107 
108  //- Runtime type information
109  TypeName("faePatchField");
110 
111 
112  // Constructors
113 
114  //- Construct from patch
115  explicit faePatchFieldBase(const faPatch& p);
116 
117  //- Construct from patch and patch type
118  explicit faePatchFieldBase(const faPatch& p, const word& patchType);
119 
120  //- Construct from patch and dictionary
121  faePatchFieldBase(const faPatch& p, const dictionary& dict);
122 
123  //- Copy construct with new patch
124  faePatchFieldBase(const faePatchFieldBase& rhs, const faPatch& p);
125 
126  //- Copy construct
128 
129 
130  //- Destructor
131  virtual ~faePatchFieldBase() = default;
132 
133 
134  // Static Member Functions
135 
136  //- The type name for \c empty patch fields
137  static const word& emptyType() noexcept
138  {
140  }
141 
142  //- The type name for \c calculated patch fields
143  static const word& calculatedType() noexcept
144  {
146  }
147 
148 
149  // Member Functions
150 
151  // Attributes
152 
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  }
160 
161  //- True if the patch field is coupled
162  virtual bool coupled() const
163  {
164  return false;
165  }
166 
167 
168  // Access
170  //- The associated objectRegistry
171  const objectRegistry& db() const;
172 
173  //- Return the patch
174  const faPatch& patch() const noexcept
175  {
176  return patch_;
177  }
178 
179 
180  // Solution
181 
182  //- True if the boundary condition has already been updated.
183  //- This is always true for faePatchField
184  bool updated() const noexcept
185  {
186  return true;
187  }
188 
189  //- True if the matrix has already been manipulated.
190  //- Currently ignored (always false) for faePatchField
191  bool manipulatedMatrix() const noexcept
192  {
193  return false;
194  }
195 
196 
197  // Check
198 
199  //- Check that patches are identical
200  void checkPatch(const faePatchFieldBase& rhs) const;
201 };
202 
203 
204 /*---------------------------------------------------------------------------*\
205  Class faePatchField Declaration
206 \*---------------------------------------------------------------------------*/
207 
208 template<class Type>
210 :
211  public faePatchFieldBase,
212  public Field<Type>
213 {
214 public:
215 
216  // Public Data Types
217 
218  //- The patch type for the patch field
219  typedef faPatch Patch;
220 
221  //- The value_type for the patch field
222  typedef Type value_type;
223 
224  //- The internal field type associated with the patch field
226 
227  //- Type for a \em calculated patch
229 
231 private:
232 
233  // Private Data
234 
235  //- Reference to internal field
236  const DimensionedField<Type, edgeMesh>& internalField_;
237 
238 protected:
239 
240  // Protected Member Functions
241 
242  //- Read the "value" entry into \c *this.
243  // The reading can be optional (default), mandatory etc.
244  // \returns True on success
245  bool readValueEntry
246  (
247  const dictionary& dict,
249  );
250 
251  //- Write \c *this field as a "value" entry
252  void writeValueEntry(Ostream& os) const
253  {
254  Field<Type>::writeEntry("value", os);
255  }
256 
257 
258 public:
259 
260  // Declare run-time constructor selection tables
261 
263  (
264  tmp,
266  patch,
267  (
268  const faPatch& p,
270  ),
271  (p, iF)
272  );
273 
275  (
276  tmp,
278  patchMapper,
279  (
280  const faePatchField<Type>& ptf,
281  const faPatch& p,
283  const faPatchFieldMapper& m
284  ),
285  (dynamic_cast<const faePatchFieldType&>(ptf), p, iF, m)
286  );
287 
289  (
290  tmp,
292  dictionary,
293  (
294  const faPatch& p,
296  const dictionary& dict
297  ),
298  (p, iF, dict)
299  );
300 
301 
302  // Constructors
303 
304  //- Construct from patch and internal field
306  (
307  const faPatch&,
309  );
310 
311  //- Construct from patch, internal field and value
313  (
314  const faPatch&,
316  const Type& value
317  );
318 
319  //- Construct from patch, internal field and patch field
321  (
322  const faPatch&,
324  const Field<Type>& pfld
325  );
326 
327  //- Construct from patch, internal field and patch field
329  (
330  const faPatch&,
332  Field<Type>&& pfld
333  );
334 
335  //- Construct from patch, internal field and dictionary
336  // \note older versions have always treated "value" as optional
338  (
339  const faPatch&,
341  const dictionary& dict,
344  );
345 
346  //- Construct by mapping the given faePatchField onto a new patch
348  (
349  const faePatchField<Type>&,
350  const faPatch&,
352  const faPatchFieldMapper&
353  );
354 
355  //- Construct as copy
357 
358  //- Construct as copy setting internal field reference
360  (
361  const faePatchField<Type>&,
363  );
364 
365  //- Clone patch field with its own internal field reference
366  virtual tmp<faePatchField<Type>> clone() const
367  {
369  (
370  new faePatchField<Type>(*this, this->internalField_)
371  );
372  }
373 
374  //- Clone with an internal field reference
376  (
378  ) const
379  {
380  return tmp<faePatchField<Type>>::New(*this, iF);
381  }
382 
383 
384  //- Destructor
385  virtual ~faePatchField() = default;
386 
387 
388  // Factory Methods
389 
390  //- Clone a patch field, optionally with internal field reference etc.
391  template<class DerivedPatchField, class... Args>
392  static tmp<faePatchField<Type>> Clone
393  (
394  const DerivedPatchField& pf,
395  Args&&... args
396  )
397  {
398  return tmp<faePatchField<Type>>
399  (
400  new DerivedPatchField(pf, std::forward<Args>(args)...)
401  );
402  }
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<faePatchField<Type>> New
408  (
409  const word& patchFieldType,
410  const faPatch&,
411  const DimensionedField<Type, edgeMesh>&
412  );
413 
414  //- Return a pointer to a new patchField created on freestore given
415  // patch and internal field
416  // (does not set the patch field values)
417  // Allows override of constraint type
418  static tmp<faePatchField<Type>> New
419  (
420  const word& patchFieldType,
421  const word& actualPatchType,
422  const faPatch&,
423  const DimensionedField<Type, edgeMesh>&
424  );
425 
426  //- Return a pointer to a new patchField created on freestore from
427  // a given faePatchField mapped onto a new patch
428  static tmp<faePatchField<Type>> New
429  (
430  const faePatchField<Type>&,
431  const faPatch&,
432  const DimensionedField<Type, edgeMesh>&,
433  const faPatchFieldMapper&
434  );
435 
436  //- Return a pointer to a new patchField created on freestore
437  // from dictionary
438  static tmp<faePatchField<Type>> New
439  (
440  const faPatch&,
442  const dictionary&
443  );
444 
445  //- Return a pointer to a new calculatedFaePatchField created on
446  // freestore without setting patchField values
448  (
449  const faPatch& p
450  );
451 
452  //- Return a pointer to a new calculatedFaePatchField created on
453  // freestore without setting patchField values
454  template<class AnyType>
456  (
457  const faePatchField<AnyType>& pf
458  );
459 
460 
461  // Member Functions
462 
463  // Access
464 
465  //- Return const-reference to the dimensioned internal field
467  {
468  return internalField_;
469  }
470 
471  //- Return const-reference to the internal field values
472  const Field<Type>& primitiveField() const noexcept
473  {
474  return internalField_;
475  }
476 
477 
478  // Evaluation Functions
479 
480  //- Initialise the evaluation of the patch field after a local
481  // operation
482  virtual void initEvaluateLocal
483  (
484  const Pstream::commsTypes commsType =
486  )
487  {}
488 
489  //- Evaluate the patch field after a local operation (e.g. *=)
490  virtual void evaluateLocal
491  (
492  const Pstream::commsTypes commsType =
494  )
495  {}
496 
497 
498  // Mapping
499 
500  //- Map (and resize as needed) from self given a mapping object
501  virtual void autoMap
502  (
503  const faPatchFieldMapper&
504  );
505 
506  //- Reverse map the given faePatchField onto this faePatchField
507  virtual void rmap
508  (
509  const faePatchField<Type>&,
510  const labelList&
511  );
512 
513 
514  // Evaluation Functions
515 
516  //- Initialise the evaluation of the patch field, generally a no-op
517  virtual void initEvaluate
518  (
520  )
521  {}
522 
523  //- Evaluate the patch field, generally a no-op
524  virtual void evaluate
525  (
527  )
528  {}
529 
530 
531  // Other
532 
533  //- Write
534  virtual void write(Ostream& os) const;
535 
536  //- Check against given patch field
537  void check(const faePatchField<Type>&) const;
538 
539 
540  // Member Operators
541 
542  virtual void operator=(const UList<Type>&);
543 
544  virtual void operator=(const faePatchField<Type>&);
545  virtual void operator+=(const faePatchField<Type>&);
546  virtual void operator-=(const faePatchField<Type>&);
547  virtual void operator*=(const faePatchField<scalar>&);
548  virtual void operator/=(const faePatchField<scalar>&);
549 
550  virtual void operator+=(const Field<Type>&);
551  virtual void operator-=(const Field<Type>&);
552 
553  virtual void operator*=(const Field<scalar>&);
554  virtual void operator/=(const Field<scalar>&);
555 
556  virtual void operator=(const Type&);
557  virtual void operator+=(const Type&);
558  virtual void operator-=(const Type&);
559  virtual void operator*=(const scalar);
560  virtual void operator/=(const scalar);
561 
562 
563  // Force an assignment irrespective of form of patch
564 
565  virtual void operator==(const faePatchField<Type>&);
566  virtual void operator==(const Field<Type>&);
567  virtual void operator==(const Type&);
568 
569  // Prevent automatic comparison rewriting (c++20)
570  bool operator!=(const faePatchField<Type>&) const = delete;
571  bool operator!=(const Field<Type>&) const = delete;
572  bool operator!=(const Type&) const = delete;
573 
574 
575  // Ostream Operator
576 
577  friend Ostream& operator<< <Type>(Ostream&, const faePatchField<Type>&);
578 };
579 
580 
581 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
582 
583 } // End namespace Foam
584 
585 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
586 
587 #ifdef NoRepository
588  #include "faePatchField.C"
590  #include "calculatedFaePatchField.H"
591 #endif
592 
593 // Runtime selection macros
594 #include "faePatchFieldMacros.H"
595 
596 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
597 
598 #endif
600 // ************************************************************************* //
virtual bool coupled() const
True if the patch field is coupled.
dictionary dict
virtual void initEvaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Initialise the evaluation of the patch field after a local.
void setUpdated(bool state) noexcept
Set updated state. This is a no-op for faePatchField.
Definition: faePatchField.H:99
virtual void readDict(const dictionary &dict)
Read dictionary entries.
virtual void write(Ostream &os) const
Write.
static const word & emptyType() noexcept
The type name for empty patch fields.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
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
Template invariant parts for faePatchField.
Definition: faePatchField.H:76
virtual void autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
bool updated() const noexcept
True if the boundary condition has already been updated. This is always true for faePatchField.
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:720
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
Definition: faePatchField.C:29
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field, generally a no-op.
virtual ~faePatchField()=default
Destructor.
const DimensionedField< Type, edgeMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
static tmp< faePatchField< Type > > Clone(const DerivedPatchField &pf, Args &&... args)
Clone a patch field, optionally with internal field reference etc.
const word calculatedType
A calculated patch field type.
declareRunTimeSelectionTable(tmp, faePatchField, patch,(const faPatch &p, const DimensionedField< Type, edgeMesh > &iF),(p, iF))
faPatch Patch
The patch type for the patch field.
Generic templated field type.
Definition: Field.H:62
DimensionedField< Type, edgeMesh > Internal
The internal field type associated with the patch field.
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void operator*=(const faePatchField< scalar > &)
bool manipulatedMatrix() const noexcept
True if the matrix has already been manipulated. Currently ignored (always false) for faePatchField...
virtual void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field after a local operation (e.g. *=)
virtual tmp< faePatchField< Type > > clone() const
Clone patch field with its own internal field reference.
const objectRegistry & db() const
The associated objectRegistry.
static tmp< faePatchField< Type > > NewCalculatedType(const faPatch &p)
Return a pointer to a new calculatedFaePatchField created on.
Macros for creating faePatchField types.
const faPatch & patch() const noexcept
Return the patch.
faePatchFieldBase(const faPatch &p)
Construct from patch.
bool operator!=(const faePatchField< Type > &) const =delete
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 void rmap(const faePatchField< Type > &, const labelList &)
Reverse map the given faePatchField onto this faePatchField.
const word emptyType
An empty patch field type.
OBJstream os(runTime.globalPath()/outputName)
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Initialise the evaluation of the patch field, generally a no-op.
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
void setManipulated(bool state) noexcept
Set matrix manipulated state. This is a no-op for faePatchField.
virtual ~faePatchFieldBase()=default
Destructor.
virtual void operator=(const UList< Type > &)
void check(const faePatchField< Type > &) const
Check against given patch field.
calculatedFaePatchField< Type > Calculated
Type for a calculated patch.
virtual void operator/=(const faePatchField< scalar > &)
TypeName("faePatchField")
Runtime type information.
virtual void operator==(const faePatchField< Type > &)
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
faePatchField(const faPatch &, const DimensionedField< Type, edgeMesh > &)
Construct from patch and internal field.
Definition: faePatchField.C:62
static tmp< faePatchField< Type > > New(const word &patchFieldType, const faPatch &, const DimensionedField< Type, edgeMesh > &)
Return a pointer to a new patchField created on freestore given.
Reading is optional [identical to READ_IF_PRESENT].
faePatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cove...
Definition: edgeFieldsFwd.H:43
virtual void operator+=(const faePatchField< Type > &)
Type value_type
The value_type for the patch field.
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)
static int disallowGenericPatchField
Debug switch to disallow the use of generic faePatchField.
Foam::argList args(argc, argv)
A FieldMapper for finite-area patch fields.
void checkPatch(const faePatchFieldBase &rhs) const
Check that patches are identical.
virtual void operator-=(const faePatchField< Type > &)
virtual bool fixesValue() const
True if the patch field fixes a value.
const Field< Type > & primitiveField() const noexcept
Return const-reference to the internal field values.
Namespace for OpenFOAM.
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
readOption
Enumeration defining read preferences.