BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / decomposePar / tetPointFieldDecomposer.C
blob69690cdf843d737b01b074627ebf497e400c7876
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Tetrahedral point field decomposer.
28 \*---------------------------------------------------------------------------*/
30 #include "tetPointFieldDecomposer.H"
31 #include "typeInfo.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
40 // Calculate point addressing
41 void tetPointFieldDecomposer::calcAddressing() const
43     if (directAddressingPtr_)
44     {
45         FatalErrorIn
46         (
47             "void tetPointFieldDecomposer::calcAddressing() const"
48         )   << "addressing already calculated"
49             << abort(FatalError);
50     }
52     // Allocate the addressing
53     directAddressingPtr_ = new labelList(processorMesh_.nPoints(), -1);
54     labelList& addr = *directAddressingPtr_;
56     label nAddr = 0;
58     // Insert point addressing
60     // Use only live points.  HJ, 14/Apr/2009
61     for (label pointI = 0; pointI < processorMesh_().nPoints(); pointI++)
62     {
63         addr[nAddr] = pointAddressing_[pointI];
64         nAddr++;
65     }
67     // Insert face addressing.  Only for face decomposition
68     const label faceOffset = originalMesh_.faceOffset();
70     // Use only live faces.  HJ, 14/Apr/2009
71     for (label faceI = 0; faceI < processorMesh_().nFaces(); faceI++)
72     {
73         // Remember to decrement the index by one (turning index)
74         addr[nAddr] = faceOffset + mag(faceAddressing_[faceI]) - 1;
75         nAddr++;
76     }
78     // Insert cell addressing
79     const label cellOffset = originalMesh_.cellOffset();
81     forAll (cellAddressing_, cellI)
82     {
83         addr[nAddr] = cellOffset + cellAddressing_[cellI];
84         nAddr++;
85     }
89 const labelList& tetPointFieldDecomposer::directAddressing() const
91     if (!directAddressingPtr_)
92     {
93         calcAddressing();
94     }
96     return *directAddressingPtr_;
100 // Calculate patch addressing
101 void tetPointFieldDecomposer::
102 tetPolyPatchFieldDecomposer::calcPatchAddressing() const
104     if (directPatchAddressingPtr_)
105     {
106         FatalErrorIn
107         (
108             "void tetPointFieldDecomposer::"
109             "tetPolyPatchFieldDecomposer::calcPatchAddressing() const"
110         )   << "addressing already calculated"
111             << abort(FatalError);
112     }
114     // Allocate the addressing
115     directPatchAddressingPtr_ = new labelList(targetPatch().size(), -1);
116     labelList& addr = *directPatchAddressingPtr_;
118     // Algorithm:
119     // Go to the source patch, create a lookup list the size of all
120     // points in the mesh and then gather the points for the current
121     // patch.
122     labelList pointLookup
123         (sourcePatch().boundaryMesh().mesh().nPoints(), -1);
125     const labelList& sourcePatchPoints = sourcePatch().meshPoints();
127     forAll (sourcePatchPoints, pointI)
128     {
129         pointLookup[sourcePatchPoints[pointI]] = pointI;
130     }
132     // Gather the information
134     const labelList& targetPatchPoints = targetPatch().meshPoints();
136     forAll (targetPatchPoints, pointI)
137     {
138         addr[pointI] =
139             pointLookup[directAddressing_[targetPatchPoints[pointI]]];
140     }
142     if (addr.size() && min(addr) < 0)
143     {
144         FatalErrorIn
145         (
146             "void tetPointFieldDecomposer::"
147             "tetPolyPatchFieldDecomposer::calcPatchAddressing() const"
148         )   << "error in addressing"
149             << abort(FatalError);
150     }
154 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
156 // Construct from components
157 tetPointFieldDecomposer::tetPointFieldDecomposer
159     const tetPolyMesh& originalMesh,
160     const tetPolyMesh& processorMesh,
161     const labelList& pointAddressing,
162     const labelList& faceAddressing,
163     const labelList& cellAddressing,
164     const labelList& boundaryAddressing
167     originalMesh_(originalMesh),
168     processorMesh_(processorMesh),
169     pointAddressing_(pointAddressing),
170     faceAddressing_(faceAddressing),
171     cellAddressing_(cellAddressing),
172     boundaryAddressing_(boundaryAddressing),
173     patchFieldDecompPtrs_
174     (
175         processorMesh_.boundary().size(),
176         reinterpret_cast<tetPolyPatchFieldDecomposer*>(NULL)
177     ),
178     directAddressingPtr_(NULL)
180     // Set the patch field decomposers for all non-processor patch fields
181     forAll (boundaryAddressing_, patchI)
182     {
183         if (boundaryAddressing_[patchI] >= 0)
184         {
185             patchFieldDecompPtrs_[patchI] =
186                 new tetPolyPatchFieldDecomposer
187                 (
188                     originalMesh_.boundary()[boundaryAddressing_[patchI]],
189                     processorMesh_.boundary()[patchI],
190                     directAddressing()
191                 );
192         }
193         // for processor patches the pointer stays null
194     }
198 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
200 tetPointFieldDecomposer::~tetPointFieldDecomposer()
202     forAll (patchFieldDecompPtrs_, patchI)
203     {
204         if (patchFieldDecompPtrs_[patchI] != NULL)
205         {
206             delete(patchFieldDecompPtrs_[patchI]);
207             patchFieldDecompPtrs_[patchI] = NULL;
208         }
209     }
213 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 } // End namespace Foam
217 // ************************************************************************* //