33 const Foam::scalar Foam::particle::negativeSpaceDisplacementFactor = 1.01;
45 void Foam::particle::stationaryTetReverseTransform
54 const vector ab = A.b() - A.a();
55 const vector ac = A.c() - A.a();
56 const vector ad = A.d() - A.a();
57 const vector bc = A.c() - A.b();
58 const vector bd = A.d() - A.b();
62 detA = ab & (ac ^ ad);
74 void Foam::particle::movingTetReverseTransform
76 const scalar fraction,
78 FixedList<scalar, 4>& detA,
79 FixedList<barycentricTensor, 3>& T
82 Pair<barycentricTensor> A = movingTetTransform(fraction);
84 const Pair<vector> ab(A[0].
b() - A[0].a(), A[1].
b() - A[1].a());
85 const Pair<vector> ac(A[0].
c() - A[0].a(), A[1].
c() - A[1].a());
86 const Pair<vector> ad(A[0].d() - A[0].a(), A[1].d() - A[1].a());
87 const Pair<vector> bc(A[0].
c() - A[0].
b(), A[1].
c() - A[1].
b());
88 const Pair<vector> bd(A[0].d() - A[0].
b(), A[1].d() - A[1].
b());
93 detA[0] = ab[0] & (ac[0] ^ ad[0]);
95 (ab[1] & (ac[0] ^ ad[0]))
96 + (ab[0] & (ac[1] ^ ad[0]))
97 + (ab[0] & (ac[0] ^ ad[1]));
99 (ab[0] & (ac[1] ^ ad[1]))
100 + (ab[1] & (ac[0] ^ ad[1]))
101 + (ab[1] & (ac[1] ^ ad[0]));
102 detA[3] = ab[1] & (ac[1] ^ ad[1]);
113 (bd[0] ^ bc[1]) + (bd[1] ^ bc[0]),
114 (ac[0] ^ ad[1]) + (ac[1] ^ ad[0]),
115 (ad[0] ^ ab[1]) + (ad[1] ^ ab[0]),
116 (ab[0] ^ ac[1]) + (ab[1] ^ ac[0])
128 void Foam::particle::reflect()
130 Swap(coordinates_.c(), coordinates_.d());
134 void Foam::particle::rotate(
const bool reverse)
138 scalar temp = coordinates_.b();
139 coordinates_.b() = coordinates_.c();
140 coordinates_.c() = coordinates_.d();
141 coordinates_.d() = temp;
145 scalar temp = coordinates_.d();
146 coordinates_.d() = coordinates_.c();
147 coordinates_.c() = coordinates_.b();
148 coordinates_.b() = temp;
153 void Foam::particle::changeTet(
const label tetTriI)
155 const bool isOwner = mesh_.faceOwner()[tetFacei_] == celli_;
157 const label firstTetPtI = 1;
158 const label lastTetPtI = mesh_.faces()[tetFacei_].size() - 2;
164 else if (tetTriI == 2)
168 if (tetPti_ == lastTetPtI)
180 if (tetPti_ == firstTetPtI)
191 else if (tetTriI == 3)
195 if (tetPti_ == firstTetPtI)
207 if (tetPti_ == lastTetPtI)
221 <<
"Changing tet without changing cell should only happen when the " 222 <<
"track is on triangle 1, 2 or 3." 228 void Foam::particle::changeFace(
const label tetTriI)
231 const triFace triOldIs(currentTetIndices().faceTriIs(mesh_));
237 sharedEdge = edge(triOldIs[1], triOldIs[2]);
239 else if (tetTriI == 2)
241 sharedEdge = edge(triOldIs[2], triOldIs[0]);
243 else if (tetTriI == 3)
245 sharedEdge = edge(triOldIs[0], triOldIs[1]);
250 <<
"Changing face without changing cell should only happen when the" 251 <<
" track is on triangle 1, 2 or 3." 254 sharedEdge = edge(-1, -1);
260 forAll(mesh_.cells()[celli_], cellFaceI)
262 const label newFaceI = mesh_.cells()[celli_][cellFaceI];
263 const class face& newFace = mesh_.faces()[newFaceI];
264 const label newOwner = mesh_.faceOwner()[newFaceI];
267 if (tetFacei_ == newFaceI)
275 const label edgeComp = newOwner == celli_ ? -1 : +1;
280 edgeI < newFace.size()
281 &&
edge::compare(sharedEdge, newFace.faceEdge(edgeI)) != edgeComp;
286 if (edgeI >= newFace.size())
292 const label newBaseI =
max(0, mesh_.tetBasePtIs()[newFaceI]);
293 edgeI = (edgeI - newBaseI + newFace.size()) % newFace.size();
298 edgeI =
min(
max(1, edgeI), newFace.size() - 2);
301 tetFacei_ = newFaceI;
311 <<
"The search for an edge-connected face and tet-point failed." 316 if (sharedEdge.otherVertex(triOldIs[1]) == -1)
320 else if (sharedEdge.otherVertex(triOldIs[2]) == -1)
326 const triFace triNewIs = currentTetIndices().faceTriIs(mesh_);
332 if (sharedEdge.otherVertex(triNewIs[1]) == -1)
336 else if (sharedEdge.otherVertex(triNewIs[2]) == -1)
343 void Foam::particle::changeCell()
346 const label ownerCellI = mesh_.faceOwner()[tetFacei_];
347 const bool isOwner = celli_ == ownerCellI;
348 celli_ = isOwner ? mesh_.faceNeighbour()[tetFacei_] : ownerCellI;
355 void Foam::particle::changeToMasterPatch()
357 label thisPatch = patch();
359 forAll(mesh_.cells()[celli_], cellFaceI)
362 const label otherFaceI = mesh_.cells()[celli_][cellFaceI];
363 if (facei_ == otherFaceI || mesh_.isInternalFace(otherFaceI))
371 const class face& thisFace = mesh_.faces()[facei_];
372 const class face& otherFace = mesh_.faces()[otherFaceI];
375 const label otherPatch =
376 mesh_.boundaryMesh().whichPatch(otherFaceI);
377 if (thisPatch > otherPatch)
380 thisPatch = otherPatch;
389 void Foam::particle::locate
394 const bool boundaryFail,
395 const string boundaryMsg
401 celli = mesh_.cellTree().findInside(position);
406 <<
"Cell not found for particle position " << position <<
"." 412 const vector displacement = position - mesh_.cellCentres()[celli_];
417 const class cell& c = mesh_.cells()[celli_];
418 label minF = 1, minTetFacei = -1, minTetPti = -1;
421 const class face& f = mesh_.faces()[c[cellTetFacei]];
422 for (
label tetPti = 1; tetPti < f.size() - 1; ++ tetPti)
425 tetFacei_ = c[cellTetFacei];
430 const scalar f = trackToTri(displacement, 0, tetTriI);
440 minTetFacei = tetFacei_;
449 tetFacei_ = minTetFacei;
453 track(displacement, 0);
470 if (direction ==
nullptr)
472 const polyPatch& p = mesh_.boundaryMesh()[patch()];
473 direction = &p.faceNormals()[p.whichFace(facei_)];
476 const vector n = *direction/
mag(*direction);
477 const vector sN = (displacement &
n)*n;
478 const vector sT = displacement - sN;
482 tetFacei_ = minTetFacei;
489 static label nWarnings = 0;
490 static const label maxNWarnings = 100;
491 if (nWarnings < maxNWarnings)
496 if (nWarnings == maxNWarnings)
499 <<
"Suppressing any further warnings about particles being " 500 <<
"located outside of the mesh." <<
endl;
514 const label tetFacei,
519 coordinates_(coordinates),
526 origId_(getNewParticleID())
538 coordinates_(- vGreat, - vGreat, - vGreat, - vGreat),
545 origId_(getNewParticleID())
553 "Particle initialised with a location outside of the mesh." 561 coordinates_(p.coordinates_),
563 tetFacei_(p.tetFacei_),
566 stepFraction_(p.stepFraction_),
567 origProc_(p.origProc_),
575 coordinates_(p.coordinates_),
577 tetFacei_(p.tetFacei_),
580 stepFraction_(p.stepFraction_),
581 origProc_(p.origProc_),
590 const vector& displacement,
591 const scalar fraction
609 const vector& displacement,
610 const scalar fraction
613 const scalar f =
trackToFace(displacement, fraction);
626 const vector& displacement,
627 const scalar fraction
638 f *=
trackToTri(f*displacement, f*fraction, tetTriI);
645 else if (tetTriI == 0)
662 const vector& displacement,
663 const scalar fraction,
668 const vector x1 = displacement;
674 <<
" along " << x1 <<
" to " << x0 + x1 <<
endl;
681 stationaryTetReverseTransform(centre, detA, T);
686 stationaryTetGeometry(o, b, v1, v2);
687 Info<<
"Tet points o=" << o <<
", b=" << b
688 <<
", v1=" << v1 <<
", v2=" << v2 <<
endl 689 <<
"Tet determinant = " << detA <<
endl 690 <<
"Start local coordinates = " << y0 <<
endl;
694 const scalar f = detA >= 0 ? 1 : negativeSpaceDisplacementFactor;
701 Info<<
"Local displacement = " << Tx1 <<
"/" << detA <<
endl;
706 scalar muH = std::isnormal(detA) && detA <= 0 ? vGreat : 1/detA;
707 for (
label i = 0; i < 4; ++ i)
709 if (std::isnormal(Tx1[i]) && Tx1[i] < 0)
711 scalar
mu = - y0[i]/Tx1[i];
715 Info<<
"Hit on tet face " << i <<
" at local coordinate " 716 << y0 + mu*Tx1 <<
", " << mu*detA*100 <<
"% of the " 717 <<
"way along the track" <<
endl;
720 if (0 <= mu && mu < muH)
732 for (
label i = 0; i < 4; ++ i)
751 Info<<
"Track hit tet face " << iH <<
" first" <<
endl;
755 Info<<
"Track hit no tet faces" <<
endl;
757 Info<<
"End local coordinates = " << yH <<
endl 759 <<
"Tracking displacement = " <<
position() - x0 <<
endl 760 << muH*detA*100 <<
"% of the step from " << stepFraction_ <<
" to " 761 << stepFraction_ + fraction <<
" completed" <<
endl <<
endl;
765 stepFraction_ += fraction*muH*detA;
767 return iH != -1 ? 1 - muH*detA : 0;
773 const vector& displacement,
774 const scalar fraction,
779 const vector x1 = displacement;
785 <<
" along " << x1 <<
" to " << x0 + x1 <<
endl;
792 movingTetReverseTransform(fraction, centre, detA, T);
797 movingTetGeometry(fraction, o, b, v1, v2);
798 Info<<
"Tet points o=" << o[0] <<
", b=" << b[0]
799 <<
", v1=" << v1[0] <<
", v2=" << v2[0] <<
endl 800 <<
"Tet determinant = " << detA[0] <<
endl 801 <<
"Start local coordinates = " << y0[0] <<
endl;
805 const scalar f = detA[0] >= 0 ? 1 : negativeSpaceDisplacementFactor;
808 const vector x0Rel = x0 - centre[0];
809 const vector x1Rel = f*x1 - centre[1];
812 cubicEqn detAEqn(
sqr(detA[0])*detA[3], detA[0]*detA[2], detA[1], 1);
815 ((x1Rel & T[2]) + detA[3]*yC)*
sqr(detA[0]);
817 ((x1Rel & T[1]) + (x0Rel & T[2]) + detA[2]*yC)*detA[0];
819 ((x1Rel & T[0]) + (x0Rel & T[1]) + detA[1]*yC);
824 hitEqn[i] =
cubicEqn(hitEqnA[i], hitEqnB[i], hitEqnC[i], hitEqnD[i]);
829 for (
label i = 0; i < 4; ++ i)
831 Info<< (i ?
" " :
"Hit equation ") << i <<
" = " 832 << hitEqn[i] <<
endl;
834 Info<<
" DetA equation = " << detA <<
endl;
839 scalar muH = std::isnormal(detA[0]) && detA[0] <= 0 ? vGreat : 1/detA[0];
840 for (
label i = 0; i < 4; ++ i)
844 for (
label j = 0; j < 3; ++ j)
852 hitEqn[0].value(mu[j]),
853 hitEqn[1].value(mu[j]),
854 hitEqn[2].value(mu[j]),
855 hitEqn[3].value(mu[j])
857 const scalar detAH = detAEqn.
value(mu[j]);
859 Info<<
"Hit on tet face " << i <<
" at local coordinate " 860 << yH/detAH <<
", " << mu[j]*detA[0]*100 <<
"% of the " 861 <<
"way along the track" <<
endl;
864 if (0 <= mu[j] && mu[j] < muH)
876 hitEqn[0].value(muH),
877 hitEqn[1].value(muH),
878 hitEqn[2].value(muH),
888 const scalar detAH = detAEqn.
value(muH);
889 if (!std::isnormal(detAH))
892 <<
"A moving tet collapsed onto a particle. This is not supported. " 893 <<
"The mesh is too poor, or the motion too severe, for particle " 899 for (
label i = 0; i < 4; ++ i)
915 stepFraction_ += fraction*muH*detA[0];
921 Info<<
"Track hit tet face " << iH <<
" first" <<
endl;
925 Info<<
"Track hit no tet faces" <<
endl;
927 Info<<
"End local coordinates = " << yH <<
endl 929 <<
"Tracking displacement = " <<
position() - x0 <<
endl 930 << muH*detA[0]*100 <<
"% of the step from " << stepFraction_
931 <<
" to " << stepFraction_ + fraction <<
" completed" <<
endl 935 return iH != -1 ? 1 - muH*detA[0] : 0;
941 const vector& displacement,
942 const scalar fraction,
1019 facei_ += ppp.
start();
1024 tetPti_ = mesh_.
faces()[tetFacei_].
size() - 1 - tetPti_;
1055 if (transform.
hasR())
1065 const vector pos(coordinates_.
b(), coordinates_.
c(), coordinates_.
d());
1069 tetFacei_ = mesh_.
cells()[celli_][0];
1085 movingTetReverseTransform(0, centre, detA, T);
1086 coordinates_ += (
pos - centre[0]) & T[0]/detA[0];
1093 stationaryTetReverseTransform(centre, detA, T);
1094 coordinates_ += (
pos - centre) & T/detA;
1102 const label procCell,
1103 const label procTetFace
1112 (mesh_.
faceOwner()[tetFacei_] == celli_)
1113 == (procMesh.
faceOwner()[procTetFace] == procCell)
1120 return procMesh.
faces()[procTetFace].
size() - 1 - tetPti_;
1137 "Particle mapped to a location outside of the mesh."
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
label origProc() const
Return the originating processor ID.
void correctAfterParallelTransfer(const label patchi, trackingData &td)
Convert processor patch addressing to the global equivalents.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
vector deviationFromMeshCentre() const
Get the displacement from the mesh centre. Used to correct the.
virtual bool separated() const
Are the planes separated.
bool moving() const
Is mesh moving.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A 1D vector of objects of type <T> with a fixed size <Size>.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label procTetPt(const polyMesh &procMesh, const label procCell, const label procTetFace) const
Return the tet point appropriate for decomposition or reconstruction.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
scalar trackToFace(const vector &displacement, const scalar fraction)
As particle::track, but stops when a face is hit.
void size(const label)
Override size to be inconsistent with allocated storage.
Tensor< Cmpt > T() const
Return transpose.
static int compare(const edge &, const edge &)
Compare edges.
scalar trackToTri(const vector &displacement, const scalar fraction, label &tetTriI)
As particle::trackToFace, but stops when a tet triangle is hit. On.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Cmpt cmptSum(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Ostream & endl(Ostream &os)
Add newline and flush stream.
The coupledPolyPatch is an abstract base class for patches that couple regions of the computational d...
dimensionedScalar y0(const dimensionedScalar &ds)
Templated storage for the roots of polynomial equations, plus flags to indicate the nature of the roo...
const cellList & cells() const
Vector< scalar > vector
A scalar version of the templated Vector.
Barycentric< scalar > barycentric
A scalar version of the templated Barycentric.
virtual void transformProperties(const tensor &T)
Transform the physical properties of the particle.
void replace(const direction, const Cmpt &)
scalar trackToCell(const vector &displacement, const scalar fraction)
As particle::track, but stops when a new cell is reached.
virtual const vectorField & separation() const
If the planes are separated the separation vector.
void prepareForInteractionListReferral(const vectorTensorTransform &transform)
Break the topology and store the particle position so that the.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
virtual const tensorField & forwardT() const
Return face transformation tensor.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
virtual bool parallel() const
Are the cyclic planes parallel.
dimensionedScalar pos(const dimensionedScalar &ds)
Cubic equation of the form a*x^3 + b*x^2 + c*x + d = 0.
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))
An ordered pair of two objects of type <T> with first() and second() elements.
const labelUList & faceCells() const
Return face-cell addressing.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
particle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components.
static int compare(const face &, const face &)
Compare faces.
void correctAfterInteractionListReferral(const label celli)
Correct the topology after referral. The particle may still be.
virtual const labelList & faceOwner() const
Return face owner.
void prepareForParallelTransfer()
Convert global addressing to the processor patch local equivalents.
virtual const faceList & faces() const
Return raw faces.
label origId() const
Return the particle ID on the originating processor.
void autoMap(const vector &position, const mapPolyMesh &mapper)
Map after a topology change.
bool onFace() const
Is the particle on a face?
const labelList & reverseCellMap() const
Reverse cell map.
defineTypeNameAndDebug(combustionModel, 0)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
BarycentricTensor< scalar > barycentricTensor
A scalar version of the templated BarycentricTensor.
const dimensionedScalar mu
Atomic mass unit.
scalar trackToMovingTri(const vector &displacement, const scalar fraction, label &tetTriI)
As particle::trackToTri, but for moving meshes.
#define WarningInFunction
Report a warning using Foam::Warning.
void type(const direction i, const roots::type t)
Set the type of the i-th root.
const dimensionedScalar c
Speed of light in a vacuum.
label start() const
Return start label of this patch in the polyMesh face list.
Templated 4x3 tensor derived from VectorSpace. Has 12 components. Can represent a barycentric transfo...
dimensioned< scalar > mag(const dimensioned< Type > &)
static label particleCount_
Cumulative particle counter - used to provode unique ID.
bool onInternalFace() const
Is the particle on an internal face?
Mesh consisting of general polyhedral cells.
scalar trackToStationaryTri(const vector &displacement, const scalar fraction, label &tetTriI)
As particle::trackToTri, but for stationary meshes.
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
scalar track(const vector &displacement, const scalar fraction)
Track along the displacement for a given fraction of the overall.
bool operator!=(const particle &, const particle &)
scalar value(const scalar x) const
Evaluate at x.
vector position() const
Return current particle position.
static const Vector< scalar > zero
label patch() const
Return the index of patch that the particle is on.