geometryPatches.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 "geometryPatches.H"
30 #include "fvMesh.H"
31 #include "volFields.H"
32 #include "emptyPolyPatch.H"
33 #include "processorPolyPatch.H"
34 #include "foamVtkTools.H"
35 #include "runTimePostProcessing.H"
37 
38 // VTK includes
39 #include "vtkActor.h"
40 #include "vtkCellArray.h"
41 #include "vtkCellData.h"
42 #include "vtkCellDataToPointData.h"
43 #include "vtkCompositeDataGeometryFilter.h"
44 #include "vtkCompositeDataSet.h"
45 #include "vtkCompositePolyDataMapper.h"
46 #include "vtkMultiPieceDataSet.h"
47 #include "vtkPointData.h"
48 #include "vtkPolyData.h"
49 #include "vtkPolyDataMapper.h"
50 #include "vtkProperty.h"
51 #include "vtkRenderer.h"
52 #include "vtkSmartPointer.h"
53 
54 
55 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace functionObjects
60 {
61 namespace runTimePostPro
62 {
63  defineTypeName(geometryPatches);
64  addToRunTimeSelectionTable(surface, geometryPatches, dictionary);
65 }
66 }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
73 (
74  const runTimePostProcessing& parent,
75  const dictionary& dict,
76  const HashPtrTable<Function1<vector>>& colours
77 )
78 :
79  geometrySurface(parent, dict, colours, List<fileName>()),
80  fieldVisualisationBase(dict, colours),
81  selectPatches_(),
82  nearCellValue_(dict.getOrDefault("nearCellValue", false))
83 {
84  dict.readEntry("patches", selectPatches_);
85 }
86 
87 
88 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
89 
91 (
92  const scalar position,
93  vtkRenderer* renderer
94 )
95 {
96  if (!visible_ || selectPatches_.empty())
97  {
98  return;
99  }
100 
101  const polyBoundaryMesh& patches = parent().mesh().boundaryMesh();
102 
103  bitSet selectedPatchIds(patches.size());
104 
105  for (const polyPatch& pp : patches)
106  {
107  if (isType<emptyPolyPatch>(pp) || pp.empty())
108  {
109  continue;
110  }
111  else if (isA<processorPolyPatch>(pp))
112  {
113  break; // No processor patches
114  }
115 
116  if (selectPatches_.match(pp.name()))
117  {
118  selectedPatchIds.set(pp.index());
119  }
120  }
121 
122 
123  labelListList patchIds(Pstream::nProcs());
124  patchIds[Pstream::myProcNo()] = selectedPatchIds.sortedToc();
125 
126  Pstream::gatherList(patchIds);
127  Pstream::scatterList(patchIds);
128 
129  label nPieces = 0;
130  for (const labelList& ids : patchIds)
131  {
132  nPieces += ids.size();
133  }
134 
137 
138  if (!nPieces)
139  {
141  << "No patches selected: " << flatOutput(selectPatches_)
142  << endl;
143  return;
144  }
145 
146  DebugInfo << " Add geometry patches" << nl;
147 
148 
149  // Create a vtkMultiPieceDataSet with vtkPolyData on the leaves
150 
151  // When adding fields, only map scalar/vector fields.
152  // - this is easier and all we mostly ever need
153 
155 
156  // Requesting glyphs on the surface - just use the faceCentres directly
157  // and attach fields as CellData (not PointData).
158 
159  if (representation_ == rtGlyph)
160  {
161  multiPiece = gatherPatchFaceCentres(patchIds);
162  }
163  else
164  {
165  multiPiece = gatherPatchPieces(patchIds);
166  }
167 
168 
169  // Add (scalar/vector) field.
170  // - Need field(s) for glyphs or colourByField:
171 
172  int nCmpt = 0;
173  if (representation_ == rtGlyph || colourBy_ == cbField)
174  {
175  if (!nCmpt)
176  {
177  nCmpt = addPatchField<scalar>
178  (
179  multiPiece,
180  patchIds,
181  parent().mesh().cfindObject<volScalarField>(fieldName_),
182  fieldName_
183  );
184  }
185  if (!nCmpt)
186  {
187  nCmpt = addPatchField<vector>
188  (
189  multiPiece,
190  patchIds,
191  parent().mesh().cfindObject<volVectorField>(fieldName_),
192  fieldName_
193  );
194  }
195  }
196 
197  // Now have a multi-piece dataset with
198  // one piece per patch and processor.
199  //
200  // For VTK=parallel, these pieces reside on their original processors.
201  // For VTK=serial, they are master only
202 
203  // Re-query actually field information, since we may have stored it
204  // somewhere slightly different than the original source.
205 
206  fieldSummary fieldInfo = queryFieldSummary(fieldName_, multiPiece);
207  fieldInfo.reduce();
208 
209  DebugInfo
210  << " Field " << fieldName_ << ' ' << fieldInfo.info() << endl;
211 
212  // Not rendering on this processor?
213  // This is where we stop, but could also have a MPI barrier
214  if (!renderer)
215  {
216  return;
217  }
218 
219 
220  // Rendering
221 
222  {
224 
225  polyData->SetInputData(multiPiece);
226  polyData->Update();
227 
228  if (representation_ == rtGlyph)
229  {
230  addGlyphs
231  (
232  position,
233  fieldName_, fieldInfo, // scaling
234  fieldName_, fieldInfo, // colouring
235  maxGlyphLength_,
236  polyData->GetOutput(),
237  surfaceActor_,
238  renderer
239  );
240  }
241  else
242  {
244 
245  // CellData - Need a cell->point filter
246  if (smooth_ && !fieldInfo.hasPointData())
247  {
249  cellToPoint->SetInputData(multiPiece);
250 
251  polyData->SetInputConnection(cellToPoint->GetOutputPort());
252  }
253  else
254  {
255  polyData->SetInputData(multiPiece);
256  }
257  polyData->Update();
258 
259 
260  if (!smooth_)
261  {
262  addFeatureEdges(renderer, polyData);
263  }
264 
266  mapper->SetInputConnection(polyData->GetOutputPort());
267 
268  setField
269  (
270  position,
271  fieldName_,
272  (
273  smooth_
275  : FieldAssociation::CELL_DATA
276  ),
277  mapper,
278  renderer
279  );
280 
281  surfaceActor_->SetMapper(mapper);
282 
283  setRepresentation(surfaceActor_);
284 
285  renderer->AddActor(surfaceActor_);
286  }
287  }
288 }
289 
290 
292 (
293  const scalar position
294 )
295 {
296  if (!visible_)
297  {
298  return;
299  }
300 
301  surface::updateActors(position);
302 
303  surfaceActor_->GetProperty()->SetOpacity(opacity(position));
304 
305  vector sc = surfaceColour_->value(position);
306  surfaceActor_->GetProperty()->SetColor(sc[0], sc[1], sc[2]);
307 
308  vector ec = edgeColour_->value(position);
309  surfaceActor_->GetProperty()->SetEdgeColor(ec[0], ec[1], ec[2]);
310 }
311 
312 
314 {
315  return true;
316 }
317 
318 
319 // ************************************************************************* //
volFields.H
Foam::functionObjects::runTimePostPro::addToRunTimeSelectionTable
addToRunTimeSelectionTable(surface, contourFilter, dictionary)
Foam::functionObjects::runTimePostPro::fieldVisualisationBase::fieldSummary
General field characteristics.
Definition: fieldVisualisationBase.H:172
foamVtkTools.H
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:64
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
Foam::expressions::patchExpr::POINT_DATA
Point data.
Definition: patchExprFwd.H:60
Foam::cellToPoint
A topoSetPointSource to select points based on usage in cells.
Definition: cellToPoint.H:83
Foam::functionObjects::fieldInfo
Helper class to store a wordRe and label used by Foam::functionObjects::fieldSelection.
Definition: fieldInfo.H:56
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:563
vtkSmartPointer
Definition: runTimePostProcessing.H:148
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::functionObjects::runTimePostPro::geometryPatches::updateActors
virtual void updateActors(const scalar position)
Update actors.
Definition: geometryPatches.C:292
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: Function1.H:56
Foam::updateActors
static void updateActors(PtrList< Type > &objects, const scalar position)
Definition: runTimePostProcessing.C:102
geometryPatches.H
patchIds
labelList patchIds
Definition: convertProcessorPatches.H:67
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:62
Foam::functionObjects::runTimePostPro::geometryPatches::addGeometryToScene
virtual void addGeometryToScene(const scalar position, vtkRenderer *renderer)
Add geometry surface(s) to scene.
Definition: geometryPatches.C:91
Foam::functionObjects::runTimePostProcessing
Generate images during run-time.
Definition: runTimePostProcessing.H:170
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::functionObjects::runTimePostPro::geometryPatches::geometryPatches
geometryPatches(const geometryPatches &)=delete
No copy construct.
setField
surfacesMesh setField(triSurfaceToAgglom)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
processorPolyPatch.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
emptyPolyPatch.H
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
Foam::functionObjects::runTimePostPro::geometryPatches::clear
virtual bool clear()
Clear files used to create the object(s)
Definition: geometryPatches.C:313
Foam::functionObjects::runTimePostPro::fieldVisualisationBase
Base class for scene objects.
Definition: fieldVisualisationBase.H:125
runTimePostProcessing.H
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:350
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::flatOutput
FlatOutput< Container > flatOutput(const Container &obj, label len=0)
Global flatOutput function.
Definition: FlatOutput.H:85
Foam::HashPtrTable
A HashTable of pointers to objects of type <T>.
Definition: HashPtrTable.H:54
Foam::Vector< scalar >
Foam::List< fileName >
Foam::functionObjects::runTimePostPro::defineTypeName
defineTypeName(contourFilter)
Foam::functionObjects::runTimePostPro::geometrySurface
Read and visualize surface geometry files.
Definition: geometrySurface.H:83
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::functionObjects::runTimePostProcessing::mesh
const fvMesh & mesh() const
Reference to the underlying OpenFOAM mesh.
Definition: runTimePostProcessing.H:259