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-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::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  // Private Data
215 
216  //- Reference to internal field
217  const DimensionedField<Type, edgeMesh>& internalField_;
218 
219 protected:
220 
221  // Protected Member Functions
222 
223  //- Read the "value" entry into \c *this.
224  // The reading can be optional (default), mandatory etc.
225  // \returns True on success
226  bool readValueEntry
227  (
228  const dictionary& dict,
230  );
231 
232  //- Write \c *this field as a "value" entry
233  void writeValueEntry(Ostream& os) const
234  {
235  Field<Type>::writeEntry("value", os);
236  }
237 
238 
239 public:
240 
241  //- The internal field type associated with the patch field
243 
244  //- The patch type for the patch field
245  typedef faPatch Patch;
246 
247  //- Type for a \em calculated patch
249 
250 
251  // Declare run-time constructor selection tables
252 
254  (
255  tmp,
257  patch,
258  (
259  const faPatch& p,
261  ),
262  (p, iF)
263  );
264 
266  (
267  tmp,
269  patchMapper,
270  (
271  const faePatchField<Type>& ptf,
272  const faPatch& p,
274  const faPatchFieldMapper& m
275  ),
276  (dynamic_cast<const faePatchFieldType&>(ptf), p, iF, m)
277  );
278 
280  (
283  dictionary,
284  (
285  const faPatch& p,
287  const dictionary& dict
288  ),
289  (p, iF, dict)
290  );
291 
293  // Constructors
294 
295  //- Construct from patch and internal field
297  (
298  const faPatch&,
300  );
301 
302  //- Construct from patch, internal field and value
304  (
305  const faPatch&,
307  const Type& value
308  );
309 
310  //- Construct from patch, internal field and patch field
312  (
313  const faPatch&,
315  const Field<Type>& pfld
316  );
317 
318  //- Construct from patch, internal field and patch field
320  (
321  const faPatch&,
323  Field<Type>&& pfld
324  );
325 
326  //- Construct from patch, internal field and dictionary
327  // \note older versions have always treated "value" as optional
329  (
330  const faPatch&,
332  const dictionary& dict,
335  );
336 
337  //- Construct by mapping the given faePatchField onto a new patch
339  (
340  const faePatchField<Type>&,
341  const faPatch&,
343  const faPatchFieldMapper&
344  );
345 
346  //- Construct as copy
348 
349  //- Construct as copy setting internal field reference
351  (
352  const faePatchField<Type>&,
354  );
355 
356  //- Construct and return a clone
357  virtual tmp<faePatchField<Type>> clone() const
358  {
359  return tmp<faePatchField<Type>>(new faePatchField<Type>(*this));
360  }
361 
362  //- Construct and return a clone setting internal field reference
364  (
366  ) const
367  {
369  (
370  new faePatchField<Type>(*this, iF)
371  );
372  }
373 
374 
375  //- Destructor
376  virtual ~faePatchField() = default;
377 
378 
379  // Selectors
380 
381  //- Return a pointer to a new patchField created on freestore given
382  // patch and internal field
383  // (does not set the patch field values)
384  static tmp<faePatchField<Type>> New
385  (
386  const word& patchFieldType,
387  const faPatch&,
388  const DimensionedField<Type, edgeMesh>&
389  );
390 
391  //- Return a pointer to a new patchField created on freestore given
392  // patch and internal field
393  // (does not set the patch field values)
394  // Allows override of constraint type
395  static tmp<faePatchField<Type>> New
396  (
397  const word& patchFieldType,
398  const word& actualPatchType,
399  const faPatch&,
400  const DimensionedField<Type, edgeMesh>&
401  );
402 
403  //- Return a pointer to a new patchField created on freestore from
404  // a given faePatchField mapped onto a new patch
405  static tmp<faePatchField<Type>> New
406  (
407  const faePatchField<Type>&,
408  const faPatch&,
409  const DimensionedField<Type, edgeMesh>&,
410  const faPatchFieldMapper&
411  );
412 
413  //- Return a pointer to a new patchField created on freestore
414  // from dictionary
415  static tmp<faePatchField<Type>> New
416  (
417  const faPatch&,
418  const DimensionedField<Type, edgeMesh>&,
419  const dictionary&
420  );
421 
422  //- Return a pointer to a new calculatedFaePatchField created on
423  // freestore without setting patchField values
424  template<class Type2>
425  static tmp<faePatchField<Type>> NewCalculatedType
426  (
427  const faePatchField<Type2>&
428  );
429 
431  // Member Functions
432 
433  // Access
434 
435  //- Return const-reference to the dimensioned internal field
437  {
438  return internalField_;
439  }
440 
441  //- Return const-reference to the internal field values
442  const Field<Type>& primitiveField() const noexcept
443  {
444  return internalField_;
445  }
446 
447 
448  // Evaluation Functions
449 
450  //- Initialise the evaluation of the patch field after a local
451  // operation
452  virtual void initEvaluateLocal
453  (
454  const Pstream::commsTypes commsType =
456  )
457  {}
458 
459  //- Evaluate the patch field after a local operation (e.g. *=)
460  virtual void evaluateLocal
461  (
462  const Pstream::commsTypes commsType =
464  )
465  {}
466 
467 
468  // Mapping
469 
470  //- Map (and resize as needed) from self given a mapping object
471  virtual void autoMap
472  (
473  const faPatchFieldMapper&
474  );
475 
476  //- Reverse map the given faePatchField onto this faePatchField
477  virtual void rmap
478  (
479  const faePatchField<Type>&,
480  const labelList&
481  );
482 
483 
484  // Evaluation Functions
485 
486  //- Initialise the evaluation of the patch field, generally a no-op
487  virtual void initEvaluate
488  (
490  )
491  {}
492 
493  //- Evaluate the patch field, generally a no-op
494  virtual void evaluate
495  (
497  )
498  {}
499 
500 
501  // Other
502 
503  //- Write
504  virtual void write(Ostream& os) const;
505 
506  //- Check against given patch field
507  void check(const faePatchField<Type>&) const;
508 
509 
510  // Member Operators
511 
512  virtual void operator=(const UList<Type>&);
513 
514  virtual void operator=(const faePatchField<Type>&);
515  virtual void operator+=(const faePatchField<Type>&);
516  virtual void operator-=(const faePatchField<Type>&);
517  virtual void operator*=(const faePatchField<scalar>&);
518  virtual void operator/=(const faePatchField<scalar>&);
519 
520  virtual void operator+=(const Field<Type>&);
521  virtual void operator-=(const Field<Type>&);
522 
523  virtual void operator*=(const Field<scalar>&);
524  virtual void operator/=(const Field<scalar>&);
525 
526  virtual void operator=(const Type&);
527  virtual void operator+=(const Type&);
528  virtual void operator-=(const Type&);
529  virtual void operator*=(const scalar);
530  virtual void operator/=(const scalar);
531 
532 
533  // Force an assignment irrespective of form of patch
534 
535  virtual void operator==(const faePatchField<Type>&);
536  virtual void operator==(const Field<Type>&);
537  virtual void operator==(const Type&);
539  // Prevent automatic comparison rewriting (c++20)
540  bool operator!=(const faePatchField<Type>&) const = delete;
541  bool operator!=(const Field<Type>&) const = delete;
542  bool operator!=(const Type&) const = delete;
543 
544 
545  // Ostream Operator
546 
547  friend Ostream& operator<< <Type>(Ostream&, const faePatchField<Type>&);
548 };
549 
550 
551 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
553 } // End namespace Foam
554 
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
556 
557 #ifdef NoRepository
558  #include "faePatchField.C"
559  #include "faePatchFieldNew.C"
560  #include "calculatedFaePatchField.H"
561 #endif
563 // Runtime selection macros
564 #include "faePatchFieldMacros.H"
565 
566 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
567 
568 #endif
569 
570 // ************************************************************************* //
virtual bool coupled() const
True if the patch field is coupled.
dictionary dict
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.
"blocking" : (MPI_Bsend, MPI_Recv)
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:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual void evaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field after a local operation (e.g. *=)
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 ~faePatchField()=default
Destructor.
const DimensionedField< Type, edgeMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
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 tmp< faePatchField< Type > > clone() const
Construct and return a clone.
const objectRegistry & db() const
The associated objectRegistry.
Macros for creating faePatchField types.
const faPatch & patch() const noexcept
Return the patch.
faePatchFieldBase(const faPatch &p)
Construct from patch.
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field, generally a no-op.
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 evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, generally a no-op.
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)
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
static tmp< faePatchField< Type > > NewCalculatedType(const faePatchField< Type2 > &)
Return a pointer to a new calculatedFaePatchField created on.
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 initEvaluateLocal(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field after a local.
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...
Definition: areaFieldsFwd.H:42
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:46
virtual void operator+=(const faePatchField< Type > &)
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.
static int disallowGenericPatchField
Debug switch to disallow the use of generic faePatchField.
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.