1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*----------------------------------------------------------------------------*/
27 #include "searchableSurfaces.H"
28 #include "searchableSurfacesQueries.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(searchableSurfaces, 0);
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 // Construct with length.
45 Foam::searchableSurfaces::searchableSurfaces(const label size)
47 PtrList<searchableSurface>(size),
49 allSurfaces_(identity(size))
53 //Foam::searchableSurfaces::searchableSurfaces
55 // const IOobject& io,
56 // const PtrList<dictionary>& dicts
59 // PtrList<searchableSurface>(dicts.size()),
60 // regionNames_(dicts.size()),
61 // allSurfaces_(identity(dicts.size()))
63 // forAll(dicts, surfI)
65 // const dictionary& dict = dicts[surfI];
67 // // Make IOobject with correct name
68 // autoPtr<IOobject> namedIO(io.clone());
69 // namedIO().rename(dict.lookup("name"));
71 // // Create and hook surface
75 // searchableSurface::New
77 // dict.lookup("type"),
82 // const searchableSurface& s = operator[](surfI);
84 // // Construct default region names by prepending surface name
86 // const wordList& localNames = s.regions();
88 // wordList globalNames(localNames.size());
89 // forAll(localNames, regionI)
91 // globalNames[regionI] = s.name() + '_' + localNames[regionI];
94 // // See if dictionary provides any global region names.
95 // if (dict.found("regions"))
97 // const dictionary& regionsDict = dict.subDict("regions");
99 // forAllConstIter(dictionary, regionsDict, iter)
101 // const word& key = iter().keyword();
103 // if (regionsDict.isDict(key))
105 // // Get the dictionary for region iter.key()
106 // const dictionary& regionDict = regionsDict.subDict(key);
108 // label index = findIndex(localNames, key);
114 // "searchableSurfaces::searchableSurfaces"
115 // "( const IOobject&, const dictionary&)"
116 // ) << "Unknown region name " << key
117 // << " for surface " << s.name() << endl
118 // << "Valid region names are " << localNames
119 // << exit(FatalError);
122 // globalNames[index] = word(regionDict.lookup("name"));
127 // // Now globalNames contains the names of the regions.
128 // Info<< "Surface:" << s.name() << " has regions:"
130 // forAll(globalNames, regionI)
132 // Info<< " " << globalNames[regionI] << endl;
135 // // Create reverse lookup
136 // forAll(globalNames, regionI)
138 // regionNames_.insert
140 // globalNames[regionI],
141 // labelPair(surfI, regionI)
148 Foam::searchableSurfaces::searchableSurfaces
151 const dictionary& topDict
154 PtrList<searchableSurface>(topDict.size()),
155 names_(topDict.size()),
156 regionNames_(topDict.size()),
157 allSurfaces_(identity(topDict.size()))
160 forAllConstIter(dictionary, topDict, iter)
162 const word& key = iter().keyword();
164 if (!topDict.isDict(key))
168 "searchableSurfaces::searchableSurfaces"
169 "( const IOobject&, const dictionary&)"
170 ) << "Found non-dictionary entry " << iter()
171 << " in top-level dictionary " << topDict
175 const dictionary& dict = topDict.subDict(key);
178 dict.readIfPresent("name", names_[surfI]);
180 // Make IOobject with correct name
181 autoPtr<IOobject> namedIO(io.clone());
182 // Note: we would like to e.g. register triSurface 'sphere.stl' as
183 // 'sphere'. Unfortunately
184 // no support for having object read from different location than
185 // their object name. Maybe have stlTriSurfaceMesh which appends .stl
186 // when reading/writing?
187 namedIO().rename(key); // names_[surfI]
189 // Create and hook surface
193 searchableSurface::New
200 const searchableSurface& s = operator[](surfI);
202 // Construct default region names by prepending surface name
204 const wordList& localNames = s.regions();
206 wordList& rNames = regionNames_[surfI];
207 rNames.setSize(localNames.size());
209 forAll(localNames, regionI)
211 rNames[regionI] = names_[surfI] + '_' + localNames[regionI];
214 // See if dictionary provides any global region names.
215 if (dict.found("regions"))
217 const dictionary& regionsDict = dict.subDict("regions");
219 forAllConstIter(dictionary, regionsDict, iter)
221 const word& key = iter().keyword();
223 if (regionsDict.isDict(key))
225 // Get the dictionary for region iter.keyword()
226 const dictionary& regionDict = regionsDict.subDict(key);
228 label index = findIndex(localNames, key);
234 "searchableSurfaces::searchableSurfaces"
235 "( const IOobject&, const dictionary&)"
236 ) << "Unknown region name " << key
237 << " for surface " << s.name() << endl
238 << "Valid region names are " << localNames
242 rNames[index] = word(regionDict.lookup("name"));
250 // Trim (not really necessary since we don't allow non-dictionary entries)
251 PtrList<searchableSurface>::setSize(surfI);
252 names_.setSize(surfI);
253 regionNames_.setSize(surfI);
254 allSurfaces_.setSize(surfI);
258 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
260 Foam::label Foam::searchableSurfaces::findSurfaceID(const word& wantedName)
263 return findIndex(names_, wantedName);
267 // Find any intersection
268 void Foam::searchableSurfaces::findAnyIntersection
270 const pointField& start,
271 const pointField& end,
272 labelList& hitSurfaces,
273 List<pointIndexHit>& hitInfo
276 searchableSurfacesQueries::findAnyIntersection
288 // Find intersections of edge nearest to both endpoints.
289 void Foam::searchableSurfaces::findAllIntersections
291 const pointField& start,
292 const pointField& end,
293 labelListList& hitSurfaces,
294 List<List<pointIndexHit> >& hitInfo
297 searchableSurfacesQueries::findAllIntersections
309 // Find nearest. Return -1 or nearest point
310 void Foam::searchableSurfaces::findNearest
312 const pointField& samples,
313 const scalarField& nearestDistSqr,
314 labelList& nearestSurfaces,
315 List<pointIndexHit>& nearestInfo
318 return searchableSurfacesQueries::findNearest
330 //- Calculate point which is on a set of surfaces.
331 Foam::pointIndexHit Foam::searchableSurfaces::facesIntersection
333 const scalar initDistSqr,
334 const scalar convergenceDistSqr,
338 return searchableSurfacesQueries::facesIntersection
349 // ************************************************************************* //