68 centres[0] = 0.5*(point1_ + point2_);
81 auto&
pts = tpts.ref();
93 const scalar nearestDistSqr
101 scalar parallel = (v & unitDir_);
104 v -= parallel*unitDir_;
105 scalar magV =
mag(v);
107 if (magV < ROOTVSMALL)
119 info.setPoint(point1_ +
min(magV, radius_)*v);
121 else if (parallel >= magDir_)
124 info.setPoint(point2_ +
min(magV, radius_)*v);
135 if (magV < ROOTVSMALL)
139 scalar magE1 =
mag(e1);
142 e1 =
point(0,1,0) ^ unitDir_;
146 cylPt = sample + radius_*e1;
150 cylPt = sample + (radius_-magV)*v;
153 if (parallel < 0.5*magDir_)
156 point end1Pt = point1_ +
min(magV, radius_)*v;
160 info.setPoint(cylPt);
164 info.setPoint(end1Pt);
170 point end2Pt = point2_ +
min(magV, radius_)*v;
174 info.setPoint(cylPt);
178 info.setPoint(end2Pt);
183 if (info.point().distSqr(sample) < nearestDistSqr)
193Foam::scalar Foam::searchableCylinder::radius2(
const point& pt)
const
195 const vector x = (pt-point1_) ^ unitDir_;
202void Foam::searchableCylinder::findLineAll
213 vector point1Start(start-point1_);
214 vector point2Start(start-point2_);
215 vector point1End(end-point1_);
218 scalar s1 = point1Start&unitDir_;
219 scalar s2 = point1End&unitDir_;
221 if ((s1 < 0 && s2 < 0) || (s1 > magDir_ && s2 > magDir_))
228 scalar magV =
mag(V);
229 if (magV < ROOTVSMALL)
245 scalar tNear = VGREAT;
246 scalar tFar = VGREAT;
249 scalar
s = (
V&unitDir_);
253 tPoint2 = -(point2Start&unitDir_)/
s;
254 if (tPoint2 < tPoint1)
256 std::swap(tPoint1, tPoint2);
258 if (tPoint1 > magV || tPoint2 < 0)
264 if (tPoint1 >= 0 && tPoint1 <= magV)
266 if (radius2(start+tPoint1*V) <=
sqr(radius_))
271 if (tPoint2 >= 0 && tPoint2 <= magV)
273 if (radius2(start+tPoint2*V) <=
sqr(radius_))
297 const vector x = point1Start ^ unitDir_;
299 const scalar d =
sqr(radius_);
302 const scalar a = (
y&
y);
303 const scalar
b = 2*(
x&
y);
304 const scalar
c = (
x&
x)-d;
306 const scalar disc =
b*
b-4*a*
c;
316 else if (disc < ROOTVSMALL)
319 if (
mag(a) > ROOTVSMALL)
327 if (t1 >= 0 && t1 <= magV && t1 >= tPoint1 && t1 <= tPoint2)
360 if (
mag(a) > ROOTVSMALL)
362 scalar sqrtDisc =
sqrt(disc);
364 t1 = (-
b - sqrtDisc)/(2*a);
365 t2 = (-
b + sqrtDisc)/(2*a);
371 if (t1 >= 0 && t1 <= magV && t1 >= tPoint1 && t1 <= tPoint2)
384 if (t2 >= 0 && t2 <= magV && t2 >= tPoint1 && t2 <= tPoint2)
418 if (tNear >= 0 && tNear <= magV)
420 near.hitPoint(start+tNear*V);
425 far.hitPoint(start+tFar*V);
429 else if (tFar >= 0 && tFar <= magV)
431 near.hitPoint(start+tFar*V);
437Foam::boundBox Foam::searchableCylinder::calcBounds()
const
487Foam::searchableCylinder::searchableCylinder
498 magDir_(
mag(point2_-point1_)),
499 unitDir_((point2_-point1_)/magDir_),
506Foam::searchableCylinder::searchableCylinder
515 magDir_(
mag(point2_-point1_)),
516 unitDir_((point2_-point1_)/magDir_),
517 radius_(
dict.get<scalar>(
"radius"))
527 if (regions_.empty())
530 regions_[0] =
"region0";
536void Foam::searchableCylinder::findNearest
540 List<pointIndexHit>& info
547 info[i] = findNearest(
samples[i], nearestDistSqr[i]);
556 List<pointIndexHit>& info
559 info.setSize(start.size());
565 findLineAll(start[i], end[i], info[i],
b);
566 if (!info[i].hit() &&
b.hit())
581 info.setSize(start.size());
587 findLineAll(start[i], end[i], info[i],
b);
588 if (!info[i].hit() &&
b.hit())
596void Foam::searchableCylinder::findLineAll
603 info.setSize(start.size());
608 findLineAll(start[i], end[i], near, far);
646 region.setSize(
info.size());
667 const scalar parallel = (v & unitDir_);
670 v -= parallel*unitDir_;
671 scalar magV =
mag(v);
675 if ((magV-radius_) <
mag(parallel))
678 normal[i] = -unitDir_;
685 else if (parallel <= 0.5*magDir_)
688 if (magV >= radius_ || (radius_-magV) < parallel)
695 normal[i] = -unitDir_;
698 else if (parallel <= magDir_)
701 if (magV >= radius_ || (radius_-magV) < (magDir_-parallel))
708 normal[i] = unitDir_;
713 if ((magV-radius_) < (parallel-magDir_))
716 normal[i] = unitDir_;
745 const scalar parallel = (v & unitDir_);
748 if (parallel < 0 || parallel > magDir_)
755 v -= parallel*unitDir_;
Macros for easy insertion into run-time selection tables.
#define addNamedToRunTimeSelectionTable(baseType, thisType, argNames, lookupName)
Add to construction table with 'lookupName' as the key.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Minimal example by using system/controlDict.functions:
Defines the attributes of an object for which implicit objectRegistry management is supported,...
InfoProxy< IOobject > info() const noexcept
Return info proxy, for printing information to a stream.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void setSize(label n)
Alias for resize().
bool hit() const noexcept
Is there a hit?
void size(const label n)
Older name for setAddressableSize.
A bounding box defined in terms of min/max extrema points.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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 getVolumeType(const pointField &points, List< volumeType > &volType) const
Determine type (inside/outside/mixed) for point.
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.
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....
virtual const boundBox & bounds() const
Return const reference to boundBox.
A class for managing temporary objects.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
@ OUTSIDE
A location outside the volume.
@ INSIDE
A location inside the volume.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.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))
const expr V(m.psi().mesh().V())
const dimensionedScalar c
Speed of light in a vacuum.
List< word > wordList
List of word.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
List< label > labelList
A List of labels.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Field< vector > vectorField
Specialisation of Field<T> for vector.
vector point
Point is a vector.
static constexpr const zero Zero
Global zero (0).
vectorField pointField
pointField is a vectorField.
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
#define forAll(list, i)
Loop across all elements in list.
scalarField samples(nIntervals, Zero)