GeometricBoundaryField.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-2017,2022 OpenFOAM Foundation
9  Copyright (C) 2015-2026 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::GeometricBoundaryField
29 
30 Description
31  Generic GeometricBoundaryField class.
32 
33 SourceFiles
34  GeometricBoundaryField.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_GeometricBoundaryField_H
39 #define Foam_GeometricBoundaryField_H
40 
41 #include "dimensionedTypes.H"
42 #include "DimensionedField.H"
43 #include "FieldField.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class GeometricBoundaryField Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 template<class Type, template<class> class PatchField, class GeoMesh>
58 :
59  public FieldField<PatchField, Type>
60 {
61 public:
62 
63  // Public Typedefs
64 
65  //- The template instance used for this GeometricBoundaryField type
67 
68  //- The boundary mesh type for the boundary fields
69  typedef typename GeoMesh::BoundaryMesh BoundaryMesh;
70 
71  //- The internal field type associated with the boundary fields
73 
74  //- This boundary field type
76 
77  //- The patch field type for the boundary fields
78  typedef PatchField<Type> Patch;
79 
80 
81 private:
82 
83  // Private Data
84 
85  //- Reference to BoundaryMesh for which this field is defined
86  const BoundaryMesh& bmesh_;
87 
88 
89  // Private Member Functions
90 
91  //- Check if patch fields have been consistently evaluated.
92  // If not:
93  // exit = true : FatalError
94  // exit = false : return bool
95  template<class CheckPatchField>
96  bool checkConsistency(const scalar tol, const bool exitIfBad) const;
97 
98 
99 public:
100 
101  //- Enable debug
102  static int debug;
103 
104 
105  // Constructors
106 
107  //- Construct from a BoundaryMesh, setting patches later
108  explicit GeometricBoundaryField(const BoundaryMesh& bmesh);
109 
110  //- Construct from a BoundaryMesh, reference to the internal field
111  //- and a patch type
113  (
114  const BoundaryMesh& bmesh,
115  const Internal& iField,
116  const word& patchFieldType = PatchField<Type>::calculatedType()
117  );
118 
119  //- Construct from a BoundaryMesh, reference to the internal field
120  //- and a wordList of patch types and optional the actual patch
121  //- types (to override constraint patches)
123  (
124  const BoundaryMesh& bmesh,
125  const Internal& iField,
126  const wordList& wantedPatchTypes,
127  const wordList& actualPatchTypes = wordList()
128  );
129 
130  //- Construct from a BoundaryMesh, reference to the internal field
131  //- and list of patch fields (to be cloned)
133  (
134  const BoundaryMesh& bmesh,
135  const Internal& iField,
138  const UPtrList<PatchField<Type>>& pflds
139  );
140 
141  //- Construct as copy, setting the reference to the internal field
143  (
144  const Internal& iField,
145  const GeometricBoundaryField& btf
146  );
147 
148  //- Construct as copy, setting the reference to the internal field
149  //- and resetting type of field for given patch IDs
151  (
152  const Internal& iField,
153  const GeometricBoundaryField& btf,
154  const labelUList& patchIDs,
155  const word& patchFieldName
156  );
157 
158  //- Construct from dictionary
160  (
161  const BoundaryMesh& bmesh,
162  const Internal& iField,
163  const dictionary& dict
164  );
165 
166  //- No copy construct
167  // Dangerous because it may be set to a field which gets deleted.
168  // Need new type of BoundaryField, one which is part of a geometric
169  // field for which snGrad etc. may be called and a free standing
170  // BoundaryField for which such operations are unavailable.
172  // :
173  // FieldField<PatchField, Type>(bf),
174  // bmesh_(bf.bmesh_)
175  // {}
176 
177  //- No move construct: likely just as dangerous as copy construct
179 
180  // FUTURE?
181  // //- Clone, setting reference to the internal field
182  // tmp<GeometricBoundaryField> clone(const Internal& iField) const
183  // {
184  // return tmp<GeometricBoundaryField>::New(iField, *this);
185  // }
186 
187 
188  // Member Functions
189 
190  //- Return non-const reference to this boundary field
191  this_type& constCast() const noexcept
192  {
193  return const_cast<this_type&>(*this);
194  }
195 
196  //- Read the boundary field
197  void readField(const Internal& iField, const dictionary& dict);
198 
199  //- Update the boundary condition coefficients
200  void updateCoeffs();
201 
202  //- Evaluate boundary conditions for each patch field.
203  //- Uses specified or default comms.
204  void evaluate
205  (
207  );
208 
209  //- Evaluate boundary conditions for patch fields matching the
210  //- given predicate. Uses specified or default comms.
211  template<class UnaryPredicate>
212  void evaluate_if
213  (
214  const UnaryPredicate& pred,
216  );
217 
218  //- Evaluate boundary conditions after change in local values.
219  //- Uses specified or default comms.
220  void evaluateLocal
221  (
223  );
225  //- Evaluate boundary conditions on coupled patches of the given type,
226  //- using specified or default comms.
227  //
228  // \tparam CoupledPatchType The coupled \b patch type that should
229  // be evaluated. For a \c void type,
230  // all coupled patch fields will be evaluated.
231  template<class CoupledPatchType>
232  void evaluateCoupled
233  (
235  );
236 
237  //- Evaluate boundary conditions for selected patches.
238  //- Uses non-blocking comms.
239  void evaluateSelected(const labelUList& patchIDs);
240 
241  //- Return a list of the patch types
242  wordList types() const;
243 
244  //- Return boundary field of values neighbouring the boundary
246 
247  //- Return a list of pointers for each patch field with only those
248  //- pointing to interfaces being set
250 
251  //- Return a list of pointers for each patch field with only those
252  //- pointing to interfaces being set
254 
255  //- Helper: check if field has been evaluated. See instantiations.
256  bool check() const;
257 
258 
259  // Write
260 
261  //- Write boundary field as dictionary entry
262  void writeEntry(const word& keyword, Ostream& os) const;
263 
264  //- Write dictionary entries of the individual boundary fields.
265  void writeEntries(Ostream& os) const;
266 
267 
268  // Member Operators
269 
270  //- Copy assignment from GeometricBoundaryField
271  void operator=(const GeometricBoundaryField& bf);
272 
273  //- Copy assignment from FieldField<PatchField, Type>
274  void operator=(const FieldField<PatchField, Type>& bf);
275 
276  //- Assignment to uniform value
277  void operator=(const Type& val);
278 
279  //- Assignment to zero
280  void operator=(Foam::zero);
281 
282  //- Forced assignment from GeometricBoundaryField
283  void operator==(const GeometricBoundaryField& bf);
284 
285  //- Forced assignment from FieldField<PatchField, Type>
287 
288  //- Forced assignment to uniform value
289  void operator==(const Type& val);
290 
291  //- Forced assignment to zero
292  void operator==(Foam::zero) { *this == Type(Foam::zero{}); }
293 
294  // Prevent automatic comparison rewriting (c++20)
295  bool operator!=(const GeometricBoundaryField&) = delete;
296  bool operator!=(const FieldField<PatchField, Type>&) = delete;
297  bool operator!=(const Type&) = delete;
298  bool operator!=(Foam::zero) = delete;
299 };
300 
301 
302 template<class Type, template<class> class PatchField, class GeoMesh>
303 Ostream& operator<<
304 (
305  Ostream&,
306  const GeometricBoundaryField<Type, PatchField, GeoMesh>&
307 );
308 
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 } // End namespace Foam
313 
314 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
315 
316 #ifdef NoRepository
317  #include "GeometricBoundaryField.C"
318 #endif
319 
320 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
321 
322 #endif
323 
324 // ************************************************************************* //
dictionary dict
PatchField< Type > Patch
The patch field type for the boundary fields.
GeometricBoundaryField(const BoundaryMesh &bmesh)
Construct from a BoundaryMesh, setting patches later.
tmp< GeometricBoundaryField > boundaryInternalField() const
Return boundary field of values neighbouring the boundary.
commsTypes
Communications types.
Definition: UPstream.H:81
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
void evaluate(const UPstream::commsTypes commsType=UPstream::defaultCommsType)
Evaluate boundary conditions for each patch field. Uses specified or default comms.
MESH::BoundaryMesh BoundaryMesh
Definition: GeoMesh.H:62
lduInterfaceFieldPtrsList scalarInterfaces() const
Return a list of pointers for each patch field with only those pointing to interfaces being set...
wordList types() const
Return a list of the patch types.
GeometricBoundaryField< Type, PatchField, GeoMesh > Boundary
This boundary field type.
void evaluateCoupled(const UPstream::commsTypes commsType=UPstream::defaultCommsType)
Evaluate boundary conditions on coupled patches of the given type, using specified or default comms...
void evaluateLocal(const UPstream::commsTypes commsType=UPstream::defaultCommsType)
Evaluate boundary conditions after change in local values. Uses specified or default comms...
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
bool operator!=(const GeometricBoundaryField &)=delete
const word calculatedType
A calculated patch field type.
GeoMesh::BoundaryMesh BoundaryMesh
The boundary mesh type for the boundary fields.
A class for handling words, derived from Foam::string.
Definition: word.H:63
void operator==(const GeometricBoundaryField &bf)
Forced assignment from GeometricBoundaryField.
void evaluate_if(const UnaryPredicate &pred, const UPstream::commsTypes commsType=UPstream::defaultCommsType)
Evaluate boundary conditions for patch fields matching the given predicate. Uses specified or default...
void evaluateSelected(const labelUList &patchIDs)
Evaluate boundary conditions for selected patches. Uses non-blocking comms.
void operator=(const GeometricBoundaryField &bf)
Copy assignment from GeometricBoundaryField.
void readField(const Internal &iField, const dictionary &dict)
Read the boundary field.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
bool check() const
Helper: check if field has been evaluated. See instantiations.
void updateCoeffs()
Update the boundary condition coefficients.
DimensionedField< Type, GeoMesh > Internal
The internal field type associated with the boundary fields.
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:265
Generic GeometricBoundaryField class.
List< word > wordList
List of word.
Definition: fileName.H:59
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:1070
labelList patchIDs
void writeEntry(const word &keyword, Ostream &os) const
Write boundary field as dictionary entry.
static int debug
Enable debug.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
LduInterfaceFieldPtrsList< Type > interfaces() const
Return a list of pointers for each patch field with only those pointing to interfaces being set...
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
void writeEntries(Ostream &os) const
Write dictionary entries of the individual boundary fields.
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:45
A class for managing temporary objects.
Definition: HashPtrTable.H:50
GeometricBoundaryField< Type, PatchField, GeoMesh > this_type
The template instance used for this GeometricBoundaryField type.
List of coupled interface fields to be used in coupling.
this_type & constCast() const noexcept
Return non-const reference to this boundary field.
Namespace for OpenFOAM.