Test-globalMeshData.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 | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  globalMeshDataTest
26 
27 Description
28  Test global point communication
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "globalMeshData.H"
33 #include "argList.H"
34 #include "polyMesh.H"
35 #include "Time.H"
36 #include "mapDistribute.H"
37 
38 using namespace Foam;
39 
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 // Main program:
44 
45 int main(int argc, char *argv[])
46 {
47  #include "setRootCase.H"
48  #include "createTime.H"
49  #include "createPolyMesh.H"
50 
51  const globalMeshData& globalData = mesh.globalData();
52  const indirectPrimitivePatch& coupledPatch = globalData.coupledPatch();
53  const globalIndexAndTransform& transforms = globalData.globalTransforms();
54 
55 
56  // Test:print shared points
57  {
58  const mapDistribute& globalPointSlavesMap =
59  globalData.globalPointSlavesMap();
60  const labelListList& slaves =
61  globalData.globalPointSlaves();
62  const labelListList& transformedSlaves =
63  globalData.globalPointTransformedSlaves();
64 
65  // Create field with my local data
66  pointField coords(globalPointSlavesMap.constructSize());
67  SubList<point>(coords, coupledPatch.nPoints()).assign
68  (
69  coupledPatch.localPoints()
70  );
71 
72  // Exchange data. Apply positional transforms.
73  globalPointSlavesMap.distribute
74  (
75  transforms,
76  coords,
78  );
79 
80  // Print
81  forAll(slaves, pointI)
82  {
83  const labelList& slavePoints = slaves[pointI];
84 
85  if (slavePoints.size() > 0)
86  {
87  Pout<< "Master point:" << pointI
88  << " coord:" << coords[pointI]
89  << " connected to untransformed slave points:" << endl;
90 
91  forAll(slavePoints, i)
92  {
93  Pout<< " " << coords[slavePoints[i]] << endl;
94  }
95  }
96 
97  const labelList& transformedSlavePoints = transformedSlaves[pointI];
98 
99  if (transformedSlavePoints.size() > 0)
100  {
101  Pout<< "Master point:" << pointI
102  << " coord:" << coords[pointI]
103  << " connected to transformed slave points:" << endl;
104 
105  forAll(transformedSlavePoints, i)
106  {
107  Pout<< " " << coords[transformedSlavePoints[i]]
108  << endl;
109  }
110  }
111  }
112  }
113 
114 
115  // Test:print shared edges
116  {
117  const mapDistribute& globalEdgeSlavesMap =
118  globalData.globalEdgeSlavesMap();
119  const labelListList& slaves =
120  globalData.globalEdgeSlaves();
121  const labelListList& transformedSlaves =
122  globalData.globalEdgeTransformedSlaves();
123 
124  // Test: distribute edge centres
125  pointField ec(globalEdgeSlavesMap.constructSize());
126  forAll(coupledPatch.edges(), edgeI)
127  {
128  ec[edgeI] = coupledPatch.edges()[edgeI].centre
129  (
130  coupledPatch.localPoints()
131  );
132  }
133 
134  // Exchange data Apply positional transforms.
135  globalEdgeSlavesMap.distribute
136  (
137  transforms,
138  ec,
140  );
141 
142  // Print
143  forAll(slaves, edgeI)
144  {
145  const labelList& slaveEdges = slaves[edgeI];
146 
147  if (slaveEdges.size() > 0)
148  {
149  Pout<< "Master edge:" << edgeI
150  << " centre:" << ec[edgeI]
151  << " connected to slave edges:" << endl;
152 
153  forAll(slaveEdges, i)
154  {
155  Pout<< " " << ec[slaveEdges[i]] << endl;
156  }
157  }
158  const labelList& transformedSlaveEdges = transformedSlaves[edgeI];
159 
160  if (transformedSlaveEdges.size() > 0)
161  {
162  Pout<< "Master edge:" << edgeI
163  << " centre:" << ec[edgeI]
164  << " connected to transformed slave edges:" << endl;
165 
166  forAll(transformedSlaveEdges, i)
167  {
168  Pout<< " " << ec[transformedSlaveEdges[i]]
169  << endl;
170  }
171  }
172  }
173  }
174 
175 
176  // Test: point to faces addressing
177  {
178  const mapDistribute& globalPointBoundaryFacesMap =
179  globalData.globalPointBoundaryFacesMap();
180  const labelListList& slaves =
181  globalData.globalPointBoundaryFaces();
182  const labelListList& transformedSlaves =
184 
185  label nBnd = mesh.nFaces()-mesh.nInternalFaces();
186 
187  pointField fc(globalPointBoundaryFacesMap.constructSize());
188  SubList<point>(fc, nBnd).assign
189  (
191  (
193  (
194  mesh.faces(),
195  nBnd,
197  ),
198  mesh.points()
199  ).faceCentres()
200  );
201 
202  // Exchange data
203  globalPointBoundaryFacesMap.distribute
204  (
205  transforms,
206  fc,
208  );
209 
210  // Print
211  forAll(slaves, pointI)
212  {
213  const labelList& slaveFaces = slaves[pointI];
214 
215  if (slaveFaces.size() > 0)
216  {
217  Pout<< "Master point:" << pointI
218  << " at:" << coupledPatch.localPoints()[pointI]
219  << " connected to " << slaveFaces.size()
220  << " untransformed faces:" << endl;
221 
222  forAll(slaveFaces, i)
223  {
224  Pout<< " " << fc[slaveFaces[i]] << endl;
225  }
226  }
227 
228  const labelList& transformedSlaveFaces = transformedSlaves[pointI];
229 
230  if (transformedSlaveFaces.size() > 0)
231  {
232  Pout<< "Master point:" << pointI
233  << " connected to " << transformedSlaveFaces.size()
234  << " transformed faces:" << endl;
235 
236  forAll(transformedSlaveFaces, i)
237  {
238  Pout<< " " << fc[transformedSlaveFaces[i]] << endl;
239  }
240  }
241  }
242  }
243 
244 
245  // Test: point to cells addressing
246  {
247  const labelList& boundaryCells = globalData.boundaryCells();
248  const mapDistribute& globalPointBoundaryCellsMap =
249  globalData.globalPointBoundaryCellsMap();
250  const labelListList& slaves = globalData.globalPointBoundaryCells();
251  const labelListList& transformedSlaves =
253 
254  pointField cc(globalPointBoundaryCellsMap.constructSize());
255  forAll(boundaryCells, i)
256  {
257  cc[i] = mesh.cellCentres()[boundaryCells[i]];
258  }
259 
260  // Exchange data
261  globalPointBoundaryCellsMap.distribute
262  (
263  transforms,
264  cc,
266  );
267 
268  // Print
269  forAll(slaves, pointI)
270  {
271  const labelList& pointCells = slaves[pointI];
272 
273  if (pointCells.size() > 0)
274  {
275  Pout<< "Master point:" << pointI
276  << " at:" << coupledPatch.localPoints()[pointI]
277  << " connected to " << pointCells.size()
278  << " untransformed boundaryCells:" << endl;
279 
280  forAll(pointCells, i)
281  {
282  Pout<< " " << cc[pointCells[i]] << endl;
283  }
284  }
285 
286  const labelList& transformPointCells = transformedSlaves[pointI];
287 
288  if (transformPointCells.size() > 0)
289  {
290  Pout<< "Master point:" << pointI
291  << " connected to " << transformPointCells.size()
292  << " transformed boundaryCells:" << endl;
293 
294  forAll(transformPointCells, i)
295  {
296  Pout<< " " << cc[transformPointCells[i]] << endl;
297  }
298  }
299  }
300  }
301 
302 
303  Info<< "End\n" << endl;
304 
305  return 0;
306 }
307 
308 
309 // ************************************************************************* //
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::globalMeshData::globalPointTransformedSlaves
const labelListList & globalPointTransformedSlaves() const
Definition: globalMeshData.C:2180
Foam::globalMeshData::globalPointSlaves
const labelListList & globalPointSlaves() const
Definition: globalMeshData.C:2170
Foam::globalMeshData::globalPointBoundaryCellsMap
const mapDistribute & globalPointBoundaryCellsMap() const
Definition: globalMeshData.C:2342
Foam::PrimitivePatch::edges
const edgeList & edges() const
Return list of edges, address into LOCAL point list.
Definition: PrimitivePatchTemplate.C:212
Foam::globalMeshData::globalEdgeSlavesMap
const mapDistribute & globalEdgeSlavesMap() const
Definition: globalMeshData.C:2245
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
globalMeshData.H
Foam::PrimitivePatch::localPoints
const Field< PointType > & localPoints() const
Return pointField of points in patch.
Definition: PrimitivePatchTemplate.C:432
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::globalMeshData::globalPointBoundaryCells
const labelListList & globalPointBoundaryCells() const
Definition: globalMeshData.C:2320
main
int main(int argc, char *argv[])
Definition: Test-globalMeshData.C:42
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::globalMeshData::globalPointSlavesMap
const mapDistribute & globalPointSlavesMap() const
Definition: globalMeshData.C:2191
Foam::mapDistribute::transformPosition
Default transformation behaviour for position.
Definition: mapDistribute.H:249
polyMesh.H
Foam::globalMeshData::boundaryCells
const labelList & boundaryCells() const
From boundary cell to mesh cell.
Definition: globalMeshData.C:2299
Foam::globalMeshData::globalPointTransformedBoundaryFaces
const labelListList & globalPointTransformedBoundaryFaces() const
Definition: globalMeshData.C:2278
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Info
messageStream Info
Foam::globalMeshData::globalTransforms
const globalIndexAndTransform & globalTransforms() const
Global transforms numbering.
Definition: globalMeshData.C:2160
argList.H
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:152
Foam::UList::assign
void assign(const UList< T > &)
Assign elements to those from UList.
Definition: UList.C:37
Foam::globalMeshData::globalEdgeSlaves
const labelListList & globalEdgeSlaves() const
Definition: globalMeshData.C:2214
Foam::mapDistribute::distribute
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
Definition: mapDistributeTemplates.C:155
Foam::globalMeshData::globalPointBoundaryFaces
const labelListList & globalPointBoundaryFaces() const
Definition: globalMeshData.C:2266
Foam::PrimitivePatch::nPoints
label nPoints() const
Return number of points supporting patch faces.
Definition: PrimitivePatchTemplate.H:293
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const
Definition: primitiveMeshI.H:52
Foam::globalMeshData
Various mesh related information for a parallel run. Upon construction, constructs all info using par...
Definition: globalMeshData.H:106
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::mapDistributeBase::constructSize
label constructSize() const
Constructed data size.
Definition: mapDistributeBase.H:244
setRootCase.H
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:211
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1004
Foam::primitiveMesh::nFaces
label nFaces() const
Definition: primitiveMeshI.H:58
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::globalMeshData::globalEdgeTransformedSlaves
const labelListList & globalEdgeTransformedSlaves() const
Definition: globalMeshData.C:2224
mapDistribute.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::globalMeshData::coupledPatch
const indirectPrimitivePatch & coupledPatch() const
Return patch of all coupled faces.
Definition: globalMeshData.C:2046
Foam::PrimitivePatch::faceCentres
const Field< PointType > & faceCentres() const
Return face centres for patch.
Definition: PrimitivePatchTemplate.C:500
Foam::globalMeshData::globalPointTransformedBoundaryCells
const labelListList & globalPointTransformedBoundaryCells() const
Definition: globalMeshData.C:2332
createTime.H
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1143
Foam::globalIndexAndTransform
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
Definition: globalIndexAndTransform.H:60
createPolyMesh.H
Foam::globalMeshData::globalPointBoundaryFacesMap
const mapDistribute & globalPointBoundaryFacesMap() const
Definition: globalMeshData.C:2288
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88