|
|
|
surfaceSets.CGo 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 Description 00026 00027 \*---------------------------------------------------------------------------*/ 00028 00029 #include "surfaceSets.H" 00030 #include "polyMesh.H" 00031 #include "triSurface.H" 00032 #include "triSurfaceSearch.H" 00033 #include "pointSet.H" 00034 #include "cellSet.H" 00035 #include "surfaceToCell.H" 00036 #include "cellToPoint.H" 00037 #include "cellToCell.H" 00038 #include "pointToCell.H" 00039 #include "meshSearch.H" 00040 #include "cellClassification.H" 00041 00042 00043 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // 00044 00045 00046 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // 00047 00048 //Foam::scalar Foam::surfaceSets::minEdgeLen 00049 //( 00050 // const primitiveMesh& mesh, 00051 // const label pointI 00052 //) 00053 //{ 00054 // const edgeList& edges = mesh.edges(); 00055 // 00056 // const pointField& points = mesh.points(); 00057 // 00058 // const labelList& pEdges = mesh.pointEdges()[pointI]; 00059 // 00060 // scalar minLen = GREAT; 00061 // 00062 // forAll(pEdges, i) 00063 // { 00064 // minLen = min(minLen, edges[pEdges[i]].mag(points)); 00065 // } 00066 // return minLen; 00067 //} 00068 // 00069 // 00071 //bool Foam::surfaceSets::usesPoint 00072 //( 00073 // const primitiveMesh& mesh, 00074 // const boolList& selectedPoint, 00075 // const label cellI 00076 //) 00077 //{ 00078 // const labelList& cFaces = mesh.cells()[cellI]; 00079 // 00080 // forAll(cFaces, cFaceI) 00081 // { 00082 // label faceI = cFaces[cFaceI]; 00083 // 00084 // const face& f = mesh.faces()[faceI]; 00085 // 00086 // forAll(f, fp) 00087 // { 00088 // if (selectedPoint[f[fp]]) 00089 // { 00090 // return true; 00091 // } 00092 // } 00093 // } 00094 // return false; 00095 //} 00096 00097 00098 00102 //Foam::label Foam::surfaceSets::removeHangingCells 00103 //( 00104 // const primitiveMesh& mesh, 00105 // const triSurfaceSearch& querySurf, 00106 // labelHashSet& internalCells 00107 //) 00108 //{ 00109 // const pointField& points = mesh.points(); 00110 // const cellList& cells = mesh.cells(); 00111 // const faceList& faces = mesh.faces(); 00112 // 00113 // // Determine cells that have all points on the boundary. 00114 // labelHashSet flatCandidates(getHangingCells(mesh, internalCells)); 00115 // 00116 // // All boundary points will become visible after subsetting and will be 00117 // // snapped 00118 // // to surface. Calculate new volume for cells using only these points and 00119 // // check if it does not become too small. 00120 // 00121 // // Get points used by flatCandidates. 00122 // labelHashSet outsidePoints(flatCandidates.size()); 00123 // 00124 // // Snap outside points to surface 00125 // pointField newPoints(points); 00126 // 00127 // for 00128 // ( 00129 // labelHashSet::const_iterator iter = flatCandidates.begin(); 00130 // iter != flatCandidates.end(); 00131 // ++iter 00132 // ) 00133 // { 00134 // const cell& cFaces = cells[iter.key()]; 00135 // 00136 // forAll(cFaces, cFaceI) 00137 // { 00138 // const face& f = faces[cFaces[cFaceI]]; 00139 // 00140 // forAll(f, fp) 00141 // { 00142 // label pointI = f[fp]; 00143 // 00144 // if (outsidePoints.insert(pointI)) 00145 // { 00146 // // Calculate new position for this outside point 00147 // tmp<pointField> tnearest = 00148 // querySurf.calcNearest(pointField(1, points[pointI])); 00149 // newPoints[pointI] = tnearest()[0]; 00150 // } 00151 // } 00152 // } 00153 // } 00154 // 00155 // 00156 // // Calculate new volume for mixed cells 00157 // label nRemoved = 0; 00158 // for 00159 // ( 00160 // labelHashSet::const_iterator iter = flatCandidates.begin(); 00161 // iter != flatCandidates.end(); 00162 // ++iter 00163 // ) 00164 // { 00165 // label cellI = iter.key(); 00166 // 00167 // const cell& cll = cells[cellI]; 00168 // 00169 // scalar newVol = cll.mag(newPoints, faces); 00170 // scalar oldVol = mesh.cellVolumes()[cellI]; 00171 // 00172 // if (newVol < 0.1 * oldVol) 00173 // { 00174 // internalCells.erase(cellI); 00175 // nRemoved++; 00176 // } 00177 // } 00178 // 00179 // return nRemoved; 00180 //} 00181 00182 00185 //void Foam::surfaceSets::getNearPoints 00186 //( 00187 // const primitiveMesh& mesh, 00188 // const triSurface&, 00189 // const triSurfaceSearch& querySurf, 00190 // const scalar edgeFactor, 00191 // const pointSet& candidateSet, 00192 // pointSet& nearPointSet 00193 //) 00194 //{ 00195 // if (edgeFactor <= 0) 00196 // { 00197 // return; 00198 // } 00199 // 00200 // labelList candidates(candidateSet.toc()); 00201 // 00202 // pointField candidatePoints(candidates.size()); 00203 // forAll(candidates, i) 00204 // { 00205 // candidatePoints[i] = mesh.points()[candidates[i]]; 00206 // } 00207 // 00208 // tmp<pointField> tnearest = querySurf.calcNearest(candidatePoints); 00209 // const pointField& nearest = tnearest(); 00210 // 00211 // const pointField& points = mesh.points(); 00212 // 00213 // forAll(candidates, i) 00214 // { 00215 // label pointI = candidates[i]; 00216 // 00217 // scalar minLen = minEdgeLen(mesh, pointI); 00218 // 00219 // scalar dist = mag(nearest[i] - points[pointI]); 00220 // 00221 // if (dist < edgeFactor * minLen) 00222 // { 00223 // nearPointSet.insert(pointI); 00224 // } 00225 // } 00226 //} 00227 00228 00229 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // 00230 00231 00232 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // 00233 00234 void Foam::surfaceSets::getSurfaceSets 00235 ( 00236 const polyMesh& mesh, 00237 const fileName&, 00238 const triSurface&, 00239 const triSurfaceSearch& querySurf, 00240 const pointField& outsidePts, 00241 00242 const label nCutLayers, 00243 00244 labelHashSet& inside, 00245 labelHashSet& outside, 00246 labelHashSet& cut 00247 ) 00248 { 00249 // Construct search engine on mesh 00250 meshSearch queryMesh(mesh, true); 00251 00252 00253 // Check all 'outside' points 00254 forAll(outsidePts, outsideI) 00255 { 00256 const point& outsidePoint = outsidePts[outsideI]; 00257 00258 // Find cell point is in. Linear search. 00259 if (queryMesh.findCell(outsidePoint, -1, false) == -1) 00260 { 00261 FatalErrorIn 00262 ( 00263 "surfaceSets::getSurfaceSets" 00264 "(const polyMesh&, const fileName&, const triSurface&" 00265 ", const triSurfaceSearch&, const pointField&" 00266 ", labelHashSet&, labelHashSet&, labelHashSet&)" 00267 ) << "outsidePoint " << outsidePoint 00268 << " is not inside any cell" 00269 << exit(FatalError); 00270 } 00271 } 00272 00273 // Cut faces with surface and classify cells 00274 cellClassification cellType 00275 ( 00276 mesh, 00277 queryMesh, 00278 querySurf, 00279 outsidePts 00280 ); 00281 00282 if (nCutLayers > 0) 00283 { 00284 // Trim cutCells so they are max nCutLayers away (as seen in point-cell 00285 // walk) from outside cells. 00286 cellType.trimCutCells 00287 ( 00288 nCutLayers, 00289 cellClassification::OUTSIDE, 00290 cellClassification::INSIDE 00291 ); 00292 } 00293 00294 forAll(cellType, cellI) 00295 { 00296 label cType = cellType[cellI]; 00297 00298 if (cType == cellClassification::CUT) 00299 { 00300 cut.insert(cellI); 00301 } 00302 else if (cType == cellClassification::INSIDE) 00303 { 00304 inside.insert(cellI); 00305 } 00306 else if (cType == cellClassification::OUTSIDE) 00307 { 00308 outside.insert(cellI); 00309 } 00310 } 00311 } 00312 00313 00314 Foam::labelHashSet Foam::surfaceSets::getHangingCells 00315 ( 00316 const primitiveMesh& mesh, 00317 const labelHashSet& internalCells 00318 ) 00319 { 00320 const cellList& cells = mesh.cells(); 00321 const faceList& faces = mesh.faces(); 00322 00323 00324 // Divide points into 00325 // -referenced by internal only 00326 // -referenced by outside only 00327 // -mixed 00328 00329 List<pointStatus> pointSide(mesh.nPoints(), NOTSET); 00330 00331 for (label cellI = 0; cellI < mesh.nCells(); cellI++) 00332 { 00333 if (internalCells.found(cellI)) 00334 { 00335 // Inside cell. Mark all vertices seen from this cell. 00336 const labelList& cFaces = cells[cellI]; 00337 00338 forAll(cFaces, cFaceI) 00339 { 00340 const face& f = faces[cFaces[cFaceI]]; 00341 00342 forAll(f, fp) 00343 { 00344 label pointI = f[fp]; 00345 00346 if (pointSide[pointI] == NOTSET) 00347 { 00348 pointSide[pointI] = INSIDE; 00349 } 00350 else if (pointSide[pointI] == OUTSIDE) 00351 { 00352 pointSide[pointI] = MIXED; 00353 } 00354 else 00355 { 00356 // mixed or inside stay same 00357 } 00358 } 00359 } 00360 } 00361 else 00362 { 00363 // Outside cell 00364 const labelList& cFaces = cells[cellI]; 00365 00366 forAll(cFaces, cFaceI) 00367 { 00368 const face& f = faces[cFaces[cFaceI]]; 00369 00370 forAll(f, fp) 00371 { 00372 label pointI = f[fp]; 00373 00374 if (pointSide[pointI] == NOTSET) 00375 { 00376 pointSide[pointI] = OUTSIDE; 00377 } 00378 else if (pointSide[pointI] == INSIDE) 00379 { 00380 pointSide[pointI] = MIXED; 00381 } 00382 else 00383 { 00384 // mixed or outside stay same 00385 } 00386 } 00387 } 00388 } 00389 } 00390 00391 00392 //OFstream mixedStr("mixed.obj"); 00393 // 00394 //forAll(pointSide, pointI) 00395 //{ 00396 // if (pointSide[pointI] == MIXED) 00397 // { 00398 // const point& pt = points[pointI]; 00399 // 00400 // mixedStr << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() 00401 // << endl; 00402 // } 00403 //} 00404 00405 00406 // Determine cells using mixed points only 00407 00408 labelHashSet mixedOnlyCells(internalCells.size()); 00409 00410 for 00411 ( 00412 labelHashSet::const_iterator iter = internalCells.begin(); 00413 iter != internalCells.end(); 00414 ++iter 00415 ) 00416 { 00417 label cellI = iter.key(); 00418 00419 const cell& cFaces = cells[cellI]; 00420 00421 label usesMixedOnly = true; 00422 00423 forAll(cFaces, i) 00424 { 00425 const face& f = faces[cFaces[i]]; 00426 00427 forAll(f, fp) 00428 { 00429 if (pointSide[f[fp]] != MIXED) 00430 { 00431 usesMixedOnly = false; 00432 break; 00433 } 00434 } 00435 00436 if (!usesMixedOnly) 00437 { 00438 break; 00439 } 00440 } 00441 if (usesMixedOnly) 00442 { 00443 mixedOnlyCells.insert(cellI); 00444 } 00445 } 00446 00447 return mixedOnlyCells; 00448 } 00449 00450 00451 //void Foam::surfaceSets::writeSurfaceSets 00452 //( 00453 // const polyMesh& mesh, 00454 // const fileName& surfName, 00455 // const triSurface& surf, 00456 // const triSurfaceSearch& querySurf, 00457 // const pointField& outsidePts, 00458 // const scalar edgeFactor 00459 //) 00460 //{ 00461 // // Cellsets for inside/outside determination 00462 // cellSet rawInside(mesh, "rawInside", mesh.nCells()/10); 00463 // cellSet rawOutside(mesh, "rawOutside", mesh.nCells()/10); 00464 // cellSet cutCells(mesh, "cutCells", mesh.nCells()/10); 00465 // 00466 // // Get inside/outside/cut cells 00467 // getSurfaceSets 00468 // ( 00469 // mesh, 00470 // surfName, 00471 // surf, 00472 // querySurf, 00473 // outsidePts, 00474 // 00475 // rawInside, 00476 // rawOutside, 00477 // cutCells 00478 // ); 00479 // 00480 // 00481 // Pout<< "rawInside:" << rawInside.size() << endl; 00482 // 00483 // label nRemoved; 00484 // do 00485 // { 00486 // nRemoved = removeHangingCells(mesh, querySurf, rawInside); 00487 // 00488 // Pout<< nl 00489 // << "Removed " << nRemoved 00490 // << " rawInside cells that have all their points on the outside" 00491 // << endl; 00492 // } 00493 // while (nRemoved != 0); 00494 // 00495 // Pout<< "Writing inside cells (" << rawInside.size() << ") to cellSet " 00496 // << rawInside.instance()/rawInside.local()/rawInside.name() 00497 // << endl << endl; 00498 // rawInside.write(); 00499 // 00500 // 00501 // 00502 // // Select outside cells 00503 // surfaceToCell outsideSource 00504 // ( 00505 // mesh, 00506 // surfName, 00507 // surf, 00508 // querySurf, 00509 // outsidePts, 00510 // false, // includeCut 00511 // false, // includeInside 00512 // true, // includeOutside 00513 // -GREAT, // nearDist 00514 // -GREAT // curvature 00515 // ); 00516 // 00517 // outsideSource.applyToSet(topoSetSource::NEW, rawOutside); 00518 // 00519 // Pout<< "rawOutside:" << rawOutside.size() << endl; 00520 // 00521 // do 00522 // { 00523 // nRemoved = removeHangingCells(mesh, querySurf, rawOutside); 00524 // 00525 // Pout<< nl 00526 // << "Removed " << nRemoved 00527 // << " rawOutside cells that have all their points on the outside" 00528 // << endl; 00529 // } 00530 // while (nRemoved != 0); 00531 // 00532 // Pout<< "Writing outside cells (" << rawOutside.size() << ") to cellSet " 00533 // << rawOutside.instance()/rawOutside.local()/rawOutside.name() 00534 // << endl << endl; 00535 // rawOutside.write(); 00536 // 00537 // 00538 // // Select cut cells by negating inside and outside set. 00539 // cutCells.invert(mesh.nCells()); 00540 // 00541 // cellToCell deleteInsideSource(mesh, rawInside.name()); 00542 // 00543 // deleteInsideSource.applyToSet(topoSetSource::DELETE, cutCells); 00544 // Pout<< "Writing cut cells (" << cutCells.size() << ") to cellSet " 00545 // << cutCells.instance()/cutCells.local()/cutCells.name() 00546 // << endl << endl; 00547 // cutCells.write(); 00548 // 00549 // 00550 // // 00551 // // Remove cells with points too close to surface. 00552 // // 00553 // 00554 // 00555 // // Get all points in cutCells. 00556 // pointSet cutPoints(mesh, "cutPoints", 4*cutCells.size()); 00557 // cellToPoint cutSource(mesh, "cutCells", cellToPoint::ALL); 00558 // cutSource.applyToSet(topoSetSource::NEW, cutPoints); 00559 // 00560 // // Get all points that are too close to surface. 00561 // pointSet nearPoints(mesh, "nearPoints", cutPoints.size()); 00562 // 00563 // getNearPoints 00564 // ( 00565 // mesh, 00566 // surf, 00567 // querySurf, 00568 // edgeFactor, 00569 // cutPoints, 00570 // nearPoints 00571 // ); 00572 // 00573 // Pout<< nl 00574 // << "Selected " << nearPoints.size() 00575 // << " points that are closer than " << edgeFactor 00576 // << " times the local minimum lengthscale to the surface" 00577 // << nl << endl; 00578 // 00579 // 00580 // // Remove cells that use any of the points in nearPoints 00581 // // from the inside and outsideCells. 00582 // nearPoints.write(); 00583 // pointToCell pToCell(mesh, nearPoints.name(), pointToCell::ANY); 00584 // 00585 // 00586 // 00587 // // Start off from copy of rawInside, rawOutside 00588 // cellSet inside(mesh, "inside", rawInside); 00589 // cellSet outside(mesh, "outside", rawOutside); 00590 // 00591 // pToCell.applyToSet(topoSetSource::DELETE, inside); 00592 // pToCell.applyToSet(topoSetSource::DELETE, outside); 00593 // 00594 // Pout<< nl 00595 // << "Removed " << rawInside.size() - inside.size() 00596 // << " inside cells that are too close to the surface" << endl; 00597 // 00598 // Pout<< nl 00599 // << "Removed " << rawOutside.size() - outside.size() 00600 // << " inside cells that are too close to the surface" << nl << endl; 00601 // 00602 // 00603 // 00604 // // 00605 // // Remove cells with one or no faces on rest of cellSet. Note: Problem is 00606 // // not these cells an sich but rather that all of their vertices will be 00607 // // outside vertices and thus projected onto surface. Which might (if they 00608 // // project onto same surface) result in flattened cells. 00609 // // 00610 // 00611 // do 00612 // { 00613 // nRemoved = removeHangingCells(mesh, querySurf, inside); 00614 // 00615 // Pout<< nl 00616 // << "Removed " << nRemoved 00617 // << " inside cells that have all their points on the outside" 00618 // << endl; 00619 // } 00620 // while (nRemoved != 0); 00621 // do 00622 // { 00623 // nRemoved = removeHangingCells(mesh, querySurf, outside); 00624 // 00625 // Pout<< nl 00626 // << "Removed " << nRemoved 00627 // << " outside cells that have all their points on the inside" 00628 // << endl; 00629 // } 00630 // while (nRemoved != 0); 00631 // 00632 // 00633 // // 00634 // // Write 00635 // // 00636 // 00637 // 00638 // Pout<< "Writing inside cells (" << inside.size() << ") to cellSet " 00639 // << inside.instance()/inside.local()/inside.name() 00640 // << endl << endl; 00641 // 00642 // inside.write(); 00643 // 00644 // Pout<< "Writing outside cells (" << outside.size() << ") to cellSet " 00645 // << outside.instance()/outside.local()/outside.name() 00646 // << endl << endl; 00647 // 00648 // outside.write(); 00649 //} 00650 00651 00652 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // 00653 00654 00655 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // 00656 00657 00658 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // 00659 00660 00661 // ************************************************************************* // |