Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / decomposePar / tetPointFieldDecomposer.C
blobf0d3ddc4096ddab00146cead4495f77db210abd4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Tetrahedral point field decomposer.
27 \*---------------------------------------------------------------------------*/
29 #include "tetPointFieldDecomposer.H"
30 #include "typeInfo.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
39 // Calculate point addressing
40 void tetPointFieldDecomposer::calcAddressing() const
42     if (directAddressingPtr_)
43     {
44         FatalErrorIn
45         (
46             "void tetPointFieldDecomposer::calcAddressing() const"
47         )   << "addressing already calculated"
48             << abort(FatalError);
49     }
51     // Allocate the addressing
52     directAddressingPtr_ = new labelList(processorMesh_.nPoints(), -1);
53     labelList& addr = *directAddressingPtr_;
55     label nAddr = 0;
57     // Insert point addressing
59     // Use only live points.  HJ, 14/Apr/2009
60     for (label pointI = 0; pointI < processorMesh_().nPoints(); pointI++)
61     {
62         addr[nAddr] = pointAddressing_[pointI];
63         nAddr++;
64     }
66     // Insert face addressing.  Only for face decomposition
67     const label faceOffset = originalMesh_.faceOffset();
69     // Use only live faces.  HJ, 14/Apr/2009
70     for (label faceI = 0; faceI < processorMesh_().nFaces(); faceI++)
71     {
72         // Remember to decrement the index by one (turning index)
73         addr[nAddr] = faceOffset + mag(faceAddressing_[faceI]) - 1;
74         nAddr++;
75     }
77     // Insert cell addressing
78     const label cellOffset = originalMesh_.cellOffset();
80     forAll (cellAddressing_, cellI)
81     {
82         addr[nAddr] = cellOffset + cellAddressing_[cellI];
83         nAddr++;
84     }
88 const labelList& tetPointFieldDecomposer::directAddressing() const
90     if (!directAddressingPtr_)
91     {
92         calcAddressing();
93     }
95     return *directAddressingPtr_;
99 // Calculate patch addressing
100 void tetPointFieldDecomposer::
101 tetPolyPatchFieldDecomposer::calcPatchAddressing() const
103     if (directPatchAddressingPtr_)
104     {
105         FatalErrorIn
106         (
107             "void tetPointFieldDecomposer::"
108             "tetPolyPatchFieldDecomposer::calcPatchAddressing() const"
109         )   << "addressing already calculated"
110             << abort(FatalError);
111     }
113     // Allocate the addressing
114     directPatchAddressingPtr_ = new labelList(targetPatch().size(), -1);
115     labelList& addr = *directPatchAddressingPtr_;
117     // Algorithm:
118     // Go to the source patch, create a lookup list the size of all
119     // points in the mesh and then gather the points for the current
120     // patch.
121     labelList pointLookup
122         (sourcePatch().boundaryMesh().mesh().nPoints(), -1);
124     const labelList& sourcePatchPoints = sourcePatch().meshPoints();
126     forAll (sourcePatchPoints, pointI)
127     {
128         pointLookup[sourcePatchPoints[pointI]] = pointI;
129     }
131     // Gather the information
133     const labelList& targetPatchPoints = targetPatch().meshPoints();
135     forAll (targetPatchPoints, pointI)
136     {
137         addr[pointI] =
138             pointLookup[directAddressing_[targetPatchPoints[pointI]]];
139     }
141     if (addr.size() && min(addr) < 0)
142     {
143         FatalErrorIn
144         (
145             "void tetPointFieldDecomposer::"
146             "tetPolyPatchFieldDecomposer::calcPatchAddressing() const"
147         )   << "error in addressing"
148             << abort(FatalError);
149     }
153 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
155 // Construct from components
156 tetPointFieldDecomposer::tetPointFieldDecomposer
158     const tetPolyMesh& originalMesh,
159     const tetPolyMesh& processorMesh,
160     const labelList& pointAddressing,
161     const labelList& faceAddressing,
162     const labelList& cellAddressing,
163     const labelList& boundaryAddressing
166     originalMesh_(originalMesh),
167     processorMesh_(processorMesh),
168     pointAddressing_(pointAddressing),
169     faceAddressing_(faceAddressing),
170     cellAddressing_(cellAddressing),
171     boundaryAddressing_(boundaryAddressing),
172     patchFieldDecompPtrs_
173     (
174         processorMesh_.boundary().size(),
175         reinterpret_cast<tetPolyPatchFieldDecomposer*>(NULL)
176     ),
177     directAddressingPtr_(NULL)
179     // Set the patch field decomposers for all non-processor patch fields
180     forAll (boundaryAddressing_, patchI)
181     {
182         if (boundaryAddressing_[patchI] >= 0)
183         {
184             patchFieldDecompPtrs_[patchI] =
185                 new tetPolyPatchFieldDecomposer
186                 (
187                     originalMesh_.boundary()[boundaryAddressing_[patchI]],
188                     processorMesh_.boundary()[patchI],
189                     directAddressing()
190                 );
191         }
192         // for processor patches the pointer stays null
193     }
197 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
199 tetPointFieldDecomposer::~tetPointFieldDecomposer()
201     forAll (patchFieldDecompPtrs_, patchI)
202     {
203         if (patchFieldDecompPtrs_[patchI] != NULL)
204         {
205             delete(patchFieldDecompPtrs_[patchI]);
206             patchFieldDecompPtrs_[patchI] = NULL;
207         }
208     }
212 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 } // End namespace Foam
216 // ************************************************************************* //