geometryCloudTemplates.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 #include "foamVtkTools.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  vtkDataSet* piece,
36  const Field<Type>& fld,
37  const word& fieldName
38 ) const
39 {
40  if (!piece) return false;
41 
42  auto vtkfield = Foam::vtk::Tools::convertFieldToVTK<Type>(fieldName, fld);
43 
44  // Only has verts
45  piece->GetPointData()->AddArray(vtkfield);
46 
47  return true;
48 }
49 
50 
51 template<class Type>
53 (
54  vtkMultiPieceDataSet* multiPiece,
55  const IOField<Type>* fldptr,
56  const word& fieldName
57 ) const
58 {
59  if (!multiPiece)
60  {
61  return false;
62  }
63 
64  if (!needsCollective())
65  {
66  // Simple case (serial-serial, parallel-parallel)
67 
68  return fldptr &&
69  addField<Type>
70  (
71  multiPiece->GetPiece(Pstream::myProcNo()),
72  *fldptr,
73  fieldName
74  );
75  }
76 
77 
78  // Gather fields
79  const bool ok = returnReduce((fldptr != nullptr), orOp<bool>());
80 
81  if (!ok)
82  {
83  return false;
84  }
85 
86  if (Pstream::master())
87  {
88  if (fldptr)
89  {
90  // My field data
91  addField<Type>
92  (
93  multiPiece->GetPiece(Pstream::myProcNo()),
94  *fldptr,
95  fieldName
96  );
97  }
98 
99  // Receive field data
100  Field<Type> recv;
101 
102  for
103  (
104  int slave=Pstream::firstSlave();
105  slave<=Pstream::lastSlave();
106  ++slave
107  )
108  {
109  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
110 
111  recv.clear();
112 
113  fromSlave
114  >> recv;
115 
116  if (recv.size())
117  {
118  addField<Type>
119  (
120  multiPiece->GetPiece(slave),
121  recv,
122  fieldName
123  );
124  }
125  }
126  }
127  else
128  {
129  // Slave - send field data
130 
131  OPstream toMaster
132  (
133  Pstream::commsTypes::scheduled,
134  Pstream::masterNo()
135  );
136 
137  if (fldptr)
138  {
139  toMaster
140  << *fldptr;
141  }
142  else
143  {
144  toMaster
145  << List<Type>();
146  }
147  }
148 
149  return ok;
150 }
151 
152 
153 template<class Type>
155 (
156  vtkMultiPieceDataSet* multiPiece,
157  const regIOobject* ioptr,
158  const word& fieldName
159 ) const
160 {
161  return addCloudField<Type>
162  (
163  multiPiece,
164  dynamic_cast<const IOField<Type>*>(ioptr),
165  fieldName
166  );
167 }
168 
169 
170 // ************************************************************************* //
Foam::functionObjects::runTimePostPro::geometryCloud::addCloudField
bool addCloudField(vtkMultiPieceDataSet *multiPiece, const IOField< Type > *fldptr, const word &fieldName) const
Add field.
Definition: geometryCloudTemplates.C:53
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
foamVtkTools.H
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::Field
Generic templated field type.
Definition: Field.H:63
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::functionObjects::runTimePostPro::geometryCloud::addField
bool addField(vtkDataSet *piece, const Field< Type > &fld, const word &fieldName) const
Add field.
Definition: geometryCloudTemplates.C:34
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::List< Type >
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
Foam::orOp
Definition: ops.H:234