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