surfaceTemplates.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 #include "polySurfaceFields.H"
30 #include "polySurfacePointFields.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Type, class GeoMeshType>
36 (
37  vtkDataSet* piece,
38  const Field<Type>& fld,
39  const word& fieldName
40 ) const
41 {
42  if (!piece) return false;
43 
44  auto vtkfield = Foam::vtk::Tools::convertFieldToVTK<Type>(fieldName, fld);
45 
46  if (piece->GetNumberOfCells() == piece->GetNumberOfPoints())
47  {
48  // Only has verts
49  piece->GetPointData()->AddArray(vtkfield);
50  }
51  else
52  {
53  Foam::vtk::Tools::FieldAccess<GeoMeshType>()(piece)->AddArray(vtkfield);
54  }
55 
56  return true;
57 }
58 
59 
60 template<class Type, class GeoMeshType>
62 (
63  vtkDataSet* piece,
64  const regIOobject* ioptr,
65  const word& fieldName
66 ) const
67 {
68  const auto* fldptr =
69  dynamic_cast<const DimensionedField<Type, GeoMeshType>*>(ioptr);
70 
71  if (fldptr)
72  {
73  return addField<Type, GeoMeshType>
74  (
75  piece,
76  fldptr->field(),
77  fieldName
78  );
79  }
80 
81  return false;
82 }
83 
84 
85 template<class GeoMeshType>
87 (
88  vtkDataSet* piece,
89  const regIOobject* ioptr,
90  const word& fieldName
91 ) const
92 {
93  return (piece && ioptr) &&
94  (
95  addDimField<scalar, GeoMeshType>
96  (
97  piece, ioptr, fieldName
98  )
99  || addDimField<vector, GeoMeshType>
100  (
101  piece, ioptr, fieldName
102  )
103  || addDimField<sphericalTensor, GeoMeshType>
104  (
105  piece, ioptr, fieldName
106  )
107  || addDimField<symmTensor, GeoMeshType>
108  (
109  piece, ioptr, fieldName
110  )
111  || addDimField<tensor, GeoMeshType>
112  (
113  piece, ioptr, fieldName
114  )
115  );
116 }
117 
118 
119 template<class Type, class GeoMeshType>
121 (
122  vtkMultiPieceDataSet* multiPiece,
124  const word& fieldName
125 ) const
126 {
127  if (!multiPiece)
128  {
129  return false;
130  }
131 
132  if (!needsCollective())
133  {
134  // Simple case (serial-serial, parallel-parallel)
135 
136  return fldptr &&
137  addField<Type, GeoMeshType>
138  (
139  multiPiece->GetPiece(Pstream::myProcNo()),
140  fldptr->field(),
141  fieldName
142  );
143  }
144 
145 
146  // Gather fields
147  const bool ok = returnReduce((fldptr != nullptr), orOp<bool>());
148 
149  if (!ok)
150  {
151  return false;
152  }
153 
154  if (Pstream::master())
155  {
156  if (fldptr)
157  {
158  // My field data
159  addField<Type, GeoMeshType>
160  (
161  multiPiece->GetPiece(Pstream::myProcNo()),
162  fldptr->field(),
163  fieldName
164  );
165  }
166 
167  // Receive field data
168  Field<Type> recv;
169 
170  for
171  (
172  int slave=Pstream::firstSlave();
173  slave<=Pstream::lastSlave();
174  ++slave
175  )
176  {
177  IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
178 
179  recv.clear();
180 
181  fromSlave
182  >> recv;
183 
184  if (recv.size())
185  {
186  addField<Type, GeoMeshType>
187  (
188  multiPiece->GetPiece(slave),
189  recv,
190  fieldName
191  );
192  }
193  }
194  }
195  else
196  {
197  // Slave - send field data
198 
199  OPstream toMaster
200  (
201  Pstream::commsTypes::scheduled,
202  Pstream::masterNo()
203  );
204 
205  if (fldptr)
206  {
207  toMaster
208  << fldptr->field();
209  }
210  else
211  {
212  toMaster
213  << List<Type>();
214  }
215  }
216 
217  return ok;
218 }
219 
220 
221 template<class Type, class GeoMeshType>
223 (
224  vtkMultiPieceDataSet* multiPiece,
225  const regIOobject* ioptr,
226  const word& fieldName
227 ) const
228 {
229  return addDimField<Type, GeoMeshType>
230  (
231  multiPiece,
232  dynamic_cast<const DimensionedField<Type, GeoMeshType>*>(ioptr),
233  fieldName
234  );
235 }
236 
237 
238 template<class GeoMeshType>
240 (
241  vtkMultiPieceDataSet* multiPiece,
242  const regIOobject* ioptr,
243  const word& fieldName
244 ) const
245 {
246  return (multiPiece) &&
247  (
248  addDimField<scalar, GeoMeshType>
249  (
250  multiPiece, ioptr, fieldName
251  )
252  || addDimField<vector, GeoMeshType>
253  (
254  multiPiece, ioptr, fieldName
255  )
256  || addDimField<sphericalTensor, GeoMeshType>
257  (
258  multiPiece, ioptr, fieldName
259  )
260  || addDimField<symmTensor, GeoMeshType>
261  (
262  multiPiece, ioptr, fieldName
263  )
264  || addDimField<tensor, GeoMeshType>
265  (
266  multiPiece, ioptr, fieldName
267  )
268  );
269 }
270 
271 
272 template<class GeoMeshType>
274 (
275  vtkMultiPieceDataSet* multiPiece,
276  const polySurface* surf,
277  const word& fieldName
278 ) const
279 {
280  const regIOobject* ioptr =
281  (
282  surf
283  ? surf->findFieldObject<GeoMeshType>(fieldName)
284  : nullptr
285  );
286 
287  return addDimField<GeoMeshType>(multiPiece, ioptr, fieldName);
288 }
289 
290 
291 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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::functionObjects::runTimePostPro::surface::addDimField
bool addDimField(vtkDataSet *piece, const regIOobject *ioptr, const word &fieldName) const
Definition: surfaceTemplates.C:62
Foam::polySurface::findFieldObject
const regIOobject * findFieldObject(const word &fieldName, const FieldAssociation association) const
Definition: polySurface.C:242
Foam::DimensionedField::field
const Field< Type > & field() const
Return field.
Definition: DimensionedFieldI.H:89
polySurfaceFields.H
Fields for polySurface.
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:52
Foam::vtk::Tools::FieldAccess
Default field access is vtkCellData.
Definition: surface.H:140
polySurfacePointFields.H
Point fields for polySurface.
Foam::polySurface
A surface mesh consisting of general polygon faces and capable of holding fields.
Definition: polySurface.H:67
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::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:67
Foam::List< Type >
Foam::functionObjects::runTimePostPro::surface::addField
bool addField(vtkDataSet *piece, const Field< Type > &fld, const word &fieldName) const
Add field of Type to piece as VTK field data in GeoMeshType slot.
Definition: surfaceTemplates.C:36
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:52
Foam::orOp
Definition: ops.H:234
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54