BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / reconstructParMesh / tetPointFieldReconstructor.C
blob25a930aaca092a28343b983bb6897e4ee628b593
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 \*---------------------------------------------------------------------------*/
27 #include "tetPointFieldReconstructor.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
36 // Calculate point addressing
37 labelList tetPointFieldReconstructor::procAddressing
39     const label procNo
40 ) const
42     // Allocate the addressing
43     labelList addr(procMeshes_[procNo].nPoints(), -1);
45     const labelList& pointAddr = pointProcAddressing_[procNo];
46     const labelList& cellAddr = cellProcAddressing_[procNo];
48     label nAddr = 0;
50     // Insert point addressing
52     // Use only live points.  HJ, 14/Apr/2009
53     for (label pointI = 0; pointI < procMeshes_[procNo]().nPoints(); pointI++)
54     {
55         addr[nAddr] = pointAddr[pointI];
56         nAddr++;
57     }
59     // Insert face addressing.  Only for face decomposition
60     const labelList& faceAddr = faceProcAddressing_[procNo];
62     const label faceOffset = mesh_.faceOffset();
64     // Use only live faces.  HJ, 14/Apr/2009
65     for (label faceI = 0; faceI < procMeshes_[procNo]().nFaces(); faceI++)
66     {
67         // Remember to decrement the index by one (turning index)
68         addr[nAddr] = faceOffset + mag(faceAddr[faceI]) - 1;
69         nAddr++;
70     }
72     // Insert cell addressing
73     const label cellOffset = mesh_.cellOffset();
75     forAll (cellAddr, cellI)
76     {
77         addr[nAddr] = cellOffset + cellAddr[cellI];
78         nAddr++;
79     }
81     return addr;
85 labelList tetPointFieldReconstructor::procPatchAddressing
87     const labelList& procToGlobalAddr,
88     const label procNo,
89     const label patchNo
90 ) const
92     labelList addr(procMeshes_[procNo].boundary()[patchNo].size(), -1);
94     // Algorithm:
95     // Go to the global patch, create a lookup list the size of all
96     // points in the mesh and then gather the points for the current
97     // patch.
98     labelList pointLookup(mesh_.nPoints(), -1);
100     const labelList& globalPatchPoints =
101         mesh_.boundary()[boundaryProcAddressing_[procNo][patchNo]].meshPoints();
103     forAll (globalPatchPoints, pointI)
104     {
105         pointLookup[globalPatchPoints[pointI]] = pointI;
106     }
108     // Gather the information
110     const labelList& procPatchPoints =
111         procMeshes_[procNo].boundary()[patchNo].meshPoints();
113     forAll (procPatchPoints, pointI)
114     {
115         addr[pointI] =
116             pointLookup[procToGlobalAddr[procPatchPoints[pointI]]];
117     }
119     if (addr.size() && min(addr) < 0)
120     {
121         FatalErrorIn
122         (
123             "labelList tetPointFieldReconstructor::"
124             "patchProcAddressing\n"
125             "(\n"
126             "    const labelList& procToGlobalAddr,\n"
127             "    const label procNo,\n"
128             "    const label patchNo\n"
129             ") const"
130         )   << "error in addressing"
131             << abort(FatalError);
132     }
134     return addr;
138 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
140 // Construct from components
141 tetPointFieldReconstructor::tetPointFieldReconstructor
143     tetPolyMesh& mesh,
144     const PtrList<tetPolyMesh>& procMeshes,
145     const PtrList<labelIOList>& pointProcAddressing,
146     const PtrList<labelIOList>& faceProcAddressing,
147     const PtrList<labelIOList>& cellProcAddressing,
148     const PtrList<labelIOList>& boundaryProcAddressing
151     mesh_(mesh),
152     procMeshes_(procMeshes),
153     pointProcAddressing_(pointProcAddressing),
154     faceProcAddressing_(faceProcAddressing),
155     cellProcAddressing_(cellProcAddressing),
156     boundaryProcAddressing_(boundaryProcAddressing)
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 } // End namespace Foam
164 // ************************************************************************* //