Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / decomposePar / faFieldDecomposer.C
blobfe359774503bd0c33d9bc7203b00a42bdfdedd64
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 \*---------------------------------------------------------------------------*/
26 #include "faFieldDecomposer.H"
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 namespace Foam
33 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
35 faFieldDecomposer::patchFieldDecomposer::patchFieldDecomposer
37     const label sizeBeforeMapping,
38     const unallocLabelList& addressingSlice,
39     const label addressingOffset
42     sizeBeforeMapping_(sizeBeforeMapping),
43     directAddressing_(addressingSlice)
45     forAll (directAddressing_, i)
46     {
47         // Subtract one to align addressing.
48         // directAddressing_[i] -= addressingOffset + 1;
49         // ZT, 12/Nov/2010
50         directAddressing_[i] -= addressingOffset;
51     }
55 faFieldDecomposer::processorAreaPatchFieldDecomposer::
56 processorAreaPatchFieldDecomposer
58     const faMesh& mesh,
59     const unallocLabelList& addressingSlice
62     sizeBeforeMapping_(mesh.nFaces()),
63     addressing_(addressingSlice.size()),
64     weights_(addressingSlice.size())
66     const scalarField& weights = mesh.weights().internalField();
67     const labelList& own = mesh.edgeOwner();
68     const labelList& neighb = mesh.edgeNeighbour();
70     forAll (addressing_, i)
71     {
72         // Subtract one to align addressing.
73         label ai = addressingSlice[i];
74 //         label ai = mag(addressingSlice[i]) - 1;
76         if (ai < neighb.size())
77         {
78             // This is a regular edge. it has been an internal edge
79             // of the original mesh and now it has become a edge
80             // on the parallel boundary
81             addressing_[i].setSize(2);
82             weights_[i].setSize(2);
84             addressing_[i][0] = own[ai];
85             addressing_[i][1] = neighb[ai];
87             weights_[i][0] = weights[ai];
88             weights_[i][1] = 1.0 - weights[ai];
89         }
90         else
91         {
92             // This is a edge that used to be on a cyclic boundary
93             // but has now become a parallel patch edge. I cannot
94             // do the interpolation properly (I would need to look
95             // up the different (edge) list of data), so I will
96             // just grab the value from the owner face
97             //
98             addressing_[i].setSize(1);
99             weights_[i].setSize(1);
101             addressing_[i][0] = own[ai];
103             weights_[i][0] = 1.0;
104         }
105     }
109 faFieldDecomposer::processorEdgePatchFieldDecomposer::
110 processorEdgePatchFieldDecomposer
112     label sizeBeforeMapping,
113     const unallocLabelList& addressingSlice
116     sizeBeforeMapping_(sizeBeforeMapping),
117     addressing_(addressingSlice.size()),
118     weights_(addressingSlice.size())
120     forAll (addressing_, i)
121     {
122         addressing_[i].setSize(1);
123         weights_[i].setSize(1);
125         addressing_[i][0] = mag(addressingSlice[i]) - 1;
126         weights_[i][0] = sign(addressingSlice[i]);
127     }
131 faFieldDecomposer::faFieldDecomposer
133     const faMesh& completeMesh,
134     const faMesh& procMesh,
135     const labelList& edgeAddressing,
136     const labelList& faceAddressing,
137     const labelList& boundaryAddressing
140     completeMesh_(completeMesh),
141     procMesh_(procMesh),
142     edgeAddressing_(edgeAddressing),
143     faceAddressing_(faceAddressing),
144     boundaryAddressing_(boundaryAddressing),
145     patchFieldDecomposerPtrs_
146     (
147         procMesh_.boundary().size(),
148         static_cast<patchFieldDecomposer*>(NULL)
149     ),
150     processorAreaPatchFieldDecomposerPtrs_
151     (
152         procMesh_.boundary().size(),
153         static_cast<processorAreaPatchFieldDecomposer*>(NULL)
154     ),
155     processorEdgePatchFieldDecomposerPtrs_
156     (
157         procMesh_.boundary().size(),
158         static_cast<processorEdgePatchFieldDecomposer*>(NULL)
159     )
161     forAll (boundaryAddressing_, patchi)
162     {
163         if (boundaryAddressing_[patchi] >= 0)
164         {
165             patchFieldDecomposerPtrs_[patchi] = new patchFieldDecomposer
166             (
167                 completeMesh_.boundary()[boundaryAddressing_[patchi]].size(),
168                 procMesh_.boundary()[patchi].patchSlice(edgeAddressing_),
169 //                 completeMesh_.boundaryMesh()
170                 completeMesh_.boundary()
171                 [
172                     boundaryAddressing_[patchi]
173                 ].start()
174             );
175         }
176         else
177         {
178             processorAreaPatchFieldDecomposerPtrs_[patchi] =
179                 new processorAreaPatchFieldDecomposer
180                 (
181                     completeMesh_,
182                     procMesh_.boundary()[patchi].patchSlice(edgeAddressing_)
183                 );
185             processorEdgePatchFieldDecomposerPtrs_[patchi] =
186                 new processorEdgePatchFieldDecomposer
187                 (
188                     procMesh_.boundary()[patchi].size(),
189                     static_cast<const unallocLabelList&>
190                     (
191                         procMesh_.boundary()[patchi].patchSlice
192                         (
193                             edgeAddressing_
194                         )
195                     )
196                 );
197         }
198     }
202 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
204 faFieldDecomposer::~faFieldDecomposer()
206     forAll (patchFieldDecomposerPtrs_, patchi)
207     {
208         if (patchFieldDecomposerPtrs_[patchi])
209         {
210             delete patchFieldDecomposerPtrs_[patchi];
211         }
212     }
214     forAll (processorAreaPatchFieldDecomposerPtrs_, patchi)
215     {
216         if (processorAreaPatchFieldDecomposerPtrs_[patchi])
217         {
218             delete processorAreaPatchFieldDecomposerPtrs_[patchi];
219         }
220     }
222     forAll (processorEdgePatchFieldDecomposerPtrs_, patchi)
223     {
224         if (processorEdgePatchFieldDecomposerPtrs_[patchi])
225         {
226             delete processorEdgePatchFieldDecomposerPtrs_[patchi];
227         }
228     }
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 } // End namespace Foam
236 // ************************************************************************* //