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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  vtkUnstructuredToFoam
28 
29 Group
30  grpMeshConversionUtilities
31 
32 Description
33  Convert legacy VTK file (ascii) containing an unstructured grid
34  to an OpenFOAM mesh without boundary information.
35 
36 Note
37  The .vtk format does not contain any boundary information.
38  It is purely a description of the internal mesh.
39  Not extensively tested.
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #include "argList.H"
44 #include "Time.H"
45 #include "polyMesh.H"
46 #include "IFstream.H"
47 #include "vtkUnstructuredReader.H"
48 
49 using namespace Foam;
50 
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 
53 
54 int main(int argc, char *argv[])
55 {
57  (
58  "Convert legacy VTK file (ascii) containing an unstructured grid"
59  " to an OpenFOAM mesh without boundary information"
60  );
61 
63  argList::addArgument("vtk-file", "The input legacy ascii vtk file");
64 
65  #include "setRootCase.H"
66  #include "createTime.H"
67 
68  IFstream mshStream(args[1]);
69 
70  vtkUnstructuredReader reader(runTime, mshStream);
71 
73  (
74  IOobject
75  (
77  runTime.constant(),
78  runTime
79  ),
80  std::move(reader.points()),
81  reader.cells(),
82  faceListList(),
83  wordList(),
84  wordList(),
85  "defaultFaces",
86  polyPatch::typeName,
87  wordList()
88  );
89 
90  // Set the precision of the points data to 10
92 
93  Info<< "Writing mesh ..." << endl;
94 
95  mesh.removeFiles();
96  mesh.write();
97 
98  Info<< "End\n" << endl;
99 
100  return 0;
101 }
102 
103 
104 // ************************************************************************* //
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:104
Foam::fvMesh::write
virtual bool write(const bool valid=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:895
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:312
Foam::IFstream
Input from file stream, using an ISstream.
Definition: IFstream.H:85
vtkUnstructuredReader.H
Foam::vtkUnstructuredReader
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only.
Definition: vtkUnstructuredReader.H:66
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:59
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyMesh::removeFiles
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1264
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
Time.H
setRootCase.H
Foam::faceListList
List< faceList > faceListList
A List of faceList.
Definition: faceListFwd.H:49
Foam::IOstream::defaultPrecision
static unsigned int defaultPrecision()
Return the default precision.
Definition: IOstream.H:333
createTime.H
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
args
Foam::argList args(argc, argv)