1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "distanceSurface.H"
27 #include "dictionary.H"
28 #include "volFields.H"
29 #include "volPointInterpolation.H"
30 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(distanceSurface, 0);
38 addToRunTimeSelectionTable(sampledSurface, distanceSurface, word);
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 void Foam::distanceSurface::createGeometry()
47 Pout<< "distanceSurface::createGeometry :updating geometry." << endl;
50 // 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),
95 List<searchableSurface::volumeType> volType;
97 surfPtr_().getVolumeType(cc, volType);
101 searchableSurface::volumeType vT = volType[i];
103 if (vT == searchableSurface::OUTSIDE)
105 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
107 else if (vT == searchableSurface::INSIDE)
109 fld[i] = -Foam::mag(cc[i] - nearest[i].hitPoint());
115 "void Foam::distanceSurface::createGeometry()"
116 ) << "getVolumeType failure, neither INSIDE or OUTSIDE"
125 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
132 forAll(fvm.C().boundaryField(), patchI)
134 const pointField& cc = fvm.C().boundaryField()[patchI];
135 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
137 List<pointIndexHit> nearest;
138 surfPtr_().findNearest
141 scalarField(cc.size(), GREAT),
147 List<searchableSurface::volumeType> volType;
149 surfPtr_().getVolumeType(cc, volType);
153 searchableSurface::volumeType vT = volType[i];
155 if (vT == searchableSurface::OUTSIDE)
157 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
159 else if (vT == searchableSurface::INSIDE)
161 fld[i] = -Foam::mag(cc[i] - nearest[i].hitPoint());
167 "void Foam::distanceSurface::createGeometry()"
168 ) << "getVolumeType failure, "
169 << "neither INSIDE or OUTSIDE"
178 fld[i] = Foam::mag(cc[i] - nearest[i].hitPoint());
185 // On processor patches the mesh.C() will already be the cell centre
186 // on the opposite side so no need to swap cellDistance.
189 // Distance to points
190 pointDistance_.setSize(fvm.nPoints());
192 const pointField& pts = fvm.points();
194 List<pointIndexHit> nearest;
195 surfPtr_().findNearest
198 scalarField(pts.size(), GREAT),
204 List<searchableSurface::volumeType> volType;
206 surfPtr_().getVolumeType(pts, volType);
210 searchableSurface::volumeType vT = volType[i];
212 if (vT == searchableSurface::OUTSIDE)
215 Foam::mag(pts[i] - nearest[i].hitPoint());
217 else if (vT == searchableSurface::INSIDE)
220 -Foam::mag(pts[i] - nearest[i].hitPoint());
226 "void Foam::distanceSurface::createGeometry()"
227 ) << "getVolumeType failure, neither INSIDE or OUTSIDE"
236 pointDistance_[i] = Foam::mag(pts[i]-nearest[i].hitPoint());
244 Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl;
245 cellDistance.write();
246 pointScalarField pDist
251 fvm.time().timeName(),
258 dimensionedScalar("zero", dimLength, 0)
260 pDist.internalField() = pointDistance_;
262 Pout<< "Writing point distance:" << pDist.objectPath() << endl;
267 //- Direct from cell field and point field.
295 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
297 Foam::distanceSurface::distanceSurface
300 const polyMesh& mesh,
301 const dictionary& dict
304 sampledSurface(name, mesh, dict),
307 searchableSurface::New
309 dict.lookup("surfaceType"),
312 dict.lookupOrDefault("surfaceName", name), // name
313 mesh.time().constant(), // directory
314 "triSurface", // instance
315 mesh.time(), // registry
322 distance_(readScalar(dict.lookup("distance"))),
323 signed_(readBool(dict.lookup("signed"))),
324 regularise_(dict.lookupOrDefault("regularise", true)),
325 average_(dict.lookupOrDefault("average", false)),
326 zoneKey_(keyType::null),
331 // dict.readIfPresent("zone", zoneKey_);
333 // if (debug && zoneKey_.size() && mesh.cellZones().findZoneID(zoneKey_) < 0)
335 // Info<< "cellZone " << zoneKey_
336 // << " not found - using entire mesh" << endl;
341 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
343 Foam::distanceSurface::~distanceSurface()
347 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
349 bool Foam::distanceSurface::needsUpdate() const
355 bool Foam::distanceSurface::expire()
359 Pout<< "distanceSurface::expire :"
360 << " have-facesPtr_:" << facesPtr_.valid()
361 << " needsUpdate_:" << needsUpdate_ << endl;
364 // Clear any stored topologies
367 // Clear derived data
370 // already marked as expired
381 bool Foam::distanceSurface::update()
385 Pout<< "distanceSurface::update :"
386 << " have-facesPtr_:" << facesPtr_.valid()
387 << " needsUpdate_:" << needsUpdate_ << endl;
397 needsUpdate_ = false;
402 Foam::tmp<Foam::scalarField> Foam::distanceSurface::sample
404 const volScalarField& vField
407 return sampleField(vField);
411 Foam::tmp<Foam::vectorField> Foam::distanceSurface::sample
413 const volVectorField& vField
416 return sampleField(vField);
420 Foam::tmp<Foam::sphericalTensorField> Foam::distanceSurface::sample
422 const volSphericalTensorField& vField
425 return sampleField(vField);
429 Foam::tmp<Foam::symmTensorField> Foam::distanceSurface::sample
431 const volSymmTensorField& vField
434 return sampleField(vField);
438 Foam::tmp<Foam::tensorField> Foam::distanceSurface::sample
440 const volTensorField& vField
443 return sampleField(vField);
447 Foam::tmp<Foam::scalarField> Foam::distanceSurface::interpolate
449 const interpolation<scalar>& interpolator
452 return interpolateField(interpolator);
456 Foam::tmp<Foam::vectorField> Foam::distanceSurface::interpolate
458 const interpolation<vector>& interpolator
461 return interpolateField(interpolator);
464 Foam::tmp<Foam::sphericalTensorField> Foam::distanceSurface::interpolate
466 const interpolation<sphericalTensor>& interpolator
469 return interpolateField(interpolator);
473 Foam::tmp<Foam::symmTensorField> Foam::distanceSurface::interpolate
475 const interpolation<symmTensor>& interpolator
478 return interpolateField(interpolator);
482 Foam::tmp<Foam::tensorField> Foam::distanceSurface::interpolate
484 const interpolation<tensor>& interpolator
487 return interpolateField(interpolator);
491 void Foam::distanceSurface::print(Ostream& os) const
493 os << "distanceSurface: " << name() << " :"
494 << " surface:" << surfPtr_().name()
495 << " distance:" << distance_
496 << " faces:" << faces().size()
497 << " points:" << points().size();
501 // ************************************************************************* //