BUGFIX: Uninitialised member variables
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / decomposePar / tetPointFieldDecomposer.C
blob6bef04fc04d4afeb9fa67d354bf030889e818487
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 #   ifdef FACE_DECOMP
68     // Insert face addressing.  Only for face decomposition
69     const label faceOffset = originalMesh_.faceOffset();
71     // Use only live faces.  HJ, 14/Apr/2009
72     for (label faceI = 0; faceI < processorMesh_().nFaces(); faceI++)
73     {
74         // Remember to decrement the index by one (turning index)
75         addr[nAddr] = faceOffset + mag(faceAddressing_[faceI]) - 1;
76         nAddr++;
77     }
78 #   endif
80     // Insert cell addressing
81     const label cellOffset = originalMesh_.cellOffset();
83     forAll (cellAddressing_, cellI)
84     {
85         addr[nAddr] = cellOffset + cellAddressing_[cellI];
86         nAddr++;
87     }
91 const labelList& tetPointFieldDecomposer::directAddressing() const
93     if (!directAddressingPtr_)
94     {
95         calcAddressing();
96     }
98     return *directAddressingPtr_;
102 // Calculate patch addressing
103 void tetPointFieldDecomposer::
104 tetPolyPatchFieldDecomposer::calcPatchAddressing() const
106     if (directPatchAddressingPtr_)
107     {
108         FatalErrorIn
109         (
110             "void tetPointFieldDecomposer::"
111             "tetPolyPatchFieldDecomposer::calcPatchAddressing() const"
112         )   << "addressing already calculated"
113             << abort(FatalError);
114     }
116     // Allocate the addressing
117     directPatchAddressingPtr_ = new labelList(targetPatch().size(), -1);
118     labelList& addr = *directPatchAddressingPtr_;
120     // Algorithm:
121     // Go to the source patch, create a lookup list the size of all
122     // points in the mesh and then gather the points for the current
123     // patch.
124     labelList pointLookup
125         (sourcePatch().boundaryMesh().mesh().nPoints(), -1);
127     const labelList& sourcePatchPoints = sourcePatch().meshPoints();
129     forAll (sourcePatchPoints, pointI)
130     {
131         pointLookup[sourcePatchPoints[pointI]] = pointI;
132     }
134     // Gather the information
136     const labelList& targetPatchPoints = targetPatch().meshPoints();
138     forAll (targetPatchPoints, pointI)
139     {
140         addr[pointI] =
141             pointLookup[directAddressing_[targetPatchPoints[pointI]]];
142     }
144     if (addr.size() && min(addr) < 0)
145     {
146         FatalErrorIn
147         (
148             "void tetPointFieldDecomposer::"
149             "tetPolyPatchFieldDecomposer::calcPatchAddressing() const"
150         )   << "error in addressing"
151             << abort(FatalError);
152     }
156 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
158 // Construct from components
159 tetPointFieldDecomposer::tetPointFieldDecomposer
161     const tetPolyMesh& originalMesh,
162     const tetPolyMesh& processorMesh,
163     const labelList& pointAddressing,
164     const labelList& faceAddressing,
165     const labelList& cellAddressing,
166     const labelList& boundaryAddressing
169     originalMesh_(originalMesh),
170     processorMesh_(processorMesh),
171     pointAddressing_(pointAddressing),
172     faceAddressing_(faceAddressing),
173     cellAddressing_(cellAddressing),
174     boundaryAddressing_(boundaryAddressing),
175     patchFieldDecompPtrs_
176     (
177         processorMesh_.boundary().size(),
178         reinterpret_cast<tetPolyPatchFieldDecomposer*>(NULL)
179     ),
180     directAddressingPtr_(NULL)
182     // Set the patch field decomposers for all non-processor patch fields
183     forAll (boundaryAddressing_, patchI)
184     {
185         if (boundaryAddressing_[patchI] >= 0)
186         {
187             patchFieldDecompPtrs_[patchI] =
188                 new tetPolyPatchFieldDecomposer
189                 (
190                     originalMesh_.boundary()[boundaryAddressing_[patchI]],
191                     processorMesh_.boundary()[patchI],
192                     directAddressing()
193                 );
194         }
195         // for processor patches the pointer stays null
196     }
200 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
202 tetPointFieldDecomposer::~tetPointFieldDecomposer()
204     forAll (patchFieldDecompPtrs_, patchI)
205     {
206         if (patchFieldDecompPtrs_[patchI] != NULL)
207         {
208             delete(patchFieldDecompPtrs_[patchI]);
209             patchFieldDecompPtrs_[patchI] = NULL;
210         }
211     }
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
217 } // End namespace Foam
219 // ************************************************************************* //