void Foam::triSurfaceMesh::calcBounds(boundBox& bb, label& nPoints) const { // Unfortunately nPoints constructs meshPoints() so do compact version // ourselves const triSurface& s = static_cast<const triSurface&>(*this); PackedBoolList pointIsUsed(points().size()); nPoints = 0; bb = boundBox::invertedBox; forAll(s, faceI) { const triSurface::FaceType& f = s[faceI]; forAll(f, fp) { label pointI = f[fp]; if (pointIsUsed.set(pointI, 1u)) { bb.min() = ::Foam::min(bb.min(), points()[pointI]); bb.max() = ::Foam::max(bb.max(), points()[pointI]); nPoints++; } } }
bool Foam::searchablePlate::overlaps(const boundBox& bb) const { return ( (origin_.x() + span_.x()) >= bb.min().x() && origin_.x() <= bb.max().x() && (origin_.y() + span_.y()) >= bb.min().y() && origin_.y() <= bb.max().y() && (origin_.z() + span_.z()) >= bb.min().z() && origin_.z() <= bb.max().z() ); }
void Foam::pointToPointPlanarInterpolation::calcWeights ( const pointField& sourcePoints, const pointField& destPoints ) { tmp<vectorField> tlocalVertices ( referenceCS_.localPosition(sourcePoints) ); vectorField& localVertices = tlocalVertices(); const boundBox bb(localVertices, true); const point bbMid(bb.midpoint()); if (debug) { Info<< "pointToPointPlanarInterpolation::readData :" << " Perturbing points with " << perturb_ << " fraction of a random position inside " << bb << " to break any ties on regular meshes." << nl << endl; } Random rndGen(123456); forAll(localVertices, i) { localVertices[i] += perturb_ *(rndGen.position(bb.min(), bb.max())-bbMid); }
bool sphereRefinement::intersectsObject(const boundBox& bb) const { const point& c = (bb.max() + bb.min()) / 2.0; if( magSqr(c - centre_) < sqr(radius_) ) return true; return false; }
void Foam::patchCloudSet::calcSamples ( DynamicList<point>& samplingPts, DynamicList<label>& samplingCells, DynamicList<label>& samplingFaces, DynamicList<label>& samplingSegments, DynamicList<scalar>& samplingCurveDist ) const { if (debug) { Info<< "patchCloudSet : 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; treeBoundBox bb(point::max, point::min); forAllConstIter(labelHashSet, patchSet_, iter) { const polyPatch& pp = mesh().boundaryMesh()[iter.key()]; forAll(pp, i) { patchFaces[sz++] = pp.start()+i; } // Do not do reduction. const boundBox patchBb(pp.points(), pp.meshPoints(), false); bb.min() = min(bb.min(), patchBb.min()); bb.max() = max(bb.max(), patchBb.max()); }
bool lineRefinement::intersectsObject(const boundBox& bb) const { //- check if the cube contains start point or end point const scalar l = bb.max().x() - bb.min().x(); const point min = bb.min() - l * vector(SMALL, SMALL, SMALL); const point max = bb.max() + l * vector(SMALL, SMALL, SMALL); //- check for intersections of line with the cube faces const vector v(p1_ - p0_); if( mag(v.x()) > SMALL ) { if( ((p0_.x() < min.x()) && (p1_.x() < min.x())) || ((p0_.x() > max.x()) && (p1_.x() > max.x())) ) return false; { //- x-min face const vector n(-1, 0, 0); const scalar t = (n & (min - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.y() > min.y()) && (i.y() < max.y()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } { //- x-max face const vector n(1, 0, 0); const scalar t = (n & (max - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.y() > min.y()) && (i.y() < max.y()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } } if( mag(v.y()) > SMALL) { if( ((p0_.y() < min.y()) && (p1_.y() < min.y())) || ((p0_.y() > max.y()) && (p1_.y() > max.y())) ) return false; { //- y-min face const vector n(0, -1, 0); const scalar t = (n & (min - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.x() > min.x()) && (i.x() < max.x()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } { //- y-max face const vector n(0, 1, 0); const scalar t = (n & (max - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) ) if( (i.x() > min.x()) && (i.x() < max.x()) && (i.z() > min.z()) && (i.z() < max.z()) ) return true; } } if( mag(v.z()) > SMALL ) { if( ((p0_.z() < min.z()) && (p1_.z() < min.z())) || ((p0_.z() > max.z()) && (p1_.z() > max.z())) ) return false; { //- z-min face const vector n(0, 0, -1); const scalar t = (n & (min - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) && (i.x() > min.x()) && (i.x() < max.x()) && (i.y() > min.y()) && (i.y() < max.y()) ) return true; } { //- z-min face const vector n(0, 0, 1); const scalar t = (n & (max - p0_)) / (n & v); const point i = p0_ + t * v; if( (t > -SMALL) && (t < (1.0+SMALL)) && (i.x() > min.x()) && (i.x() < max.x()) && (i.y() > min.y()) && (i.y() < max.y()) ) return true; } } if( (p0_.x() > min.x()) && (p0_.x() < max.x()) && (p0_.y() > min.y()) && (p0_.y() < max.y()) && (p0_.z() > min.z()) && (p0_.z() < max.z()) ) return true; return false; }
void timeVaryingMappedFixedValueFvPatchField<Type>::readSamplePoints() { // Read the sample points pointIOField samplePoints ( IOobject ( "points", this->db().time().constant(), "boundaryData"/this->patch().name(), this->db(), IOobject::MUST_READ, IOobject::AUTO_WRITE, false ) ); const fileName samplePointsFile = samplePoints.filePath(); if (debug) { Info<< "timeVaryingMappedFixedValueFvPatchField :" << " Read " << samplePoints.size() << " sample points from " << samplePointsFile << endl; } // Determine coordinate system from samplePoints if (samplePoints.size() < 3) { FatalErrorIn ( "timeVaryingMappedFixedValueFvPatchField<Type>::readSamplePoints()" ) << "Only " << samplePoints.size() << " points read from file " << samplePoints.objectPath() << nl << "Need at least three non-colinear samplePoints" << " to be able to interpolate." << "\n on patch " << this->patch().name() << " of points " << samplePoints.name() << " in file " << samplePoints.objectPath() << exit(FatalError); } const point& p0 = samplePoints[0]; // Find furthest away point vector e1; label index1 = -1; scalar maxDist = -GREAT; for (label i = 1; i < samplePoints.size(); i++) { const vector d = samplePoints[i] - p0; scalar magD = mag(d); if (magD > maxDist) { e1 = d/magD; index1 = i; maxDist = magD; } } // Find point that is furthest away from line p0-p1 const point& p1 = samplePoints[index1]; label index2 = -1; maxDist = -GREAT; for (label i = 1; i < samplePoints.size(); i++) { if (i != index1) { const point& p2 = samplePoints[i]; vector e2(p2 - p0); e2 -= (e2&e1)*e1; scalar magE2 = mag(e2); if (magE2 > maxDist) { index2 = i; maxDist = magE2; } } } if (index2 == -1) { FatalErrorIn ( "timeVaryingMappedFixedValueFvPatchField<Type>::readSamplePoints()" ) << "Cannot find points that make valid normal." << nl << "Have so far points " << p0 << " and " << p1 << "Need at least three sample points which are not in a line." << "\n on patch " << this->patch().name() << " of points " << samplePoints.name() << " in file " << samplePoints.objectPath() << exit(FatalError); } vector n = e1^(samplePoints[index2]-p0); n /= mag(n); if (debug) { Info<< "timeVaryingMappedFixedValueFvPatchField :" << " Used points " << p0 << ' ' << samplePoints[index1] << ' ' << samplePoints[index2] << " to define coordinate system with normal " << n << endl; } referenceCS_.reset ( new coordinateSystem ( "reference", p0, // origin n, // normal e1 // 0-axis ) ); tmp<vectorField> tlocalVertices ( referenceCS().localPosition(samplePoints) ); vectorField& localVertices = tlocalVertices(); const boundBox bb(localVertices, true); const point bbMid(bb.midpoint()); if (debug) { Info<< "timeVaryingMappedFixedValueFvPatchField :" << " Perturbing points with " << perturb_ << " fraction of a random position inside " << bb << " to break any ties on regular meshes." << nl << endl; } Random rndGen(123456); forAll(localVertices, i) { localVertices[i] += perturb_ *(rndGen.position(bb.min(), bb.max())-bbMid); }
void Foam::displacementSBRStressFvMotionSolver::updateMesh ( const mapPolyMesh& mpm ) { fvMotionSolver::updateMesh(mpm); // Map points0_ // Map points0_. Bit special since we somehow have to come up with // a sensible points0 position for introduced points. // Find out scaling between points0 and current points // Get the new points either from the map or the mesh const pointField& points = ( mpm.hasMotionPoints() ? mpm.preMotionPoints() : fvMesh_.points() ); // Note: boundBox does reduce const boundBox bb0(points0_, true); const vector span0(bb0.max()-bb0.min()); const boundBox bb(points, true); const vector span(bb.max()-bb.min()); vector scaleFactors(cmptDivide(span0, span)); pointField newPoints0(mpm.pointMap().size()); forAll(newPoints0, pointI) { label oldPointI = mpm.pointMap()[pointI]; if (oldPointI >= 0) { label masterPointI = mpm.reversePointMap()[oldPointI]; if (masterPointI == pointI) { newPoints0[pointI] = points0_[oldPointI]; } else { // New point. Assume motion is scaling. newPoints0[pointI] = points0_[oldPointI] + cmptMultiply ( scaleFactors, points[pointI]-points[masterPointI] ); } } else { FatalErrorIn ( "displacementSBRStressFvMotionSolver::updateMesh" "(const mapPolyMesh& mpm)" ) << "Cannot work out coordinates of introduced vertices." << " New vertex " << pointI << " at coordinate " << points[pointI] << exit(FatalError); } }