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 #include "fieldviewTopology.H"
00030 #include "polyMesh.H"
00031 #include "cellShape.H"
00032 #include "cellModeller.H"
00033 #include "wallPolyPatch.H"
00034 #include "symmetryPolyPatch.H"
00035
00036
00037 #include "fv_reader_tags.h"
00038
00039 extern "C"
00040 {
00041 unsigned int fv_encode_elem_header(int elem_type, int wall_info[]);
00042 }
00043
00044
00045
00046
00047 Foam::labelList Foam::fieldviewTopology::calcFaceAddressing
00048 (
00049 const faceList& allFaces,
00050 const cellShape& shape,
00051 const labelList& faces,
00052 const label cellI
00053 )
00054 {
00055
00056 labelList shapeToMesh(shape.nFaces(), -1);
00057
00058 const faceList modelFaces(shape.faces());
00059
00060
00061 forAll(modelFaces, cellFaceI)
00062 {
00063
00064 const face& modelFace = modelFaces[cellFaceI];
00065
00066
00067 forAll(faces, faceI)
00068 {
00069 const face& vertLabels = allFaces[faces[faceI]];
00070
00071 if (vertLabels == modelFace)
00072 {
00073 shapeToMesh[cellFaceI] = faces[faceI];
00074 break;
00075 }
00076 }
00077
00078 if (shapeToMesh[cellFaceI] == -1)
00079 {
00080 FatalErrorIn("foamToFieldview : calcFaceAddressing")
00081 << "calcFaceAddressing : can't match face to shape.\n"
00082 << " shape face:" << modelFace << endl
00083 << " face labels:" << faces << endl
00084 << " cellI:" << cellI << endl;
00085
00086 FatalError << "Faces consist of vertices:" << endl;
00087 forAll(faces, faceI)
00088 {
00089 FatalError
00090 << " face:" << faces[faceI]
00091 << allFaces[faces[faceI]] << endl;
00092 }
00093 FatalError << exit(FatalError);
00094 }
00095 }
00096 return shapeToMesh;
00097 }
00098
00099
00100
00101
00102
00103 Foam::fieldviewTopology::fieldviewTopology
00104 (
00105 const polyMesh& mesh,
00106 const bool setWallInfo
00107 )
00108 :
00109 hexLabels_((1+8)*mesh.nCells()),
00110 prismLabels_((1+6)*mesh.nCells()),
00111 pyrLabels_((1+5)*mesh.nCells()),
00112 tetLabels_((1+4)*mesh.nCells()),
00113 nPoly_(0),
00114 quadFaceLabels_(mesh.boundaryMesh().size()),
00115 nPolyFaces_(mesh.boundaryMesh().size())
00116 {
00117
00118
00119
00120 labelList wallFace(mesh.nFaces(), NOT_A_WALL);
00121 boolList wallCell(mesh.nCells(), false);
00122
00123 if (setWallInfo)
00124 {
00125 forAll (mesh.boundaryMesh(), patchI)
00126 {
00127 const polyPatch& currPatch = mesh.boundaryMesh()[patchI];
00128 if
00129 (
00130 isType<wallPolyPatch>(currPatch)
00131 || isType<symmetryPolyPatch>(currPatch)
00132 )
00133 {
00134 forAll(currPatch, patchFaceI)
00135 {
00136 label meshFaceI = currPatch.start() + patchFaceI;
00137
00138 wallFace[meshFaceI] = A_WALL;
00139 wallCell[mesh.faceOwner()[meshFaceI]] = true;
00140 }
00141 }
00142 }
00143 }
00144
00145
00146
00147 const cellModel& tet = *(cellModeller::lookup("tet"));
00148 const cellModel& pyr = *(cellModeller::lookup("pyr"));
00149 const cellModel& prism = *(cellModeller::lookup("prism"));
00150 const cellModel& wedge = *(cellModeller::lookup("wedge"));
00151 const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
00152 const cellModel& hex = *(cellModeller::lookup("hex"));
00153
00154
00155 labelList notWallFlags(6, NOT_A_WALL);
00156 label tetNotWall = fv_encode_elem_header
00157 (
00158 FV_TET_ELEM_ID, notWallFlags.begin()
00159 );
00160 label pyrNotWall = fv_encode_elem_header
00161 (
00162 FV_PYRA_ELEM_ID, notWallFlags.begin()
00163 );
00164 label prismNotWall = fv_encode_elem_header
00165 (
00166 FV_PRISM_ELEM_ID, notWallFlags.begin()
00167 );
00168 label hexNotWall = fv_encode_elem_header
00169 (
00170 FV_HEX_ELEM_ID, notWallFlags.begin()
00171 );
00172
00173
00174 const cellList& cellFaces = mesh.cells();
00175 const cellShapeList& cellShapes = mesh.cellShapes();
00176
00177
00178 label hexi = 0;
00179 label prismi = 0;
00180 label pyri = 0;
00181 label teti = 0;
00182
00183 const faceList& allFaces = mesh.faces();
00184
00185 labelList wallFlags(6);
00186 forAll(cellShapes, celli)
00187 {
00188 const cellShape& cellShape = cellShapes[celli];
00189 const cellModel& cellModel = cellShape.model();
00190
00191 if (cellModel == tet)
00192 {
00193 if (!wallCell[celli])
00194 {
00195 tetLabels_[teti++] = tetNotWall;
00196 }
00197 else
00198 {
00199 labelList modelToMesh = calcFaceAddressing
00200 (
00201 allFaces, cellShape, cellFaces[celli], celli
00202 );
00203
00204 wallFlags[0] = wallFace[modelToMesh[0]];
00205 wallFlags[1] = wallFace[modelToMesh[1]];
00206 wallFlags[2] = wallFace[modelToMesh[2]];
00207 wallFlags[3] = wallFace[modelToMesh[3]];
00208
00209 tetLabels_[teti++] = fv_encode_elem_header
00210 (
00211 FV_TET_ELEM_ID, wallFlags.begin()
00212 );
00213 }
00214
00215 tetLabels_[teti++] = cellShape[0] + 1;
00216 tetLabels_[teti++] = cellShape[1] + 1;
00217 tetLabels_[teti++] = cellShape[2] + 1;
00218 tetLabels_[teti++] = cellShape[3] + 1;
00219 }
00220 else if (cellModel == pyr)
00221 {
00222 if (!wallCell[celli])
00223 {
00224 pyrLabels_[pyri++] = pyrNotWall;
00225 }
00226 else
00227 {
00228 labelList modelToMesh = calcFaceAddressing
00229 (
00230 allFaces, cellShape, cellFaces[celli], celli
00231 );
00232
00233 wallFlags[0] = wallFace[modelToMesh[0]];
00234 wallFlags[1] = wallFace[modelToMesh[3]];
00235 wallFlags[2] = wallFace[modelToMesh[2]];
00236 wallFlags[3] = wallFace[modelToMesh[1]];
00237 wallFlags[4] = wallFace[modelToMesh[4]];
00238
00239 pyrLabels_[pyri++] = fv_encode_elem_header
00240 (
00241 FV_PYRA_ELEM_ID, wallFlags.begin()
00242 );
00243 }
00244
00245 pyrLabels_[pyri++] = cellShape[0] + 1;
00246 pyrLabels_[pyri++] = cellShape[1] + 1;
00247 pyrLabels_[pyri++] = cellShape[2] + 1;
00248 pyrLabels_[pyri++] = cellShape[3] + 1;
00249 pyrLabels_[pyri++] = cellShape[4] + 1;
00250 }
00251 else if (cellModel == prism)
00252 {
00253 if (!wallCell[celli])
00254 {
00255 prismLabels_[prismi++] = prismNotWall;
00256 }
00257 else
00258 {
00259 labelList modelToMesh = calcFaceAddressing
00260 (
00261 allFaces, cellShape, cellFaces[celli], celli
00262 );
00263
00264 wallFlags[0] = wallFace[modelToMesh[4]];
00265 wallFlags[1] = wallFace[modelToMesh[2]];
00266 wallFlags[2] = wallFace[modelToMesh[3]];
00267 wallFlags[3] = wallFace[modelToMesh[0]];
00268 wallFlags[4] = wallFace[modelToMesh[1]];
00269
00270 prismLabels_[prismi++] = fv_encode_elem_header
00271 (
00272 FV_PRISM_ELEM_ID, wallFlags.begin()
00273 );
00274 }
00275
00276 prismLabels_[prismi++] = cellShape[0] + 1;
00277 prismLabels_[prismi++] = cellShape[3] + 1;
00278 prismLabels_[prismi++] = cellShape[4] + 1;
00279 prismLabels_[prismi++] = cellShape[1] + 1;
00280 prismLabels_[prismi++] = cellShape[5] + 1;
00281 prismLabels_[prismi++] = cellShape[2] + 1;
00282 }
00283 else if (cellModel == tetWedge)
00284 {
00285
00286 if (!wallCell[celli])
00287 {
00288 prismLabels_[prismi++] = prismNotWall;
00289 }
00290 else
00291 {
00292 labelList modelToMesh = calcFaceAddressing
00293 (
00294 allFaces, cellShape, cellFaces[celli], celli
00295 );
00296
00297 wallFlags[0] = wallFace[modelToMesh[1]];
00298 wallFlags[1] = wallFace[modelToMesh[2]];
00299 wallFlags[2] = wallFace[modelToMesh[3]];
00300 wallFlags[3] = wallFace[modelToMesh[0]];
00301 wallFlags[4] = wallFace[modelToMesh[3]];
00302
00303 prismLabels_[prismi++] = fv_encode_elem_header
00304 (
00305 FV_PRISM_ELEM_ID, wallFlags.begin()
00306 );
00307 }
00308
00309 prismLabels_[prismi++] = cellShape[0] + 1;
00310 prismLabels_[prismi++] = cellShape[3] + 1;
00311 prismLabels_[prismi++] = cellShape[4] + 1;
00312 prismLabels_[prismi++] = cellShape[1] + 1;
00313 prismLabels_[prismi++] = cellShape[4] + 1;
00314 prismLabels_[prismi++] = cellShape[2] + 1;
00315 }
00316 else if (cellModel == wedge)
00317 {
00318 if (!wallCell[celli])
00319 {
00320 hexLabels_[hexi++] = hexNotWall;
00321 }
00322 else
00323 {
00324 labelList modelToMesh = calcFaceAddressing
00325 (
00326 allFaces, cellShape, cellFaces[celli], celli
00327 );
00328
00329 wallFlags[0] = wallFace[modelToMesh[2]];
00330 wallFlags[1] = wallFace[modelToMesh[3]];
00331 wallFlags[2] = wallFace[modelToMesh[0]];
00332 wallFlags[3] = wallFace[modelToMesh[1]];
00333 wallFlags[4] = wallFace[modelToMesh[4]];
00334 wallFlags[5] = wallFace[modelToMesh[5]];
00335
00336 hexLabels_[hexi++] = fv_encode_elem_header
00337 (
00338 FV_HEX_ELEM_ID, wallFlags.begin()
00339 );
00340 }
00341 hexLabels_[hexi++] = cellShape[0] + 1;
00342 hexLabels_[hexi++] = cellShape[1] + 1;
00343 hexLabels_[hexi++] = cellShape[0] + 1;
00344 hexLabels_[hexi++] = cellShape[2] + 1;
00345 hexLabels_[hexi++] = cellShape[3] + 1;
00346 hexLabels_[hexi++] = cellShape[4] + 1;
00347 hexLabels_[hexi++] = cellShape[6] + 1;
00348 hexLabels_[hexi++] = cellShape[5] + 1;
00349 }
00350 else if (cellModel == hex)
00351 {
00352 if (!wallCell[celli])
00353 {
00354 hexLabels_[hexi++] = hexNotWall;
00355 }
00356 else
00357 {
00358 labelList modelToMesh = calcFaceAddressing
00359 (
00360 allFaces, cellShape, cellFaces[celli], celli
00361 );
00362
00363 wallFlags[0] = wallFace[modelToMesh[0]];
00364 wallFlags[1] = wallFace[modelToMesh[1]];
00365 wallFlags[2] = wallFace[modelToMesh[4]];
00366 wallFlags[3] = wallFace[modelToMesh[5]];
00367 wallFlags[4] = wallFace[modelToMesh[2]];
00368 wallFlags[5] = wallFace[modelToMesh[3]];
00369
00370 hexLabels_[hexi++] = fv_encode_elem_header
00371 (
00372 FV_HEX_ELEM_ID, wallFlags.begin()
00373 );
00374 }
00375 hexLabels_[hexi++] = cellShape[0] + 1;
00376 hexLabels_[hexi++] = cellShape[1] + 1;
00377 hexLabels_[hexi++] = cellShape[3] + 1;
00378 hexLabels_[hexi++] = cellShape[2] + 1;
00379 hexLabels_[hexi++] = cellShape[4] + 1;
00380 hexLabels_[hexi++] = cellShape[5] + 1;
00381 hexLabels_[hexi++] = cellShape[7] + 1;
00382 hexLabels_[hexi++] = cellShape[6] + 1;
00383 }
00384 else
00385 {
00386 nPoly_++;
00387 }
00388 }
00389
00390 hexLabels_.setSize(hexi);
00391 prismLabels_.setSize(prismi);
00392 pyrLabels_.setSize(pyri);
00393 tetLabels_.setSize(teti);
00394
00395
00396
00397
00398
00399 forAll(mesh.boundaryMesh(), patchI)
00400 {
00401 const polyPatch& patchFaces = mesh.boundaryMesh()[patchI];
00402
00403 labelList& faceLabels = quadFaceLabels_[patchI];
00404
00405
00406 faceLabels.setSize(patchFaces.size()*4);
00407
00408 label labelI = 0;
00409
00410 forAll(patchFaces, faceI)
00411 {
00412 const face& patchFace = patchFaces[faceI];
00413
00414 if (patchFace.size() == 3)
00415 {
00416 faceLabels[labelI++] = patchFace[0] + 1;
00417 faceLabels[labelI++] = patchFace[1] + 1;
00418 faceLabels[labelI++] = patchFace[2] + 1;
00419 faceLabels[labelI++] = 0;
00420 }
00421 else if (patchFace.size() == 4)
00422 {
00423 faceLabels[labelI++] = patchFace[0] + 1;
00424 faceLabels[labelI++] = patchFace[1] + 1;
00425 faceLabels[labelI++] = patchFace[2] + 1;
00426 faceLabels[labelI++] = patchFace[3] + 1;
00427 }
00428 }
00429
00430 faceLabels.setSize(labelI);
00431
00432 label nFaces = labelI/4;
00433
00434 nPolyFaces_[patchI] = patchFaces.size() - nFaces;
00435 }
00436 }
00437
00438
00439