55 centres[0] = 0.5*(point1_ + point2_);
80 const scalar nearestDistSqr
85 vector v(sample - point1_);
88 scalar parallel = (v & unitDir_);
91 v -= parallel*unitDir_;
94 if (magV < rootVSmall)
106 info.setPoint(point1_ +
min(magV, radius_)*v);
108 else if (parallel >= magDir_)
111 info.setPoint(point2_ +
min(magV, radius_)*v);
122 if (magV < rootVSmall)
126 scalar magE1 =
mag(e1);
129 e1 =
point(0,1,0) ^ unitDir_;
133 cylPt = sample + radius_*e1;
137 cylPt = sample + (radius_-magV)*v;
140 if (parallel < 0.5*magDir_)
143 point end1Pt = point1_ +
min(magV, radius_)*v;
147 info.setPoint(cylPt);
151 info.setPoint(end1Pt);
157 point end2Pt = point2_ +
min(magV, radius_)*v;
161 info.setPoint(cylPt);
165 info.setPoint(end2Pt);
170 if (
magSqr(sample - info.rawPoint()) < nearestDistSqr)
180 Foam::scalar Foam::searchableCylinder::radius2(
const point& pt)
const
182 const vector x = (pt-point1_) ^ unitDir_;
189 void Foam::searchableCylinder::findLineAll
200 vector point1Start(start-point1_);
201 vector point2Start(start-point2_);
202 vector point1End(end-point1_);
205 scalar s1 = point1Start&unitDir_;
206 scalar s2 = point1End&unitDir_;
208 if ((s1 < 0 && s2 < 0) || (s1 > magDir_ && s2 > magDir_))
215 scalar magV =
mag(V);
216 if (magV < rootVSmall)
232 scalar tNear = vGreat;
233 scalar tFar = vGreat;
236 scalar
s = (V&unitDir_);
240 tPoint2 = -(point2Start&unitDir_)/
s;
241 if (tPoint2 < tPoint1)
243 Swap(tPoint1, tPoint2);
245 if (tPoint1 > magV || tPoint2 < 0)
251 if (tPoint1 >= 0 && tPoint1 <= magV)
253 if (radius2(start+tPoint1*V) <=
sqr(radius_))
258 if (tPoint2 >= 0 && tPoint2 <= magV)
260 if (radius2(start+tPoint2*V) <=
sqr(radius_))
284 const vector x = point1Start ^ unitDir_;
286 const scalar d =
sqr(radius_);
289 const scalar a = (
y&
y);
290 const scalar
b = 2*(
x&
y);
291 const scalar
c = (
x&
x)-d;
293 const scalar disc =
b*
b-4*a*
c;
303 else if (disc < rootVSmall)
306 if (
mag(a) > rootVSmall)
314 if (t1 >= 0 && t1 <= magV && t1 >= tPoint1 && t1 <= tPoint2)
347 if (
mag(a) > rootVSmall)
349 scalar sqrtDisc =
sqrt(disc);
351 t1 = (-
b - sqrtDisc)/(2*a);
352 t2 = (-
b + sqrtDisc)/(2*a);
358 if (t1 >= 0 && t1 <= magV && t1 >= tPoint1 && t1 <= tPoint2)
371 if (t2 >= 0 && t2 <= magV && t2 >= tPoint1 && t2 <= tPoint2)
405 if (tNear >= 0 && tNear <= magV)
407 near.setPoint(start+tNear*V);
413 far.setPoint(start+tFar*V);
418 else if (tFar >= 0 && tFar <= magV)
420 near.setPoint(start+tFar*V);
471 return boundBox(
min,
max);
488 magDir_(
mag(point2_-point1_)),
489 unitDir_((point2_-point1_)/magDir_),
505 magDir_(
mag(point2_ - point1_)),
506 unitDir_((point2_ - point1_)/magDir_),
523 if (regions_.empty())
526 regions_[0] =
"region0";
532 void Foam::searchableCylinder::findNearest
543 info[i] = findNearest(
samples[i], nearestDistSqr[i]);
561 findLineAll(start[i], end[i], info[i],
b);
562 if (!info[i].hit() &&
b.hit())
583 findLineAll(start[i], end[i], info[i],
b);
584 if (!info[i].hit() &&
b.hit())
592 void Foam::searchableCylinder::findLineAll
599 info.setSize(start.
size());
604 findLineAll(start[i], end[i], near, far);
660 vector v(info[i].hitPoint() - point1_);
663 scalar parallel = (v & unitDir_);
666 v -= parallel*unitDir_;
667 scalar magV =
mag(v);
671 if ((magV-radius_) <
mag(parallel))
674 normal[i] = -unitDir_;
681 else if (parallel <= 0.5*magDir_)
684 if (magV >= radius_ || (radius_-magV) < parallel)
691 normal[i] = -unitDir_;
694 else if (parallel <= magDir_)
697 if (magV >= radius_ || (radius_-magV) < (magDir_-parallel))
704 normal[i] = unitDir_;
709 if ((magV-radius_) < (parallel-magDir_))
712 normal[i] = unitDir_;
740 scalar parallel = v & unitDir_;
747 else if (parallel > magDir_)
755 v -= parallel*unitDir_;
757 if (
mag(v) > radius_)
#define forAll(list, i)
Loop across all elements in list.
Macros for easy insertion into run-time selection tables.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
bool hit() const
Is there a hit.
A bounding box defined in terms of the points at its extremities.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Surface geometry with a cylinder shape, which can be used with snappyHexMesh.
virtual void getVolumeType(const pointField &, List< volumeType > &) const
Determine type (inside/outside/mixed) for point. unknown if.
searchableCylinder(const IOobject &io, const point &, const point &, const scalar radius)
Construct from components.
virtual void findLine(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Find first intersection on segment from start to end.
virtual void findLineAny(const pointField &start, const pointField &end, List< pointIndexHit > &) const
Return any intersection on segment from start to end.
virtual void boundingSpheres(pointField ¢res, scalarField &radiusSqr) const
Get bounding spheres (centre and radius squared), one per element.
virtual void getNormal(const List< pointIndexHit > &, vectorField &normal) const
From a set of points and indices get the normal.
virtual void getRegion(const List< pointIndexHit > &, labelList ®ion) const
From a set of points and indices get the region.
virtual ~searchableCylinder()
Destructor.
virtual const wordList & regions() const
Names of regions.
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
virtual tmp< pointField > points() const
Get the points that define the surface.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
const boundBox & bounds() const
Return const reference to boundBox.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const dimensionedScalar c
Speed of light in a vacuum.
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
PointIndexHit< point > pointIndexHit
const dimensionSet dimLength
vectorField pointField
pointField is a vectorField.
vector point
Point is a vector.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
Vector< scalar > vector
A scalar version of the templated Vector.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
scalarField samples(nIntervals, 0)