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();
25
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 );
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 label nIntFaces = topoMesh.nInternalFaces();
108 const label nBndFaces = topoMesh.nBoundaryFaces();
109
110 faceList bndFaces
111 (
112 faceList::subList(topoMesh.faces(), nBndFaces, nIntFaces)
113 );
114
115 vtk::surfaceWriter writer
116 (
117 topoMesh.points(),
118 bndFaces,
119 vtk::formatType::INLINE_ASCII,
120 runTime.path()/"blockFaces"
121 );
122
123
124 labelList blockIds(nBndFaces, -1);
125 labelList cellFaceIds(nBndFaces, -1);
126 labelList patchIds(nBndFaces, -1);
127
128 {
129 const labelList& own = topoMesh.faceOwner();
130 const cellList& cells = topoMesh.cells();
131 const polyPatchList& patches = topoMesh.boundaryMesh();
132
133 for (const polyPatch& pp : patches)
134 {
135 label bndFacei = pp.start() - nIntFaces;
136 label meshFacei = pp.start();
137
138 forAll(pp, bfacei)
139 {
140 const label celli = own[meshFacei];
141 const label cellFacei = cells[celli].find(meshFacei);
142
143 blockIds[bndFacei] = celli;
144 cellFaceIds[bndFacei] = cellFacei;
145 patchIds[bndFacei] = pp.index();
146
147 ++bndFacei;
148 ++meshFacei;
149 }
150 }
151 }
152
153 Info<< "Writing block boundary faces in vtk format: "
154 << args.relativePath(writer.output()).c_str() << endl;
155
156 writer.writeGeometry();
157
158 writer.beginCellData();
159 writer.writeCellData("block", blockIds);
160 writer.writeCellData("face", cellFaceIds);
161 writer.writeCellData("patch", patchIds);
162}
163
164
165// ************************************************************************* //
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
const polyMesh & topoMesh
Definition: blockMeshVTK.H:31
refPtr< polyMesh > topoMeshPtr(blocks.topology(true))
void resize(const label len)
Adjust allocated size of list.
Definition: ListI.H:139
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: argListI.H:94
static constexpr direction nComponents
Number of components in bool is 1.
Definition: bool.H:98
labelList patchIds
const polyBoundaryMesh & patches
engineTime & runTime
const cellShapeList & cells
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition: polyPatch.H:63
List< label > labelList
A List of labels.
Definition: List.H:66
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333