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 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 \*---------------------------------------------------------------------------*/
17 
18 {
19  // Non-legacy and ASCII (mesh is small, want readable output)
20  const vtk::outputOptions writeOpts = vtk::formatType::INLINE_ASCII;
21 
22  const polyMesh& topoMesh = blocks.topology();
23  const vtk::vtuCells topoCells(topoMesh, writeOpts);
24 
25  vtk::internalMeshWriter writer
26  (
27  topoMesh,
28  topoCells,
29  writeOpts,
30  runTime.path()/"blockTopology"
31  );
32 
33  Info<< "Writing block topology in vtk format: "
34  << args.relativePath(writer.output()).c_str() << endl;
35 
36  writer.writeGeometry();
37  writer.beginCellData();
38  writer.writeCellIDs();
39 
40  // No cell decomposition, so there is a 1-to-1 correspondence between
41  // input blocks and VTK output cells.
42 
43  vectorField localNormal(blocks.size());
44 
45  // Generate local normals as fields for visualisation
46  for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
47  {
48  const label faceMin = label(2*cmpt);
49  const label faceMax = faceMin+1;
50 
51  localNormal.resize(blocks.size());
52 
53  forAll(blocks, blocki)
54  {
55  const cellShape& shape = blocks[blocki].blockShape();
56  const pointField& verts = blocks[blocki].vertices();
57 
58  if (shape.model() == cellModel::ref(cellModel::HEX))
59  {
60  localNormal[blocki] =
61  (
62  // 30% cell-width as arbitrary value for vector length
63  0.3*mag
64  (
65  shape.face(faceMax).centre(verts)
66  - shape.face(faceMin).centre(verts)
67  )
68  * normalised
69  (
70  // Weigh by area to avoid influence of zero-faces
71  shape.face(faceMax).areaNormal(verts)
72  - shape.face(faceMin).areaNormal(verts)
73  )
74  );
75  }
76  else
77  {
78  // Could handle other shapes (how?)
79  localNormal[blocki] = Zero;
80  }
81  }
82 
83  // Additional safety (should not happen)
84  localNormal.resize(topoMesh.nCells(), Zero);
85 
86  writer.writeCellData
87  (
88  word("local-direction" + name(cmpt)),
89  localNormal
90  );
91  }
92 
93  // if (topoMesh.nCells() != blocks.size())
94  // {
95  // Info<< "Warning: indicated normals may be incorrect" << nl;
96  // }
97 }
98 
99 
100 // ************************************************************************* //
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:350
ref
rDeltaT ref()
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
writer
vtk::internalMeshWriter writer(topoMesh, topoCells, writeOpts, runTime.path()/"blockTopology")
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
topoMesh
const polyMesh & topoMesh
Definition: blockMeshVTK.H:31
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
topoCells
const vtk::vtuCells topoCells(topoMesh, writeOpts)
Foam::normalised
VectorSpace< Form, Cmpt, Ncmpts > normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:483
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::direction
uint8_t direction
Definition: direction.H:52
args
Foam::argList args(argc, argv)
Foam::argList::relativePath
fileName relativePath(const fileName &input, const bool caseTag=false) const
Definition: argListI.H:94