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

searchableSurfaces.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 "searchableSurfaces.H"
00028 #include "searchableSurfacesQueries.H"
00029 #include "ListOps.H"
00030 #include "Time.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 defineTypeNameAndDebug(searchableSurfaces, 0);
00038 
00039 }
00040 
00041 
00042 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00043 
00044 // Construct with length.
00045 Foam::searchableSurfaces::searchableSurfaces(const label size)
00046 :
00047     PtrList<searchableSurface>(size),
00048     regionNames_(size),
00049     allSurfaces_(identity(size))
00050 {}
00051 
00052 
00053 //Foam::searchableSurfaces::searchableSurfaces
00054 //(
00055 //    const IOobject& io,
00056 //    const PtrList<dictionary>& dicts
00057 //)
00058 //:
00059 //    PtrList<searchableSurface>(dicts.size()),
00060 //    regionNames_(dicts.size()),
00061 //    allSurfaces_(identity(dicts.size()))
00062 //{
00063 //    forAll(dicts, surfI)
00064 //    {
00065 //        const dictionary& dict = dicts[surfI];
00066 //
00067 //        // Make IOobject with correct name
00068 //        autoPtr<IOobject> namedIO(io.clone());
00069 //        namedIO().rename(dict.lookup("name"));
00070 //
00071 //        // Create and hook surface
00072 //        set
00073 //        (
00074 //            surfI,
00075 //            searchableSurface::New
00076 //            (
00077 //                dict.lookup("type"),
00078 //                namedIO(),
00079 //                dict
00080 //            )
00081 //        );
00082 //        const searchableSurface& s = operator[](surfI);
00083 //
00084 //        // Construct default region names by prepending surface name
00085 //        // to region name.
00086 //        const wordList& localNames = s.regions();
00087 //
00088 //        wordList globalNames(localNames.size());
00089 //        forAll(localNames, regionI)
00090 //        {
00091 //            globalNames[regionI] = s.name() + '_' + localNames[regionI];
00092 //        }
00093 //
00094 //        // See if dictionary provides any global region names.
00095 //        if (dict.found("regions"))
00096 //        {
00097 //            const dictionary& regionsDict = dict.subDict("regions");
00098 //
00099 //            forAllConstIter(dictionary, regionsDict, iter)
00100 //            {
00101 //                const word& key = iter().keyword();
00102 //
00103 //                if (regionsDict.isDict(key))
00104 //                {
00105 //                    // Get the dictionary for region iter.key()
00106 //                    const dictionary& regionDict = regionsDict.subDict(key);
00107 //
00108 //                    label index = findIndex(localNames, key);
00109 //
00110 //                    if (index == -1)
00111 //                    {
00112 //                        FatalErrorIn
00113 //                        (
00114 //                            "searchableSurfaces::searchableSurfaces"
00115 //                            "( const IOobject&, const dictionary&)"
00116 //                        )   << "Unknown region name " << key
00117 //                            << " for surface " << s.name() << endl
00118 //                            << "Valid region names are " << localNames
00119 //                            << exit(FatalError);
00120 //                    }
00121 //
00122 //                    globalNames[index] = word(regionDict.lookup("name"));
00123 //                }
00124 //            }
00125 //        }
00126 //
00127 //        // Now globalNames contains the names of the regions.
00128 //        Info<< "Surface:" << s.name() << " has regions:"
00129 //            << endl;
00130 //        forAll(globalNames, regionI)
00131 //        {
00132 //            Info<< "    " << globalNames[regionI] << endl;
00133 //        }
00134 //
00135 //        // Create reverse lookup
00136 //        forAll(globalNames, regionI)
00137 //        {
00138 //            regionNames_.insert
00139 //            (
00140 //                globalNames[regionI],
00141 //                labelPair(surfI, regionI)
00142 //            );
00143 //        }
00144 //    }
00145 //}
00146 
00147 
00148 Foam::searchableSurfaces::searchableSurfaces
00149 (
00150     const IOobject& io,
00151     const dictionary& topDict
00152 )
00153 :
00154     PtrList<searchableSurface>(topDict.size()),
00155     names_(topDict.size()),
00156     regionNames_(topDict.size()),
00157     allSurfaces_(identity(topDict.size()))
00158 {
00159     label surfI = 0;
00160     forAllConstIter(dictionary, topDict, iter)
00161     {
00162         const word& key = iter().keyword();
00163 
00164         if (!topDict.isDict(key))
00165         {
00166             FatalErrorIn
00167             (
00168                 "searchableSurfaces::searchableSurfaces"
00169                 "( const IOobject&, const dictionary&)"
00170             )   << "Found non-dictionary entry " << iter()
00171                 << " in top-level dictionary " << topDict
00172                 << exit(FatalError);
00173         }
00174 
00175         const dictionary& dict = topDict.subDict(key);
00176 
00177         names_[surfI] = key;
00178         dict.readIfPresent("name", names_[surfI]);
00179 
00180         // Make IOobject with correct name
00181         autoPtr<IOobject> namedIO(io.clone());
00182         // Note: we would like to e.g. register triSurface 'sphere.stl' as
00183         // 'sphere'. Unfortunately
00184         // no support for having object read from different location than
00185         // their object name. Maybe have stlTriSurfaceMesh which appends .stl
00186         // when reading/writing?
00187         namedIO().rename(key);  // names_[surfI]
00188 
00189         // Create and hook surface
00190         set
00191         (
00192             surfI,
00193             searchableSurface::New
00194             (
00195                 dict.lookup("type"),
00196                 namedIO(),
00197                 dict
00198             )
00199         );
00200         const searchableSurface& s = operator[](surfI);
00201 
00202         // Construct default region names by prepending surface name
00203         // to region name.
00204         const wordList& localNames = s.regions();
00205 
00206         wordList& rNames = regionNames_[surfI];
00207         rNames.setSize(localNames.size());
00208 
00209         forAll(localNames, regionI)
00210         {
00211             rNames[regionI] = names_[surfI] + '_' + localNames[regionI];
00212         }
00213 
00214         // See if dictionary provides any global region names.
00215         if (dict.found("regions"))
00216         {
00217             const dictionary& regionsDict = dict.subDict("regions");
00218 
00219             forAllConstIter(dictionary, regionsDict, iter)
00220             {
00221                 const word& key = iter().keyword();
00222 
00223                 if (regionsDict.isDict(key))
00224                 {
00225                     // Get the dictionary for region iter.keyword()
00226                     const dictionary& regionDict = regionsDict.subDict(key);
00227 
00228                     label index = findIndex(localNames, key);
00229 
00230                     if (index == -1)
00231                     {
00232                         FatalErrorIn
00233                         (
00234                             "searchableSurfaces::searchableSurfaces"
00235                             "( const IOobject&, const dictionary&)"
00236                         )   << "Unknown region name " << key
00237                             << " for surface " << s.name() << endl
00238                             << "Valid region names are " << localNames
00239                             << exit(FatalError);
00240                     }
00241 
00242                     rNames[index] = word(regionDict.lookup("name"));
00243                 }
00244             }
00245         }
00246 
00247         surfI++;
00248     }
00249 
00250     // Trim (not really necessary since we don't allow non-dictionary entries)
00251     PtrList<searchableSurface>::setSize(surfI);
00252     names_.setSize(surfI);
00253     regionNames_.setSize(surfI);
00254     allSurfaces_.setSize(surfI);
00255 }
00256 
00257 
00258 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00259 
00260 Foam::label Foam::searchableSurfaces::findSurfaceID(const word& wantedName)
00261  const
00262 {
00263     return findIndex(names_, wantedName);
00264 }
00265 
00266 
00267 // Find any intersection
00268 void Foam::searchableSurfaces::findAnyIntersection
00269 (
00270     const pointField& start,
00271     const pointField& end,
00272     labelList& hitSurfaces,
00273     List<pointIndexHit>& hitInfo
00274 ) const
00275 {
00276     searchableSurfacesQueries::findAnyIntersection
00277     (
00278         *this,
00279         allSurfaces_,
00280         start,
00281         end,
00282         hitSurfaces,
00283         hitInfo
00284     );
00285 }
00286 
00287 
00288 // Find intersections of edge nearest to both endpoints.
00289 void Foam::searchableSurfaces::findAllIntersections
00290 (
00291     const pointField& start,
00292     const pointField& end,
00293     labelListList& hitSurfaces,
00294     List<List<pointIndexHit> >& hitInfo
00295 ) const
00296 {
00297     searchableSurfacesQueries::findAllIntersections
00298     (
00299         *this,
00300         allSurfaces_,
00301         start,
00302         end,
00303         hitSurfaces,
00304         hitInfo
00305     );
00306 }
00307 
00308 
00309 // Find nearest. Return -1 or nearest point
00310 void Foam::searchableSurfaces::findNearest
00311 (
00312     const pointField& samples,
00313     const scalarField& nearestDistSqr,
00314     labelList& nearestSurfaces,
00315     List<pointIndexHit>& nearestInfo
00316 ) const
00317 {
00318     return searchableSurfacesQueries::findNearest
00319     (
00320         *this,
00321         allSurfaces_,
00322         samples,
00323         nearestDistSqr,
00324         nearestSurfaces,
00325         nearestInfo
00326     );
00327 }
00328 
00329 
00330 //- Calculate point which is on a set of surfaces.
00331 Foam::pointIndexHit Foam::searchableSurfaces::facesIntersection
00332 (
00333     const scalar initDistSqr,
00334     const scalar convergenceDistSqr,
00335     const point& start
00336 ) const
00337 {
00338     return searchableSurfacesQueries::facesIntersection
00339     (
00340         *this,
00341         allSurfaces_,
00342         initDistSqr,
00343         convergenceDistSqr,
00344         start
00345     );
00346 }
00347 
00348 
00349 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd