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 #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
00042
00043
00044 Foam::searchableSurfaces::searchableSurfaces(const label size)
00045 :
00046 PtrList<searchableSurface>(size),
00047 regionNames_(size),
00048 allSurfaces_(identity(size))
00049 {}
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 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
00180 autoPtr<IOobject> namedIO(io.clone());
00181
00182
00183
00184
00185
00186 namedIO().rename(key);
00187
00188
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
00202
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
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
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
00250 PtrList<searchableSurface>::setSize(surfI);
00251 names_.setSize(surfI);
00252 regionNames_.setSize(surfI);
00253 allSurfaces_.setSize(surfI);
00254 }
00255
00256
00257
00258
00259 Foam::label Foam::searchableSurfaces::findSurfaceID(const word& wantedName)
00260 const
00261 {
00262 return findIndex(names_, wantedName);
00263 }
00264
00265
00266
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
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
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
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