Commit 2c08067a authored by graham's avatar graham
Browse files

ENH: Auto and limited min cell size for densityWeightedStochastic.

parent f8213e80
......@@ -51,9 +51,13 @@ densityWeightedStochastic::densityWeightedStochastic
:
initialPointsMethod(typeName, initialPointsDict, cvMesh),
totalVolume_(readScalar(detailsDict().lookup("totalVolume"))),
maxDensity_
minCellSize_
(
1.0/pow3(readScalar(detailsDict().lookup("minCellSize")))
detailsDict().lookupOrDefault<scalar>("minCellSize", GREAT)
),
minCellSizeLimit_
(
detailsDict().lookupOrDefault<scalar>("minCellSizeLimit", 0.0)
)
{}
......@@ -76,6 +80,8 @@ std::vector<Vb::Point> densityWeightedStochastic::initialPoints() const
label trialPoints = 0;
scalar maxDensity = 1/pow3(max(minCellSize_, SMALL));
while (volumeAdded < totalVolume_)
{
trialPoints++;
......@@ -91,10 +97,19 @@ std::vector<Vb::Point> densityWeightedStochastic::initialPoints() const
scalar localSize = cvMesh_.cellSizeControl().cellSize(p);
if (localSize < minCellSize_)
{
minCellSize_ = max(localSize, minCellSizeLimit_);
// 1/(minimum cell size)^3, gives the maximum permissible point
// density
maxDensity = 1/pow3(max(minCellSize_, SMALL));
}
scalar localDensity = 1/pow3(max(localSize, SMALL));
// Accept possible placements proportional to the relative local density
if (localDensity/maxDensity_ > rndGen.scalar01())
if (localDensity/maxDensity > rndGen.scalar01())
{
// Determine if the point is "wellInside" the domain
if
......@@ -116,7 +131,8 @@ std::vector<Vb::Point> densityWeightedStochastic::initialPoints() const
Info<< nl << " " << typeName << " - "
<< trialPoints << " locations queried ("
<< scalar(initialPoints.size())/scalar(trialPoints)
<< " success rate)" << endl;
<< " success rate). minCellSize " << minCellSize_
<< endl;
return initialPoints;
}
......
......@@ -25,6 +25,8 @@ Class
Foam::densityWeightedStochastic
Description
Choose random points inside the domain and place them with a probability
proportional to the target density of points.
SourceFiles
densityWeightedStochastic.C
......@@ -44,7 +46,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class densityWeightedStochastic Declaration
Class densityWeightedStochastic Declaration
\*---------------------------------------------------------------------------*/
class densityWeightedStochastic
......@@ -59,9 +61,13 @@ private:
//- The total volume to be filled
scalar totalVolume_;
//- 1/(minimum cell size)^3, gives the maximum permissible point
// density
scalar maxDensity_;
//- Working variable for minimum cell size, a starting value may be
// specified in the dictionary
mutable scalar minCellSize_;
//- Smallest minimum cell size allowed, i.e. to avoid high initial
// population of areas of small size
scalar minCellSizeLimit_;
public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment