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 #include "polyMesh.H"
00031 #include "Time.H"
00032 #include "primitiveMesh.H"
00033 #include "DynamicList.H"
00034
00035
00036
00037 Foam::labelListList Foam::polyMesh::cellShapePointCells
00038 (
00039 const cellShapeList& c
00040 ) const
00041 {
00042 List<DynamicList<label, primitiveMesh::cellsPerPoint_> >
00043 pc(points().size());
00044
00045
00046 forAll(c, i)
00047 {
00048
00049 const labelList& labels = c[i];
00050
00051 forAll(labels, j)
00052 {
00053
00054 label curPoint = labels[j];
00055 DynamicList<label, primitiveMesh::cellsPerPoint_>& curPointCells =
00056 pc[curPoint];
00057
00058
00059 curPointCells.append(i);
00060 }
00061 }
00062
00063 labelListList pointCellAddr(pc.size());
00064
00065 forAll (pc, pointI)
00066 {
00067 pointCellAddr[pointI].transfer(pc[pointI]);
00068 }
00069
00070 return pointCellAddr;
00071 }
00072
00073
00074 Foam::labelList Foam::polyMesh::facePatchFaceCells
00075 (
00076 const faceList& patchFaces,
00077 const labelListList& pointCells,
00078 const faceListList& cellsFaceShapes,
00079 const label patchID
00080 ) const
00081 {
00082 register bool found;
00083
00084 labelList FaceCells(patchFaces.size());
00085
00086 forAll(patchFaces, fI)
00087 {
00088 found = false;
00089
00090 const face& curFace = patchFaces[fI];
00091 const labelList& facePoints = patchFaces[fI];
00092
00093 forAll(facePoints, pointI)
00094 {
00095 const labelList& facePointCells = pointCells[facePoints[pointI]];
00096
00097 forAll(facePointCells, cellI)
00098 {
00099 faceList cellFaces = cellsFaceShapes[facePointCells[cellI]];
00100
00101 forAll(cellFaces, cellFace)
00102 {
00103 if (cellFaces[cellFace] == curFace)
00104 {
00105
00106 FaceCells[fI] = facePointCells[cellI];
00107
00108 found = true;
00109 }
00110 if (found) break;
00111 }
00112 if (found) break;
00113 }
00114 if (found) break;
00115 }
00116
00117 if (!found)
00118 {
00119 FatalErrorIn
00120 (
00121 "polyMesh::facePatchFaceCells(const faceList& patchFaces,"
00122 "const labelListList& pointCells,"
00123 "const faceListList& cellsFaceShapes,"
00124 "const label patchID)"
00125 ) << "face " << fI << " in patch " << patchID
00126 << " does not have neighbour cell"
00127 << " face: " << patchFaces[fI]
00128 << abort(FatalError);
00129 }
00130 }
00131
00132 return FaceCells;
00133 }
00134
00135
00136 Foam::polyMesh::polyMesh
00137 (
00138 const IOobject& io,
00139 const Xfer<pointField>& points,
00140 const cellShapeList& cellsAsShapes,
00141 const faceListList& boundaryFaces,
00142 const wordList& boundaryPatchNames,
00143 const wordList& boundaryPatchTypes,
00144 const word& defaultBoundaryPatchName,
00145 const word& defaultBoundaryPatchType,
00146 const wordList& boundaryPatchPhysicalTypes,
00147 const bool syncPar
00148 )
00149 :
00150 objectRegistry(io),
00151 primitiveMesh(),
00152 points_
00153 (
00154 IOobject
00155 (
00156 "points",
00157 instance(),
00158 meshSubDir,
00159 *this,
00160 IOobject::NO_READ,
00161 IOobject::AUTO_WRITE
00162 ),
00163 points
00164 ),
00165 faces_
00166 (
00167 IOobject
00168 (
00169 "faces",
00170 instance(),
00171 meshSubDir,
00172 *this,
00173 IOobject::NO_READ,
00174 IOobject::AUTO_WRITE
00175 ),
00176 0
00177 ),
00178 owner_
00179 (
00180 IOobject
00181 (
00182 "owner",
00183 instance(),
00184 meshSubDir,
00185 *this,
00186 IOobject::NO_READ,
00187 IOobject::AUTO_WRITE
00188 ),
00189 0
00190 ),
00191 neighbour_
00192 (
00193 IOobject
00194 (
00195 "neighbour",
00196 instance(),
00197 meshSubDir,
00198 *this,
00199 IOobject::NO_READ,
00200 IOobject::AUTO_WRITE
00201 ),
00202 0
00203 ),
00204 clearedPrimitives_(false),
00205 boundary_
00206 (
00207 IOobject
00208 (
00209 "boundary",
00210 instance(),
00211 meshSubDir,
00212 *this,
00213 IOobject::NO_READ,
00214 IOobject::AUTO_WRITE
00215 ),
00216 *this,
00217 boundaryFaces.size() + 1
00218 ),
00219 bounds_(points_, syncPar),
00220 geometricD_(Vector<label>::zero),
00221 solutionD_(Vector<label>::zero),
00222 pointZones_
00223 (
00224 IOobject
00225 (
00226 "pointZones",
00227 instance(),
00228 meshSubDir,
00229 *this,
00230 IOobject::NO_READ,
00231 IOobject::NO_WRITE
00232 ),
00233 *this,
00234 0
00235 ),
00236 faceZones_
00237 (
00238 IOobject
00239 (
00240 "faceZones",
00241 instance(),
00242 meshSubDir,
00243 *this,
00244 IOobject::NO_READ,
00245 IOobject::NO_WRITE
00246 ),
00247 *this,
00248 0
00249 ),
00250 cellZones_
00251 (
00252 IOobject
00253 (
00254 "cellZones",
00255 instance(),
00256 meshSubDir,
00257 *this,
00258 IOobject::NO_READ,
00259 IOobject::NO_WRITE
00260 ),
00261 *this,
00262 0
00263 ),
00264 globalMeshDataPtr_(NULL),
00265 moving_(false),
00266 curMotionTimeIndex_(time().timeIndex()),
00267 oldPointsPtr_(NULL)
00268 {
00269 if (debug)
00270 {
00271 Info<<"Constructing polyMesh from cell and boundary shapes." << endl;
00272 }
00273
00274
00275 removeFiles(instance());
00276
00277
00278
00279 label maxFaces = 0;
00280
00281
00282 faceListList cellsFaceShapes(cellsAsShapes.size());
00283 cellList cells(cellsAsShapes.size());
00284
00285 forAll(cellsFaceShapes, cellI)
00286 {
00287 cellsFaceShapes[cellI] = cellsAsShapes[cellI].faces();
00288
00289 cells[cellI].setSize(cellsFaceShapes[cellI].size());
00290
00291
00292 static_cast<labelList&>(cells[cellI]) = -1;
00293
00294
00295 maxFaces += cellsFaceShapes[cellI].size();
00296 }
00297
00298
00299 faces_.setSize(maxFaces);
00300
00301
00302 label nFaces = 0;
00303
00304
00305 labelListList PointCells = cellShapePointCells(cellsAsShapes);
00306
00307 bool found = false;
00308
00309 forAll(cells, cellI)
00310 {
00311
00312
00313
00314
00315
00316
00317 const faceList& curFaces = cellsFaceShapes[cellI];
00318
00319
00320 labelList neiCells(curFaces.size(), -1);
00321
00322
00323 labelList faceOfNeiCell(curFaces.size(), -1);
00324
00325 label nNeighbours = 0;
00326
00327
00328 forAll(curFaces, faceI)
00329 {
00330
00331 if (cells[cellI][faceI] >= 0) continue;
00332
00333 found = false;
00334
00335 const face& curFace = curFaces[faceI];
00336
00337
00338 const labelList& curPoints = curFace;
00339
00340
00341 forAll(curPoints, pointI)
00342 {
00343
00344 const labelList& curNeighbours =
00345 PointCells[curPoints[pointI]];
00346
00347
00348 forAll(curNeighbours, neiI)
00349 {
00350 label curNei = curNeighbours[neiI];
00351
00352
00353 if (curNei > cellI)
00354 {
00355
00356 const faceList& searchFaces = cellsFaceShapes[curNei];
00357
00358 forAll(searchFaces, neiFaceI)
00359 {
00360 if (searchFaces[neiFaceI] == curFace)
00361 {
00362
00363 found = true;
00364
00365
00366 neiCells[faceI] = curNei;
00367 faceOfNeiCell[faceI] = neiFaceI;
00368 nNeighbours++;
00369
00370 break;
00371 }
00372 }
00373 if (found) break;
00374 }
00375 if (found) break;
00376 }
00377 if (found) break;
00378 }
00379 }
00380
00381
00382 for (label neiSearch = 0; neiSearch < nNeighbours; neiSearch++)
00383 {
00384
00385 label nextNei = -1;
00386 label minNei = cells.size();
00387
00388 forAll (neiCells, ncI)
00389 {
00390 if (neiCells[ncI] > -1 && neiCells[ncI] < minNei)
00391 {
00392 nextNei = ncI;
00393 minNei = neiCells[ncI];
00394 }
00395 }
00396
00397 if (nextNei > -1)
00398 {
00399
00400 faces_[nFaces] = curFaces[nextNei];
00401
00402
00403 cells[cellI][nextNei] = nFaces;
00404 cells[neiCells[nextNei]][faceOfNeiCell[nextNei]] = nFaces;
00405
00406
00407 neiCells[nextNei] = -1;
00408
00409
00410 nFaces++;
00411 }
00412 else
00413 {
00414 FatalErrorIn
00415 (
00416 "polyMesh::polyMesh\n"
00417 "(\n"
00418 " const IOobject&,\n"
00419 " const Xfer<pointField>&,\n"
00420 " const cellShapeList& cellsAsShapes,\n"
00421 " const faceListList& boundaryFaces,\n"
00422 " const wordList& boundaryPatchTypes,\n"
00423 " const wordList& boundaryPatchNames,\n"
00424 " const word& defaultBoundaryPatchType\n"
00425 ")"
00426 ) << "Error in internal face insertion"
00427 << abort(FatalError);
00428 }
00429 }
00430 }
00431
00432
00433
00434 labelList patchSizes(boundaryFaces.size(), -1);
00435 labelList patchStarts(boundaryFaces.size(), -1);
00436
00437 forAll (boundaryFaces, patchI)
00438 {
00439 const faceList& patchFaces = boundaryFaces[patchI];
00440
00441 labelList curPatchFaceCells =
00442 facePatchFaceCells
00443 (
00444 patchFaces,
00445 PointCells,
00446 cellsFaceShapes,
00447 patchI
00448 );
00449
00450
00451 label curPatchStart = nFaces;
00452
00453 forAll (patchFaces, faceI)
00454 {
00455 const face& curFace = patchFaces[faceI];
00456
00457 const label cellInside = curPatchFaceCells[faceI];
00458
00459 faces_[nFaces] = curFace;
00460
00461
00462 const faceList& facesOfCellInside = cellsFaceShapes[cellInside];
00463
00464 bool found = false;
00465
00466 forAll (facesOfCellInside, cellFaceI)
00467 {
00468 if (facesOfCellInside[cellFaceI] == curFace)
00469 {
00470 if (cells[cellInside][cellFaceI] >= 0)
00471 {
00472 FatalErrorIn
00473 (
00474 "polyMesh::polyMesh\n"
00475 "(\n"
00476 " const IOobject&,\n"
00477 " const Xfer<pointField>&,\n"
00478 " const cellShapeList& cellsAsShapes,\n"
00479 " const faceListList& boundaryFaces,\n"
00480 " const wordList& boundaryPatchTypes,\n"
00481 " const wordList& boundaryPatchNames,\n"
00482 " const word& defaultBoundaryPatchType\n"
00483 ")"
00484 ) << "Trying to specify a boundary face " << curFace
00485 << " on the face on cell " << cellInside
00486 << " which is either an internal face or already "
00487 << "belongs to some other patch. This is face "
00488 << faceI << " of patch "
00489 << patchI << " named "
00490 << boundaryPatchNames[patchI] << "."
00491 << abort(FatalError);
00492 }
00493
00494 found = true;
00495
00496 cells[cellInside][cellFaceI] = nFaces;
00497
00498 break;
00499 }
00500 }
00501
00502 if (!found)
00503 {
00504 FatalErrorIn("polyMesh::polyMesh(... construct from shapes...)")
00505 << "face " << faceI << " of patch " << patchI
00506 << " does not seem to belong to cell " << cellInside
00507 << " which, according to the addressing, "
00508 << "should be next to it."
00509 << abort(FatalError);
00510 }
00511
00512
00513 nFaces++;
00514 }
00515
00516 patchSizes[patchI] = nFaces - curPatchStart;
00517 patchStarts[patchI] = curPatchStart;
00518 }
00519
00520
00521
00522 label defaultPatchStart = nFaces;
00523
00524 forAll(cells, cellI)
00525 {
00526 labelList& curCellFaces = cells[cellI];
00527
00528 forAll(curCellFaces, faceI)
00529 {
00530 if (curCellFaces[faceI] == -1)
00531 {
00532 curCellFaces[faceI] = nFaces;
00533 faces_[nFaces] = cellsFaceShapes[cellI][faceI];
00534
00535 nFaces++;
00536 }
00537 }
00538 }
00539
00540
00541 faces_.setSize(nFaces);
00542
00543
00544
00545 forAll (boundaryFaces, patchI)
00546 {
00547
00548 boundary_.set
00549 (
00550 patchI,
00551 polyPatch::New
00552 (
00553 boundaryPatchTypes[patchI],
00554 boundaryPatchNames[patchI],
00555 patchSizes[patchI],
00556 patchStarts[patchI],
00557 patchI,
00558 boundary_
00559 )
00560 );
00561
00562 if
00563 (
00564 boundaryPatchPhysicalTypes.size()
00565 && boundaryPatchPhysicalTypes[patchI].size()
00566 )
00567 {
00568 boundary_[patchI].physicalType() =
00569 boundaryPatchPhysicalTypes[patchI];
00570 }
00571 }
00572
00573 label nAllPatches = boundaryFaces.size();
00574
00575 if (nFaces > defaultPatchStart)
00576 {
00577 WarningIn("polyMesh::polyMesh(... construct from shapes...)")
00578 << "Found " << nFaces - defaultPatchStart
00579 << " undefined faces in mesh; adding to default patch." << endl;
00580
00581 boundary_.set
00582 (
00583 nAllPatches,
00584 polyPatch::New
00585 (
00586 defaultBoundaryPatchType,
00587 defaultBoundaryPatchName,
00588 nFaces - defaultPatchStart,
00589 defaultPatchStart,
00590 boundary_.size() - 1,
00591 boundary_
00592 )
00593 );
00594
00595 nAllPatches++;
00596 }
00597
00598
00599 boundary_.setSize(nAllPatches);
00600
00601
00602 initMesh(cells);
00603
00604 if (syncPar)
00605 {
00606
00607 boundary_.updateMesh();
00608
00609
00610 boundary_.calcGeometry();
00611 }
00612
00613 if (debug)
00614 {
00615 if (checkMesh())
00616 {
00617 Info << "Mesh OK" << endl;
00618 }
00619 }
00620 }
00621
00622
00623