mappedPatchBase.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::mappedPatchBase
26 
27 Description
28  Engine which provides mapping between two patches
29 
30  Example:
31  \verbatim
32  // The name of the region to map from. Optional. Defaults to the same
33  // region as the patch.
34  neighbourRegion region0;
35 
36  // The name of the patch to map from
37  neighbourPatch movingWall;
38 
39  // Couple group to specify the region and patch to map from. This is an
40  // alternative to specifying neighbourRegion and neighbourPatch
41  // directly, as shown above.
42  coupleGroup baffleGroup;
43  \endverbatim
44 
45 SourceFiles
46  mappedPatchBase.C
47 
48 \*---------------------------------------------------------------------------*/
49 
50 #ifndef mappedPatchBase_H
51 #define mappedPatchBase_H
52 
53 #include "pointField.H"
54 #include "patchToPatch.H"
55 #include "coupleGroupIdentifier.H"
56 #include "cyclicTransform.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 class polyPatch;
64 class polyMesh;
65 class distributionMap;
66 
67 /*---------------------------------------------------------------------------*\
68  Class mappedPatchBase Declaration
69 \*---------------------------------------------------------------------------*/
70 
71 class mappedPatchBase
72 {
73 protected:
74 
75  // Protected data
76 
77  //- Patch to map to
78  const polyPatch& patch_;
79 
80  //- Couple group for the region/patch to map from
82 
83  //- Name of the region to map from
84  mutable word nbrRegionName_;
85 
86  //- Name of the patch to map from
87  mutable word nbrPatchName_;
88 
89  //- The transformation between the patches
91 
92  //- Are we using the tree mapping method, or a patch-to-patch
93  // intersection engine? The former is typically faster on small,
94  // pairs of patches with identical meshes. The latter is better
95  // parallelised and provides options for connecting patches with
96  // differing surface meshes.
97  const bool usingTree_;
98 
99  //- Distributor (if using tree)
101 
102  //- Indices of the neighbouring patch faces who's values
103  // have to be supplied to the distribution map (if using tree)
105 
106  //- Is the patch-to-patch intersection engine up to date? (if using
107  // patch-to-patch)
108  mutable bool patchToPatchIsValid_;
109 
110  //- Patch-to-patch intersection engine (if using patch-to-patch)
112 
113  //- Default Matching tolerance
114  static const scalar defaultMatchTol_;
115 
116  //- Matching tolerance
117  const scalar matchTol_;
118 
119  //- Do we need to re-calculate the mapping if mesh motion takes place?
120  // Defaults to true.
121  const bool reMapAfterMove_;
122 
123  //- Do we need to re-map the neighbour because this patch moved?
124  mutable bool reMapNbr_;
125 
126 
127  // Protected Member Functions
128 
129  //- Get the face-areas for this patch
130  virtual tmp<vectorField> patchFaceAreas() const;
131 
132  //- Get the face-centres for this patch
133  virtual tmp<pointField> patchFaceCentres() const;
134 
135  //- Get the local points for this patch
136  virtual tmp<pointField> patchLocalPoints() const;
137 
138  //- Get the face-areas for the neighbour patch
140 
141  //- Get the face-centres for the neighbour patch
143 
144  //- Get the local points for the neighbour patch
146 
147  //- Calculate mapping
148  void calcMapping() const;
149 
150  //- Return whether or not the neighbour patch is of mapped type
151  inline bool nbrPatchIsMapped() const;
152 
153  //- Get the mapped neighbouring patch
154  inline const mappedPatchBase& nbrMappedPatch() const;
155 
156  //- Determine whether the neighbouring patch maps from this patch in
157  // the same way as this patch maps from its neighbour
158  inline bool symmetric() const;
159 
160 
161 public:
162 
163  //- Runtime type information
164  TypeName("mappedPatchBase");
165 
166 
167  // Constructors
168 
169  //- Construct from patch
170  mappedPatchBase(const polyPatch&);
171 
172  //- Construct from components
174  (
175  const polyPatch& pp,
176  const word& nbrRegionName,
177  const word& nbrPatchName,
179  );
180 
181  //- Construct from dictionary
183  (
184  const polyPatch& pp,
185  const dictionary& dict,
186  const bool defaultTransformIsNone
187  );
188 
189  //- Construct as copy, resetting patch
190  mappedPatchBase(const polyPatch&, const mappedPatchBase&);
191 
192 
193  //- Destructor
194  virtual ~mappedPatchBase();
195 
196 
197  // Member Functions
198 
199  // Access
200 
201  //- Name of the region to map from
202  inline const word& nbrRegionName() const;
203 
204  //- Is the neighbour region the same as for this patch?
205  inline bool sameRegion() const;
206 
207  //- Is the neighbour patch the same as this patch?
208  inline bool samePatch() const;
209 
210  //- Is the neighbour patch the same as this patch with no transform?
211  inline bool sameUntransformedPatch() const;
212 
213  //- Name of the patch to map from
214  inline const word& nbrPatchName() const;
215 
216  //- Get the mesh for the region to map from
217  const polyMesh& nbrMesh() const;
218 
219  //- Get the patch to map from
220  const polyPatch& nbrPolyPatch() const;
221 
222 
223  // Casting
224 
225  //- Cast the given polyPatch to a mappedPatchBase. Handle errors.
226  static const mappedPatchBase& getMap(const polyPatch& patch);
227 
228  //- Restrict use of the mapper to certain configurations
229  struct from
230  {
231  static const label any = 0;
232  static const label sameRegion = 1;
233  static const label differentRegion = 2;
234  static const label differentPatch = 4;
235  };
236 
237  //- Validate that the map exists and is appropriate for the given
238  // set of permitted configurations
239  template<class PatchFieldType, class FieldType>
240  static void validateMapForField
241  (
242  const PatchFieldType& field,
243  const FieldType& iF,
244  const dictionary& context,
245  const label froms = from::any
246  );
247 
248  //- Validate that the map is appropriate for the given
249  // set of permitted configurations
250  template<class PatchFieldType, class FieldType>
251  void validateForField
252  (
253  const PatchFieldType& field,
254  const FieldType& iF,
255  const dictionary& context,
256  const label froms = from::any
257  ) const;
258 
259 
260  // Edit
261 
262  //- Clear out data on mesh change
263  virtual void clearOut();
264 
265 
266  // Distribute
267 
268  //- Map/interpolate the neighbour patch field to this patch
269  template<class Type>
270  tmp<Field<Type>> fromNeighbour(const Field<Type>& nbrFld) const;
271 
272  //- Map/interpolate the neighbour patch field to this patch
273  template<class Type>
275  (
276  const tmp<Field<Type>>& nbrFld
277  ) const;
278 
279  //- Map/interpolate patch field to the neighbour patch
280  template<class Type>
282 
283  //- Map/interpolate patch field to the neighbour patch
284  template<class Type>
286  (
287  const tmp<Field<Type>>& fld
288  ) const;
289 
290 
291  // I/O
292 
293  //- Return whether or not the given dictionary contains a
294  // mappedPatchBase specification
295  static bool specified(const dictionary& dict);
296 
297  //- Write as a dictionary
298  virtual void write(Ostream&) const;
299 };
300 
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 } // End namespace Foam
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 #include "mappedPatchBaseI.H"
309 
310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 
312 #ifdef NoRepository
313  #include "mappedPatchBaseTemplates.C"
314 #endif
315 
316 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
317 
318 #endif
319 
320 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:82
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Encapsulates using patchGroups to specify coupled patch.
Cyclic plane transformation.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Engine which provides mapping between two patches.
tmp< Field< Type > > toNeighbour(const Field< Type > &fld) const
Map/interpolate patch field to the neighbour patch.
bool symmetric() const
Determine whether the neighbouring patch maps from this patch in.
tmp< pointField > nbrPatchLocalPoints() const
Get the local points for the neighbour patch.
const bool reMapAfterMove_
Do we need to re-calculate the mapping if mesh motion takes place?
const polyPatch & nbrPolyPatch() const
Get the patch to map from.
word nbrRegionName_
Name of the region to map from.
word nbrPatchName_
Name of the patch to map from.
bool samePatch() const
Is the neighbour patch the same as this patch?
static const mappedPatchBase & getMap(const polyPatch &patch)
Cast the given polyPatch to a mappedPatchBase. Handle errors.
TypeName("mappedPatchBase")
Runtime type information.
const polyPatch & patch_
Patch to map to.
virtual void write(Ostream &) const
Write as a dictionary.
virtual tmp< vectorField > patchFaceAreas() const
Get the face-areas for this patch.
virtual tmp< pointField > patchLocalPoints() const
Get the local points for this patch.
bool patchToPatchIsValid_
Is the patch-to-patch intersection engine up to date? (if using.
const polyMesh & nbrMesh() const
Get the mesh for the region to map from.
const scalar matchTol_
Matching tolerance.
static void validateMapForField(const PatchFieldType &field, const FieldType &iF, const dictionary &context, const label froms=from::any)
Validate that the map exists and is appropriate for the given.
autoPtr< patchToPatch > patchToPatchPtr_
Patch-to-patch intersection engine (if using patch-to-patch)
static const scalar defaultMatchTol_
Default Matching tolerance.
const word & nbrPatchName() const
Name of the patch to map from.
labelList treeNbrPatchFaceIndices_
Indices of the neighbouring patch faces who's values.
cyclicTransform transform_
The transformation between the patches.
void validateForField(const PatchFieldType &field, const FieldType &iF, const dictionary &context, const label froms=from::any) const
Validate that the map is appropriate for the given.
const word & nbrRegionName() const
Name of the region to map from.
autoPtr< distributionMap > treeMapPtr_
Distributor (if using tree)
bool sameUntransformedPatch() const
Is the neighbour patch the same as this patch with no transform?
bool reMapNbr_
Do we need to re-map the neighbour because this patch moved?
mappedPatchBase(const polyPatch &)
Construct from patch.
tmp< vectorField > nbrPatchFaceAreas() const
Get the face-areas for the neighbour patch.
bool sameRegion() const
Is the neighbour region the same as for this patch?
const mappedPatchBase & nbrMappedPatch() const
Get the mapped neighbouring patch.
static bool specified(const dictionary &dict)
Return whether or not the given dictionary contains a.
tmp< pointField > nbrPatchFaceCentres() const
Get the face-centres for the neighbour patch.
virtual ~mappedPatchBase()
Destructor.
void calcMapping() const
Calculate mapping.
tmp< Field< Type > > fromNeighbour(const Field< Type > &nbrFld) const
Map/interpolate the neighbour patch field to this patch.
const coupleGroupIdentifier coupleGroup_
Couple group for the region/patch to map from.
const bool usingTree_
Are we using the tree mapping method, or a patch-to-patch.
bool nbrPatchIsMapped() const
Return whether or not the neighbour patch is of mapped type.
virtual tmp< pointField > patchFaceCentres() const
Get the face-centres for this patch.
virtual void clearOut()
Clear out data on mesh change.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:483
dictionary dict
Restrict use of the mapper to certain configurations.
static const label differentPatch
static const label differentRegion
static const label sameRegion