diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 438f67c235bee0371777c382e273f44620027361..a97d335f176f2de67c575f0575b7be70f0ab78d1 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -6,6 +6,7 @@ sampledSet/circle/circleSet.C sampledSet/cloud/cloudSet.C sampledSet/patchCloud/patchCloudSet.C sampledSet/polyLine/polyLineSet.C +sampledSet/cellCentre/cellCentreSet.C sampledSet/face/faceOnlySet.C sampledSet/midPoint/midPointSet.C sampledSet/midPointAndFace/midPointAndFaceSet.C diff --git a/src/sampling/sampledSet/cellCentre/cellCentreSet.C b/src/sampling/sampledSet/cellCentre/cellCentreSet.C new file mode 100644 index 0000000000000000000000000000000000000000..2631595ff1fe3e506420e5a9790c71fa0885fdfa --- /dev/null +++ b/src/sampling/sampledSet/cellCentre/cellCentreSet.C @@ -0,0 +1,132 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "cellCentreSet.H" +#include "meshSearch.H" +#include "polyMesh.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(cellCentreSet, 0); + addToRunTimeSelectionTable(sampledSet, cellCentreSet, word); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::cellCentreSet::genSamples() +{ + const label len = mesh().nCells(); + + const auto& cellCentres = + refCast<const fvMesh>(mesh()).C().primitiveField(); + + labelList selectedCells = identity(len); + List<point> selectedPoints; + + if (bounds_.empty()) + { + selectedPoints = cellCentres; + } + else + { + label count = 0; + for (label celli=0; celli < len; ++celli) + { + if (bounds_.contains(cellCentres[celli])) + { + selectedCells[count++] = celli; + } + } + + selectedCells.resize(count); + selectedPoints = UIndirectList<point>(cellCentres, selectedCells); + } + + labelList samplingFaces(selectedCells.size(), -1); + labelList samplingSegments(selectedCells.size(), -1); + scalarList samplingCurveDist(selectedCells.size(), 0.0); + + // Move into *this + setSamples + ( + std::move(selectedPoints), + std::move(selectedCells), + std::move(samplingFaces), + std::move(samplingSegments), + std::move(samplingCurveDist) + ); + + if (debug) + { + write(Info); + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::cellCentreSet::cellCentreSet +( + const word& name, + const polyMesh& mesh, + const meshSearch& searchEngine, + const word& axis, + const boundBox& bbox +) +: + sampledSet(name, mesh, searchEngine, axis), + bounds_(bbox) +{ + genSamples(); +} + + +Foam::cellCentreSet::cellCentreSet +( + const word& name, + const polyMesh& mesh, + const meshSearch& searchEngine, + const dictionary& dict +) +: + sampledSet + ( + name, + mesh, + searchEngine, + dict.lookupOrDefault<word>("axis", "xyz") + ), + bounds_(dict.lookupOrDefault("bounds", boundBox::invertedBox)) +{ + genSamples(); +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/cellCentre/cellCentreSet.H b/src/sampling/sampledSet/cellCentre/cellCentreSet.H new file mode 100644 index 0000000000000000000000000000000000000000..508e82ee51e875d2d4d0c1e04f2818ed4ed0b51a --- /dev/null +++ b/src/sampling/sampledSet/cellCentre/cellCentreSet.H @@ -0,0 +1,115 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 <http://www.gnu.org/licenses/>. + +Class + Foam::cellCentreSet + +Description + A sampleSet based on cell centres + + For a dictionary specification: + \table + Property | Description | Required | Default + type | cellCentre | yes | + axis | x, y, z, xyz, distance | no | xyz + bounds | limit with bounding box | no | + \endtable + +SourceFiles + cellCentreSet.C + +\*---------------------------------------------------------------------------*/ + +#ifndef cellCentreSet_H +#define cellCentreSet_H + +#include "sampledSet.H" +#include "boundBox.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class cellCentreSet Declaration +\*---------------------------------------------------------------------------*/ + +class cellCentreSet +: + public sampledSet +{ + // Private data + + //- Optional bounding box to restrict the geometry + const boundBox bounds_; + + + // Private Member Functions + + //- Generate samples + void genSamples(); + + +public: + + //- Runtime type information + TypeName("cellCentre"); + + + // Constructors + + //- Construct from components + cellCentreSet + ( + const word& name, + const polyMesh& mesh, + const meshSearch& searchEngine, + const word& axis, + const boundBox& bbox = boundBox::invertedBox + ); + + //- Construct from dictionary + cellCentreSet + ( + const word& name, + const polyMesh& mesh, + const meshSearch& searchEngine, + const dictionary& dict + ); + + + //- Destructor + virtual ~cellCentreSet() = default; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/tutorials/compressible/rhoSimpleFoam/squareBend/system/controlDict b/tutorials/compressible/rhoSimpleFoam/squareBend/system/controlDict index 74ccb50c5a6f64c548fe6b612698394da1deea18..7e1979925be0b7bf451383018bda13535b3b7f38 100644 --- a/tutorials/compressible/rhoSimpleFoam/squareBend/system/controlDict +++ b/tutorials/compressible/rhoSimpleFoam/squareBend/system/controlDict @@ -53,6 +53,7 @@ functions { #include "sampling" // #include "samplingDebug" + // #include "sampleCellCentres" } diff --git a/tutorials/compressible/rhoSimpleFoam/squareBend/system/sampleCellCentres b/tutorials/compressible/rhoSimpleFoam/squareBend/system/sampleCellCentres new file mode 100644 index 0000000000000000000000000000000000000000..a11a449d6cb79016d24c98d665543153270a77d9 --- /dev/null +++ b/tutorials/compressible/rhoSimpleFoam/squareBend/system/sampleCellCentres @@ -0,0 +1,34 @@ +// -*- C++ -*- + +sampleSets +{ + type sets; + libs ("libsampling.so"); + log on; + enabled true; + + writeControl timeStep; + writeInterval 10; + + setFormat vtk; + setFormat csv; + interpolationScheme cell; + + // fields ( U p ); + + fields ( U ); + + sets + ( + centres + { + type cellCentre; + // axis xyz; // default: xyz + + // bounds (-0.2 -1 -1) (-0.195 0 1); + bounds (-0.025 -1 -1) (-0.0225 0 1); // single cell layer + } + ); +} + +// ************************************************************************* //