ENH: add 'cellCentre' sampledSet (issue #869)
- samples on cell centres, can optionally limit based on a bounding box. Can be used, for example, to extract volume fields into CSV format.
This commit is contained in:
parent
7402cd7b5a
commit
b2b77c9c13
@ -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
|
||||
|
132
src/sampling/sampledSet/cellCentre/cellCentreSet.C
Normal file
132
src/sampling/sampledSet/cellCentre/cellCentreSet.C
Normal file
@ -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();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
115
src/sampling/sampledSet/cellCentre/cellCentreSet.H
Normal file
115
src/sampling/sampledSet/cellCentre/cellCentreSet.H
Normal file
@ -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
|
||||
|
||||
// ************************************************************************* //
|
@ -53,6 +53,7 @@ functions
|
||||
{
|
||||
#include "sampling"
|
||||
// #include "samplingDebug"
|
||||
// #include "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
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
Loading…
Reference in New Issue
Block a user