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
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #include <OpenFOAM/argList.H>
00100 #include <OpenFOAM/Time.H>
00101 #include <OpenFOAM/polyMesh.H>
00102 #include <OpenFOAM/IFstream.H>
00103 #include <OpenFOAM/polyPatch.H>
00104 #include <OpenFOAM/cellModeller.H>
00105 #include <OpenFOAM/triFace.H>
00106
00107 using namespace Foam;
00108
00109
00110
00111
00112
00113 int main(int argc, char *argv[])
00114 {
00115 argList::validArgs.append("Neutral file");
00116
00117 # include <OpenFOAM/setRootCase.H>
00118 # include <OpenFOAM/createTime.H>
00119
00120 fileName neuFile(args.additionalArgs()[0]);
00121
00122
00123 IFstream str(neuFile);
00124
00125
00126
00127
00128
00129 label nNodes(readLabel(str));
00130
00131 Info<< "nNodes:" << nNodes << endl;
00132
00133
00134 pointField points(nNodes);
00135
00136 forAll(points, pointI)
00137 {
00138 scalar x,y,z;
00139
00140 str >> x >> y >> z;
00141
00142 points[pointI] = point(x, y, z);
00143 }
00144
00145
00146
00147
00148 label nTets(readLabel(str));
00149
00150 Info<< "nTets:" << nTets << endl;
00151
00152 const cellModel& tet = *(cellModeller::lookup("tet"));
00153
00154 cellShapeList cells(nTets);
00155
00156 labelList tetPoints(4);
00157
00158 forAll(cells, cellI)
00159 {
00160 label domain(readLabel(str));
00161
00162 if (domain != 1)
00163 {
00164 WarningIn(args.executable())
00165 << "Cannot handle multiple domains"
00166 << nl << "Ignoring domain " << domain << " setting on line "
00167 << str.lineNumber() << endl;
00168 }
00169
00170 tetPoints[1] = readLabel(str) - 1;
00171 tetPoints[0] = readLabel(str) - 1;
00172 tetPoints[2] = readLabel(str) - 1;
00173 tetPoints[3] = readLabel(str) - 1;
00174
00175 cells[cellI] = cellShape(tet, tetPoints);
00176 }
00177
00178
00179
00180 label nFaces(readLabel(str));
00181
00182 Info<< "nFaces:" << nFaces << endl;
00183
00184
00185 faceList boundaryFaces(nFaces);
00186
00187
00188 labelList boundaryPatch(nFaces, -1);
00189
00190
00191 label maxPatch = 0;
00192
00193
00194 HashTable<label, triFace, Hash<triFace> > vertsToBoundary(nFaces);
00195
00196 forAll(boundaryFaces, faceI)
00197 {
00198 label patchI(readLabel(str));
00199
00200 if (patchI < 0)
00201 {
00202 FatalErrorIn(args.executable())
00203 << "Invalid boundary region number " << patchI
00204 << " on line " << str.lineNumber()
00205 << exit(FatalError);
00206 }
00207
00208
00209 maxPatch = max(maxPatch, patchI);
00210
00211 triFace tri(readLabel(str)-1, readLabel(str)-1, readLabel(str)-1);
00212
00213
00214 boundaryFaces[faceI].setSize(3);
00215 boundaryFaces[faceI][0] = tri[0];
00216 boundaryFaces[faceI][1] = tri[1];
00217 boundaryFaces[faceI][2] = tri[2];
00218 boundaryPatch[faceI] = patchI;
00219
00220 vertsToBoundary.insert(tri, faceI);
00221 }
00222
00223 label nPatches = maxPatch + 1;
00224
00225
00226
00227
00228
00229
00230 forAll(cells, cellI)
00231 {
00232 const cellShape& cll = cells[cellI];
00233
00234
00235 faceList tris(cll.faces());
00236
00237 forAll(tris, i)
00238 {
00239 const face& f = tris[i];
00240
00241
00242
00243 HashTable<label, triFace, Hash<triFace> >::iterator iter =
00244 vertsToBoundary.find(triFace(f[0], f[1], f[2]));
00245
00246 if (iter != vertsToBoundary.end())
00247 {
00248 label faceI = iter();
00249 const triFace& tri = iter.key();
00250
00251
00252 point cc(cll.centre(points));
00253 point fc(tri.centre(points));
00254 vector fn(tri.normal(points));
00255
00256 if (((fc - cc) & fn) < 0)
00257 {
00258
00259 boundaryFaces[faceI] = boundaryFaces[faceI].reverseFace();
00260 }
00261
00262
00263 vertsToBoundary.erase(iter);
00264 }
00265 }
00266 }
00267
00268
00269 if (vertsToBoundary.size())
00270 {
00271
00272 WarningIn(args.executable())
00273 << "There are boundary faces without attached cells."
00274 << "Boundary faces (as triFaces):" << vertsToBoundary.toc()
00275 << endl;
00276 }
00277
00278
00279
00280
00281 faceListList patchFaces(nPatches);
00282
00283 wordList patchNames(nPatches);
00284
00285 forAll(patchNames, patchI)
00286 {
00287 patchNames[patchI] = word("patch") + name(patchI);
00288 }
00289
00290 wordList patchTypes(nPatches, polyPatch::typeName);
00291 word defaultFacesName = "defaultFaces";
00292 word defaultFacesType = polyPatch::typeName;
00293 wordList patchPhysicalTypes(nPatches, polyPatch::typeName);
00294
00295 {
00296
00297 List<DynamicList<face> > allPatchFaces(nPatches);
00298
00299 forAll(boundaryPatch, faceI)
00300 {
00301 label patchI = boundaryPatch[faceI];
00302
00303 allPatchFaces[patchI].append(boundaryFaces[faceI]);
00304 }
00305
00306 Info<< "Patches:" << nl
00307 << "\tNeutral Boundary\tPatch name\tSize" << nl
00308 << "\t----------------\t----------\t----" << endl;
00309
00310 forAll(allPatchFaces, patchI)
00311 {
00312 Info<< '\t' << patchI << "\t\t\t"
00313 << patchNames[patchI] << "\t\t"
00314 << allPatchFaces[patchI].size() << endl;
00315
00316 patchFaces[patchI].transfer(allPatchFaces[patchI]);
00317 }
00318
00319 Info<< endl;
00320 }
00321
00322
00323 polyMesh mesh
00324 (
00325 IOobject
00326 (
00327 polyMesh::defaultRegion,
00328 runTime.constant(),
00329 runTime
00330 ),
00331 xferMove(points),
00332 cells,
00333 patchFaces,
00334 patchNames,
00335 patchTypes,
00336 defaultFacesName,
00337 defaultFacesType,
00338 patchPhysicalTypes
00339 );
00340
00341 Info<< "Writing mesh to " << runTime.constant() << endl << endl;
00342
00343 mesh.write();
00344
00345
00346 Info<< "End\n" << endl;
00347
00348 return 0;
00349 }
00350
00351
00352