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 "sampledCuttingPlane.H"
27 #include "dictionary.H"
28 #include "volFields.H"
29 #include "volPointInterpolation.H"
30 #include "addToRunTimeSelectionTable.H"
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 defineTypeNameAndDebug(sampledCuttingPlane, 0);
38 addNamedToRunTimeSelectionTable
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 void Foam::sampledCuttingPlane::createGeometry()
53 Pout<< "sampledCuttingPlane::createGeometry :updating geometry."
57 // Clear any stored topologies
60 pointDistance_.clear();
61 cellDistancePtr_.clear();
67 if (zoneID_.index() != -1 && !subMeshPtr_.valid())
69 const polyBoundaryMesh& patches = mesh().boundaryMesh();
71 // Patch to put exposed internal faces into
72 const 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.
254 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
256 Foam::sampledCuttingPlane::sampledCuttingPlane
259 const polyMesh& mesh,
260 const dictionary& dict
263 sampledSurface(name, mesh, dict),
265 mergeTol_(dict.lookupOrDefault("mergeTol", 1E-6)),
266 regularise_(dict.lookupOrDefault("regularise", true)),
267 average_(dict.lookupOrDefault("average", false)),
268 zoneID_(dict.lookupOrDefault("zone", word::null), mesh.cellZones()),
269 exposedPatchName_(word::null),
272 cellDistancePtr_(NULL),
276 if (zoneID_.index() != -1)
278 dict.lookup("exposedPatchName") >> exposedPatchName_;
280 if (mesh.boundaryMesh().findPatchID(exposedPatchName_) == -1)
284 "sampledCuttingPlane::sampledCuttingPlane"
285 "(const word&, const polyMesh&, const dictionary&)"
286 ) << "Cannot find patch " << exposedPatchName_
287 << " in which to put exposed faces." << endl
288 << "Valid patches are " << mesh.boundaryMesh().names()
292 if (debug && zoneID_.index() != -1)
294 Info<< "Restricting to cellZone " << zoneID_.name()
295 << " with exposed internal faces into patch "
296 << exposedPatchName_ << endl;
302 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
304 Foam::sampledCuttingPlane::~sampledCuttingPlane()
308 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
310 bool Foam::sampledCuttingPlane::needsUpdate() const
316 bool Foam::sampledCuttingPlane::expire()
320 Pout<< "sampledCuttingPlane::expire :"
321 << " have-facesPtr_:" << facesPtr_.valid()
322 << " needsUpdate_:" << needsUpdate_ << endl;
325 // Clear any stored topologies
328 // Clear derived data
331 // already marked as expired
342 bool Foam::sampledCuttingPlane::update()
346 Pout<< "sampledCuttingPlane::update :"
347 << " have-facesPtr_:" << facesPtr_.valid()
348 << " needsUpdate_:" << needsUpdate_ << endl;
358 needsUpdate_ = false;
363 Foam::tmp<Foam::scalarField>
364 Foam::sampledCuttingPlane::sample
366 const volScalarField& vField
369 return sampleField(vField);
373 Foam::tmp<Foam::vectorField>
374 Foam::sampledCuttingPlane::sample
376 const volVectorField& vField
379 return sampleField(vField);
383 Foam::tmp<Foam::sphericalTensorField>
384 Foam::sampledCuttingPlane::sample
386 const volSphericalTensorField& vField
389 return sampleField(vField);
393 Foam::tmp<Foam::symmTensorField>
394 Foam::sampledCuttingPlane::sample
396 const volSymmTensorField& vField
399 return sampleField(vField);
403 Foam::tmp<Foam::tensorField>
404 Foam::sampledCuttingPlane::sample
406 const volTensorField& vField
409 return sampleField(vField);
413 Foam::tmp<Foam::scalarField>
414 Foam::sampledCuttingPlane::interpolate
416 const interpolation<scalar>& interpolator
419 return interpolateField(interpolator);
423 Foam::tmp<Foam::vectorField>
424 Foam::sampledCuttingPlane::interpolate
426 const interpolation<vector>& interpolator
429 return interpolateField(interpolator);
432 Foam::tmp<Foam::sphericalTensorField>
433 Foam::sampledCuttingPlane::interpolate
435 const interpolation<sphericalTensor>& interpolator
438 return interpolateField(interpolator);
442 Foam::tmp<Foam::symmTensorField>
443 Foam::sampledCuttingPlane::interpolate
445 const interpolation<symmTensor>& interpolator
448 return interpolateField(interpolator);
452 Foam::tmp<Foam::tensorField>
453 Foam::sampledCuttingPlane::interpolate
455 const interpolation<tensor>& interpolator
458 return interpolateField(interpolator);
462 void Foam::sampledCuttingPlane::print(Ostream& os) const
464 os << "sampledCuttingPlane: " << name() << " :"
465 << " plane:" << plane_
466 << " faces:" << faces().size()
467 << " points:" << points().size();
471 // ************************************************************************* //