1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
25 Foam::globalIndexAndTransform
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.
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.
38 globalIndexAndTransform.C
40 \*---------------------------------------------------------------------------*/
42 #ifndef globalIndexAndTransform_H
43 #define globalIndexAndTransform_H
45 #include "labelPair.H"
46 #include "vectorTensorTransform.H"
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 /*---------------------------------------------------------------------------*\
58 Class globalIndexAndTransform Declaration
59 \*---------------------------------------------------------------------------*/
61 class globalIndexAndTransform
67 //- Less function class used in sorting encoded transforms and indices
76 inline bool operator()(const labelPair&, const labelPair&) const;
85 const polyMesh& mesh_;
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)
94 List<vectorTensorTransform> transforms_;
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
100 List<vectorTensorTransform> transformPermutations_;
102 //- Index of identity transform.
103 label nullTransformIndex_;
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_;
111 // Private static data
113 //- Number of spaces to reserve for transform encoding
114 static const label base_;
117 // Private Member Functions
119 //- Determine all of the independent basic transforms of the
120 // geometry by analysing the coupledPolyPatches
121 void determineTransforms();
123 //- Generate all of the transformation permutations
124 void determineTransformPermutations();
126 //- Determine which patch uses which transform (if any) and which
128 void determinePatchTransformSign();
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.
135 const List<vectorTensorTransform>& refTransforms,
136 label& matchedRefTransformI,
137 const vectorTensorTransform& testTransform,
142 //- Encode transform index. Hardcoded to 3 independent transforms max.
143 inline label encodeTransformIndex
145 const FixedList<Foam::label, 3>& permutationIndices
148 //- Decode transform index. Hardcoded to 3 independent transforms max.
149 inline FixedList<label, 3> decodeTransformIndex
151 const label transformIndex
154 //- Disallow default bitwise copy construct
155 globalIndexAndTransform(const globalIndexAndTransform&);
157 //- Disallow default bitwise assignment
158 void operator=(const globalIndexAndTransform&);
163 //- Declare friendship with the entry class for IO
164 friend class globalPoints;
167 // Declare name of the class and its debug switch
168 ClassName("globalIndexAndTransform");
173 //- Construct from components
174 globalIndexAndTransform(const polyMesh& mesh);
178 ~globalIndexAndTransform();
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
188 const List<label>& permutationIndices
191 //- Add patch transformation to transformIndex. Return new
192 // transformIndex. (by default the patch is the sending, not the
194 inline label addToTransformIndex
196 const label transformIndex,
198 const bool isSendingSide = true
201 //- Combine two transformIndices
202 inline label mergeTransformIndex
204 const label transformIndex0,
205 const label transformIndex1
208 //- Combine two transformIndices
209 inline label minimumTransformIndex
211 const label transformIndex0,
212 const label transformIndex1
215 //- Subtract two transformIndices
216 inline label subtractTransformIndex
218 const label transformIndex0,
219 const label transformIndex1
222 //- Encode index and bare index as components on own processor
223 inline static labelPair encode
226 const label transformIndex
229 //- Encode index and bare index as components on given processor
230 inline static labelPair encode
234 const label transformIndex
237 //- Index carried by the object
238 inline static label index(const labelPair& globalIAndTransform);
240 //- Which processor does this come from?
241 inline static label processor(const labelPair& globalIAndTransform);
243 //- Transform carried by the object
244 inline static label transformIndex
246 const labelPair& globalIAndTransform
251 //- Return the number of independent transforms
252 inline label nIndependentTransforms() const;
254 //- Return access to the stored independent transforms
255 inline const List<vectorTensorTransform>& transforms() const;
257 //- Return access to the permuted transforms
258 inline const List<vectorTensorTransform>&
259 transformPermutations() const;
261 //- Return the transformIndex (index in transformPermutations)
262 // of the identity transform
263 inline label nullTransformIndex() const;
265 //- Return access to the per-patch transform-sign pairs
266 inline const List<Pair<label> >& patchTransformSign() const;
268 //- Access the overall (permuted) transform corresponding
269 // to the transformIndex
270 inline const vectorTensorTransform& transform
275 //- Access the all of the indices of the transform
276 // permutations corresponding the transforms of the
277 // listed patch indices
278 inline labelList transformIndicesForPatches
280 const labelHashSet& patchIs
283 //- Apply all of the transform permutations
284 // corresponding the transforms of the listed patch
285 // indices to the supplied point
286 inline pointField transformPatches
288 const labelHashSet& patchIs,
295 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
297 } // End namespace Foam
299 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 #include "globalIndexAndTransformI.H"
303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 // ************************************************************************* //