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:169
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1041
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:318
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:53
vtkUnstructuredReader.H
Foam::vtkUnstructuredReader
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
Definition: vtkUnstructuredReader.H:67
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:412
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
polyMesh.H
Foam::argList::get
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:301
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1325
argList.H
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
IFstream.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:342
Time.H
setRootCase.H
Foam::faceListList
List< faceList > faceListList
A List of faceList.
Definition: faceListFwd.H:49
createTime.H
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:510
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
args
Foam::argList args(argc, argv)