Loading...
Searching...
No Matches
blockMeshVTK.H
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) 2020-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13Description
14 VTK output of blockMesh topology blocks
15
16 Always write in ASCII since the mesh is small and we want easily
17 readable output for inspection.
18
19\*---------------------------------------------------------------------------*/
20
21// Common
22
23refPtr<polyMesh> topoMeshPtr(blocks.topology(true));
24const polyMesh& topoMesh = topoMeshPtr();
26// Internal mesh - ie, the blocks
27{
28 const vtk::vtuCells topoCells(topoMesh, vtk::formatType::INLINE_ASCII);
29
30 vtk::internalMeshWriter writer
31 (
33 topoCells,
34 vtk::formatType::INLINE_ASCII,
35 runTime.path()/"blockTopology"
36 );
37
38 Info<< "Writing block topology in vtk format: "
39 << args.relativePath(writer.output()).c_str() << endl;
40
41 writer.writeGeometry();
42 writer.beginCellData();
43 writer.writeCellIDs();
44
45 // No cell decomposition, so there is a 1-to-1 correspondence between
46 // input blocks and VTK output cells.
47
48 vectorField localNormal(blocks.size());
49
50 // Generate local normals as fields for visualisation
51 for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
52 {
53 const label faceMin = label(2*cmpt);
54 const label faceMax = faceMin+1;
55
56 localNormal.resize(blocks.size());
57
58 forAll(blocks, blocki)
59 {
60 const cellShape& shape = blocks[blocki].blockShape();
61 const pointField& verts = blocks[blocki].vertices();
62
63 if (shape.model() == cellModel::ref(cellModel::HEX))
64 {
65 localNormal[blocki] =
66 (
67 // 30% cell-width as arbitrary value for vector length
68 0.3*mag
69 (
70 shape.face(faceMax).centre(verts)
71 - shape.face(faceMin).centre(verts)
72 )
73 * normalised
74 (
75 // Weigh by area to avoid influence of zero-faces
76 shape.face(faceMax).areaNormal(verts)
77 - shape.face(faceMin).areaNormal(verts)
78 )
79 );
80 }
81 else
82 {
83 // Could handle other shapes (how?)
84 localNormal[blocki] = Zero;
85 }
86 }
87
88 // Additional safety (should not happen)
89 localNormal.resize(topoMesh.nCells(), Zero);
90
91 writer.writeCellData
92 (
93 word("local-direction" + name(cmpt)),
94 localNormal
95 );
96 }
97
98 // if (topoMesh.nCells() != blocks.size())
99 // {
100 // Info<< "Warning: indicated normals may be incorrect" << nl;
101 // }
102}
103
104
105// Block boundary faces
106{
107 const auto& patches = topoMesh.boundaryMesh();
108 const label nBndFaces = topoMesh.nBoundaryFaces();
109
110 const faceList allPatchFaces(patches.faces());
111
112 vtk::surfaceWriter writer
113 (
114 topoMesh.points(),
115 allPatchFaces,
116 vtk::formatType::INLINE_ASCII,
117 runTime.path()/"blockFaces"
118 );
119
120
121 labelList blockIds(nBndFaces, -1);
122 labelList cellFaceIds(nBndFaces, -1);
123 labelList patchIds(nBndFaces, -1);
124
125 {
126 const labelList& own = topoMesh.faceOwner();
127 const cellList& cells = topoMesh.cells();
128 const polyPatchList& patches = topoMesh.boundaryMesh();
129
130 for (const polyPatch& pp : patches)
131 {
132 label bndFacei = pp.offset();
133 label meshFacei = pp.start();
134
135 forAll(pp, bfacei)
136 {
137 const label celli = own[meshFacei];
138 const label cellFacei = cells[celli].find(meshFacei);
139
140 blockIds[bndFacei] = celli;
141 cellFaceIds[bndFacei] = cellFacei;
142 patchIds[bndFacei] = pp.index();
143
144 ++bndFacei;
145 ++meshFacei;
146 }
147 }
148 }
149
150 Info<< "Writing block boundary faces in vtk format: "
151 << args.relativePath(writer.output()).c_str() << endl;
152
153 writer.writeGeometry();
154
155 writer.beginCellData();
156 writer.writeCellData("block", blockIds);
157 writer.writeCellData("face", cellFaceIds);
158 writer.writeCellData("patch", patchIds);
159}
160
161
162// ************************************************************************* //
const polyMesh & topoMesh
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
refPtr< polyMesh > topoMeshPtr(blocks.topology(true))
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edgesCentres")))
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
labelList patchIds
const polyBoundaryMesh & patches
engineTime & runTime
auto & name
const cellShapeList & cells
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition polyPatch.H:61
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
Definition faceListFwd.H:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
List< cell > cellList
List of cell.
Definition cellListFwd.H:41
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299