Loading...
Searching...
No Matches
mshToFoam.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-2016 OpenFOAM Foundation
9 Copyright (C) 2021-2024 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Application
28 mshToFoam
29
30Group
31 grpMeshConversionUtilities
32
33Description
34 Convert .msh file generated by the Adventure system.
35
36 Note: the .msh format does not contain any boundary information. It is
37 purely a description of the internal mesh.
38
39 Can read both linear-tet format (i.e. 4 verts per tet) and linear-hex
40 format (8 verts per hex) (if provided with the -hex (at your option)
41 (Note: will bomb out if not supplied with the correct option for the
42 file format)
43
44 Not extensively tested.
45
46\*---------------------------------------------------------------------------*/
47
48#include "argList.H"
49#include "Time.H"
50#include "polyMesh.H"
51#include "IFstream.H"
52#include "polyPatch.H"
53#include "ListOps.H"
54#include "cellModel.H"
55
56#include <fstream>
57
58using namespace Foam;
59
60// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61
62
63int main(int argc, char *argv[])
64{
66 (
67 "Convert an Adventure .msh file to OpenFOAM"
68 );
70 argList::addArgument(".msh file");
72 (
73 "hex",
74 "Treat input as containing hex instead of tet cells"
75 );
76
77 #include "setRootCase.H"
78 #include "createTime.H"
79
80 const bool readHex = args.found("hex");
81 IFstream mshStream(args.get<fileName>(1));
82
83 label nCells;
84 mshStream >> nCells;
85
86 if (readHex)
87 {
88 Info<< "Trying to read " << nCells << " hexes." << nl << endl;
89 }
90 else
91 {
92 Info<< "Trying to read " << nCells << " tets." << nl << endl;
93 }
94
95 cellShapeList cells(nCells);
96
99
101 labelList hexPoints(8);
102
103 if (readHex)
104 {
105 for (label celli = 0; celli < nCells; celli++)
106 {
107 for (label cp = 0; cp < 8; cp++)
108 {
109 mshStream >> hexPoints[cp];
110 }
111 cells[celli].reset(hex, hexPoints);
112 }
113 }
114 else
115 {
116 for (label celli = 0; celli < nCells; celli++)
117 {
118 for (label cp = 0; cp < 4; cp++)
119 {
120 mshStream >> tetPoints[cp];
121 }
122 cells[celli].reset(tet, tetPoints);
123 }
124 }
125
126
127 label nPoints;
128
129 mshStream >> nPoints;
130
131 Info<< "Trying to read " << nPoints << " points." << endl << endl;
132
134
135
136 for (label pointi = 0; pointi < nPoints; pointi++)
137 {
138 scalar x, y, z;
139
140 mshStream >> x >> y >> z;
141
142 points[pointi] = point(x, y, z);
143 }
144
145
147 (
149 (
151 runTime.constant(),
152 runTime
153 ),
154 std::move(points),
155 cells,
156 faceListList(),
157 wordList(),
158 wordList(),
159 "defaultFaces",
160 polyPatch::typeName,
161 wordList()
162 );
163
164 // More precision (for points data)
166
167 Info<< "Writing mesh ..." << endl;
168
169 mesh.removeFiles();
170 mesh.write();
171
172 Info<< "End\n" << endl;
173
174 return 0;
175}
176
177
178// ************************************************************************* //
scalar y
Various functions to operate on Lists.
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
Definition IFstream.H:55
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Definition IOstream.H:459
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void noParallel()
Remove the parallel options.
Definition argList.C:599
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
Maps a geometry to a set of cell primitives.
Definition cellModel.H:73
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
Definition cellModels.C:150
A class for handling file names.
Definition fileName.H:75
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
static word defaultRegion
Return the default region name.
Definition polyMesh.H:406
Tet point storage. Default constructable (tetrahedron is not).
Definition tetrahedron.H:85
dynamicFvMesh & mesh
engineTime & runTime
const pointField & points
label nPoints
const cellShapeList & cells
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
IOstream & hex(IOstream &io)
Definition IOstream.H:579
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
List< faceList > faceListList
List of faceList.
Definition faceListFwd.H:44
vector point
Point is a vector.
Definition point.H:37
vectorField pointField
pointField is a vectorField.
List< cellShape > cellShapeList
List of cellShape.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
const volScalarField & cp
Foam::argList args(argc, argv)