globalIndexAndTransform.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 | Copyright (C) 2011-2016 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 "vectorTensorTransform.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<vectorTensorTransform> 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<vectorTensorTransform> 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<vectorTensorTransform>& refTransforms,
137  label& matchedRefTransformI,
138  const vectorTensorTransform& 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  //- Disallow default bitwise copy construct
155 
156  //- Disallow default bitwise assignment
157  void operator=(const globalIndexAndTransform&);
158 
159 
160 public:
161 
162  // Declare name of the class and its debug switch
163  ClassName("globalIndexAndTransform");
164 
165 
166  // Constructors
167 
168  //- Construct from components
170 
171 
172  // Member Functions
173 
174  //- Generate a transform index from the permutation indices of
175  // the independent transforms. Permutations indices must
176  // only be -1, 0 or +1.
178  (
179  const labelList& permutationIndices
180  ) const;
181 
182  //- Decode transform index
184 
185  //- Add patch transformation to transformIndex. Return new
186  // transformIndex. (by default the patch is the sending, not the
187  // receiving, patch)
189  (
190  const label transformIndex,
191  const label patchi,
192  const bool isSendingSide = true,
193  const scalar tol = SMALL
194  ) const;
195 
196  //- Combine two transformIndices
198  (
199  const label transformIndex0,
200  const label transformIndex1
201  ) const;
202 
203  //- Combine two transformIndices
205  (
206  const label transformIndex0,
207  const label transformIndex1
208  ) const;
209 
210  //- Subtract two transformIndices
212  (
213  const label transformIndex0,
214  const label transformIndex1
215  ) const;
216 
217  //- Encode index and bare index as components on own processor
218  inline labelPair encode
219  (
220  const label index,
221  const label transformIndex
222  ) const;
223 
224  //- Encode index and bare index as components on given processor
225  inline labelPair encode
226  (
227  const label proci,
228  const label index,
229  const label transformIndex
230  ) const;
231 
232  //- Index carried by the object
233  inline label index(const labelPair& globalIAndTransform) const;
234 
235  //- Which processor does this come from?
236  inline label processor(const labelPair& globalIAndTransform) const;
237 
238  //- Transform carried by the object
239  inline label transformIndex(const labelPair& globalIAndTransform) const;
240 
241  //- Return the number of independent transforms
242  inline label nIndependentTransforms() const;
243 
244  //- Return access to the stored independent transforms
245  inline const List<vectorTensorTransform>& transforms() const;
246 
247  //- Return access to the permuted transforms
248  inline const List<vectorTensorTransform>&
249  transformPermutations() const;
250 
251  //- Return the transformIndex (index in transformPermutations)
252  // of the identity transform
253  inline label nullTransformIndex() const;
254 
255  //- Return access to the per-patch transform-sign pairs
256  inline const List<labelPair>& patchTransformSign() const;
257 
258  //- Access the overall (permuted) transform corresponding
259  // to the transformIndex
260  inline const vectorTensorTransform& transform
261  (
262  label transformIndex
263  ) const;
264 
265  //- Access the all of the indices of the transform
266  // permutations corresponding the transforms of the
267  // listed patch indices. This only allows a maximum of three
268  // transformations (since routine is used to transform points and
269  // any given point can only be on 3 or less transforms)
271  (
272  const labelHashSet& patchIs
273  ) const;
274 
275  //- Apply all of the transform permutations
276  // corresponding the transforms of the listed patch
277  // indices to the supplied point
279  (
280  const labelHashSet& patchIs,
281  const point& pt
282  ) const;
283 
284 };
285 
286 
287 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
288 
289 } // End namespace Foam
290 
291 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
292 
294 
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
296 
297 #endif
298 
299 // ************************************************************************* //
Less function class used in sorting encoded transforms and indices.
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
label index(const labelPair &globalIAndTransform) const
Index carried by the object.
label nIndependentTransforms() const
Return the number of independent transforms.
Vector-tensor class used to perform translations and rotations in 3D space.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
const List< vectorTensorTransform > & transformPermutations() const
Return access to the permuted transforms.
label processor(const labelPair &globalIAndTransform) const
Which processor does this come from?
labelPair encode(const label index, const label transformIndex) const
Encode index and bare index as components on own processor.
label subtractTransformIndex(const label transformIndex0, const label transformIndex1) const
Subtract two transformIndices.
dynamicFvMesh & mesh
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: contiguous.H:49
const List< vectorTensorTransform > & transforms() const
Return access to the stored independent transforms.
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 vectorTensorTransform & transform(label transformIndex) const
Access the overall (permuted) transform corresponding.
const List< labelPair > & patchTransformSign() const
Return access to the per-patch transform-sign pairs.
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 minimumTransformIndex(const label transformIndex0, const label transformIndex1) const
Combine two transformIndices.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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.