sampledSet: Consistent renaming, documentation, and code maintenance

The sampled sets have been renamed in a more explicit and consistent
manner, and two new ones have also been added. The available sets are as
follows:

    arcUniform: Uniform samples along an arc. Replaces "circle", and
    adds the ability to sample along only a part of the circle's
    circumference. Example:

        {
            type        arcUniform;
            centre      (0.95 0 0.25);
            normal      (1 0 0);
            radial      (0 0 0.25);
            startAngle  -1.57079633;
            endAngle    0.52359878;
            nPoints     200;
            axis        x;
        }

    boundaryPoints: Specified point samples associated with a subset of
    the boundary. Replaces "patchCloud". Example:

        {
            type        boundaryPoints;
            patches     (inlet1 inlet2);
            points      ((0 -0.05 0.05) (0 -0.05 0.1) (0 -0.05 0.15));
            maxDistance 0.01;
            axis        x;
        }

    boundaryRandom: Random samples within a subset of the boundary.
    Replaces "patchSeed", but changes the behaviour to be entirely
    random. It does not seed the boundary face centres first. Example:

        {
            type        boundaryRandom;
            patches     (inlet1 inlet2);
            nPoints     1000;
            axis        x;
        }

    boxUniform: Uniform grid of samples within a axis-aligned box.
    Replaces "array". Example:

        {
            type    boxUniform;
            box     (0.95 0 0.25) (1.2 0.25 0.5);
            nPoints (2 4 6);
            axis    x;
        }

    circleRandom: Random samples within a circle. New. Example:

        {
            type        circleRandom;
            centre      (0.95 0 0.25);
            normal      (1 0 0);
            radius      0.25;
            nPoints     200;
            axis        x;
        }

    lineFace: Face-intersections along a line. Replaces "face". Example:

        {
            type        lineFace;
            start       (0.6 0.6 0.5);
            end         (0.6 -0.3 -0.1);
            axis        x;
        }

    lineCell: Cell-samples along a line at the mid-points in-between
    face-intersections. Replaces "midPoint". Example:

        {
            type        lineCell;
            start       (0.5 0.6 0.5);
            end         (0.5 -0.3 -0.1);
            axis        x;
        }

    lineCellFace: Combination of "lineFace" and "lineCell". Replaces
    "midPointAndFace". Example:

        {
            type        lineCellFace;
            start       (0.55 0.6 0.5);
            end         (0.55 -0.3 -0.1);
            axis        x;
        }

    lineUniform: Uniform samples along a line. Replaces "uniform".
    Example:

        {
            type        lineUniform;
            start       (0.65 0.3 0.3);
            end         (0.65 -0.3 -0.1);
            nPoints     200;
            axis        x;
        }

    points: Specified points. Replaces "cloud" when the ordered flag is
    false, and "polyLine" when the ordered flag is true. Example:

        {
            type        points;
            points      ((0 -0.05 0.05) (0 -0.05 0.1) (0 -0.05 0.15));
            ordered     yes;
            axis        x;
        }

    sphereRandom: Random samples within a sphere. New. Example:

        {
            type        sphereRandom;
            centre      (0.95 0 0.25);
            radius      0.25;
            nPoints     200;
            axis        x;
        }

    triSurfaceMesh: Samples from all the points of a triSurfaceMesh.
    Replaces "triSurfaceMeshPointSet". Example:

        {
            type        triSurfaceMesh;
            surface     "surface.stl";
            axis        x;
        }

The headers have also had documentation added. Example usage and a
description of the control parameters now exists for all sets.

In addition, a number of the algorithms which generate the sets have
been refactored or rewritten. This was done either to take advantage of
the recent changes to random number generation, or to remove ad-hoc
fixes that were made unnecessary by the barycentric tracking algorithm.
This commit is contained in:
Will Bainbridge
2018-05-14 15:20:05 +01:00
parent b4dfbd7f06
commit 3ef4c803cd
59 changed files with 2596 additions and 3464 deletions

View File

@ -12,8 +12,8 @@ setFormat raw;
setConfig setConfig
{ {
type uniform; // midPoint, midPointAndFace type lineUniform; // lineCell, lineCellFace
axis distance; // x, y, z, xyz axis distance; // x, y, z, xyz
nPoints 100; nPoints 100;
} }

View File

@ -19,7 +19,7 @@ fields (U p);
#includeEtc "caseDicts/postProcessing/graphs/sampleDict.cfg" #includeEtc "caseDicts/postProcessing/graphs/sampleDict.cfg"
// Override settings here, e.g. // Override settings here, e.g.
// setConfig { type midPoint; } // setConfig { type lineCell; }
// Must be last entry // Must be last entry
#includeEtc "caseDicts/postProcessing/graphs/graph.cfg" #includeEtc "caseDicts/postProcessing/graphs/graph.cfg"

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Description Description
Writes out values of fields at a cloud of points, interpolated to Writes out values of fields at a specified list of points, interpolated to
specified boundary patches. specified boundary patches.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -22,6 +22,6 @@ maxDistance 0.1;
patches (".*"); patches (".*");
#includeEtc "caseDicts/postProcessing/probes/boundaryCloud.cfg" #includeEtc "caseDicts/postProcessing/probes/boundaryPoints.cfg"
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,13 +6,13 @@
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#includeEtc "caseDicts/postProcessing/probes/cloud.cfg" #includeEtc "caseDicts/postProcessing/probes/points.cfg"
sets sets
( (
cloud points
{ {
type patchCloud; type boundaryPoints;
axis xyz; axis xyz;
points $points; points $points;
maxDistance $maxDistance; maxDistance $maxDistance;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Description Description
Writes out values of fields interpolated to a specified cloud of points. Writes out values of fields interpolated to a specified list of points.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -16,6 +16,6 @@ points
(0 0 0) (0 0 0)
); );
#includeEtc "caseDicts/postProcessing/probes/internalCloud.cfg" #includeEtc "caseDicts/postProcessing/probes/internalPoints.cfg"
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,13 +6,13 @@
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#includeEtc "caseDicts/postProcessing/probes/cloud.cfg" #includeEtc "caseDicts/postProcessing/probes/points.cfg"
sets sets
( (
cloud points
{ {
type cloud; type points;
axis xyz; axis xyz;
points $points; points $points;
} }

View File

@ -22,7 +22,7 @@ cloudName particleTracks;
seedSampleSet seedSampleSet
{ {
type uniform; type lineUniform;
axis x; axis x;
start $start; start $start;
end $end; end $end;

View File

@ -28,7 +28,7 @@ graph
( (
centreline centreline
{ {
type uniform; type lineUniform;
axis x; axis x;
start ( 0 1e-6 0); start ( 0 1e-6 0);
end (25 1e-6 0); end (25 1e-6 0);

View File

@ -28,7 +28,7 @@ License
#include "interpolation.H" #include "interpolation.H"
#include "IOmanip.H" #include "IOmanip.H"
#include "meshSearch.H" #include "meshSearch.H"
#include "midPointAndFaceSet.H" #include "lineCellFaceSet.H"
#include "Time.H" #include "Time.H"
#include "uniformDimensionedFields.H" #include "uniformDimensionedFields.H"
#include "volFields.H" #include "volFields.H"
@ -72,7 +72,7 @@ void Foam::functionObjects::interfaceHeight::writePositions()
forAll(locations_, li) forAll(locations_, li)
{ {
// Create a set along a ray projected in the direction of gravity // Create a set along a ray projected in the direction of gravity
const midPointAndFaceSet set const lineCellFaceSet set
( (
"", "",
mesh_, mesh_,

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -61,8 +61,8 @@ SourceFiles
#define interfaceHeight_H #define interfaceHeight_H
#include "fvMeshFunctionObject.H" #include "fvMeshFunctionObject.H"
#include "midPointAndFaceSet.H"
#include "logFiles.H" #include "logFiles.H"
#include "point.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -2,20 +2,21 @@ probes/probes.C
probes/patchProbes.C probes/patchProbes.C
probes/probesGrouping.C probes/probesGrouping.C
sampledSet/circle/circleSet.C
sampledSet/cloud/cloudSet.C
sampledSet/patchCloud/patchCloudSet.C
sampledSet/polyLine/polyLineSet.C
sampledSet/face/faceOnlySet.C
sampledSet/midPoint/midPointSet.C
sampledSet/midPointAndFace/midPointAndFaceSet.C
sampledSet/patchSeed/patchSeedSet.C
sampledSet/sampledSet/sampledSet.C sampledSet/sampledSet/sampledSet.C
sampledSet/sampledSets/sampledSets.C sampledSet/sampledSets/sampledSets.C
sampledSet/sampledSets/sampledSetsGrouping.C sampledSet/sampledSets/sampledSetsGrouping.C
sampledSet/triSurfaceMeshPointSet/triSurfaceMeshPointSet.C sampledSet/arcUniform/arcUniformSet.C
sampledSet/uniform/uniformSet.C sampledSet/boxUniform/boxUniformSet.C
sampledSet/array/arraySet.C sampledSet/circleRandom/circleRandomSet.C
sampledSet/lineCell/lineCellSet.C
sampledSet/lineCellFace/lineCellFaceSet.C
sampledSet/lineFace/lineFaceSet.C
sampledSet/lineUniform/lineUniformSet.C
sampledSet/boundaryPoints/boundaryPointsSet.C
sampledSet/boundaryRandom/boundaryRandomSet.C
sampledSet/points/pointsSet.C
sampledSet/sphereRandom/sphereRandomSet.C
sampledSet/triSurfaceMesh/triSurfaceMeshSet.C
cuttingPlane/cuttingPlane.C cuttingPlane/cuttingPlane.C

View File

@ -0,0 +1,148 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "arcUniformSet.H"
#include "sampledSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "word.H"
#include "unitConversion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(arcUniformSet, 0);
addToRunTimeSelectionTable(sampledSet, arcUniformSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::arcUniformSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
const vector axis1 = radial_ - (radial_ & normal_)*normal_;
const vector axis2 = normal_ ^ axis1;
const scalar radius = mag(axis1);
for (label i = 0; i < nPoints_; ++ i)
{
const scalar t = scalar(i)/(nPoints_ - 1);
const scalar theta = (1 - t)*startAngle_ + t*endAngle_;
const scalar c = cos(theta), s = sin(theta);
const point pt = centre_ + c*axis1 + s*axis2;
const label celli = searchEngine().findCell(pt);
if (celli != -1)
{
samplingPts.append(pt);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingSegments.append(samplingSegments.size());
samplingCurveDist.append(radius*theta);
}
}
}
void Foam::arcUniformSet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::arcUniformSet::arcUniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
centre_(dict.lookup("centre")),
normal_(normalised(dict.lookupType<vector>("normal"))),
radial_(dict.lookupType<vector>("radial")),
startAngle_(readScalar(dict.lookup("startAngle"))),
endAngle_(readScalar(dict.lookup("endAngle"))),
nPoints_(dict.lookupType<scalar>("nPoints"))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::arcUniformSet::~arcUniformSet()
{}
// ************************************************************************* //

View File

@ -0,0 +1,150 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::arcUniformSet
Description
Uniform samples along an arc
Usage
\table
Property | Description | Req'd? | Default
centre | Centre of the circle | yes |
normal | Direction normal to the plane of the circle | yes |
radial | Vector from the centre to a point on the arc | yes |
startAngle | The angle of the start of the arc in radians | yes |
endAngle | The angle of the end of the arc in radians | yes |
nPoints | The number of points | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type arcUniform;
centre (0.95 0 0.25);
normal (1 0 0);
radial (0 0 0.25);
startAngle -1.57079633;
endAngle 0.52359878;
nPoints 200;
axis x;
}
\endverbatim
SourceFiles
arcUniformSet.C
\*---------------------------------------------------------------------------*/
#ifndef arcUniformSet_H
#define arcUniformSet_H
#include "sampledSet.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class arcUniformSet Declaration
\*---------------------------------------------------------------------------*/
class arcUniformSet
:
public sampledSet
{
// Private data
// Arc definition
//- Centre of the circle of which the arc is a part
const point centre_;
//- Normal direction to the circle of which the arc is a part
const vector normal_;
//- Radial vector from the centre to the point on the arc from
// which the angles are measured
const vector radial_;
//- Start angle
const scalar startAngle_;
//- End angle
const scalar endAngle_;
//- Number of points spaced along the arc
const label nPoints_;
// Private Member Functions
//- Calculate all the sampling points
void calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const;
//- Uses calcSamples to obtain samples and copies them into *this
void genSamples();
public:
//- Runtime type information
TypeName("arcUniform");
// Constructors
//- Construct from dictionary
arcUniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
);
// Destructor
virtual ~arcUniformSet();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -23,28 +23,27 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "patchCloudSet.H" #include "boundaryPointsSet.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "treeBoundBox.H" #include "treeBoundBox.H"
#include "treeDataFace.H" #include "treeDataFace.H"
#include "Time.H" #include "Time.H"
#include "meshTools.H" #include "meshTools.H"
// For 'nearInfo' helper class only
#include "mappedPatchBase.H" #include "mappedPatchBase.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(patchCloudSet, 0); defineTypeNameAndDebug(boundaryPointsSet, 0);
addToRunTimeSelectionTable(sampledSet, patchCloudSet, word); addToRunTimeSelectionTable(sampledSet, boundaryPointsSet, word);
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::patchCloudSet::calcSamples void Foam::boundaryPointsSet::calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells, DynamicList<label>& samplingCells,
@ -53,174 +52,144 @@ void Foam::patchCloudSet::calcSamples
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const ) const
{ {
if (debug) // Construct a single list of all patch faces
{ label nPatchFaces = 0;
Info<< "patchCloudSet : sampling on patches :" << endl; forAllConstIter(labelHashSet, patches_, iter)
}
// Construct search tree for all patch faces.
label sz = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
{ {
const polyPatch& pp = mesh().boundaryMesh()[iter.key()]; const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
nPatchFaces += pp.size();
sz += pp.size();
if (debug)
{
Info<< " " << pp.name() << " size " << pp.size() << endl;
}
} }
labelList patchFaces(nPatchFaces);
labelList patchFaces(sz); nPatchFaces = 0;
sz = 0; forAllConstIter(labelHashSet, patches_, iter)
treeBoundBox bb(point::max, point::min);
forAllConstIter(labelHashSet, patchSet_, iter)
{ {
const polyPatch& pp = mesh().boundaryMesh()[iter.key()]; const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
forAll(pp, i) forAll(pp, i)
{ {
patchFaces[sz++] = pp.start()+i; patchFaces[nPatchFaces++] = pp.start()+i;
} }
// Do not do reduction.
const boundBox patchBb(pp.points(), pp.meshPoints(), false);
bb.min() = min(bb.min(), patchBb.min());
bb.max() = max(bb.max(), patchBb.max());
} }
bb = bb.extend(1e-4);
// Construct a processor-local bound box
treeBoundBox patchBB(point::max, point::min);
forAllConstIter(labelHashSet, patches_, iter)
{
const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
const boundBox patchBb(pp.points(), pp.meshPoints(), false);
patchBB.min() = min(patchBB.min(), patchBb.min());
patchBB.max() = max(patchBB.max(), patchBb.max());
}
patchBB = patchBB.extend(1e-4);
// Create a search tree
indexedOctree<treeDataFace> patchTree indexedOctree<treeDataFace> patchTree
( (
treeDataFace // all information needed to search faces treeDataFace // all information needed to search faces
( (
false, // do not cache bb false, // do not cache the bound box
mesh(), mesh(),
patchFaces // boundary faces only patchFaces
), ),
bb, // overall search domain patchBB, // overall search box
8, // maxLevel 8, // maximum number of levels
10, // leafsize 10, // how many elements per leaf
3.0 // duplicity 3.0 // in how many leaves is a shape on average
); );
// Force calculation of face-diagonal decomposition // Force calculation of face-diagonal decomposition
(void)mesh().tetBasePtIs(); (void)mesh().tetBasePtIs();
// Generate the nearest patch information for each sampling point
// All the info for nearest. Construct to miss List<mappedPatchBase::nearInfo> nearest(points_.size());
List<mappedPatchBase::nearInfo> nearest(sampleCoords_.size()); forAll(points_, sampleI)
forAll(sampleCoords_, sampleI)
{ {
const point& sample = sampleCoords_[sampleI]; const point& sample = points_[sampleI];
pointIndexHit& nearInfo = nearest[sampleI].first(); pointIndexHit& nearHit = nearest[sampleI].first();
scalar& nearDist = nearest[sampleI].second().first();
label& nearProc = nearest[sampleI].second().second();
// Find the nearest locally // Find the nearest
if (patchFaces.size()) if (patchFaces.size())
{ {
nearInfo = patchTree.findNearest(sample, sqr(searchDist_)); nearHit = patchTree.findNearest(sample, sqr(maxDistance_));
} }
else else
{ {
nearInfo.setMiss(); nearHit.setMiss();
} }
// Fill in the information
// Fill in the distance field and the processor field if (nearHit.hit())
if (!nearInfo.hit())
{ {
nearest[sampleI].second().first() = Foam::sqr(great); nearHit.setIndex(patchFaces[nearHit.index()]);
nearest[sampleI].second().second() = Pstream::myProcNo(); nearDist = magSqr(nearHit.hitPoint() - sample);
nearProc = Pstream::myProcNo();
} }
else else
{ {
// Set nearest to mesh face label nearHit.setIndex(-1);
nearInfo.setIndex(patchFaces[nearInfo.index()]); nearDist = Foam::sqr(great);
nearProc = Pstream::myProcNo();
nearest[sampleI].second().first() = magSqr
(
nearInfo.hitPoint()
- sample
);
nearest[sampleI].second().second() = Pstream::myProcNo();
} }
} }
// Reduce to get the nearest patch locations globally
// Find nearest.
Pstream::listCombineGather(nearest, mappedPatchBase::nearestEqOp()); Pstream::listCombineGather(nearest, mappedPatchBase::nearestEqOp());
Pstream::listCombineScatter(nearest); Pstream::listCombineScatter(nearest);
// Dump connecting lines from the sampling points to the hit locations
if (debug && Pstream::master()) if (debug && Pstream::master())
{ {
OFstream str OFstream str(mesh().time().path() / name() + "_nearest.obj");
(
mesh().time().path()
/ name()
+ "_nearest.obj"
);
Info<< "Dumping mapping as lines from supplied points to"
<< " nearest patch face to file " << str.name() << endl;
label vertI = 0; label verti = 0;
forAll(nearest, i) forAll(nearest, i)
{ {
if (nearest[i].first().hit()) if (nearest[i].first().hit())
{ {
meshTools::writeOBJ(str, sampleCoords_[i]); meshTools::writeOBJ(str, points_[i]);
vertI++; verti++;
meshTools::writeOBJ(str, nearest[i].first().hitPoint()); meshTools::writeOBJ(str, nearest[i].first().hitPoint());
vertI++; verti++;
str << "l " << vertI-1 << ' ' << vertI << nl; str << "l " << verti - 1 << ' ' << verti << nl;
} }
} }
} }
// Store the sampling locations on the nearest processor // Store the sampling locations on the nearest processor
forAll(nearest, sampleI) forAll(nearest, sampleI)
{ {
const pointIndexHit& nearInfo = nearest[sampleI].first(); const pointIndexHit& nearHit = nearest[sampleI].first();
const label& nearProc = nearest[sampleI].second().second();
if (nearInfo.hit()) if (nearHit.hit())
{ {
if (nearest[sampleI].second().second() == Pstream::myProcNo()) if (nearProc == Pstream::myProcNo())
{ {
label facei = nearInfo.index(); label facei = nearHit.index();
samplingPts.append(nearInfo.hitPoint()); samplingPts.append(nearHit.hitPoint());
samplingCells.append(mesh().faceOwner()[facei]); samplingCells.append(mesh().faceOwner()[facei]);
samplingFaces.append(facei); samplingFaces.append(facei);
samplingSegments.append(0); samplingSegments.append(0);
samplingCurveDist.append(1.0 * sampleI); samplingCurveDist.append(sampleI);
} }
} }
else else
{ {
// No processor found point near enough. Mark with special value WarningInFunction
// which is intercepted when interpolating << "Unable to find location on patches " << patches_
if (Pstream::master()) << " for the point " << points_[sampleI]
{ << " within a distance of " << maxDistance_ << endl;
samplingPts.append(sampleCoords_[sampleI]);
samplingCells.append(-1);
samplingFaces.append(-1);
samplingSegments.append(0);
samplingCurveDist.append(1.0 * sampleI);
}
} }
} }
} }
void Foam::patchCloudSet::genSamples() void Foam::boundaryPointsSet::genSamples()
{ {
// Storage for sample points
DynamicList<point> samplingPts; DynamicList<point> samplingPts;
DynamicList<label> samplingCells; DynamicList<label> samplingCells;
DynamicList<label> samplingFaces; DynamicList<label> samplingFaces;
@ -255,32 +224,7 @@ void Foam::patchCloudSet::genSamples()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::patchCloudSet::patchCloudSet Foam::boundaryPointsSet::boundaryPointsSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const List<point>& sampleCoords,
const labelHashSet& patchSet,
const scalar searchDist
)
:
sampledSet(name, mesh, searchEngine, axis),
sampleCoords_(sampleCoords),
patchSet_(patchSet),
searchDist_(searchDist)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::patchCloudSet::patchCloudSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -289,15 +233,15 @@ Foam::patchCloudSet::patchCloudSet
) )
: :
sampledSet(name, mesh, searchEngine, dict), sampledSet(name, mesh, searchEngine, dict),
sampleCoords_(dict.lookup("points")), points_(dict.lookup("points")),
patchSet_ patches_
( (
mesh.boundaryMesh().patchSet mesh.boundaryMesh().patchSet
( (
wordReList(dict.lookup("patches")) wordReList(dict.lookup("patches"))
) )
), ),
searchDist_(readScalar(dict.lookup("maxDistance"))) maxDistance_(readScalar(dict.lookup("maxDistance")))
{ {
genSamples(); genSamples();
@ -310,7 +254,7 @@ Foam::patchCloudSet::patchCloudSet
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::patchCloudSet::~patchCloudSet() Foam::boundaryPointsSet::~boundaryPointsSet()
{} {}

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,23 +22,48 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::patchSeedSet Foam::boundaryPointsSet
Description Description
Initialises points on or just off patch Specified point samples within patches
Usage
\table
Property | Description | Req'd? | Default
patches | The patches on which to sample | yes |
points | The points to sample | yes |
maxDistance | The maximum distance from patch to point | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type boundaryPoints;
patches (inlet1 inlet2);
points
(
(0 -0.05 0.05)
(0 -0.05 0.15)
(0 0.05 0.15)
(0 0.05 0.05)
);
maxDistance 0.01;
axis x;
}
\endverbatim
SourceFiles SourceFiles
patchSeedSet.C boundaryPointsSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef patchSeedSet_H #ifndef boundaryPointsSet_H
#define patchSeedSet_H #define boundaryPointsSet_H
#include "sampledSet.H" #include "sampledSet.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "HashSet.H" #include "HashSet.H"
#include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -46,34 +71,28 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class patchSeedSet Declaration Class boundaryPointsSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class patchSeedSet class boundaryPointsSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
//- Sampling points
const List<point> points_;
//- Patches to sample //- Patches to sample
const labelHashSet patchSet_; const labelHashSet patches_;
// //- Maximum distance to look for nearest //- Maximum distance to to search for a nearby patch
// const scalar searchDist_; const scalar maxDistance_;
//
// //- Offset distance
// const scalar offsetDist_;
//- Maximum number of patch faces to seed
const label maxPoints_;
//- Random number generator (if maxPoints < num patch faces)
autoPtr<Random> rndGenPtr_;
// Private Member Functions // Private Member Functions
//- Samples all points in sampleCoords. //- Samples all points in sampleCoords
void calcSamples void calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
@ -81,7 +100,7 @@ class patchSeedSet
DynamicList<label>& samplingFaces, DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments, DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
); ) const;
//- Uses calcSamples to obtain samples. Copies them into *this. //- Uses calcSamples to obtain samples. Copies them into *this.
void genSamples(); void genSamples();
@ -90,13 +109,13 @@ class patchSeedSet
public: public:
//- Runtime type information //- Runtime type information
TypeName("patchSeed"); TypeName("boundaryPoints");
// Constructors // Constructors
//- Construct from dictionary //- Construct from dictionary
patchSeedSet boundaryPointsSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -106,7 +125,7 @@ public:
//- Destructor //- Destructor
virtual ~patchSeedSet(); virtual ~boundaryPointsSet();
}; };

View File

@ -0,0 +1,248 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boundaryRandomSet.H"
#include "sampledSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "word.H"
#include "Random.H"
#include "SubField.H"
#include "barycentric2D.H"
#include "triPointRef.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(boundaryRandomSet, 0);
addToRunTimeSelectionTable(sampledSet, boundaryRandomSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::boundaryRandomSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
// Triangulate the patches
List<DynamicList<face>> trisDyn(patches_.size());
List<DynamicList<label>> trisFaceiDyn(patches_.size());
forAll(patches_, patchi)
{
const polyPatch& patch = mesh().boundaryMesh()[patchi];
forAll(patch, patchFacei)
{
const face& f = patch[patchFacei];
const label facei = patchFacei + patch.start();
DynamicList<face> faceTris(f.nTriangles());
f.triangles(patch.points(), faceTris);
trisDyn[patchi].append(faceTris);
trisFaceiDyn[patchi].append(labelList(f.nTriangles(), facei));
}
}
List<faceList> tris(patches_.size());
List<labelList> trisFacei(patches_.size());
forAll(patches_, patchi)
{
tris[patchi].transfer(trisDyn[patchi]);
trisFacei[patchi].transfer(trisFaceiDyn[patchi]);
}
// Generate the fractions which select the processor, patch and triangle
List<scalarField> trisFraction(patches_.size());
forAll(patches_, patchi)
{
const polyPatch& patch = mesh().boundaryMesh()[patchi];
const pointField& points = patch.points();
trisFraction[patchi] = scalarField(tris[patchi].size() + 1, 0);
forAll(tris[patchi], patchTrii)
{
trisFraction[patchi][patchTrii + 1] =
trisFraction[patchi][patchTrii]
+ tris[patchi][patchTrii].mag(points);
}
}
scalarField patchesFraction(patches_.size() + 1, 0);
forAll(patches_, patchi)
{
patchesFraction[patchi + 1] =
patchesFraction[patchi] + trisFraction[patchi].last();
}
scalarField procsArea(Pstream::nProcs(), 0);
procsArea[Pstream::myProcNo()] = patchesFraction.last();
Pstream::listCombineGather(procsArea, maxEqOp<scalar>());
Pstream::listCombineScatter(procsArea);
scalarField procsFraction(Pstream::nProcs() + 1, 0);
for(label proci = 0; proci < Pstream::nProcs(); ++ proci)
{
procsFraction[proci + 1] = procsFraction[proci] + procsArea[proci];
}
bool anyTris = false;
forAll(patches_, patchi)
{
if (tris[patchi].size())
{
trisFraction[patchi] /= trisFraction[patchi].last();
anyTris = true;
}
}
if (anyTris)
{
patchesFraction /= patchesFraction.last();
}
procsFraction /= procsFraction.last();
// Generate the samples
Random rndGen(261782);
const label proci = Pstream::myProcNo();
for (label i = 0; i < nPoints_; ++ i)
{
// Request all random numbers simultaneously on all processors so that
// the generator state stays consistent
const scalar rProc = rndGen.scalar01();
const scalar rPatch = rndGen.scalar01();
const scalar rTri = rndGen.scalar01();
const barycentric2D r = barycentric2D01(rndGen);
if (procsFraction[proci] < rProc && rProc <= procsFraction[proci + 1])
{
label patchi = 0;
while (rPatch > patchesFraction[patchi + 1])
{
++ patchi;
}
label trii = 0;
while (rTri > trisFraction[patchi][trii + 1])
{
++ trii;
}
const polyPatch& patch = mesh().boundaryMesh()[patchi];
const pointField& points = patch.points();
const face& tf = tris[patchi][trii];
const triPointRef tt(points[tf[0]], points[tf[1]], points[tf[2]]);
samplingPts.append(tt.barycentricToPoint(r));
samplingCells.append(mesh().faceOwner()[trisFacei[patchi][trii]]);
samplingFaces.append(trisFacei[patchi][trii]);
samplingSegments.append(0);
samplingCurveDist.append(scalar(i));
}
}
}
void Foam::boundaryRandomSet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boundaryRandomSet::boundaryRandomSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
patches_
(
mesh.boundaryMesh().patchSet
(
wordReList(dict.lookup("patches"))
)
),
nPoints_(readLabel(dict.lookup("nPoints")))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::boundaryRandomSet::~boundaryRandomSet()
{}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,19 +22,36 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::patchCloudSet Foam::boundaryRandomSet
Description Description
Like cloudSet but samples nearest patch face Random samples within patches
Usage
\table
Property | Description | Req'd? | Default
patches | The patches on which to sample | yes |
nPoints | The number of points | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type boundaryRandom;
patches (inlet1 inlet2);
nPoints 1000;
axis x;
}
\endverbatim
SourceFiles SourceFiles
patchCloudSet.C boundaryRandomSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef patchCloudSet_H #ifndef boundaryRandomSet_H
#define patchCloudSet_H #define boundaryRandomSet_H
#include "sampledSet.H" #include "sampledSet.H"
#include "DynamicList.H" #include "DynamicList.H"
@ -46,28 +63,25 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class patchCloudSet Declaration Class boundaryRandomSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class patchCloudSet class boundaryRandomSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
//- Sampling points
const List<point> sampleCoords_;
//- Patches to sample //- Patches to sample
const labelHashSet patchSet_; const labelHashSet patches_;
//- Maximum distance to look for nearest //- Number of points
const scalar searchDist_; const label nPoints_;
// Private Member Functions // Private Member Functions
//- Samples all points in sampleCoords. //- Sample all points
void calcSamples void calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
@ -77,32 +91,20 @@ class patchCloudSet
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const; ) const;
//- Uses calcSamples to obtain samples. Copies them into *this. //- Use calcSamples to obtain samples and copy them into *this
void genSamples(); void genSamples();
public: public:
//- Runtime type information //- Runtime type information
TypeName("patchCloud"); TypeName("boundaryRandom");
// Constructors // Constructors
//- Construct from components
patchCloudSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const List<point>& sampleCoords,
const labelHashSet& patchSet,
const scalar searchDist
);
//- Construct from dictionary //- Construct from dictionary
patchCloudSet boundaryRandomSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -112,7 +114,7 @@ public:
//- Destructor //- Destructor
virtual ~patchCloudSet(); virtual ~boundaryRandomSet();
}; };

View File

@ -0,0 +1,148 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boxUniformSet.H"
#include "sampledSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "word.H"
#include "transform.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(boxUniformSet, 0);
addToRunTimeSelectionTable(sampledSet, boxUniformSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::boxUniformSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
for (label k = 0; k < nPoints_.z(); ++ k)
{
for (label j = 0; j < nPoints_.y(); ++ j)
{
for (label i = 0; i < nPoints_.x(); ++ i)
{
const vector t =
cmptDivide(vector(i, j, k), vector(nPoints_) - vector::one);
const point pt =
cmptMultiply(vector::one - t, box_.min())
+ cmptMultiply(t, box_.max());
const label celli = searchEngine().findCell(pt);
if (celli != -1)
{
samplingPts.append(pt);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingSegments.append(0);
samplingCurveDist.append(scalar(i));
}
}
}
}
}
void Foam::boxUniformSet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::boxUniformSet::boxUniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
box_(dict.lookup("box")),
nPoints_(dict.lookup("nPoints"))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::boxUniformSet::~boxUniformSet()
{}
// ************************************************************************* //

View File

@ -22,21 +22,41 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::arraySet Foam::boxUniformSet
Description Description
Uniform 3D-grid of samples
Usage
\table
Property | Description | Req'd? | Default
box | The box which contains the samples | yes |
nPoints | The number of points in each direction | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type boxUniform;
box (0.95 0 0.25) (1.2 0.25 0.5);
nPoints (2 4 6);
axis x;
}
\endverbatim
SourceFiles SourceFiles
arraySet.C boxUniformSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef arraySet_H #ifndef boxUniformSet_H
#define arraySet_H #define boxUniformSet_H
#include "sampledSet.H" #include "sampledSet.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "coordinateSystem.H" #include "labelVector.H"
#include "boundBox.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -48,23 +68,20 @@ class passiveParticle;
template<class Type> class particle; template<class Type> class particle;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class arraySet Declaration Class boxUniformSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class arraySet class boxUniformSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
//- Coordinate system //- Box
coordinateSystem coordSys_; const boundBox box_;
//- Point density vector //- The number of points across each direction of the box
Vector<label> pointsDensity_; const labelVector nPoints_;
//- Span box
Vector<scalar> spanBox_;
// Private Member Functions // Private Member Functions
@ -86,25 +103,13 @@ class arraySet
public: public:
//- Runtime type information //- Runtime type information
TypeName("array"); TypeName("boxUniform");
// Constructors // Constructors
//- Construct from components
arraySet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const coordinateSystem& coordSys,
const Vector<label>& pointsDensity,
const Vector<scalar>& spanBox
);
//- Construct from dictionary //- Construct from dictionary
arraySet boxUniformSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -114,7 +119,7 @@ public:
//- Destructor //- Destructor
virtual ~arraySet(); virtual ~boxUniformSet();
}; };

View File

@ -1,243 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "circleSet.H"
#include "sampledSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "word.H"
#include "mathematicalConstants.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(circleSet, 0);
addToRunTimeSelectionTable(sampledSet, circleSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::circleSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
static const string funcName =
(
"void circleSet::calcSamples"
"("
"DynamicList<point>&, "
"DynamicList<label>&, "
"DynamicList<label>&, "
"DynamicList<label>&, "
"DynamicList<scalar>&"
") const"
);
// set start point
label celli = searchEngine().findCell(startPoint_);
if (celli != -1)
{
samplingPts.append(startPoint_);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingSegments.append(0);
samplingCurveDist.append(0.0);
}
else
{
WarningInFunction
<< "Unable to find cell at point id " << 0
<< " at location " << startPoint_ << endl;
}
// add remaining points
const scalar alpha = constant::mathematical::pi/180.0*dTheta_;
const scalar sinAlpha = sin(alpha);
const scalar cosAlpha = cos(alpha);
// first axis
vector axis1 = startPoint_ - origin_;
const scalar radius = mag(axis1);
if (mag(axis1 & circleAxis_) > small)
{
WarningInFunction
<< "Vector defined by (startPoint - origin) not orthogonal to "
<< "circleAxis:" << nl
<< " startPoint - origin = " << axis1 << nl
<< " circleAxis = " << circleAxis_ << nl
<< endl;
}
axis1 /= mag(axis1);
scalar theta = dTheta_;
label nPoint = 1;
while (theta < 360)
{
axis1 = axis1*cosAlpha + (axis1^circleAxis_)*sinAlpha;
axis1 /= mag(axis1);
point pt = origin_ + radius*axis1;
label celli = searchEngine().findCell(pt);
if (celli != -1)
{
samplingPts.append(pt);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingSegments.append(nPoint);
samplingCurveDist.append
(
radius*constant::mathematical::pi/180.0*theta
);
nPoint++;
}
else
{
WarningInFunction
<< "Unable to find cell at point id " << nPoint
<< " at location " << pt << endl;
}
theta += dTheta_;
}
}
void Foam::circleSet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::circleSet::circleSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& origin,
const vector& circleAxis,
const point& startPoint,
const scalar dTheta
)
:
sampledSet(name, mesh, searchEngine, axis),
origin_(origin),
circleAxis_(circleAxis),
startPoint_(startPoint),
dTheta_(dTheta)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::circleSet::circleSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
origin_(dict.lookup("origin")),
circleAxis_(dict.lookup("circleAxis")),
startPoint_(dict.lookup("startPoint")),
dTheta_(readScalar(dict.lookup("dTheta")))
{
// normalise circleAxis
circleAxis_ /= mag(circleAxis_);
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::circleSet::~circleSet()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::circleSet::getRefPoint(const List<point>& pts) const
{
return startPoint_;
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,27 +23,28 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "arraySet.H" #include "circleRandomSet.H"
#include "sampledSet.H" #include "sampledSet.H"
#include "meshSearch.H" #include "meshSearch.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "word.H" #include "word.H"
#include "transform.H" #include "mathematicalConstants.H"
#include "Random.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(arraySet, 0); defineTypeNameAndDebug(circleRandomSet, 0);
addToRunTimeSelectionTable(sampledSet, arraySet, word); addToRunTimeSelectionTable(sampledSet, circleRandomSet, word);
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::arraySet::calcSamples void Foam::circleRandomSet::calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells, DynamicList<label>& samplingCells,
@ -52,57 +53,36 @@ void Foam::arraySet::calcSamples
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const ) const
{ {
const meshSearch& queryMesh = searchEngine(); Random rndGen(261782);
label nTotalSamples const vector radial1 = normalised(perpendicular(normal_));
( const vector radial2 = normalised(normal_ ^ radial1);
pointsDensity_.x()
*pointsDensity_.y()
*pointsDensity_.z()
);
List<point> sampleCoords(nTotalSamples); for (label i = 0; i < nPoints_; ++ i)
const scalar deltax = spanBox_.x()/(pointsDensity_.x() + 1);
const scalar deltay = spanBox_.y()/(pointsDensity_.y() + 1);
const scalar deltaz = spanBox_.z()/(pointsDensity_.z() + 1);
label p(0);
for (label k=1; k<=pointsDensity_.z(); k++)
{ {
for (label j=1; j<=pointsDensity_.y(); j++) // Request all random numbers simultaneously on all processors so that
{ // the generator state stays consistent
for (label i=1; i<=pointsDensity_.x(); i++)
{
vector t(deltax*i , deltay*j, deltaz*k);
sampleCoords[p] = coordSys_.origin() + t;
p++;
}
}
}
forAll(sampleCoords, i) const scalar r = radius_*rndGen.scalar01();
{ const scalar theta = 2*constant::mathematical::pi*rndGen.scalar01();
sampleCoords[i] = transform(coordSys_.R().R(), sampleCoords[i]); const scalar c = cos(theta), s = sin(theta);
}
forAll(sampleCoords, sampleI) const point pt = centre_ + r*(c*radial1 + s*radial2);
{ const label celli = searchEngine().findCell(pt);
label celli = queryMesh.findCell(sampleCoords[sampleI]);
if (celli != -1) if (celli != -1)
{ {
samplingPts.append(sampleCoords[sampleI]); samplingPts.append(pt);
samplingCells.append(celli); samplingCells.append(celli);
samplingFaces.append(-1); samplingFaces.append(-1);
samplingSegments.append(0); samplingSegments.append(0);
samplingCurveDist.append(1.0 * sampleI); samplingCurveDist.append(scalar(i));
} }
} }
} }
void Foam::arraySet::genSamples() void Foam::circleRandomSet::genSamples()
{ {
// Storage for sample points // Storage for sample points
DynamicList<point> samplingPts; DynamicList<point> samplingPts;
@ -139,32 +119,7 @@ void Foam::arraySet::genSamples()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::arraySet::arraySet Foam::circleRandomSet::circleRandomSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const coordinateSystem& origin,
const Vector<label>& pointsDensity,
const Vector<scalar>& spanBox
)
:
sampledSet(name, mesh, searchEngine, axis),
coordSys_(origin),
pointsDensity_(pointsDensity),
spanBox_(spanBox)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::arraySet::arraySet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -173,9 +128,10 @@ Foam::arraySet::arraySet
) )
: :
sampledSet(name, mesh, searchEngine, dict), sampledSet(name, mesh, searchEngine, dict),
coordSys_(dict), centre_(dict.lookup("centre")),
pointsDensity_(dict.lookup("pointsDensity")), normal_(normalised(dict.lookupType<vector>("normal"))),
spanBox_(dict.lookup("spanBox")) radius_(readScalar(dict.lookup("radius"))),
nPoints_(readLabel(dict.lookup("nPoints")))
{ {
genSamples(); genSamples();
@ -188,7 +144,7 @@ Foam::arraySet::arraySet
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::arraySet::~arraySet() Foam::circleRandomSet::~circleRandomSet()
{} {}

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::circleRandomSet
Description
Random samples within a circle
Usage
\table
Property | Description | Req'd? | Default
centre | Centre of the circle | yes |
normal | Direction normal to the plane of the circle | yes |
radius | Radius of the circle | yes |
nPoints | The number of points | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type circleRandom;
centre (0.95 0 0.25);
normal (1 0 0);
radius 0.25;
nPoints 200;
axis x;
}
\endverbatim
SourceFiles
circleRandomSet.C
\*---------------------------------------------------------------------------*/
#ifndef circleRandomSet_H
#define circleRandomSet_H
#include "sampledSet.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class circleRandomSet Declaration
\*---------------------------------------------------------------------------*/
class circleRandomSet
:
public sampledSet
{
// Private data
//- Centre point
const point centre_;
//- Direction normal to the circle
const vector normal_;
//- Radius
const scalar radius_;
//- Number of points
const label nPoints_;
// Private Member Functions
//- Samples all points in sampleCoords
void calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const;
//- Uses calcSamples to obtain samples. Copies them into *this.
void genSamples();
public:
//- Runtime type information
TypeName("circleRandom");
// Constructors
//- Construct from dictionary
circleRandomSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
);
// Destructor
virtual ~circleRandomSet();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,378 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "faceOnlySet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(faceOnlySet, 0);
addToRunTimeSelectionTable(sampledSet, faceOnlySet, word);
const scalar faceOnlySet::tol = 1e-6;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::faceOnlySet::trackToBoundary
(
passiveParticleCloud& particleCloud,
passiveParticle& singleParticle,
const scalar smallDist,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<scalar>& samplingCurveDist
) const
{
particle::trackingData td(particleCloud);
point trackPt = singleParticle.position();
while(true)
{
point oldPoint = trackPt;
singleParticle.trackToAndHitFace(end_ - start_, 0, particleCloud, td);
trackPt = singleParticle.position();
if (singleParticle.face() != -1 && mag(oldPoint - trackPt) > smallDist)
{
// Reached face. Sample.
samplingPts.append(trackPt);
samplingCells.append(singleParticle.cell());
samplingFaces.append(singleParticle.face());
samplingCurveDist.append(mag(trackPt - start_));
}
if (mag(trackPt - end_) < smallDist)
{
// End reached
return false;
}
else if (singleParticle.onBoundaryFace())
{
// Boundary reached
return true;
}
}
}
void Foam::faceOnlySet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
// Distance vector between sampling points
if (mag(end_ - start_) < small)
{
FatalErrorInFunction
<< "Incorrect sample specification :"
<< " start equals end point." << endl
<< " start:" << start_
<< " end:" << end_
<< exit(FatalError);
}
const vector offset = (end_ - start_);
const vector normOffset = offset/mag(offset);
const vector smallVec = tol*offset;
const scalar smallDist = mag(smallVec);
// Force calculation of cloud addressing on all processors
const bool oldMoving = const_cast<polyMesh&>(mesh()).moving(false);
passiveParticleCloud particleCloud(mesh());
// Get all boundary intersections
List<pointIndexHit> bHits = searchEngine().intersections
(
start_ - smallVec,
end_ + smallVec
);
point bPoint(great, great, great);
label bFacei = -1;
if (bHits.size())
{
bPoint = bHits[0].hitPoint();
bFacei = bHits[0].index();
}
// Get first tracking point. Use bPoint, bFacei if provided.
point trackPt;
label trackCelli = -1;
label trackFacei = -1;
// Pout<< "before getTrackingPoint : bPoint:" << bPoint
// << " bFacei:" << bFacei << endl;
getTrackingPoint
(
start_,
bPoint,
bFacei,
smallDist,
trackPt,
trackCelli,
trackFacei
);
// Pout<< "after getTrackingPoint : "
// << " trackPt:" << trackPt
// << " trackCelli:" << trackCelli
// << " trackFacei:" << trackFacei
// << endl;
if (trackCelli == -1)
{
// Line start_ - end_ does not intersect domain at all.
// (or is along edge)
// Set points and cell/face labels to empty lists
// Pout<< "calcSamples : Both start_ and end_ outside domain"
// << endl;
const_cast<polyMesh&>(mesh()).moving(oldMoving);
return;
}
if (trackFacei == -1)
{
// No boundary face. Check for nearish internal face
trackFacei = findNearFace(trackCelli, trackPt, smallDist);
}
// Pout<< "calcSamples : got first point to track from :"
// << " trackPt:" << trackPt
// << " trackCell:" << trackCelli
// << " trackFace:" << trackFacei
// << endl;
//
// Track until hit end of all boundary intersections
//
// current segment number
label segmentI = 0;
// starting index of current segment in samplePts
label startSegmentI = 0;
// index in bHits; current boundary intersection
label bHitI = 1;
while (true)
{
if (trackFacei != -1)
{
// Pout<< "trackPt:" << trackPt << " on face so use." << endl;
samplingPts.append(trackPt);
samplingCells.append(trackCelli);
samplingFaces.append(trackFacei);
samplingCurveDist.append(mag(trackPt - start_));
}
// Initialize tracking starting from trackPt
passiveParticle singleParticle
(
mesh(),
trackPt,
trackCelli
);
bool reachedBoundary = trackToBoundary
(
particleCloud,
singleParticle,
smallDist,
samplingPts,
samplingCells,
samplingFaces,
samplingCurveDist
);
// Fill sampleSegments
for (label i = samplingPts.size() - 1; i >= startSegmentI; --i)
{
samplingSegments.append(segmentI);
}
if (!reachedBoundary)
{
// Pout<< "calcSamples : Reached end of samples: "
// << " samplePt now:" << singleParticle.position()
// << endl;
break;
}
bool foundValidB = false;
while (bHitI < bHits.size())
{
scalar dist =
(bHits[bHitI].hitPoint() - singleParticle.position())
& normOffset;
// Pout<< "Finding next boundary : "
// << "bPoint:" << bHits[bHitI].hitPoint()
// << " tracking:" << singleParticle.position()
// << " dist:" << dist
// << endl;
if (dist > smallDist)
{
// Hit-point is past tracking position
foundValidB = true;
break;
}
else
{
bHitI++;
}
}
if (!foundValidB || bHitI == bHits.size() - 1)
{
// No valid boundary intersection found beyond tracking position
break;
}
// Update starting point for tracking
trackFacei = bHits[bHitI].index();
trackPt = pushIn(bHits[bHitI].hitPoint(), trackFacei);
trackCelli = getBoundaryCell(trackFacei);
segmentI++;
startSegmentI = samplingPts.size();
}
const_cast<polyMesh&>(mesh()).moving(oldMoving);
}
void Foam::faceOnlySet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
// Copy into *this
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faceOnlySet::faceOnlySet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
)
:
sampledSet(name, mesh, searchEngine, axis),
start_(start),
end_(end)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::faceOnlySet::faceOnlySet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
start_(dict.lookup("start")),
end_(dict.lookup("end"))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::faceOnlySet::~faceOnlySet()
{}
// ************************************************************************* //

View File

@ -0,0 +1,217 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "lineCellSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(lineCellSet, 0);
addToRunTimeSelectionTable(sampledSet, lineCellSet, word);
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::lineCellSet::calcMidPointSample
(
const polyMesh& mesh,
const point& prevPt,
const label prevFace,
const label prevSegment,
const scalar prevCurveDist,
const point& nextPt,
const label nextFace,
const label nextSegment,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
)
{
if (prevSegment == nextSegment)
{
const point pt = (prevPt + nextPt)/2;
const vector delta = nextPt - prevPt;
const label prevOwner = mesh.faceOwner()[prevFace];
const label prevNeighbour =
prevFace < mesh.faceNeighbour().size()
? mesh.faceNeighbour()[prevFace]
: -1;
const label nextOwner = mesh.faceOwner()[nextFace];
const label nextNeighbour =
nextFace < mesh.faceNeighbour().size()
? mesh.faceNeighbour()[nextFace]
: -2;
label celli = -1;
if (prevOwner == nextOwner || prevOwner == nextNeighbour)
{
celli = prevOwner;
}
else if (prevNeighbour == nextOwner || prevNeighbour == nextNeighbour)
{
celli = prevNeighbour;
}
else
{
FatalErrorInFunction
<< "Adjacent faces in the same segment do not share a cell. "
<< "This is a bug." << exit(FatalError);
}
samplingPts.append(pt);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingCurveDist.append(prevCurveDist + mag(delta)/2);
samplingSegments.append(prevSegment);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::lineCellSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
// Run the algorithm from lineFaceSet to get all the face intersections
DynamicList<point> facePts;
DynamicList<label> faceCells;
DynamicList<label> faceFaces;
DynamicList<label> faceSegments;
DynamicList<scalar> faceCurveDist;
lineFaceSet::calcSamples
(
mesh(),
searchEngine(),
start_,
end_,
facePts,
faceCells,
faceFaces,
faceSegments,
faceCurveDist
);
// Append all mid points to the set
for (label facei = 1; facei < facePts.size(); ++ facei)
{
calcMidPointSample
(
mesh(),
facePts[facei - 1],
faceFaces[facei - 1],
faceSegments[facei - 1],
faceCurveDist[facei - 1],
facePts[facei],
faceFaces[facei],
faceSegments[facei],
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
}
void Foam::lineCellSet::genSamples()
{
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lineCellSet::lineCellSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
start_(dict.lookup("start")),
end_(dict.lookup("end"))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::lineCellSet::~lineCellSet()
{}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,21 +22,38 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::faceOnlySet Foam::lineCellSet
Description Description
Cell-samples along a line at the mid-points in-between face-intersections
Usage
\table
Property | Description | Req'd? | Default
start | The start point of the line | yes |
end | The end point of the line | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type lineCell;
start (0.5 0.6 0.5);
end (0.5 -0.3 -0.1);
axis x;
}
\endverbatim
SourceFiles SourceFiles
faceOnlySet.C lineCellSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef faceOnlySet_H #ifndef lineCellSet_H
#define faceOnlySet_H #define lineCellSet_H
#include "sampledSet.H" #include "lineFaceSet.H"
#include "DynamicList.H"
#include "passiveParticleCloud.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -44,42 +61,26 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class faceOnlySet Declaration Class lineCellSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class faceOnlySet class lineCellSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
//- Starting point //- Start point
point start_; const point start_;
//- End point //- End point
point end_; const point end_;
// Private Member Functions // Private Member Functions
//- Samples from startTrackPt/Celli. Updates particle/samplePt/sampleI //- Calculate all the sampling points
// and puts virtual void calcSamples
// samples in the DynamicLists. Returns false if end of all samples
// reached
bool trackToBoundary
(
passiveParticleCloud& particleCloud,
passiveParticle& singleParticle,
const scalar smallDist,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<scalar>& samplingCurve
) const;
//- Samples from start_ to end_. samplingSegments contains segmentNo
// for each sample.
void calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells, DynamicList<label>& samplingCells,
@ -88,38 +89,41 @@ class faceOnlySet
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const; ) const;
//- Uses calcSamples to obtain samples. Copies them into *this. //- Uses calcSamples to obtain samples and copies them into *this
void genSamples(); void genSamples();
public: public:
//- Runtime type information //- Runtime type information
TypeName("face"); TypeName("lineCell");
// Static data // Static Member Functions
//- Tolerance when comparing points relative to difference between //- Calculate the next mid point sample
// start_ and end_ static void calcMidPointSample
static const scalar tol; (
const polyMesh& mesh,
const point& prevPt,
const label prevFace,
const label prevSegment,
const scalar prevCurveDist,
const point& nextPt,
const label nextFace,
const label nextSegment,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
);
// Constructors // Constructors
//- Construct from components
faceOnlySet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
);
//- Construct from dictionary //- Construct from dictionary
faceOnlySet lineCellSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -129,20 +133,7 @@ public:
//- Destructor //- Destructor
virtual ~faceOnlySet(); virtual ~lineCellSet();
// Member Functions
const point& start() const
{
return start_;
}
const point& end() const
{
return end_;
}
}; };

View File

@ -0,0 +1,199 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "lineCellFaceSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(lineCellFaceSet, 0);
addToRunTimeSelectionTable(sampledSet, lineCellFaceSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::lineCellFaceSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
// Run the algorithm from lineFaceSet to get all the face intersections
DynamicList<point> facePts;
DynamicList<label> faceCells;
DynamicList<label> faceFaces;
DynamicList<label> faceSegments;
DynamicList<scalar> faceCurveDist;
lineFaceSet::calcSamples
(
mesh(),
searchEngine(),
start_,
end_,
facePts,
faceCells,
faceFaces,
faceSegments,
faceCurveDist
);
// If there are no intersections then quit
if (!facePts.size())
{
return;
}
// Append all the face intersections to the set, additionally adding mid
// points when the segment is the same
samplingPts.append(facePts[0]);
samplingCells.append(faceCells[0]);
samplingFaces.append(faceFaces[0]);
samplingSegments.append(faceSegments[0]);
samplingCurveDist.append(faceCurveDist[0]);
for (label facei = 1; facei < facePts.size(); ++ facei)
{
lineCellSet::calcMidPointSample
(
mesh(),
samplingPts.last(),
samplingFaces.last(),
samplingSegments.last(),
samplingCurveDist.last(),
facePts[facei],
faceFaces[facei],
faceSegments[facei],
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.append(facePts[facei]);
samplingCells.append(faceCells[facei]);
samplingFaces.append(faceFaces[facei]);
samplingSegments.append(faceSegments[facei]);
samplingCurveDist.append(faceCurveDist[facei]);
}
}
void Foam::lineCellFaceSet::genSamples()
{
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lineCellFaceSet::lineCellFaceSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
start_(dict.lookup("start")),
end_(dict.lookup("end"))
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::lineCellFaceSet::lineCellFaceSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
)
:
sampledSet(name, mesh, searchEngine, axis),
start_(start),
end_(end)
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::lineCellFaceSet::~lineCellFaceSet()
{}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,63 +22,66 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::circleSet Foam::lineCellFaceSet
Description Description
Samples along a circular path Face-intersections along a line, plus cell-samples at the mid-points
in-between
Usage
\table
Property | Description | Req'd? | Default
start | The start point of the line | yes |
end | The end point of the line | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type lineCellFace;
start (0.55 0.6 0.5);
end (0.55 -0.3 -0.1);
axis x;
}
\endverbatim
SourceFiles SourceFiles
circleSet.C lineCellFaceSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef circleSet_H #ifndef lineCellFaceSet_H
#define circleSet_H #define lineCellFaceSet_H
#include "sampledSet.H" #include "lineCellSet.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declaration of classes
class meshSearch;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class circleSet Declaration Class lineCellFaceSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class circleSet class lineCellFaceSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
// Circle definition //- Start point
const point start_;
//- Origin (x, y, z) in global cartesian co-ordinates //- End point
point origin_; const point end_;
//- Axis of the circle
vector circleAxis_;
//- Point on circle (x, y, z) in global cartesian co-ordinates
// Defines start point
point startPoint_;
// Sampling definition
//- Sampling interval in degrees about the origin
scalar dTheta_;
// Private Member Functions // Private Member Functions
//- Samples all points in sampleCoords. //- Calculate all the sampling points
void calcSamples virtual void calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells, DynamicList<label>& samplingCells,
@ -87,32 +90,20 @@ class circleSet
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const; ) const;
//- Uses calcSamples to obtain samples. Copies them into *this. //- Uses calcSamples to obtain samples and copies them into *this
void genSamples(); void genSamples();
public: public:
//- Runtime type information //- Runtime type information
TypeName("circle"); TypeName("lineCellFace");
// Constructors // Constructors
//- Construct from components
circleSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& origin,
const vector& circleAxis,
const point& startPoint,
const scalar dTheta
);
//- Construct from dictionary //- Construct from dictionary
circleSet lineCellFaceSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -120,16 +111,20 @@ public:
const dictionary& dict const dictionary& dict
); );
//- Construct from components
// Destructor lineCellFaceSet
(
virtual ~circleSet(); const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
);
// Member Functions //- Destructor
virtual ~lineCellFaceSet();
//- Get reference point
virtual point getRefPoint(const List<point>&) const;
}; };

View File

@ -0,0 +1,251 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "lineFaceSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(lineFaceSet, 0);
addToRunTimeSelectionTable(sampledSet, lineFaceSet, word);
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::lineFaceSet::calcSamples
(
const polyMesh& mesh,
const meshSearch& searchEngine,
const vector& start,
const vector& end,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
)
{
// Test for an inward pointing first hit. If this exists, then the start
// point is outside, and the sampling should begin from the hit.
label bHitI = -1;
const List<pointIndexHit> bHits =
searchEngine.intersections(start, end);
if (bHits.size())
{
const label bFaceI = bHits[0].index();
const vector bNormal = normalised(mesh.faceAreas()[bFaceI]);
const scalar bDot = bNormal & (end - start);
if (bDot < 0)
{
bHitI = 0;
}
}
// If an initial inward pointing hit was not found then initialise the
// within the cell containing the start point
vector startPt = vector::max;
label startFaceI = -1, startCellI = -1;
if (bHitI == -1)
{
startPt = start;
startFaceI = -1;
startCellI = searchEngine.findCell(start);
}
// If neither hits nor a containing cell for the start point were found then
// the line is completely outside the mesh. Return without generating any
// sampling points.
if (bHits.size() == 0 && startCellI == -1)
{
return;
}
// If nothing is set by now then something has gone wrong
if (bHitI == -1 && startCellI == -1)
{
FatalErrorInFunction
<< "The initial location for the line " << start << " to " << end
<< "could not be found" << exit(FatalError);
}
// Loop over the hits, starting a new segment at every second hit
for
(
label sampleSegmentI = 0;
bHitI < bHits.size();
bHitI += 2, sampleSegmentI += 1
)
{
// Set the start point and topology, unless starting within a cell
if (bHitI != -1)
{
startPt = bHits[bHitI].hitPoint();
startFaceI = bHits[bHitI].index();
startCellI = mesh.faceOwner()[startFaceI];
}
// Create a particle. If we are starting on a boundary face, track
// backwards into it so that the particle has the correct topology.
passiveParticle sampleParticle(mesh, startPt, startCellI);
if (startFaceI != -1)
{
sampleParticle.track(start - end, 0);
if (!sampleParticle.onBoundaryFace())
{
FatalErrorInFunction
<< exit(FatalError);
}
}
// Track until a boundary is hit, appending the face intersections to
// the lists of samples
while (true)
{
const point pt = sampleParticle.position();
const scalar dist = mag(pt - start);
const bool first =
samplingSegments.size() == 0
|| samplingSegments.last() != sampleSegmentI;
if (sampleParticle.onFace())
{
samplingPts.append(pt);
samplingCells.append(sampleParticle.cell());
samplingFaces.append(sampleParticle.face());
samplingSegments.append(sampleSegmentI);
samplingCurveDist.append(dist);
}
const vector s = (1 - dist/mag(end - start))*(end - start);
if
(
(!first && sampleParticle.onBoundaryFace())
|| sampleParticle.trackToCell(s, 0) == 0
)
{
break;
}
}
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::lineFaceSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
calcSamples
(
mesh(),
searchEngine(),
start_,
end_,
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
void Foam::lineFaceSet::genSamples()
{
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lineFaceSet::lineFaceSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
start_(dict.lookup("start")),
end_(dict.lookup("end"))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::lineFaceSet::~lineFaceSet()
{}
// ************************************************************************* //

View File

@ -22,18 +22,36 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::polyLineSet Foam::lineFaceSet
Description Description
Sample along poly line defined by a list of points (knots) Face-intersections along a line
Usage
\table
Property | Description | Req'd? | Default
start | The start point of the line | yes |
end | The end point of the line | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type lineFace;
start (0.6 0.6 0.5);
end (0.6 -0.3 -0.1);
axis x;
}
\endverbatim
SourceFiles SourceFiles
polyLineSet.C lineFaceSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef polyLineSet_H #ifndef lineFaceSet_H
#define polyLineSet_H #define lineFaceSet_H
#include "sampledSet.H" #include "sampledSet.H"
#include "DynamicList.H" #include "DynamicList.H"
@ -45,37 +63,25 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class polyLineSet Declaration Class lineFaceSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class polyLineSet class lineFaceSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
//- Sampling points //- Start point
List<point> sampleCoords_; const point start_;
//- End point
const point end_;
// Private Member Functions // Protected Member Functions
//- Sample till hits boundary. Called with singleParticle at position //- Calculate all the sampling points
// in between sampleCoords_[sampleI] and sampleCoords_[sampleI+1].
// Returns false if end of samples reached.
bool trackToBoundary
(
passiveParticleCloud& particleCloud,
passiveParticle& singleParticle,
label& sampleI,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<scalar>& samplingCurveDist
) const;
//- Samples all point in sampleCoords_
// samplingSegments contains segmentNo for each sample.
void calcSamples void calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
@ -85,37 +91,37 @@ class polyLineSet
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const; ) const;
//- Uses calcSamples to obtain samples. Copies them into *this. //- Uses calcSamples to obtain samples and copies them into *this
void genSamples(); void genSamples();
public: public:
//- Runtime type information //- Runtime type information
TypeName("polyLine"); TypeName("lineFace");
// Static data // Static Member Functions
//- Tolerance when comparing points relative to difference between //- Calculate all the sampling points
// start_ and end_ static void calcSamples
static const scalar tol; (
const polyMesh& mesh,
const meshSearch& searchEngine,
const vector& start,
const vector& end,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
);
// Constructors // Constructors
//- Construct from components
polyLineSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const List<point>& samplePoints
);
//- Construct from dictionary //- Construct from dictionary
polyLineSet lineFaceSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -125,7 +131,7 @@ public:
//- Destructor //- Destructor
virtual ~polyLineSet(); virtual ~lineFaceSet();
}; };

View File

@ -0,0 +1,158 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "lineUniformSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(lineUniformSet, 0);
addToRunTimeSelectionTable(sampledSet, lineUniformSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::lineUniformSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
label sampleSegmentI = 0, sampleI = 0;
scalar sampleT = 0;
while (sampleI < nPoints_)
{
const point pt = (1 - sampleT)*start_ + sampleT*end_;
const label sampleCellI = searchEngine().findCell(pt);
if (sampleCellI == -1)
{
if (++ sampleI < nPoints_)
{
sampleT = scalar(sampleI)/(nPoints_ - 1);
}
}
else
{
passiveParticle sampleParticle(mesh(), pt, sampleCellI);
do
{
samplingPts.append(sampleParticle.position());
samplingCells.append(sampleParticle.cell());
samplingFaces.append(-1);
samplingSegments.append(sampleSegmentI);
samplingCurveDist.append(sampleT*mag(end_ - start_));
if (++ sampleI < nPoints_)
{
sampleT = scalar(sampleI)/(nPoints_ - 1);
sampleParticle.track((end_ - start_)/(nPoints_ - 1), 0);
}
}
while (sampleI < nPoints_ && !sampleParticle.onBoundaryFace());
++ sampleSegmentI;
}
}
}
void Foam::lineUniformSet::genSamples()
{
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lineUniformSet::lineUniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
start_(dict.lookup("start")),
end_(dict.lookup("end")),
nPoints_(readLabel(dict.lookup("nPoints")))
{
genSamples();
if (debug)
{
write(Pout);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::lineUniformSet::~lineUniformSet()
{}
// ************************************************************************* //

View File

@ -0,0 +1,135 @@
/*---------------------------------------------------------------------------* \
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::lineUniformSet
Description
Uniform samples along a line
Usage
\table
Property | Description | Req'd? | Default
start | The start point of the line | yes |
end | The end point of the line | yes |
nPoints | The number of points | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type lineUniform;
start (0.65 0.3 0.3);
end (0.65 -0.3 -0.1);
nPoints 200;
axis x;
}
\endverbatim
SourceFiles
lineUniformSet.C
\*---------------------------------------------------------------------------*/
#ifndef lineUniformSet_H
#define lineUniformSet_H
#include "passiveParticleCloud.H"
#include "sampledSet.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class lineUniformSet Declaration
\*---------------------------------------------------------------------------*/
class lineUniformSet
:
public sampledSet
{
// Private data
//- Starting point
const point start_;
//- End point
const point end_;
//- Number of points
const label nPoints_;
// Private Member Functions
//- Samples from start_ to end_. samplingSegments contains segmentNo
// for each sample.
void calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const;
//- Uses calcSamples to obtain samples. Copies them into *this.
void genSamples();
public:
//- Runtime type information
TypeName("lineUniform");
// Constructors
//- Construct from dictionary
lineUniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
);
//- Destructor
virtual ~lineUniformSet();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,150 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "midPointSet.H"
#include "polyMesh.H"
#include "meshSearch.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(midPointSet, 0);
addToRunTimeSelectionTable(sampledSet, midPointSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::midPointSet::genSamples()
{
// Generate midpoints.
List<point> midPoints(2*size());
labelList midCells(2*size());
labelList midSegments(2*size());
scalarList midCurveDist(2*size());
label mSamplei = 0;
label samplei = 0;
while (size() > 0)
{
// Calculate midpoint between samplei and samplei+1 (if in same segment)
while
(
(samplei < size() - 1)
&& (segments_[samplei] == segments_[samplei+1])
)
{
point midPoint(0.5*(operator[](samplei) + operator[](samplei+1)));
label cellm = pointInCell(midPoint, samplei);
if (cellm != -1)
{
midPoints[mSamplei] = midPoint;
midCells[mSamplei] = cellm;
midSegments[mSamplei] = segments_[samplei];
midCurveDist[mSamplei] = mag(midPoints[mSamplei] - start());
mSamplei++;
}
samplei++;
}
if (samplei == size() - 1)
{
break;
}
samplei++;
}
midPoints.setSize(mSamplei);
midCells.setSize(mSamplei);
midSegments.setSize(mSamplei);
midCurveDist.setSize(mSamplei);
setSamples
(
midPoints,
midCells,
labelList(midCells.size(), -1),
midSegments,
midCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::midPointSet::midPointSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
)
:
faceOnlySet(name, mesh, searchEngine, axis, start, end)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::midPointSet::midPointSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
faceOnlySet(name, mesh, searchEngine, dict)
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::midPointSet::~midPointSet()
{}
// ************************************************************************* //

View File

@ -1,102 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::midPointSet
Description
SourceFiles
midPointSet.C
\*---------------------------------------------------------------------------*/
#ifndef midPointSet_H
#define midPointSet_H
#include "faceOnlySet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class meshSearch;
/*---------------------------------------------------------------------------*\
Class midPointSet Declaration
\*---------------------------------------------------------------------------*/
class midPointSet
:
public faceOnlySet
{
// Private Member Functions
void genSamples();
public:
//- Runtime type information
TypeName("midPoint");
// Constructors
//- Construct from components
midPointSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
);
//- Construct from dictionary
midPointSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
);
//- Destructor
virtual ~midPointSet();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,170 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "midPointAndFaceSet.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(midPointAndFaceSet, 0);
addToRunTimeSelectionTable(sampledSet, midPointAndFaceSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::midPointAndFaceSet::genSamples()
{
// Generate midpoints and add to face points
List<point> mpfSamplePoints(3*size());
labelList mpfSampleCells(3*size());
labelList mpfSampleFaces(3*size());
labelList mpfSampleSegments(3*size());
scalarList mpfSampleCurveDist(3*size());
label mpfSamplei = 0;
label samplei = 0;
while (size() > 0)
{
// Add first face
mpfSamplePoints[mpfSamplei] = operator[](samplei);
mpfSampleCells[mpfSamplei] = cells_[samplei];
mpfSampleFaces[mpfSamplei] = faces_[samplei];
mpfSampleSegments[mpfSamplei] = segments_[samplei];
mpfSampleCurveDist[mpfSamplei] = curveDist_[samplei];
mpfSamplei++;
while
(
(samplei < size() - 1)
&& (segments_[samplei] == segments_[samplei+1])
)
{
point midPoint(0.5*(operator[](samplei) + operator[](samplei+1)));
label cellm = pointInCell(midPoint, samplei);
if (cellm != -1)
{
mpfSamplePoints[mpfSamplei] = midPoint;
mpfSampleCells[mpfSamplei] = cellm;
mpfSampleFaces[mpfSamplei] = -1;
mpfSampleSegments[mpfSamplei] = segments_[samplei];
mpfSampleCurveDist[mpfSamplei] =
mag(mpfSamplePoints[mpfSamplei] - start());
mpfSamplei++;
}
// Add second face
mpfSamplePoints[mpfSamplei] = operator[](samplei+1);
mpfSampleCells[mpfSamplei] = cells_[samplei+1];
mpfSampleFaces[mpfSamplei] = faces_[samplei+1];
mpfSampleSegments[mpfSamplei] = segments_[samplei+1];
mpfSampleCurveDist[mpfSamplei] =
mag(mpfSamplePoints[mpfSamplei] - start());
mpfSamplei++;
samplei++;
}
if (samplei == size() - 1)
{
break;
}
samplei++;
}
mpfSamplePoints.setSize(mpfSamplei);
mpfSampleCells.setSize(mpfSamplei);
mpfSampleFaces.setSize(mpfSamplei);
mpfSampleSegments.setSize(mpfSamplei);
mpfSampleCurveDist.setSize(mpfSamplei);
setSamples
(
mpfSamplePoints,
mpfSampleCells,
mpfSampleFaces,
mpfSampleSegments,
mpfSampleCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::midPointAndFaceSet::midPointAndFaceSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
)
:
faceOnlySet(name, mesh, searchEngine, axis, start, end)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::midPointAndFaceSet::midPointAndFaceSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
faceOnlySet(name, mesh, searchEngine, dict)
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::midPointAndFaceSet::~midPointAndFaceSet()
{}
// ************************************************************************* //

View File

@ -1,103 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::midPointAndFaceSet
Description
SourceFiles
midPointAndFaceSet.C
\*---------------------------------------------------------------------------*/
#ifndef midPointAndFaceSet_H
#define midPointAndFaceSet_H
#include "faceOnlySet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class meshSearch;
/*---------------------------------------------------------------------------*\
Class midPointAndFaceSet Declaration
\*---------------------------------------------------------------------------*/
class midPointAndFaceSet
:
public faceOnlySet
{
// Private Member Functions
void genSamples();
public:
//- Runtime type information
TypeName("midPointAndFace");
// Constructors
//- Construct from components
midPointAndFaceSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end
);
//- Construct from dictionary
midPointAndFaceSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
);
//- Destructor
virtual ~midPointAndFaceSet();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,239 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "patchSeedSet.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "treeBoundBox.H"
#include "treeDataFace.H"
#include "Time.H"
#include "meshTools.H"
//#include "Random.H"
// For 'facePoint' helper function only
#include "mappedPatchBase.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(patchSeedSet, 0);
addToRunTimeSelectionTable(sampledSet, patchSeedSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::patchSeedSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
)
{
if (debug)
{
Info<< "patchSeedSet : sampling on patches :" << endl;
}
// Construct search tree for all patch faces.
label sz = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
{
const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
sz += pp.size();
if (debug)
{
Info<< " " << pp.name() << " size " << pp.size() << endl;
}
}
labelList patchFaces(sz);
sz = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
{
const polyPatch& pp = mesh().boundaryMesh()[iter.key()];
forAll(pp, i)
{
patchFaces[sz++] = pp.start()+i;
}
}
label totalSize = returnReduce(sz, sumOp<label>());
// Shuffle and truncate if in random mode
if (maxPoints_ < totalSize)
{
// Check what fraction of maxPoints_ I need to generate locally.
label myMaxPoints = label(scalar(sz)/totalSize*maxPoints_);
rndGenPtr_.reset(new Random(123456));
Random& rndGen = rndGenPtr_();
labelList subset = identity(sz);
for (label iter = 0; iter < 4; iter++)
{
forAll(subset, i)
{
label j = rndGen.sampleAB<label>(0, subset.size());
Swap(subset[i], subset[j]);
}
}
// Truncate
subset.setSize(myMaxPoints);
// Subset patchFaces
patchFaces = UIndirectList<label>(patchFaces, subset)();
if (debug)
{
Pout<< "In random mode : selected " << patchFaces.size()
<< " faces out of " << sz << endl;
}
}
// Get points on patchFaces.
globalIndex globalSampleNumbers(patchFaces.size());
samplingPts.setCapacity(patchFaces.size());
samplingCells.setCapacity(patchFaces.size());
samplingFaces.setCapacity(patchFaces.size());
samplingSegments.setCapacity(patchFaces.size());
samplingCurveDist.setCapacity(patchFaces.size());
// For calculation of min-decomp tet base points
(void)mesh().tetBasePtIs();
forAll(patchFaces, i)
{
label facei = patchFaces[i];
pointIndexHit info = mappedPatchBase::facePoint
(
mesh(),
facei,
polyMesh::FACE_DIAG_TRIS
);
label celli = mesh().faceOwner()[facei];
if (info.hit())
{
// Move the point into the cell
const point& cc = mesh().cellCentres()[celli];
samplingPts.append
(
info.hitPoint() + 1e-1*(cc-info.hitPoint())
);
}
else
{
samplingPts.append(info.rawPoint());
}
samplingCells.append(celli);
samplingFaces.append(facei);
samplingSegments.append(0);
samplingCurveDist.append(globalSampleNumbers.toGlobal(i));
}
}
void Foam::patchSeedSet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::patchSeedSet::patchSeedSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
patchSet_
(
mesh.boundaryMesh().patchSet
(
wordReList(dict.lookup("patches"))
)
),
// searchDist_(readScalar(dict.lookup("maxDistance"))),
// offsetDist_(readScalar(dict.lookup("offsetDist"))),
maxPoints_(readLabel(dict.lookup("maxPoints")))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::patchSeedSet::~patchSeedSet()
{}
// ************************************************************************* //

View File

@ -0,0 +1,200 @@
/*---------------------------------------------------------------------------* \
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pointsSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pointsSet, 0);
addToRunTimeSelectionTable(sampledSet, pointsSet, word);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::pointsSet::calcSamplesUnordered
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
forAll(points_, i)
{
const point& pt = points_[i];
const label celli = searchEngine().findCell(pt);
if (celli != -1)
{
samplingPts.append(pt);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingSegments.append(samplingSegments.size());
samplingCurveDist.append(scalar(i));
}
}
}
void Foam::pointsSet::calcSamplesOrdered
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
const label n = points_.size();
label sampleSegmentI = 0;
label sampleI = 0;
scalar sampleDist = 0;
while (sampleI < n)
{
const point pt = points_[sampleI];
const label sampleCellI = searchEngine().findCell(pt);
if (sampleCellI == -1)
{
if (++ sampleI < n)
{
sampleDist += mag(points_[sampleI] - points_[sampleI - 1]);
}
}
else
{
passiveParticle sampleParticle(mesh(), pt, sampleCellI);
do
{
samplingPts.append(sampleParticle.position());
samplingCells.append(sampleParticle.cell());
samplingFaces.append(-1);
samplingSegments.append(sampleSegmentI);
samplingCurveDist.append(sampleDist);
if (++ sampleI < n)
{
const vector s = points_[sampleI] - points_[sampleI - 1];
sampleDist += mag(s);
sampleParticle.track(s, 0);
}
}
while (sampleI < n && !sampleParticle.onBoundaryFace());
++ sampleSegmentI;
}
}
}
void Foam::pointsSet::genSamples()
{
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
if (!ordered_)
{
calcSamplesUnordered
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
else
{
calcSamplesOrdered
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pointsSet::pointsSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
points_(dict.lookup("points")),
ordered_(dict.lookup("ordered"))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::pointsSet::~pointsSet()
{}
// ************************************************************************* //

View File

@ -22,21 +22,54 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::uniformSet Foam::pointsSet
Description Description
Specified point samples. Optionally ordered into a continuous path.
Ordering is an optimisation; it enables tracking from one point to the
next. If ordering is off, each point is searched for individually.
Usage
\table
Property | Description | Req'd? | Default
points | The points to sample | yes |
ordered | Are the points in order? | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type points;
points
(
(0.95 0 0.25)
(0.951251 0 0.250119)
(0.952468 0 0.250473)
(0.953618 0 0.251057)
(0.954669 0 0.251859)
(0.95559 0 0.252865)
(0.956353 0 0.254057)
(0.956931 0 0.255413)
(0.9573 0 0.256908)
(0.957441 0 0.258513)
);
ordered yes;
axis x;
}
\endverbatim
SourceFiles SourceFiles
uniformSet.C pointsSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef uniformSet_H #ifndef pointsSet_H
#define uniformSet_H #define pointsSet_H
#include "passiveParticleCloud.H"
#include "sampledSet.H" #include "sampledSet.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "passiveParticleCloud.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -44,57 +77,26 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class uniformSet Declaration Class pointsSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class uniformSet class pointsSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
//- Starting point //- Sampling points
point start_; const List<point> points_;
//- End point //- Do the points form an ordered sequence?
point end_; const Switch ordered_;
//- Number of points
label nPoints_;
// Private Member Functions // Private Member Functions
//- Calculates - starting at samplePt - the first sampling point //- Calculate all the sampling points
// on or after currentPt. smallDist is the tolerance used to compare void calcSamplesUnordered
// positions. Returns false if end of samples reached.
bool nextSample
(
const point& currentPt,
const vector& offset,
const scalar smallDist,
point& samplePt,
label& sampleI
) const;
//- Samples from startTrackPt/Celli. Updates particle/samplePt/sampleI
// and puts
// samples in the DynamicLists. Returns false if end of all samples
// reached
bool trackToBoundary
(
passiveParticleCloud& particleCloud,
passiveParticle& singleParticle,
point& samplePt,
label& sampleI,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<scalar>& samplingCurveDist
) const;
//- Samples from start_ to end_. samplingSegments contains segmentNo
// for each sample.
void calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells, DynamicList<label>& samplingCells,
@ -103,39 +105,30 @@ class uniformSet
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const; ) const;
//- Uses calcSamples to obtain samples. Copies them into *this. //- Calculate all the sampling points
void calcSamplesOrdered
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const;
//- Uses calcSamples to obtain samples and copies them into *this
void genSamples(); void genSamples();
public: public:
//- Runtime type information //- Runtime type information
TypeName("uniform"); TypeName("points");
// Static data
//- Tolerance when comparing points relative to difference between
// start_ and end_
static const scalar tol;
// Constructors // Constructors
//- Construct from components
uniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end,
const label nPoints
);
//- Construct from dictionary //- Construct from dictionary
uniformSet pointsSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -145,7 +138,7 @@ public:
//- Destructor //- Destructor
virtual ~uniformSet(); virtual ~pointsSet();
}; };

View File

@ -1,387 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "polyLineSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(polyLineSet, 0);
addToRunTimeSelectionTable(sampledSet, polyLineSet, word);
const scalar polyLineSet::tol = 1e-6;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::polyLineSet::trackToBoundary
(
passiveParticleCloud& particleCloud,
passiveParticle& singleParticle,
label& sampleI,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<scalar>& samplingCurveDist
) const
{
while (true)
{
// Local geometry info
const vector offset = sampleCoords_[sampleI+1] - sampleCoords_[sampleI];
const scalar smallDist = mag(tol*offset);
singleParticle.track(offset, 0);
const point trackPt = singleParticle.position();
if (singleParticle.onBoundaryFace())
{
// Info<< "trackToBoundary : reached boundary"
// << " trackPt:" << trackPt << endl;
if
(
mag(trackPt - sampleCoords_[sampleI+1])
< smallDist
)
{
// Reached samplePt on boundary
// Info<< "trackToBoundary : boundary. also sampling."
// << " trackPt:" << trackPt << " sampleI+1:" << sampleI+1
// << endl;
samplingPts.append(trackPt);
samplingCells.append(singleParticle.cell());
samplingFaces.append(singleParticle.face());
// trackPt is at sampleI+1
samplingCurveDist.append(1.0*(sampleI+1));
}
return true;
}
// Reached samplePt in cell
samplingPts.append(trackPt);
samplingCells.append(singleParticle.cell());
samplingFaces.append(-1);
// Convert trackPt to fraction in between sampleI and sampleI+1
scalar dist =
mag(trackPt - sampleCoords_[sampleI])
/ mag(sampleCoords_[sampleI+1] - sampleCoords_[sampleI]);
samplingCurveDist.append(sampleI + dist);
// go to next samplePt
sampleI++;
if (sampleI == sampleCoords_.size() - 1)
{
// no more samples.
// Info<< "trackToBoundary : Reached end : sampleI now:" << sampleI
// << endl;
return false;
}
}
}
void Foam::polyLineSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
// Check sampling points
if (sampleCoords_.size() < 2)
{
FatalErrorInFunction
<< "Incorrect sample specification. Too few points:"
<< sampleCoords_ << exit(FatalError);
}
point oldPoint = sampleCoords_[0];
for (label sampleI = 1; sampleI < sampleCoords_.size(); sampleI++)
{
if (mag(sampleCoords_[sampleI] - oldPoint) < small)
{
FatalErrorInFunction
<< "Incorrect sample specification."
<< " Point " << sampleCoords_[sampleI-1]
<< " at position " << sampleI-1
<< " and point " << sampleCoords_[sampleI]
<< " at position " << sampleI
<< " are too close" << exit(FatalError);
}
oldPoint = sampleCoords_[sampleI];
}
// Force calculation of cloud addressing on all processors
const bool oldMoving = const_cast<polyMesh&>(mesh()).moving(false);
passiveParticleCloud particleCloud(mesh());
// current segment number
label segmentI = 0;
// starting index of current segment in samplePts
label startSegmentI = 0;
label sampleI = 0;
point lastSample(great, great, great);
while (true)
{
// Get boundary intersection
point trackPt;
label trackCelli = -1;
label trackFacei = -1;
do
{
const vector offset =
sampleCoords_[sampleI+1] - sampleCoords_[sampleI];
const scalar smallDist = mag(tol*offset);
// Get all boundary intersections
List<pointIndexHit> bHits = searchEngine().intersections
(
sampleCoords_[sampleI],
sampleCoords_[sampleI+1]
);
point bPoint(great, great, great);
label bFacei = -1;
if (bHits.size())
{
bPoint = bHits[0].hitPoint();
bFacei = bHits[0].index();
}
// Get tracking point
bool isSample =
getTrackingPoint
(
sampleCoords_[sampleI],
bPoint,
bFacei,
smallDist,
trackPt,
trackCelli,
trackFacei
);
if (isSample && (mag(lastSample - trackPt) > smallDist))
{
// Info<< "calcSamples : getTrackingPoint returned valid sample"
// << " trackPt:" << trackPt
// << " trackFacei:" << trackFacei
// << " trackCelli:" << trackCelli
// << " sampleI:" << sampleI
// << " dist:" << dist
// << endl;
samplingPts.append(trackPt);
samplingCells.append(trackCelli);
samplingFaces.append(trackFacei);
// Convert sampling position to unique curve parameter. Get
// fraction of distance between sampleI and sampleI+1.
scalar dist =
mag(trackPt - sampleCoords_[sampleI])
/ mag(sampleCoords_[sampleI+1] - sampleCoords_[sampleI]);
samplingCurveDist.append(sampleI + dist);
lastSample = trackPt;
}
if (trackCelli == -1)
{
// No intersection found. Go to next point
sampleI++;
}
} while ((trackCelli == -1) && (sampleI < sampleCoords_.size() - 1));
if (sampleI == sampleCoords_.size() - 1)
{
// Info<< "calcSamples : Reached end of samples: "
// << " sampleI now:" << sampleI
// << endl;
break;
}
//
// Segment sampleI .. sampleI+1 intersected by domain
//
// Initialize tracking starting from sampleI
passiveParticle singleParticle
(
mesh(),
trackPt,
trackCelli
);
bool bReached = trackToBoundary
(
particleCloud,
singleParticle,
sampleI,
samplingPts,
samplingCells,
samplingFaces,
samplingCurveDist
);
// fill sampleSegments
for (label i = samplingPts.size() - 1; i >= startSegmentI; --i)
{
samplingSegments.append(segmentI);
}
if (!bReached)
{
// Info<< "calcSamples : Reached end of samples: "
// << " sampleI now:" << sampleI
// << endl;
break;
}
lastSample = singleParticle.position();
// Find next boundary.
sampleI++;
if (sampleI == sampleCoords_.size() - 1)
{
// Info<< "calcSamples : Reached end of samples: "
// << " sampleI now:" << sampleI
// << endl;
break;
}
segmentI++;
startSegmentI = samplingPts.size();
}
const_cast<polyMesh&>(mesh()).moving(oldMoving);
}
void Foam::polyLineSet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polyLineSet::polyLineSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const List<point>& sampleCoords
)
:
sampledSet(name, mesh, searchEngine, axis),
sampleCoords_(sampleCoords)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::polyLineSet::polyLineSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
sampleCoords_(dict.lookup("points"))
{
genSamples();
if (debug)
{
write(Info);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::polyLineSet::~polyLineSet()
{}
// ************************************************************************* //

View File

@ -25,10 +25,8 @@ License
#include "sampledSet.H" #include "sampledSet.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H"
#include "meshSearch.H" #include "meshSearch.H"
#include "writer.H" #include "writer.H"
#include "particle.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -41,322 +39,6 @@ namespace Foam
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::label Foam::sampledSet::getBoundaryCell(const label facei) const
{
return mesh().faceOwner()[facei];
}
Foam::label Foam::sampledSet::getNeighbourCell(const label facei) const
{
if (facei >= mesh().nInternalFaces())
{
return mesh().faceOwner()[facei];
}
else
{
return mesh().faceNeighbour()[facei];
}
}
Foam::label Foam::sampledSet::pointInCell
(
const point& p,
const label samplei
) const
{
// Collect the face owner and neighbour cells of the sample into an array
// for convenience
label cells[4] =
{
mesh().faceOwner()[faces_[samplei]],
getNeighbourCell(faces_[samplei]),
mesh().faceOwner()[faces_[samplei+1]],
getNeighbourCell(faces_[samplei+1])
};
// Find the sampled cell by checking the owners and neighbours of the
// sampled faces
label cellm =
(cells[0] == cells[2] || cells[0] == cells[3]) ? cells[0]
: (cells[1] == cells[2] || cells[1] == cells[3]) ? cells[1]
: -1;
if (cellm != -1)
{
// If found the sampled cell check the point is in the cell
// otherwise ignore
if (!mesh().pointInCell(p, cellm, searchEngine_.decompMode()))
{
cellm = -1;
if (debug)
{
WarningInFunction
<< "Could not find mid-point " << p
<< " cell " << cellm << endl;
}
}
}
else
{
// If the sample does not pass through a single cell check if the point
// is in any of the owners or neighbours otherwise ignore
for (label i=0; i<4; i++)
{
if (mesh().pointInCell(p, cells[i], searchEngine_.decompMode()))
{
return cells[i];
}
}
if (debug)
{
WarningInFunction
<< "Could not find cell for mid-point" << nl
<< " samplei: " << samplei
<< " pts[samplei]: " << operator[](samplei)
<< " face[samplei]: " << faces_[samplei]
<< " pts[samplei+1]: " << operator[](samplei+1)
<< " face[samplei+1]: " << faces_[samplei+1]
<< " cellio: " << cells[0]
<< " cellin: " << cells[1]
<< " celljo: " << cells[2]
<< " celljn: " << cells[3]
<< endl;
}
}
return cellm;
}
Foam::scalar Foam::sampledSet::calcSign
(
const label facei,
const point& sample
) const
{
vector vec = sample - mesh().faceCentres()[facei];
scalar magVec = mag(vec);
if (magVec < vSmall)
{
// Sample on face centre. Regard as inside
return -1;
}
vec /= magVec;
vector n = mesh().faceAreas()[facei];
n /= mag(n) + vSmall;
return n & vec;
}
Foam::label Foam::sampledSet::findNearFace
(
const label celli,
const point& sample,
const scalar smallDist
) const
{
const cell& myFaces = mesh().cells()[celli];
forAll(myFaces, myFacei)
{
const face& f = mesh().faces()[myFaces[myFacei]];
pointHit inter = f.nearestPoint(sample, mesh().points());
scalar dist;
if (inter.hit())
{
dist = mag(inter.hitPoint() - sample);
}
else
{
dist = mag(inter.missPoint() - sample);
}
if (dist < smallDist)
{
return myFaces[myFacei];
}
}
return -1;
}
Foam::point Foam::sampledSet::pushIn
(
const point& facePt,
const label facei
) const
{
label celli = mesh().faceOwner()[facei];
const point& cC = mesh().cellCentres()[celli];
point newPosition = facePt;
// Taken from particle::initCellFacePt()
label tetFacei;
label tetPtI;
mesh().findTetFacePt(celli, facePt, tetFacei, tetPtI);
// This is the tolerance that was defined as a static constant of the
// particle class. It is no longer used by particle, following the switch to
// barycentric tracking. The only place in which the tolerance is now used
// is here. I'm not sure what the purpose of this code is, but it probably
// wants removing. It is doing tet-searches for a particle position. This
// should almost certainly be left to the particle class.
const scalar trackingCorrectionTol = 1e-5;
if (tetFacei == -1 || tetPtI == -1)
{
newPosition = facePt;
label trap(1.0/trackingCorrectionTol + 1);
label iterNo = 0;
do
{
newPosition += trackingCorrectionTol*(cC - facePt);
mesh().findTetFacePt
(
celli,
newPosition,
tetFacei,
tetPtI
);
iterNo++;
} while (tetFacei < 0 && iterNo <= trap);
}
if (tetFacei == -1)
{
FatalErrorInFunction
<< "After pushing " << facePt << " to " << newPosition
<< " it is still outside face " << facei
<< " at " << mesh().faceCentres()[facei]
<< " of cell " << celli
<< " at " << cC << endl
<< "Please change your starting point"
<< abort(FatalError);
}
return newPosition;
}
bool Foam::sampledSet::getTrackingPoint
(
const point& samplePt,
const point& bPoint,
const label bFacei,
const scalar smallDist,
point& trackPt,
label& trackCelli,
label& trackFacei
) const
{
bool isGoodSample = false;
if (bFacei == -1)
{
// No boundary intersection. Try and find cell samplePt is in
trackCelli = mesh().findCell(samplePt, searchEngine_.decompMode());
if
(
(trackCelli == -1)
|| !mesh().pointInCell
(
samplePt,
trackCelli,
searchEngine_.decompMode()
)
)
{
// Line samplePt - end_ does not intersect domain at all.
// (or is along edge)
trackCelli = -1;
trackFacei = -1;
isGoodSample = false;
}
else
{
// Start is inside. Use it as tracking point
trackPt = samplePt;
trackFacei = -1;
isGoodSample = true;
}
}
else if (mag(samplePt - bPoint) < smallDist)
{
// samplePt close to bPoint. Snap to it
trackPt = pushIn(bPoint, bFacei);
trackFacei = bFacei;
trackCelli = getBoundaryCell(trackFacei);
isGoodSample = true;
}
else
{
scalar sign = calcSign(bFacei, samplePt);
if (sign < 0)
{
// samplePt inside or marginally outside.
trackPt = samplePt;
trackFacei = -1;
trackCelli = mesh().findCell(trackPt, searchEngine_.decompMode());
isGoodSample = true;
}
else
{
// samplePt outside. use bPoint
trackPt = pushIn(bPoint, bFacei);
trackFacei = bFacei;
trackCelli = getBoundaryCell(trackFacei);
isGoodSample = false;
}
}
if (debug)
{
InfoInFunction
<< " samplePt:" << samplePt
<< " bPoint:" << bPoint
<< " bFacei:" << bFacei
<< endl << " Calculated first tracking point :"
<< " trackPt:" << trackPt
<< " trackCelli:" << trackCelli
<< " trackFacei:" << trackFacei
<< " isGoodSample:" << isGoodSample
<< endl;
}
return isGoodSample;
}
void Foam::sampledSet::setSamples void Foam::sampledSet::setSamples
( (
const List<point>& samplingPts, const List<point>& samplingPts,

View File

@ -27,8 +27,8 @@ Class
Description Description
Holds list of sampling points which is filled at construction time. Holds list of sampling points which is filled at construction time.
Various implementations of this base class to e.g. get sampling points Various implementations of this base class to e.g. get sampling points
at uniform distance along a line (uniformSet) or directly specified at uniform distance along a line (lineUniformSet) or directly specified
(cloudSet) (pointsSet)
Each 'sampledSet' has a name and a specifier of how the axis should be Each 'sampledSet' has a name and a specifier of how the axis should be
write (x/y/z component or all 3 components) write (x/y/z component or all 3 components)
@ -86,52 +86,6 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Returns cell next to boundary face
label getBoundaryCell(const label) const;
//- Returns the neighbour cell or the owner if face in on the boundary
label getNeighbourCell(const label) const;
//- Return the cell in which the point on the sample line
// resides if found otherwise return -1
label pointInCell(const point& p, const label samplei) const;
//- Calculates inproduct of face normal and vector sample-face centre
// <0 if sample inside.
scalar calcSign(const label facei, const point& sample) const;
//- Returns face label (or -1) of face which is close to sample
label findNearFace
(
const label celli,
const point& sample,
const scalar smallDist
) const;
//- Moves sample in direction of -n to it is 'inside' of facei
point pushIn
(
const point& sample,
const label facei
) const;
//- Calculates start of tracking given samplePt and first boundary
// intersection
// (bPoint, bFacei) (bFacei == -1 if no boundary intersection)
// Returns true if trackPt is valid sampling point. Sets trackPt,
// trackFacei, trackCelli (-1 if no tracking point found)
bool getTrackingPoint
(
const point& samplePt,
const point& bPoint,
const label bFacei,
const scalar smallDist,
point& trackPt,
label& trackCelli,
label& trackFacei
) const;
//- Sets sample data //- Sets sample data
void setSamples void setSamples
( (

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,26 +23,28 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "cloudSet.H" #include "sphereRandomSet.H"
#include "sampledSet.H" #include "sampledSet.H"
#include "meshSearch.H" #include "meshSearch.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "word.H" #include "word.H"
#include "mathematicalConstants.H"
#include "Random.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(cloudSet, 0); defineTypeNameAndDebug(sphereRandomSet, 0);
addToRunTimeSelectionTable(sampledSet, cloudSet, word); addToRunTimeSelectionTable(sampledSet, sphereRandomSet, word);
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::cloudSet::calcSamples void Foam::sphereRandomSet::calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells, DynamicList<label>& samplingCells,
@ -51,25 +53,35 @@ void Foam::cloudSet::calcSamples
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const ) const
{ {
const meshSearch& queryMesh = searchEngine(); Random rndGen(261782);
forAll(sampleCoords_, sampleI) for (label i = 0; i < nPoints_; ++ i)
{ {
label celli = queryMesh.findCell(sampleCoords_[sampleI]); // Request all random numbers simultaneously on all processors so that
// the generator state stays consistent
vector dpt(vector::uniform(radius_));
while (magSqr(dpt) > sqr(radius_))
{
dpt = 2*radius_*(rndGen.sample01<vector>() - vector::uniform(0.5));
}
const point pt = centre_ + dpt;
const label celli = searchEngine().findCell(pt);
if (celli != -1) if (celli != -1)
{ {
samplingPts.append(sampleCoords_[sampleI]); samplingPts.append(pt);
samplingCells.append(celli); samplingCells.append(celli);
samplingFaces.append(-1); samplingFaces.append(-1);
samplingSegments.append(0); samplingSegments.append(0);
samplingCurveDist.append(1.0 * sampleI); samplingCurveDist.append(scalar(i));
} }
} }
} }
void Foam::cloudSet::genSamples() void Foam::sphereRandomSet::genSamples()
{ {
// Storage for sample points // Storage for sample points
DynamicList<point> samplingPts; DynamicList<point> samplingPts;
@ -106,28 +118,7 @@ void Foam::cloudSet::genSamples()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cloudSet::cloudSet Foam::sphereRandomSet::sphereRandomSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const List<point>& sampleCoords
)
:
sampledSet(name, mesh, searchEngine, axis),
sampleCoords_(sampleCoords)
{
genSamples();
if (debug)
{
write(Info);
}
}
Foam::cloudSet::cloudSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -136,7 +127,9 @@ Foam::cloudSet::cloudSet
) )
: :
sampledSet(name, mesh, searchEngine, dict), sampledSet(name, mesh, searchEngine, dict),
sampleCoords_(dict.lookup("points")) centre_(dict.lookup("centre")),
radius_(readScalar(dict.lookup("radius"))),
nPoints_(readLabel(dict.lookup("nPoints")))
{ {
genSamples(); genSamples();
@ -149,7 +142,7 @@ Foam::cloudSet::cloudSet
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::cloudSet::~cloudSet() Foam::sphereRandomSet::~sphereRandomSet()
{} {}

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,17 +22,38 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::cloudSet Foam::sphereRandomSet
Description Description
Random samples within a sphere
Usage
\table
Property | Description | Req'd? | Default
centre | Centre of the sphere | yes |
radius | Radius of the sphere | yes |
nPoints | The number of points | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type sphereRandom;
centre (0.95 0 0.25);
radius 0.25;
nPoints 200;
axis x;
}
\endverbatim
SourceFiles SourceFiles
cloudSet.C sphereRandomSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef cloudSet_H #ifndef sphereRandomSet_H
#define cloudSet_H #define sphereRandomSet_H
#include "sampledSet.H" #include "sampledSet.H"
#include "DynamicList.H" #include "DynamicList.H"
@ -42,27 +63,29 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes
class passiveParticle;
template<class Type> class particle;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class cloudSet Declaration Class sphereRandomSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class cloudSet class sphereRandomSet
: :
public sampledSet public sampledSet
{ {
// Private data // Private data
//- Sampling points //- Centre point
List<point> sampleCoords_; const point centre_;
//- Radius
const scalar radius_;
//- Number of points
const label nPoints_;
// Private Member Functions // Private Member Functions
//- Samples all points in sampleCoords. //- Samples all points in sampleCoords
void calcSamples void calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
@ -79,23 +102,13 @@ class cloudSet
public: public:
//- Runtime type information //- Runtime type information
TypeName("cloud"); TypeName("sphereRandom");
// Constructors // Constructors
//- Construct from components
cloudSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const List<point>& sampleCoords
);
//- Construct from dictionary //- Construct from dictionary
cloudSet sphereRandomSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -104,8 +117,9 @@ public:
); );
//- Destructor // Destructor
virtual ~cloudSet();
virtual ~sphereRandomSet();
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -23,7 +23,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "triSurfaceMeshPointSet.H" #include "triSurfaceMeshSet.H"
#include "meshSearch.H" #include "meshSearch.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "polyMesh.H" #include "polyMesh.H"
@ -35,14 +35,14 @@ License
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(triSurfaceMeshPointSet, 0); defineTypeNameAndDebug(triSurfaceMeshSet, 0);
addToRunTimeSelectionTable(sampledSet, triSurfaceMeshPointSet, word); addToRunTimeSelectionTable(sampledSet, triSurfaceMeshSet, word);
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::triSurfaceMeshPointSet::calcSamples void Foam::triSurfaceMeshSet::calcSamples
( (
DynamicList<point>& samplingPts, DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells, DynamicList<label>& samplingCells,
@ -51,23 +51,24 @@ void Foam::triSurfaceMeshPointSet::calcSamples
DynamicList<scalar>& samplingCurveDist DynamicList<scalar>& samplingCurveDist
) const ) const
{ {
forAll(sampleCoords_, sampleI) forAll(points_, i)
{ {
label celli = searchEngine().findCell(sampleCoords_[sampleI]); const point& pt = points_[i];
const label celli = searchEngine().findCell(pt);
if (celli != -1) if (celli != -1)
{ {
samplingPts.append(sampleCoords_[sampleI]); samplingPts.append(pt);
samplingCells.append(celli); samplingCells.append(celli);
samplingFaces.append(-1); samplingFaces.append(-1);
samplingSegments.append(0); samplingSegments.append(0);
samplingCurveDist.append(1.0 * sampleI); samplingCurveDist.append(scalar(i));
} }
} }
} }
void Foam::triSurfaceMeshPointSet::genSamples() void Foam::triSurfaceMeshSet::genSamples()
{ {
// Storage for sample points // Storage for sample points
DynamicList<point> samplingPts; DynamicList<point> samplingPts;
@ -104,7 +105,7 @@ void Foam::triSurfaceMeshPointSet::genSamples()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::triSurfaceMeshPointSet::triSurfaceMeshPointSet Foam::triSurfaceMeshSet::triSurfaceMeshSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -113,35 +114,26 @@ Foam::triSurfaceMeshPointSet::triSurfaceMeshPointSet
) )
: :
sampledSet(name, mesh, searchEngine, dict), sampledSet(name, mesh, searchEngine, dict),
surface_(dict.lookup("surface")) surface_(dict.lookup("surface")),
{ points_
// Load surface. (
if (mesh.time().foundObject<triSurfaceMesh>(surface_)) mesh.time().foundObject<triSurfaceMesh>(surface_)
{ ? mesh.time().lookupObject<triSurfaceMesh>(surface_).points()
// Note: should use localPoints() instead of points() but assume : triSurfaceMesh
// trisurface is compact.
sampleCoords_ = mesh.time().lookupObject<triSurfaceMesh>
(
surface_
).points();
}
else
{
sampleCoords_ = triSurfaceMesh
( (
IOobject IOobject
( (
surface_, surface_,
mesh.time().constant(), // instance mesh.time().constant(),
"triSurface", // local "triSurface",
mesh.time(), mesh.time(),
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE, IOobject::NO_WRITE,
false false
) )
).points(); ).points()
} )
{
genSamples(); genSamples();
if (debug) if (debug)
@ -153,25 +145,8 @@ Foam::triSurfaceMeshPointSet::triSurfaceMeshPointSet
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::triSurfaceMeshPointSet::~triSurfaceMeshPointSet() Foam::triSurfaceMeshSet::~triSurfaceMeshSet()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::triSurfaceMeshPointSet::getRefPoint(const List<point>& pts)
const
{
if (pts.size())
{
// Use first samplePt as starting point
return pts[0];
}
else
{
return Zero;
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -22,18 +22,35 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::triSurfaceMeshPointSet Foam::triSurfaceMeshSet
Description Description
sampleSet from all points of a triSurfaceMesh. Samples from all the points of a triSurfaceMesh. Surface files are read
from constant/triSurface.
Usage
\table
Property | Description | Req'd? | Default
surface | The surface file name | yes |
axis | The coordinate axis that is written | yes |
\endtable
Example specification:
\verbatim
{
type triSurfaceMesh;
surface "surface.stl";
axis x;
}
\endverbatim
SourceFiles SourceFiles
triSurfaceMeshPointSet.C triSurfaceMeshSet.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef triSurfaceMeshPointSet_H #ifndef triSurfaceMeshSet_H
#define triSurfaceMeshPointSet_H #define triSurfaceMeshSet_H
#include "sampledSet.H" #include "sampledSet.H"
@ -42,13 +59,11 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class triSurfaceMeshPointSet Declaration Class triSurfaceMeshSet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class triSurfaceMeshPointSet class triSurfaceMeshSet
: :
public sampledSet public sampledSet
{ {
@ -58,7 +73,7 @@ class triSurfaceMeshPointSet
const word surface_; const word surface_;
//- Sampling points //- Sampling points
List<point> sampleCoords_; const List<point> points_;
// Private Member Functions // Private Member Functions
@ -80,13 +95,13 @@ class triSurfaceMeshPointSet
public: public:
//- Runtime type information //- Runtime type information
TypeName("triSurfaceMeshPointSet"); TypeName("triSurfaceMesh");
// Constructors // Constructors
//- Construct from dictionary //- Construct from dictionary
triSurfaceMeshPointSet triSurfaceMeshSet
( (
const word& name, const word& name,
const polyMesh& mesh, const polyMesh& mesh,
@ -96,13 +111,7 @@ public:
//- Destructor //- Destructor
virtual ~triSurfaceMeshPointSet(); virtual ~triSurfaceMeshSet();
// Member Functions
//- Get reference point
virtual point getRefPoint(const List<point>&) const;
}; };

View File

@ -1,460 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "uniformSet.H"
#include "meshSearch.H"
#include "DynamicList.H"
#include "polyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(uniformSet, 0);
addToRunTimeSelectionTable(sampledSet, uniformSet, word);
const scalar uniformSet::tol = 1e-3;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::uniformSet::nextSample
(
const point& currentPt,
const vector& offset,
const scalar smallDist,
point& samplePt,
label& sampleI
) const
{
bool pointFound = false;
const vector normOffset = offset/mag(offset);
samplePt += offset;
sampleI++;
for (; sampleI < nPoints_; sampleI++)
{
scalar s = (samplePt - currentPt) & normOffset;
if (s > -smallDist)
{
// samplePt is close to or beyond currentPt -> use it
pointFound = true;
break;
}
samplePt += offset;
}
return pointFound;
}
bool Foam::uniformSet::trackToBoundary
(
passiveParticleCloud& particleCloud,
passiveParticle& singleParticle,
point& samplePt,
label& sampleI,
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<scalar>& samplingCurveDist
) const
{
// distance vector between sampling points
const vector offset = (end_ - start_)/(nPoints_ - 1);
const vector smallVec = tol*offset;
const scalar smallDist = mag(smallVec);
point trackPt = singleParticle.position();
while(true)
{
// Find next samplePt on/after trackPt. Update samplePt, sampleI
if (!nextSample(trackPt, offset, smallDist, samplePt, sampleI))
{
// no more samples.
if (debug)
{
Pout<< "trackToBoundary : Reached end : samplePt now:"
<< samplePt << " sampleI now:" << sampleI << endl;
}
return false;
}
if (mag(samplePt - trackPt) < smallDist)
{
// trackPt corresponds with samplePt. Store and use next samplePt
if (debug)
{
Pout<< "trackToBoundary : samplePt corresponds to trackPt : "
<< " trackPt:" << trackPt << " samplePt:" << samplePt
<< endl;
}
samplingPts.append(trackPt);
samplingCells.append(singleParticle.cell());
samplingFaces.append(-1);
samplingCurveDist.append(mag(trackPt - start_));
// go to next samplePt
if (!nextSample(trackPt, offset, smallDist, samplePt, sampleI))
{
// no more samples.
if (debug)
{
Pout<< "trackToBoundary : Reached end : "
<< " samplePt now:" << samplePt
<< " sampleI now:" << sampleI
<< endl;
}
return false;
}
}
if (debug)
{
Pout<< "Searching along trajectory from "
<< " trackPt:" << trackPt
<< " trackCelli:" << singleParticle.cell()
<< " to:" << samplePt << endl;
}
singleParticle.track(samplePt - trackPt, 0);
trackPt = singleParticle.position();
if (singleParticle.onBoundaryFace())
{
// Pout<< "trackToBoundary : reached boundary" << endl;
if (mag(trackPt - samplePt) < smallDist)
{
// Pout<< "trackToBoundary : boundary is also sampling point"
// << endl;
// Reached samplePt on boundary
samplingPts.append(trackPt);
samplingCells.append(singleParticle.cell());
samplingFaces.append(singleParticle.face());
samplingCurveDist.append(mag(trackPt - start_));
}
return true;
}
// Pout<< "trackToBoundary : reached internal sampling point" << endl;
// Reached samplePt in cell or on internal face
samplingPts.append(trackPt);
samplingCells.append(singleParticle.cell());
samplingFaces.append(-1);
samplingCurveDist.append(mag(trackPt - start_));
// go to next samplePt
}
}
void Foam::uniformSet::calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
) const
{
// distance vector between sampling points
if ((nPoints_ < 2) || (mag(end_ - start_) < small))
{
FatalErrorInFunction
<< "Incorrect sample specification. Either too few points or"
<< " start equals end point." << endl
<< "nPoints:" << nPoints_
<< " start:" << start_
<< " end:" << end_
<< exit(FatalError);
}
const vector offset = (end_ - start_)/(nPoints_ - 1);
const vector normOffset = offset/mag(offset);
const vector smallVec = tol*offset;
const scalar smallDist = mag(smallVec);
// Force calculation of cloud addressing on all processors
const bool oldMoving = const_cast<polyMesh&>(mesh()).moving(false);
passiveParticleCloud particleCloud(mesh());
// Get all boundary intersections
List<pointIndexHit> bHits = searchEngine().intersections
(
start_ - smallVec,
end_ + smallVec
);
point bPoint(great, great, great);
label bFacei = -1;
if (bHits.size())
{
bPoint = bHits[0].hitPoint();
bFacei = bHits[0].index();
}
// Get first tracking point. Use bPoint, bFacei if provided.
point trackPt;
label trackCelli = -1;
label trackFacei = -1;
bool isSample =
getTrackingPoint
(
start_,
bPoint,
bFacei,
smallDist,
trackPt,
trackCelli,
trackFacei
);
if (trackCelli == -1)
{
// Line start_ - end_ does not intersect domain at all.
// (or is along edge)
// Set points and cell/face labels to empty lists
const_cast<polyMesh&>(mesh()).moving(oldMoving);
return;
}
if (isSample)
{
samplingPts.append(start_);
samplingCells.append(trackCelli);
samplingFaces.append(trackFacei);
samplingCurveDist.append(0.0);
}
//
// Track until hit end of all boundary intersections
//
// current segment number
label segmentI = 0;
// starting index of current segment in samplePts
label startSegmentI = 0;
label sampleI = 0;
point samplePt = start_;
// index in bHits; current boundary intersection
label bHitI = 1;
while(true)
{
// Initialize tracking starting from trackPt
passiveParticle singleParticle(mesh(), trackPt, trackCelli);
bool reachedBoundary = trackToBoundary
(
particleCloud,
singleParticle,
samplePt,
sampleI,
samplingPts,
samplingCells,
samplingFaces,
samplingCurveDist
);
// fill sampleSegments
for (label i = samplingPts.size() - 1; i >= startSegmentI; --i)
{
samplingSegments.append(segmentI);
}
if (!reachedBoundary)
{
if (debug)
{
Pout<< "calcSamples : Reached end of samples: "
<< " samplePt now:" << samplePt
<< " sampleI now:" << sampleI
<< endl;
}
break;
}
bool foundValidB = false;
while (bHitI < bHits.size())
{
scalar dist =
(bHits[bHitI].hitPoint() - singleParticle.position())
& normOffset;
if (debug)
{
Pout<< "Finding next boundary : "
<< "bPoint:" << bHits[bHitI].hitPoint()
<< " tracking:" << singleParticle.position()
<< " dist:" << dist
<< endl;
}
if (dist > smallDist)
{
// hitpoint is past tracking position
foundValidB = true;
break;
}
else
{
bHitI++;
}
}
if (!foundValidB)
{
// No valid boundary intersection found beyond tracking position
break;
}
// Update starting point for tracking
trackFacei = bFacei;
trackPt = pushIn(bPoint, trackFacei);
trackCelli = getBoundaryCell(trackFacei);
segmentI++;
startSegmentI = samplingPts.size();
}
const_cast<polyMesh&>(mesh()).moving(oldMoving);
}
void Foam::uniformSet::genSamples()
{
// Storage for sample points
DynamicList<point> samplingPts;
DynamicList<label> samplingCells;
DynamicList<label> samplingFaces;
DynamicList<label> samplingSegments;
DynamicList<scalar> samplingCurveDist;
calcSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
samplingPts.shrink();
samplingCells.shrink();
samplingFaces.shrink();
samplingSegments.shrink();
samplingCurveDist.shrink();
setSamples
(
samplingPts,
samplingCells,
samplingFaces,
samplingSegments,
samplingCurveDist
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::uniformSet::uniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const word& axis,
const point& start,
const point& end,
const label nPoints
)
:
sampledSet(name, mesh, searchEngine, axis),
start_(start),
end_(end),
nPoints_(nPoints)
{
genSamples();
if (debug)
{
write(Pout);
}
}
Foam::uniformSet::uniformSet
(
const word& name,
const polyMesh& mesh,
const meshSearch& searchEngine,
const dictionary& dict
)
:
sampledSet(name, mesh, searchEngine, dict),
start_(dict.lookup("start")),
end_(dict.lookup("end")),
nPoints_(readLabel(dict.lookup("nPoints")))
{
genSamples();
if (debug)
{
write(Pout);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::uniformSet::~uniformSet()
{}
// ************************************************************************* //

View File

@ -1,162 +0,0 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location system;
object sampleDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Set output format : choice of
// xmgr
// jplot
// gnuplot
// raw
setFormat raw;
// Surface output format. Choice of
// null : suppress output
// foamFile : separate points, faces and values file
// dx : DX scalar or vector format
// vtk : VTK ascii format
// raw : x y z value format for use with e.g. gnuplot 'splot'.
//
// Note:
// other formats such as obj, stl, etc can also be written (by proxy)
// but without any values!
surfaceFormat vtk;
// interpolationScheme. choice of
// cell : use cell-centre value only; constant over cells (default)
// cellPoint : use cell-centre and vertex values
// cellPointFace : use cell-centre, vertex and face values.
// 1] vertex values determined from neighbouring cell-centre values
// 2] face values determined using the current face interpolation scheme
// for the field (linear, gamma, etc.)
interpolationScheme cellPoint;
// Fields to sample.
fields
(
T
CO
CO2
H2
H2O
N2
O2
OH
CH4
);
// Set sampling definition: choice of
// uniform evenly distributed points on line
// face one point per face intersection
// midPoint one point per cell, in between two face intersections
// midPointAndFace combination of face and midPoint
//
// curve specified points, not necessary on line, uses
// tracking
// cloud specified points, uses findCell
//
// axis: how to write point coordinate. Choice of
// - x/y/z: x/y/z coordinate only
// - xyz: three columns
// (probably does not make sense for anything but raw)
// - distance: distance from start of sampling line (if uses line) or
// distance from first specified sampling point
//
// type specific:
// uniform, face, midPoint, midPointAndFace : start and end coordinate
// uniform: extra number of sampling points
// curve, cloud: list of coordinates
sets
(
Centerline
{
type uniform;
axis distance;
start (0.00001 0. 0. );
end (0.00001 0. 0.500);
nPoints 500;
}
Radial_075
{
type uniform;
axis distance;
start (0 0 0.054);
end (0.020 0 0.054);
nPoints 100;
}
Radial_15
{
type uniform;
axis distance;
start (0 0 0.108);
end (0.024 0.108);
nPoints 100;
}
Radial_30
{
type uniform;
axis distance;
start (0 0 0.216);
end (0.042 0 0.216);
nPoints 100;
}
Radial_45
{
type uniform;
axis distance;
start (0 0 0.324);
end (0.056 0 0.324);
nPoints 100;
}
Radial_60
{
type uniform;
axis distance;
start (0 0 0.432);
end (0.070 0 0.432);
nPoints 100;
}
Radial_75
{
type uniform;
axis distance;
start (0 0 0.54);
end (0.080 0 0.54);
nPoints 100;
}
);
// Surface sampling definition: choice of
// plane : values on plane defined by point, normal.
// patch : values on patch.
//
// 1] patches are not triangulated by default
// 2] planes are always triangulated
// 3] iso-surfaces are always triangulated
surfaces ();
// *********************************************************************** //

View File

@ -26,7 +26,7 @@ sets
( (
cone25 cone25
{ {
type face; type lineFace;
axis x; axis x;
start (0 0 0); start (0 0 0);
end (0.09208087 0.042939 0); end (0.09208087 0.042939 0);
@ -34,7 +34,7 @@ sets
} }
cone55 cone55
{ {
type face; type lineFace;
axis x; axis x;
start (0.09208087 0.042939 0); start (0.09208087 0.042939 0);
end (0.153683 0.13092 0); end (0.153683 0.13092 0);
@ -42,7 +42,7 @@ sets
} }
base base
{ {
type face; type lineFace;
axis x; axis x;
start (0.153683 0.13092 0); start (0.153683 0.13092 0);
end (0.193675 0.13092 0); end (0.193675 0.13092 0);

View File

@ -26,7 +26,7 @@ sets
( (
line line
{ {
type face; type lineFace;
axis x; axis x;
start (-5 0 0); start (-5 0 0);
end (5 0 0); end (5 0 0);

View File

@ -26,7 +26,7 @@ sets
( (
data data
{ {
type uniform; type lineUniform;
axis x; axis x;
start (-4.995 0 0); start (-4.995 0 0);
end (4.995 0 0); end (4.995 0 0);

View File

@ -26,7 +26,7 @@ sets
( (
line_centreProfile line_centreProfile
{ {
type uniform; type lineUniform;
axis distance; axis distance;
start (10.001 -1 0.01); start (10.001 -1 0.01);
end (10.001 1 0.01); end (10.001 1 0.01);

View File

@ -27,63 +27,63 @@ sets
( (
y0.1 y0.1
{ {
type face; type lineFace;
axis x; axis x;
start (-1 0.218 0); start (-1 0.218 0);
end (1 0.218 0); end (1 0.218 0);
} }
y0.2 y0.2
{ {
type face; type lineFace;
axis x; axis x;
start (-1 0.436 0); start (-1 0.436 0);
end (1 0.436 0); end (1 0.436 0);
} }
y0.3 y0.3
{ {
type face; type lineFace;
axis x; axis x;
start (-1 0.654 0); start (-1 0.654 0);
end (1 0.654 0); end (1 0.654 0);
} }
y0.4 y0.4
{ {
type face; type lineFace;
axis x; axis x;
start (-1 0.872 0); start (-1 0.872 0);
end (1 0.872 0); end (1 0.872 0);
} }
y0.5 y0.5
{ {
type face; type lineFace;
axis x; axis x;
start (-1 1.09 0); start (-1 1.09 0);
end (1 1.09 0); end (1 1.09 0);
} }
y0.6 y0.6
{ {
type face; type lineFace;
axis x; axis x;
start (-1 1.308 0); start (-1 1.308 0);
end (1 1.308 0); end (1 1.308 0);
} }
y0.7 y0.7
{ {
type face; type lineFace;
axis x; axis x;
start (-1 1.526 0); start (-1 1.526 0);
end (1 1.526 0); end (1 1.526 0);
} }
y0.8 y0.8
{ {
type face; type lineFace;
axis x; axis x;
start (-1 1.744 0); start (-1 1.744 0);
end (1 1.744 0); end (1 1.744 0);
} }
y0.9 y0.9
{ {
type face; type lineFace;
axis x; axis x;
start (-1 1.962 0); start (-1 1.962 0);
end (1 1.962 0); end (1 1.962 0);

View File

@ -15,9 +15,6 @@ Description
// Sampling and I/O settings // Sampling and I/O settings
#includeEtc "caseDicts/postProcessing/graphs/sampleDict.cfg" #includeEtc "caseDicts/postProcessing/graphs/sampleDict.cfg"
// Override settings here, e.g.
// setConfig { type midPoint; }
type sets; type sets;
libs ("libsampling.so"); libs ("libsampling.so");
@ -29,7 +26,7 @@ setFormat raw;
setConfig setConfig
{ {
type midPoint; // midPoint type lineCell;
axis distance; // x, y, z, xyz axis distance; // x, y, z, xyz
} }

View File

@ -15,9 +15,6 @@ Description
// Sampling and I/O settings // Sampling and I/O settings
#includeEtc "caseDicts/postProcessing/graphs/sampleDict.cfg" #includeEtc "caseDicts/postProcessing/graphs/sampleDict.cfg"
// Override settings here, e.g.
// setConfig { type midPoint; }
type sets; type sets;
libs ("libsampling.so"); libs ("libsampling.so");
@ -29,7 +26,7 @@ setFormat raw;
setConfig setConfig
{ {
type midPoint; // midPoint type lineCell;
axis distance; // x, y, z, xyz axis distance; // x, y, z, xyz
} }

View File

@ -61,7 +61,7 @@ functions
cloudName particleTracks; cloudName particleTracks;
seedSampleSet seedSampleSet
{ {
type uniform; type lineUniform;
axis x; axis x;
start (-1.001 1e-07 0.0011); start (-1.001 1e-07 0.0011);
end (-1.001 1e-07 1.0011); end (-1.001 1e-07 1.0011);

View File

@ -34,7 +34,7 @@ streamLines
// Seeding method. // Seeding method.
seedSampleSet seedSampleSet
{ {
type uniform; type lineUniform;
axis x; // distance; axis x; // distance;
// Note: tracks slightly offset so as not to be on a face // Note: tracks slightly offset so as not to be on a face

View File

@ -44,7 +44,7 @@ streamLines
// Seeding method. // Seeding method.
seedSampleSet seedSampleSet
{ {
type uniform; type lineUniform;
axis x; // distance; axis x; // distance;
// Note: tracks slightly offset so as not to be on a face // Note: tracks slightly offset so as not to be on a face

View File

@ -78,7 +78,7 @@ functions
// Seeding method. // Seeding method.
seedSampleSet seedSampleSet
{ {
type uniform; type lineUniform;
axis x; // distance; axis x; // distance;
start (-0.0205 0.001 0.00001); start (-0.0205 0.001 0.00001);