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-2024 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  // More precision (for points data)
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 // ************************************************************************* //
List< faceList > faceListList
List of faceList.
Definition: faceListFwd.H:44
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
A class for handling file names.
Definition: fileName.H:72
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void noParallel()
Remove the parallel options.
Definition: argList.C:584
Reader for vtk UNSTRUCTURED_GRID legacy files. Supports single CELLS, POINTS etc. entry only...
dynamicFvMesh & mesh
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
Definition: polyMesh.C:1329
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:406
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Definition: IOstream.H:440
virtual bool write(const bool writeOnProc=true) const
Write mesh using IO settings from time.
Definition: fvMesh.C:1113
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
Input from file stream as an ISstream, normally using std::ifstream for the actual input...
Definition: IFstream.H:51
List< word > wordList
List of word.
Definition: fileName.H:59
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:351
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:180
Namespace for OpenFOAM.