00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00043
00044
00045 Foam::searchableSurfaces::searchableSurfaces(const label size)
00046 :
00047 PtrList<searchableSurface>(size),
00048 regionNames_(size),
00049 allSurfaces_(identity(size))
00050 {}
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
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
00181 autoPtr<IOobject> namedIO(io.clone());
00182
00183
00184
00185
00186
00187 namedIO().rename(key);
00188
00189
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
00203
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
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
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
00251 PtrList<searchableSurface>::setSize(surfI);
00252 names_.setSize(surfI);
00253 regionNames_.setSize(surfI);
00254 allSurfaces_.setSize(surfI);
00255 }
00256
00257
00258
00259
00260 Foam::label Foam::searchableSurfaces::findSurfaceID(const word& wantedName)
00261 const
00262 {
00263 return findIndex(names_, wantedName);
00264 }
00265
00266
00267
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
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
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
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