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

searchableSurfacesQueries.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 "searchableSurfacesQueries.H"
00028 #include "ListOps.H"
00029 #include "OFstream.H"
00030 #include "meshTools.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 defineTypeNameAndDebug(Foam::searchableSurfacesQueries, 0);
00035 
00036 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00037 
00038 Foam::pointIndexHit Foam::searchableSurfacesQueries::tempFindNearest
00039 (
00040     const searchableSurface& surf,
00041     const point& pt,
00042     const scalar initDistSqr
00043 )
00044 {
00045     pointField onePoint(1, pt);
00046     scalarField oneDist(1, initDistSqr);
00047     List<pointIndexHit> oneHit(1);
00048     surf.findNearest(onePoint, oneDist, oneHit);
00049     return oneHit[0];
00050 }
00051 
00052 
00053 // Calculate sum of distance to surfaces.
00054 Foam::scalar Foam::searchableSurfacesQueries::sumDistSqr
00055 (
00056     const PtrList<searchableSurface>& allSurfaces,
00057     const labelList& surfacesToTest,
00058     const scalar initDistSqr,
00059     const point& pt
00060 )
00061 {
00062     scalar sum = 0;
00063 
00064     forAll(surfacesToTest, testI)
00065     {
00066         label surfI = surfacesToTest[testI];
00067 
00068         pointIndexHit hit
00069         (
00070             tempFindNearest(allSurfaces[surfI], pt, initDistSqr)
00071         );
00072 
00073         // Note: make it fall over if not hit.
00074         sum += magSqr(hit.hitPoint()-pt);
00075     }
00076     return sum;
00077 }
00078 
00079 
00080 // Reflects the point furthest away around the triangle centre by a factor fac.
00081 // (triangle centre is the average of all points but the ihi. pSum is running
00082 //  sum of all points)
00083 Foam::scalar Foam::searchableSurfacesQueries::tryMorphTet
00084 (
00085     const PtrList<searchableSurface>& allSurfaces,
00086     const labelList& surfacesToTest,
00087     const scalar initDistSqr,
00088     List<vector>& p,
00089     List<scalar>& y,
00090     vector& pSum,
00091     const label ihi,
00092     const scalar fac
00093 )
00094 {
00095     scalar fac1 = (1.0-fac)/vector::nComponents;
00096     scalar fac2 = fac1-fac;
00097 
00098     vector ptry = pSum*fac1-p[ihi]*fac2;
00099 
00100     scalar ytry = sumDistSqr(allSurfaces, surfacesToTest, initDistSqr, ptry);
00101 
00102     if (ytry < y[ihi])
00103     {
00104         y[ihi] = ytry;
00105         pSum += ptry - p[ihi];
00106         p[ihi] = ptry;
00107     }
00108     return ytry;
00109 }
00110 
00111 
00112 bool Foam::searchableSurfacesQueries::morphTet
00113 (
00114     const PtrList<searchableSurface>& allSurfaces,
00115     const labelList& surfacesToTest,
00116     const scalar initDistSqr,
00117     const scalar convergenceDistSqr,
00118     const label maxIter,
00119     List<vector>& p,
00120     List<scalar>& y
00121 )
00122 {
00123     vector pSum = sum(p);
00124 
00125     autoPtr<OFstream> str;
00126     label vertI = 0;
00127     if (debug)
00128     {
00129         wordList names(surfacesToTest.size());
00130         forAll(surfacesToTest, i)
00131         {
00132             names[i] = allSurfaces[surfacesToTest[i]].name();
00133         }
00134         Pout<< "searchableSurfacesQueries::morphTet : intersection of "
00135             << names << " starting from points:" << p << endl;
00136         str.reset(new OFstream("track.obj"));
00137         meshTools::writeOBJ(str(), p[0]);
00138         vertI++;
00139     }
00140 
00141     for (label iter = 0; iter < maxIter; iter++)
00142     {
00143         // Get the indices of lowest, highest and second-highest values.
00144         label ilo, ihi, inhi;
00145         {
00146             labelList sortedIndices;
00147             sortedOrder(y, sortedIndices);
00148             ilo  = sortedIndices[0];
00149             ihi  = sortedIndices[sortedIndices.size()-1];
00150             inhi = sortedIndices[sortedIndices.size()-2];
00151         }
00152 
00153         if (debug)
00154         {
00155             Pout<< "Iteration:" << iter
00156                 << " lowest:" << y[ilo] << " highest:" << y[ihi]
00157                 << " points:" << p << endl;
00158 
00159             meshTools::writeOBJ(str(), p[ilo]);
00160             vertI++;
00161             str()<< "l " << vertI-1 << ' ' << vertI << nl;
00162         }
00163 
00164         if (y[ihi] < convergenceDistSqr)
00165         {
00166             // Get point on 0th surface.
00167             Swap(p[0], p[ilo]);
00168             Swap(y[0], y[ilo]);
00169             return true;
00170         }
00171 
00172         // Reflection: point furthest away gets reflected.
00173         scalar ytry = tryMorphTet
00174         (
00175             allSurfaces,
00176             surfacesToTest,
00177             10*y[ihi],             // search box.
00178             p,
00179             y,
00180             pSum,
00181             ihi,
00182             -1.0
00183         );
00184 
00185         if (ytry <= y[ilo])
00186         {
00187             // If in right direction (y lower) expand by two.
00188             ytry = tryMorphTet
00189             (
00190                 allSurfaces,
00191                 surfacesToTest,
00192                 10*y[ihi],
00193                 p,
00194                 y,
00195                 pSum,
00196                 ihi,
00197                 2.0
00198             );
00199         }
00200         else if (ytry >= y[inhi])
00201         {
00202             // If inside tet try contraction.
00203 
00204             scalar ysave = y[ihi];
00205 
00206             ytry = tryMorphTet
00207             (
00208                 allSurfaces,
00209                 surfacesToTest,
00210                 10*y[ihi],
00211                 p,
00212                 y,
00213                 pSum,
00214                 ihi,
00215                 0.5
00216             );
00217 
00218             if (ytry >= ysave)
00219             {
00220                 // Contract around lowest point.
00221                 forAll(p, i)
00222                 {
00223                     if (i != ilo)
00224                     {
00225                         p[i] = 0.5*(p[i] + p[ilo]);
00226                         y[i] = sumDistSqr
00227                         (
00228                             allSurfaces,
00229                             surfacesToTest,
00230                             y[ihi],
00231                             p[i]
00232                         );
00233                     }
00234                 }
00235                 pSum = sum(p);
00236             }
00237         }
00238     }
00239 
00240     if (debug)
00241     {
00242         meshTools::writeOBJ(str(), p[0]);
00243         vertI++;
00244         str()<< "l " << vertI-1 << ' ' << vertI << nl;
00245     }
00246 
00247     // Failure to converge. Return best guess so far.
00248     label ilo = findMin(y);
00249     Swap(p[0], p[ilo]);
00250     Swap(y[0], y[ilo]);
00251     return false;
00252 }
00253 
00254 
00256 //void Foam::searchableSurfacesQueries::findAllIntersections
00257 //(
00258 //    const searchableSurface& s,
00259 //    const pointField& start,
00260 //    const pointField& end,
00261 //    const vectorField& smallVec,
00262 //    List<List<pointIndexHit> >& surfaceHitInfo
00263 //)
00264 //{
00265 //    surfaceHitInfo.setSize(start.size());
00266 //
00267 //    // Current start point of vector
00268 //    pointField p0(start);
00269 //
00270 //    List<pointIndexHit> intersectInfo(start.size());
00271 //
00272 //    // For test whether finished doing vector.
00273 //    const vectorField dirVec(end-start);
00274 //    const scalarField magSqrDirVec(magSqr(dirVec));
00275 //
00276 //    while (true)
00277 //    {
00278 //        // Find first intersection. Synced.
00279 //        s.findLine(p0, end, intersectInfo);
00280 //
00281 //        label nHits = 0;
00282 //
00283 //        forAll(intersectInfo, i)
00284 //        {
00285 //            if (intersectInfo[i].hit())
00286 //            {
00287 //                nHits++;
00288 //
00289 //                label sz = surfaceHitInfo[i].size();
00290 //                surfaceHitInfo[i].setSize(sz+1);
00291 //                surfaceHitInfo[i][sz] = intersectInfo[i];
00292 //
00293 //                p0[i] = intersectInfo[i].hitPoint() + smallVec[i];
00294 //
00295 //                // If beyond endpoint set to endpoint so as not to pick up
00296 //                // any intersections. Could instead just filter out hits.
00297 //                if (((p0[i]-start[i])&dirVec[i]) > magSqrDirVec[i])
00298 //                {
00299 //                    p0[i] = end[i];
00300 //                }
00301 //            }
00302 //            else
00303 //            {
00304 //                // Set to endpoint to stop intersection test. See above.
00305 //                p0[i] = end[i];
00306 //            }
00307 //        }
00308 //
00309 //        // returnReduce(nHits) ?
00310 //        if (nHits == 0)
00311 //        {
00312 //            break;
00313 //        }
00314 //    }
00315 //}
00316 
00317 
00318 // Given current set of hits (allSurfaces, allInfo) merge in those coming from
00319 // surface surfI.
00320 void Foam::searchableSurfacesQueries::mergeHits
00321 (
00322     const point& start,
00323     const scalar mergeDist,
00324 
00325     const label testI,                          // index of surface
00326     const List<pointIndexHit>& surfHits,  // hits on surface
00327 
00328     labelList& allSurfaces,
00329     List<pointIndexHit>& allInfo,
00330     scalarList& allDistSqr
00331 )
00332 {
00333     // Precalculate distances
00334     scalarList surfDistSqr(surfHits.size());
00335     forAll(surfHits, i)
00336     {
00337         surfDistSqr[i] = magSqr(surfHits[i].hitPoint()-start);
00338     }
00339 
00340     forAll(surfDistSqr, i)
00341     {
00342         label index = findLower(allDistSqr, surfDistSqr[i]);
00343 
00344         // Check if equal to lower.
00345         if
00346         (
00347             index >= 0
00348          && (mag(allDistSqr[index]-surfDistSqr[i]) < mergeDist)
00349         )
00350         {
00351             // Same. Do not count.
00352             //Pout<< "point:" << surfHits[i].hitPoint()
00353             //    << " considered same as:" << allInfo[index].hitPoint()
00354             //    << " within tol:" << mergeDist
00355             //    << endl;
00356         }
00357         else
00358         {
00359             // Check if equal to higher
00360             label next = index+1;
00361             if
00362             (
00363                 next < allDistSqr.size()
00364              && (mag(allDistSqr[next]-surfDistSqr[i]) < mergeDist)
00365             )
00366             {
00367                 //Pout<< "point:" << surfHits[i].hitPoint()
00368                 //    << " considered same as:" << allInfo[next].hitPoint()
00369                 //    << " within tol:" << mergeDist
00370                 //    << endl;
00371             }
00372             else
00373             {
00374                 // Insert after index
00375                 label sz = allSurfaces.size();
00376                 allSurfaces.setSize(sz+1);
00377                 allInfo.setSize(allSurfaces.size());
00378                 allDistSqr.setSize(allSurfaces.size());
00379                 // Make space.
00380                 for (label j = sz-1; j > index; --j)
00381                 {
00382                     allSurfaces[j+1] = allSurfaces[j];
00383                     allInfo[j+1] = allInfo[j];
00384                     allDistSqr[j+1] = allDistSqr[j];
00385                 }
00386                 // Insert new value
00387                 allSurfaces[index+1] = testI;
00388                 allInfo[index+1] = surfHits[i];
00389                 allDistSqr[index+1] = surfDistSqr[i];
00390             }
00391         }
00392     }
00393 }
00394 
00395 
00396 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00397 
00398 // Find any intersection
00399 void Foam::searchableSurfacesQueries::findAnyIntersection
00400 (
00401     const PtrList<searchableSurface>& allSurfaces,
00402     const labelList& surfacesToTest,
00403     const pointField& start,
00404     const pointField& end,
00405     labelList& hitSurfaces,
00406     List<pointIndexHit>& hitInfo
00407 )
00408 {
00409     hitSurfaces.setSize(start.size());
00410     hitSurfaces = -1;
00411     hitInfo.setSize(start.size());
00412 
00413     // Work arrays
00414     labelList hitMap(identity(start.size()));
00415     pointField p0(start);
00416     pointField p1(end);
00417     List<pointIndexHit> intersectInfo(start.size());
00418 
00419     forAll(surfacesToTest, testI)
00420     {
00421         // Do synchronised call to all surfaces.
00422         allSurfaces[surfacesToTest[testI]].findLineAny(p0, p1, intersectInfo);
00423 
00424         // Copy all hits into arguments, continue with misses
00425         label newI = 0;
00426         forAll(intersectInfo, i)
00427         {
00428             if (intersectInfo[i].hit())
00429             {
00430                 hitInfo[hitMap[i]] = intersectInfo[i];
00431                 hitSurfaces[hitMap[i]] = testI;
00432             }
00433             else
00434             {
00435                 if (i != newI)
00436                 {
00437                     hitMap[newI] = hitMap[i];
00438                     p0[newI] = p0[i];
00439                     p1[newI] = p1[i];
00440                 }
00441                 newI++;
00442             }
00443         }
00444 
00445         // All done? Note that this decision should be synchronised
00446         if (newI == 0)
00447         {
00448             break;
00449         }
00450 
00451         // Trim and continue
00452         hitMap.setSize(newI);
00453         p0.setSize(newI);
00454         p1.setSize(newI);
00455         intersectInfo.setSize(newI);
00456     }
00457 }
00458 
00459 
00460 void Foam::searchableSurfacesQueries::findAllIntersections
00461 (
00462     const PtrList<searchableSurface>& allSurfaces,
00463     const labelList& surfacesToTest,
00464     const pointField& start,
00465     const pointField& end,
00466     labelListList& hitSurfaces,
00467     List<List<pointIndexHit> >& hitInfo
00468 )
00469 {
00470     // Note: maybe move the single-surface all intersections test into
00471     // searchable surface? Some of the tolerance issues might be
00472     // lessened.
00473 
00474     // 2. Currently calling searchableSurface::findLine with start==end
00475     //    is expected to find no intersection. Problem if it does.
00476 
00477     hitSurfaces.setSize(start.size());
00478     hitInfo.setSize(start.size());
00479 
00480     if (surfacesToTest.empty())
00481     {
00482         return;
00483     }
00484 
00485     // Test first surface
00486     allSurfaces[surfacesToTest[0]].findLineAll(start, end, hitInfo);
00487 
00488     // Set hitSurfaces and distance
00489     List<scalarList> hitDistSqr(hitInfo.size());
00490     forAll(hitInfo, pointI)
00491     {
00492         const List<pointIndexHit>& pHits = hitInfo[pointI];
00493 
00494         labelList& pSurfaces = hitSurfaces[pointI];
00495         pSurfaces.setSize(pHits.size());
00496         pSurfaces = 0;
00497 
00498         scalarList& pDistSqr = hitDistSqr[pointI];
00499         pDistSqr.setSize(pHits.size());
00500         forAll(pHits, i)
00501         {
00502             pDistSqr[i] = magSqr(pHits[i].hitPoint() - start[pointI]);
00503         }
00504     }
00505 
00506 
00507     if (surfacesToTest.size() > 1)
00508     {
00509         // Small vector to increment start vector by to find next intersection
00510         // along line. Constant factor added to make sure that start==end still
00511         // ends iteration in findAllIntersections. Also SMALL is just slightly
00512         // too small.
00513         const vectorField smallVec
00514         (
00515             1E2*SMALL*(end-start)
00516           + vector(ROOTVSMALL,ROOTVSMALL,ROOTVSMALL)
00517         );
00518 
00519         // Tolerance used to check whether points are equal. Note: used to
00520         // compare distance^2. Note that we use the maximum possible tolerance
00521         // (reached at intersections close to the end point)
00522         const scalarField mergeDist(2*mag(smallVec)*mag(end-start));
00523 
00524         // Test the other surfaces and merge (according to distance from start).
00525         for (label testI = 1; testI < surfacesToTest.size(); testI++)
00526         {
00527             List<List<pointIndexHit> > surfHits;
00528             allSurfaces[surfacesToTest[testI]].findLineAll
00529             (
00530                 start,
00531                 end,
00532                 surfHits
00533             );
00534 
00535             forAll(surfHits, pointI)
00536             {
00537                 mergeHits
00538                 (
00539                     start[pointI],          // Current segment
00540                     mergeDist[pointI],
00541 
00542                     testI,                  // Surface and its hits
00543                     surfHits[pointI],
00544 
00545                     hitSurfaces[pointI],    // Merge into overall hit info
00546                     hitInfo[pointI],
00547                     hitDistSqr[pointI]
00548                 );
00549             }
00550         }
00551     }
00552 }
00553 
00554 
00556 //void Foam::searchableSurfacesQueries::findNearestIntersection
00557 //(
00558 //    const PtrList<searchableSurface>& allSurfaces,
00559 //    const labelList& surfacesToTest,
00560 //    const pointField& start,
00561 //    const pointField& end,
00562 //
00563 //    labelList& surface1,
00564 //    List<pointIndexHit>& hit1,
00565 //    labelList& surface2,
00566 //    List<pointIndexHit>& hit2
00567 //)
00568 //{
00569 //    // 1. intersection from start to end
00570 //    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00571 //
00572 //    // Initialize arguments
00573 //    surface1.setSize(start.size());
00574 //    surface1 = -1;
00575 //    hit1.setSize(start.size());
00576 //
00577 //    // Current end of segment to test.
00578 //    pointField nearest(end);
00579 //    // Work array
00580 //    List<pointIndexHit> nearestInfo(start.size());
00581 //
00582 //    forAll(surfacesToTest, testI)
00583 //    {
00584 //        // See if any intersection between start and current nearest
00585 //        allSurfaces[surfacesToTest[testI]].findLine
00586 //        (
00587 //            start,
00588 //            nearest,
00589 //            nearestInfo
00590 //        );
00591 //
00592 //        forAll(nearestInfo, pointI)
00593 //        {
00594 //            if (nearestInfo[pointI].hit())
00595 //            {
00596 //                hit1[pointI] = nearestInfo[pointI];
00597 //                surface1[pointI] = testI;
00598 //                nearest[pointI] = hit1[pointI].hitPoint();
00599 //            }
00600 //        }
00601 //    }
00602 //
00603 //
00604 //    // 2. intersection from end to last intersection
00605 //    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00606 //
00607 //    // Find the nearest intersection from end to start. Note that we
00608 //    // initialize to the first intersection (if any).
00609 //    surface2 = surface1;
00610 //    hit2 = hit1;
00611 //
00612 //    // Set current end of segment to test.
00613 //    forAll(nearest, pointI)
00614 //    {
00615 //        if (hit1[pointI].hit())
00616 //        {
00617 //            nearest[pointI] = hit1[pointI].hitPoint();
00618 //        }
00619 //        else
00620 //        {
00621 //            // Disable testing by setting to end.
00622 //            nearest[pointI] = end[pointI];
00623 //        }
00624 //    }
00625 //
00626 //    forAll(surfacesToTest, testI)
00627 //    {
00628 //        // See if any intersection between end and current nearest
00629 //        allSurfaces[surfacesToTest[i]].findLine(end, nearest, nearestInfo);
00630 //
00631 //        forAll(nearestInfo, pointI)
00632 //        {
00633 //            if (nearestInfo[pointI].hit())
00634 //            {
00635 //                hit2[pointI] = nearestInfo[pointI];
00636 //                surface2[pointI] = testI;
00637 //                nearest[pointI] = hit2[pointI].hitPoint();
00638 //            }
00639 //        }
00640 //    }
00641 //}
00642 
00643 
00644 // Find nearest. Return -1 or nearest point
00645 void Foam::searchableSurfacesQueries::findNearest
00646 (
00647     const PtrList<searchableSurface>& allSurfaces,
00648     const labelList& surfacesToTest,
00649     const pointField& samples,
00650     const scalarField& nearestDistSqr,
00651     labelList& nearestSurfaces,
00652     List<pointIndexHit>& nearestInfo
00653 )
00654 {
00655     // Initialise
00656     nearestSurfaces.setSize(samples.size());
00657     nearestSurfaces = -1;
00658     nearestInfo.setSize(samples.size());
00659 
00660     // Work arrays
00661     scalarField minDistSqr(nearestDistSqr);
00662     List<pointIndexHit> hitInfo(samples.size());
00663 
00664     forAll(surfacesToTest, testI)
00665     {
00666         allSurfaces[surfacesToTest[testI]].findNearest
00667         (
00668             samples,
00669             minDistSqr,
00670             hitInfo
00671         );
00672 
00673         // Update minDistSqr and arguments
00674         forAll(hitInfo, pointI)
00675         {
00676             if (hitInfo[pointI].hit())
00677             {
00678                 minDistSqr[pointI] = magSqr
00679                 (
00680                     hitInfo[pointI].hitPoint()
00681                   - samples[pointI]
00682                 );
00683                 nearestInfo[pointI] = hitInfo[pointI];
00684                 nearestSurfaces[pointI] = testI;
00685             }
00686         }
00687     }
00688 }
00689 
00690 
00691 //- Calculate point which is on a set of surfaces.
00692 Foam::pointIndexHit Foam::searchableSurfacesQueries::facesIntersection
00693 (
00694     const PtrList<searchableSurface>& allSurfaces,
00695     const labelList& surfacesToTest,
00696     const scalar initDistSqr,
00697     const scalar convergenceDistSqr,
00698     const point& start
00699 )
00700 {
00701     // Get four starting points. Take these as the projection of the
00702     // starting point onto the surfaces and the mid point
00703     List<point> nearest(surfacesToTest.size()+1);
00704 
00705     point sumNearest = vector::zero;
00706 
00707     forAll(surfacesToTest, i)
00708     {
00709         pointIndexHit hit
00710         (
00711             tempFindNearest(allSurfaces[surfacesToTest[i]], start, initDistSqr)
00712         );
00713 
00714         if (hit.hit())
00715         {
00716             nearest[i] = hit.hitPoint();
00717             sumNearest += nearest[i];
00718         }
00719         else
00720         {
00721             FatalErrorIn
00722             (
00723                 "searchableSurfacesQueries::facesIntersection"
00724                 "(const labelList&, const scalar, const scalar, const point&)"
00725             )   << "Did not find point within distance "
00726                 << initDistSqr << " of starting point " << start
00727                 << " on surface "
00728                 << allSurfaces[surfacesToTest[i]].IOobject::name()
00729                 << abort(FatalError);
00730         }
00731     }
00732 
00733     nearest[nearest.size()-1] = sumNearest / surfacesToTest.size();
00734 
00735 
00736     // Get the sum of distances (initial evaluation)
00737     List<scalar> nearestDist(nearest.size());
00738 
00739     forAll(nearestDist, i)
00740     {
00741         nearestDist[i] = sumDistSqr
00742         (
00743             allSurfaces,
00744             surfacesToTest,
00745             initDistSqr,
00746             nearest[i]
00747         );
00748     }
00749 
00750 
00751     //- Downhill Simplex method
00752 
00753     bool converged = morphTet
00754     (
00755         allSurfaces,
00756         surfacesToTest,
00757         initDistSqr,
00758         convergenceDistSqr,
00759         2000,
00760         nearest,
00761         nearestDist
00762     );
00763 
00764 
00765     pointIndexHit intersection;
00766 
00767     if (converged)
00768     {
00769         // Project nearest onto 0th surface.
00770         intersection = tempFindNearest
00771         (
00772             allSurfaces[surfacesToTest[0]],
00773             nearest[0],
00774             nearestDist[0]
00775         );
00776     }
00777 
00778     //if (!intersection.hit())
00779     //{
00780     //    // Restart
00781     //    scalar smallDist = Foam::sqr(convergenceDistSqr);
00782     //    nearest[0] = intersection.hitPoint();
00783     //    nearest[1] = nearest[0];
00784     //    nearest[1].x() += smallDist;
00785     //    nearest[2] = nearest[0];
00786     //    nearest[2].y() += smallDist;
00787     //    nearest[3] = nearest[0];
00788     //    nearest[3].z() += smallDist;
00789     //
00790     //    forAll(nearestDist, i)
00791     //    {
00792     //        nearestDist[i] = sumDistSqr
00793     //        (
00794     //            surfacesToTest,
00795     //            initDistSqr,
00796     //            nearest[i]
00797     //        );
00798     //    }
00799     //
00800     //    intersection = morphTet
00801     //    (
00802     //        allSurfaces,
00803     //        surfacesToTest,
00804     //        initDistSqr,
00805     //        convergenceDistSqr,
00806     //        1000,
00807     //        nearest,
00808     //        nearestDist
00809     //    );
00810     //}
00811 
00812     return intersection;
00813 }
00814 
00815 
00816 
00817 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd