1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
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 "sampledCuttingPlane.H"
28 #include "dictionary.H"
29 #include "volFields.H"
30 #include "volPointInterpolation.H"
31 #include "addToRunTimeSelectionTable.H"
33 #include "isoSurface.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(sampledCuttingPlane, 0);
40 addNamedToRunTimeSelectionTable
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 void Foam::sampledCuttingPlane::createGeometry()
55 Pout<< "sampledCuttingPlane::createGeometry :updating geometry."
59 // Clear any stored topologies
62 pointDistance_.clear();
63 cellDistancePtr_.clear();
67 if (zoneID_.index() != -1 && !subMeshPtr_.valid())
69 const polyBoundaryMesh& patches = mesh().boundaryMesh();
71 // Patch to put exposed internal faces into
72 label exposedPatchI = patches.findPatchID(exposedPatchName_);
76 Info<< "Allocating subset of size "
77 << mesh().cellZones()[zoneID_.index()].size()
78 << " with exposed faces into patch "
79 << patches[exposedPatchI].name() << endl;
84 new fvMeshSubset(static_cast<const fvMesh&>(mesh()))
86 subMeshPtr_().setLargeCellSubset
88 labelHashSet(mesh().cellZones()[zoneID_.index()]),
94 // Select either the submesh or the underlying mesh
98 ? subMeshPtr_().subMesh()
99 : static_cast<const fvMesh&>(mesh())
103 // Distance to cell centres
104 // ~~~~~~~~~~~~~~~~~~~~~~~~
106 cellDistancePtr_.reset
113 fvm.time().timeName(),
120 dimensionedScalar("zero", dimLength, 0)
123 volScalarField& cellDistance = cellDistancePtr_();
127 const pointField& cc = fvm.cellCentres();
128 scalarField& fld = cellDistance.internalField();
133 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
139 forAll(cellDistance.boundaryField(), patchI)
143 isA<emptyFvPatchScalarField>
145 cellDistance.boundaryField()[patchI]
149 cellDistance.boundaryField().set
152 new calculatedFvPatchScalarField
154 fvm.boundary()[patchI],
159 const polyPatch& pp = fvm.boundary()[patchI].patch();
160 pointField::subField cc = pp.patchSlice(fvm.faceCentres());
162 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
163 fld.setSize(pp.size());
166 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
171 const pointField& cc = fvm.C().boundaryField()[patchI];
172 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
176 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
183 // On processor patches the mesh.C() will already be the cell centre
184 // on the opposite side so no need to swap cellDistance.
187 // Distance to points
188 pointDistance_.setSize(fvm.nPoints());
190 const pointField& pts = fvm.points();
192 forAll(pointDistance_, i)
194 pointDistance_[i] = (pts[i] - plane_.refPoint()) & plane_.normal();
201 Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl;
202 cellDistance.write();
203 pointScalarField pDist
208 fvm.time().timeName(),
215 dimensionedScalar("zero", dimLength, 0)
217 pDist.internalField() = pointDistance_;
219 Pout<< "Writing point distance:" << pDist.objectPath() << endl;
224 //- Direct from cell field and point field.
244 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
246 Foam::sampledCuttingPlane::sampledCuttingPlane
249 const polyMesh& mesh,
250 const dictionary& dict
253 sampledSurface(name, mesh, dict),
255 mergeTol_(dict.lookupOrDefault("mergeTol", 1E-6)),
256 regularise_(dict.lookupOrDefault("regularise", true)),
257 zoneID_(dict.lookupOrDefault("zone", word::null), mesh.cellZones()),
258 exposedPatchName_(word::null),
261 cellDistancePtr_(NULL),
265 if (zoneID_.index() != -1)
267 dict.lookup("exposedPatchName") >> exposedPatchName_;
269 if (mesh.boundaryMesh().findPatchID(exposedPatchName_) == -1)
273 "sampledCuttingPlane::sampledCuttingPlane"
274 "(const word&, const polyMesh&, const dictionary&)"
275 ) << "Cannot find patch " << exposedPatchName_
276 << " in which to put exposed faces." << endl
277 << "Valid patches are " << mesh.boundaryMesh().names()
281 if (debug && zoneID_.index() != -1)
283 Info<< "Restricting to cellZone " << zoneID_.name()
284 << " with exposed internal faces into patch "
285 << exposedPatchName_ << endl;
291 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
293 Foam::sampledCuttingPlane::~sampledCuttingPlane()
297 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
299 bool Foam::sampledCuttingPlane::needsUpdate() const
305 bool Foam::sampledCuttingPlane::expire()
309 Pout<< "sampledCuttingPlane::expire :"
310 << " have-facesPtr_:" << facesPtr_.valid()
311 << " needsUpdate_:" << needsUpdate_ << endl;
314 // Clear any stored topologies
317 // already marked as expired
328 bool Foam::sampledCuttingPlane::update()
332 Pout<< "sampledCuttingPlane::update :"
333 << " have-facesPtr_:" << facesPtr_.valid()
334 << " needsUpdate_:" << needsUpdate_ << endl;
344 needsUpdate_ = false;
349 Foam::tmp<Foam::scalarField>
350 Foam::sampledCuttingPlane::sample
352 const volScalarField& vField
355 return sampleField(vField);
359 Foam::tmp<Foam::vectorField>
360 Foam::sampledCuttingPlane::sample
362 const volVectorField& vField
365 return sampleField(vField);
369 Foam::tmp<Foam::sphericalTensorField>
370 Foam::sampledCuttingPlane::sample
372 const volSphericalTensorField& vField
375 return sampleField(vField);
379 Foam::tmp<Foam::symmTensorField>
380 Foam::sampledCuttingPlane::sample
382 const volSymmTensorField& vField
385 return sampleField(vField);
389 Foam::tmp<Foam::tensorField>
390 Foam::sampledCuttingPlane::sample
392 const volTensorField& vField
395 return sampleField(vField);
399 Foam::tmp<Foam::scalarField>
400 Foam::sampledCuttingPlane::interpolate
402 const interpolation<scalar>& interpolator
405 return interpolateField(interpolator);
409 Foam::tmp<Foam::vectorField>
410 Foam::sampledCuttingPlane::interpolate
412 const interpolation<vector>& interpolator
415 return interpolateField(interpolator);
418 Foam::tmp<Foam::sphericalTensorField>
419 Foam::sampledCuttingPlane::interpolate
421 const interpolation<sphericalTensor>& interpolator
424 return interpolateField(interpolator);
428 Foam::tmp<Foam::symmTensorField>
429 Foam::sampledCuttingPlane::interpolate
431 const interpolation<symmTensor>& interpolator
434 return interpolateField(interpolator);
438 Foam::tmp<Foam::tensorField>
439 Foam::sampledCuttingPlane::interpolate
441 const interpolation<tensor>& interpolator
444 return interpolateField(interpolator);
448 void Foam::sampledCuttingPlane::print(Ostream& os) const
450 os << "sampledCuttingPlane: " << name() << " :"
451 << " plane:" << plane_
452 << " faces:" << faces().size()
453 << " points:" << points().size();
457 // ************************************************************************* //