FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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