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 "distanceSurface.H"
00028 #include "dictionary.H"
00029 #include "volFields.H"
00030 #include "volPointInterpolation.H"
00031 #include "addToRunTimeSelectionTable.H"
00032 #include "fvMesh.H"
00033 #include "isoSurface.H"
00034
00035
00036
00037
00038 namespace Foam
00039 {
00040 defineTypeNameAndDebug(distanceSurface, 0);
00041 addToRunTimeSelectionTable(sampledSurface, distanceSurface, word);
00042 }
00043
00044
00045
00046 void Foam::distanceSurface::createGeometry()
00047 {
00048 if (debug)
00049 {
00050 Pout<< "distanceSurface::createGeometry :updating geometry." << endl;
00051 }
00052
00053
00054 facesPtr_.clear();
00055
00056 const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
00057
00058
00059
00060
00061 cellDistancePtr_.reset
00062 (
00063 new volScalarField
00064 (
00065 IOobject
00066 (
00067 "cellDistance",
00068 fvm.time().timeName(),
00069 fvm.time(),
00070 IOobject::NO_READ,
00071 IOobject::NO_WRITE,
00072 false
00073 ),
00074 fvm,
00075 dimensionedScalar("zero", dimLength, 0)
00076 )
00077 );
00078 volScalarField& cellDistance = cellDistancePtr_();
00079
00080
00081 {
00082 const pointField& cc = fvm.C();
00083 scalarField& fld = cellDistance.internalField();
00084
00085 List<pointIndexHit> nearest;
00086 surfPtr_().findNearest
00087 (
00088 cc,
00089 scalarField(cc.size(), GREAT),
00090 nearest
00091 );
00092
00093 if (signed_)
00094 {
00095 vectorField normal;
00096 surfPtr_().getNormal(nearest, normal);
00097
00098 forAll(nearest, i)
00099 {
00100 vector d(cc[i]-nearest[i].hitPoint());
00101
00102 if ((d&normal[i]) > 0)
00103 {
00104 fld[i] = Foam::mag(d);
00105 }
00106 else
00107 {
00108 fld[i] = -Foam::mag(d);
00109 }
00110 }
00111 }
00112 else
00113 {
00114 forAll(nearest, i)
00115 {
00116 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
00117 }
00118 }
00119 }
00120
00121
00122 {
00123 forAll(fvm.C().boundaryField(), patchI)
00124 {
00125 const pointField& cc = fvm.C().boundaryField()[patchI];
00126 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
00127
00128 List<pointIndexHit> nearest;
00129 surfPtr_().findNearest
00130 (
00131 cc,
00132 scalarField(cc.size(), GREAT),
00133 nearest
00134 );
00135
00136 if (signed_)
00137 {
00138 vectorField normal;
00139 surfPtr_().getNormal(nearest, normal);
00140
00141 forAll(nearest, i)
00142 {
00143 vector d(cc[i]-nearest[i].hitPoint());
00144
00145 if ((d&normal[i]) > 0)
00146 {
00147 fld[i] = Foam::mag(d);
00148 }
00149 else
00150 {
00151 fld[i] = -Foam::mag(d);
00152 }
00153 }
00154 }
00155 else
00156 {
00157 forAll(nearest, i)
00158 {
00159 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
00160 }
00161 }
00162 }
00163 }
00164
00165
00166
00167
00168
00169
00170
00171 pointDistance_.setSize(fvm.nPoints());
00172 {
00173 const pointField& pts = fvm.points();
00174
00175 List<pointIndexHit> nearest;
00176 surfPtr_().findNearest
00177 (
00178 pts,
00179 scalarField(pts.size(), GREAT),
00180 nearest
00181 );
00182
00183 if (signed_)
00184 {
00185 vectorField normal;
00186 surfPtr_().getNormal(nearest, normal);
00187
00188 forAll(nearest, i)
00189 {
00190 vector d(pts[i]-nearest[i].hitPoint());
00191
00192 if ((d&normal[i]) > 0)
00193 {
00194 pointDistance_[i] = Foam::mag(d);
00195 }
00196 else
00197 {
00198 pointDistance_[i] = -Foam::mag(d);
00199 }
00200 }
00201 }
00202 else
00203 {
00204 forAll(nearest, i)
00205 {
00206 pointDistance_[i] = Foam::mag(pts[i]-nearest[i].hitPoint());
00207 }
00208 }
00209 }
00210
00211
00212 if (debug)
00213 {
00214 Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl;
00215 cellDistance.write();
00216 pointScalarField pDist
00217 (
00218 IOobject
00219 (
00220 "pointDistance",
00221 fvm.time().timeName(),
00222 fvm.time(),
00223 IOobject::NO_READ,
00224 IOobject::NO_WRITE,
00225 false
00226 ),
00227 pointMesh::New(fvm),
00228 dimensionedScalar("zero", dimLength, 0)
00229 );
00230 pDist.internalField() = pointDistance_;
00231
00232 Pout<< "Writing point distance:" << pDist.objectPath() << endl;
00233 pDist.write();
00234 }
00235
00236
00237
00238 isoSurfPtr_.reset
00239 (
00240 new isoSurface
00241 (
00242 cellDistance,
00243 pointDistance_,
00244 distance_,
00245 regularise_
00246 )
00247 );
00248
00249 if (debug)
00250 {
00251 print(Pout);
00252 Pout<< endl;
00253 }
00254 }
00255
00256
00257
00258
00259 Foam::distanceSurface::distanceSurface
00260 (
00261 const word& name,
00262 const polyMesh& mesh,
00263 const dictionary& dict
00264 )
00265 :
00266 sampledSurface(name, mesh, dict),
00267 surfPtr_
00268 (
00269 searchableSurface::New
00270 (
00271 dict.lookup("surfaceType"),
00272 IOobject
00273 (
00274 dict.lookupOrDefault("surfaceName", name),
00275 mesh.time().constant(),
00276 "triSurface",
00277 mesh.time(),
00278 IOobject::MUST_READ,
00279 IOobject::NO_WRITE
00280 ),
00281 dict
00282 )
00283 ),
00284 distance_(readScalar(dict.lookup("distance"))),
00285 signed_(readBool(dict.lookup("signed"))),
00286 regularise_(dict.lookupOrDefault("regularise", true)),
00287 zoneName_(word::null),
00288 needsUpdate_(true),
00289 isoSurfPtr_(NULL),
00290 facesPtr_(NULL)
00291 {
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 }
00303
00304
00305
00306
00307 Foam::distanceSurface::~distanceSurface()
00308 {}
00309
00310
00311
00312
00313 bool Foam::distanceSurface::needsUpdate() const
00314 {
00315 return needsUpdate_;
00316 }
00317
00318
00319 bool Foam::distanceSurface::expire()
00320 {
00321 if (debug)
00322 {
00323 Pout<< "distanceSurface::expire :"
00324 << " have-facesPtr_:" << facesPtr_.valid()
00325 << " needsUpdate_:" << needsUpdate_ << endl;
00326 }
00327
00328
00329 facesPtr_.clear();
00330
00331
00332 if (needsUpdate_)
00333 {
00334 return false;
00335 }
00336
00337 needsUpdate_ = true;
00338 return true;
00339 }
00340
00341
00342 bool Foam::distanceSurface::update()
00343 {
00344 if (debug)
00345 {
00346 Pout<< "distanceSurface::update :"
00347 << " have-facesPtr_:" << facesPtr_.valid()
00348 << " needsUpdate_:" << needsUpdate_ << endl;
00349 }
00350
00351 if (!needsUpdate_)
00352 {
00353 return false;
00354 }
00355
00356 createGeometry();
00357
00358 needsUpdate_ = false;
00359 return true;
00360 }
00361
00362
00363 Foam::tmp<Foam::scalarField>
00364 Foam::distanceSurface::sample
00365 (
00366 const volScalarField& vField
00367 ) const
00368 {
00369 return sampleField(vField);
00370 }
00371
00372
00373 Foam::tmp<Foam::vectorField>
00374 Foam::distanceSurface::sample
00375 (
00376 const volVectorField& vField
00377 ) const
00378 {
00379 return sampleField(vField);
00380 }
00381
00382
00383 Foam::tmp<Foam::sphericalTensorField>
00384 Foam::distanceSurface::sample
00385 (
00386 const volSphericalTensorField& vField
00387 ) const
00388 {
00389 return sampleField(vField);
00390 }
00391
00392
00393 Foam::tmp<Foam::symmTensorField>
00394 Foam::distanceSurface::sample
00395 (
00396 const volSymmTensorField& vField
00397 ) const
00398 {
00399 return sampleField(vField);
00400 }
00401
00402
00403 Foam::tmp<Foam::tensorField>
00404 Foam::distanceSurface::sample
00405 (
00406 const volTensorField& vField
00407 ) const
00408 {
00409 return sampleField(vField);
00410 }
00411
00412
00413 Foam::tmp<Foam::scalarField>
00414 Foam::distanceSurface::interpolate
00415 (
00416 const interpolation<scalar>& interpolator
00417 ) const
00418 {
00419 return interpolateField(interpolator);
00420 }
00421
00422
00423 Foam::tmp<Foam::vectorField>
00424 Foam::distanceSurface::interpolate
00425 (
00426 const interpolation<vector>& interpolator
00427 ) const
00428 {
00429 return interpolateField(interpolator);
00430 }
00431
00432 Foam::tmp<Foam::sphericalTensorField>
00433 Foam::distanceSurface::interpolate
00434 (
00435 const interpolation<sphericalTensor>& interpolator
00436 ) const
00437 {
00438 return interpolateField(interpolator);
00439 }
00440
00441
00442 Foam::tmp<Foam::symmTensorField>
00443 Foam::distanceSurface::interpolate
00444 (
00445 const interpolation<symmTensor>& interpolator
00446 ) const
00447 {
00448 return interpolateField(interpolator);
00449 }
00450
00451
00452 Foam::tmp<Foam::tensorField>
00453 Foam::distanceSurface::interpolate
00454 (
00455 const interpolation<tensor>& interpolator
00456 ) const
00457 {
00458 return interpolateField(interpolator);
00459 }
00460
00461
00462 void Foam::distanceSurface::print(Ostream& os) const
00463 {
00464 os << "distanceSurface: " << name() << " :"
00465 << " surface:" << surfPtr_().name()
00466 << " distance:" << distance_
00467 << " faces:" << faces().size()
00468 << " points:" << points().size();
00469 }
00470
00471
00472