1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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
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 "sampledCuttingPlane.H"
27 #include "dictionary.H"
28 #include "volFields.H"
29 #include "volPointInterpolation.H"
30 #include "addToRunTimeSelectionTable.H"
32 #include "isoSurface.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(sampledCuttingPlane, 0);
39 addNamedToRunTimeSelectionTable
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 void Foam::sampledCuttingPlane::createGeometry()
54 Pout<< "sampledCuttingPlane::createGeometry :updating geometry."
58 // Clear any stored topologies
61 pointDistance_.clear();
62 cellDistancePtr_.clear();
68 if (zoneID_.index() != -1 && !subMeshPtr_.valid())
70 const polyBoundaryMesh& patches = mesh().boundaryMesh();
72 // Patch to put exposed internal faces into
73 label exposedPatchI = patches.findPatchID(exposedPatchName_);
77 Info<< "Allocating subset of size "
78 << mesh().cellZones()[zoneID_.index()].size()
79 << " with exposed faces into patch "
80 << patches[exposedPatchI].name() << endl;
85 new fvMeshSubset(static_cast<const fvMesh&>(mesh()))
87 subMeshPtr_().setLargeCellSubset
89 labelHashSet(mesh().cellZones()[zoneID_.index()]),
95 // Select either the submesh or the underlying mesh
99 ? subMeshPtr_().subMesh()
100 : static_cast<const fvMesh&>(mesh())
104 // Distance to cell centres
105 // ~~~~~~~~~~~~~~~~~~~~~~~~
107 cellDistancePtr_.reset
114 fvm.time().timeName(),
121 dimensionedScalar("zero", dimLength, 0)
124 volScalarField& cellDistance = cellDistancePtr_();
128 const pointField& cc = fvm.cellCentres();
129 scalarField& fld = cellDistance.internalField();
134 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
140 forAll(cellDistance.boundaryField(), patchI)
144 isA<emptyFvPatchScalarField>
146 cellDistance.boundaryField()[patchI]
150 cellDistance.boundaryField().set
153 new calculatedFvPatchScalarField
155 fvm.boundary()[patchI],
160 const polyPatch& pp = fvm.boundary()[patchI].patch();
161 pointField::subField cc = pp.patchSlice(fvm.faceCentres());
163 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
164 fld.setSize(pp.size());
167 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
172 const pointField& cc = fvm.C().boundaryField()[patchI];
173 fvPatchScalarField& fld = cellDistance.boundaryField()[patchI];
177 fld[i] = (cc[i] - plane_.refPoint()) & plane_.normal();
184 // On processor patches the mesh.C() will already be the cell centre
185 // on the opposite side so no need to swap cellDistance.
188 // Distance to points
189 pointDistance_.setSize(fvm.nPoints());
191 const pointField& pts = fvm.points();
193 forAll(pointDistance_, i)
195 pointDistance_[i] = (pts[i] - plane_.refPoint()) & plane_.normal();
202 Pout<< "Writing cell distance:" << cellDistance.objectPath() << endl;
203 cellDistance.write();
204 pointScalarField pDist
209 fvm.time().timeName(),
216 dimensionedScalar("zero", dimLength, 0)
218 pDist.internalField() = pointDistance_;
220 Pout<< "Writing point distance:" << pDist.objectPath() << endl;
225 //- Direct from cell field and point field.
245 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
247 Foam::sampledCuttingPlane::sampledCuttingPlane
250 const polyMesh& mesh,
251 const dictionary& dict
254 sampledSurface(name, mesh, dict),
256 mergeTol_(dict.lookupOrDefault("mergeTol", 1E-6)),
257 regularise_(dict.lookupOrDefault("regularise", true)),
258 zoneID_(dict.lookupOrDefault("zone", word::null), mesh.cellZones()),
259 exposedPatchName_(word::null),
262 cellDistancePtr_(NULL),
266 if (zoneID_.index() != -1)
268 dict.lookup("exposedPatchName") >> exposedPatchName_;
270 if (mesh.boundaryMesh().findPatchID(exposedPatchName_) == -1)
274 "sampledCuttingPlane::sampledCuttingPlane"
275 "(const word&, const polyMesh&, const dictionary&)"
276 ) << "Cannot find patch " << exposedPatchName_
277 << " in which to put exposed faces." << endl
278 << "Valid patches are " << mesh.boundaryMesh().names()
282 if (debug && zoneID_.index() != -1)
284 Info<< "Restricting to cellZone " << zoneID_.name()
285 << " with exposed internal faces into patch "
286 << exposedPatchName_ << endl;
292 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
294 Foam::sampledCuttingPlane::~sampledCuttingPlane()
298 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
300 bool Foam::sampledCuttingPlane::needsUpdate() const
306 bool Foam::sampledCuttingPlane::expire()
310 Pout<< "sampledCuttingPlane::expire :"
311 << " have-facesPtr_:" << facesPtr_.valid()
312 << " needsUpdate_:" << needsUpdate_ << endl;
315 // Clear any stored topologies
318 // Clear derived data
321 // already marked as expired
332 bool Foam::sampledCuttingPlane::update()
336 Pout<< "sampledCuttingPlane::update :"
337 << " have-facesPtr_:" << facesPtr_.valid()
338 << " needsUpdate_:" << needsUpdate_ << endl;
348 needsUpdate_ = false;
353 Foam::tmp<Foam::scalarField>
354 Foam::sampledCuttingPlane::sample
356 const volScalarField& vField
359 return sampleField(vField);
363 Foam::tmp<Foam::vectorField>
364 Foam::sampledCuttingPlane::sample
366 const volVectorField& vField
369 return sampleField(vField);
373 Foam::tmp<Foam::sphericalTensorField>
374 Foam::sampledCuttingPlane::sample
376 const volSphericalTensorField& vField
379 return sampleField(vField);
383 Foam::tmp<Foam::symmTensorField>
384 Foam::sampledCuttingPlane::sample
386 const volSymmTensorField& vField
389 return sampleField(vField);
393 Foam::tmp<Foam::tensorField>
394 Foam::sampledCuttingPlane::sample
396 const volTensorField& vField
399 return sampleField(vField);
403 Foam::tmp<Foam::scalarField>
404 Foam::sampledCuttingPlane::interpolate
406 const interpolation<scalar>& interpolator
409 return interpolateField(interpolator);
413 Foam::tmp<Foam::vectorField>
414 Foam::sampledCuttingPlane::interpolate
416 const interpolation<vector>& interpolator
419 return interpolateField(interpolator);
422 Foam::tmp<Foam::sphericalTensorField>
423 Foam::sampledCuttingPlane::interpolate
425 const interpolation<sphericalTensor>& interpolator
428 return interpolateField(interpolator);
432 Foam::tmp<Foam::symmTensorField>
433 Foam::sampledCuttingPlane::interpolate
435 const interpolation<symmTensor>& interpolator
438 return interpolateField(interpolator);
442 Foam::tmp<Foam::tensorField>
443 Foam::sampledCuttingPlane::interpolate
445 const interpolation<tensor>& interpolator
448 return interpolateField(interpolator);
452 void Foam::sampledCuttingPlane::print(Ostream& os) const
454 os << "sampledCuttingPlane: " << name() << " :"
455 << " plane:" << plane_
456 << " faces:" << faces().size()
457 << " points:" << points().size();
461 // ************************************************************************* //