geometryCloudGather.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) 2019 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 // OpenFOAM includes
29 #include "geometryCloud.H"
30 #include "cloud.H"
31 #include "runTimePostProcessing.H"
32 
33 #include "foamVtkTools.H"
34 
35 // VTK includes
36 #include "vtkMultiPieceDataSet.h"
37 #include "vtkPolyData.h"
38 #include "vtkSmartPointer.h"
39 
40 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
41 
44 (
45  const objectRegistry& obrTmp
46 ) const
47 {
49  multiPiece->SetNumberOfPieces(Pstream::nProcs());
50 
51  const auto* pointsPtr = cloud::findIOPosition(obrTmp);
52 
53  if (!needsCollective())
54  {
55  // Simple case (serial-serial, parallel-parallel)
56 
57  if (pointsPtr && pointsPtr->size())
58  {
59  multiPiece->SetPiece
60  (
61  Pstream::myProcNo(),
62  Foam::vtk::Tools::Vertices(*pointsPtr)
63  );
64  }
65  }
66  else if (Pstream::master())
67  {
68  // Gather pieces on master
69 
70  if (pointsPtr && pointsPtr->size())
71  {
72  // Add myself
73 
74  multiPiece->SetPiece
75  (
76  Pstream::myProcNo(),
77  Foam::vtk::Tools::Vertices(*pointsPtr)
78  );
79  }
80 
81  // Receive points
83 
84  for
85  (
86  int slave=Pstream::firstSlave();
87  slave<=Pstream::lastSlave();
88  ++slave
89  )
90  {
91  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
92 
93  points.clear();
94 
95  fromSlave >> points;
96 
97  if (points.size())
98  {
99  multiPiece->SetPiece
100  (
101  slave,
103  );
104  }
105  }
106  }
107  else
108  {
109  // Slave - send points
110 
111  OPstream toMaster
112  (
113  Pstream::commsTypes::scheduled,
114  Pstream::masterNo()
115  );
116 
117  if (pointsPtr)
118  {
119  toMaster << *pointsPtr;
120  }
121  else
122  {
123  toMaster << pointField();
124  }
125  }
126 
127  return multiPiece;
128 }
129 
130 
131 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::vtk::Tools::Vertices
vtkSmartPointer< vtkPolyData > Vertices(const UList< point > &pts)
Return vtkPolyData of vertices for each point.
Definition: foamVtkToolsI.H:104
foamVtkTools.H
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
cloud.H
vtkSmartPointer
Definition: runTimePostProcessing.H:148
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Field< vector >
geometryCloud.H
Foam::functionObjects::runTimePostPro::geometryCloud::gatherCloud
vtkSmartPointer< vtkMultiPieceDataSet > gatherCloud(const objectRegistry &obrTmp) const
Gather and convert cloud positions with vtkPolyData for the leaves.
Definition: geometryCloudGather.C:44
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
runTimePostProcessing.H
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52