46 void Foam::autoDensity::writeOBJ
48 const treeBoundBox& bb,
52 OFstream str(time().path()/name +
".obj");
67 str <<
"l " << e[0] + 1 <<
' ' << e[1] + 1 <<
nl;
72 bool Foam::autoDensity::combinedOverlaps(
const treeBoundBox& box)
const 77 decomposition().overlapsThisProcessor(box)
78 || geometryToConformTo().overlaps(box);
81 return geometryToConformTo().overlaps(box);
85 bool Foam::autoDensity::combinedInside(
const point& p)
const 90 decomposition().positionOnThisProcessor(p)
91 && geometryToConformTo().inside(p);
94 return geometryToConformTo().inside(p);
106 return geometryToConformTo().wellInside
109 minimumSurfaceDistanceCoeffSqr_*
sqr(sizes)
113 Field<bool> inside(pts.size(),
true);
120 geometryToConformTo().wellInside
123 minimumSurfaceDistanceCoeffSqr_*
sqr(sizes)
129 decomposition().positionOnThisProcessor(pts)
148 inside[i] = (insideA[i] && insideB[i]);
155 bool Foam::autoDensity::combinedWellInside
165 inside = decomposition().positionOnThisProcessor(p);
172 && geometryToConformTo().wellInside
175 minimumSurfaceDistanceCoeffSqr_*
sqr(size)
184 DynamicList<Vb::Point>& initialPoints,
185 const treeBoundBox& bb,
194 treeBoundBox subBB = bb.subBbox(i);
196 word newName = recursionName +
"_" +
Foam::name(i);
200 if (combinedOverlaps(subBB))
224 word(newName +
"_overlap")
227 Pout<< newName +
"_overlap " << subBB <<
endl;
230 if (!fillBox(initialPoints, subBB,
true))
247 else if (combinedInside(subBB.midpoint()))
257 Pout<< newName +
"_inside " << subBB <<
endl;
260 if (!fillBox(initialPoints, subBB,
false))
289 return treeDepth + 1;
293 bool Foam::autoDensity::fillBox
295 DynamicList<Vb::Point>& initialPoints,
296 const treeBoundBox& bb,
300 const conformationSurfaces& geometry = geometryToConformTo();
302 label initialSize = initialPoints.size();
304 scalar maxCellSize = -great;
306 scalar minCellSize = great;
308 scalar maxDensity = 1/
pow3(minCellSize);
310 scalar volumeAdded = 0.0;
316 scalar totalVolume = bb.volume();
318 label trialPoints = 0;
320 bool wellInside =
false;
332 geometry.findSurfaceNearest
344 Pout<<
"box wellInside, no need to sample surface." <<
endl;
351 if (!overlapping && !wellInside)
360 scalarField cornerSizes = cellShapeControls().cellSize(corners);
362 Field<bool> insideCorners = combinedWellInside(corners, cornerSizes);
369 scalar s = cornerSizes[i];
378 minCellSize =
max(s, minCellSizeLimit_);
381 if (maxCellSize/minCellSize > maxSizeRatio_)
385 Pout<<
"Abort fill at corner sample stage," 386 <<
" minCellSize " << minCellSize
387 <<
" maxCellSize " << maxCellSize
388 <<
" maxSizeRatio " << maxCellSize/minCellSize
395 if (!insideCorners[i])
402 Pout<<
"Inside box found to have some non-wellInside " 403 <<
"corners, using overlapping fill." 415 vector delta = span/(surfRes_ - 1);
417 label nLine = 6*(surfRes_ - 2);
423 for (
label i = 0; i < surfRes_; i++)
427 for (
label j = 1; j < surfRes_ - 1 ; j++)
431 +
vector(0, delta.y()*i, delta.z()*j);
437 delta.x()*(surfRes_ - 1),
444 +
vector(delta.x()*j, 0, delta.z()*i);
451 delta.y()*(surfRes_ - 1),
457 +
vector(delta.x()*i, delta.y()*j, 0);
465 delta.z()*(surfRes_ - 1)
469 lineSizes = cellShapeControls().cellSize(linePoints);
471 Field<bool> insideLines = combinedWellInside
480 scalar s = lineSizes[i];
489 minCellSize =
max(s, minCellSizeLimit_);
492 if (maxCellSize/minCellSize > maxSizeRatio_)
496 Pout<<
"Abort fill at surface sample stage, " 497 <<
" minCellSize " << minCellSize
498 <<
" maxCellSize " << maxCellSize
499 <<
" maxSizeRatio " << maxCellSize/minCellSize
514 Pout<<
"Inside box found to have some non-" 515 <<
"wellInside surface points, using " 516 <<
"overlapping fill." 534 volRes_*volRes_*volRes_,
538 vector delta = span/volRes_;
542 for (
label i = 0; i < volRes_; i++)
544 for (
label j = 0; j < volRes_; j++)
571 scalarField sampleSizes = cellShapeControls().cellSize(samplePoints);
573 Field<bool> insidePoints = combinedWellInside
587 scalar s = sampleSizes[i];
596 minCellSize =
max(s, minCellSizeLimit_);
599 if (maxCellSize/minCellSize > maxSizeRatio_)
603 Pout<<
"Abort fill at sample stage," 604 <<
" minCellSize " << minCellSize
605 <<
" maxCellSize " << maxCellSize
606 <<
" maxSizeRatio " << maxCellSize/minCellSize
619 Pout<<
"No sample points found inside box" <<
endl;
627 Pout<< scalar(nInside)/scalar(samplePoints.size())
628 <<
" full overlapping box" << endl;
631 totalVolume *= scalar(nInside)/scalar(samplePoints.size());
635 Pout<<
"Total volume to fill = " << totalVolume <<
endl;
642 maxDensity = 1/
pow3(
max(minCellSize, small));
650 const point& p = samplePoints[i];
652 scalar localSize = sampleSizes[i];
654 scalar localDensity = 1/
pow3(localSize);
665 if (localDensity/maxDensity >
rndGen().scalar01())
667 scalar localVolume = 1/localDensity;
669 if (volumeAdded + localVolume > totalVolume)
675 scalar addProbability =
676 (totalVolume - volumeAdded)/localVolume;
682 Pout<<
"totalVolume " << totalVolume <<
nl 683 <<
"volumeAdded " << volumeAdded <<
nl 684 <<
"localVolume " << localVolume <<
nl 685 <<
"addProbability " << addProbability <<
nl 690 if (addProbability > r)
703 volumeAdded += localVolume;
709 initialPoints.append(
Vb::Point(p.x(), p.y(), p.z()));
711 volumeAdded += localVolume;
717 if (volumeAdded < totalVolume)
721 Pout<<
"Adding random points, remaining volume " 722 << totalVolume - volumeAdded
726 maxDensity = 1/
pow3(
max(minCellSize, small));
734 scalar localSize = cellShapeControls().cellSize(p);
736 bool insidePoint =
false;
745 insidePoint = combinedWellInside(p, localSize);
750 if (localSize > maxCellSize)
752 maxCellSize = localSize;
755 if (localSize < minCellSize)
757 minCellSize =
max(localSize, minCellSizeLimit_);
759 localSize = minCellSize;
763 maxDensity = 1/
pow3(
max(minCellSize, small));
766 if (maxCellSize/minCellSize > maxSizeRatio_)
770 Pout<<
"Abort fill at random fill stage," 771 <<
" minCellSize " << minCellSize
772 <<
" maxCellSize " << maxCellSize
773 <<
" maxSizeRatio " << maxCellSize/minCellSize
779 initialPoints.resize(initialSize);
784 scalar localDensity = 1/
pow3(
max(localSize, small));
788 if (localDensity/maxDensity >
rndGen().scalar01())
790 scalar localVolume = 1/localDensity;
792 if (volumeAdded + localVolume > totalVolume)
798 scalar addProbability =
799 (totalVolume - volumeAdded)/localVolume;
805 Pout<<
"totalVolume " << totalVolume <<
nl 806 <<
"volumeAdded " << volumeAdded <<
nl 807 <<
"localVolume " << localVolume <<
nl 808 <<
"addProbability " << addProbability <<
nl 813 if (addProbability > r)
826 volumeAdded += localVolume;
832 initialPoints.append(
Vb::Point(p.x(), p.y(), p.z()));
834 volumeAdded += localVolume;
840 globalTrialPoints_ += trialPoints;
845 <<
" locations queried, " << initialPoints.size() - initialSize
846 <<
" points placed, (" 847 << scalar(initialPoints.size() - initialSize)
848 /scalar(
max(trialPoints, 1))
849 <<
" success rate)." <<
nl 850 <<
"minCellSize " << minCellSize
851 <<
", maxCellSize " << maxCellSize
852 <<
", ratio " << maxCellSize/minCellSize
864 const dictionary& initialPointsDict,
867 const conformationSurfaces& geometryToConformTo,
868 const cellShapeControl& cellShapeControls,
869 const autoPtr<backgroundMeshDecomposition>& decomposition
882 globalTrialPoints_(0),
885 detailsDict().lookupOrDefault<scalar>(
"minCellSizeLimit", 0.0)
887 minLevels_(detailsDict().
lookup<
label>(
"minLevels")),
888 maxSizeRatio_(detailsDict().
lookup<scalar>(
"maxSizeRatio")),
889 volRes_(detailsDict().
lookup<
label>(
"sampleResolution")),
892 detailsDict().lookupOrDefault<
label>(
"surfaceSampleResolution", volRes_)
895 if (maxSizeRatio_ <= 1.0)
900 <<
"The maxSizeRatio must be greater than one to be sensible, " 901 <<
"setting to " << maxSizeRatio_
917 hierBB = decomposition().procBounds();
922 hierBB = geometryToConformTo().globalBounds().extend(1
e-6);
925 DynamicList<Vb::Point> initialPoints;
931 Pout<<
" Filling box " << hierBB <<
endl;
934 label treeDepth = recurseAndFill
942 initialPoints.shrink();
944 label nInitialPoints = initialPoints.size();
948 reduce(nInitialPoints, sumOp<label>());
949 reduce(globalTrialPoints_, sumOp<label>());
953 <<
indent << nInitialPoints <<
" points placed" <<
nl 954 <<
indent << globalTrialPoints_ <<
" locations queried" <<
nl 956 << scalar(nInitialPoints)/scalar(
max(globalTrialPoints_, 1))
957 <<
" success rate" <<
nl 960 <<
" levels of recursion (maximum)" 964 return move(initialPoints);
virtual const fileName & name() const
Return the name of the stream.
void shuffle(UList< T > &)
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & indent(Ostream &os)
Indent stream.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Holds information (coordinate and normal) regarding nearest wall point.
PointIndexHit< point > pointIndexHit
Vector< scalar > vector
A scalar version of the templated Vector.
label k
Boltzmann constant.
Macros for easy insertion into run-time selection tables.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
vectorField pointField
pointField is a vectorField.
stressControl lookup("compactNormalStress") >> compactNormalStress
autoDensity(const dictionary &initialPointsDict, const Time &runTime, Random &rndGen, const conformationSurfaces &geometryToConformTo, const cellShapeControl &cellShapeControls, const autoPtr< backgroundMeshDecomposition > &decomposition)
Construct from components.
Pre-declare SubField and related Field type.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
virtual List< Vb::Point > initialPoints() const
Return the initial points for the conformalVoronoiMesh.
static const edgeList edges
Edge to point addressing.
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
word name(const complex &)
Return a string representation of a complex.
dimensionedScalar pow3(const dimensionedScalar &ds)
static bool & parRun()
Is this a parallel run?
vector point
Point is a vector.
#define WarningInFunction
Report a warning using Foam::Warning.
prefixOSstream Pout(cout, "Pout")
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
const doubleScalar e
Elementary charge.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
scalar scalar01()
Advance the state and return a scalar sample from a uniform.