globalIndexAndTransform.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-2019 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::globalIndexAndTransform
26 
27 Description
28  Determination and storage of the possible independent transforms
29  introduced by coupledPolyPatches, as well as all of the possible
30  permutations of these transforms generated by the presence of
31  multiple coupledPolyPatches, i.e. more than one cyclic boundary. Note that
32  any given point can be on maximum 3 transforms only (and these transforms
33  have to be perpendicular)
34 
35  Also provides global index encoding and decoding for entity
36  (i.e. cell) index, processor index and transform index (0 or
37  positive integer) to a labelPair.
38 
39 SourceFiles
40  globalIndexAndTransform.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef globalIndexAndTransform_H
45 #define globalIndexAndTransform_H
46 
47 #include "labelPair.H"
48 #include "transformer.H"
49 #include "HashSet.H"
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 namespace Foam
54 {
55 
56 class polyMesh;
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class globalIndexAndTransform Declaration
61 \*---------------------------------------------------------------------------*/
62 
64 {
65 public:
66 
67  // Public classes
68 
69  //- Less function class used in sorting encoded transforms and indices
70  // Minimum of:
71  // - processor
72  // - local index
73  // - transform
74  class less
75  {
76  const globalIndexAndTransform& gi_;
77 
78  public:
79 
80  less(const globalIndexAndTransform& gi)
81  :
82  gi_(gi)
83  {}
84 
85  inline bool operator()(const labelPair&, const labelPair&) const;
86  };
87 
88 
89 private:
90 
91  // Private Data
92 
93  //- Reference to mesh
94  const polyMesh& mesh_;
95 
96  //- The possible independent (non-permuted) transforms of the
97  // geometry, i.e. for a geometry with two cyclics, this
98  // stores the two transforms, not the eight permutations.
99  // Any point can not be on more than three transforms but overall
100  // the mesh can have more than three.
101  List<transformer> transforms_;
102 
103  //- The permutations of the transforms, stored for lookup
104  // efficiency. If there are n transforms, then there are
105  // (3^n) permutations, including the no-transformation
106  // transform.
107  List<transformer> transformPermutations_;
108 
109  //- Index of identity transform.
110  label nullTransformIndex_;
111 
112  //- Mapping from patch index to which transform it matches (or
113  // -1 for none) (.first()) and what sign to use for it,
114  // i.e. +/- 1 (.second()).
115  List<labelPair> patchTransformSign_;
116 
117 
118  // Private Member Functions
119 
120  //- Determine all of the independent basic transforms of the
121  // geometry by analysing the coupledPolyPatches
122  void determineTransforms();
123 
124  //- Generate all of the transformation permutations
125  void determineTransformPermutations();
126 
127  //- Determine which patch uses which transform (if any) and which
128  // sign to use
129  void determinePatchTransformSign();
130 
131  //- Test a list of reference transforms to see if the test
132  // transform matches one. Return +1 or -1 depending on the
133  // sign of the match, or 0 if none matches.
134  label matchTransform
135  (
136  const List<transformer>& refTransforms,
137  label& matchedRefTransformI,
138  const transformer& testTransform,
139  scalar tolerance,
140  bool checkBothSigns
141  ) const;
142 
143  //- Return true if transform is not yet present in trafos. Issues
144  // warning if too many transforms
145  bool uniqueTransform
146  (
147  const point& pt,
148  labelPairList& trafos,
149  const label patchi,
150  const labelPair& patchTrafo
151  ) const;
152 
153 
154 public:
155 
156  // Declare name of the class and its debug switch
157  ClassName("globalIndexAndTransform");
158 
159 
160  // Constructors
161 
162  //- Construct from components
164 
165  //- Disallow default bitwise copy construction
167 
168 
169  // Member Functions
170 
171  //- Generate a transform index from the permutation indices of
172  // the independent transforms. Permutations indices must
173  // only be -1, 0 or +1.
175  (
176  const labelList& permutationIndices
177  ) const;
178 
179  //- Decode transform index
181 
182  //- Add patch transformation to transformIndex. Return new
183  // transformIndex. (by default the patch is the sending, not the
184  // receiving, patch)
186  (
187  const label transformIndex,
188  const label patchi,
189  const bool isSendingSide = true,
190  const scalar tol = small
191  ) const;
192 
193  //- Combine two transformIndices
195  (
196  const label transformIndex0,
197  const label transformIndex1
198  ) const;
199 
200  //- Combine two transformIndices
202  (
203  const label transformIndex0,
204  const label transformIndex1
205  ) const;
206 
207  //- Subtract two transformIndices
209  (
210  const label transformIndex0,
211  const label transformIndex1
212  ) const;
213 
214  //- Encode index and bare index as components on own processor
215  inline labelPair encode
216  (
217  const label index,
218  const label transformIndex
219  ) const;
220 
221  //- Encode index and bare index as components on given processor
222  inline labelPair encode
223  (
224  const label proci,
225  const label index,
226  const label transformIndex
227  ) const;
228 
229  //- Index carried by the object
230  inline label index(const labelPair& globalIAndTransform) const;
231 
232  //- Which processor does this come from?
233  inline label processor(const labelPair& globalIAndTransform) const;
234 
235  //- Transform carried by the object
236  inline label transformIndex(const labelPair& globalIAndTransform) const;
237 
238  //- Return the number of independent transforms
239  inline label nIndependentTransforms() const;
240 
241  //- Return access to the stored independent transforms
242  inline const List<transformer>& transforms() const;
243 
244  //- Return access to the permuted transforms
245  inline const List<transformer>&
246  transformPermutations() const;
247 
248  //- Return the transformIndex (index in transformPermutations)
249  // of the identity transform
250  inline label nullTransformIndex() const;
251 
252  //- Return access to the per-patch transform-sign pairs
253  inline const List<labelPair>& patchTransformSign() const;
254 
255  //- Access the overall (permuted) transform corresponding
256  // to the transformIndex
257  inline const transformer& transform
258  (
259  label transformIndex
260  ) const;
261 
262  //- Access the all of the indices of the transform
263  // permutations corresponding the transforms of the
264  // listed patch indices. This only allows a maximum of three
265  // transformations (since routine is used to transform points and
266  // any given point can only be on 3 or less transforms)
268  (
269  const labelHashSet& patchIs
270  ) const;
271 
272  //- Apply all of the transform permutations
273  // corresponding the transforms of the listed patch
274  // indices to the supplied point
276  (
277  const labelHashSet& patchIs,
278  const point& pt
279  ) const;
280 
281 
282  // Member Operators
283 
284  //- Disallow default bitwise assignment
285  void operator=(const globalIndexAndTransform&) = delete;
286 };
287 
288 
289 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
290 
291 } // End namespace Foam
292 
293 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
294 
296 
297 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
298 
299 #endif
300 
301 // ************************************************************************* //
Less function class used in sorting encoded transforms and indices.
void operator=(const globalIndexAndTransform &)=delete
Disallow default bitwise assignment.
const List< transformer > & transformPermutations() const
Return access to the permuted transforms.
label index(const labelPair &globalIAndTransform) const
Index carried by the object.
Vector-tensor class used to perform translations, rotations and scaling operations in 3D space...
Definition: transformer.H:83
label nIndependentTransforms() const
Return the number of independent transforms.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
globalIndexAndTransform(const polyMesh &mesh)
Construct from components.
const List< transformer > & transforms() const
Return access to the stored independent transforms.
label processor(const labelPair &globalIAndTransform) const
Which processor does this come from?
const transformer & transform(label transformIndex) const
Access the overall (permuted) transform corresponding.
fvMesh & mesh
labelPair encode(const label index, const label transformIndex) const
Encode index and bare index as components on own processor.
label addToTransformIndex(const label transformIndex, const label patchi, const bool isSendingSide=true, const scalar tol=small) const
Add patch transformation to transformIndex. Return new.
label subtractTransformIndex(const label transformIndex0, const label transformIndex1) const
Subtract two transformIndices.
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
ClassName("globalIndexAndTransform")
less(const globalIndexAndTransform &gi)
label nullTransformIndex() const
Return the transformIndex (index in transformPermutations)
bool operator()(const labelPair &, const labelPair &) const
label mergeTransformIndex(const label transformIndex0, const label transformIndex1) const
Combine two transformIndices.
pointField transformPatches(const labelHashSet &patchIs, const point &pt) const
Apply all of the transform permutations.
label transformIndex(const labelPair &globalIAndTransform) const
Transform carried by the object.
label patchi
const List< labelPair > & patchTransformSign() const
Return access to the per-patch transform-sign pairs.
label minimumTransformIndex(const label transformIndex0, const label transformIndex1) const
Combine two transformIndices.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
labelList transformIndicesForPatches(const labelHashSet &patchIs) const
Access the all of the indices of the transform.
labelList decodeTransformIndex(const label transformIndex) const
Decode transform index.
Namespace for OpenFOAM.
Determination and storage of the possible independent transforms introduced by coupledPolyPatches, as well as all of the possible permutations of these transforms generated by the presence of multiple coupledPolyPatches, i.e. more than one cyclic boundary. Note that any given point can be on maximum 3 transforms only (and these transforms have to be perpendicular)
label encodeTransformIndex(const labelList &permutationIndices) const
Generate a transform index from the permutation indices of.