Forward compatibility: flex
[foam-extend-3.2.git] / src / finiteArea / faMesh / faGlobalMeshData / faGlobalMeshData.C
blob56015712af937a6755e78260d402806649878c91
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 Class
25     faGlobalMeshData
27 Description
29 Author
30     Hrvoje Jasak
32 \*----------------------------------------------------------------------------*/
34 #include "faGlobalMeshData.H"
35 #include "faMesh.H"
36 #include "globalMeshData.H"
37 #include "PstreamCombineReduceOps.H"
39 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
41 Foam::faGlobalMeshData::faGlobalMeshData(const faMesh& mesh)
43     faProcessorTopology(mesh.boundary()),
44     mesh_(mesh),
45     nGlobalPoints_(-1),
46     sharedPointLabels_(0),
47     sharedPointAddr_(0)
49     updateMesh();
53 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
55 Foam::faGlobalMeshData::~faGlobalMeshData()
59 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
61 const Foam::faMesh& Foam::faGlobalMeshData::mesh() const
63     return mesh_;
67 // Update all data after morph
68 void Foam::faGlobalMeshData::updateMesh()
70     label polyMeshNGlobalPoints =
71         mesh_().globalData().nGlobalPoints();
73     const labelList& polyMeshSharedPointLabels =
74         mesh_().globalData().sharedPointLabels();
76     const labelList& polyMeshSharedPointAddr =
77         mesh_().globalData().sharedPointAddr();
79     labelHashSet sharedPointLabels;
81     labelField globalList(polyMeshNGlobalPoints, 0);
83     forAll(mesh_.boundary(), patchI)
84     {
85         if(mesh_.boundary()[patchI].type() == processorFaPatch::typeName)
86         {
87             const labelList& localPointLabels =
88                 mesh_.boundary()[patchI].pointLabels();
90             forAll(localPointLabels, pointI)
91             {
92                 label polyMeshPoint =
93                     mesh_.patch().meshPoints()[localPointLabels[pointI]];
95                 label sharedPolyMeshPoint =
96                     findIndex(polyMeshSharedPointLabels, polyMeshPoint);
98                 if
99                 (
100                     sharedPolyMeshPoint != -1
101                  && !sharedPointLabels.found(localPointLabels[pointI])
102                 )
103                 {
104                     globalList[polyMeshSharedPointAddr[sharedPolyMeshPoint]]
105                         += 1;
107                     sharedPointLabels.insert(localPointLabels[pointI]);
108                 }
109             }
110         }
111     }
113     sharedPointLabels_ = sharedPointLabels.toc();
115     combineReduce(globalList, plusEqOp<labelField >());
117     nGlobalPoints_ = 0;
118     for (label i=0; i<globalList.size(); i++)
119     {
120         if(globalList[i] > 0)
121         {
122             globalList[i] = ++nGlobalPoints_;
123         }
124     }
126     sharedPointAddr_.setSize(sharedPointLabels_.size());
127     forAll(sharedPointAddr_, pointI)
128     {
129         label polyMeshSharedPointIndex = findIndex
130         (
131             polyMeshSharedPointLabels,
132             mesh_.patch().meshPoints()[sharedPointLabels_[pointI]]
133         );
135         sharedPointAddr_[pointI] =
136             globalList[polyMeshSharedPointAddr[polyMeshSharedPointIndex]]
137           - 1;
138     }
141 // ************************************************************************* //