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