33 namespace searchableSurfaces
74 centres[0] = 0.5*(point1_ + point2_);
99 const scalar nearestDistSqr
104 vector v(sample - point1_);
107 scalar parallel = (v & unitDir_);
110 v -= parallel*unitDir_;
111 scalar magV =
mag(v);
113 if (magV < rootVSmall)
125 info.setPoint(point1_ +
min(magV, radius_)*v);
127 else if (parallel >= magDir_)
130 info.setPoint(point2_ +
min(magV, radius_)*v);
141 if (magV < rootVSmall)
145 scalar magE1 =
mag(e1);
148 e1 =
point(0,1,0) ^ unitDir_;
152 cylPt = sample + radius_*e1;
156 cylPt = sample + (radius_-magV)*v;
159 if (parallel < 0.5*magDir_)
162 point end1Pt = point1_ +
min(magV, radius_)*v;
166 info.setPoint(cylPt);
170 info.setPoint(end1Pt);
176 point end2Pt = point2_ +
min(magV, radius_)*v;
180 info.setPoint(cylPt);
184 info.setPoint(end2Pt);
189 if (
magSqr(sample - info.rawPoint()) < nearestDistSqr)
199 Foam::scalar Foam::searchableSurfaces::cylinder::radius2(
const point& pt)
const
201 const vector x = (pt-point1_) ^ unitDir_;
208 void Foam::searchableSurfaces::cylinder::findLineAll
219 vector point1Start(start-point1_);
220 vector point2Start(start-point2_);
221 vector point1End(end-point1_);
224 scalar s1 = point1Start&unitDir_;
225 scalar s2 = point1End&unitDir_;
227 if ((s1 < 0 && s2 < 0) || (s1 > magDir_ && s2 > magDir_))
234 scalar magV =
mag(V);
235 if (magV < rootVSmall)
251 scalar tNear = vGreat;
252 scalar tFar = vGreat;
255 scalar
s = (V&unitDir_);
259 tPoint2 = -(point2Start&unitDir_)/
s;
260 if (tPoint2 < tPoint1)
262 Swap(tPoint1, tPoint2);
264 if (tPoint1 > magV || tPoint2 < 0)
270 if (tPoint1 >= 0 && tPoint1 <= magV)
272 if (radius2(start+tPoint1*V) <=
sqr(radius_))
277 if (tPoint2 >= 0 && tPoint2 <= magV)
279 if (radius2(start+tPoint2*V) <=
sqr(radius_))
303 const vector x = point1Start ^ unitDir_;
305 const scalar d =
sqr(radius_);
308 const scalar a = (
y&
y);
309 const scalar
b = 2*(
x&
y);
310 const scalar
c = (
x&
x)-d;
312 const scalar disc =
b*
b-4*a*
c;
322 else if (disc < rootVSmall)
325 if (
mag(a) > rootVSmall)
333 if (t1 >= 0 && t1 <= magV && t1 >= tPoint1 && t1 <= tPoint2)
366 if (
mag(a) > rootVSmall)
368 scalar sqrtDisc =
sqrt(disc);
370 t1 = (-
b - sqrtDisc)/(2*a);
371 t2 = (-
b + sqrtDisc)/(2*a);
377 if (t1 >= 0 && t1 <= magV && t1 >= tPoint1 && t1 <= tPoint2)
390 if (t2 >= 0 && t2 <= magV && t2 >= tPoint1 && t2 <= tPoint2)
424 if (tNear >= 0 && tNear <= magV)
426 near.setPoint(start+tNear*V);
432 far.setPoint(start+tFar*V);
437 else if (tFar >= 0 && tFar <= magV)
439 near.setPoint(start+tFar*V);
446 Foam::boundBox Foam::searchableSurfaces::cylinder::calcBounds()
const
490 return boundBox(
min,
max);
507 magDir_(
mag(point2_-point1_)),
508 unitDir_((point2_-point1_)/magDir_),
524 magDir_(
mag(point2_ - point1_)),
525 unitDir_((point2_ - point1_)/magDir_),
542 if (regions_.empty())
545 regions_[0] =
"region0";
551 void Foam::searchableSurfaces::cylinder::findNearest
562 info[i] = findNearest(
samples[i], nearestDistSqr[i]);
580 findLineAll(start[i], end[i], info[i],
b);
581 if (!info[i].hit() &&
b.hit())
602 findLineAll(start[i], end[i], info[i],
b);
603 if (!info[i].hit() &&
b.hit())
611 void Foam::searchableSurfaces::cylinder::findLineAll
618 info.setSize(start.
size());
623 findLineAll(start[i], end[i], near, far);
679 vector v(info[i].hitPoint() - point1_);
682 scalar parallel = (v & unitDir_);
685 v -= parallel*unitDir_;
686 scalar magV =
mag(v);
690 if ((magV-radius_) <
mag(parallel))
693 normal[i] = -unitDir_;
700 else if (parallel <= 0.5*magDir_)
703 if (magV >= radius_ || (radius_-magV) < parallel)
710 normal[i] = -unitDir_;
713 else if (parallel <= magDir_)
716 if (magV >= radius_ || (radius_-magV) < (magDir_-parallel))
723 normal[i] = unitDir_;
728 if ((magV-radius_) < (parallel-magDir_))
731 normal[i] = unitDir_;
759 scalar parallel = v & unitDir_;
766 else if (parallel > magDir_)
774 v -= parallel*unitDir_;
776 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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
const boundBox & bounds() const
Return const reference to boundBox.
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.
virtual ~cylinder()
Destructor.
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 const wordList & regions() const
Names of regions.
cylinder(const IOobject &io, const point &, const point &, const scalar radius)
Construct from components.
virtual tmp< pointField > coordinates() const
Get representative set of element coordinates.
virtual tmp< pointField > points() const
Get the points that define the surface.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const dimensionedScalar c
Speed of light in a vacuum.
addToRunTimeSelectionTable(searchableSurface, box, dictionary)
defineTypeNameAndDebug(box, 0)
addBackwardCompatibleToRunTimeSelectionTable(searchableSurface, box, dictionary, searchableBox, "searchableBox")
PointIndexHit< point > pointIndexHit
const dimensionSet dimLength
vectorField pointField
pointField is a vectorField.
vector point
Point is a vector.
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
Vector< scalar > vector
A scalar version of the templated Vector.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void sqr(LagrangianPatchField< typename outerProduct< Type, Type >::type > &f, const LagrangianPatchField< Type > &f1)
void magSqr(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
scalarField samples(nIntervals, 0)