vtkUnstructuredToFoam.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) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  vtkUnstructuredToFoam
29 
30 Group
31  grpMeshConversionUtilities
32 
33 Description
34  Convert legacy VTK file (ascii) containing an unstructured grid
35  to an OpenFOAM mesh without boundary information.
36 
37 Note
38  The .vtk format does not contain any boundary information.
39  It is purely a description of the internal mesh.
40  Not extensively tested.
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #include "argList.H"
45 #include "Time.H"
46 #include "polyMesh.H"
47 #include "IFstream.H"
48 #include "vtkUnstructuredReader.H"
49 
50 using namespace Foam;
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 
55 int main(int argc, char *argv[])
56 {
58  (
59  "Convert legacy VTK file (ascii) containing an unstructured grid"
60  " to an OpenFOAM mesh without boundary information"
61  );
62 
64  argList::addArgument("vtk-file", "The input legacy ascii vtk file");
65 
66  #include "setRootCase.H"
67  #include "createTime.H"
68 
69  IFstream mshStream(args.get<fileName>(1));
70 
71  vtkUnstructuredReader reader(runTime, mshStream);
72 
74  (
75  IOobject
76  (
78  runTime.constant(),
79  runTime
80  ),
81  std::move(reader.points()),
82  reader.cells(),
83  faceListList(),
84  wordList(),
85  wordList(),
86  "defaultFaces",
87  polyPatch::typeName,
88  wordList()
89  );
90 
91  // Set the precision of the points data to 10
93 
94  Info<< "Writing mesh ..." << endl;
95 
96  mesh.removeFiles();
97  mesh.write();
98 
99  Info<< "End\n" << endl;
100 
101  return 0;
102 }
103 
104 
105 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Definition: fvMesh.C:1034
Foam::polyMesh::defaultRegion
static word defaultRegion
Definition: polyMesh.H:314
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:49
vtkUnstructuredReader.H
Foam::vtkUnstructuredReader
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
Definition: vtkUnstructuredReader.H:63
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
polyMesh.H
Foam::argList::get
T get(const label index) const
Definition: argListI.H:271
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:58
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Definition: argList.C:294
Foam::Info
messageStream Info
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Definition: polyMesh.C:1318
argList.H
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Definition: hashSets.C:40
IFstream.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Definition: atmBoundaryLayer.C:26
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Definition: IOstream.H:338
Time.H
setRootCase.H
Foam::List< faceList >
createTime.H
Foam::argList::noParallel
static void noParallel()
Definition: argList.C:503
Foam::TimePaths::constant
const word & constant() const
Definition: TimePathsI.H:89
args
Foam::argList args(argc, argv)