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 "distanceSurface.H"
28 #include "dictionary.H"
29 #include "volFields.H"
30 #include "volPointInterpolation.H"
31 #include "addToRunTimeSelectionTable.H"
33 #include "isoSurface.H"
34 // #include "isoSurfaceCell.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 defineTypeNameAndDebug(distanceSurface, 0);
41 addToRunTimeSelectionTable(sampledSurface, distanceSurface, word);
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 void Foam::distanceSurface::createGeometry()
50 Pout<< "distanceSurface::createGeometry :updating geometry." << endl;
53 // Clear any stored topologies
56 const fvMesh& fvm = static_cast<const fvMesh&>(mesh());
58 // Distance to cell centres
59 // ~~~~~~~~~~~~~~~~~~~~~~~~
61 cellDistancePtr_.reset
68 fvm.time().timeName(),
75 dimensionedScalar("zero", dimLength, 0)
78 volScalarField& cellDistance = cellDistancePtr_();
82 const pointField& cc = fvm.C();
83 scalarField& fld = cellDistance.internalField();
85 List<pointIndexHit> nearest;
86 surfPtr_().findNearest
89 scalarField(cc.size(), GREAT),
96 surfPtr_().getNormal(nearest, normal);
100 vector d(cc[i]-nearest[i].hitPoint());
102 if ((d&normal[i]) > 0)
104 fld[i] = Foam::mag(d);
108 fld[i] = -Foam::mag(d);
116 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
123 forAll(fvm.C().boundaryField(), patchI)
125 const pointField& cc = fvm.C().boundaryField()[patchI];
126 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
128 List<pointIndexHit> nearest;
129 surfPtr_().findNearest
132 scalarField(cc.size(), GREAT),
139 surfPtr_().getNormal(nearest, normal);
143 vector d(cc[i]-nearest[i].hitPoint());
145 if ((d&normal[i]) > 0)
147 fld[i] = Foam::mag(d);
151 fld[i] = -Foam::mag(d);
159 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
166 // On processor patches the mesh.C() will already be the cell centre
167 // on the opposite side so no need to swap cellDistance.
170 // Distance to points
171 pointDistance_.setSize(fvm.nPoints());
173 const pointField& pts = fvm.points();
175 List<pointIndexHit> nearest;
176 surfPtr_().findNearest
179 scalarField(pts.size(), GREAT),
186 surfPtr_().getNormal(nearest, normal);
190 vector d(pts[i]-nearest[i].hitPoint());
192 if ((d&normal[i]) > 0)
194 pointDistance_[i] = Foam::mag(d);
198 pointDistance_[i] = -Foam::mag(d);
206 pointDistance_[i] = Foam::mag(pts[i]-nearest[i].hitPoint());
214 Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl;
215 cellDistance.write();
216 pointScalarField pDist
221 fvm.time().timeName(),
228 dimensionedScalar("zero", dimLength, 0)
230 pDist.internalField() = pointDistance_;
232 Pout<< "Writing point distance:" << pDist.objectPath() << endl;
237 //- Direct from cell field and point field.
257 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
259 Foam::distanceSurface::distanceSurface
262 const polyMesh& mesh,
263 const dictionary& dict
266 sampledSurface(name, mesh, dict),
269 searchableSurface::New
271 dict.lookup("surfaceType"),
274 dict.lookupOrDefault("surfaceName", name), // name
275 mesh.time().constant(), // directory
276 "triSurface", // instance
277 mesh.time(), // registry
284 distance_(readScalar(dict.lookup("distance"))),
285 signed_(readBool(dict.lookup("signed"))),
286 regularise_(dict.lookupOrDefault("regularise", true)),
287 zoneName_(word::null),
292 // dict.readIfPresent("zone", zoneName_);
294 // if (debug && zoneName_.size())
296 // if (mesh.cellZones().findZoneID(zoneName_) < 0)
298 // Info<< "cellZone \"" << zoneName_
299 // << "\" not found - using entire mesh" << endl;
305 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
307 Foam::distanceSurface::~distanceSurface()
311 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
313 bool Foam::distanceSurface::needsUpdate() const
319 bool Foam::distanceSurface::expire()
323 Pout<< "distanceSurface::expire :"
324 << " have-facesPtr_:" << facesPtr_.valid()
325 << " needsUpdate_:" << needsUpdate_ << endl;
328 // Clear any stored topologies
331 // already marked as expired
342 bool Foam::distanceSurface::update()
346 Pout<< "distanceSurface::update :"
347 << " have-facesPtr_:" << facesPtr_.valid()
348 << " needsUpdate_:" << needsUpdate_ << endl;
358 needsUpdate_ = false;
363 Foam::tmp<Foam::scalarField>
364 Foam::distanceSurface::sample
366 const volScalarField& vField
369 return sampleField(vField);
373 Foam::tmp<Foam::vectorField>
374 Foam::distanceSurface::sample
376 const volVectorField& vField
379 return sampleField(vField);
383 Foam::tmp<Foam::sphericalTensorField>
384 Foam::distanceSurface::sample
386 const volSphericalTensorField& vField
389 return sampleField(vField);
393 Foam::tmp<Foam::symmTensorField>
394 Foam::distanceSurface::sample
396 const volSymmTensorField& vField
399 return sampleField(vField);
403 Foam::tmp<Foam::tensorField>
404 Foam::distanceSurface::sample
406 const volTensorField& vField
409 return sampleField(vField);
413 Foam::tmp<Foam::scalarField>
414 Foam::distanceSurface::interpolate
416 const interpolation<scalar>& interpolator
419 return interpolateField(interpolator);
423 Foam::tmp<Foam::vectorField>
424 Foam::distanceSurface::interpolate
426 const interpolation<vector>& interpolator
429 return interpolateField(interpolator);
432 Foam::tmp<Foam::sphericalTensorField>
433 Foam::distanceSurface::interpolate
435 const interpolation<sphericalTensor>& interpolator
438 return interpolateField(interpolator);
442 Foam::tmp<Foam::symmTensorField>
443 Foam::distanceSurface::interpolate
445 const interpolation<symmTensor>& interpolator
448 return interpolateField(interpolator);
452 Foam::tmp<Foam::tensorField>
453 Foam::distanceSurface::interpolate
455 const interpolation<tensor>& interpolator
458 return interpolateField(interpolator);
462 void Foam::distanceSurface::print(Ostream& os) const
464 os << "distanceSurface: " << name() << " :"
465 << " surface:" << surfPtr_().name()
466 << " distance:" << distance_
467 << " faces:" << faces().size()
468 << " points:" << points().size();
472 // ************************************************************************* //