netgenNeutralToFoam.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #include "argList.H"
00076 #include "Time.H"
00077 #include "polyMesh.H"
00078 #include "IFstream.H"
00079 #include "polyPatch.H"
00080 #include "cellModeller.H"
00081 #include "triFace.H"
00082
00083 using namespace Foam;
00084
00085
00086
00087
00088
00089 int main(int argc, char *argv[])
00090 {
00091 argList::validArgs.append("Neutral file");
00092
00093 # include "setRootCase.H"
00094 # include "createTime.H"
00095
00096 fileName neuFile(args.additionalArgs()[0]);
00097
00098
00099 IFstream str(neuFile);
00100
00101
00102
00103
00104
00105 label nNodes(readLabel(str));
00106
00107 Info<< "nNodes:" << nNodes << endl;
00108
00109
00110 pointField points(nNodes);
00111
00112 forAll(points, pointI)
00113 {
00114 scalar x,y,z;
00115
00116 str >> x >> y >> z;
00117
00118 points[pointI] = point(x, y, z);
00119 }
00120
00121
00122
00123
00124 label nTets(readLabel(str));
00125
00126 Info<< "nTets:" << nTets << endl;
00127
00128 const cellModel& tet = *(cellModeller::lookup("tet"));
00129
00130 cellShapeList cells(nTets);
00131
00132 labelList tetPoints(4);
00133
00134 forAll(cells, cellI)
00135 {
00136 label domain(readLabel(str));
00137
00138 if (domain != 1)
00139 {
00140 WarningIn(args.executable())
00141 << "Cannot handle multiple domains"
00142 << nl << "Ignoring domain " << domain << " setting on line "
00143 << str.lineNumber() << endl;
00144 }
00145
00146 tetPoints[1] = readLabel(str) - 1;
00147 tetPoints[0] = readLabel(str) - 1;
00148 tetPoints[2] = readLabel(str) - 1;
00149 tetPoints[3] = readLabel(str) - 1;
00150
00151 cells[cellI] = cellShape(tet, tetPoints);
00152 }
00153
00154
00155
00156 label nFaces(readLabel(str));
00157
00158 Info<< "nFaces:" << nFaces << endl;
00159
00160
00161 faceList boundaryFaces(nFaces);
00162
00163
00164 labelList boundaryPatch(nFaces, -1);
00165
00166
00167 label maxPatch = 0;
00168
00169
00170 HashTable<label, triFace, Hash<triFace> > vertsToBoundary(nFaces);
00171
00172 forAll(boundaryFaces, faceI)
00173 {
00174 label patchI(readLabel(str));
00175
00176 if (patchI < 0)
00177 {
00178 FatalErrorIn(args.executable())
00179 << "Invalid boundary region number " << patchI
00180 << " on line " << str.lineNumber()
00181 << exit(FatalError);
00182 }
00183
00184
00185 maxPatch = max(maxPatch, patchI);
00186
00187 triFace tri(readLabel(str)-1, readLabel(str)-1, readLabel(str)-1);
00188
00189
00190 boundaryFaces[faceI].setSize(3);
00191 boundaryFaces[faceI][0] = tri[0];
00192 boundaryFaces[faceI][1] = tri[1];
00193 boundaryFaces[faceI][2] = tri[2];
00194 boundaryPatch[faceI] = patchI;
00195
00196 vertsToBoundary.insert(tri, faceI);
00197 }
00198
00199 label nPatches = maxPatch + 1;
00200
00201
00202
00203
00204
00205
00206 forAll(cells, cellI)
00207 {
00208 const cellShape& cll = cells[cellI];
00209
00210
00211 faceList tris(cll.faces());
00212
00213 forAll(tris, i)
00214 {
00215 const face& f = tris[i];
00216
00217
00218
00219 HashTable<label, triFace, Hash<triFace> >::iterator iter =
00220 vertsToBoundary.find(triFace(f[0], f[1], f[2]));
00221
00222 if (iter != vertsToBoundary.end())
00223 {
00224 label faceI = iter();
00225 const triFace& tri = iter.key();
00226
00227
00228 point cc(cll.centre(points));
00229 point fc(tri.centre(points));
00230 vector fn(tri.normal(points));
00231
00232 if (((fc - cc) & fn) < 0)
00233 {
00234
00235 boundaryFaces[faceI] = boundaryFaces[faceI].reverseFace();
00236 }
00237
00238
00239 vertsToBoundary.erase(iter);
00240 }
00241 }
00242 }
00243
00244
00245 if (vertsToBoundary.size())
00246 {
00247
00248 WarningIn(args.executable())
00249 << "There are boundary faces without attached cells."
00250 << "Boundary faces (as triFaces):" << vertsToBoundary.toc()
00251 << endl;
00252 }
00253
00254
00255
00256
00257 faceListList patchFaces(nPatches);
00258
00259 wordList patchNames(nPatches);
00260
00261 forAll(patchNames, patchI)
00262 {
00263 patchNames[patchI] = word("patch") + name(patchI);
00264 }
00265
00266 wordList patchTypes(nPatches, polyPatch::typeName);
00267 word defaultFacesName = "defaultFaces";
00268 word defaultFacesType = polyPatch::typeName;
00269 wordList patchPhysicalTypes(nPatches, polyPatch::typeName);
00270
00271 {
00272
00273 List<DynamicList<face> > allPatchFaces(nPatches);
00274
00275 forAll(boundaryPatch, faceI)
00276 {
00277 label patchI = boundaryPatch[faceI];
00278
00279 allPatchFaces[patchI].append(boundaryFaces[faceI]);
00280 }
00281
00282 Info<< "Patches:" << nl
00283 << "\tNeutral Boundary\tPatch name\tSize" << nl
00284 << "\t----------------\t----------\t----" << endl;
00285
00286 forAll(allPatchFaces, patchI)
00287 {
00288 Info<< '\t' << patchI << "\t\t\t"
00289 << patchNames[patchI] << "\t\t"
00290 << allPatchFaces[patchI].size() << endl;
00291
00292 patchFaces[patchI].transfer(allPatchFaces[patchI]);
00293 }
00294
00295 Info<< endl;
00296 }
00297
00298
00299 polyMesh mesh
00300 (
00301 IOobject
00302 (
00303 polyMesh::defaultRegion,
00304 runTime.constant(),
00305 runTime
00306 ),
00307 xferMove(points),
00308 cells,
00309 patchFaces,
00310 patchNames,
00311 patchTypes,
00312 defaultFacesName,
00313 defaultFacesType,
00314 patchPhysicalTypes
00315 );
00316
00317 Info<< "Writing mesh to " << runTime.constant() << endl << endl;
00318
00319 mesh.write();
00320
00321
00322 Info<< "End\n" << endl;
00323
00324 return 0;
00325 }
00326
00327
00328
Copyright © 2000-2009 OpenCFD Ltd