BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / decomposePar / faFieldDecomposer.C
blob433b84ae0d34511a9b3294b153c8df44ddc8d685
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 "faFieldDecomposer.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
36 faFieldDecomposer::patchFieldDecomposer::patchFieldDecomposer
38     const label sizeBeforeMapping,
39     const unallocLabelList& addressingSlice,
40     const label addressingOffset
43     sizeBeforeMapping_(sizeBeforeMapping),
44     directAddressing_(addressingSlice)
46     forAll (directAddressing_, i)
47     {
48         // Subtract one to align addressing.
49         // directAddressing_[i] -= addressingOffset + 1;
50         // ZT, 12/Nov/2010
51         directAddressing_[i] -= addressingOffset;
52     }
56 faFieldDecomposer::processorAreaPatchFieldDecomposer::
57 processorAreaPatchFieldDecomposer
59     const faMesh& mesh,
60     const unallocLabelList& addressingSlice
63     sizeBeforeMapping_(mesh.nFaces()),
64     addressing_(addressingSlice.size()),
65     weights_(addressingSlice.size())
67     const scalarField& weights = mesh.weights().internalField();
68     const labelList& own = mesh.edgeOwner();
69     const labelList& neighb = mesh.edgeNeighbour();
71     forAll (addressing_, i)
72     {
73         // Subtract one to align addressing.
74         label ai = addressingSlice[i];
75 //         label ai = mag(addressingSlice[i]) - 1;
77         if (ai < neighb.size())
78         {
79             // This is a regular edge. it has been an internal edge
80             // of the original mesh and now it has become a edge
81             // on the parallel boundary
82             addressing_[i].setSize(2);
83             weights_[i].setSize(2);
85             addressing_[i][0] = own[ai];
86             addressing_[i][1] = neighb[ai];
88             weights_[i][0] = weights[ai];
89             weights_[i][1] = 1.0 - weights[ai];
90         }
91         else
92         {
93             // This is a edge that used to be on a cyclic boundary
94             // but has now become a parallel patch edge. I cannot
95             // do the interpolation properly (I would need to look
96             // up the different (edge) list of data), so I will
97             // just grab the value from the owner face
98             //
99             addressing_[i].setSize(1);
100             weights_[i].setSize(1);
102             addressing_[i][0] = own[ai];
104             weights_[i][0] = 1.0;
105         }
106     }
110 faFieldDecomposer::processorEdgePatchFieldDecomposer::
111 processorEdgePatchFieldDecomposer
113     label sizeBeforeMapping,
114     const unallocLabelList& addressingSlice
117     sizeBeforeMapping_(sizeBeforeMapping),
118     addressing_(addressingSlice.size()),
119     weights_(addressingSlice.size())
121     forAll (addressing_, i)
122     {
123         addressing_[i].setSize(1);
124         weights_[i].setSize(1);
126         addressing_[i][0] = mag(addressingSlice[i]) - 1;
127         weights_[i][0] = sign(addressingSlice[i]);
128     }
132 faFieldDecomposer::faFieldDecomposer
134     const faMesh& completeMesh,
135     const faMesh& procMesh,
136     const labelList& edgeAddressing,
137     const labelList& faceAddressing,
138     const labelList& boundaryAddressing
141     completeMesh_(completeMesh),
142     procMesh_(procMesh),
143     edgeAddressing_(edgeAddressing),
144     faceAddressing_(faceAddressing),
145     boundaryAddressing_(boundaryAddressing),
146     patchFieldDecomposerPtrs_
147     (
148         procMesh_.boundary().size(),
149         static_cast<patchFieldDecomposer*>(NULL)
150     ),
151     processorAreaPatchFieldDecomposerPtrs_
152     (
153         procMesh_.boundary().size(),
154         static_cast<processorAreaPatchFieldDecomposer*>(NULL)
155     ),
156     processorEdgePatchFieldDecomposerPtrs_
157     (
158         procMesh_.boundary().size(),
159         static_cast<processorEdgePatchFieldDecomposer*>(NULL)
160     )
162     forAll (boundaryAddressing_, patchi)
163     {
164         if (boundaryAddressing_[patchi] >= 0)
165         {
166             patchFieldDecomposerPtrs_[patchi] = new patchFieldDecomposer
167             (
168                 completeMesh_.boundary()[boundaryAddressing_[patchi]].size(),
169                 procMesh_.boundary()[patchi].patchSlice(edgeAddressing_),
170 //                 completeMesh_.boundaryMesh()
171                 completeMesh_.boundary()
172                 [
173                     boundaryAddressing_[patchi]
174                 ].start()
175             );
176         }
177         else
178         {
179             processorAreaPatchFieldDecomposerPtrs_[patchi] =
180                 new processorAreaPatchFieldDecomposer
181                 (
182                     completeMesh_,
183                     procMesh_.boundary()[patchi].patchSlice(edgeAddressing_)
184                 );
186             processorEdgePatchFieldDecomposerPtrs_[patchi] =
187                 new processorEdgePatchFieldDecomposer
188                 (
189                     procMesh_.boundary()[patchi].size(),
190                     static_cast<const unallocLabelList&>
191                     (
192                         procMesh_.boundary()[patchi].patchSlice
193                         (
194                             edgeAddressing_
195                         )
196                     )
197                 );
198         }
199     }
203 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
205 faFieldDecomposer::~faFieldDecomposer()
207     forAll (patchFieldDecomposerPtrs_, patchi)
208     {
209         if (patchFieldDecomposerPtrs_[patchi])
210         {
211             delete patchFieldDecomposerPtrs_[patchi];
212         }
213     }
215     forAll (processorAreaPatchFieldDecomposerPtrs_, patchi)
216     {
217         if (processorAreaPatchFieldDecomposerPtrs_[patchi])
218         {
219             delete processorAreaPatchFieldDecomposerPtrs_[patchi];
220         }
221     }
223     forAll (processorEdgePatchFieldDecomposerPtrs_, patchi)
224     {
225         if (processorEdgePatchFieldDecomposerPtrs_[patchi])
226         {
227             delete processorEdgePatchFieldDecomposerPtrs_[patchi];
228         }
229     }
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 } // End namespace Foam
237 // ************************************************************************* //