faGlobalMeshData.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2017 Wikki Ltd
9  Copyright (C) 2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Author
28  Hrvoje Jasak
29 
30 \*----------------------------------------------------------------------------*/
31 
32 #include "faGlobalMeshData.H"
33 #include "faMesh.H"
34 #include "globalMeshData.H"
35 #include "processorFaPatch.H"
36 #include "processorTopologyNew.H"
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
40 Foam::faGlobalMeshData::faGlobalMeshData(const faMesh& mesh)
41 :
42  mesh_(mesh),
43  processorTopology_
44  (
46  (
47  mesh.boundary(),
48  UPstream::worldComm
49  )
50  ),
51  nGlobalPoints_(-1),
52  sharedPointLabels_(),
53  sharedPointAddr_()
54 {
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 
61 // A non-default destructor since we had incomplete types in the header
63 {}
64 
65 
66 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
67 
69 {
70  return mesh_;
71 }
72 
73 
75 {
76  // The polyMesh globalMeshData
77  const globalMeshData& pData = mesh_.mesh().globalData();
78 
79  const labelList& polyMeshSharedPointLabels =
80  pData.sharedPointLabels();
81 
82  const labelList& polyMeshSharedPointAddr =
83  pData.sharedPointAddr();
84 
85  labelHashSet sharedPointLabels;
86 
87  labelField globalList(pData.nGlobalPoints(), Zero);
88 
89  forAll(mesh_.boundary(), patchI)
90  {
91  const faPatch& fap = mesh_.boundary()[patchI];
92 
93  if (isA<processorFaPatch>(fap))
94  {
95  const labelList& localPointLabels = fap.pointLabels();
96 
97  forAll(localPointLabels, pointI)
98  {
99  label polyMeshPoint =
100  mesh_.patch().meshPoints()[localPointLabels[pointI]];
101 
102  const label sharedPolyMeshPoint =
103  polyMeshSharedPointLabels.find(polyMeshPoint);
104 
105  if
106  (
107  sharedPolyMeshPoint != -1
108  && !sharedPointLabels.found(localPointLabels[pointI])
109  )
110  {
111  globalList[polyMeshSharedPointAddr[sharedPolyMeshPoint]]
112  += 1;
113 
114  sharedPointLabels.insert(localPointLabels[pointI]);
115  }
116  }
117  }
118  }
119 
120  sharedPointLabels_ = sharedPointLabels.toc();
121 
122  Pstream::combineReduce(globalList, plusEqOp<labelField>());
123 
124  nGlobalPoints_ = 0;
125  for (label i=0; i<globalList.size(); ++i)
126  {
127  if (globalList[i] > 0)
128  {
129  globalList[i] = ++nGlobalPoints_;
130  }
131  }
132 
133  sharedPointAddr_.setSize(sharedPointLabels_.size());
134  forAll(sharedPointAddr_, pointI)
135  {
136  const label polyMeshSharedPointIndex =
137  polyMeshSharedPointLabels.find
138  (
139  mesh_.patch().meshPoints()[sharedPointLabels_[pointI]]
140  );
141 
142  sharedPointAddr_[pointI] =
143  globalList[polyMeshSharedPointAddr[polyMeshSharedPointIndex]]
144  - 1;
145  }
146 }
147 
148 
149 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
faceListList boundary
const labelList & sharedPointLabels() const
Return indices of local points that are globally shared.
bool found(const Key &key) const
Same as contains()
Definition: HashTable.H:1354
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
const labelList & pointLabels() const
Return patch point labels.
Definition: faPatch.C:276
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
Definition: HashSet.H:232
const faMesh & mesh() const noexcept
Return mesh reference.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
~faGlobalMeshData()
Destructor.
label nGlobalPoints() const
Return number of globally shared points.
dynamicFvMesh & mesh
const globalMeshData & globalData() const
Return parallel info (demand-driven)
Definition: polyMesh.C:1311
label find(const T &val) const
Find index of the first occurrence of the value.
Definition: UList.C:173
static void combineReduce(const List< commsStruct > &comms, T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
const direction noexcept
Definition: Scalar.H:258
Determines/represents processor-processor connection. After instantiation contains the processor-proc...
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
Define the processor-processor connection table by walking a list of patches and detecting the proces...
void updateMesh()
Change global mesh data given a topological change.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Definition: HashTable.C:124
const labelList & sharedPointAddr() const
Return addressing into the complete globally shared points.
Inter-processor communications stream.
Definition: UPstream.H:60
Processor patch.
const polyMesh & mesh() const noexcept
Return the mesh reference.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127