OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

meshRefinementProblemCells.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*----------------------------------------------------------------------------*/
00026 
00027 #include "meshRefinement.H"
00028 #include "fvMesh.H"
00029 #include "syncTools.H"
00030 #include "Time.H"
00031 #include "refinementSurfaces.H"
00032 #include "pointSet.H"
00033 #include "faceSet.H"
00034 #include "indirectPrimitivePatch.H"
00035 #include "OFstream.H"
00036 #include "cellSet.H"
00037 #include "searchableSurfaces.H"
00038 #include "polyMeshGeometry.H"
00039 #include "IOmanip.H"
00040 
00041 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00042 
00043 void Foam::meshRefinement::markBoundaryFace
00044 (
00045     const label faceI,
00046     boolList& isBoundaryFace,
00047     boolList& isBoundaryEdge,
00048     boolList& isBoundaryPoint
00049 ) const
00050 {
00051     isBoundaryFace[faceI] = true;
00052 
00053     const labelList& fEdges = mesh_.faceEdges(faceI);
00054 
00055     forAll(fEdges, fp)
00056     {
00057         isBoundaryEdge[fEdges[fp]] = true;
00058     }
00059 
00060     const face& f = mesh_.faces()[faceI];
00061 
00062     forAll(f, fp)
00063     {
00064         isBoundaryPoint[f[fp]] = true;
00065     }
00066 }
00067 
00068 
00069 void Foam::meshRefinement::findNearest
00070 (
00071     const labelList& meshFaces,
00072     List<pointIndexHit>& nearestInfo,
00073     labelList& nearestSurface,
00074     labelList& nearestRegion,
00075     vectorField& nearestNormal
00076 ) const
00077 {
00078     pointField fc(meshFaces.size());
00079     forAll(meshFaces, i)
00080     {
00081         fc[i] = mesh_.faceCentres()[meshFaces[i]];
00082     }
00083 
00084     const labelList allSurfaces(identity(surfaces_.surfaces().size()));
00085 
00086     surfaces_.findNearest
00087     (
00088         allSurfaces,
00089         fc,
00090         scalarField(fc.size(), sqr(GREAT)),    // sqr of attraction
00091         nearestSurface,
00092         nearestInfo
00093     );
00094 
00095     // Do normal testing per surface.
00096     nearestNormal.setSize(nearestInfo.size());
00097     nearestRegion.setSize(nearestInfo.size());
00098 
00099     forAll(allSurfaces, surfI)
00100     {
00101         DynamicList<pointIndexHit> localHits;
00102 
00103         forAll(nearestSurface, i)
00104         {
00105             if (nearestSurface[i] == surfI)
00106             {
00107                 localHits.append(nearestInfo[i]);
00108             }
00109         }
00110 
00111         label geomI = surfaces_.surfaces()[surfI];
00112 
00113         pointField localNormals;
00114         surfaces_.geometry()[geomI].getNormal(localHits, localNormals);
00115 
00116         labelList localRegion;
00117         surfaces_.geometry()[geomI].getRegion(localHits, localRegion);
00118 
00119         label localI = 0;
00120         forAll(nearestSurface, i)
00121         {
00122             if (nearestSurface[i] == surfI)
00123             {
00124                 nearestNormal[i] = localNormals[localI];
00125                 nearestRegion[i] = localRegion[localI];
00126                 localI++;
00127             }
00128         }
00129     }
00130 }
00131 
00132 
00133 Foam::Map<Foam::label> Foam::meshRefinement::findEdgeConnectedProblemCells
00134 (
00135     const scalarField& perpendicularAngle,
00136     const labelList& globalToPatch
00137 ) const
00138 {
00139     // Construct addressing engine from all patches added for meshing.
00140     autoPtr<indirectPrimitivePatch> ppPtr
00141     (
00142         meshRefinement::makePatch
00143         (
00144             mesh_,
00145             meshedPatches()
00146         )
00147     );
00148     const indirectPrimitivePatch& pp = ppPtr();
00149 
00150 
00151     // 1. Collect faces to test
00152     // ~~~~~~~~~~~~~~~~~~~~~~~~
00153 
00154     DynamicList<label> candidateFaces(pp.size()/20);
00155 
00156     const labelListList& edgeFaces = pp.edgeFaces();
00157 
00158     const labelList& cellLevel = meshCutter_.cellLevel();
00159 
00160     forAll(edgeFaces, edgeI)
00161     {
00162         const labelList& eFaces = edgeFaces[edgeI];
00163 
00164         if (eFaces.size() == 2)
00165         {
00166             label face0 = pp.addressing()[eFaces[0]];
00167             label face1 = pp.addressing()[eFaces[1]];
00168 
00169             label cell0 = mesh_.faceOwner()[face0];
00170             label cell1 = mesh_.faceOwner()[face1];
00171 
00172             if (cellLevel[cell0] > cellLevel[cell1])
00173             {
00174                 // cell0 smaller.
00175                 const vector& n0 = pp.faceNormals()[eFaces[0]];
00176                 const vector& n1 = pp.faceNormals()[eFaces[1]];
00177 
00178                 if (mag(n0 & n1) < 0.1)
00179                 {
00180                     candidateFaces.append(face0);
00181                 }
00182             }
00183             else if (cellLevel[cell1] > cellLevel[cell0])
00184             {
00185                 // cell1 smaller.
00186                 const vector& n0 = pp.faceNormals()[eFaces[0]];
00187                 const vector& n1 = pp.faceNormals()[eFaces[1]];
00188 
00189                 if (mag(n0 & n1) < 0.1)
00190                 {
00191                     candidateFaces.append(face1);
00192                 }
00193             }
00194         }
00195     }
00196     candidateFaces.shrink();
00197 
00198     Info<< "Testing " << returnReduce(candidateFaces.size(), sumOp<label>())
00199         << " faces on edge-connected cells of differing level."
00200         << endl;
00201 
00202     if (debug)
00203     {
00204         faceSet fSet(mesh_, "edgeConnectedFaces", candidateFaces);
00205         Pout<< "Writing " << fSet.size()
00206             << " with problematic topology to faceSet "
00207             << fSet.objectPath() << endl;
00208         fSet.write();
00209     }
00210 
00211 
00212     // 2. Find nearest surface on candidate faces
00213     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00214 
00215     List<pointIndexHit> nearestInfo;
00216     labelList nearestSurface;
00217     labelList nearestRegion;
00218     vectorField nearestNormal;
00219     findNearest
00220     (
00221         candidateFaces,
00222         nearestInfo,
00223         nearestSurface,
00224         nearestRegion,
00225         nearestNormal
00226     );
00227 
00228 
00229     // 3. Test angle to surface
00230     // ~~~~~~~~~~~~~~~~~~~~~~~~
00231 
00232     Map<label> candidateCells(candidateFaces.size());
00233 
00234     faceSet perpFaces(mesh_, "perpendicularFaces", pp.size()/100);
00235 
00236     forAll(candidateFaces, i)
00237     {
00238         label faceI = candidateFaces[i];
00239 
00240         vector n = mesh_.faceAreas()[faceI];
00241         n /= mag(n);
00242 
00243         label region = surfaces_.globalRegion
00244         (
00245             nearestSurface[i],
00246             nearestRegion[i]
00247         );
00248 
00249         scalar angle =
00250             perpendicularAngle[region]
00251           / 180.0
00252           * mathematicalConstant::pi;
00253 
00254         if (angle >= 0)
00255         {
00256             if (mag(n & nearestNormal[i]) < Foam::sin(angle))
00257             {
00258                 perpFaces.insert(faceI);
00259                 candidateCells.insert
00260                 (
00261                     mesh_.faceOwner()[faceI],
00262                     globalToPatch[region]
00263                 );
00264             }
00265         }
00266     }
00267 
00268     if (debug)
00269     {
00270         Pout<< "Writing " << perpFaces.size()
00271             << " faces that are perpendicular to the surface to set "
00272             << perpFaces.objectPath() << endl;
00273         perpFaces.write();
00274     }
00275     return candidateCells;
00276 }
00277 
00278 
00279 // Check if moving face to new points causes a 'collapsed' face.
00280 // Uses new point position only for the face, not the neighbouring
00281 // cell centres
00282 bool Foam::meshRefinement::isCollapsedFace
00283 (
00284     const pointField& points,
00285     const pointField& neiCc,
00286     const scalar minFaceArea,
00287     const scalar maxNonOrtho,
00288     const label faceI
00289 ) const
00290 {
00291     vector s = mesh_.faces()[faceI].normal(points);
00292     scalar magS = mag(s);
00293 
00294     // Check face area
00295     if (magS < minFaceArea)
00296     {
00297         return true;
00298     }
00299 
00300     // Check orthogonality
00301     const point& ownCc = mesh_.cellCentres()[mesh_.faceOwner()[faceI]];
00302 
00303     if (mesh_.isInternalFace(faceI))
00304     {
00305         label nei = mesh_.faceNeighbour()[faceI];
00306         vector d = ownCc - mesh_.cellCentres()[nei];
00307 
00308         scalar dDotS = (d & s)/(mag(d)*magS + VSMALL);
00309         
00310         if (dDotS < maxNonOrtho)
00311         {
00312             return true;
00313         }
00314         else
00315         {
00316             return false;
00317         }
00318     }
00319     else
00320     {
00321         label patchI = mesh_.boundaryMesh().whichPatch(faceI);
00322 
00323         if (mesh_.boundaryMesh()[patchI].coupled())
00324         {
00325             vector d = ownCc - neiCc[faceI-mesh_.nInternalFaces()];
00326 
00327             scalar dDotS = (d & s)/(mag(d)*magS + VSMALL);
00328 
00329             if (dDotS < maxNonOrtho)
00330             {
00331                 return true;
00332             }
00333             else
00334             {
00335                 return false;
00336             }
00337         }
00338         else
00339         {
00340             // Collapsing normal boundary face does not cause problems with
00341             // non-orthogonality
00342             return true;
00343         }
00344     }
00345 }
00346 
00347 
00348 // Check if moving cell to new points causes it to collapse.
00349 bool Foam::meshRefinement::isCollapsedCell
00350 (
00351     const pointField& points,
00352     const scalar volFraction,
00353     const label cellI
00354 ) const
00355 {
00356     scalar vol = mesh_.cells()[cellI].mag(points, mesh_.faces());
00357 
00358     if (vol/mesh_.cellVolumes()[cellI] < volFraction)
00359     {
00360         return true;
00361     }
00362     else
00363     {
00364         return false;
00365     }
00366 }
00367 
00368 
00369 // Returns list with for every internal face -1 or the patch they should
00370 // be baffled into. Gets run after createBaffles so all the unzoned surface
00371 // intersections have already been turned into baffles. (Note: zoned surfaces
00372 // are not baffled at this stage)
00373 // Used to remove cells by baffling all their faces and have the
00374 // splitMeshRegions chuck away non used regions.
00375 Foam::labelList Foam::meshRefinement::markFacesOnProblemCells
00376 (
00377     const dictionary& motionDict,
00378     const bool removeEdgeConnectedCells,
00379     const scalarField& perpendicularAngle,
00380     const labelList& globalToPatch
00381 ) const
00382 {
00383     const labelList& cellLevel = meshCutter_.cellLevel();
00384     const labelList& pointLevel = meshCutter_.pointLevel();
00385     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00386 
00387     // Per internal face (boundary faces not used) the patch that the
00388     // baffle should get (or -1)
00389     labelList facePatch(mesh_.nFaces(), -1);
00390 
00391     // Mark all points and edges on baffle patches (so not on any inlets,
00392     // outlets etc.)
00393     boolList isBoundaryPoint(mesh_.nPoints(), false);
00394     boolList isBoundaryEdge(mesh_.nEdges(), false);
00395     boolList isBoundaryFace(mesh_.nFaces(), false);
00396 
00397     // Fill boundary data. All elements on meshed patches get marked.
00398     // Get the labels of added patches.
00399     labelList adaptPatchIDs(meshedPatches());
00400 
00401     forAll(adaptPatchIDs, i)
00402     {
00403         label patchI = adaptPatchIDs[i];
00404 
00405         const polyPatch& pp = patches[patchI];
00406 
00407         label faceI = pp.start();
00408 
00409         forAll(pp, j)
00410         {
00411             markBoundaryFace
00412             (
00413                 faceI,
00414                 isBoundaryFace,
00415                 isBoundaryEdge,
00416                 isBoundaryPoint
00417             );
00418 
00419             faceI++;
00420         }
00421     }
00422 
00423     // Swap neighbouring cell centres and cell level
00424     labelList neiLevel(mesh_.nFaces()-mesh_.nInternalFaces());
00425     pointField neiCc(mesh_.nFaces()-mesh_.nInternalFaces());
00426     calcNeighbourData(neiLevel, neiCc);
00427 
00428 
00429     // Count of faces marked for baffling
00430     label nBaffleFaces = 0;
00431 
00432     // Count of faces not baffled since would not cause a collapse
00433     label nPrevented = 0;
00434 
00435     if (removeEdgeConnectedCells && max(perpendicularAngle) >= 0)
00436     {
00437         Info<< "markFacesOnProblemCells :"
00438             << " Checking for edge-connected cells of highly differing sizes."
00439             << endl;
00440 
00441         // Pick up the cells that need to be removed and (a guess for)
00442         // the patch they should be patched with.
00443         Map<label> problemCells
00444         (
00445             findEdgeConnectedProblemCells
00446             (
00447                 perpendicularAngle,
00448                 globalToPatch
00449             )
00450         );
00451 
00452         // Baffle all faces of cells that need to be removed
00453         forAllConstIter(Map<label>, problemCells, iter)
00454         {
00455             const cell& cFaces = mesh_.cells()[iter.key()];
00456 
00457             forAll(cFaces, i)
00458             {
00459                 label faceI = cFaces[i];
00460 
00461                 if (facePatch[faceI] == -1 && mesh_.isInternalFace(faceI))
00462                 {
00463                     facePatch[faceI] = getBafflePatch(facePatch, faceI);
00464                     nBaffleFaces++;
00465 
00466                     // Mark face as a 'boundary'
00467                     markBoundaryFace
00468                     (
00469                         faceI,
00470                         isBoundaryFace,
00471                         isBoundaryEdge,
00472                         isBoundaryPoint
00473                     );
00474                 }
00475             }
00476         }
00477         Info<< "markFacesOnProblemCells : Marked "
00478             << returnReduce(nBaffleFaces, sumOp<label>())
00479             << " additional internal faces to be converted into baffles"
00480             << " due to "
00481             << returnReduce(problemCells.size(), sumOp<label>())
00482             << " cells edge-connected to lower level cells." << endl;
00483 
00484         if (debug)
00485         {
00486             cellSet problemCellSet(mesh_, "problemCells", problemCells.toc());
00487             Pout<< "Writing " << problemCellSet.size()
00488                 << " cells that are edge connected to coarser cell to set "
00489                 << problemCellSet.objectPath() << endl;
00490             problemCellSet.write();
00491         }
00492     }
00493 
00494     syncTools::syncPointList
00495     (
00496         mesh_,
00497         isBoundaryPoint,
00498         orEqOp<bool>(),
00499         false,              // null value
00500         false               // no separation
00501     );
00502 
00503     syncTools::syncEdgeList
00504     (
00505         mesh_,
00506         isBoundaryEdge,
00507         orEqOp<bool>(),
00508         false,              // null value
00509         false               // no separation
00510     );
00511 
00512     syncTools::syncFaceList
00513     (
00514         mesh_,
00515         isBoundaryFace,
00516         orEqOp<bool>(),
00517         false               // no separation
00518     );
00519 
00520 
00521     // See if checking for collapse
00522     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00523 
00524     // Collapse checking parameters
00525     scalar volFraction = -1;
00526     if (motionDict.found("minVolCollapseRatio"))
00527     {
00528         volFraction = readScalar(motionDict.lookup("minVolCollapseRatio"));
00529     }
00530     const bool checkCollapse = (volFraction > 0);
00531     scalar minArea = -1;
00532     scalar maxNonOrtho = -1;
00533 
00534 
00535     // Find nearest (non-baffle) surface
00536     pointField newPoints;
00537 
00538     if (checkCollapse)
00539     {
00540         minArea = readScalar(motionDict.lookup("minArea"));
00541         maxNonOrtho = readScalar(motionDict.lookup("maxNonOrtho"));
00542 
00543         Info<< "markFacesOnProblemCells :"
00544             << " Deleting all-anchor surface cells only if"
00545             << "snapping them violates mesh quality constraints:" << nl
00546             << "    snapped/original cell volume < " << volFraction << nl
00547             << "    face area                    < " << minArea << nl
00548             << "    non-orthogonality            > " << maxNonOrtho << nl
00549             << endl;
00550 
00551         // Construct addressing engine.
00552         autoPtr<indirectPrimitivePatch> ppPtr
00553         (
00554             meshRefinement::makePatch
00555             (
00556                 mesh_,
00557                 adaptPatchIDs
00558             )
00559         );
00560         const indirectPrimitivePatch& pp = ppPtr();
00561         const pointField& localPoints = pp.localPoints();
00562         const labelList& meshPoints = pp.meshPoints();
00563 
00564         List<pointIndexHit> hitInfo;
00565         labelList hitSurface;
00566         surfaces_.findNearest
00567         (
00568             surfaces_.getUnnamedSurfaces(),
00569             localPoints,
00570             scalarField(localPoints.size(), sqr(GREAT)),    // sqr of attraction
00571             hitSurface,
00572             hitInfo
00573         );
00574 
00575         // Start of from current points
00576         newPoints = mesh_.points();
00577 
00578         forAll(hitInfo, i)
00579         {
00580             if (hitInfo[i].hit())
00581             {
00582                 newPoints[meshPoints[i]] = hitInfo[i].hitPoint();
00583             }
00584         }
00585     }
00586 
00587 
00588 
00589     // For each cell count the number of anchor points that are on
00590     // the boundary:
00591     // 8 : check the number of (baffle) boundary faces. If 3 or more block
00592     //     off the cell since the cell would get squeezed down to a diamond
00593     //     (probably; if the 3 or more faces are unrefined (only use the
00594     //      anchor points))
00595     // 7 : store. Used to check later on whether there are points with
00596     //     3 or more of these cells. (note that on a flat surface a boundary
00597     //     point will only have 4 cells connected to it)
00598 
00599 
00600     // Does cell have exactly 7 of its 8 anchor points on the boundary?
00601     PackedBoolList hasSevenBoundaryAnchorPoints(mesh_.nCells());
00602     // If so what is the remaining non-boundary anchor point?
00603     labelHashSet nonBoundaryAnchors(mesh_.nCells()/10000);
00604 
00605     // On-the-fly addressing storage.
00606     DynamicList<label> dynFEdges;
00607     DynamicList<label> dynCPoints;
00608 
00609     forAll(cellLevel, cellI)
00610     {
00611         const labelList& cPoints = mesh_.cellPoints(cellI, dynCPoints);
00612 
00613         // Get number of anchor points (pointLevel <= cellLevel)
00614 
00615         label nBoundaryAnchors = 0;
00616         label nNonAnchorBoundary = 0;
00617         label nonBoundaryAnchor = -1;
00618 
00619         forAll(cPoints, i)
00620         {
00621             label pointI = cPoints[i];
00622 
00623             if (pointLevel[pointI] <= cellLevel[cellI])
00624             {
00625                 // Anchor point
00626                 if (isBoundaryPoint[pointI])
00627                 {
00628                     nBoundaryAnchors++;
00629                 }
00630                 else
00631                 {
00632                     // Anchor point which is not on the surface
00633                     nonBoundaryAnchor = pointI;
00634                 }
00635             }
00636             else if (isBoundaryPoint[pointI])
00637             {
00638                 nNonAnchorBoundary++;
00639             }
00640         }
00641 
00642         if (nBoundaryAnchors == 8)
00643         {
00644             const cell& cFaces = mesh_.cells()[cellI];
00645 
00646             // Count boundary faces.
00647             label nBfaces = 0;
00648 
00649             forAll(cFaces, cFaceI)
00650             {
00651                 if (isBoundaryFace[cFaces[cFaceI]])
00652                 {
00653                     nBfaces++;
00654                 }
00655             }
00656 
00657             // If nBfaces > 1 make all non-boundary non-baffle faces baffles.
00658             // We assume that this situation is where there is a single
00659             // cell sticking out which would get flattened.
00660 
00661             // Eugene: delete cell no matter what.
00662             //if (nBfaces > 1)
00663             {
00664                 if
00665                 (
00666                     checkCollapse
00667                 && !isCollapsedCell(newPoints, volFraction, cellI)
00668                 )
00669                 {
00670                     nPrevented++;
00671                     //Pout<< "Preventing collapse of 8 anchor point cell "
00672                     //    << cellI << " at " << mesh_.cellCentres()[cellI]
00673                     //    << " since new volume "
00674                     //    << mesh_.cells()[cellI].mag(newPoints, mesh_.faces())
00675                     //    << " old volume " << mesh_.cellVolumes()[cellI]
00676                     //    << endl;
00677                 }
00678                 else
00679                 {
00680                     // Block all faces of cell
00681                     forAll(cFaces, cf)
00682                     {
00683                         label faceI = cFaces[cf];
00684 
00685                         if
00686                         (
00687                             facePatch[faceI] == -1
00688                          && mesh_.isInternalFace(faceI)
00689                         )
00690                         {
00691                             facePatch[faceI] = getBafflePatch(facePatch, faceI);
00692                             nBaffleFaces++;
00693 
00694                             // Mark face as a 'boundary'
00695                             markBoundaryFace
00696                             (
00697                                 faceI,
00698                                 isBoundaryFace,
00699                                 isBoundaryEdge,
00700                                 isBoundaryPoint
00701                             );
00702                         }
00703                     }
00704                 }
00705             }
00706         }
00707         else if (nBoundaryAnchors == 7)
00708         {
00709             // Mark the cell. Store the (single!) non-boundary anchor point.
00710             hasSevenBoundaryAnchorPoints.set(cellI, 1u);
00711             nonBoundaryAnchors.insert(nonBoundaryAnchor);
00712         }
00713     }
00714 
00715 
00716     // Loop over all points. If a point is connected to 4 or more cells
00717     // with 7 anchor points on the boundary set those cell's non-boundary faces
00718     // to baffles
00719 
00720     DynamicList<label> dynPCells;
00721 
00722     forAllConstIter(labelHashSet, nonBoundaryAnchors, iter)
00723     {
00724         label pointI = iter.key();
00725 
00726         const labelList& pCells = mesh_.pointCells(pointI, dynPCells);
00727 
00728         // Count number of 'hasSevenBoundaryAnchorPoints' cells.
00729         label n = 0;
00730 
00731         forAll(pCells, i)
00732         {
00733             if (hasSevenBoundaryAnchorPoints.get(pCells[i]) == 1u)
00734             {
00735                 n++;
00736             }
00737         }
00738 
00739         if (n > 3)
00740         {
00741             // Point in danger of being what? Remove all 7-cells.
00742             forAll(pCells, i)
00743             {
00744                 label cellI = pCells[i];
00745 
00746                 if (hasSevenBoundaryAnchorPoints.get(cellI) == 1u)
00747                 {
00748                     if
00749                     (
00750                         checkCollapse
00751                     && !isCollapsedCell(newPoints, volFraction, cellI)
00752                     )
00753                     {
00754                         nPrevented++;
00755                         //Pout<< "Preventing collapse of 7 anchor cell "
00756                         //    << cellI
00757                         //    << " at " << mesh_.cellCentres()[cellI]
00758                         //    << " since new volume "
00759                         //    << mesh_.cells()[cellI].mag
00760                         //        (newPoints, mesh_.faces())
00761                         //    << " old volume " << mesh_.cellVolumes()[cellI]
00762                         //    << endl;
00763                     }
00764                     else
00765                     {
00766                         const cell& cFaces = mesh_.cells()[cellI];
00767 
00768                         forAll(cFaces, cf)
00769                         {
00770                             label faceI = cFaces[cf];
00771 
00772                             if
00773                             (
00774                                 facePatch[faceI] == -1
00775                              && mesh_.isInternalFace(faceI)
00776                             )
00777                             {
00778                                 facePatch[faceI] = getBafflePatch
00779                                 (
00780                                     facePatch,
00781                                     faceI
00782                                 );
00783                                 nBaffleFaces++;
00784 
00785                                 // Mark face as a 'boundary'
00786                                 markBoundaryFace
00787                                 (
00788                                     faceI,
00789                                     isBoundaryFace,
00790                                     isBoundaryEdge,
00791                                     isBoundaryPoint
00792                                 );
00793                             }
00794                         }
00795                     }
00796                 }
00797             }
00798         }
00799     }
00800 
00801 
00802     // Sync all. (note that pointdata and facedata not used anymore but sync
00803     // anyway)
00804 
00805     syncTools::syncPointList
00806     (
00807         mesh_,
00808         isBoundaryPoint,
00809         orEqOp<bool>(),
00810         false,              // null value
00811         false               // no separation
00812     );
00813 
00814     syncTools::syncEdgeList
00815     (
00816         mesh_,
00817         isBoundaryEdge,
00818         orEqOp<bool>(),
00819         false,              // null value
00820         false               // no separation
00821     );
00822 
00823     syncTools::syncFaceList
00824     (
00825         mesh_,
00826         isBoundaryFace,
00827         orEqOp<bool>(),
00828         false               // no separation
00829     );
00830 
00831 
00832     // Find faces with all edges on the boundary and make them baffles
00833     for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
00834     {
00835         if (facePatch[faceI] == -1)
00836         {
00837             const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
00838             label nFaceBoundaryEdges = 0;
00839 
00840             forAll(fEdges, fe)
00841             {
00842                 if (isBoundaryEdge[fEdges[fe]])
00843                 {
00844                     nFaceBoundaryEdges++;
00845                 }
00846             }
00847 
00848             if (nFaceBoundaryEdges == fEdges.size())
00849             {
00850                 if
00851                 (
00852                     checkCollapse
00853                 && !isCollapsedFace
00854                     (
00855                         newPoints,
00856                         neiCc,
00857                         minArea,
00858                         maxNonOrtho,
00859                         faceI
00860                     )
00861                 )
00862                 {
00863                     nPrevented++;
00864                     //Pout<< "Preventing collapse of face " << faceI
00865                     //    << " with all boundary edges "
00866                     //    << " at " << mesh_.faceCentres()[faceI]
00867                     //    << endl;
00868                 }
00869                 else
00870                 {
00871                     facePatch[faceI] = getBafflePatch(facePatch, faceI);
00872                     nBaffleFaces++;
00873 
00874                     // Do NOT update boundary data since this would grow blocked
00875                     // faces across gaps.
00876                 }
00877             }
00878         }
00879     }
00880 
00881     forAll(patches, patchI)
00882     {
00883         const polyPatch& pp = patches[patchI];
00884 
00885         if (pp.coupled())
00886         {
00887             label faceI = pp.start();
00888 
00889             forAll(pp, i)
00890             {
00891                 if (facePatch[faceI] == -1)
00892                 {
00893                     const labelList& fEdges = mesh_.faceEdges(faceI, dynFEdges);
00894                     label nFaceBoundaryEdges = 0;
00895 
00896                     forAll(fEdges, fe)
00897                     {
00898                         if (isBoundaryEdge[fEdges[fe]])
00899                         {
00900                             nFaceBoundaryEdges++;
00901                         }
00902                     }
00903 
00904                     if (nFaceBoundaryEdges == fEdges.size())
00905                     {
00906                         if
00907                         (
00908                             checkCollapse
00909                         && !isCollapsedFace
00910                             (
00911                                 newPoints,
00912                                 neiCc,
00913                                 minArea,
00914                                 maxNonOrtho,
00915                                 faceI
00916                             )
00917                         )
00918                         {
00919                             nPrevented++;
00920                             //Pout<< "Preventing collapse of coupled face "
00921                             //    << faceI
00922                             //    << " with all boundary edges "
00923                             //    << " at " << mesh_.faceCentres()[faceI]
00924                             //    << endl;
00925                         }
00926                         else
00927                         {
00928                             facePatch[faceI] = getBafflePatch(facePatch, faceI);
00929                             nBaffleFaces++;
00930 
00931                             // Do NOT update boundary data since this would grow
00932                             // blocked faces across gaps.
00933                         }
00934                     }
00935                 }
00936 
00937                 faceI++;
00938             }
00939         }
00940     }
00941 
00942     Info<< "markFacesOnProblemCells : marked "
00943         << returnReduce(nBaffleFaces, sumOp<label>())
00944         << " additional internal faces to be converted into baffles."
00945         << endl;
00946 
00947     if (checkCollapse)
00948     {
00949         Info<< "markFacesOnProblemCells : prevented "
00950             << returnReduce(nPrevented, sumOp<label>())
00951             << " internal faces fom getting converted into baffles."
00952             << endl;
00953     }
00954 
00955     return facePatch;
00956 }
00957 
00958 
00961 //Foam::labelList Foam::meshRefinement::markFacesOnProblemCellsGeometric
00962 //(
00963 //    const dictionary& motionDict
00964 //) const
00965 //{
00966 //    // Construct addressing engine.
00967 //    autoPtr<indirectPrimitivePatch> ppPtr
00968 //    (
00969 //        meshRefinement::makePatch
00970 //        (
00971 //            mesh_,
00972 //            meshedPatches()
00973 //        )
00974 //    );
00975 //    const indirectPrimitivePatch& pp = ppPtr();
00976 //    const pointField& localPoints = pp.localPoints();
00977 //    const labelList& meshPoints = pp.meshPoints();
00978 //
00979 //    // Find nearest (non-baffle) surface
00980 //    pointField newPoints(mesh_.points());
00981 //    {
00982 //        List<pointIndexHit> hitInfo;
00983 //        labelList hitSurface;
00984 //        surfaces_.findNearest
00985 //        (
00986 //            surfaces_.getUnnamedSurfaces(),
00987 //            localPoints,
00988 //            scalarField(localPoints.size(), sqr(GREAT)),// sqr of attraction
00989 //            hitSurface,
00990 //            hitInfo
00991 //        );
00992 //
00993 //        forAll(hitInfo, i)
00994 //        {
00995 //            if (hitInfo[i].hit())
00996 //            {
00997 //                //label pointI = meshPoints[i];
00998 //                //Pout<< "   " << pointI << " moved from "
00999 //                //    << mesh_.points()[pointI] << " by "
01000 //                //    << mag(hitInfo[i].hitPoint()-mesh_.points()[pointI])
01001 //                //    << endl;
01002 //                newPoints[meshPoints[i]] = hitInfo[i].hitPoint();
01003 //            }
01004 //        }
01005 //    }
01006 //
01007 //    // Per face (internal or coupled!) the patch that the
01008 //    // baffle should get (or -1).
01009 //    labelList facePatch(mesh_.nFaces(), -1);
01010 //    // Count of baffled faces
01011 //    label nBaffleFaces = 0;
01012 //
01013 //    {
01014 //        pointField oldPoints(mesh_.points());
01015 //        mesh_.movePoints(newPoints);
01016 //        faceSet wrongFaces(mesh_, "wrongFaces", 100);
01017 //        {
01018 //            //motionSmoother::checkMesh(false, mesh_, motionDict, wrongFaces);
01019 //
01020 //            // Just check the errors from squashing
01021 //            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
01022 //
01023 //            const labelList allFaces(identity(mesh_.nFaces()));
01024 //            label nWrongFaces = 0;
01025 //
01026 //            scalar minArea(readScalar(motionDict.lookup("minArea")));
01027 //            if (minArea > -SMALL)
01028 //            {
01029 //                polyMeshGeometry::checkFaceArea
01030 //                (
01031 //                    false,
01032 //                    minArea,
01033 //                    mesh_,
01034 //                    mesh_.faceAreas(),
01035 //                    allFaces,
01036 //                    &wrongFaces
01037 //                );
01038 //
01039 //                label nNewWrongFaces = returnReduce
01040 //                (
01041 //                    wrongFaces.size(),
01042 //                    sumOp<label>()
01043 //                );
01044 //
01045 //                Info<< "    faces with area < "
01046 //                    << setw(5) << minArea
01047 //                    << " m^2                            : "
01048 //                    << nNewWrongFaces-nWrongFaces << endl;
01049 //
01050 //                nWrongFaces = nNewWrongFaces;
01051 //            }
01052 //
01054 //            scalar minDet = 0.01;
01055 //            if (minDet > -1)
01056 //            {
01057 //                polyMeshGeometry::checkCellDeterminant
01058 //                (
01059 //                    false,
01060 //                    minDet,
01061 //                    mesh_,
01062 //                    mesh_.faceAreas(),
01063 //                    allFaces,
01064 //                    polyMeshGeometry::affectedCells(mesh_, allFaces),
01065 //                    &wrongFaces
01066 //                );
01067 //
01068 //                label nNewWrongFaces = returnReduce
01069 //                (
01070 //                    wrongFaces.size(),
01071 //                    sumOp<label>()
01072 //                );
01073 //
01074 //                Info<< "    faces on cells with determinant < "
01075 //                    << setw(5) << minDet << "                : "
01076 //                    << nNewWrongFaces-nWrongFaces << endl;
01077 //
01078 //                nWrongFaces = nNewWrongFaces;
01079 //            }
01080 //        }
01081 //
01082 //
01083 //        forAllConstIter(faceSet, wrongFaces, iter)
01084 //        {
01085 //            label patchI = mesh_.boundaryMesh().whichPatch(iter.key());
01086 //
01087 //            if (patchI == -1 || mesh_.boundaryMesh()[patchI].coupled())
01088 //            {
01089 //                facePatch[iter.key()] = getBafflePatch(facePatch, iter.key());
01090 //                nBaffleFaces++;
01091 //
01092 //                //Pout<< "    " << iter.key()
01093 //                //    //<< " on patch " << mesh_.boundaryMesh()[patchI].name()
01094 //                //    << " is destined for patch " << facePatch[iter.key()]
01095 //                //    << endl;
01096 //            }
01097 //        }
01098 //        // Restore points.
01099 //        mesh_.movePoints(oldPoints);
01100 //    }
01101 //
01102 //
01103 //    Info<< "markFacesOnProblemCellsGeometric : marked "
01104 //        << returnReduce(nBaffleFaces, sumOp<label>())
01105 //        << " additional internal and coupled faces"
01106 //        << " to be converted into baffles." << endl;
01107 //
01108 //    syncTools::syncFaceList
01109 //    (
01110 //        mesh_,
01111 //        facePatch,
01112 //        maxEqOp<label>(),
01113 //        false               // no separation
01114 //    );
01115 //
01116 //    return facePatch;
01117 //}
01118 
01119 
01120 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd