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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 Description
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 
23 refPtr<polyMesh> topoMeshPtr(blocks.topology(true));
24 const 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  (
32  topoMesh,
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 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 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
ref
rDeltaT ref()
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
topoMeshPtr
refPtr< polyMesh > topoMeshPtr(blocks.topology(true))
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
patchIds
labelList patchIds
Definition: convertProcessorPatches.H:67
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
topoMesh
const polyMesh & topoMesh
Definition: blockMeshVTK.H:31
Foam::polyPatchList
PtrList< polyPatch > polyPatchList
container classes for polyPatch
Definition: polyPatchList.H:47
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Foam::normalised
VectorSpace< Form, Cmpt, Ncmpts > normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:487
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::direction
uint8_t direction
Definition: direction.H:52
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
args
Foam::argList args(argc, argv)
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, vtk::formatType::INLINE_ASCII, runTime.path()/"blockTopology")
Foam::argList::relativePath
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: argListI.H:94