faPatchField.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 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::faPatchField
29 
30 Description
31  faPatchField<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 proceedures, particularly with respect to specific fields.
37 
38 Author
39  Zeljko Tukovic, FMENA
40  Hrvoje Jasak, Wikki Ltd.
41 
42 SourceFiles
43  faPatchField.C
44  newPatchField.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef faPatchField_H
49 #define faPatchField_H
50 
51 #include "faPatch.H"
52 #include "DimensionedField.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 
59 // Class forward declarations
60 
61 class objectRegistry;
62 class dictionary;
63 class faPatchFieldMapper;
64 class areaMesh;
65 
66 // Forward declaration of friend functions and operators
67 
68 template<class Type>
69 class faPatchField;
70 
71 template<class Type>
72 class calculatedFaPatchField;
73 
74 template<class Type>
75 Ostream& operator<<(Ostream&, const faPatchField<Type>&);
76 
77 /*---------------------------------------------------------------------------*\
78  Class faPatchField Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class Type>
82 class faPatchField
83 :
84  public Field<Type>
85 {
86  // Private data
87 
88  //- Reference to a patch
89  const faPatch& patch_;
90 
91  //- Reference to internal field
92  const DimensionedField<Type, areaMesh>& internalField_;
93 
94  //- Update index used so that updateCoeffs is called only once during
95  // the construction of the matrix
96  bool updated_;
97 
98  //- Optional patch type, used to allow specified boundary conditions
99  // to be applied to constraint patches by providing the constraint
100  // patch type as 'patchType'
101  word patchType_;
102 
103 
104 public:
105 
106  typedef faPatch Patch;
108 
109 
110  //- Runtime type information
111  TypeName("faPatchField");
112 
113  //- Debug switch to disallow the use of
114  static int disallowGenericFaPatchField;
115 
116 
117  // Declare run-time constructor selection tables
118 
120  (
121  tmp,
122  faPatchField,
123  patch,
124  (
125  const faPatch& p,
127  ),
128  (p, iF)
129  );
130 
132  (
133  tmp,
134  faPatchField,
135  patchMapper,
136  (
137  const faPatchField<Type>& ptf,
138  const faPatch& p,
140  const faPatchFieldMapper& m
141  ),
142  (dynamic_cast<const faPatchFieldType&>(ptf), p, iF, m)
143  );
144 
146  (
147  tmp,
148  faPatchField,
149  dictionary,
150  (
151  const faPatch& p,
153  const dictionary& dict
154  ),
155  (p, iF, dict)
156  );
157 
158 
159  // Constructors
160 
161  //- Construct from patch and internal field
163  (
164  const faPatch&,
166  );
167 
168  //- Construct from patch and internal field and patch field
170  (
171  const faPatch&,
173  const Field<Type>&
174  );
175 
176  //- Construct from patch, internal field and dictionary
178  (
179  const faPatch&,
181  const dictionary&
182  );
183 
184  //- Construct by mapping the given faPatchField onto a new patch
186  (
187  const faPatchField<Type>&,
188  const faPatch&,
190  const faPatchFieldMapper&
191  );
192 
193  //- Construct as copy
195 
196  //- Construct and return a clone
197  virtual tmp<faPatchField<Type>> clone() const
198  {
199  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this));
200  }
201 
202  //- Construct as copy setting internal field reference
204  (
205  const faPatchField<Type>&,
207  );
208 
209  //- Construct and return a clone setting internal field reference
211  (
213  ) const
214  {
215  return tmp<faPatchField<Type>>(new faPatchField<Type>(*this, iF));
216  }
217 
218 
219  // Selectors
220 
221  //- Return a pointer to a new patchField created on freestore given
222  // patch and internal field
223  // (does not set the patch field values)
225  (
226  const word& patchFieldType,
227  const word& actualPatchType,
228  const faPatch&,
230  );
231 
232  //- Return a pointer to a new patchField created on freestore given
233  // patch and internal field
234  // (does not set the patch field values)
236  (
237  const word& patchFieldType,
238  const faPatch&,
240  );
241 
242  //- Return a pointer to a new patchField created on freestore from
243  // a given faPatchField mapped onto a new patch
245  (
246  const faPatchField<Type>&,
247  const faPatch&,
249  const faPatchFieldMapper&
250  );
251 
252  //- Return a pointer to a new patchField created on freestore
253  // from dictionary
255  (
256  const faPatch&,
258  const dictionary&
259  );
260 
261  //- Return a pointer to a new calculatedFaPatchField created on
262  // freestore without setting patchField values
263  template<class Type2>
265  (
266  const faPatchField<Type2>&
267  );
268 
269 
270  //- Destructor
271  virtual ~faPatchField<Type>() = default;
272 
273 
274  // Member functions
275 
276  // Access
277 
278  //- Return local objectRegistry
279  const objectRegistry& db() const;
280 
281  //- Return patch
282  const faPatch& patch() const
283  {
284  return patch_;
285  }
286 
287  //- Return dimensioned internal field reference
289  {
290  return internalField_;
291  }
292 
293  //- Return internal field reference
294  const Field<Type>& primitiveField() const
295  {
296  return internalField_;
297  }
298 
299  //- Optional patch type
300  const word& patchType() const
301  {
302  return patchType_;
303  }
304 
305  //- Optional patch type
306  word& patchType()
307  {
308  return patchType_;
309  }
310 
311  //- Return the type of the calculated for of faPatchField
312  static const word& calculatedType();
313 
314  //- Return true if this patch field fixes a value.
315  // Needed to check if a level has to be specified while solving
316  // Poissons equations.
317  virtual bool fixesValue() const
318  {
319  return false;
320  }
321 
322  //- Return true if this patch field is coupled
323  virtual bool coupled() const
324  {
325  return false;
326  }
327 
328  //- Return true if the boundary condition has already been updated
329  bool updated() const
330  {
331  return updated_;
332  }
333 
334 
335  // Mapping functions
336 
337  //- Map (and resize as needed) from self given a mapping object
338  virtual void autoMap
339  (
340  const faPatchFieldMapper&
341  );
342 
343  //- Reverse map the given faPatchField onto this faPatchField
344  virtual void rmap
345  (
346  const faPatchField<Type>&,
347  const labelList&
348  );
349 
350 
351  // Evaluation functions
352 
353  //- Return patch-normal gradient
354  virtual tmp<Field<Type>> snGrad() const;
355 
356  //- Update the coefficients associated with the patch field
357  // Sets Updated to true
358  virtual void updateCoeffs()
359  {
360  updated_ = true;
361  }
362 
363  //- Return internal field next to patch as patch field
364  virtual tmp<Field<Type>> patchInternalField() const;
365 
366  //- Return patchField on the opposite patch of a coupled patch
367  virtual tmp<Field<Type>> patchNeighbourField() const
368  {
370  return *this;
371  }
372 
373  //- Initialise the evaluation of the patch field
374  virtual void initEvaluate
375  (
376  const Pstream::commsTypes commsType =
378  )
379  {}
380 
381  //- Evaluate the patch field, sets Updated to false
382  virtual void evaluate
383  (
384  const Pstream::commsTypes commsType =
386  );
387 
388 
389  //- Return the matrix diagonal coefficients corresponding to the
390  // evaluation of the value of this patchField with given weights
392  (
393  const tmp<Field<scalar>>&
394  ) const
395  {
397  return *this;
398  }
399 
400  //- Return the matrix source coefficients corresponding to the
401  // evaluation of the value of this patchField with given weights
403  (
404  const tmp<Field<scalar>>&
405  ) const
406  {
408  return *this;
409  }
410 
411  //- Return the matrix diagonal coefficients corresponding to the
412  // evaluation of the gradient of this patchField
413  virtual tmp<Field<Type>> gradientInternalCoeffs() const
414  {
416  return *this;
417  }
418 
419  //- Return the matrix source coefficients corresponding to the
420  // evaluation of the gradient of this patchField
421  virtual tmp<Field<Type>> gradientBoundaryCoeffs() const
422  {
424  return *this;
425  }
426 
427 
428  //- Write
429  virtual void write(Ostream&) const;
430 
431 
432  // Check
433 
434  //- Check faPatchField<Type> against given faPatchField<Type>
435  void check(const faPatchField<Type>&) const;
436 
437 
438  // Member operators
439 
440  virtual void operator=(const UList<Type>&);
441 
442  virtual void operator=(const faPatchField<Type>&);
443  virtual void operator+=(const faPatchField<Type>&);
444  virtual void operator-=(const faPatchField<Type>&);
445  virtual void operator*=(const faPatchField<scalar>&);
446  virtual void operator/=(const faPatchField<scalar>&);
447 
448  virtual void operator+=(const Field<Type>&);
449  virtual void operator-=(const Field<Type>&);
450 
451  virtual void operator*=(const Field<scalar>&);
452  virtual void operator/=(const Field<scalar>&);
453 
454  virtual void operator=(const Type&);
455  virtual void operator+=(const Type&);
456  virtual void operator-=(const Type&);
457  virtual void operator*=(const scalar);
458  virtual void operator/=(const scalar);
459 
460 
461  // Force an assignment irrespective of form of patch
462 
463  virtual void operator==(const faPatchField<Type>&);
464  virtual void operator==(const Field<Type>&);
465  virtual void operator==(const Type&);
466 
467 
468  // Ostream operator
469 
470  friend Ostream& operator<< <Type>(Ostream&, const faPatchField<Type>&);
471 };
472 
473 
474 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475 
476 } // End namespace Foam
477 
478 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
479 
480 #ifdef NoRepository
481  #include "faPatchField.C"
482  #include "calculatedFaPatchField.H"
483 #endif
484 
485 
486 #define addToFaPatchFieldRunTimeSelection(PatchTypeField, typePatchTypeField) \
487  \
488 addToRunTimeSelectionTable \
489 ( \
490  PatchTypeField, typePatchTypeField, patch \
491 ); \
492  \
493 addToRunTimeSelectionTable \
494 ( \
495  PatchTypeField, \
496  typePatchTypeField, \
497  patchMapper \
498 ); \
499  \
500 addToRunTimeSelectionTable \
501 ( \
502  PatchTypeField, typePatchTypeField, dictionary \
503 );
504 
505 
506 #define makeFaPatchTypeFieldTypeName(typePatchTypeField) \
507  \
508 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0);
509 
510 
511 #define makeFaPatchFieldsTypeName(typePatchField) \
512  \
513 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchScalarField); \
514 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchVectorField); \
515 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchSphericalTensorField); \
516 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchSymmTensorField); \
517 makeFaPatchTypeFieldTypeName(typePatchField##FaPatchTensorField);
518 
519 
520 #define makeFaPatchTypeField(PatchTypeField, typePatchTypeField) \
521  \
522 defineTypeNameAndDebug(typePatchTypeField, 0); \
523  \
524 addToFaPatchFieldRunTimeSelection \
525 ( \
526  PatchTypeField, typePatchTypeField \
527 );
528 
529 #define makeTemplateFaPatchTypeField(PatchTypeField, typePatchTypeField) \
530  \
531 defineNamedTemplateTypeNameAndDebug(typePatchTypeField, 0); \
532  \
533 addToFaPatchFieldRunTimeSelection \
534 ( \
535  PatchTypeField, typePatchTypeField \
536 );
537 
538 
539 #define makeFaPatchFields(type) \
540  \
541 makeTemplateFaPatchTypeField(faPatchScalarField, type##FaPatchScalarField); \
542 makeTemplateFaPatchTypeField(faPatchVectorField, type##FaPatchVectorField); \
543 makeTemplateFaPatchTypeField \
544 ( \
545  faPatchSphericalTensorField, \
546  type##FaPatchSphericalTensorField \
547 ); \
548 makeTemplateFaPatchTypeField \
549 ( \
550  faPatchSymmTensorField, \
551  type##FaPatchSymmTensorField \
552 ); \
553 makeTemplateFaPatchTypeField \
554 ( \
555  faPatchTensorField, \
556  type##FaPatchTensorField \
557 );
558 
559 
560 #define makeFaPatchTypeFieldTypedefs(type) \
561  \
562 typedef type##FaPatchField<scalar> type##FaPatchScalarField; \
563 typedef type##FaPatchField<vector> type##FaPatchVectorField; \
564 typedef type##FaPatchField<sphericalTensor> \
565  type##FaPatchSphericalTensorField; \
566 typedef type##FaPatchField<symmTensor> type##FaPatchSymmTensorField; \
567 typedef type##FaPatchField<tensor> type##FaPatchTensorField;
568 
569 
570 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
571 
572 #endif
573 
574 // ************************************************************************* //
Foam::faPatchField::clone
virtual tmp< faPatchField< Type > > clone() const
Construct and return a clone.
Definition: faPatchField.H:196
Foam::faPatchField::faPatchField
faPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
Definition: faPatchField.C:35
Foam::faPatchField::operator*=
virtual void operator*=(const faPatchField< scalar > &)
Definition: faPatchField.C:264
Foam::UPstream::commsTypes::blocking
Foam::faPatchField::internalField
const DimensionedField< Type, areaMesh > & internalField() const
Return dimensioned internal field reference.
Definition: faPatchField.H:287
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::faPatchField
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:50
Foam::faPatchField::write
virtual void write(Ostream &) const
Write.
Definition: faPatchField.C:206
Foam::faPatchField::primitiveField
const Field< Type > & primitiveField() const
Return internal field reference.
Definition: faPatchField.H:293
Foam::faPatchField::snGrad
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
Definition: faPatchField.C:161
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::faPatchField::NewCalculatedType
static tmp< faPatchField< Type > > NewCalculatedType(const faPatchField< Type2 > &)
Return a pointer to a new calculatedFaPatchField created on.
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::faPatchField::Patch
faPatch Patch
Definition: faPatchField.H:105
Foam::faPatchField::check
void check(const faPatchField< Type > &) const
Check faPatchField<Type> against given faPatchField<Type>
Definition: faPatchField.C:149
Foam::faPatchField::Calculated
calculatedFaPatchField< Type > Calculated
Definition: faPatchField.H:106
DimensionedField.H
Foam::faPatchField::New
static tmp< faPatchField< Type > > New(const word &patchFieldType, const word &actualPatchType, const faPatch &, const DimensionedField< Type, areaMesh > &)
Return a pointer to a new patchField created on freestore given.
Definition: faPatchFieldNew.C:33
calculatedFaPatchField.H
Foam::faPatchField::operator-=
virtual void operator-=(const faPatchField< Type > &)
Definition: faPatchField.C:253
Foam::faPatchField::calculatedType
static const word & calculatedType()
Return the type of the calculated for of faPatchField.
Definition: calculatedFaPatchField.C:34
Foam::faPatchField::fixesValue
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: faPatchField.H:316
Foam::faPatchFieldMapper
Definition: faPatchFieldMapper.H:44
Foam::faPatchField::autoMap
virtual void autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
Definition: faPatchField.C:176
Foam::faPatchField::operator/=
virtual void operator/=(const faPatchField< scalar > &)
Definition: faPatchField.C:281
Foam::faPatchField::initEvaluate
virtual void initEvaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Initialise the evaluation of the patch field.
Definition: faPatchField.H:374
Foam::faPatchField::updated
bool updated() const
Return true if the boundary condition has already been updated.
Definition: faPatchField.H:328
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::faPatchField::valueInternalCoeffs
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< Field< scalar >> &) const
Return the matrix diagonal coefficients corresponding to the.
Definition: faPatchField.H:391
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:419
Foam::faPatchField::coupled
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: faPatchField.H:322
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::faPatchField::valueBoundaryCoeffs
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< Field< scalar >> &) const
Return the matrix source coefficients corresponding to the.
Definition: faPatchField.H:402
Foam::faPatchField::gradientInternalCoeffs
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
Definition: faPatchField.H:412
Foam::calculatedFaPatchField
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
Definition: calculatedFaPatchField.H:54
Foam::faPatchField::disallowGenericFaPatchField
static int disallowGenericFaPatchField
Debug switch to disallow the use of.
Definition: faPatchField.H:113
Foam::faPatchField::patchInternalField
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch as patch field.
Definition: faPatchField.C:169
Foam::faPatchField::evaluate
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: faPatchField.C:194
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::faPatchField::patchNeighbourField
virtual tmp< Field< Type > > patchNeighbourField() const
Return patchField on the opposite patch of a coupled patch.
Definition: faPatchField.H:366
Foam::faPatchField::gradientBoundaryCoeffs
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
Definition: faPatchField.H:420
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:66
Foam::faPatchField::patchType
const word & patchType() const
Optional patch type.
Definition: faPatchField.H:299
Foam::List< label >
faPatch.H
Foam::UList< Type >
Foam::faPatchField::db
const objectRegistry & db() const
Return local objectRegistry.
Definition: faPatchField.C:141
Foam::faPatchField::rmap
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
Definition: faPatchField.C:184
Foam::faPatchField::operator+=
virtual void operator+=(const faPatchField< Type > &)
Definition: faPatchField.C:242
Foam::faPatchField::patchType
word & patchType()
Optional patch type.
Definition: faPatchField.H:305
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
faPatchField.C
Foam::faPatchField::operator==
virtual void operator==(const faPatchField< Type > &)
Definition: faPatchField.C:388
Foam::faPatch
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:65
Foam::faPatchField::updateCoeffs
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: faPatchField.H:357
Foam::faPatchField::operator=
virtual void operator=(const UList< Type > &)
Definition: faPatchField.C:221
Foam::faPatchField::TypeName
TypeName("faPatchField")
Runtime type information.
Foam::faPatchField::patch
const faPatch & patch() const
Return patch.
Definition: faPatchField.H:281
Foam::faPatchField::declareRunTimeSelectionTable
declareRunTimeSelectionTable(tmp, faPatchField, patch,(const faPatch &p, const DimensionedField< Type, areaMesh > &iF),(p, iF))
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54