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  label polyMeshNGlobalPoints = mesh_().globalData().nGlobalPoints();
77 
78  const labelList& polyMeshSharedPointLabels =
79  mesh_().globalData().sharedPointLabels();
80 
81  const labelList& polyMeshSharedPointAddr =
82  mesh_().globalData().sharedPointAddr();
83 
84  labelHashSet sharedPointLabels;
85 
86  labelField globalList(polyMeshNGlobalPoints, Zero);
87 
88  forAll(mesh_.boundary(), patchI)
89  {
90  const faPatch& fap = mesh_.boundary()[patchI];
91 
92  if (isA<processorFaPatch>(fap))
93  {
94  const labelList& localPointLabels = fap.pointLabels();
95 
96  forAll(localPointLabels, pointI)
97  {
98  label polyMeshPoint =
99  mesh_.patch().meshPoints()[localPointLabels[pointI]];
100 
101  const label sharedPolyMeshPoint =
102  polyMeshSharedPointLabels.find(polyMeshPoint);
103 
104  if
105  (
106  sharedPolyMeshPoint != -1
107  && !sharedPointLabels.found(localPointLabels[pointI])
108  )
109  {
110  globalList[polyMeshSharedPointAddr[sharedPolyMeshPoint]]
111  += 1;
112 
113  sharedPointLabels.insert(localPointLabels[pointI]);
114  }
115  }
116  }
117  }
118 
119  sharedPointLabels_ = sharedPointLabels.toc();
120 
121  Pstream::combineReduce(globalList, plusEqOp<labelField>());
122 
123  nGlobalPoints_ = 0;
124  for (label i=0; i<globalList.size(); ++i)
125  {
126  if (globalList[i] > 0)
127  {
128  globalList[i] = ++nGlobalPoints_;
129  }
130  }
131 
132  sharedPointAddr_.setSize(sharedPointLabels_.size());
133  forAll(sharedPointAddr_, pointI)
134  {
135  const label polyMeshSharedPointIndex =
136  polyMeshSharedPointLabels.find
137  (
138  mesh_.patch().meshPoints()[sharedPointLabels_[pointI]]
139  );
140 
141  sharedPointAddr_[pointI] =
142  globalList[polyMeshSharedPointAddr[polyMeshSharedPointIndex]]
143  - 1;
144  }
145 }
146 
147 
148 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:88
faceListList boundary
label find(const T &val, label pos=0) const
Find index of the first occurrence of the value.
Definition: UList.C:204
bool found(const Key &key) const
Same as contains()
Definition: HashTable.H:1333
const labelList & pointLabels() const
Return patch point labels.
Definition: faPatch.C:277
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:227
const faMesh & mesh() const noexcept
Return mesh reference.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
~faGlobalMeshData()
Destructor.
dynamicFvMesh & mesh
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:115
Inter-processor communications stream.
Definition: UPstream.H:62
Processor patch.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:133