From 2c08067a59934b0c71ec02a8f98cf23f88646efa Mon Sep 17 00:00:00 2001 From: graham Date: Mon, 1 Nov 2010 17:09:25 +0000 Subject: [PATCH] ENH: Auto and limited min cell size for densityWeightedStochastic. --- .../densityWeightedStochastic.C | 24 +++++++++++++++---- .../densityWeightedStochastic.H | 14 +++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.C b/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.C index 0e9b3beab4..8dd5c71e96 100644 --- a/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.C +++ b/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.C @@ -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("minCellSize", GREAT) + ), + minCellSizeLimit_ + ( + detailsDict().lookupOrDefault("minCellSizeLimit", 0.0) ) {} @@ -76,6 +80,8 @@ std::vector densityWeightedStochastic::initialPoints() const label trialPoints = 0; + scalar maxDensity = 1/pow3(max(minCellSize_, SMALL)); + while (volumeAdded < totalVolume_) { trialPoints++; @@ -91,10 +97,19 @@ std::vector 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 densityWeightedStochastic::initialPoints() const Info<< nl << " " << typeName << " - " << trialPoints << " locations queried (" << scalar(initialPoints.size())/scalar(trialPoints) - << " success rate)" << endl; + << " success rate). minCellSize " << minCellSize_ + << endl; return initialPoints; } diff --git a/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.H b/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.H index d345fa4578..8cc1afc0cb 100644 --- a/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.H +++ b/src/mesh/conformalVoronoiMesh/initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.H @@ -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: