Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
applications
utilities
mesh
conversion
mshToFoam
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
6
\\/ M anipulation |
7
-------------------------------------------------------------------------------
8
License
9
This file is part of OpenFOAM.
10
11
OpenFOAM is free software: you can redistribute it and/or modify it
12
under the terms of the GNU General Public License as published by
13
the Free Software Foundation, either version 3 of the License, or
14
(at your option) any later version.
15
16
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19
for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23
24
Application
25
mshToFoam
26
27
Description
28
Converts .msh file generated by the Adventure system.
29
30
Note
31
The .msh format does not contain any boundary information. It is
32
purely a description of the internal mesh.
33
34
Can read both linear-tet format (i.e. 4 verts per tet) and linear-hex
35
format (8 verts per hex) (if provided with the -hex option)
36
37
Will bomb out if not supplied with the correct option for the
38
file format
39
40
Not extensively tested.
41
42
Usage
43
44
- mshToFoam [OPTIONS] <.msh file>
45
46
@param <.msh file> \n
47
@todo Detailed description of argument.
48
49
@param -hex \n
50
Read hex cells.
51
52
@param -help \n
53
Display help message.
54
55
@param -doc \n
56
Display Doxygen API documentation page for this application.
57
58
@param -srcDoc \n
59
Display Doxygen source documentation page for this application.
60
61
\*---------------------------------------------------------------------------*/
62
63
#include <
OpenFOAM/argList.H
>
64
#include <
OpenFOAM/Time.H
>
65
#include <
OpenFOAM/polyMesh.H
>
66
#include <
OpenFOAM/IFstream.H
>
67
#include <
OpenFOAM/polyPatch.H
>
68
#include <
OpenFOAM/ListOps.H
>
69
#include <
OpenFOAM/cellModeller.H
>
70
71
#include <fstream>
72
73
using namespace
Foam;
74
75
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
76
77
// Main program:
78
79
int
main
(
int
argc,
char
*argv[])
80
{
81
argList::noParallel
();
82
argList::validArgs
.
append
(
".msh file"
);
83
argList::validOptions
.
insert
(
"hex"
,
""
);
84
85
# include <
OpenFOAM/setRootCase.H
>
86
# include <
OpenFOAM/createTime.H
>
87
88
bool
readHex =
args
.
optionFound
(
"hex"
);
89
90
fileName
mshFile(
args
.
additionalArgs
()[0]);
91
IFstream
mshStream(mshFile);
92
93
label nCells;
94
mshStream >> nCells;
95
96
if
(readHex)
97
{
98
Info
<<
"Trying to read "
<< nCells <<
" hexes."
<<
endl
<<
endl
;
99
}
100
else
101
{
102
Info
<<
"Trying to read "
<< nCells <<
" tets."
<<
endl
<<
endl
;
103
}
104
105
cellShapeList
cells
(nCells);
106
107
const
cellModel
& tet = *(
cellModeller::lookup
(
"tet"
));
108
const
cellModel
&
hex
= *(
cellModeller::lookup
(
"hex"
));
109
110
labelList
tetPoints(4);
111
labelList
hexPoints(8);
112
113
if
(readHex)
114
{
115
for
(label cellI = 0; cellI < nCells; cellI++)
116
{
117
for
(label
cp
= 0;
cp
< 8;
cp
++)
118
{
119
mshStream >> hexPoints[
cp
];
120
}
121
cells
[cellI] =
cellShape
(hex, hexPoints);
122
}
123
}
124
else
125
{
126
for
(label cellI = 0; cellI < nCells; cellI++)
127
{
128
for
(label
cp
= 0;
cp
< 4;
cp
++)
129
{
130
mshStream >> tetPoints[
cp
];
131
}
132
cells
[cellI] =
cellShape
(tet, tetPoints);
133
}
134
}
135
136
137
label
nPoints
;
138
139
mshStream >>
nPoints
;
140
141
Info
<<
"Trying to read "
<< nPoints <<
" points."
<<
endl
<<
endl
;
142
143
pointField
points
(nPoints);
144
145
146
for
(label pointI = 0; pointI <
nPoints
; pointI++)
147
{
148
scalar x,
y
, z;
149
150
mshStream >> x >> y >> z;
151
152
points
[pointI] =
point
(x, y, z);
153
}
154
155
156
polyMesh
mesh
157
(
158
IOobject
159
(
160
polyMesh::defaultRegion
,
161
runTime.constant(),
162
runTime
163
),
164
xferMove
(
points
),
165
cells
,
166
faceListList
(0),
167
wordList
(0),
168
wordList
(0),
169
"defaultFaces"
,
170
polyPatch::typeName,
171
wordList
(0)
172
);
173
174
Info
<<
"Writing mesh ..."
<<
endl
;
175
176
mesh
.
write
();
177
178
179
Info
<<
"End\n"
<<
endl
;
180
181
return
0;
182
}
183
184
185
// ************************ vim: set sw=4 sts=4 et: ************************ //