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-2025 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 a PtrList<PatchField<Type>> (to be cloned)
133  (
134  const BoundaryMesh& bmesh,
135  const Internal& iField,
136  const PtrList<PatchField<Type>>& ptfl
137  );
138 
139  //- Construct as copy, setting the reference to the internal field
141  (
142  const Internal& iField,
144  );
145 
146  //- Construct as copy, setting the reference to the internal field
147  //- and resetting type of field for given patch IDs
149  (
150  const Internal& iField,
152  const labelList& patchIDs,
153  const word& patchFieldName
154  );
155 
156  //- Copy construct
157  // Dangerous because Field may be set to a field which gets deleted
158  // Need new type of BoundaryField, one which is part of a geometric
159  // field for which snGrad etc. may be called and a free standing
160  // BoundaryField for which such operations are unavailable.
162 
163  //- Construct from dictionary
165  (
166  const BoundaryMesh& bmesh,
167  const Internal& iField,
168  const dictionary& dict
169  );
170 
171 
172  // Member Functions
173 
174  //- Return non-const reference to this boundary field
175  this_type& constCast() const noexcept
176  {
177  return const_cast<this_type&>(*this);
178  }
179 
180  //- Read the boundary field
181  void readField(const Internal& iField, const dictionary& dict);
182 
183  //- Update the boundary condition coefficients
184  void updateCoeffs();
185 
186  //- Evaluate boundary conditions for each patch field.
187  //- Uses specified or default comms.
188  void evaluate
189  (
191  );
192 
193  //- Evaluate boundary conditions for patch fields matching the
194  //- given predicate. Uses specified or default comms.
195  template<class UnaryPredicate>
196  void evaluate_if
197  (
198  const UnaryPredicate& pred,
200  );
201 
202  //- Evaluate boundary conditions after change in local values.
203  //- Uses specified or default comms.
204  void evaluateLocal
205  (
207  );
208 
209  //- Evaluate boundary conditions on coupled patches of the given type,
210  //- using specified or default comms.
211  //
212  // \tparam CoupledPatchType The coupled \b patch type that should
213  // be evaluated. For a \c void type,
214  // all coupled patch fields will be evaluated.
215  template<class CoupledPatchType>
216  void evaluateCoupled
217  (
219  );
220 
221  //- Evaluate boundary conditions for selected patches.
222  //- Uses non-blocking comms.
223  void evaluateSelected(const labelUList& patchIDs);
224 
225  //- Return a list of the patch types
226  wordList types() const;
227 
228  //- Return boundary field of values neighbouring the boundary
230 
231  //- Return a list of pointers for each patch field with only those
232  //- pointing to interfaces being set
234 
235  //- Return a list of pointers for each patch field with only those
236  //- pointing to interfaces being set
238 
239  //- Helper: check if field has been evaluated. See instantiations.
240  bool check() const;
241 
242 
243  // Write
244 
245  //- Write boundary field as dictionary entry
246  void writeEntry(const word& keyword, Ostream& os) const;
247 
248  //- Write dictionary entries of the individual boundary fields.
249  void writeEntries(Ostream& os) const;
250 
251 
252  // Member Operators
253 
254  //- Copy assignment from GeometricBoundaryField
255  void operator=(const GeometricBoundaryField& bf);
256 
257  //- Copy assignment from FieldField<PatchField, Type>
258  void operator=(const FieldField<PatchField, Type>& bf);
259 
260  //- Assignment to uniform value
261  void operator=(const Type& val);
262 
263  //- Forced assignment from GeometricBoundaryField
264  void operator==(const GeometricBoundaryField& bf);
265 
266  //- Forced assignment from FieldField<PatchField, Type>
268 
269  //- Forced assignment to uniform value
270  void operator==(const Type& val);
271 
272  // Prevent automatic comparison rewriting (c++20)
273  bool operator!=(const GeometricBoundaryField&) = delete;
274  bool operator!=(const FieldField<PatchField, Type>&) = delete;
275  bool operator!=(const Type&) = delete;
276 };
277 
278 
279 template<class Type, template<class> class PatchField, class GeoMesh>
280 Ostream& operator<<
281 (
282  Ostream&,
284 );
285 
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 } // End namespace Foam
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
293 #ifdef NoRepository
294  #include "GeometricBoundaryField.C"
295 #endif
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #endif
300 
301 // ************************************************************************* //
const labelList patchIDs(pbm.indices(polyPatchNames, true))
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:77
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
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:255
OBJstream os(runTime.globalPath()/outputName)
Generic GeometricBoundaryField class.
List< word > wordList
List of word.
Definition: fileName.H:59
static commsTypes defaultCommsType
Default commsType.
Definition: UPstream.H:963
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:54
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...
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.