diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.C b/src/OpenFOAM/meshes/pointMesh/pointMesh.C index c00c67cdb0..0e55f32437 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.C +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.C @@ -35,9 +35,7 @@ License namespace Foam { - defineTypeNameAndDebug(pointMesh, 0); - } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -88,18 +86,6 @@ Foam::pointMesh::pointMesh(const polyMesh& pMesh) } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::pointMesh::~pointMesh() -{ - if (debug) - { - Pout<< "~pointMesh::pointMesh()" - << endl; - } -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // bool Foam::pointMesh::movePoints() @@ -121,8 +107,7 @@ void Foam::pointMesh::updateMesh(const mapPolyMesh& mpm) if (debug) { Pout<< "pointMesh::updateMesh(const mapPolyMesh&): " - << "Updating for topology changes." << endl; - Pout<< endl; + << "Updating for topology changes." << nl << endl; } boundary_.updateMesh(); diff --git a/src/OpenFOAM/meshes/pointMesh/pointMesh.H b/src/OpenFOAM/meshes/pointMesh/pointMesh.H index 28180b1252..db404d83fc 100644 --- a/src/OpenFOAM/meshes/pointMesh/pointMesh.H +++ b/src/OpenFOAM/meshes/pointMesh/pointMesh.H @@ -60,13 +60,13 @@ class pointMesh // Private Member Functions //- Map all fields - void mapFields(const mapPolyMesh&); + void mapFields(const mapPolyMesh& mpm); - //- Disallow default bitwise copy construct - pointMesh(const pointMesh&); + //- No copy construct + pointMesh(const pointMesh&) = delete; - //- Disallow default bitwise assignment - void operator=(const pointMesh&); + //- No copy assignment + void operator=(const pointMesh&) = delete; public: @@ -86,7 +86,7 @@ public: //- Destructor - ~pointMesh(); + ~pointMesh() = default; // Member Functions @@ -122,13 +122,13 @@ public: } - // Mesh motion + // Mesh motion - //- Move points - bool movePoints(); + //- Move points + bool movePoints(); - //- Update the mesh corresponding to given map - void updateMesh(const mapPolyMesh& mpm); + //- Update the mesh corresponding to given map + void updateMesh(const mapPolyMesh& mpm); // Member Operators diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C index c2e27c8eea..348802c69f 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.C @@ -34,25 +34,19 @@ void Foam::plane::calcPntAndVec(const scalarList& C) { point_ = vector((-C[3]/C[0]), 0, 0); } + else if (mag(C[1]) > VSMALL) + { + point_ = vector(0, (-C[3]/C[1]), 0); + } + else if (mag(C[2]) > VSMALL) + { + point_ = vector(0, 0, (-C[3]/C[2])); + } else { - if (mag(C[1]) > VSMALL) - { - point_ = vector(0, (-C[3]/C[1]), 0); - } - else - { - if (mag(C[2]) > VSMALL) - { - point_ = vector(0, 0, (-C[3]/C[2])); - } - else - { - FatalErrorInFunction - << "At least one plane coefficient must have a value" - << abort(FatalError); - } - } + FatalErrorInFunction + << "At least one plane coefficient must have a value" + << abort(FatalError); } normal_ = vector(C[0], C[1], C[2]); @@ -127,7 +121,7 @@ Foam::plane::plane(const vector& normalVector) else { FatalErrorInFunction - << "plane normal has zero length. basePoint:" << point_ + << "plane normal has zero length. base point:" << point_ << abort(FatalError); } } @@ -148,7 +142,7 @@ Foam::plane::plane if (magSqrNormalVector < VSMALL) { FatalErrorInFunction - << "plane normal has zero length. basePoint:" << point_ + << "plane normal has zero length. base point:" << point_ << abort(FatalError); } @@ -247,7 +241,7 @@ Foam::plane::plane(Istream& is) else { FatalErrorInFunction - << "plane normal has zero length. basePoint:" << point_ + << "plane normal has zero length. base point:" << point_ << abort(FatalError); } } diff --git a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H index 9ef1304ba9..2917939bf3 100644 --- a/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H +++ b/src/OpenFOAM/meshes/primitiveShapes/plane/plane.H @@ -28,6 +28,40 @@ Description Geometric class that creates a 3D plane and can return the intersection point between a line and the plane. + Construction from a dictionary is driven by the \c planeType + + For \c planeType as \c pointAndNormal : + \verbatim + pointAndNormalDict + { + point ; // or basePoint + normal ; // or normalVector + } + \endverbatim + + For \c planeType as \c embeddedPoints : + \verbatim + embeddedPointsDict + { + point1 ; + point2 ; + point3 ; + } + \endverbatim + + For \c planeType with \c planeEquation coefficients + \f$ ax + by + cz + d = 0 \f$ : + + \verbatim + planeEquationDict + { + a ; + b ; + c ; + d ; + } + \endverbatim + SourceFiles plane.C @@ -63,10 +97,11 @@ public: //- Side of the plane enum side { - NORMAL, - FLIP + NORMAL = 1, //!< The front (or normal) side of the plane + FLIP = -1 //!< The back (or flip) side of the plane }; + //- A direction and a reference point class ray { @@ -126,10 +161,12 @@ public: //- Construct null. Does not set normal and point. plane(); - //- Construct from normal vector through the origin + //- Construct from normal vector through the origin. + // The vector is normalised to a unit vector on input. explicit plane(const vector& normalVector); - //- Construct from normal vector and point in plane + //- Construct from normal vector and point in plane. + // By default, the vector is normalised to a unit vector on input. explicit plane ( const point& basePoint, @@ -150,7 +187,7 @@ public: explicit plane(const scalarList& C); //- Construct from dictionary - explicit plane(const dictionary& planeDict); + explicit plane(const dictionary& dict); //- Construct from Istream. Assumes the base + normal notation. explicit plane(Istream& is); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H index 8d32b05ec5..94b71defce 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/phaseHydrostaticPressure/phaseHydrostaticPressureFvPatchScalarField.H @@ -45,7 +45,7 @@ Description \endtable The values are assigned according to the phase-fraction field: - - 1: apply \$fp_{hyd}\$f + - 1: apply \f$p_{hyd}\f$ - 0: apply a zero-gradient condition Usage diff --git a/src/finiteVolume/interpolation/interpolation/interpolationCell/interpolationCell.H b/src/finiteVolume/interpolation/interpolation/interpolationCell/interpolationCell.H index d2e61b8e43..0699018c28 100644 --- a/src/finiteVolume/interpolation/interpolation/interpolationCell/interpolationCell.H +++ b/src/finiteVolume/interpolation/interpolation/interpolationCell/interpolationCell.H @@ -42,7 +42,7 @@ namespace Foam class fvMesh; /*---------------------------------------------------------------------------*\ - Class interpolationCell Declaration + Class interpolationCell Declaration \*---------------------------------------------------------------------------*/ template diff --git a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H index 823d389e93..c29282bddf 100644 --- a/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H +++ b/src/finiteVolume/interpolation/volPointInterpolation/volPointInterpolation.H @@ -64,20 +64,20 @@ class volPointInterpolation scalarListList pointWeights_; - // Boundary handling + // Boundary handling - //- Boundary addressing - autoPtr boundaryPtr_; + //- Boundary addressing + autoPtr boundaryPtr_; - //- Per boundary face whether is on non-coupled patch - boolList boundaryIsPatchFace_; + //- Per boundary face whether is on non-coupled patch + boolList boundaryIsPatchFace_; - //- Per mesh(!) point whether is on non-coupled patch (on any - // processor) - boolList isPatchPoint_; + //- Per mesh(!) point whether is on non-coupled patch (on any + // processor) + boolList isPatchPoint_; - //- Per boundary point the weights per pointFaces. - scalarListList boundaryPointWeights_; + //- Per boundary point the weights per pointFaces. + scalarListList boundaryPointWeights_; // Private Member Functions @@ -113,11 +113,11 @@ class volPointInterpolation GeometricField& ) const; - //- Disallow default bitwise copy construct - volPointInterpolation(const volPointInterpolation&); + //- No copy construct + volPointInterpolation(const volPointInterpolation&) = delete; - //- Disallow default bitwise assignment - void operator=(const volPointInterpolation&); + //- No copy assignment + void operator=(const volPointInterpolation&) = delete; public: @@ -138,19 +138,19 @@ public: // Member functions - // Edit + // Edit - //- Update mesh topology using the morph engine - void updateMesh(const mapPolyMesh&); + //- Update mesh topology using the morph engine + void updateMesh(const mapPolyMesh&); - //- Correct weighting factors for moving mesh. - bool movePoints(); + //- Correct weighting factors for moving mesh. + bool movePoints(); - // Interpolation functions + // Interpolation Functions //- Interpolate volField using inverse distance weighting - // returning pointField + // \return pointField template tmp> interpolate ( @@ -158,7 +158,7 @@ public: ) const; //- Interpolate tmp using inverse distance weighting - // returning pointField + // \return pointField template tmp> interpolate ( @@ -188,7 +188,7 @@ public: ) const; //- Interpolate dimensionedField using inverse distance weighting - // returning pointField + // \return pointField template tmp> interpolate ( @@ -204,82 +204,82 @@ public: ) const; - // Low level + // Low level - //- Interpolate internal field from volField to pointField - // using inverse distance weighting - template - void interpolateInternalField - ( - const GeometricField&, - GeometricField& - ) const; + //- Interpolate internal field from volField to pointField + // using inverse distance weighting + template + void interpolateInternalField + ( + const GeometricField&, + GeometricField& + ) const; - //- Interpolate boundary field without applying constraints/boundary - // conditions - template - void interpolateBoundaryField - ( - const GeometricField& vf, - GeometricField& pf - ) const; + //- Interpolate boundary field without applying constraints/boundary + // conditions + template + void interpolateBoundaryField + ( + const GeometricField& vf, + GeometricField& pf + ) const; - //- Interpolate boundary with constraints/boundary conditions - template - void interpolateBoundaryField - ( - const GeometricField& vf, - GeometricField& pf, - const bool overrideFixedValue - ) const; + //- Interpolate boundary with constraints/boundary conditions + template + void interpolateBoundaryField + ( + const GeometricField& vf, + GeometricField& pf, + const bool overrideFixedValue + ) const; - //- Interpolate from volField to pointField - // using inverse distance weighting - template - void interpolate - ( - const GeometricField&, - GeometricField& - ) const; + //- Interpolate from volField to pointField + // using inverse distance weighting + template + void interpolate + ( + const GeometricField&, + GeometricField& + ) const; - //- Interpolate volField using inverse distance weighting - // returning pointField with name. Optionally caches - template - tmp> interpolate - ( - const GeometricField&, - const word& name, - const bool cache - ) const; + //- Interpolate volField using inverse distance weighting + // returning pointField with name. Optionally caches + template + tmp> interpolate + ( + const GeometricField&, + const word& name, + const bool cache + ) const; - //- Interpolate dimensioned internal field from cells to points - // using inverse distance weighting - template - void interpolateDimensionedInternalField - ( - const DimensionedField& vf, - DimensionedField& pf - ) const; + //- Interpolate dimensioned internal field from cells to points + // using inverse distance weighting + template + void interpolateDimensionedInternalField + ( + const DimensionedField& vf, + DimensionedField& pf + ) const; - //- Interpolate dimensionedField using inverse distance weighting - // returning pointField with name. Optionally caches - template - tmp> interpolate - ( - const DimensionedField&, - const word& name, - const bool cache - ) const; + //- Interpolate dimensionedField using inverse distance weighting + // returning pointField with name. Optionally caches + template + tmp> interpolate + ( + const DimensionedField&, + const word& name, + const bool cache + ) const; - // Interpolation for displacement (applies 2D correction) + // Interpolation for displacement (applies 2D correction) - //- Interpolate from volField to pointField - // using inverse distance weighting - void interpolateDisplacement - ( - const volVectorField&, - pointVectorField& - ) const; + //- Interpolate from volField to pointField + // using inverse distance weighting + void interpolateDisplacement + ( + const volVectorField&, + pointVectorField& + ) const; }; diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C index 0dbb882e84..2cd561e626 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +29,7 @@ License #include "volFields.H" #include "sampledSurface.H" #include "surfaceWriter.H" +#include "interpolationCell.H" #include "interpolationCellPoint.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -100,18 +101,15 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues // Average const faceList& faces = surfacePtr_().faces(); - tmp> tavg - ( - new Field(faces.size(), Zero) - ); - Field& avg = tavg.ref(); + auto tavg = tmp>::New(faces.size(), Zero); + auto& avg = tavg.ref(); forAll(faces, facei) { const face& f = faces[facei]; - forAll(f, fp) + for (const label labi : f) { - avg[facei] += intFld[f[fp]]; + avg[facei] += intFld[labi]; } avg[facei] /= f.size(); } @@ -120,7 +118,9 @@ Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues } else { - return surfacePtr_().sample(fld); + const interpolationCell interp(fld); + + return surfacePtr_().sample(interp); } } else diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 3bb94cc39b..438f67c235 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -19,22 +19,24 @@ sampledSet/array/arraySet.C sampledSet/shortestPath/shortestPathSet.C surface/cuttingPlane/cuttingPlane.C +surface/distanceSurface/distanceSurface.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 +surfMeshSample/surfMeshSample/surfMeshSample.C +surfMeshSample/surfMeshSamplers/surfMeshSamplers.C +surfMeshSample/distanceSurface/surfMeshSampleDistanceSurface.C +surfMeshSample/plane/surfMeshSamplePlane.C +surfMeshSample/triSurfaceMesh/surfMeshSampleDiscrete.C sampledSurface/sampledPatch/sampledPatch.C sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C sampledSurface/sampledPlane/sampledPlane.C sampledSurface/isoSurface/sampledIsoSurface.C sampledSurface/isoSurface/sampledIsoSurfaceCell.C -sampledSurface/distanceSurface/distanceSurface.C +sampledSurface/distanceSurface/sampledDistanceSurface.C sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C sampledSurface/sampledSurface/sampledSurface.C sampledSurface/sampledSurfaces/sampledSurfaces.C diff --git a/src/sampling/probes/probes.C b/src/sampling/probes/probes.C index ad9c9fdb07..562702f8c9 100644 --- a/src/sampling/probes/probes.C +++ b/src/sampling/probes/probes.C @@ -214,8 +214,7 @@ Foam::label Foam::probes::prepare() { probeDir = mesh_.time().path()/probeSubDir; } - // Remove ".." - probeDir.clean(); + probeDir.clean(); // Remove unneeded ".." // ignore known fields, close streams for fields that no longer exist forAllIter(HashPtrTable, probeFilePtrs_, iter) diff --git a/src/sampling/sampledSet/sampledSets/sampledSets.C b/src/sampling/sampledSet/sampledSets/sampledSets.C index 4cfbc9cc3a..014a30a8c2 100644 --- a/src/sampling/sampledSet/sampledSets/sampledSets.C +++ b/src/sampling/sampledSet/sampledSets/sampledSets.C @@ -109,8 +109,7 @@ Foam::sampledSets::sampledSets { outputPath_ = outputPath_/mesh_.name(); } - // Remove ".." - outputPath_.clean(); + outputPath_.clean(); // Remove unneeded ".." read(dict); } @@ -145,8 +144,7 @@ Foam::sampledSets::sampledSets { outputPath_ = outputPath_/mesh_.name(); } - // Remove ".." - outputPath_.clean(); + outputPath_.clean(); // Remove unneeded ".." read(dict); } diff --git a/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.C b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.C new file mode 100644 index 0000000000..2a646ec9d9 --- /dev/null +++ b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.C @@ -0,0 +1,211 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 "sampledDistanceSurface.H" +#include "dictionary.H" +#include "volFields.H" +#include "volPointInterpolation.H" +#include "addToRunTimeSelectionTable.H" +#include "fvMesh.H" +#include "volumeType.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(sampledDistanceSurface, 0); + addNamedToRunTimeSelectionTable + ( + sampledSurface, + sampledDistanceSurface, + word, + distanceSurface + ); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::sampledDistanceSurface::sampledDistanceSurface +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + sampledSurface(name, mesh, dict), + distanceSurface(name, mesh, dict), + average_(dict.lookupOrDefault("average", false)), + needsUpdate_(true) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::sampledDistanceSurface::needsUpdate() const +{ + return needsUpdate_; +} + + +bool Foam::sampledDistanceSurface::expire() +{ + if (debug) + { + Pout<< "sampledDistanceSurface::expire :" + << " needsUpdate:" << needsUpdate_ << endl; + } + + // Clear derived data + clearGeom(); + + // already marked as expired + if (needsUpdate_) + { + return false; + } + + needsUpdate_ = true; + return true; +} + + +bool Foam::sampledDistanceSurface::update() +{ + if (debug) + { + Pout<< "sampledDistanceSurface::update :" + << " needsUpdate:" << needsUpdate_ << endl; + } + + if (!needsUpdate_) + { + return false; + } + + distanceSurface::createGeometry(); + + needsUpdate_ = false; + return true; +} + + +Foam::tmp Foam::sampledDistanceSurface::sample +( + const interpolation& sampler +) const +{ + return sampleOnFaces(sampler); +} + + +Foam::tmp Foam::sampledDistanceSurface::sample +( + const interpolation& sampler +) const +{ + return sampleOnFaces(sampler); +} + + +Foam::tmp Foam::sampledDistanceSurface::sample +( + const interpolation& sampler +) const +{ + return sampleOnFaces(sampler); +} + + +Foam::tmp Foam::sampledDistanceSurface::sample +( + const interpolation& sampler +) const +{ + return sampleOnFaces(sampler); +} + + +Foam::tmp Foam::sampledDistanceSurface::sample +( + const interpolation& sampler +) const +{ + return sampleOnFaces(sampler); +} + + +Foam::tmp Foam::sampledDistanceSurface::interpolate +( + const interpolation& interpolator +) const +{ + return sampleOnPoints(interpolator); +} + + +Foam::tmp Foam::sampledDistanceSurface::interpolate +( + const interpolation& interpolator +) const +{ + return sampleOnPoints(interpolator); +} + +Foam::tmp Foam::sampledDistanceSurface::interpolate +( + const interpolation& interpolator +) const +{ + return sampleOnPoints(interpolator); +} + + +Foam::tmp Foam::sampledDistanceSurface::interpolate +( + const interpolation& interpolator +) const +{ + return sampleOnPoints(interpolator); +} + + +Foam::tmp Foam::sampledDistanceSurface::interpolate +( + const interpolation& interpolator +) const +{ + return sampleOnPoints(interpolator); +} + + +void Foam::sampledDistanceSurface::print(Ostream& os) const +{ + os << "distanceSurface: " << name() << " :"; + distanceSurface::print(os); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.H similarity index 56% rename from src/sampling/sampledSurface/distanceSurface/distanceSurface.H rename to src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.H index 138d9d49d6..783707e8d0 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurface.H +++ b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurface.H @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -22,25 +22,51 @@ License along with OpenFOAM. If not, see . Class - Foam::distanceSurface + Foam::sampledDistanceSurface Description - A sampledSurface defined by a distance to a surface. + A sampledSurface defined by a distance to a surface - using either + an isoSurfaceCell or an isoSurface. + + This is often embedded as part of a sampled surfaces function object. + +Usage + Example of function object partial specification: + \verbatim + surfaces + ( + surface1 + { + type dDistanceSurface; + } + ); + \endverbatim + + Where the sub-entries comprise: + \table + Property | Description | Required | Default + type | distanceSurface | yes | + distance | distance from surface | yes | + signed | apply sign for +ve/-ve distance | yes | + cell | use isoSurfaceCell algorithm | no | true + regularise | point snapping | yes | + average | cell values from averaged point values | no | false + bounds | limit with bounding box | no | + surfaceType | type of surface | yes | + surfaceName | name of surface in triSurface/ | no | dict name + \endtable - Uses either isoSurfaceCell or isoSurface. SourceFiles - distanceSurface.C + sampledDistanceSurface.C \*---------------------------------------------------------------------------*/ -#ifndef distanceSurface_H -#define distanceSurface_H +#ifndef sampledDistanceSurface_H +#define sampledDistanceSurface_H #include "sampledSurface.H" -#include "searchableSurface.H" -#include "isoSurfaceCell.H" -#include "isoSurface.H" +#include "distanceSurface.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -48,109 +74,59 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class distanceSurface Declaration + Class sampledDistanceSurface Declaration \*---------------------------------------------------------------------------*/ -class distanceSurface +class sampledDistanceSurface : - public sampledSurface + public sampledSurface, + public distanceSurface { // Private data - //- Surface - const autoPtr surfPtr_; - - //- Distance value - const scalar distance_; - - //- Signed distance - const bool signed_; - - //- Whether to use isoSurfaceCell or isoSurface - const bool cell_; - - //- Whether to coarsen - const Switch regularise_; - //- Whether to recalculate cell values as average of point values const Switch average_; - //- Optional bounding box to trim triangles against - const boundBox bounds_; - - //- If restricted to zones, name of this zone or a regular expression - keyType zoneKey_; - //- Track if the surface needs an update mutable bool needsUpdate_; - //- Distance to cell centres - autoPtr cellDistancePtr_; - - //- Distance to points - scalarField pointDistance_; - - //- Constructed iso surface - autoPtr isoSurfCellPtr_; - - //- Constructed iso surface - autoPtr isoSurfPtr_; - - // Private Member Functions - //- Create iso surface - void createGeometry(); - - //- Sample field on faces + //- Sample volume field onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const; - + //- Interpolate volume field onto surface points template - tmp> - interpolateField(const interpolation&) const; + tmp> sampleOnPoints + ( + const interpolation& interpolation + ) const; public: //- Runtime type information - TypeName("distanceSurface"); + TypeName("sampledDistanceSurface"); // Constructors //- Construct from dictionary - distanceSurface + sampledDistanceSurface ( const word& name, const polyMesh& mesh, const dictionary& dict ); - //- Construct from components - distanceSurface - ( - const word& name, - const polyMesh& mesh, - const bool interpolate, - const word& surfaceType, - const word& surfaceName, - const scalar distance, - const bool signedDistance, - const bool cell, - const Switch regularise, - const Switch average, - const boundBox& bounds = boundBox::invertedBox - ); - //- Destructor - virtual ~distanceSurface(); + virtual ~sampledDistanceSurface() = default; // Member Functions @@ -204,81 +180,76 @@ public: } - //- The underlying surface - const meshedSurface& surface() const - { - if (cell_) - { - return *isoSurfCellPtr_; - } + // Sample - return *isoSurfPtr_; - } - - - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volScalarField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volVectorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSphericalTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSymmTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volTensorField& + const interpolation& sampler ) const; - //- Interpolate field on surface + // Interpolate + + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Write - virtual void print(Ostream&) const; + + // Output + + //- Print information + virtual void print(Ostream& os) const; }; @@ -289,7 +260,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository - #include "distanceSurfaceTemplates.C" + #include "sampledDistanceSurfaceTemplates.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurfaceTemplates.C similarity index 54% rename from src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C rename to src/sampling/sampledSurface/distanceSurface/sampledDistanceSurfaceTemplates.C index c1411e378b..f6134eacaa 100644 --- a/src/sampling/sampledSurface/distanceSurface/distanceSurfaceTemplates.C +++ b/src/sampling/sampledSurface/distanceSurface/sampledDistanceSurfaceTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "distanceSurface.H" +#include "sampledDistanceSurface.H" #include "volFieldsFwd.H" #include "pointFields.H" #include "volPointInterpolation.H" @@ -32,71 +32,39 @@ License template Foam::tmp> -Foam::distanceSurface::sampleField +Foam::sampledDistanceSurface::sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const { - if (cell_) - { - return tmp> - ( - new Field(vField, isoSurfCellPtr_().meshCells()) - ); - } - else - { - return tmp> - ( - new Field(vField, isoSurfPtr_().meshCells()) - ); - } + return sampledSurface::sampleOnFaces + ( + sampler, + meshCells(), + faces(), + points() + ); } template Foam::tmp> -Foam::distanceSurface::interpolateField +Foam::sampledDistanceSurface::sampleOnPoints ( const interpolation& interpolator ) const { - const fvMesh& fvm = static_cast(mesh()); + // Assume volPointInterpolation for the point field! + const auto& volFld = interpolator.psi(); - // Get fields to sample. Assume volPointInterpolation! - const GeometricField& volFld = - interpolator.psi(); + auto tpointFld = + volPointInterpolation::New(volFld.mesh()).interpolate(volFld); - tmp> pointFld + return distanceSurface::interpolate ( - volPointInterpolation::New(fvm).interpolate(volFld) + (average_ ? pointAverage(tpointFld())() : volFld), + tpointFld() ); - - // Sample. - if (cell_) - { - return isoSurfCellPtr_().interpolate - ( - ( - average_ - ? pointAverage(pointFld())() - : volFld - ), - pointFld() - ); - } - else - { - return isoSurfPtr_().interpolate - ( - ( - average_ - ? pointAverage(pointFld())() - : volFld - ), - pointFld() - ); - } } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C index ddf3ebe114..17bebb0043 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -538,13 +538,13 @@ bool Foam::sampledIsoSurface::expire() // Clear derived data clearGeom(); - // already marked as expired + // Already marked as expired if (prevTimeIndex_ == -1) { return false; } - // force update + // Force update prevTimeIndex_ = -1; return true; } @@ -558,46 +558,46 @@ bool Foam::sampledIsoSurface::update() Foam::tmp Foam::sampledIsoSurface::sample ( - const volScalarField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurface::sample ( - const volVectorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurface::sample ( - const volSphericalTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurface::sample ( - const volSymmTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurface::sample ( - const volTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } @@ -606,7 +606,7 @@ Foam::tmp Foam::sampledIsoSurface::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -615,7 +615,7 @@ Foam::tmp Foam::sampledIsoSurface::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } Foam::tmp Foam::sampledIsoSurface::interpolate @@ -623,7 +623,7 @@ Foam::tmp Foam::sampledIsoSurface::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -632,7 +632,7 @@ Foam::tmp Foam::sampledIsoSurface::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -641,7 +641,7 @@ Foam::tmp Foam::sampledIsoSurface::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H index 97a2d5eb39..3c83c5c5bb 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurface.H @@ -3,7 +3,7 @@ \\ / 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. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,6 +29,35 @@ Description To be used in sampleSurfaces / functionObjects. Recalculates iso surface only if time changes. + This is often embedded as part of a sampled surfaces function object. + +Usage + Example of function object partial specification: + \verbatim + surfaces + ( + surface1 + { + type sampledIsoSurface; + cell false; + } + ); + \endverbatim + + Where the sub-entries comprise: + \table + Property | Description | Required | Default + type | sampledIsoSurface | yes | + isoField | field name for obtaining iso-surface | yes | + isoValue | value of iso-surface | yes | + mergeTol | tolerance for merging points | no | 1e-6 + regularise | point snapping | yes | + average | cell values from averaged point values | no | false + bounds | limit with bounding box | no | + zone | limit to specified zone | no | + exposedPatchName | name for zone subset | partly | + \endtable + SourceFiles sampledIsoSurface.C @@ -84,30 +113,29 @@ class sampledIsoSurface mutable autoPtr surfPtr_; - // Recreated for every isoSurface + // Recreated for every isoSurface - //- Time at last call, also track if surface needs an update - mutable label prevTimeIndex_; + //- Time at last call, also track if surface needs an update + mutable label prevTimeIndex_; - //- Cached volfield - mutable autoPtr storedVolFieldPtr_; - mutable const volScalarField* volFieldPtr_; + //- Cached volfield + mutable autoPtr storedVolFieldPtr_; + mutable const volScalarField* volFieldPtr_; - //- Cached pointfield - mutable const pointScalarField* pointFieldPtr_; + //- Cached pointfield + mutable const pointScalarField* pointFieldPtr_; - // And on subsetted mesh + // And on subsetted mesh - //- Cached submesh - mutable autoPtr subMeshPtr_; + //- Cached submesh + mutable autoPtr subMeshPtr_; - //- Cached volfield - mutable autoPtr storedVolSubFieldPtr_; - mutable const volScalarField* volSubFieldPtr_; - - //- Cached pointfield - mutable const pointScalarField* pointSubFieldPtr_; + //- Cached volfield + mutable autoPtr storedVolSubFieldPtr_; + mutable const volScalarField* volSubFieldPtr_; + //- Cached pointfield + mutable const pointScalarField* pointSubFieldPtr_; // Private Member Functions @@ -119,17 +147,19 @@ class sampledIsoSurface // Do nothing (and return false) if no update was needed bool updateGeometry() const; - //- Sample field on faces + //- Sample volume field onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const; - + //- Interpolate volume field onto surface points template - tmp> - interpolateField(const interpolation&) const; + tmp> sampleOnPoints + ( + const interpolation& interpolator + ) const; public: @@ -217,67 +247,67 @@ public: // Sample - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volScalarField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volVectorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSphericalTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSymmTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volTensorField& + const interpolation& sampler ) const; // Interpolate - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C index 5690220b7c..0c329b200e 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,7 +51,7 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const { const fvMesh& fvm = static_cast(mesh()); - // no update needed + // No update needed if (fvm.time().timeIndex() == prevTimeIndex_) { return false; @@ -62,76 +62,67 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const // Clear derived data sampledSurface::clearGeom(); - // Optionally read volScalarField - autoPtr readFieldPtr_; + // Use field from database, or try to read it in - // 1. see if field in database - // 2. see if field can be read - const volScalarField* cellFldPtr = nullptr; - if (fvm.foundObject(isoField_)) + const auto* cellFldPtr = fvm.lookupObjectPtr(isoField_); + + if (debug) { - if (debug) + if (cellFldPtr) { InfoInFunction << "Lookup " << isoField_ << endl; } - - cellFldPtr = &fvm.lookupObject(isoField_); - } - else - { - // Bit of a hack. Read field and store. - - if (debug) + else { InfoInFunction << "Reading " << isoField_ - << " from time " <(); } - const volScalarField& cellFld = *cellFldPtr; - tmp pointFld - ( - volPointInterpolation::New(fvm).interpolate(cellFld) - ); + // For holding the volScalarField read in. + autoPtr fieldReadPtr; + + if (!cellFldPtr) + { + // Bit of a hack. Read field and store. + + fieldReadPtr = autoPtr::New + ( + IOobject + ( + isoField_, + fvm.time().timeName(), + fvm, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ), + fvm + ); + } + + const volScalarField& cellFld = + (fieldReadPtr.valid() ? *fieldReadPtr : *cellFldPtr); + + auto tpointFld = volPointInterpolation::New(fvm).interpolate(cellFld); if (average_) { //- From point field and interpolated cell. - scalarField cellAvg(fvm.nCells(), scalar(0.0)); - labelField nPointCells(fvm.nCells(), 0); + scalarField cellAvg(fvm.nCells(), Zero); + labelField nPointCells(fvm.nCells(), Zero); + + for (label pointi = 0; pointi < fvm.nPoints(); ++pointi) { - for (label pointi = 0; pointi < fvm.nPoints(); pointi++) + const scalar& val = tpointFld().primitiveField()[pointi]; + const labelList& pCells = fvm.pointCells(pointi); + + for (const label celli : pCells) { - const labelList& pCells = fvm.pointCells(pointi); - - forAll(pCells, i) - { - label celli = pCells[i]; - - cellAvg[celli] += pointFld().primitiveField()[pointi]; - nPointCells[celli]++; - } + cellAvg[celli] += val; + ++nPointCells[celli]; } } forAll(cellAvg, celli) @@ -139,11 +130,11 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const cellAvg[celli] /= nPointCells[celli]; } - isoSurfaceCell iso + isoSurfaceCell surf ( fvm, cellAvg, - pointFld().primitiveField(), + tpointFld().primitiveField(), isoVal_, regularise_, bounds_ @@ -152,17 +143,17 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const const_cast ( *this - ).transfer(static_cast(iso)); - meshCells_ = iso.meshCells(); + ).transfer(static_cast(surf)); + meshCells_.transfer(surf.meshCells()); } else { //- Direct from cell field and point field. Gives bad continuity. - isoSurfaceCell iso + isoSurfaceCell surf ( fvm, cellFld.primitiveField(), - pointFld().primitiveField(), + tpointFld().primitiveField(), isoVal_, regularise_, bounds_ @@ -171,8 +162,8 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const const_cast ( *this - ).transfer(static_cast(iso)); - meshCells_ = iso.meshCells(); + ).transfer(static_cast(surf)); + meshCells_.transfer(surf.meshCells()); } @@ -212,7 +203,7 @@ Foam::sampledIsoSurfaceCell::sampledIsoSurfaceCell average_(dict.lookupOrDefault("average", true)), zoneKey_(keyType::null), prevTimeIndex_(-1), - meshCells_(0) + meshCells_() {} @@ -237,13 +228,13 @@ bool Foam::sampledIsoSurfaceCell::expire() // Clear derived data sampledSurface::clearGeom(); - // already marked as expired + // Already marked as expired if (prevTimeIndex_ == -1) { return false; } - // force update + // Force update prevTimeIndex_ = -1; return true; } @@ -258,50 +249,50 @@ bool Foam::sampledIsoSurfaceCell::update() Foam::tmp Foam::sampledIsoSurfaceCell::sample ( - const volScalarField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurfaceCell::sample ( - const volVectorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurfaceCell::sample ( - const volSphericalTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurfaceCell::sample ( - const volSymmTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledIsoSurfaceCell::sample ( - const volTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } @@ -311,7 +302,7 @@ Foam::sampledIsoSurfaceCell::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -321,7 +312,7 @@ Foam::sampledIsoSurfaceCell::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } Foam::tmp @@ -330,7 +321,7 @@ Foam::sampledIsoSurfaceCell::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -340,7 +331,7 @@ Foam::sampledIsoSurfaceCell::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -350,7 +341,7 @@ Foam::sampledIsoSurfaceCell::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H index d88bf87b55..86188f264a 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCell.H @@ -29,6 +29,33 @@ Description To be used in sampleSurfaces / functionObjects. Recalculates iso surface only if time changes. + This is often embedded as part of a sampled surfaces function object. + +Usage + Example of function object partial specification: + \verbatim + surfaces + ( + surface1 + { + type sampledIsoSurfaceCell; + cell true; + } + ); + \endverbatim + + Where the sub-entries comprise: + \table + Property | Description | Required | Default + type | sampledIsoSurfaceCell | yes | + isoField | field name for obtaining iso-surface | yes | + isoValue | value of iso-surface | yes | + mergeTol | tolerance for merging points | no | 1e-6 + regularise | point snapping | yes | + average | cell values from averaged point values | no | false + bounds | limit with bounding box | no | + \endtable + SourceFiles sampledIsoSurfaceCell.C @@ -79,13 +106,13 @@ class sampledIsoSurfaceCell keyType zoneKey_; - // Recreated for every isoSurface + // Recreated for every isoSurface - //- Time at last call, also track it surface needs an update - mutable label prevTimeIndex_; + //- Time at last call, also track it surface needs an update + mutable label prevTimeIndex_; - //- For every triangle the original cell in mesh - mutable labelList meshCells_; + //- For every triangle the original cell in mesh + mutable labelList meshCells_; // Private Member Functions @@ -94,17 +121,19 @@ class sampledIsoSurfaceCell // Do nothing (and return false) if no update was needed bool updateGeometry() const; - //- Sample field on faces + //- Sample volume field onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const; - + //- Interpolate volume field onto surface points template - tmp> - interpolateField(const interpolation&) const; + tmp> sampleOnPoints + ( + const interpolation& interpolator + ) const; public: @@ -180,65 +209,69 @@ public: } - //- Sample field on surface + // Sample + + //- Sample volume field onto surface faces virtual tmp sample ( - const volScalarField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volVectorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSphericalTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSymmTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volTensorField& + const interpolation& sampler ) const; - //- Interpolate field on surface + // Interpolate + + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; //- Write diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C index ffaa1ff8c0..0d2e71b2f2 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceCellTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -33,50 +33,57 @@ License template Foam::tmp> -Foam::sampledIsoSurfaceCell::sampleField +Foam::sampledIsoSurfaceCell::sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const { - // Recreate geometry if time has changed - updateGeometry(); + updateGeometry(); // Recreate geometry if time has changed - return tmp>::New(vField, meshCells_); + return sampledSurface::sampleOnFaces + ( + sampler, + meshCells_, + faces(), + points() + ); } template Foam::tmp> -Foam::sampledIsoSurfaceCell::interpolateField +Foam::sampledIsoSurfaceCell::sampleOnPoints ( const interpolation& interpolator ) const { - // Recreate geometry if time has changed - updateGeometry(); + updateGeometry(); // Recreate geometry if time has changed + + const labelList& elements = meshCells_; // One value per point - tmp> tvalues(new Field(points().size())); - Field& values = tvalues.ref(); + auto tvalues = tmp>::New(points().size()); + auto& values = tvalues.ref(); - boolList pointDone(points().size(), false); + const faceList& fcs = faces(); + const pointField& pts = points(); + + bitSet pointDone(points().size()); forAll(faces(), cutFacei) { - const face& f = faces()[cutFacei]; + const face& f = fcs[cutFacei]; + const label celli = elements[cutFacei]; - forAll(f, faceVertI) + for (const label pointi : f) { - label pointi = f[faceVertI]; - - if (!pointDone[pointi]) + if (pointDone.set(pointi)) { values[pointi] = interpolator.interpolate ( - points()[pointi], - meshCells_[cutFacei] + pts[pointi], + celli ); - pointDone[pointi] = true; } } } diff --git a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C index 859c82c741..a68d6debfb 100644 --- a/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C +++ b/src/sampling/sampledSurface/isoSurface/sampledIsoSurfaceTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,70 +32,59 @@ License template Foam::tmp> -Foam::sampledIsoSurface::sampleField +Foam::sampledIsoSurface::sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const { - // Recreate geometry if time has changed - updateGeometry(); + updateGeometry(); // Recreate geometry if time has changed - return tmp>::New(vField, surface().meshCells()); + return sampledSurface::sampleOnFaces + ( + sampler, + surface().meshCells(), + surface(), + points() + ); } template Foam::tmp> -Foam::sampledIsoSurface::interpolateField +Foam::sampledIsoSurface::sampleOnPoints ( const interpolation& interpolator ) const { - // Get fields to sample. Assume volPointInterpolation! - const GeometricField& volFld = - interpolator.psi(); + updateGeometry(); // Recreate geometry if time has changed - // Recreate geometry if time has changed - updateGeometry(); + // Assume volPointInterpolation for the point field! + const auto& volFld = interpolator.psi(); if (subMeshPtr_.valid()) { - tmp> tvolSubFld = - subMeshPtr_().interpolate(volFld); + auto tvolSubFld = subMeshPtr_().interpolate(volFld); + const auto& volSubFld = tvolSubFld(); - const GeometricField& volSubFld = - tvolSubFld(); - - tmp> tpointSubFld = + auto tpointFld = volPointInterpolation::New(volSubFld.mesh()).interpolate(volSubFld); - // Sample. return surface().interpolate ( - ( - average_ - ? pointAverage(tpointSubFld())() - : volSubFld - ), - tpointSubFld() - ); - } - else - { - tmp> tpointFld = - volPointInterpolation::New(volFld.mesh()).interpolate(volFld); - - // Sample. - return surface().interpolate - ( - ( - average_ - ? pointAverage(tpointFld())() - : volFld - ), + (average_ ? pointAverage(tpointFld())() : volSubFld), tpointFld() ); } + + + auto tpointFld = + volPointInterpolation::New(volFld.mesh()).interpolate(volFld); + + return surface().interpolate + ( + (average_ ? pointAverage(tpointFld())() : volFld), + tpointFld() + ); } diff --git a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C index efcd6b6f97..0275d48231 100644 --- a/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C +++ b/src/sampling/sampledSurface/readers/ensight/ensightSurfaceReaderTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -164,21 +164,16 @@ Foam::tmp> Foam::ensightSurfaceReader::readField } } - tmp> tField(new Field(n, pTraits::zero)); - Field& field = tField.ref(); + auto tfield = tmp>::New(n, Zero); + auto& field = tfield.ref(); - for - ( - direction cmptI=0; - cmptI < pTraits::nComponents; - ++cmptI - ) + for (direction cmpti=0; cmpti < pTraits::nComponents; ++cmpti) { - field.replace(cmptI, values[cmptI]); - values[cmptI].clear(); + field.replace(cmpti, values[cmpti]); + values[cmpti].clear(); } - return tField; + return tfield; } diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C index 7badfa4885..f92e21de37 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -386,50 +386,50 @@ bool Foam::sampledCuttingPlane::update() Foam::tmp Foam::sampledCuttingPlane::sample ( - const volScalarField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledCuttingPlane::sample ( - const volVectorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledCuttingPlane::sample ( - const volSphericalTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledCuttingPlane::sample ( - const volSymmTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledCuttingPlane::sample ( - const volTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } @@ -439,7 +439,7 @@ Foam::sampledCuttingPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -449,16 +449,17 @@ Foam::sampledCuttingPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } + Foam::tmp Foam::sampledCuttingPlane::interpolate ( const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -468,7 +469,7 @@ Foam::sampledCuttingPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -478,7 +479,7 @@ Foam::sampledCuttingPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H index 1b868d2a6c..915ee45b5c 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlane.H @@ -3,7 +3,7 @@ \\ / 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. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,7 +26,41 @@ Class Description A sampledSurface defined by a plane using the iso-surface algorithm - to 'cut' the mesh. + to \a cut the mesh. + + This is often embedded as part of a sampled surfaces function object. + +Usage + Example of function object partial specification: + \verbatim + surfaces + ( + surface1 + { + type cuttingPlane; + planeType pointAndNormal; + pointAndNormalDict + { + ... + } + } + ); + \endverbatim + + Where the sub-entries comprise: + \table + Property | Description | Required | Default + type | cuttingPlane | yes | + planeType | plane description (pointAndNormal etc) | yes | + mergeTol | tolerance for merging points | no | 1e-6 + regularise | point snapping | no | true + bounds | limit with bounding box | no | + zone | limit to specified zone | no | + exposedPatchName | name for zone subset | partly | + \endtable + +SeeAlso + Foam::plane SourceFiles sampledCuttingPlane.C @@ -49,7 +83,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class sampledCuttingPlane Declaration + Class sampledCuttingPlane Declaration \*---------------------------------------------------------------------------*/ class sampledCuttingPlane @@ -93,7 +127,7 @@ class sampledCuttingPlane scalarField pointDistance_; //- Constructed iso surface - //autoPtr isoSurfPtr_; + //autoPtr isoSurfCellPtr_; autoPtr isoSurfPtr_; @@ -102,17 +136,19 @@ class sampledCuttingPlane //- Create iso surface void createGeometry(); - //- Sample field on faces + //- Sample volume field onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const; - + //- Interpolate volume field onto surface points template - tmp> - interpolateField(const interpolation&) const; + tmp> sampleOnPoints + ( + const interpolation& interpolator + ) const; public: @@ -193,76 +229,95 @@ public: } + //- The underlying surface + meshedSurface& surface() + { + return *isoSurfPtr_; + } + + //- For each face, the original cell in mesh + const labelList& meshCells() const + { + return isoSurfPtr_->meshCells(); + } + + //- For each face, the original cell in mesh + labelList& meshCells() + { + return isoSurfPtr_->meshCells(); + } + + // Sample - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volScalarField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volVectorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSphericalTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSymmTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volTensorField& + const interpolation& sampler ) const; // Interpolate - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; // Output - //- Write - virtual void print(Ostream&) const; + //- Print information + virtual void print(Ostream& os) const; }; diff --git a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C index 27dade962d..fcf2d2dc80 100644 --- a/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C +++ b/src/sampling/sampledSurface/sampledCuttingPlane/sampledCuttingPlaneTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,66 +32,55 @@ License template Foam::tmp> -Foam::sampledCuttingPlane::sampleField +Foam::sampledCuttingPlane::sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const { - return tmp>::New(vField, surface().meshCells()); + return sampledSurface::sampleOnFaces + ( + sampler, + meshCells(), + faces(), + points() + ); } template Foam::tmp> -Foam::sampledCuttingPlane::interpolateField +Foam::sampledCuttingPlane::sampleOnPoints ( const interpolation& interpolator ) const { - // Get fields to sample. Assume volPointInterpolation! - const GeometricField& volFld = - interpolator.psi(); + // Assume volPointInterpolation for the point field! + const auto& volFld = interpolator.psi(); if (subMeshPtr_.valid()) { - tmp> tvolSubFld = - subMeshPtr_().interpolate(volFld); + auto tvolSubFld = subMeshPtr_().interpolate(volFld); + const auto& volSubFld = tvolSubFld(); - const GeometricField& volSubFld = - tvolSubFld(); - - tmp> tpointSubFld = + auto tpointFld = volPointInterpolation::New(volSubFld.mesh()).interpolate(volSubFld); - // Sample. return surface().interpolate ( - ( - average_ - ? pointAverage(tpointSubFld())() - : volSubFld - ), - tpointSubFld() - ); - } - else - { - tmp> tpointFld - ( - volPointInterpolation::New(volFld.mesh()).interpolate(volFld) - ); - - // Sample. - return surface().interpolate - ( - ( - average_ - ? pointAverage(tpointFld())() - : volFld - ), + (average_ ? pointAverage(tpointFld())() : volSubFld), tpointFld() ); } + + + auto tpointFld = + volPointInterpolation::New(volFld.mesh()).interpolate(volFld); + + return surface().interpolate + ( + (average_ ? pointAverage(tpointFld())() : volFld), + tpointFld() + ); } diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.C b/src/sampling/sampledSurface/sampledPatch/sampledPatch.C index ddb69bb1dd..f778e8a42d 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.C +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -118,10 +118,8 @@ bool Foam::sampledPatch::update() } label sz = 0; - forAll(patchIDs(), i) + for (const label patchi : patchIDs()) { - const label patchi = patchIDs()[i]; - const polyPatch& pp = mesh().boundaryMesh()[patchi]; if (isA(pp)) @@ -156,7 +154,7 @@ bool Foam::sampledPatch::update() patchIndex_[sz] = i; patchFaceLabels_[sz] = j; meshFaceLabels[sz] = pp.start()+j; - sz++; + ++sz; } } @@ -224,46 +222,46 @@ void Foam::sampledPatch::remapFaces(const labelUList& faceMap) Foam::tmp Foam::sampledPatch::sample ( - const volScalarField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPatch::sample ( - const volVectorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPatch::sample ( - const volSphericalTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPatch::sample ( - const volSymmTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPatch::sample ( - const volTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } @@ -272,7 +270,7 @@ Foam::tmp Foam::sampledPatch::sample const surfaceScalarField& sField ) const { - return sampleField(sField); + return sampleOnFaces(sField); } @@ -281,7 +279,7 @@ Foam::tmp Foam::sampledPatch::sample const surfaceVectorField& sField ) const { - return sampleField(sField); + return sampleOnFaces(sField); } @@ -290,7 +288,7 @@ Foam::tmp Foam::sampledPatch::sample const surfaceSphericalTensorField& sField ) const { - return sampleField(sField); + return sampleOnFaces(sField); } @@ -299,7 +297,7 @@ Foam::tmp Foam::sampledPatch::sample const surfaceSymmTensorField& sField ) const { - return sampleField(sField); + return sampleOnFaces(sField); } @@ -308,7 +306,7 @@ Foam::tmp Foam::sampledPatch::sample const surfaceTensorField& sField ) const { - return sampleField(sField); + return sampleOnFaces(sField); } @@ -317,7 +315,7 @@ Foam::tmp Foam::sampledPatch::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -326,7 +324,7 @@ Foam::tmp Foam::sampledPatch::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -335,7 +333,7 @@ Foam::tmp Foam::sampledPatch::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -344,7 +342,7 @@ Foam::tmp Foam::sampledPatch::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -353,7 +351,7 @@ Foam::tmp Foam::sampledPatch::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H index 17f4b63340..a6afdbe612 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatch.H +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatch.H @@ -27,6 +27,29 @@ Class Description A sampledSurface on patches. Non-triangulated by default. + This is often embedded as part of a sampled surfaces function object. + +Usage + Example of function object partial specification: + \verbatim + surfaces + ( + surface1 + { + type patch; + patches (inlet "outlet.*"); + } + ); + \endverbatim + + Where the sub-entries comprise: + \table + Property | Description | Required | Default + type | patch | yes | + patches | patch selection as word/regex list | yes | + triangulate | triangulate faces | no | false + \endtable + SourceFiles sampledPatch.C @@ -83,22 +106,27 @@ class sampledPatch // Private Member Functions - //- Sample field on faces + //- Sample boundary field (from volume field) onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const; - //- Sample surface field on faces + //- Sample boundary field (from surface field) onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( const GeometricField& sField ) const; + //- Interpolate boundary field (from volume field) onto surface points template - tmp> interpolateField(const interpolation&) const; + tmp> sampleOnPoints + ( + const interpolation& interpolator + ) const; + //- Re-map action on triangulation or cleanup virtual void remapFaces(const labelUList& faceMap); @@ -206,100 +234,104 @@ public: } - // Sample + // Sample - //- Sample field on surface - virtual tmp sample - ( - const volScalarField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volVectorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volSphericalTensorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volSymmTensorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volTensorField& - ) const; - - //- Surface sample field on surface - virtual tmp sample - ( - const surfaceScalarField& - ) const; - - //- Surface Sample field on surface - virtual tmp sample - ( - const surfaceVectorField& - ) const; - - //- Surface sample field on surface - virtual tmp sample - ( - const surfaceSphericalTensorField& - ) const; - - //- Surface sample field on surface - virtual tmp sample - ( - const surfaceSymmTensorField& - ) const; - - //- Surface sample field on surface - virtual tmp sample - ( - const surfaceTensorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - // Interpolate + //- Sample boundary of surface field on surface + virtual tmp sample + ( + const surfaceScalarField& + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Sample boundary of surface field on surface + virtual tmp sample + ( + const surfaceVectorField& + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Sample boundary of surface field on surface + virtual tmp sample + ( + const surfaceSphericalTensorField& + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Sample boundary of surface field on surface + virtual tmp sample + ( + const surfaceSymmTensorField& + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Sample boundary of surface field on surface + virtual tmp sample + ( + const surfaceTensorField& + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + + // Interpolate + + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + + // Output //- Write virtual void print(Ostream&) const; diff --git a/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C b/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C index 7265c5ea14..244f61b45a 100644 --- a/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C +++ b/src/sampling/sampledSurface/sampledPatch/sampledPatchTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,19 +29,23 @@ License template Foam::tmp> -Foam::sampledPatch::sampleField +Foam::sampledPatch::sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const { + const auto& vField = sampler.psi(); + // One value per face - tmp> tvalues(new Field(patchFaceLabels_.size())); - Field& values = tvalues.ref(); + auto tvalues = tmp>::New(patchFaceLabels_.size()); + auto& values = tvalues.ref(); + forAll(patchFaceLabels_, i) { - label patchi = patchIDs_[patchIndex_[i]]; - const Field& bField = vField.boundaryField()[patchi]; - values[i] = bField[patchFaceLabels_[i]]; + const label patchi = patchIDs_[patchIndex_[i]]; + const label patchFacei = patchFaceLabels_[i]; + + values[i] = vField.boundaryField()[patchi][patchFacei]; } return tvalues; @@ -50,19 +54,21 @@ Foam::sampledPatch::sampleField template Foam::tmp> -Foam::sampledPatch::sampleField +Foam::sampledPatch::sampleOnFaces ( const GeometricField& sField ) const { // One value per face - tmp> tvalues(new Field(patchFaceLabels_.size())); - Field& values = tvalues.ref(); + auto tvalues = tmp>::New(patchFaceLabels_.size()); + auto& values = tvalues.ref(); forAll(patchFaceLabels_, i) { - label patchi = patchIDs_[patchIndex_[i]]; - values[i] = sField.boundaryField()[patchi][patchFaceLabels_[i]]; + const label patchi = patchIDs_[patchIndex_[i]]; + const label patchFacei = patchFaceLabels_[i]; + + values[i] = sField.boundaryField()[patchi][patchFacei]; } return tvalues; @@ -71,34 +77,32 @@ Foam::sampledPatch::sampleField template Foam::tmp> -Foam::sampledPatch::interpolateField +Foam::sampledPatch::sampleOnPoints ( const interpolation& interpolator ) const { // One value per vertex - tmp> tvalues(new Field(points().size())); - Field& values = tvalues.ref(); + auto tvalues = tmp>::New(points().size()); + auto& values = tvalues.ref(); const labelList& own = mesh().faceOwner(); - boolList pointDone(points().size(), false); + bitSet pointDone(points().size()); forAll(faces(), cutFacei) { - label patchi = patchIDs_[patchIndex_[cutFacei]]; + const label patchi = patchIDs_[patchIndex_[cutFacei]]; const polyPatch& pp = mesh().boundaryMesh()[patchi]; - label patchFacei = patchFaceLabels()[cutFacei]; + const label patchFacei = patchFaceLabels()[cutFacei]; const face& f = faces()[cutFacei]; - forAll(f, faceVertI) + for (const label pointi : f) { - label pointi = f[faceVertI]; - - if (!pointDone[pointi]) + if (pointDone.set(pointi)) { - label facei = patchFacei + pp.start(); - label celli = own[facei]; + const label facei = patchFacei + pp.start(); + const label celli = own[facei]; values[pointi] = interpolator.interpolate ( @@ -106,7 +110,6 @@ Foam::sampledPatch::interpolateField celli, facei ); - pointDone[pointi] = true; } } } diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C index a133fdd8ce..46b65703e1 100644 --- a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C +++ b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -135,55 +135,50 @@ Foam::sampledPatchInternalField::sampledPatchInternalField } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::sampledPatchInternalField::~sampledPatchInternalField() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // Foam::tmp Foam::sampledPatchInternalField::sample ( - const volScalarField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPatchInternalField::sample ( - const volVectorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } + Foam::tmp Foam::sampledPatchInternalField::sample ( - const volSphericalTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPatchInternalField::sample ( - const volSymmTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPatchInternalField::sample ( - const volTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } @@ -192,7 +187,7 @@ Foam::tmp Foam::sampledPatchInternalField::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -201,7 +196,7 @@ Foam::tmp Foam::sampledPatchInternalField::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -211,7 +206,7 @@ Foam::sampledPatchInternalField::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -220,7 +215,7 @@ Foam::tmp Foam::sampledPatchInternalField::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -229,7 +224,7 @@ Foam::tmp Foam::sampledPatchInternalField::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H index 59671c946e..fd32180c03 100644 --- a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H +++ b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -32,6 +32,34 @@ Description - interpolate=true : interpolate inside cell and interpolate to points There is no option to get interpolated value inside the cell on the faces. + This is often embedded as part of a sampled surfaces function object. + +Usage + Example of function object partial specification: + \verbatim + surfaces + ( + surface1 + { + type patchInternalField; + patches (inlet "outlet.*"); + offsetMode normal; + distance 0.05; + } + ); + \endverbatim + + Where the sub-entries comprise: + \table + Property | Description | Required | Default + type | patchInternalField | yes | + patches | patch selection as word/regex list | yes | + offsetMode | normal/uniform/nonuniform | no | normal + distance | distance for normal offset | partly | + offset | point offset for uniform offset | partly | + offsets | point offsets for nonuniform offset | partly | + \endtable + SourceFiles sampledPatchInternalField.C @@ -64,15 +92,19 @@ class sampledPatchInternalField // Private Member Functions - //- Sample field on faces + //- Sample volume field onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const; + //- Interpolate volume field onto surface points template - tmp> interpolateField(const interpolation&) const; + tmp> sampleOnPoints + ( + const interpolation& interpolator + ) const; public: @@ -93,79 +125,81 @@ public: //- Destructor - virtual ~sampledPatchInternalField(); + virtual ~sampledPatchInternalField() = default; // Member Functions - // Sample + // Sample - //- Sample field on surface - virtual tmp sample - ( - const volScalarField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volVectorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volSphericalTensorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volSymmTensorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - //- Sample field on surface - virtual tmp sample - ( - const volTensorField& - ) const; + //- Sample boundary of volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; - // Interpolate + // Interpolate - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; - //- Interpolate field on surface - virtual tmp interpolate - ( - const interpolation& - ) const; + //- Interpolate boundary of volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; - //- Write - virtual void print(Ostream&) const; + // Output + + //- Print information + virtual void print(Ostream& os) const; }; diff --git a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C index 211f55ca91..54b5198107 100644 --- a/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C +++ b/src/sampling/sampledSurface/sampledPatchInternalField/sampledPatchInternalFieldTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -31,14 +31,16 @@ License template Foam::tmp> -Foam::sampledPatchInternalField::sampleField +Foam::sampledPatchInternalField::sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const { + const auto& vField = sampler.psi(); + // One value per face - tmp> tvalues(new Field(patchFaceLabels().size())); - Field& values = tvalues.ref(); + auto tvalues = tmp>::New(patchFaceLabels().size()); + auto& values = tvalues.ref(); forAll(patchStart(), i) { @@ -66,7 +68,7 @@ Foam::sampledPatchInternalField::sampleField template Foam::tmp> -Foam::sampledPatchInternalField::interpolateField +Foam::sampledPatchInternalField::sampleOnPoints ( const interpolation& interpolator ) const @@ -118,9 +120,9 @@ Foam::sampledPatchInternalField::interpolateField labelList meshFaceLabels(allPatchVals.size()); sz = 0; - forAll(patchIDs(), i) + for (const label patchId : patchIDs()) { - const polyPatch& pp = mesh().boundaryMesh()[patchIDs()[i]]; + const polyPatch& pp = mesh().boundaryMesh()[patchId]; forAll(pp, i) { meshFaceLabels[sz++] = pp.start()+i; diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C index 32a1892fd3..1e7799d7a8 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.C +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -35,7 +35,13 @@ License namespace Foam { defineTypeNameAndDebug(sampledPlane, 0); - addNamedToRunTimeSelectionTable(sampledSurface, sampledPlane, word, plane); + addNamedToRunTimeSelectionTable + ( + sampledSurface, + sampledPlane, + word, + plane + ); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -170,6 +176,7 @@ bool Foam::sampledPlane::update() << nl << endl; } + labelList selectedCells(mesh().cellZones().findMatching(zoneKey_).toc()); bool fullMesh = returnReduce(selectedCells.empty(), andOp()); @@ -234,46 +241,46 @@ bool Foam::sampledPlane::update() Foam::tmp Foam::sampledPlane::sample ( - const volScalarField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPlane::sample ( - const volVectorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPlane::sample ( - const volSphericalTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPlane::sample ( - const volSymmTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } Foam::tmp Foam::sampledPlane::sample ( - const volTensorField& vField + const interpolation& sampler ) const { - return sampleField(vField); + return sampleOnFaces(sampler); } @@ -282,7 +289,7 @@ Foam::tmp Foam::sampledPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -291,7 +298,7 @@ Foam::tmp Foam::sampledPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } Foam::tmp Foam::sampledPlane::interpolate @@ -299,7 +306,7 @@ Foam::tmp Foam::sampledPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -308,7 +315,7 @@ Foam::tmp Foam::sampledPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } @@ -317,7 +324,7 @@ Foam::tmp Foam::sampledPlane::interpolate const interpolation& interpolator ) const { - return interpolateField(interpolator); + return sampleOnPoints(interpolator); } diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H index 8a64dfe896..731c46fbc5 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlane.H +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlane.H @@ -3,7 +3,7 @@ \\ / 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. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,8 +25,43 @@ Class Foam::sampledPlane Description - A sampledSurface defined by a plane which 'cuts' the mesh using the - cuttingPlane alorithm. The plane is triangulated by default. + A sampledSurface defined by a plane which \a cuts the mesh using the + cuttingPlane alorithm. The surface is triangulated by default. + + This is often embedded as part of a sampled surfaces function object. + +Usage + Example of function object partial specification: + \verbatim + surfaces + ( + surface1 + { + type plane; + planeType pointAndNormal; + pointAndNormalDict + { + ... + } + } + ); + \endverbatim + + Where the sub-entries comprise: + \table + Property | Description | Required | Default + type | plane | yes | + planeType | plane description (pointAndNormal etc) | yes | + triangulate | triangulate faces | no | true + bounds | limit with bounding box | no | + zone | limit to specified zone | no | + coordinateSystem | plane relative to given coordinate system | no | + \endtable + +SeeAlso + Foam::coordinateSystem + Foam::cuttingPlane + Foam::plane Note Does not actually cut until update() called. @@ -70,19 +105,22 @@ class sampledPlane //- Track if the surface needs an update mutable bool needsUpdate_; + // Private Member Functions - //- Sample field on faces + //- Sample volume field onto surface faces template - tmp> sampleField + tmp> sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const; - + //- Interpolate volume field onto surface points template - tmp> - interpolateField(const interpolation&) const; + tmp> sampleOnPoints + ( + const interpolation& interpolator + ) const; public: @@ -168,78 +206,80 @@ public: return cuttingPlane::Cf(); } + //- For each face, the original cell in mesh + using cuttingPlane::meshCells; - //- For every face original cell in mesh - const labelList& meshCells() const - { - return cuttingPlane::meshCells(); - } - //- Sample field on surface + // Sample + + //- Sample volume field onto surface faces virtual tmp sample ( - const volScalarField& + const interpolation& sampler ) const; - - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volVectorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSphericalTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSymmTensorField& + const interpolation& sampler ) const; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volTensorField& + const interpolation& sampler ) const; - //- Interpolate field on surface + // Interpolate + + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const; - //- Write - virtual void print(Ostream&) const; + + // Output + + //- Print information + virtual void print(Ostream& os) const; }; diff --git a/src/sampling/sampledSurface/sampledPlane/sampledPlaneTemplates.C b/src/sampling/sampledSurface/sampledPlane/sampledPlaneTemplates.C index 070408490e..cb9bc70c64 100644 --- a/src/sampling/sampledSurface/sampledPlane/sampledPlaneTemplates.C +++ b/src/sampling/sampledSurface/sampledPlane/sampledPlaneTemplates.C @@ -29,40 +29,50 @@ License template Foam::tmp> -Foam::sampledPlane::sampleField +Foam::sampledPlane::sampleOnFaces ( - const GeometricField& vField + const interpolation& sampler ) const { - return tmp>::New(vField, meshCells()); + return sampledSurface::sampleOnFaces + ( + sampler, + meshCells(), + faces(), + points() + ); } template Foam::tmp> -Foam::sampledPlane::interpolateField +Foam::sampledPlane::sampleOnPoints ( const interpolation& interpolator ) const { + // elements to sample + const labelList& elements = meshCells(); + // One value per point. // Initialize with Zero to handle missed/degenerate faces - tmp> tvalues(new Field(points().size(), Zero)); - Field& values = tvalues.ref(); + auto tvalues = tmp>::New(points().size(), Zero); + auto& values = tvalues.ref(); - boolList pointDone(points().size(), false); + bitSet pointDone(points().size()); - forAll(faces(), cutFacei) + const faceList& fcs = faces(); + + forAll(fcs, facei) { - const face& f = faces()[cutFacei]; - const label celli = meshCells()[cutFacei]; + const face& f = fcs[facei]; + const label celli = elements[facei]; for (const label pointi : f) { - if (!pointDone[pointi]) + if (pointDone.set(pointi)) { - pointDone[pointi] = true; values[pointi] = interpolator.interpolate ( points()[pointi], diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C index 9265cd389f..83ed4511d3 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C @@ -181,57 +181,6 @@ Foam::tmp Foam::sampledSurface::sample } -Foam::tmp> -Foam::sampledSurface::project(const Field& field) const -{ - tmp> tRes(new Field(faces().size())); - Field& res = tRes.ref(); - - forAll(faces(), facei) - { - res[facei] = field[facei]; - } - - return tRes; -} - - -Foam::tmp> -Foam::sampledSurface::project(const Field& field) const -{ - tmp> tRes(new Field(faces().size())); - project(tRes.ref(), field); - return tRes; -} - - -Foam::tmp> -Foam::sampledSurface::project(const Field& field) const -{ - tmp> tRes(new Field(faces().size())); - project(tRes.ref(), field); - return tRes; -} - - -Foam::tmp> -Foam::sampledSurface::project(const Field& field) const -{ - tmp> tRes(new Field(faces().size())); - project(tRes.ref(), field); - return tRes; -} - - -Foam::tmp> -Foam::sampledSurface::project(const Field& field) const -{ - tmp> tRes(new Field(faces().size())); - project(tRes.ref(), field); - return tRes; -} - - void Foam::sampledSurface::print(Ostream& os) const { os << type(); @@ -240,7 +189,7 @@ void Foam::sampledSurface::print(Ostream& os) const // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // -Foam::Ostream& Foam::operator<<(Ostream &os, const sampledSurface& s) +Foam::Ostream& Foam::operator<<(Ostream& os, const sampledSurface& s) { s.print(os); os.check(FUNCTION_NAME); diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index cdda4084ce..a82137a874 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -3,7 +3,7 @@ \\ / 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. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -70,11 +70,10 @@ SourceFiles namespace Foam { -// Forward declaration of friend functions and operators +// Forward declarations class sampledSurface; - -Ostream& operator<<(Ostream&, const sampledSurface&); +Ostream& operator<<(Ostream& os, const sampledSurface& s); /*---------------------------------------------------------------------------*\ @@ -103,36 +102,28 @@ class sampledSurface mutable scalar area_; - // Service methods - - //- Check field size matches surface size - template - bool checkFieldSize(const Field&) const; - - //- Project field onto surface - template - void project - ( - Field&, - const Field& - ) const; - - //- Project field onto surface - template - void project - ( - Field&, - const tmp>& - ) const; - - //- Project field onto surface - template - tmp> project(const tmp>&) const; - - protected: - // Protected Member functions + // Protected Member Functions + + //- General loop for sampling elements to faces + template + static tmp> sampleOnFaces + ( + const interpolation& sampler, + const labelUList& elements, + const faceList& fcs, + const pointField& pts + ); + + + //- Create cell values by averaging the point values + template + static tmp> pointAverage + ( + const GeometricField& pfld + ); + virtual void clearGeom() const; @@ -226,7 +217,7 @@ public: // Member Functions - // Access + // Access //- Access to the underlying mesh const polyMesh& mesh() const @@ -277,137 +268,100 @@ public: scalar area() const; - //- Integration of a field across the surface - template - Type integrate(const Field&) const; - - //- Integration of a field across the surface - template - Type integrate(const tmp>&) const; - - //- Area-averaged value of a field across the surface - template - Type average(const Field&) const; - - //- Area-averaged value of a field across the surface - template - Type average(const tmp>&) const; - - //- Project field onto surface - tmp> project(const Field&) const; - - //- Project field onto surface - tmp> project(const Field&) const; - - //- Project field onto surface - tmp> project(const Field&) const; - - //- Project field onto surface - tmp> project(const Field&) const; - - //- Project field onto surface - tmp> project(const Field&) const; - - //- Interpolate from points to cell centre - template - tmp> pointAverage - ( - const GeometricField& pfld - ) const; - - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volScalarField& + const interpolation& sampler ) const = 0; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volVectorField& + const interpolation& sampler ) const = 0; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSphericalTensorField& + const interpolation& sampler ) const = 0; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volSymmTensorField& + const interpolation& sampler ) const = 0; - //- Sample field on surface + //- Sample volume field onto surface faces virtual tmp sample ( - const volTensorField& + const interpolation& sampler ) const = 0; - //- Surface sample field on surface + + //- Sample surface field onto surface virtual tmp sample ( - const surfaceScalarField& + const surfaceScalarField& sField ) const; - //- Surface Sample field on surface + //- Sample surface field onto surface virtual tmp sample ( - const surfaceVectorField& + const surfaceVectorField& sField ) const; - //- Surface sample field on surface + //- Sample surface field onto surface virtual tmp sample ( - const surfaceSphericalTensorField& + const surfaceSphericalTensorField& sField ) const; - //- Surface sample field on surface + //- Sample surface field onto surface virtual tmp sample ( - const surfaceSymmTensorField& + const surfaceSymmTensorField& sField ) const; - //- Surface sample field on surface + //- Sample surface field onto surface virtual tmp sample ( - const surfaceTensorField& + const surfaceTensorField& sField ) const; - //- Interpolate field on surface + + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const = 0; - - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const = 0; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const = 0; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const = 0; - //- Interpolate field on surface + //- Interpolate volume field onto surface points virtual tmp interpolate ( - const interpolation& + const interpolation& interpolator ) const = 0; - // Edit + // Edit //- Rename virtual void rename(const word& newName) @@ -416,13 +370,13 @@ public: } - // Write + // Write - //- Write - virtual void print(Ostream&) const; + //- Print information + virtual void print(Ostream& os) const; //- Ostream operator - friend Ostream& operator<<(Ostream&, const sampledSurface&); + friend Ostream& operator<<(Ostream& os, const sampledSurface& s); }; diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C index 7fa7405009..fc739d3214 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -25,129 +25,41 @@ License #include "sampledSurface.H" -template -bool Foam::sampledSurface::checkFieldSize(const Field& field) const -{ - if (faces().empty() || field.empty()) - { - return false; - } +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - if (field.size() != faces().size()) +template +Foam::tmp> +Foam::sampledSurface::sampleOnFaces +( + const interpolation& sampler, + const labelUList& elements, + const faceList& fcs, + const pointField& pts +) +{ + const label len = elements.size(); + + if (len != fcs.size()) { FatalErrorInFunction << "size mismatch: " - << "field (" << field.size() - << ") != surface (" << faces().size() << ")" + << "sampled elements (" << len + << ") != faces (" << fcs.size() << ')' << exit(FatalError); } - return true; -} + auto tvalues = tmp>::New(len); + auto& values = tvalues.ref(); - -template -Type Foam::sampledSurface::integrate(const Field& field) const -{ - Type value = Zero; - - if (checkFieldSize(field)) + for (label i=0; i < len; ++i) { - value = sum(field*magSf()); + const label celli = elements[i]; + const point pt = fcs[i].centre(pts); + + values[i] = sampler.interpolate(pt, celli); } - reduce(value, sumOp()); - return value; -} - - -template -Type Foam::sampledSurface::integrate(const tmp>& field) const -{ - Type value = integrate(field()); - field.clear(); - return value; -} - - -template -Type Foam::sampledSurface::average(const Field& field) const -{ - Type value = Zero; - - if (checkFieldSize(field)) - { - value = sum(field*magSf()); - } - - reduce(value, sumOp()); - - // avoid divide-by-zero - if (area()) - { - return value/area(); - } - else - { - return Zero; - } -} - - -template -Type Foam::sampledSurface::average(const tmp>& field) const -{ - Type value = average(field()); - field.clear(); - return value; -} - - -template -void Foam::sampledSurface::project -( - Field& res, - const Field& field -) const -{ - if (checkFieldSize(field)) - { - const vectorField& norm = Sf(); - - forAll(norm, facei) - { - res[facei] = field[facei] & (norm[facei]/mag(norm[facei])); - } - } - else - { - res.clear(); - } -} - - -template -void Foam::sampledSurface::project -( - Field& res, - const tmp>& field -) const -{ - project(res, field()); - field.clear(); -} - - -template -Foam::tmp> -Foam::sampledSurface::project -( - const tmp>& field -) const -{ - tmp> tRes(new Field(faces().size())); - project(tRes(), field); - return tRes; + return tvalues; } @@ -156,48 +68,45 @@ Foam::tmp> Foam::sampledSurface::pointAverage ( const GeometricField& pfld -) const +) { const fvMesh& mesh = dynamic_cast(pfld.mesh()()); - tmp> tcellAvg + auto tcellAvg = tmp>::New ( - new GeometricField + IOobject ( - IOobject - ( - "cellAvg", - mesh.time().timeName(), - pfld.db(), - IOobject::NO_READ, - IOobject::NO_WRITE, - false - ), - mesh, - dimensioned(dimless, Zero) - ) + "cellAvg", + mesh.time().timeName(), + pfld.db(), + IOobject::NO_READ, + IOobject::NO_WRITE, + false + ), + mesh, + dimensioned(dimless, Zero) ); - GeometricField& cellAvg = tcellAvg.ref(); + auto& cellAvg = tcellAvg.ref(); - labelField nPointCells(mesh.nCells(), 0); + labelField nPointCells(mesh.nCells(), Zero); + + for (label pointi = 0; pointi < mesh.nPoints(); ++pointi) { - for (label pointi = 0; pointi < mesh.nPoints(); pointi++) + const Type& val = pfld[pointi]; + const labelList& pCells = mesh.pointCells(pointi); + + for (const label celli : pCells) { - const labelList& pCells = mesh.pointCells(pointi); - - forAll(pCells, i) - { - label celli = pCells[i]; - - cellAvg[celli] += pfld[pointi]; - nPointCells[celli]++; - } + cellAvg[celli] += val; + ++nPointCells[celli]; } } + forAll(cellAvg, celli) { cellAvg[celli] /= nPointCells[celli]; } + // Give value to calculatedFvPatchFields cellAvg.correctBoundaryConditions(); diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 1f881bd321..c1fcbe4adf 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,7 @@ License #include "dictionary.H" #include "Time.H" #include "IOmanip.H" +#include "interpolationCell.H" #include "volPointInterpolation.H" #include "PatchTools.H" #include "mapPolyMesh.H" @@ -61,19 +62,19 @@ void Foam::sampledSurfaces::writeGeometry() const const fileName outputDir = outputPath_/time_.timeName(); - forAll(*this, surfI) + forAll(*this, surfi) { - const sampledSurface& s = operator[](surfI); + const sampledSurface& s = operator[](surfi); if (Pstream::parRun()) { - if (Pstream::master() && mergedList_[surfI].size()) + if (Pstream::master() && mergedList_[surfi].size()) { formatter_->write ( outputDir, s.name(), - mergedList_[surfI] + mergedList_[surfi] ); } } @@ -90,9 +91,9 @@ void Foam::sampledSurfaces::writeOriginalIds() const word fieldName = "Ids"; const fileName outputDir = outputPath_/time_.timeName(); - forAll(*this, surfI) + forAll(*this, surfi) { - const sampledSurface& s = operator[](surfI); + const sampledSurface& s = operator[](surfi); if (isA(s)) { @@ -109,7 +110,7 @@ void Foam::sampledSurfaces::writeOriginalIds() ids[i] = idLst[i]; } - writeSurface(ids, surfI, fieldName, outputDir); + writeSurface(ids, surfi, fieldName, outputDir); } } } @@ -131,7 +132,8 @@ Foam::sampledSurfaces::sampledSurfaces loadFromFiles_(false), outputPath_(fileName::null), fieldSelection_(), - interpolationScheme_(word::null), + sampleFaceScheme_(word::null), + sampleNodeScheme_(word::null), mergedList_(), formatter_(nullptr) { @@ -143,8 +145,7 @@ Foam::sampledSurfaces::sampledSurfaces { outputPath_ = mesh_.time().path()/"postProcessing"/name; } - // Remove ".." - outputPath_.clean(); + outputPath_.clean(); // Remove unneeded ".." read(dict); } @@ -164,7 +165,8 @@ Foam::sampledSurfaces::sampledSurfaces loadFromFiles_(loadFromFiles), outputPath_(fileName::null), fieldSelection_(), - interpolationScheme_(word::null), + sampleFaceScheme_(word::null), + sampleNodeScheme_(word::null), mergedList_(), formatter_(nullptr) { @@ -178,8 +180,7 @@ Foam::sampledSurfaces::sampledSurfaces { outputPath_ = time_.path()/"postProcessing"/name; } - // Remove ".." - outputPath_.clean(); + outputPath_.clean(); // Remove unneeded ".." read(dict); } @@ -207,35 +208,38 @@ bool Foam::sampledSurfaces::execute() bool Foam::sampledSurfaces::write() { - if (size()) + if (empty()) { - // Finalize surfaces, merge points etc. - update(); - - const label nFields = classifyFields(); - - // write geometry first if required, - // or when no fields would otherwise be written - if (nFields == 0 || formatter_->separateGeometry()) - { - writeGeometry(); - } - - const IOobjectList objects(obr_, obr_.time().timeName()); - - sampleAndWrite(objects); - sampleAndWrite(objects); - sampleAndWrite(objects); - sampleAndWrite(objects); - sampleAndWrite(objects); - - sampleAndWrite(objects); - sampleAndWrite(objects); - sampleAndWrite(objects); - sampleAndWrite(objects); - sampleAndWrite(objects); + return true; } + + // Finalize surfaces, merge points etc. + update(); + + const label nFields = classifyFields(); + + // write geometry first if required, + // or when no fields would otherwise be written + if (nFields == 0 || formatter_->separateGeometry()) + { + writeGeometry(); + } + + const IOobjectList objects(obr_, obr_.time().timeName()); + + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + sampleAndWrite(objects); + return true; } @@ -246,9 +250,12 @@ bool Foam::sampledSurfaces::read(const dictionary& dict) if (surfacesFound) { + sampleFaceScheme_ = dict.lookupOrDefault("sampleScheme", "cell"); + + dict.lookup("interpolationScheme") >> sampleNodeScheme_; + dict.lookup("fields") >> fieldSelection_; - dict.lookup("interpolationScheme") >> interpolationScheme_; const word writeType(dict.lookup("surfaceFormat")); // Define the surface formatter @@ -277,9 +284,9 @@ bool Foam::sampledSurfaces::read(const dictionary& dict) if (this->size()) { Info<< "Reading surface description:" << nl; - forAll(*this, surfI) + forAll(*this, surfi) { - Info<< " " << operator[](surfI).name() << nl; + Info<< " " << operator[](surfi).name() << nl; } Info<< endl; } @@ -290,9 +297,9 @@ bool Foam::sampledSurfaces::read(const dictionary& dict) Pout<< "sample fields:" << fieldSelection_ << nl << "sample surfaces:" << nl << "(" << nl; - forAll(*this, surfI) + forAll(*this, surfi) { - Pout<< " " << operator[](surfI) << endl; + Pout<< " " << operator[](surfi) << nl; } Pout<< ")" << endl; } @@ -332,9 +339,9 @@ void Foam::sampledSurfaces::readUpdate(const polyMesh::readUpdateState state) bool Foam::sampledSurfaces::needsUpdate() const { - forAll(*this, surfI) + forAll(*this, surfi) { - if (operator[](surfI).needsUpdate()) + if (operator[](surfi).needsUpdate()) { return true; } @@ -348,9 +355,9 @@ bool Foam::sampledSurfaces::expire() { bool justExpired = false; - forAll(*this, surfI) + forAll(*this, surfi) { - if (operator[](surfI).expire()) + if (operator[](surfi).expire()) { justExpired = true; } @@ -358,7 +365,7 @@ bool Foam::sampledSurfaces::expire() // Clear merge information if (Pstream::parRun()) { - mergedList_[surfI].clear(); + mergedList_[surfi].clear(); } } @@ -379,9 +386,9 @@ bool Foam::sampledSurfaces::update() // Serial: quick and easy, no merging required if (!Pstream::parRun()) { - forAll(*this, surfI) + forAll(*this, surfi) { - if (operator[](surfI).update()) + if (operator[](surfi).update()) { updated = true; } @@ -390,8 +397,9 @@ bool Foam::sampledSurfaces::update() return updated; } + // Dimension as fraction of mesh bounding box - scalar mergeDim = mergeTol_*mesh_.bounds().mag(); + const scalar mergeDim = mergeTol_*mesh_.bounds().mag(); if (Pstream::master() && debug) { @@ -399,14 +407,14 @@ bool Foam::sampledSurfaces::update() << mergeDim << " metre" << endl; } - forAll(*this, surfI) + forAll(*this, surfi) { - sampledSurface& s = operator[](surfI); + sampledSurface& s = operator[](surfi); if (s.update()) { updated = true; - mergedList_[surfI].merge(s, mergeDim); + mergedList_[surfi].merge(s, mergeDim); } } @@ -422,9 +430,9 @@ Foam::scalar Foam::sampledSurfaces::mergeTol() Foam::scalar Foam::sampledSurfaces::mergeTol(const scalar tol) { - scalar oldTol = mergeTol_; + const scalar prev(mergeTol_); mergeTol_ = tol; - return oldTol; + return prev; } diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index db220ca7af..590da3ed4b 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -44,13 +44,17 @@ Description // Fields to be sampled fields (p U); - // Interpolation scheme to use (only used if interpolate=true for - // the surfaces below) + // Scheme to obtain face centre value + sampleScheme cell; + + // Scheme to obtain node values + // (only used if interpolate=true for the surfaces below) + interpolationScheme cell; // Output surface format surfaceFormat vtk; - formatOptions { } + formatOptions { } surfaces ( @@ -95,7 +99,7 @@ SourceFiles namespace Foam { -// Forward declaration of classes +// Forward declarations class Time; class fvMesh; class dictionary; @@ -130,25 +134,28 @@ class sampledSurfaces fileName outputPath_; - // Read from dictonary + // Read from dictonary - //- Names of fields to sample - wordRes fieldSelection_; + //- Names of fields to sample + wordRes fieldSelection_; - //- Interpolation scheme to use - word interpolationScheme_; + //- Interpolation/sample scheme to obtain face values + word sampleFaceScheme_; + + //- Interpolation/sample scheme to obtain node values + word sampleNodeScheme_; - // surfaces + // Surfaces - //- Merged meshed surfaces (parallel only) - List mergedList_; + //- Merged meshed surfaces (parallel only) + List mergedList_; - // Calculated + // Calculated - //- Surface formatter - autoPtr formatter_; + //- Surface formatter + autoPtr formatter_; // Private Member Functions @@ -168,7 +175,7 @@ class sampledSurfaces void writeSurface ( const Field& values, - const label surfI, + const label surfi, const word& fieldName, const fileName& outputDir ); @@ -177,22 +184,25 @@ class sampledSurfaces template void sampleAndWrite ( - const GeometricField& + const GeometricField& vField ); //- Sample and write a particular surface field template void sampleAndWrite ( - const GeometricField& + const GeometricField& sField ); //- Sample and write all sampled fields template void sampleAndWrite(const IOobjectList& objects); - //- Disallow default bitwise copy construct and assignment - sampledSurfaces(const sampledSurfaces&); - void operator=(const sampledSurfaces&); + + //- No copy construct + sampledSurfaces(const sampledSurfaces&) = delete; + + //- No copy assignment + void operator=(const sampledSurfaces&) = delete; public: @@ -207,7 +217,7 @@ public: sampledSurfaces ( const word& name, - const Time& time, + const Time& runTime, const dictionary& dict ); @@ -216,8 +226,8 @@ public: sampledSurfaces ( const word& name, - const objectRegistry&, - const dictionary&, + const objectRegistry& obr, + const dictionary& dict, const bool loadFromFiles = false ); @@ -265,7 +275,7 @@ public: static scalar mergeTol(); //- Set tolerance (and return old tolerance) - static scalar mergeTol(const scalar); + static scalar mergeTol(const scalar tol); }; diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index 0dd8c248ef..f314d93818 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -35,12 +35,12 @@ template void Foam::sampledSurfaces::writeSurface ( const Field& values, - const label surfI, + const label surfi, const word& fieldName, const fileName& outputDir ) { - const sampledSurface& s = operator[](surfI); + const sampledSurface& s = operator[](surfi); if (Pstream::parRun()) { @@ -63,21 +63,21 @@ void Foam::sampledSurfaces::writeSurface ); // Renumber (point data) to correspond to merged points - if (mergedList_[surfI].pointsMap().size() == allValues.size()) + if (mergedList_[surfi].pointsMap().size() == allValues.size()) { - inplaceReorder(mergedList_[surfI].pointsMap(), allValues); - allValues.setSize(mergedList_[surfI].points().size()); + inplaceReorder(mergedList_[surfi].pointsMap(), allValues); + allValues.setSize(mergedList_[surfi].points().size()); } // Write to time directory under outputPath_ // skip surface without faces (eg, a failed cut-plane) - if (mergedList_[surfI].size()) + if (mergedList_[surfi].size()) { sampleFile = formatter_->write ( outputDir, s.name(), - mergedList_[surfI], + mergedList_[surfi], fieldName, allValues, s.interpolate() @@ -123,37 +123,46 @@ void Foam::sampledSurfaces::sampleAndWrite const GeometricField& vField ) { - // interpolator for this field - autoPtr> interpolatorPtr; + // sampler/interpolator for this field + autoPtr> interpPtr; const word& fieldName = vField.name(); const fileName outputDir = outputPath_/vField.time().timeName(); - forAll(*this, surfI) + forAll(*this, surfi) { - const sampledSurface& s = operator[](surfI); + const sampledSurface& s = operator[](surfi); Field values; if (s.interpolate()) { - if (interpolatorPtr.empty()) + if (interpPtr.empty()) { - interpolatorPtr = interpolation::New + interpPtr = interpolation::New ( - interpolationScheme_, + sampleNodeScheme_, vField ); } - values = s.interpolate(interpolatorPtr()); + values = s.interpolate(*interpPtr); } else { - values = s.sample(vField); + if (interpPtr.empty()) + { + interpPtr = interpolation::New + ( + sampleFaceScheme_, + vField + ); + } + + values = s.sample(*interpPtr); } - writeSurface(values, surfI, fieldName, outputDir); + writeSurface(values, surfi, fieldName, outputDir); } } @@ -167,11 +176,11 @@ void Foam::sampledSurfaces::sampleAndWrite const word& fieldName = sField.name(); const fileName outputDir = outputPath_/sField.time().timeName(); - forAll(*this, surfI) + forAll(*this, surfi) { - const sampledSurface& s = operator[](surfI); + const sampledSurface& s = operator[](surfi); Field values(s.sample(sField)); - writeSurface(values, surfI, fieldName, outputDir); + writeSurface(values, surfi, fieldName, outputDir); } } @@ -191,13 +200,11 @@ void Foam::sampledSurfaces::sampleAndWrite(const IOobjectList& objects) writeOriginalIds(); } - forAll(fieldNames, fieldi) + for (const word& fieldName : fieldNames) { - const word& fieldName = fieldNames[fieldi]; - - if ((Pstream::master()) && verbose_) + if (verbose_) { - Pout<< "sampleAndWrite: " << fieldName << endl; + Info<< "sampleAndWrite: " << fieldName << endl; } if (loadFromFiles_) diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C index 08e9700e4a..93a5eb7103 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C @@ -87,9 +87,8 @@ void Foam::sampledTriSurfaceMesh::setZoneMap ) { label sz = 0; - forAll(zoneLst, zonei) + for (const surfZone& zn : zoneLst) { - const surfZone& zn = zoneLst[zonei]; sz += zn.size(); } @@ -119,9 +118,8 @@ Foam::sampledTriSurfaceMesh::nonCoupledboundaryTree() const labelList bndFaces(mesh().nFaces()-mesh().nInternalFaces()); label bndI = 0; - forAll(patches, patchi) + for (const polyPatch& pp : patches) { - const polyPatch& pp = patches[patchi]; if (!pp.coupled()) { forAll(pp, i) @@ -174,10 +172,10 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) // elements globalIndex globalCells(onBoundary() ? mesh().nFaces() : mesh().nCells()); - forAll(nearest, i) + for (nearInfo& near : nearest) { - nearest[i].first() = GREAT; - nearest[i].second() = labelMax; + near.first() = GREAT; + near.second() = labelMax; } if (sampleSource_ == cells) @@ -333,20 +331,16 @@ bool Foam::sampledTriSurfaceMesh::update(const meshSearch& meshSearcher) const triSurface::FaceType& f = s[facei]; const label regionid = f.region(); - Map