Skip to content
Snippets Groups Projects
Commit 9791395a authored by mattijs's avatar mattijs
Browse files

ENH: patchSeedSet: sampledSet for starting tracks on patches

parent 81ba434c
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@ sampledSet/polyLine/polyLineSet.C
sampledSet/face/faceOnlySet.C
sampledSet/midPoint/midPointSet.C
sampledSet/midPointAndFace/midPointAndFaceSet.C
/* sampledSet/patchSeed/patchSeedSet.C */
sampledSet/patchSeed/patchSeedSet.C
sampledSet/sampledSet/sampledSet.C
sampledSet/sampledSets/sampledSets.C
sampledSet/sampledSets/sampledSetsGrouping.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 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/>.
\*---------------------------------------------------------------------------*/
#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.integer(0, subset.size()-1);
Swap(subset[i], subset[j]);
}
}
// Truncate
subset.setSize(myMaxPoints);
// Subset patchFaces
patchFaces = UIndirectList<label>(patchFaces, subset)();
if (debug)
{
Pout<< "In random mode : selected " << patchFaces
<< " 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::FACEDIAGTETS
);
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,
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()
{}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 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::patchSeedSet
Description
Initialises points on or just off patch
SourceFiles
patchSeedSet.C
\*---------------------------------------------------------------------------*/
#ifndef patchSeedSet_H
#define patchSeedSet_H
#include "sampledSet.H"
#include "DynamicList.H"
#include "HashSet.H"
#include "Random.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class patchSeedSet Declaration
\*---------------------------------------------------------------------------*/
class patchSeedSet
:
public sampledSet
{
// Private data
//- Patches to sample
const labelHashSet patchSet_;
// //- Maximum distance to look for nearest
// const scalar searchDist_;
//
// //- 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
//- Samples all points in sampleCoords.
void calcSamples
(
DynamicList<point>& samplingPts,
DynamicList<label>& samplingCells,
DynamicList<label>& samplingFaces,
DynamicList<label>& samplingSegments,
DynamicList<scalar>& samplingCurveDist
);
//- Uses calcSamples to obtain samples. Copies them into *this.
void genSamples();
public:
//- Runtime type information
TypeName("patchSeed");
// Constructors
// //- Construct from components
// patchSeedSet
// (
// const word& name,
// const polyMesh& mesh,
// meshSearch& searchEngine,
// const word& axis,
// const List<point>& sampleCoords,
// const labelHashSet& patchSet,
// const scalar searchDist
// );
//- Construct from dictionary
patchSeedSet
(
const word& name,
const polyMesh& mesh,
meshSearch& searchEngine,
const dictionary& dict
);
//- Destructor
virtual ~patchSeedSet();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment