From 4a845f5c416b0b6273f5b172d21e05c67aa1ae55 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 15 Dec 2016 09:54:25 +0100 Subject: [PATCH] ENH: newly structured surface 'sources' for sampling. - extend the sampling concept to include surfMeshes and surfFields for storage. - Note the createOnRead switch in surfMeshSamplers can be desirable in some situations to force creation of the surface faces within the constructor. --- src/sampling/Make/files | 10 + .../sampledSurfaces/sampledSurfaces.H | 3 + .../triSurfaceMesh/sampledDiscreteSurface.C | 234 +++++ .../triSurfaceMesh/sampledDiscreteSurface.H | 283 ++++++ .../sampledDiscreteSurfaceTemplates.C | 32 + .../plane/surfMeshPlaneSampler.C | 204 ++++ .../plane/surfMeshPlaneSampler.H | 166 ++++ .../plane/surfMeshPlaneSamplerTemplates.C | 63 ++ .../surfMeshSampler/surfMeshSampler.C | 224 +++++ .../surfMeshSampler/surfMeshSampler.H | 285 ++++++ .../surfMeshSamplerTemplates.C | 125 +++ .../surfMeshSamplers/surfMeshSamplers.C | 421 +++++++++ .../surfMeshSamplers/surfMeshSamplers.H | 228 +++++ .../surfMeshSamplersTemplates.C | 66 ++ .../triSurfaceMesh/surfMeshDiscreteSampler.C | 160 ++++ .../triSurfaceMesh/surfMeshDiscreteSampler.H | 153 +++ .../surfMeshDiscreteSamplerTemplates.C | 97 ++ .../surface/triSurfaceMesh/discreteSurface.C | 868 ++++++++++++++++++ .../surface/triSurfaceMesh/discreteSurface.H | 341 +++++++ .../triSurfaceMesh/discreteSurfaceTemplates.C | 231 +++++ 20 files changed, 4194 insertions(+) create mode 100644 src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.C create mode 100644 src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H create mode 100644 src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurfaceTemplates.C create mode 100644 src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C create mode 100644 src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.H create mode 100644 src/sampling/surfMeshSampler/plane/surfMeshPlaneSamplerTemplates.C create mode 100644 src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.C create mode 100644 src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H create mode 100644 src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSamplerTemplates.C create mode 100644 src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C create mode 100644 src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.H create mode 100644 src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplersTemplates.C create mode 100644 src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.C create mode 100644 src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.H create mode 100644 src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSamplerTemplates.C create mode 100644 src/sampling/surface/triSurfaceMesh/discreteSurface.C create mode 100644 src/sampling/surface/triSurfaceMesh/discreteSurface.H create mode 100644 src/sampling/surface/triSurfaceMesh/discreteSurfaceTemplates.C diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 1ac57449f6..8dbf6e9394 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -21,6 +21,12 @@ surface/cuttingPlane/cuttingPlane.C surface/isoSurface/isoSurface.C surface/isoSurface/isoSurfaceCell.C surface/thresholdCellFaces/thresholdCellFaces.C +surface/triSurfaceMesh/discreteSurface.C + +surfMeshSampler/surfMeshSampler/surfMeshSampler.C +surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C +surfMeshSampler/plane/surfMeshPlaneSampler.C +surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.C sampledSurface/sampledPatch/sampledPatch.C sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C @@ -35,6 +41,10 @@ sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C +/* Proof-of-concept: */ +/* sampledSurface/triSurfaceMesh/sampledDiscreteSurface.C */ + + surfWriters = sampledSurface/writers $(surfWriters)/surfaceWriter.C diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index aaa66caa13..7f41fd7795 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -64,6 +64,9 @@ Description } \endverbatim +See also + Foam::surfMeshSamplers + SourceFiles sampledSurfaces.C diff --git a/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.C b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.C new file mode 100644 index 0000000000..3f745dd820 --- /dev/null +++ b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.C @@ -0,0 +1,234 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "sampledDiscreteSurface.H" +#include "meshSearch.H" +#include "Tuple2.H" +#include "globalIndex.H" +#include "treeDataCell.H" +#include "treeDataFace.H" +#include "meshTools.H" + +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(sampledDiscreteSurface, 0); + addToRunTimeSelectionTable + ( + sampledSurface, + sampledDiscreteSurface, + word + ); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::sampledDiscreteSurface::sampledDiscreteSurface +( + const word& name, + const polyMesh& mesh, + const word& surfaceName, + const discreteSurface::samplingSource sampleSource +) +: + sampledSurface(name, mesh), + SurfaceSource(mesh, surfaceName, sampleSource) +{} + + +Foam::sampledDiscreteSurface::sampledDiscreteSurface +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + sampledSurface(name, mesh, dict), + SurfaceSource(mesh, dict) +{} + + +Foam::sampledDiscreteSurface::sampledDiscreteSurface +( + const word& name, + const polyMesh& mesh, + const triSurface& surface, + const word& sampleSourceName +) +: + sampledSurface(name, mesh), + SurfaceSource(name, mesh, surface, sampleSourceName) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::sampledDiscreteSurface::~sampledDiscreteSurface() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::sampledDiscreteSurface::needsUpdate() const +{ + return SurfaceSource::needsUpdate(); +} + + +bool Foam::sampledDiscreteSurface::expire() +{ + if (SurfaceSource::expire()) + { + // merged information etc + sampledSurface::clearGeom(); + + return true; + } + + return false; +} + + +bool Foam::sampledDiscreteSurface::update() +{ + return SurfaceSource::update(); +} + + +bool Foam::sampledDiscreteSurface::update(const treeBoundBox& bb) +{ + return SurfaceSource::update(bb); +} + + +bool Foam::sampledDiscreteSurface::sampleAndStore +( + const objectRegistry& store, + const word& fieldName +) const +{ + return SurfaceSource::sampleAndStore(store, fieldName); +} + + +Foam::tmp Foam::sampledDiscreteSurface::sample +( + const volScalarField& vField +) const +{ + return SurfaceSource::sampleField(vField); +} + + +Foam::tmp Foam::sampledDiscreteSurface::sample +( + const volVectorField& vField +) const +{ + return SurfaceSource::sampleField(vField); +} + +Foam::tmp Foam::sampledDiscreteSurface::sample +( + const volSphericalTensorField& vField +) const +{ + return SurfaceSource::sampleField(vField); +} + + +Foam::tmp Foam::sampledDiscreteSurface::sample +( + const volSymmTensorField& vField +) const +{ + return SurfaceSource::sampleField(vField); +} + + +Foam::tmp Foam::sampledDiscreteSurface::sample +( + const volTensorField& vField +) const +{ + return SurfaceSource::sampleField(vField); +} + + +Foam::tmp Foam::sampledDiscreteSurface::interpolate +( + const interpolation& interpolator +) const +{ + return SurfaceSource::interpolateField(interpolator); +} + + +Foam::tmp Foam::sampledDiscreteSurface::interpolate +( + const interpolation& interpolator +) const +{ + return SurfaceSource::interpolateField(interpolator); +} + +Foam::tmp Foam::sampledDiscreteSurface::interpolate +( + const interpolation& interpolator +) const +{ + return SurfaceSource::interpolateField(interpolator); +} + + +Foam::tmp Foam::sampledDiscreteSurface::interpolate +( + const interpolation& interpolator +) const +{ + return SurfaceSource::interpolateField(interpolator); +} + + +Foam::tmp Foam::sampledDiscreteSurface::interpolate +( + const interpolation& interpolator +) const +{ + return SurfaceSource::interpolateField(interpolator); +} + + +void Foam::sampledDiscreteSurface::print(Ostream& os) const +{ + os << "sampledDiscreteSurface: " << name() << " :"; + SurfaceSource::print(os); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H new file mode 100644 index 0000000000..605bb0a67f --- /dev/null +++ b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H @@ -0,0 +1,283 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::sampledDiscreteSurface + +Description + A sampledSurface from a triSurfaceMesh. + It samples on the points/triangles of a triSurfaceMesh. + +See Also + discreteSurface, sampledSurface + +SourceFiles + sampledDiscreteSurface.C + sampledDiscreteSurfaceTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef sampledDiscreteSurface_H +#define sampledDiscreteSurface_H + +#include "sampledSurface.H" +#include "discreteSurface.H" +#include "triSurfaceMesh.H" +#include "MeshedSurface.H" +#include "MeshedSurfacesFwd.H" + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class sampledDiscreteSurface; + +/*---------------------------------------------------------------------------*\ + Class sampledDiscreteSurface Declaration +\*---------------------------------------------------------------------------*/ + +class sampledDiscreteSurface +: + public sampledSurface, + public discreteSurface +{ + //- Private typedefs for convenience + typedef discreteSurface MeshStorage; + typedef discreteSurface SurfaceSource; + + + // Private Member Functions + + //- Sample field on faces + template + tmp> sampleField + ( + const GeometricField& vField + ) const; + + + template + tmp> + interpolateField(const interpolation&) const; + + +public: + + //- Runtime type information + TypeName("sampledDiscreteSurface"); + + + // Constructors + + //- Construct from components + sampledDiscreteSurface + ( + const word& name, + const polyMesh& mesh, + const word& surfaceName, + const discreteSurface::samplingSource sampleSource + ); + + //- Construct from dictionary + sampledDiscreteSurface + ( + const word& name, + const polyMesh& mesh, + const dictionary& dict + ); + + //- Construct from triSurface + sampledDiscreteSurface + ( + const word& name, + const polyMesh& mesh, + const triSurface& surface, + const word& sampleSourceName + ); + + + //- Destructor + virtual ~sampledDiscreteSurface(); + + + // Member Functions + + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire(); + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update(); + + //- Update the surface using a bound box to limit the searching. + // For direct use, i.e. not through sample. + // Do nothing (and return false) if no update was needed + bool update(const treeBoundBox&); + + //- Points of surface + virtual const pointField& points() const + { + return MeshStorage::points(); + } + + //- Faces of surface + virtual const faceList& faces() const + { + return MeshStorage::surfFaces(); + } + + //- Const access to per-face zone/region information + virtual const labelList& zoneIds() const + { + return MeshStorage::zoneIds(); + } + + //- Face area vectors + virtual const vectorField& Sf() const + { + return MeshStorage::Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return MeshStorage::magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return MeshStorage::Cf(); + } + + //- If element ids/order of the original surface are kept + bool keepIds() const + { + return MeshStorage::keepIds(); + } + + //- List of element ids/order of the original surface, + // when keepIds is active. + const labelList& originalIds() const + { + return MeshStorage::originalIds(); + } + + //- Sample the volume field onto surface, + // store it (temporarily) onto the given registry + virtual bool sampleAndStore + ( + const objectRegistry& store, + const word& fieldName + ) const; + + + //- Sample field on surface + virtual tmp sample + ( + const volScalarField& + ) const; + + //- Sample field on surface + virtual tmp sample + ( + const volVectorField& + ) const; + + //- Sample field on surface + virtual tmp sample + ( + const volSphericalTensorField& + ) const; + + //- Sample field on surface + virtual tmp sample + ( + const volSymmTensorField& + ) const; + + //- Sample field on surface + virtual tmp sample + ( + const volTensorField& + ) const; + + + //- Interpolate field on surface + virtual tmp interpolate + ( + const interpolation& + ) const; + + + //- Interpolate field on surface + virtual tmp interpolate + ( + const interpolation& + ) const; + + //- Interpolate field on surface + virtual tmp interpolate + ( + const interpolation& + ) const; + + //- Interpolate field on surface + virtual tmp interpolate + ( + const interpolation& + ) const; + + //- Interpolate field on surface + virtual tmp interpolate + ( + const interpolation& + ) const; + + //- Write information + virtual void print(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// #ifdef NoRepository +// #include "sampledDiscreteSurfaceTemplates.C" +// #endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurfaceTemplates.C b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurfaceTemplates.C new file mode 100644 index 0000000000..f6f67b89fd --- /dev/null +++ b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurfaceTemplates.C @@ -0,0 +1,32 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "sampledDiscreteSurface.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C new file mode 100644 index 0000000000..b01b09a355 --- /dev/null +++ b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.C @@ -0,0 +1,204 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshPlaneSampler.H" +#include "dictionary.H" +#include "polyMesh.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(surfMeshPlaneSampler, 0); + addNamedToRunTimeSelectionTable + ( + surfMeshSampler, + surfMeshPlaneSampler, + word, + plane + ); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::surfMeshPlaneSampler::transferContent() +{ + SurfaceSource& src = static_cast(*this); + surfMesh& dst = getOrCreateSurfMesh(); + + dst.transfer(src); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::surfMeshPlaneSampler::surfMeshPlaneSampler +( + const word& name, + const polyMesh& mesh, + const plane& planeDesc, + const keyType& zoneKey, + const bool triangulate +) +: + surfMeshSampler(name, mesh), + SurfaceSource(planeDesc), + zoneKey_(zoneKey), + triangulate_(triangulate), + needsUpdate_(true) +{ + if (debug && zoneKey_.size() && mesh.cellZones().findIndex(zoneKey_) < 0) + { + Info<< "cellZone " << zoneKey_ + << " not found - using entire mesh" << endl; + } +} + + +Foam::surfMeshPlaneSampler::surfMeshPlaneSampler +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + surfMeshSampler(name, mesh, dict), + SurfaceSource(plane(dict)), + zoneKey_(keyType::null), + triangulate_(dict.lookupOrDefault("triangulate", true)), + needsUpdate_(true) +{ + // Make plane relative to the coordinateSystem (Cartesian) + // allow lookup from global coordinate systems + if (dict.found("coordinateSystem")) + { + coordinateSystem cs(mesh, dict.subDict("coordinateSystem")); + + point base = cs.globalPosition(planeDesc().refPoint()); + vector norm = cs.globalVector(planeDesc().normal()); + + // Assign the plane description + static_cast(*this) = plane(base, norm); + } + + dict.readIfPresent("zone", zoneKey_); + + if (debug && zoneKey_.size() && mesh.cellZones().findIndex(zoneKey_) < 0) + { + Info<< "cellZone " << zoneKey_ + << " not found - using entire mesh" << endl; + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::surfMeshPlaneSampler::~surfMeshPlaneSampler() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::surfMeshPlaneSampler::needsUpdate() const +{ + return needsUpdate_; +} + + +bool Foam::surfMeshPlaneSampler::expire() +{ + // Already marked as expired + if (needsUpdate_) + { + return false; + } + + needsUpdate_ = true; + return true; +} + + +bool Foam::surfMeshPlaneSampler::update() +{ + if (!needsUpdate_) + { + return false; + } + + labelList selectedCells = mesh().cellZones().findMatching(zoneKey_).used(); + if (selectedCells.empty()) + { + reCut(mesh(), triangulate_); + } + else + { + Foam::sort(selectedCells); + reCut(mesh(), triangulate_, selectedCells); + } + + if (debug) + { + print(Pout); + Pout<< endl; + } + + transferContent(); + + needsUpdate_ = false; + return true; +} + + +bool Foam::surfMeshPlaneSampler::sample +( + const word& fieldName +) const +{ + return + ( + sampleType(fieldName) + || sampleType(fieldName) + || sampleType(fieldName) + || sampleType(fieldName) + || sampleType(fieldName) + ); +} + + +void Foam::surfMeshPlaneSampler::print(Ostream& os) const +{ + os << "surfMeshPlaneSampler: " << name() << " :" + << " base:" << cuttingPlane::refPoint() + << " normal:" << cuttingPlane::normal() + << " triangulate:" << triangulate_ + << " faces:" << SurfaceSource::surfFaces().size() + << " points:" << SurfaceSource::points().size(); +} + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.H b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.H new file mode 100644 index 0000000000..5fe1f4deac --- /dev/null +++ b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSampler.H @@ -0,0 +1,166 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::surfMeshPlaneSampler + +Description + Sampling surfFields onto a surfMesh based on a plane. + The cuttingPlane algorithm 'cuts' the mesh. + The plane is triangulated by default. + +Note + Does not actually cut until update() called. + +SourceFiles + surfMeshPlaneSampler.C + surfMeshPlaneSamplerTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef surfMeshPlaneSampler_H +#define surfMeshPlaneSampler_H + +#include "surfMeshSampler.H" +#include "cuttingPlane.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class surfMeshPlaneSampler Declaration +\*---------------------------------------------------------------------------*/ + +class surfMeshPlaneSampler +: + public surfMeshSampler, + private cuttingPlane +{ + // Private typedefs for convenience + typedef cuttingPlane SurfaceSource; + + // Private data + + //- If restricted to zones, name of this zone or a regular expression + keyType zoneKey_; + + //- Triangulated faces or keep faces as is + const bool triangulate_; + + //- Track if the surface needs an update + mutable bool needsUpdate_; + + + // Private Member Functions + + //- Transfer mesh content from SurfaceSource to surfMesh + void transferContent(); + + + //- Sample field on surface. + template + bool sampleType + ( + const word& fieldName + ) const; + + + //- Sample field on surface + template + tmp> sampleField + ( + const GeometricField& vField + ) const; + + +public: + + //- Runtime type information + TypeName("surfMeshPlaneSampler"); + + + // Constructors + + //- Construct from components + surfMeshPlaneSampler + ( + const word& name, + const polyMesh& mesh, + const plane& planeDesc, + const keyType& zoneKey = word::null, + const bool triangulate = true + ); + + //- Construct from dictionary + surfMeshPlaneSampler + ( + const word& name, + const polyMesh& mesh, + const dictionary& dict + ); + + + //- Destructor + virtual ~surfMeshPlaneSampler(); + + + // Member Functions + + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire(); + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update(); + + //- Sample the volume field onto surface + virtual bool sample(const word& fieldName) const; + + + //- Write + virtual void print(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "surfMeshPlaneSamplerTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/plane/surfMeshPlaneSamplerTemplates.C b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSamplerTemplates.C new file mode 100644 index 0000000000..e84d56545e --- /dev/null +++ b/src/sampling/surfMeshSampler/plane/surfMeshPlaneSamplerTemplates.C @@ -0,0 +1,63 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshPlaneSampler.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +bool Foam::surfMeshPlaneSampler::sampleType +( + const word& fieldName +) const +{ + typedef GeometricField VolFieldType; + + if (!mesh().foundObject(fieldName)) + { + return false; + } + + const VolFieldType& fld = mesh().lookupObject(fieldName); + + getOrCreateSurfField(fld).field() + = SurfaceSource::sample(fld); + + return true; +} + + +template +Foam::tmp> +Foam::surfMeshPlaneSampler::sampleField +( + const GeometricField& vField +) const +{ + return SurfaceSource::sample(vField); +} + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.C b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.C new file mode 100644 index 0000000000..a26a3e1623 --- /dev/null +++ b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.C @@ -0,0 +1,224 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshSampler.H" +#include "MeshedSurfaces.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(surfMeshSampler, 0); + defineRunTimeSelectionTable(surfMeshSampler, word); +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +Foam::surfMesh& +Foam::surfMeshSampler::getOrCreateSurfMesh() const +{ + if (!mesh().foundObject(name())) + { + surfMesh* ptr = new surfMesh + ( + IOobject + ( + name(), + mesh().time().timeName(), + mesh(), + IOobject::NO_READ, + IOobject::NO_WRITE + ), + xferCopy(pointField()), // initially no points + xferCopy(faceList()), // initially no faces + name() + ); + ptr->setWriteOption(IOobject::NO_WRITE); + + mesh().objectRegistry::store(ptr); + } + + return const_cast(surface()); +} + + +// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * // + +Foam::autoPtr +Foam::surfMeshSampler::New +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +{ + const word sampleType(dict.lookup("type")); + + wordConstructorTable::iterator cstrIter = + wordConstructorTablePtr_->find(sampleType); + + if (cstrIter == wordConstructorTablePtr_->end()) + { + FatalErrorInFunction + << "Unknown sample type " + << sampleType << nl << nl + << "Valid sample types : " << endl + << wordConstructorTablePtr_->sortedToc() + << exit(FatalError); + } + + return autoPtr(cstrIter()(name, mesh, dict)); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::surfMeshSampler::surfMeshSampler +( + const word& name, + const polyMesh& mesh +) +: + name_(name), + mesh_(mesh) +{} + + +Foam::surfMeshSampler::surfMeshSampler +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + name_(name), + mesh_(mesh) +{ + dict.readIfPresent("name", name_); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::surfMeshSampler::~surfMeshSampler() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::surfMeshSampler::create() const +{ + getOrCreateSurfMesh(); +} + + +const Foam::surfMesh& Foam::surfMeshSampler::surface() const +{ + return mesh().lookupObject(name()); +} + + +// Demonstration of using separate tmp registry +// Foam::label Foam::surfMeshSampler::sample +// ( +// const objectRegistry& store, +// const UList& fields +// ) const +// { +// label count = 0; +// forAll(fields, fieldi) +// { +// const word& fieldName = fields[fieldi]; +// bool ok = +// ( +// sampleAndStore(store, fieldName) +// && +// ( +// transferField(store, fieldName) +// || transferField(store, fieldName) +// || transferField(store, fieldName) +// || transferField(store, fieldName) +// || transferField(store, fieldName) +// ) +// ); +// +// if (ok) +// { +// ++count; +// } +// } +// +// return count; +// } + + +Foam::label Foam::surfMeshSampler::sample +( + const UList& fields +) const +{ + label count = 0; + forAll(fields, fieldi) + { + if (sample(fields[fieldi])) + { + ++count; + } + } + + return count; +} + + +Foam::label Foam::surfMeshSampler::write(const wordReList& select) const +{ + label count = + ( + writeFields(select) + + writeFields(select) + + writeFields(select) + + writeFields(select) + + writeFields(select) + ); + + if (count) + { + surface().write(); + } + + return count; +} + + + +void Foam::surfMeshSampler::print(Ostream& os) const +{ + os << type(); +} + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H new file mode 100644 index 0000000000..010429e390 --- /dev/null +++ b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSampler.H @@ -0,0 +1,285 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::surfMeshSampler + +Group + grpUtilitiesFunctionObjects + +Description + An abstract class for surfMesh with sampling. + +SourceFiles + surfMeshSampler.C + surfMeshSamplerTemplates.C + +\*---------------------------------------------------------------------------*/ + +#ifndef surfMeshSampler_H +#define surfMeshSampler_H + +#include "surfMesh.H" +#include "surfFields.H" + +#include "pointField.H" +#include "word.H" +#include "labelList.H" +#include "faceList.H" +#include "typeInfo.H" +#include "runTimeSelectionTables.H" +#include "autoPtr.H" +#include "volFieldsFwd.H" +#include "surfaceFieldsFwd.H" +#include "polyMesh.H" +#include "coordinateSystems.H" +#include "interpolation.H" +#include "error.H" +#include "IOobjectList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class surfMeshSampler; + +/*---------------------------------------------------------------------------*\ + Class surfMeshSampler Declaration +\*---------------------------------------------------------------------------*/ + +class surfMeshSampler +{ + // Private data + + //- Name for surfMesh lookup + word name_; + + //- Mesh reference + const polyMesh& mesh_; + + + // Private Member Functions + + // Service methods + + +protected: + + // Protected Member Functions + + //- Get existing or create new surfMesh + surfMesh& getOrCreateSurfMesh() const; + + //- Get existing or create new surfField. + // Create with same name and dimensions as the 'parent' volField. + template + DimensionedField& + getOrCreateSurfField + ( + const GeometricField& vField + ) const; + + + // //- Transfer field from object registry to surfField + // template + // bool transferField + // ( + // const objectRegistry& store, + // const word& fieldName + // ) const; + + + //- Write the given fields + template + label writeFields(const wordReList& select) const; + +public: + + //- Runtime type information + TypeName("surfMeshSampler"); + + + //- Declare run-time constructor selection table + declareRunTimeSelectionTable + ( + autoPtr, + surfMeshSampler, + word, + ( + const word& name, + const polyMesh& mesh, + const dictionary& dict + ), + (name, mesh, dict) + ); + + + // iNew helper class + + //- Class used for the PtrLists read-construction + class iNew + { + //- Reference to the volume mesh + const polyMesh& mesh_; + + public: + + iNew(const polyMesh& mesh) + : + mesh_(mesh) + {} + + autoPtr operator()(Istream& is) const + { + word name(is); + dictionary dict(is); + + return surfMeshSampler::New(name, mesh_, dict); + } + }; + + + // Constructors + + //- Construct from name, mesh + surfMeshSampler + ( + const word& name, + const polyMesh& mesh + ); + + //- Construct from dictionary + surfMeshSampler + ( + const word& name, + const polyMesh& mesh, + const dictionary& dict + ); + + + //- Clone + autoPtr clone() const + { + NotImplemented; + return autoPtr(nullptr); + } + + + + // Selectors + + //- Return a reference to the selected surface + static autoPtr New + ( + const word& name, + const polyMesh& mesh, + const dictionary& dict + ); + + + //- Destructor + virtual ~surfMeshSampler(); + + + // Member Functions + + // Access + + //- Access to the underlying mesh + const polyMesh& mesh() const + { + return mesh_; + } + + //- Name of surface + const word& name() const + { + return name_; + } + + + //- Create surfMesh if required. + void create() const; + + //- Return existing surfMesh. + virtual const surfMesh& surface() const; + + + //- Does the surface need an update? + virtual bool needsUpdate() const = 0; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire() = 0; + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update() = 0; + + + // Edit + + //- Rename + virtual void rename(const word& newName) + { + name_ = newName; + } + + + // Execute + + //- Sample from specified volume field to surface + virtual bool sample(const word& fieldName) const = 0; + + //- Sample from volume fields to specified surface fields. + virtual label sample(const UList& fields) const; + + + // Write + + //- Write specified fields + virtual label write(const wordReList& fieldSelection) const; + + //- Write + virtual void print(Ostream&) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "surfMeshSamplerTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSamplerTemplates.C b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSamplerTemplates.C new file mode 100644 index 0000000000..a195865f81 --- /dev/null +++ b/src/sampling/surfMeshSampler/surfMeshSampler/surfMeshSamplerTemplates.C @@ -0,0 +1,125 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshSampler.H" +#include "dimensionedType.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +Foam::DimensionedField& +Foam::surfMeshSampler::getOrCreateSurfField +( + const GeometricField& vField +) const +{ + typedef DimensionedField SurfFieldType; + + const surfMesh& surf = surface(); + const word& fieldName = vField.name(); + + SurfFieldType* ptr = surf.lookupObjectRefPtr(fieldName); + if (!ptr) + { + ptr = new SurfFieldType + ( + IOobject + ( + fieldName, + surf.time().timeName(), + surf, + IOobject::NO_READ, + IOobject::NO_WRITE + ), + surf, + dimensioned("0", vField.dimensions(), Zero) + ); + ptr->writeOpt() = IOobject::NO_WRITE; + + surf.store(ptr); + } + + return *ptr; +} + + +// // Older code for transferring an IOField to a surfField between +// // different registries +// template +// bool Foam::surfMeshSampler::transferField +// ( +// const objectRegistry& store, +// const word& fieldName +// ) const +// { +// typedef GeometricField VolFieldType; +// typedef DimensionedField SurfFieldType; +// typedef IOField TmpFieldType; +// +// // foundObject includes a type check +// bool ok = +// ( +// mesh_.foundObject(fieldName) +// && store.foundObject(fieldName) +// ); +// +// if (ok) +// { +// SurfFieldType& sfield = getOrCreateSurfField +// ( +// mesh_.lookupObject(fieldName) +// ); +// +// TmpFieldType& iofield = +// store.lookupObjectRef(fieldName); +// +// sfield.transfer(iofield); +// store.checkOut(iofield); +// } +// +// return ok; +// } + + +template +Foam::label Foam::surfMeshSampler::writeFields +( + const wordReList& select +) const +{ + typedef DimensionedField SurfFieldType; + const surfMesh& s = surface(); + + wordList names = s.sortedNames(select); + forAll(names, namei) + { + s.lookupObject(names[namei]).write(); + } + + return names.size(); +} + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C new file mode 100644 index 0000000000..38deded051 --- /dev/null +++ b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.C @@ -0,0 +1,421 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshSamplers.H" +#include "volFields.H" +#include "dictionary.H" +#include "Time.H" +#include "IOmanip.H" +#include "volPointInterpolation.H" +#include "PatchTools.H" +#include "mapPolyMesh.H" +#include "wordReListMatcher.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(surfMeshSamplers, 0); + addToRunTimeSelectionTable + ( + functionObject, + surfMeshSamplers, + dictionary + ); +} + + +bool Foam::surfMeshSamplers::verbose_ = false; + +void Foam::surfMeshSamplers::checkOutNames +( + const objectRegistry& registry, + const UList& names +) +{ + objectRegistry& reg = const_cast(registry); + + forAll(names, namei) + { + objectRegistry::iterator iter = reg.find(names[namei]); + if (iter != reg.end()) + { + registry.checkOut(*iter()); + } + } +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// //- Temporary object registry for passing around values +// const objectRegistry& tmpRegistry() const; +// +// //- Temporary object registry for passing around values +// const objectRegistry& tmpRegistry(const word& subName) const; + +// const Foam::objectRegistry& +// Foam::surfMeshSamplers::tmpRegistry() const +// { +// // Sub-registry for sampling, choose name for fewer collisions +// return mesh_.thisDb().subRegistry +// ( +// "$tmp$" + type() + "$" + name(), +// true, +// false +// ); +// } +// +// +// const Foam::objectRegistry& +// Foam::surfMeshSamplers::tmpRegistry(const word& subName) const +// { +// return tmpRegistry().subRegistry(subName, true, false); +// } + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::surfMeshSamplers::surfMeshSamplers +( + const word& name, + const Time& runTime, + const dictionary& dict +) +: + functionObjects::regionFunctionObject(name, runTime, dict), + PtrList(), + mesh_(refCast(obr_)), + fieldSelection_() +{ + read(dict); +} + + +Foam::surfMeshSamplers::surfMeshSamplers +( + const word& name, + const objectRegistry& obr, + const dictionary& dict +) +: + functionObjects::regionFunctionObject(name, obr, dict), + PtrList(), + mesh_(refCast(obr)), + fieldSelection_(), + derivedNames_() +{ + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::surfMeshSamplers::~surfMeshSamplers() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::surfMeshSamplers::verbose(const bool verbosity) +{ + verbose_ = verbosity; +} + + +bool Foam::surfMeshSamplers::execute() +{ + if (size()) + { + const objectRegistry& db = mesh_.thisDb(); + + // Manage derived names + DynamicList added(derivedNames_.size()); + DynamicList cleanup(derivedNames_.size()); + + forAll(derivedNames_, namei) + { + const word& derivedName = derivedNames_[namei]; + + if (derivedName == "rhoU") + { + added.append(derivedName); + + if (!db.foundObject(derivedName)) + { + cleanup.append(derivedName); + + db.store + ( + new volVectorField + ( + derivedName, + // rhoU = rho * U + ( + mesh_.lookupObject("rho") + * mesh_.lookupObject("U") + ) + ) + ); + } + } + else if (derivedName == "pTotal") + { + added.append(derivedName); + + if (!db.foundObject(derivedName)) + { + cleanup.append(derivedName); + + db.store + ( + new volScalarField + ( + derivedName, + // pTotal = p + U^2 / 2 + ( + mesh_.lookupObject("p") + + 0.5 + * mesh_.lookupObject("rho") + * magSqr(mesh_.lookupObject("U")) + ) + ) + ); + } + } + else + { + WarningInFunction + << "unknown derived name: " << derivedName << nl + << "Use one of 'rhoU', 'pTotal'" << nl + << endl; + } + } + + // The acceptable fields + wordHashSet acceptable(added); + acceptable.insert(acceptType()); + acceptable.insert(acceptType()); + acceptable.insert(acceptType()); + acceptable.insert(acceptType()); + acceptable.insert(acceptType()); + + const wordList fields = acceptable.sortedToc(); + if (!fields.empty()) + { + forAll(*this, surfI) + { + surfMeshSampler& s = operator[](surfI); + + // Potentially monitor the update for writing geometry? + if (s.needsUpdate()) + { + s.update(); + } + + s.sample(fields); + } + } + + checkOutNames(db, cleanup); + } + + return true; +} + + +bool Foam::surfMeshSamplers::write() +{ + // Write sampled fields (on surface) + // + // Doesn't bother checking which fields have been generated here + // or elsewhere + + // This could be more efficient + wordReList select(fieldSelection_.size() + derivedNames_.size()); + + label nElem = 0; + forAll(fieldSelection_, i) + { + select[nElem++] = fieldSelection_[i]; + } + forAll(derivedNames_, i) + { + select[nElem++] = derivedNames_[i]; + } + + // avoid duplicate entries + select = wordReListMatcher::uniq(select); + + forAll(*this, surfI) + { + const surfMeshSampler& s = operator[](surfI); + s.write(select); + } + + return true; +} + + +bool Foam::surfMeshSamplers::read(const dictionary& dict) +{ + derivedNames_.clear(); + + const bool createOnRead = + dict.lookupOrDefault("createOnRead", false); + + if (dict.found("surfaces")) + { + fieldSelection_ = wordReListMatcher::uniq + ( + wordReList(dict.lookup("fields")) + ); + Info<< type() << " fields: " << fieldSelection_ << nl; + + if (dict.readIfPresent("derived", derivedNames_)) + { + Info<< type() << " derived: " << derivedNames_ << nl; + } + + PtrList newList + ( + dict.lookup("surfaces"), + surfMeshSampler::iNew(mesh_) + ); + transfer(newList); + + // Ensure all surfaces and merge information are expired + expire(); + + // Need to initialize corresponding surfMesh for others in the chain. + // This can simply be a zero-sized placeholder, or the real surface with + // faces. + if (this->size()) + { + Info<< "Reading surface description:" << nl; + forAll(*this, surfI) + { + surfMeshSampler& s = operator[](surfI); + + Info<< " " << s.name() << nl; + if (createOnRead) + { + s.update(); + } + else + { + s.create(); + } + } + Info<< endl; + } + } + + return true; +} + + +void Foam::surfMeshSamplers::updateMesh(const mapPolyMesh& mpm) +{ + if (&mpm.mesh() == &mesh_) + { + expire(); + } + + // pointMesh and interpolation will have been reset in mesh.update +} + + +void Foam::surfMeshSamplers::movePoints(const polyMesh& m) +{ + if (&m == &mesh_) + { + expire(); + } +} + + +void Foam::surfMeshSamplers::readUpdate(const polyMesh::readUpdateState state) +{ + if (state != polyMesh::UNCHANGED) + { + expire(); + } +} + + +bool Foam::surfMeshSamplers::needsUpdate() const +{ + forAll(*this, surfI) + { + if (operator[](surfI).needsUpdate()) + { + return true; + } + } + + return false; +} + + +bool Foam::surfMeshSamplers::expire() +{ + bool justExpired = false; + + forAll(*this, surfI) + { + if (operator[](surfI).expire()) + { + justExpired = true; + } + } + + // True if any surfaces just expired + return justExpired; +} + + +bool Foam::surfMeshSamplers::update() +{ + if (!needsUpdate()) + { + return false; + } + + bool updated = false; + forAll(*this, surfI) + { + if (operator[](surfI).update()) + { + updated = true; + } + } + + return updated; +} + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.H b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.H new file mode 100644 index 0000000000..b7f7fc8b5e --- /dev/null +++ b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplers.H @@ -0,0 +1,228 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::surfMeshSamplers + +Description + Set of surfaces to sample into a surfMesh/surfField. + + The execute() method is used to sample, and the write() method to write. + It is fairly common to use for sampling only and have the write disabled. + + \verbatim + surfaces + { + type surfMeshes; + libs ("libsampling.so"); + + // Sample at every time-step + executeControl timeStep; + executeInterval 1; + + // Disable writing (or write at same frequency as fields) + writeControl none; + writeInterval 1; + + // Fields to be sampled + fields (p U); + + // Optional: pre-defined derived fields to be sampled + derived (rhoU pTotal); + + // Optional: create surface immediately on read + // The default is to create a placeholder without any faces. + createOnRead false; + + surfaces + ( + f0surf + { + type sampledTriSurfaceMesh; + surface f0surf.obj; + source cells; + } + ); + } + \endverbatim + + +See also + Foam::sampledSurfaces + +SourceFiles + surfMeshSamplers.C + +\*---------------------------------------------------------------------------*/ + +#ifndef surfMeshSamplers_H +#define surfMeshSamplers_H + +#include "regionFunctionObject.H" +#include "surfMeshSampler.H" +#include "volFieldsFwd.H" +#include "surfaceFieldsFwd.H" +#include "wordReList.H" +#include "IOobjectList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class Time; +class fvMesh; +class dictionary; + +/*---------------------------------------------------------------------------*\ + Class surfMeshSamplers Declaration +\*---------------------------------------------------------------------------*/ + +class surfMeshSamplers +: + public functionObjects::regionFunctionObject, + public PtrList +{ + // Static data members + + //- output verbosity + static bool verbose_; + + + // Private data + + //- Const reference to fvMesh + const fvMesh& mesh_; + + + // Read from dictonary + + //- Names of fields to sample + wordReList fieldSelection_; + + //- Names of derived fields to create and sample + wordList derivedNames_; + + + // Private Member Functions + + //- Remove items by name from objectRegistry + static void checkOutNames + ( + const objectRegistry& registry, + const UList& names + ); + + + //- Filter acceptable fields types + template + wordList acceptType() const; + + + //- Disallow default bitwise copy construct and assignment + surfMeshSamplers(const surfMeshSamplers&) = delete; + void operator=(const surfMeshSamplers&) = delete; + + +public: + + //- Runtime type information + TypeName("surfMeshes"); + + + // Constructors + + //- Construct from Time and dictionary + surfMeshSamplers + ( + const word& name, + const Time& time, + const dictionary& dict + ); + + //- Construct for given objectRegistry and dictionary + surfMeshSamplers + ( + const word& name, + const objectRegistry&, + const dictionary& + ); + + + //- Destructor + virtual ~surfMeshSamplers(); + + + // Member Functions + + //- Do any of the surfaces need an update? + virtual bool needsUpdate() const; + + //- Mark the surfaces as needing an update. + // May also free up unneeded data. + // Return false if all surfaces were already marked as expired. + virtual bool expire(); + + //- Update the surfaces as required and merge surface points (parallel). + // Return false if no surfaces required an update. + virtual bool update(); + + //- set verbosity level + void verbose(const bool verbosity = true); + + //- Read the surfMeshSamplers dictionary + virtual bool read(const dictionary&); + + //- Execute, does sampling + virtual bool execute(); + + //- Write sampled values + virtual bool write(); + + //- Update for changes of mesh - expires the surfaces + virtual void updateMesh(const mapPolyMesh&); + + //- Update for mesh point-motion - expires the surfaces + virtual void movePoints(const polyMesh&); + + //- Update for changes of mesh due to readUpdate - expires the surfaces + virtual void readUpdate(const polyMesh::readUpdateState state); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "surfMeshSamplersTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplersTemplates.C b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplersTemplates.C new file mode 100644 index 0000000000..6eedaabed0 --- /dev/null +++ b/src/sampling/surfMeshSampler/surfMeshSamplers/surfMeshSamplersTemplates.C @@ -0,0 +1,66 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshSamplers.H" +#include "volFields.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +Foam::wordList +Foam::surfMeshSamplers::acceptType() const +{ + typedef GeometricField VolFieldType; + + return mesh_.names(fieldSelection_); +} + +#if 0 +template +Foam::wordList +Foam::surfMeshSamplers::acceptType +( + const IOobjectList& objects, + bool fromFiles +) const +{ + typedef GeometricField VolFieldType; + + if (fromFiles_) + { + // This should actually be in the caller: + // IOobjectList objects1 = objects.lookup(fieldSelection_); + + return objects.names(VolFieldType::typeName, fieldSelection_); + } + else + { + return mesh_.names(fieldSelection_); + } +} +#endif + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.C b/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.C new file mode 100644 index 0000000000..bb82b29eff --- /dev/null +++ b/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.C @@ -0,0 +1,160 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshDiscreteSampler.H" +#include "MeshedSurfaces.H" + +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(surfMeshDiscreteSampler, 0); + + // Add under name "sampledTriSurfaceMesh" + // for symmetry with normal sampledSurface + addNamedToRunTimeSelectionTable + ( + surfMeshSampler, + surfMeshDiscreteSampler, + word, + sampledTriSurfaceMesh + ); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::surfMeshDiscreteSampler::transferContent() +{ + SurfaceSource& src = static_cast(*this); + surfMesh& dst = getOrCreateSurfMesh(); + + dst.transfer(src); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::surfMeshDiscreteSampler::surfMeshDiscreteSampler +( + const word& name, + const polyMesh& mesh, + const word& surfaceName, + const discreteSurface::samplingSource sampleSource +) +: + surfMeshSampler(name, mesh), + SurfaceSource(mesh, surfaceName, sampleSource, false) // no interpolate +{} + + +Foam::surfMeshDiscreteSampler::surfMeshDiscreteSampler +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + surfMeshSampler(name, mesh), + SurfaceSource(mesh, dict, false) // no interpolate +{} + + +Foam::surfMeshDiscreteSampler::surfMeshDiscreteSampler +( + const word& name, + const polyMesh& mesh, + const triSurface& surface, + const word& sampleSourceName +) +: + surfMeshSampler(name, mesh), + SurfaceSource(name, mesh, surface, sampleSourceName, false) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::surfMeshDiscreteSampler::~surfMeshDiscreteSampler() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::surfMeshDiscreteSampler::needsUpdate() const +{ + return SurfaceSource::needsUpdate(); +} + + +bool Foam::surfMeshDiscreteSampler::expire() +{ + return SurfaceSource::expire(); +} + + +bool Foam::surfMeshDiscreteSampler::update() +{ + if (SurfaceSource::update()) + { + transferContent(); + return true; + } + + return false; +} + + +bool Foam::surfMeshDiscreteSampler::update(const treeBoundBox& bb) +{ + if (SurfaceSource::update(bb)) + { + transferContent(); + return true; + } + + return false; +} + + +bool Foam::surfMeshDiscreteSampler::sample +( + const word& fieldName +) const +{ + return + ( + sampleType(fieldName) + || sampleType(fieldName) + || sampleType(fieldName) + || sampleType(fieldName) + || sampleType(fieldName) + ); +} + + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.H b/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.H new file mode 100644 index 0000000000..f2a3d64382 --- /dev/null +++ b/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSampler.H @@ -0,0 +1,153 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Class + Foam::surfMeshDiscreteSampler + +Description + Sampling surfFields onto a surfMesh based on a triSurfaceMesh. + +See Also + discreteSurface, surfMeshSampler + +SourceFiles + surfMeshDiscreteSampler.C + +\*---------------------------------------------------------------------------*/ + +#ifndef surfMeshDiscreteSampler_H +#define surfMeshDiscreteSampler_H + +#include "surfMeshSampler.H" +#include "discreteSurface.H" +#include "triSurfaceMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class surfMeshDiscreteSampler; + +/*---------------------------------------------------------------------------*\ + Class surfMeshDiscreteSampler Declaration +\*---------------------------------------------------------------------------*/ + +class surfMeshDiscreteSampler +: + public surfMeshSampler, + private discreteSurface +{ + // Private typedefs for convenience + typedef discreteSurface SurfaceSource; + + + // Private Member Functions + + //- Transfer mesh content from SurfaceSource to surfMesh + void transferContent(); + +public: + + //- Runtime type information + TypeName("surfMeshDiscreteSampler"); + + + // Constructors + + //- Construct from components + surfMeshDiscreteSampler + ( + const word& name, + const polyMesh& mesh, + const word& surfaceName, + const discreteSurface::samplingSource sampleSource + ); + + //- Construct from dictionary + surfMeshDiscreteSampler + ( + const word& name, + const polyMesh& mesh, + const dictionary& dict + ); + + //- Construct from triSurface + surfMeshDiscreteSampler + ( + const word& name, + const polyMesh& mesh, + const triSurface& surface, + const word& sampleSourceName + ); + + + //- Destructor + virtual ~surfMeshDiscreteSampler(); + + + // Member Functions + + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + // May also free up unneeded data. + // Return false if surface was already marked as expired. + virtual bool expire(); + + //- Update the surface as required. + // Do nothing (and return false) if no update was needed + virtual bool update(); + + //- Update the surface using a bound box to limit the searching. + // For direct use, i.e. not through sample. + // Do nothing (and return false) if no update was needed + bool update(const treeBoundBox&); + + + //- Sample the volume field onto surface + virtual bool sample(const word& fieldName) const; + + //- Sample field on surface. + template + bool sampleType(const word& fieldName) const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "surfMeshDiscreteSamplerTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSamplerTemplates.C b/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSamplerTemplates.C new file mode 100644 index 0000000000..34d78f4984 --- /dev/null +++ b/src/sampling/surfMeshSampler/triSurfaceMesh/surfMeshDiscreteSamplerTemplates.C @@ -0,0 +1,97 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "surfMeshDiscreteSampler.H" +#include "dimensionedType.H" +#include "error.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +bool Foam::surfMeshDiscreteSampler::sampleType +( + const word& fieldName +) const +{ + typedef GeometricField VolFieldType; + + const polyMesh& mesh = SurfaceSource::mesh(); + + if (!mesh.foundObject(fieldName)) + { + return false; + } + + const VolFieldType& fld = mesh.lookupObject(fieldName); + + getOrCreateSurfField(fld).field() + = SurfaceSource::sampleField(fld); + + return true; +} + + +// template +// Foam::tmp> +// Foam::surfMeshDiscreteSampler::sampleField +// ( +// const GeometricField& fld +// ) const +// { +// typedef DimensionedField SurfFieldType; +// +// tmp> tfield = SurfaceSource::sampleField(fld); +// SurfFieldType& result = getOrCreateSurfField(fld); +// +// // need to verify if this will be needed (in the future) +// const surfMesh& s = surface(); +// if (result.size() != s.size()) +// { +// // maybe resampling changed the surfMesh, +// // but the existing surfField wasn't updated +// +// result.setSize(s.size(), Zero); +// } +// +// if (result.size() != sampleElements().size()) +// { +// FatalErrorInFunction +// << "mismatch in field/mesh sizes " +// << result.name() << nl +// << " field has " << result.size() +// << " but sampleElements has " << sampleElements().size() << nl +// << endl +// << exit(FatalError); +// +// Info<< "WARNING: " +// << endl; +// } +// +// result = tfield; +// return result; +// } + + +// ************************************************************************* // diff --git a/src/sampling/surface/triSurfaceMesh/discreteSurface.C b/src/sampling/surface/triSurfaceMesh/discreteSurface.C new file mode 100644 index 0000000000..b6bc9d87d8 --- /dev/null +++ b/src/sampling/surface/triSurfaceMesh/discreteSurface.C @@ -0,0 +1,868 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "discreteSurface.H" +#include "meshSearch.H" +#include "Tuple2.H" +#include "globalIndex.H" +#include "treeDataCell.H" +#include "treeDataFace.H" +#include "meshTools.H" + +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(discreteSurface, 0); + + template<> + const char* NamedEnum::names[] = + { + "cells", + "insideCells", + "boundaryFaces" + }; + + const NamedEnum + discreteSurface::samplingSourceNames_; + + + //- Private class for finding nearest + // Comprising: + // - global index + // - sqr(distance) + typedef Tuple2 nearInfo; + + class nearestEqOp + { + public: + + void operator()(nearInfo& x, const nearInfo& y) const + { + if (y.first() < x.first()) + { + x = y; + } + } + }; +} + + +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + +void Foam::discreteSurface::setZoneMap +( + const surfZoneList& zoneLst, + labelList& zoneIds +) +{ + label sz = 0; + forAll(zoneLst, zonei) + { + const surfZone& zn = zoneLst[zonei]; + sz += zn.size(); + } + + zoneIds.setSize(sz); + forAll(zoneLst, zonei) + { + const surfZone& zn = zoneLst[zonei]; + + // Assign sub-zone Ids + SubList