diff --git a/src/sampling/Make/files b/src/sampling/Make/files index c6191009cb..3e42081cc0 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -38,6 +38,7 @@ surfMeshSample/distanceSurface/surfMeshSampleDistanceSurface.C surfMeshSample/plane/surfMeshSamplePlane.C surfMeshSample/triSurfaceMesh/surfMeshSampleDiscrete.C +sampledSurface/sampledNone/sampledNone.C sampledSurface/sampledPatch/sampledPatch.C sampledSurface/sampledPatchInternalField/sampledPatchInternalField.C sampledSurface/sampledPlane/sampledPlane.C diff --git a/src/sampling/sampledSurface/sampledNone/sampledNone.C b/src/sampling/sampledSurface/sampledNone/sampledNone.C new file mode 100644 index 0000000000..c9de902b87 --- /dev/null +++ b/src/sampling/sampledSurface/sampledNone/sampledNone.C @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 "sampledNone.H" +#include "dictionary.H" +#include "polyMesh.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(sampledNone, 0); + addNamedToRunTimeSelectionTable(sampledSurface, sampledNone, word, none); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::sampledNone::sampledNone() +: + sampledSurface(word::null, nullptr) +{} + + +Foam::sampledNone::sampledNone(const word& name) +: + sampledSurface(name, nullptr) +{} + + +Foam::sampledNone::sampledNone +( + const word& name, + const polyMesh& mesh, + const dictionary& dict +) +: + sampledSurface(name, nullptr) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::sampledNone::needsUpdate() const +{ + return false; +} + + +bool Foam::sampledNone::expire() +{ + return false; +} + + +bool Foam::sampledNone::update() +{ + return false; +} + + +#undef makeDummy +#define makeDummy(Func,Type) \ + Foam::tmp> \ + Foam::sampledNone::Func(const interpolation&) const \ + { \ + return tmp>::New(); \ + } + +makeDummy(sample, scalar); +makeDummy(sample, vector); +makeDummy(sample, sphericalTensor); +makeDummy(sample, symmTensor); +makeDummy(sample, tensor); + +makeDummy(interpolate, scalar); +makeDummy(interpolate, vector); +makeDummy(interpolate, sphericalTensor); +makeDummy(interpolate, symmTensor); +makeDummy(interpolate, tensor); + +#undef makeDummy + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledNone/sampledNone.H b/src/sampling/sampledSurface/sampledNone/sampledNone.H new file mode 100644 index 0000000000..0743927c16 --- /dev/null +++ b/src/sampling/sampledSurface/sampledNone/sampledNone.H @@ -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 . + +Class + Foam::sampledNone + +Description + A no operation sampledSurface that can be used when a sampler + is expected but is not desired. For example, to temporarily disable + a sampling definition, or to provide a boilerplate definition that + is overwritten at a later stage in a dictionary. + +Usage + \table + Property | Description | Required | Default + type | 'none' | yes | + \endtable + +SourceFiles + sampledNone.C + +\*---------------------------------------------------------------------------*/ + +#ifndef sampledNone_H +#define sampledNone_H + +#include "sampledSurface.H" +#include "MeshedSurfaces.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class sampledNone Declaration +\*---------------------------------------------------------------------------*/ + +class sampledNone +: + public meshedSurface, + public sampledSurface +{ + typedef meshedSurface Mesh; + +public: + + //- Runtime type information + TypeName("sampledNone"); + + + // Constructors + + //- Construct null + explicit sampledNone(); + + //- Construct null, with specified name + explicit sampledNone(const word& name); + + //- Construct null, with dictionary + sampledNone(const word& name, const polyMesh&, const dictionary&); + + + //- Destructor + virtual ~sampledNone() = default; + + + // Member Functions + + //- Does the surface need an update? + virtual bool needsUpdate() const; + + //- Mark the surface as needing an update. + virtual bool expire(); + + //- Update the surface as required. + virtual bool update(); + + //- Points of surface + virtual const pointField& points() const + { + return Mesh::points(); + } + + //- Faces of surface + virtual const faceList& faces() const + { + return Mesh::surfFaces(); + } + + //- Const access to per-face zone/region information + virtual const labelList& zoneIds() const + { + return Foam::emptyLabelList; + } + + //- Face area magnitudes + virtual const vectorField& Sf() const + { + return Mesh::Sf(); + } + + //- Face area magnitudes + virtual const scalarField& magSf() const + { + return Mesh::magSf(); + } + + //- Face centres + virtual const vectorField& Cf() const + { + return Mesh::Cf(); + } + + + // Sample + + //- Sample volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; + + //- Sample volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; + + //- Sample volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; + + //- Sample volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; + + //- Sample volume field onto surface faces + virtual tmp sample + ( + const interpolation& sampler + ) const; + + + // Interpolate + + //- Interpolate volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; + + //- Interpolate volume field onto surface points + virtual tmp interpolate + ( + const interpolation& interpolator + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C index 69184fa467..e5eafd25ae 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.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. @@ -27,7 +27,6 @@ License #include "polyMesh.H" #include "demandDrivenData.H" - // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam @@ -37,7 +36,7 @@ namespace Foam } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::sampledSurface::clearGeom() const { @@ -79,6 +78,15 @@ Foam::autoPtr Foam::sampledSurface::New // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +Foam::sampledSurface::sampledSurface(const word& name, std::nullptr_t) +: + name_(name), + mesh_(NullObjectRef()), + interpolate_(false), + area_(-1) +{} + + Foam::sampledSurface::sampledSurface ( const word& name, @@ -123,8 +131,7 @@ Foam::scalar Foam::sampledSurface::area() const { if (area_ < 0) { - area_ = sum(magSf()); - reduce(area_, sumOp()); + area_ = gSum(magSf()); } return area_; @@ -187,7 +194,7 @@ void Foam::sampledSurface::print(Ostream& os) const } -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // Foam::Ostream& Foam::operator<<(Ostream& os, const sampledSurface& s) { diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index a82137a874..7bd8b6f9da 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -70,12 +70,6 @@ SourceFiles namespace Foam { -// Forward declarations - -class sampledSurface; -Ostream& operator<<(Ostream& os, const sampledSurface& s); - - /*---------------------------------------------------------------------------*\ Class sampledSurface Declaration \*---------------------------------------------------------------------------*/ @@ -84,6 +78,8 @@ class sampledSurface : public meshedSurf { +private: + // Private data //- Name of sample surface @@ -127,6 +123,8 @@ protected: virtual void clearGeom() const; + //- Construct null + explicit sampledSurface(const word& name, std::nullptr_t); public: @@ -180,7 +178,7 @@ public: sampledSurface ( const word& name, - const polyMesh&, + const polyMesh& mesh, const bool interpolate = false ); @@ -188,8 +186,8 @@ public: sampledSurface ( const word& name, - const polyMesh&, - const dictionary& + const polyMesh& mesh, + const dictionary& dict ); //- Clone @@ -206,8 +204,8 @@ public: static autoPtr New ( const word& name, - const polyMesh&, - const dictionary& + const polyMesh& mesh, + const dictionary& dict ); @@ -267,6 +265,21 @@ public: //- The total surface area scalar area() const; + //- If element ids/order of the original surface are available + virtual bool hasFaceIds() const + { + return false; + } + + //- List of element ids/order of the original surface, + //- when hasFaceIds is true. + const labelList& originalIds() const + { + return Foam::emptyLabelList; + } + + + // Sample (faces) //- Sample volume field onto surface faces virtual tmp sample @@ -330,6 +343,8 @@ public: ) const; + // Interpolate (points) + //- Interpolate volume field onto surface points virtual tmp interpolate ( @@ -374,12 +389,14 @@ public: //- Print information virtual void print(Ostream& os) const; - - //- Ostream operator - friend Ostream& operator<<(Ostream& os, const sampledSurface& s); }; +// Global Operators + +//- Ostream operator +Ostream& operator<<(Ostream& os, const sampledSurface& s); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 15273813fe..12dc6058d8 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -58,7 +58,7 @@ Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10; void Foam::sampledSurfaces::writeGeometry() const { // Write to time directory under outputPath_ - // Skip surface without faces (eg, a failed cut-plane) + // Skip surfaces without faces (eg, a failed cut-plane) const fileName outputDir = outputPath_/time_.timeName(); @@ -95,23 +95,18 @@ void Foam::sampledSurfaces::writeOriginalIds() { const sampledSurface& s = operator[](surfi); - if (isA(s)) + if (s.hasFaceIds()) { - const sampledTriSurfaceMesh& surf = - dynamicCast(s); + const labelList& idLst = s.originalIds(); - if (surf.keepIds()) + // Transcribe from label to scalar + Field ids(idLst.size()); + forAll(idLst, i) { - const labelList& idLst = surf.originalIds(); - - Field ids(idLst.size()); - forAll(idLst, i) - { - ids[i] = idLst[i]; - } - - writeSurface(ids, surfi, fieldName, outputDir); + ids[i] = idLst[i]; } + + writeSurface(ids, surfi, fieldName, outputDir); } } } @@ -130,25 +125,17 @@ Foam::sampledSurfaces::sampledSurfaces PtrList(), mesh_(refCast(obr_)), loadFromFiles_(false), - outputPath_(fileName::null), + outputPath_ + ( + time_.globalPath()/functionObject::outputPrefix/name + ), fieldSelection_(), - sampleFaceScheme_(word::null), - sampleNodeScheme_(word::null), + sampleFaceScheme_(), + sampleNodeScheme_(), mergedList_(), changedGeom_(), formatter_(nullptr) { - const fileName relPath(functionObject::outputPrefix/name); - - if (Pstream::parRun()) - { - outputPath_ = mesh_.time().path()/".."/relPath; - } - else - { - outputPath_ = mesh_.time().path()/relPath; - } - outputPath_.clean(); // Remove unneeded ".." read(dict); @@ -167,39 +154,23 @@ Foam::sampledSurfaces::sampledSurfaces PtrList(), mesh_(refCast(obr)), loadFromFiles_(loadFromFiles), - outputPath_(fileName::null), + outputPath_ + ( + time_.globalPath()/functionObject::outputPrefix/name + ), fieldSelection_(), - sampleFaceScheme_(word::null), - sampleNodeScheme_(word::null), + sampleFaceScheme_(), + sampleNodeScheme_(), mergedList_(), changedGeom_(), formatter_(nullptr) { - read(dict); - - const fileName relPath(functionObject::outputPrefix/name); - - if (Pstream::parRun()) - { - outputPath_ = time_.path()/".."/relPath; - } - else - { - outputPath_ = time_.path()/relPath; - } - outputPath_.clean(); // Remove unneeded ".." read(dict); } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::sampledSurfaces::~sampledSurfaces() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::sampledSurfaces::verbose(const bool verbosity) @@ -388,13 +359,13 @@ bool Foam::sampledSurfaces::expire() bool Foam::sampledSurfaces::update() { - bool updated = false; - if (!needsUpdate()) { - return updated; + return false; } + bool updated = false; + // Serial: quick and easy, no merging required if (!Pstream::parRun()) { diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index 9493bf39cf..9d4c04b407 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -178,6 +178,17 @@ class sampledSurfaces // Private Member Functions + //- Return the surfaces + const PtrList& surfaces() const + { + return *this; + } + + //- Return the surfaces + PtrList& surfaces() + { + return *this; + } //- Return number of fields label classifyFields(); @@ -251,7 +262,7 @@ public: //- Destructor - virtual ~sampledSurfaces(); + virtual ~sampledSurfaces() = default; // Member Functions diff --git a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H index d81c2f0f17..b8f5386cf3 100644 --- a/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H +++ b/src/sampling/sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.H @@ -288,14 +288,14 @@ public: } //- If element ids/order of the original surface are kept - bool keepIds() const + virtual bool hasFaceIds() const { return keepIds_; } //- List of element ids/order of the original surface, // when keepIds is active. - const labelList& originalIds() const + virtual const labelList& originalIds() const { return originalIds_; } diff --git a/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H index 57c1667b10..a1f74e6bfb 100644 --- a/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H +++ b/src/sampling/sampledSurface/triSurfaceMesh/sampledDiscreteSurface.H @@ -180,14 +180,14 @@ public: } //- If element ids/order of the original surface are kept - bool keepIds() const + virtual bool hasFaceIds() const { - return MeshStorage::keepIds(); + return MeshStorage::hasFaceIds(); } //- List of element ids/order of the original surface, // when keepIds is active. - const labelList& originalIds() const + virtual const labelList& originalIds() const { return MeshStorage::originalIds(); } diff --git a/src/sampling/surface/triSurfaceMesh/discreteSurface.C b/src/sampling/surface/triSurfaceMesh/discreteSurface.C index 1e0dccc66f..df4952394f 100644 --- a/src/sampling/surface/triSurfaceMesh/discreteSurface.C +++ b/src/sampling/surface/triSurfaceMesh/discreteSurface.C @@ -651,8 +651,8 @@ Foam::discreteSurface::discreteSurface keepIds_(false), originalIds_(), zoneIds_(), - sampleElements_(0), - samplePoints_(0) + sampleElements_(), + samplePoints_() {} @@ -689,8 +689,8 @@ Foam::discreteSurface::discreteSurface keepIds_(dict.lookupOrDefault("keepIds", false)), originalIds_(), zoneIds_(), - sampleElements_(0), - samplePoints_(0) + sampleElements_(), + samplePoints_() {} @@ -726,8 +726,8 @@ Foam::discreteSurface::discreteSurface keepIds_(false), originalIds_(), zoneIds_(), - sampleElements_(0), - samplePoints_(0) + sampleElements_(), + samplePoints_() {} diff --git a/src/sampling/surface/triSurfaceMesh/discreteSurface.H b/src/sampling/surface/triSurfaceMesh/discreteSurface.H index 1bc7c0df9d..7752ba527d 100644 --- a/src/sampling/surface/triSurfaceMesh/discreteSurface.H +++ b/src/sampling/surface/triSurfaceMesh/discreteSurface.H @@ -275,26 +275,24 @@ public: } //- If element ids/order of the original surface are kept - bool keepIds() const + virtual bool hasFaceIds() const { return keepIds_; } //- List of element ids/order of the original surface, // when keepIds is active. - const labelList& originalIds() const + virtual const labelList& originalIds() const { return originalIds_; } - //- Sampling boundary values instead of cell values bool onBoundary() const { return sampleSource_ == boundaryFaces; } - //- From local surface face to mesh cell/face. const labelList& sampleElements() const {