Commit 8ec07bb8 authored by graham's avatar graham
Browse files

ENH: Adding hierarchicalDensityWeightedStochastic initial points method.

Requires "overlaps(const boundBox& bb)" function for searchableSurface.
parent d1cbc06c
......@@ -25,6 +25,7 @@ initialPointsMethod/bodyCentredCubic/bodyCentredCubic.C
initialPointsMethod/faceCentredCubic/faceCentredCubic.C
initialPointsMethod/pointFile/pointFile.C
initialPointsMethod/densityWeightedStochastic/densityWeightedStochastic.C
initialPointsMethod/hierarchicalDensityWeightedStochastic/hierarchicalDensityWeightedStochastic.C
relaxationModel/relaxationModel/relaxationModel.C
relaxationModel/adaptiveLinear/adaptiveLinear.C
......
......@@ -163,7 +163,7 @@ Foam::scalar Foam::cellSizeControlSurfaces::cellSize
) const
{
// Regions requesting with the same priority take the average
// // Regions requesting with the same priority take the average
// scalar sizeAccumulator = 0;
// scalar numberOfFunctions = 0;
......
......@@ -776,8 +776,12 @@ void Foam::conformalVoronoiMesh::insertInitialPoints()
Info<< nl << "Inserting initial points" << endl;
timeCheck();
std::vector<Point> initPts = initialPointsMethod_->initialPoints();
timeCheck();
insertPoints(initPts);
if(cvMeshControls().objOutput())
......
......@@ -212,6 +212,20 @@ Foam::conformationSurfaces::~conformationSurfaces()
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::conformationSurfaces::overlaps(const boundBox& bb) const
{
forAll(surfaces_, s)
{
if (allGeometry_[surfaces_[s]].overlaps(bb))
{
return true;
}
}
return false;
}
Foam::Field<bool> Foam::conformationSurfaces::inside
(
const pointField& samplePts
......@@ -221,6 +235,15 @@ Foam::Field<bool> Foam::conformationSurfaces::inside
}
bool Foam::conformationSurfaces::inside
(
const point& samplePt
) const
{
return wellInside(pointField(1, samplePt), scalarField(1, 0))[0];
}
Foam::Field<bool> Foam::conformationSurfaces::outside
(
const pointField& samplePts
......@@ -230,6 +253,15 @@ Foam::Field<bool> Foam::conformationSurfaces::outside
}
bool Foam::conformationSurfaces::outside
(
const point& samplePt
) const
{
return wellOutside(pointField(1, samplePt), scalarField(1, 0))[0];
}
Foam::Field<bool> Foam::conformationSurfaces::wellInside
(
const pointField& samplePts,
......
......@@ -160,12 +160,22 @@ public:
// Query
//- Check if point is inside surfaces to conform to
//- Check if the supplied bound box overlaps any part of any of
// the surfaces
bool overlaps(const boundBox& bb) const;
//- Check if points are inside surfaces to conform to
Field<bool> inside(const pointField& samplePts) const;
//- Check if point is outside surfaces to conform to
//- Check if point is inside surfaces to conform to
bool inside(const point& samplePt) const;
//- Check if points are outside surfaces to conform to
Field<bool> outside(const pointField& samplePts) const;
//- Check if point is outside surfaces to conform to
bool outside(const point& samplePt) const;
//- Check if point is inside surfaces to conform to by at least
// testDistSqr
Field<bool> wellInside
......
......@@ -62,15 +62,15 @@ std::vector<Vb::Point> bodyCentredCubic::initialPoints() const
scalar x0 = bb.min().x();
scalar xR = bb.max().x() - x0;
int ni = int(xR/initialCellSize_) + 1;
label ni = label(xR/initialCellSize_) + 1;
scalar y0 = bb.min().y();
scalar yR = bb.max().y() - y0;
int nj = int(yR/initialCellSize_) + 1;
label nj = label(yR/initialCellSize_) + 1;
scalar z0 = bb.min().z();
scalar zR = bb.max().z() - z0;
int nk = int(zR/initialCellSize_) + 1;
label nk = label(zR/initialCellSize_) + 1;
vector delta(xR/ni, yR/nj, zR/nk);
......@@ -84,9 +84,9 @@ std::vector<Vb::Point> bodyCentredCubic::initialPoints() const
List<bool> isSurfacePoint(2*nk, false);
for (int i = 0; i < ni; i++)
for (label i = 0; i < ni; i++)
{
for (int j = 0; j < nj; j++)
for (label j = 0; j < nj; j++)
{
// Generating, testing and adding points one line at a time to
// reduce the memory requirement for cases with bounding boxes that
......@@ -96,7 +96,7 @@ std::vector<Vb::Point> bodyCentredCubic::initialPoints() const
pointField points(2*nk);
for (int k = 0; k < nk; k++)
for (label k = 0; k < nk; k++)
{
point pA
(
......
......@@ -128,10 +128,12 @@ std::vector<Vb::Point> densityWeightedStochastic::initialPoints() const
}
}
Info<< nl << " " << typeName << " - "
<< trialPoints << " locations queried ("
<< scalar(initialPoints.size())/scalar(trialPoints)
<< " success rate). minCellSize " << minCellSize_
Info<< nl << " " << typeName << nl
<< " " << initialPoints.size() << " points placed" << nl
<< " " << trialPoints << " locations queried" << nl
<< " " << scalar(initialPoints.size())/scalar(trialPoints)
<< " success rate" << nl
<< " minCellSize " << minCellSize_
<< endl;
return initialPoints;
......
......@@ -62,15 +62,15 @@ std::vector<Vb::Point> faceCentredCubic::initialPoints() const
scalar x0 = bb.min().x();
scalar xR = bb.max().x() - x0;
int ni = int(xR/initialCellSize_) + 1;
label ni = label(xR/initialCellSize_) + 1;
scalar y0 = bb.min().y();
scalar yR = bb.max().y() - y0;
int nj = int(yR/initialCellSize_) + 1;
label nj = label(yR/initialCellSize_) + 1;
scalar z0 = bb.min().z();
scalar zR = bb.max().z() - z0;
int nk = int(zR/initialCellSize_) + 1;
label nk = label(zR/initialCellSize_) + 1;
vector delta(xR/ni, yR/nj, zR/nk);
......@@ -84,9 +84,9 @@ std::vector<Vb::Point> faceCentredCubic::initialPoints() const
List<bool> isSurfacePoint(4*nk, false);
for (int i = 0; i < ni; i++)
for (label i = 0; i < ni; i++)
{
for (int j = 0; j < nj; j++)
for (label j = 0; j < nj; j++)
{
// Generating, testing and adding points one line at a time to
// reduce the memory requirement for cases with bounding boxes that
......@@ -96,7 +96,7 @@ std::vector<Vb::Point> faceCentredCubic::initialPoints() const
pointField points(4*nk);
for (int k = 0; k < nk; k++)
for (label k = 0; k < nk; k++)
{
point p
(
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::hierarchicalDensityWeightedStochastic
Description
Choose random points inside the domain and place them with a probability
proportional to the target density of points.
SourceFiles
hierarchicalDensityWeightedStochastic.C
\*---------------------------------------------------------------------------*/
#ifndef hierarchicalDensityWeightedStochastic_H
#define hierarchicalDensityWeightedStochastic_H
#include "initialPointsMethod.H"
#include "treeBoundBox.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class hierarchicalDensityWeightedStochastic Declaration
\*---------------------------------------------------------------------------*/
class hierarchicalDensityWeightedStochastic
:
public initialPointsMethod
{
private:
// Private data
//- Trial points attempted to be placed in all boxes
mutable label globalTrialPoints_;
//- Smallest minimum cell size allowed, i.e. to avoid high initial
// population of areas of small size
scalar minCellSizeLimit_;
//- Maximum normal level of recursion, can be more if a high density
// ratio is detected
label maxLevels_;
//- Maximum allowed ratio of cell size in a box
scalar maxSizeRatio_;
//- How fine should the initial sample of the volume a box be to
// investigate it cell sizes and volume fraction
label volRes_;
//- How fine should the initial sample of the surface of a box be to
// investigate if it is near to a the geometry.
label surfRes_;
//- Write boundBox as obj
void writeOBJ
(
const treeBoundBox& bb,
fileName name
) const;
//- Descend into octants of the supplied bound box
void recurseAndFill
(
std::vector<Vb::Point>& initialPoints,
const treeBoundBox& bb,
label levelLimit,
word recursionName
) const;
//- Fill the given box, optionally filling surface overlapping boxes.
// Returns true if the fill is successful, false if it is to be aborted
// in favour of further recursion.
bool fillBox
(
std::vector<Vb::Point>& initialPoints,
const treeBoundBox& bb,
bool overlapping
) const;
public:
//- Runtime type information
TypeName("hierarchicalDensityWeightedStochastic");
// Constructors
//- Construct from components
hierarchicalDensityWeightedStochastic
(
const dictionary& initialPointsDict,
const conformalVoronoiMesh& cvMesh
);
//- Destructor
virtual ~hierarchicalDensityWeightedStochastic()
{}
// Member Functions
//- Return the initial points for the conformalVoronoiMesh
virtual std::vector<Vb::Point> initialPoints() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -62,15 +62,15 @@ std::vector<Vb::Point> uniformGrid::initialPoints() const
scalar x0 = bb.min().x();
scalar xR = bb.max().x() - x0;
int ni = int(xR/initialCellSize_) + 1;
label ni = label(xR/initialCellSize_) + 1;
scalar y0 = bb.min().y();
scalar yR = bb.max().y() - y0;
int nj = int(yR/initialCellSize_) + 1;
label nj = label(yR/initialCellSize_) + 1;
scalar z0 = bb.min().z();
scalar zR = bb.max().z() - z0;
int nk = int(zR/initialCellSize_) + 1;
label nk = label(zR/initialCellSize_) + 1;
vector delta(xR/ni, yR/nj, zR/nk);
......@@ -84,9 +84,9 @@ std::vector<Vb::Point> uniformGrid::initialPoints() const
List<bool> isSurfacePoint(nk, false);
for (int i = 0; i < ni; i++)
for (label i = 0; i < ni; i++)
{
for (int j = 0; j < nj; j++)
for (label j = 0; j < nj; j++)
{
// Generating, testing and adding points one line at a time to
// reduce the memory requirement for cases with bounding boxes that
......@@ -96,7 +96,7 @@ std::vector<Vb::Point> uniformGrid::initialPoints() const
pointField points(nk);
for (int k = 0; k < nk; k++)
for (label k = 0; k < nk; k++)
{
point p
(
......
......@@ -129,6 +129,12 @@ public:
// Usually the element centres (should be of length size()).
virtual pointField coordinates() const;
// Does any part of the surface overlap the supplied bound box?
virtual bool overlaps(const boundBox& bb) const
{
return boundBox::overlaps(bb);
}
// Single point queries.
//- Calculate nearest point on surface. Returns
......
......@@ -206,6 +206,17 @@ public:
// Usually the element centres (should be of length size()).
virtual pointField coordinates() const = 0;
// Does any part of the surface overlap the supplied bound box?
virtual bool overlaps(const boundBox& bb) const
{
notImplemented
(
"searchableSurface::overlaps(const boundBox& bb) const"
);
return false;
}
// Single point queries.
......
......@@ -488,6 +488,16 @@ Foam::pointField Foam::triSurfaceMesh::coordinates() const
}
bool Foam::triSurfaceMesh::overlaps(const boundBox& bb) const
{
const indexedOctree<treeDataTriSurface>& octree = tree();
labelList indices = octree.findBox(treeBoundBox(bb));
return !indices.empty();
}
void Foam::triSurfaceMesh::movePoints(const pointField& newPoints)
{
tree_.clear();
......
......@@ -195,6 +195,9 @@ public:
// Usually the element centres (should be of length size()).
virtual pointField coordinates() const;
// Does any part of the surface overlap the supplied bound box?
virtual bool overlaps(const boundBox& bb) const;
virtual void findNearest
(
const pointField& sample,
......
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