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  //- Optional patch type
87  // Used to allow specified boundary conditions to be applied
88  // to constraint patches by providing the constraint
89  // patch type as 'patchType'
90  word patchType_;
91 
92 
93 protected:
94 
95  // Protected Member Functions
96 
97  //- Read dictionary entries.
98  // Useful when initially constructed without a dictionary
99  virtual void readDict(const dictionary& dict);
100 
101 
102 public:
103 
104  //- Debug switch to disallow the use of generic faePatchField
105  static int disallowGenericPatchField;
106 
107  //- Runtime type information
108  TypeName("faePatchField");
109 
110 
111  // Constructors
113  //- Construct from patch
114  explicit faePatchFieldBase(const faPatch& p);
115 
116  //- Construct from patch and patch type
117  explicit faePatchFieldBase(const faPatch& p, const word& patchType);
118 
119  //- Construct from patch and dictionary
120  faePatchFieldBase(const faPatch& p, const dictionary& dict);
121 
122  //- Copy construct with new patch
123  faePatchFieldBase(const faePatchFieldBase& rhs, const faPatch& p);
124 
125  //- Copy construct
127 
128 
129  //- Destructor
130  virtual ~faePatchFieldBase() = default;
131 
132 
133  // Static Member Functions
134 
135  //- The type name for \c empty patch fields
136  static const word& emptyType() noexcept
137  {
139  }
140 
141  //- The type name for \c calculated patch fields
142  static const word& calculatedType() noexcept
143  {
145  }
146 
147 
148  // Member Functions
149 
150  // Attributes
151 
152  //- True if the patch field fixes a value.
153  // Needed to check if a level has to be specified while solving
154  // Poissons equations.
155  virtual bool fixesValue() const
156  {
157  return false;
158  }
160  //- True if the patch field is coupled
161  virtual bool coupled() const
162  {
163  return false;
164  }
165 
166 
167  // Access
168 
169  //- The associated objectRegistry
170  const objectRegistry& db() const;
171 
172  //- Return the patch
173  const faPatch& patch() const noexcept
174  {
175  return patch_;
176  }
177 
178  //- The optional patch type
179  const word& patchType() const noexcept
180  {
181  return patchType_;
182  }
184  //- The optional patch type
186  {
187  return patchType_;
188  }
189 
190  //- True if the type does not correspond to the constraint type
191  virtual bool constraintOverride() const
192  {
193  return !patchType_.empty() && patchType_ != type();
194  }
195 
196 
197  // Solution
198 
199  //- True if the boundary condition has already been updated.
200  //- This is always true for faePatchField
201  bool updated() const noexcept
202  {
203  return true;
204  }
205 
206  //- Set updated state. This is a no-op for faePatchField
207  void setUpdated(bool state) noexcept
208  {}
209 
210  //- True if the matrix has already been manipulated.
211  //- Always false for faePatchField
212  bool manipulatedMatrix() const noexcept
213  {
214  return false;
215  }
216 
217  //- Set matrix manipulated state.
218  //- This is a no-op for faePatchField
219  void setManipulated(bool state) noexcept
220  {}
221 
222 
223  // Check
224 
225  //- Check that patches are identical
226  void checkPatch(const faePatchFieldBase& rhs) const;
227 };
228 
229 
230 /*---------------------------------------------------------------------------*\
231  Class faePatchField Declaration
232 \*---------------------------------------------------------------------------*/
233 
234 template<class Type>
235 class faePatchField
236 :
237  public faePatchFieldBase,
238  public Field<Type>
239 {
240 public:
241 
242  // Public Data Types
244  //- The patch type for the patch field
245  typedef faPatch Patch;
246 
247  //- The value_type for the patch field
248  typedef Type value_type;
249 
250  //- The component type for patch field
252 
253  //- The internal field type associated with the patch field
255 
256  //- Type for a \em calculated patch
259 
260 private:
261 
262  // Private Data
263 
264  //- Reference to internal field
265  const DimensionedField<Type, edgeMesh>& internalField_;
266 
267 protected:
268 
269  // Protected Member Functions
270 
271  //- Read the "value" entry into \c *this.
272  // The reading can be optional (default), mandatory etc.
273  // \returns True on success
274  bool readValueEntry
275  (
276  const dictionary& dict,
278  );
279 
280  //- Write \c *this field as a "value" entry
281  void writeValueEntry(Ostream& os) const
282  {
283  Field<Type>::writeEntry("value", os);
284  }
285 
286 
287 public:
288 
289  // Declare run-time constructor selection tables
290 
292  (
293  tmp,
295  patch,
296  (
297  const faPatch& p,
299  ),
300  (p, iF)
301  );
304  (
305  tmp,
307  patchMapper,
308  (
309  const faePatchField<Type>& ptf,
310  const faPatch& p,
313  ),
314  (dynamic_cast<const faePatchFieldType&>(ptf), p, iF, m)
315  );
316 
318  (
319  tmp,
321  dictionary,
322  (
323  const faPatch& p,
325  const dictionary& dict
326  ),
327  (p, iF, dict)
328  );
329 
330 
331  // Constructors
332 
333  //- Construct from patch and internal field
335  (
336  const faPatch&,
338  );
339 
340  //- Construct from patch, internal field and value
342  (
343  const faPatch&,
345  const Type& value
346  );
347 
348  //- Construct from patch, internal field and patch field
350  (
351  const faPatch&,
353  const Field<Type>& pfld
354  );
355 
356  //- Construct from patch, internal field and patch field
358  (
359  const faPatch&,
361  Field<Type>&& pfld
362  );
363 
364  //- Construct from patch, internal field and dictionary
365  // \note older versions have always treated "value" as optional
367  (
368  const faPatch&,
370  const dictionary& dict,
373  );
374 
375  //- Construct by mapping the given faePatchField onto a new patch
377  (
378  const faePatchField<Type>&,
379  const faPatch&,
381  const faPatchFieldMapper&
382  );
383 
384  //- Construct as copy
386 
387  //- Construct as copy setting internal field reference
389  (
390  const faePatchField<Type>&,
392  );
393 
394  //- Clone patch field with its own internal field reference
395  virtual tmp<faePatchField<Type>> clone() const
396  {
398  (
399  new faePatchField<Type>(*this, this->internalField_)
400  );
401  }
402 
403  //- Clone with an internal field reference
405  (
407  ) const
408  {
409  return tmp<faePatchField<Type>>::New(*this, iF);
410  }
411 
412 
413  //- Destructor
414  virtual ~faePatchField() = default;
415 
416 
417  // Factory Methods
418 
419  //- Clone a patch field, optionally with internal field reference etc.
420  template<class DerivedPatchField, class... Args>
421  static tmp<faePatchField<Type>> Clone
422  (
423  const DerivedPatchField& pf,
424  Args&&... args
425  )
426  {
427  return tmp<faePatchField<Type>>
428  (
429  new DerivedPatchField(pf, std::forward<Args>(args)...)
430  );
431  }
432 
433  //- Return a pointer to a new patchField created on freestore given
434  // patch and internal field
435  // (does not set the patch field values)
436  static tmp<faePatchField<Type>> New
437  (
438  const word& patchFieldType,
439  const faPatch&,
440  const DimensionedField<Type, edgeMesh>&
441  );
442 
443  //- Return a pointer to a new patchField created on freestore given
444  // patch and internal field
445  // (does not set the patch field values)
446  // Allows override of constraint type
447  static tmp<faePatchField<Type>> New
448  (
449  const word& patchFieldType,
450  const word& actualPatchType,
451  const faPatch&,
452  const DimensionedField<Type, edgeMesh>&
453  );
454 
455  //- Return a pointer to a new patchField created on freestore from
456  // a given faePatchField mapped onto a new patch
457  static tmp<faePatchField<Type>> New
458  (
459  const faePatchField<Type>&,
460  const faPatch&,
461  const DimensionedField<Type, edgeMesh>&,
462  const faPatchFieldMapper&
463  );
464 
465  //- Return a pointer to a new patchField created on freestore
466  // from dictionary
467  static tmp<faePatchField<Type>> New
468  (
469  const faPatch&,
470  const DimensionedField<Type, edgeMesh>&,
471  const dictionary&
472  );
473 
474  //- Return a pointer to a new calculatedFaePatchField created on
475  // freestore without setting patchField values
476  static tmp<faePatchField<Type>> NewCalculatedType
477  (
478  const faPatch& p
479  );
480 
481  //- Return a pointer to a new calculatedFaePatchField created on
482  // freestore without setting patchField values
483  template<class AnyType>
485  (
486  const faePatchField<AnyType>& pf
487  );
488 
489 
490  // Member Functions
491 
492  // Access
494  //- Return const-reference to the dimensioned internal field
496  {
497  return internalField_;
498  }
499 
500  //- Return const-reference to the internal field values
501  const Field<Type>& primitiveField() const noexcept
502  {
503  return internalField_;
504  }
505 
506 
507  // Evaluation Functions
508 
509  //- Initialise the evaluation of the patch field after a local
510  // operation
511  virtual void initEvaluateLocal
512  (
513  const Pstream::commsTypes commsType =
515  )
516  {}
517 
518  //- Evaluate the patch field after a local operation (e.g. *=)
519  virtual void evaluateLocal
520  (
521  const Pstream::commsTypes commsType =
523  )
524  {}
525 
526 
527  // Mapping
528 
529  //- Map (and resize as needed) from self given a mapping object
530  virtual void autoMap
531  (
532  const faPatchFieldMapper&
533  );
534 
535  //- Reverse map the given faePatchField onto this faePatchField
536  virtual void rmap
537  (
538  const faePatchField<Type>&,
539  const labelList&
540  );
541 
542 
543  // Evaluation Functions
544 
545  //- Initialise the evaluation of the patch field, generally a no-op
546  virtual void initEvaluate
547  (
549  )
550  {}
551 
552  //- Evaluate the patch field, generally a no-op
553  virtual void evaluate
554  (
556  )
557  {}
558 
559 
560  // Other
561 
562  //- Write
563  virtual void write(Ostream& os) const;
564 
565  //- Check against given patch field
566  void check(const faePatchField<Type>&) const;
567 
568 
569  // Member Operators
570 
571  virtual void operator=(const UList<Type>&);
572 
573  virtual void operator=(const faePatchField<Type>&);
574  virtual void operator+=(const faePatchField<Type>&);
575  virtual void operator-=(const faePatchField<Type>&);
576  virtual void operator*=(const faePatchField<scalar>&);
577  virtual void operator/=(const faePatchField<scalar>&);
578 
579  virtual void operator+=(const Field<Type>&);
580  virtual void operator-=(const Field<Type>&);
581 
582  virtual void operator*=(const Field<scalar>&);
583  virtual void operator/=(const Field<scalar>&);
584 
585  virtual void operator=(const Type&);
586  virtual void operator+=(const Type&);
587  virtual void operator-=(const Type&);
588  virtual void operator*=(const scalar);
589  virtual void operator/=(const scalar);
590 
591 
592  // Force an assignment irrespective of form of patch
593 
594  virtual void operator==(const faePatchField<Type>&);
595  virtual void operator==(const Field<Type>&);
596  virtual void operator==(const Type&);
597 
598  // Prevent automatic comparison rewriting (c++20)
599  bool operator!=(const faePatchField<Type>&) const = delete;
600  bool operator!=(const Field<Type>&) const = delete;
601  bool operator!=(const Type&) const = delete;
602 
603 
604  // Ostream Operator
605 
606  friend Ostream& operator<< <Type>(Ostream&, const faePatchField<Type>&);
607 };
608 
609 
610 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
611 
612 } // End namespace Foam
613 
614 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
616 #ifdef NoRepository
617  #include "faePatchField.C"
618  #include "faePatchFieldNew.C"
619  #include "calculatedFaePatchField.H"
620 #endif
621 
622 // Runtime selection macros
623 #include "faePatchFieldMacros.H"
624 
625 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
626 
627 #endif
628 
629 // ************************************************************************* //
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.
virtual void readDict(const dictionary &dict)
Read dictionary entries.
virtual void write(Ostream &os) const
Write.
pTraits< Type >::cmptType cmptType
The component type for patch field.
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.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:61
void writeEntry(const word &keyword, Ostream &os) const
Write the field as a dictionary entry.
Definition: Field.C:754
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.
virtual bool constraintOverride() const
True if the type does not correspond to the constraint type.
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.
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
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:63
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. 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: scalarImpl.H:255
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
const word & patchType() const noexcept
The optional patch type.
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:61
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.