46 void Foam::particle::stationaryTetReverseTransform
55 const vector ab = A.b() - A.a();
56 const vector ac = A.c() - A.a();
57 const vector ad = A.d() - A.a();
58 const vector bc = A.c() - A.b();
59 const vector bd = A.d() - A.b();
63 detA = ab & (ac ^ ad);
75 void Foam::particle::movingTetReverseTransform
77 const scalar fraction,
79 FixedList<scalar, 4>& detA,
80 FixedList<barycentricTensor, 3>& T
83 Pair<barycentricTensor> A = movingTetTransform(fraction);
85 const Pair<vector> ab(A[0].
b() - A[0].a(), A[1].
b() - A[1].a());
86 const Pair<vector> ac(A[0].
c() - A[0].a(), A[1].
c() - A[1].a());
87 const Pair<vector> ad(A[0].d() - A[0].a(), A[1].d() - A[1].a());
88 const Pair<vector> bc(A[0].
c() - A[0].
b(), A[1].
c() - A[1].
b());
89 const Pair<vector> bd(A[0].d() - A[0].
b(), A[1].d() - A[1].
b());
94 detA[0] = ab[0] & (ac[0] ^ ad[0]);
96 (ab[1] & (ac[0] ^ ad[0]))
97 + (ab[0] & (ac[1] ^ ad[0]))
98 + (ab[0] & (ac[0] ^ ad[1]));
100 (ab[0] & (ac[1] ^ ad[1]))
101 + (ab[1] & (ac[0] ^ ad[1]))
102 + (ab[1] & (ac[1] ^ ad[0]));
103 detA[3] = ab[1] & (ac[1] ^ ad[1]);
114 (bd[0] ^ bc[1]) + (bd[1] ^ bc[0]),
115 (ac[0] ^ ad[1]) + (ac[1] ^ ad[0]),
116 (ad[0] ^ ab[1]) + (ad[1] ^ ab[0]),
117 (ab[0] ^ ac[1]) + (ab[1] ^ ac[0])
129 void Foam::particle::reflect()
131 Swap(coordinates_.c(), coordinates_.d());
135 void Foam::particle::rotate(
const bool reverse)
139 scalar temp = coordinates_.b();
140 coordinates_.b() = coordinates_.c();
141 coordinates_.c() = coordinates_.d();
142 coordinates_.d() = temp;
146 scalar temp = coordinates_.d();
147 coordinates_.d() = coordinates_.c();
148 coordinates_.c() = coordinates_.b();
149 coordinates_.b() = temp;
154 void Foam::particle::changeTet(
const label tetTriI)
161 const bool isOwner = mesh_.faceOwner()[tetFacei_] == celli_;
163 const label firstTetPtI = 1;
164 const label lastTetPtI = mesh_.faces()[tetFacei_].size() - 2;
170 else if (tetTriI == 2)
174 if (tetPti_ == lastTetPtI)
186 if (tetPti_ == firstTetPtI)
197 else if (tetTriI == 3)
201 if (tetPti_ == firstTetPtI)
213 if (tetPti_ == lastTetPtI)
227 <<
"Changing tet without changing cell should only happen when the " 228 <<
"track is on triangle 1, 2 or 3." 234 void Foam::particle::changeFace(
const label tetTriI)
242 const triFace triOldIs(currentTetIndices().faceTriIs(mesh_));
248 sharedEdge = edge(triOldIs[1], triOldIs[2]);
250 else if (tetTriI == 2)
252 sharedEdge = edge(triOldIs[2], triOldIs[0]);
254 else if (tetTriI == 3)
256 sharedEdge = edge(triOldIs[0], triOldIs[1]);
261 <<
"Changing face without changing cell should only happen when the" 262 <<
" track is on triangle 1, 2 or 3." 265 sharedEdge = edge(-1, -1);
271 forAll(mesh_.cells()[celli_], cellFaceI)
273 const label newFaceI = mesh_.cells()[celli_][cellFaceI];
274 const class face& newFace = mesh_.faces()[newFaceI];
275 const label newOwner = mesh_.faceOwner()[newFaceI];
278 if (tetFacei_ == newFaceI)
286 const label edgeComp = newOwner == celli_ ? -1 : +1;
291 edgeI < newFace.size()
292 &&
edge::compare(sharedEdge, newFace.faceEdge(edgeI)) != edgeComp;
297 if (edgeI >= newFace.size())
303 const label newBaseI =
max(0, mesh_.tetBasePtIs()[newFaceI]);
304 edgeI = (edgeI - newBaseI + newFace.size()) % newFace.size();
309 edgeI =
min(
max(1, edgeI), newFace.size() - 2);
312 tetFacei_ = newFaceI;
322 <<
"The search for an edge-connected face and tet-point failed." 327 if (sharedEdge.otherVertex(triOldIs[1]) == -1)
331 else if (sharedEdge.otherVertex(triOldIs[2]) == -1)
337 const triFace triNewIs = currentTetIndices().faceTriIs(mesh_);
343 if (sharedEdge.otherVertex(triNewIs[1]) == -1)
347 else if (sharedEdge.otherVertex(triNewIs[2]) == -1)
354 void Foam::particle::changeCell()
362 const label ownerCellI = mesh_.faceOwner()[tetFacei_];
363 const bool isOwner = celli_ == ownerCellI;
364 celli_ = isOwner ? mesh_.faceNeighbour()[tetFacei_] : ownerCellI;
371 void Foam::particle::changeToMasterPatch()
378 label thisPatch = patch();
380 forAll(mesh_.cells()[celli_], cellFaceI)
383 const label otherFaceI = mesh_.cells()[celli_][cellFaceI];
384 if (facei_ == otherFaceI || mesh_.isInternalFace(otherFaceI))
392 const class face& thisFace = mesh_.faces()[facei_];
393 const class face& otherFace = mesh_.faces()[otherFaceI];
396 const label otherPatch =
397 mesh_.boundaryMesh().whichPatch(otherFaceI);
398 if (thisPatch > otherPatch)
401 thisPatch = otherPatch;
410 void Foam::particle::locate
414 const bool boundaryFail,
415 const string boundaryMsg
426 celli = mesh_.cellTree().findInside(position);
431 <<
"Cell not found for particle position " << position <<
"." 437 const vector displacement = position - mesh_.cellCentres()[celli_];
442 const class cell& c = mesh_.cells()[celli_];
443 scalar minF = vGreat;
444 label minTetFacei = -1, minTetPti = -1;
447 const class face& f = mesh_.faces()[c[cellTetFacei]];
448 for (
label tetPti = 1; tetPti < f.size() - 1; ++ tetPti)
451 tetFacei_ = c[cellTetFacei];
456 const scalar f = trackToTri(displacement, 0, tetTriI);
466 minTetFacei = tetFacei_;
475 tetFacei_ = minTetFacei;
479 track(displacement, 0);
492 static label nWarnings = 0;
493 static const label maxNWarnings = 100;
494 if (nWarnings < maxNWarnings)
499 if (nWarnings == maxNWarnings)
502 <<
"Suppressing any further warnings about particles being " 503 <<
"located outside of the mesh." <<
endl;
517 const label tetFacei,
522 coordinates_(coordinates),
531 origId_(getNewParticleID())
543 coordinates_(- vGreat, - vGreat, - vGreat, - vGreat),
552 origId_(getNewParticleID())
559 "Particle initialised with a location outside of the mesh." 567 coordinates_(p.coordinates_),
569 tetFacei_(p.tetFacei_),
572 stepFraction_(p.stepFraction_),
574 nBehind_(p.nBehind_),
575 origProc_(p.origProc_),
583 coordinates_(p.coordinates_),
585 tetFacei_(p.tetFacei_),
588 stepFraction_(p.stepFraction_),
590 nBehind_(p.nBehind_),
591 origProc_(p.origProc_),
600 const vector& displacement,
601 const scalar fraction
624 const vector& displacement,
625 const scalar fraction
633 const scalar f =
trackToFace(displacement, fraction);
646 const vector& displacement,
647 const scalar fraction
662 while (nBehind_ < maxNBehind_)
664 f *=
trackToTri(f*displacement, f*fraction, tetTriI);
671 else if (tetTriI == 0)
685 static label stuckID = -1, stuckProc = -1;
686 if (origId_ != stuckID && origProc_ != stuckProc)
689 <<
"Particle #" << origId_ <<
" got stuck at " <<
position()
694 stuckProc = origProc_;
696 stepFraction_ += f*fraction;
707 const vector& displacement,
708 const scalar fraction,
713 const vector x1 = displacement;
719 <<
" along " << x1 <<
" to " << x0 + x1 <<
endl;
726 stationaryTetReverseTransform(centre, detA, T);
731 stationaryTetGeometry(o, b, v1, v2);
732 Info<<
"Tet points o=" << o <<
", b=" << b
733 <<
", v1=" << v1 <<
", v2=" << v2 <<
endl 734 <<
"Tet determinant = " << detA <<
endl 735 <<
"Start local coordinates = " << y0 <<
endl;
743 Info<<
"Local displacement = " << Tx1 <<
"/" << detA <<
endl;
748 scalar muH = std::isnormal(detA) && detA <= 0 ? vGreat : 1/detA;
749 for (
label i = 0; i < 4; ++ i)
751 if (Tx1[i] < - detA*small)
753 scalar
mu = - y0[i]/Tx1[i];
757 Info<<
"Hit on tet face " << i <<
" at local coordinate " 758 << y0 + mu*Tx1 <<
", " << mu*detA*100 <<
"% of the " 759 <<
"way along the track" <<
endl;
762 if (0 <= mu && mu < muH)
774 for (
label i = 0; i < 4; ++ i)
793 Info<<
"Track hit tet face " << iH <<
" first" <<
endl;
797 Info<<
"Track hit no tet faces" <<
endl;
799 Info<<
"End local coordinates = " << yH <<
endl 801 <<
"Tracking displacement = " <<
position() - x0 <<
endl 802 << muH*detA*100 <<
"% of the step from " << stepFraction_ <<
" to " 803 << stepFraction_ + fraction <<
" completed" <<
endl <<
endl;
807 stepFraction_ += fraction*muH*detA;
810 if (detA <= 0 || nBehind_ > 0)
812 behind_ += muH*detA*
mag(displacement);
825 return iH != -1 ? 1 - muH*detA : 0;
831 const vector& displacement,
832 const scalar fraction,
837 const vector x1 = displacement;
843 <<
" along " << x1 <<
" to " << x0 + x1 <<
endl;
850 movingTetReverseTransform(fraction, centre, detA, T);
855 movingTetGeometry(fraction, o, b, v1, v2);
856 Info<<
"Tet points o=" << o[0] <<
", b=" << b[0]
857 <<
", v1=" << v1[0] <<
", v2=" << v2[0] <<
endl 858 <<
"Tet determinant = " << detA[0] <<
endl 859 <<
"Start local coordinates = " << y0[0] <<
endl;
863 const vector x0Rel = x0 - centre[0];
864 const vector x1Rel = x1 - centre[1];
867 cubicEqn detAEqn(
sqr(detA[0])*detA[3], detA[0]*detA[2], detA[1], 1);
870 ((x1Rel & T[2]) + detA[3]*yC)*
sqr(detA[0]);
872 ((x1Rel & T[1]) + (x0Rel & T[2]) + detA[2]*yC)*detA[0];
874 ((x1Rel & T[0]) + (x0Rel & T[1]) + detA[1]*yC);
879 hitEqn[i] =
cubicEqn(hitEqnA[i], hitEqnB[i], hitEqnC[i], hitEqnD[i]);
884 for (
label i = 0; i < 4; ++ i)
886 Info<< (i ?
" " :
"Hit equation ") << i <<
" = " 887 << hitEqn[i] <<
endl;
889 Info<<
" DetA equation = " << detA <<
endl;
894 scalar muH = std::isnormal(detA[0]) && detA[0] <= 0 ? vGreat : 1/detA[0];
895 for (
label i = 0; i < 4; ++ i)
899 for (
label j = 0; j < 3; ++ j)
904 && hitEqn[i].derivative(mu[j]) < - detA[0]*small
911 hitEqn[0].value(mu[j]),
912 hitEqn[1].value(mu[j]),
913 hitEqn[2].value(mu[j]),
914 hitEqn[3].value(mu[j])
916 const scalar detAH = detAEqn.
value(mu[j]);
918 Info<<
"Hit on tet face " << i <<
" at local coordinate " 919 << (std::isnormal(detAH) ?
name(yH/detAH) :
"???")
920 <<
", " << mu[j]*detA[0]*100 <<
"% of the " 921 <<
"way along the track" <<
endl;
924 if (0 <= mu[j] && mu[j] < muH)
936 hitEqn[0].value(muH),
937 hitEqn[1].value(muH),
938 hitEqn[2].value(muH),
948 const scalar detAH = detAEqn.
value(muH);
949 if (!std::isnormal(detAH))
952 <<
"A moving tet collapsed onto a particle. This is not supported. " 953 <<
"The mesh is too poor, or the motion too severe, for particle " 959 for (
label i = 0; i < 4; ++ i)
975 stepFraction_ += fraction*muH*detA[0];
978 if (detA[0] <= 0 || nBehind_ > 0)
980 behind_ += muH*detA[0]*
mag(displacement);
997 Info<<
"Track hit tet face " << iH <<
" first" <<
endl;
1001 Info<<
"Track hit no tet faces" <<
endl;
1003 Info<<
"End local coordinates = " << yH <<
endl 1005 <<
"Tracking displacement = " <<
position() - x0 <<
endl 1006 << muH*detA[0]*100 <<
"% of the step from " << stepFraction_
1007 <<
" to " << stepFraction_ + fraction <<
" completed" <<
endl 1011 return iH != -1 ? 1 - muH*detA[0] : 0;
1017 const vector& displacement,
1018 const scalar fraction,
1022 if (mesh_.
moving() && (stepFraction_ != 1 || fraction != 0))
1075 facei_ += ppp.
start();
1081 tetPti_ = mesh_.
faces()[tetFacei_].
size() - 1 - tetPti_;
1121 const vector pos(coordinates_.
b(), coordinates_.
c(), coordinates_.
d());
1125 tetFacei_ = mesh_.
cells()[celli_][0];
1136 if (mesh_.
moving() && stepFraction_ != 1)
1141 movingTetReverseTransform(0, centre, detA, T);
1142 coordinates_ += (
pos - centre[0]) & T[0]/detA[0];
1149 stationaryTetReverseTransform(centre, detA, T);
1150 coordinates_ += (
pos - centre) & T/detA;
1158 const label procCell,
1159 const label procTetFace
1168 (mesh_.
faceOwner()[tetFacei_] == celli_)
1169 == (procMesh.
faceOwner()[procTetFace] == procCell)
1176 return procMesh.
faces()[procTetFace].
size() - 1 - tetPti_;
1192 "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.
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)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
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.
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)
const dimensionedScalar b
Wien displacement law constant: default SI units: [m K].
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 const transformer & transform() const =0
Return transformation between the coupled patches.
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 void transformProperties(const transformer &)
Transform the physical properties of the particle.
const dimensionedScalar c
Speed of light in a vacuum.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const Vector< label > & geometricD() const
Return the vector of geometric directions in mesh.
dimensionedScalar pos(const dimensionedScalar &ds)
Cubic equation of the form a*x^3 + b*x^2 + c*x + d = 0.
void prepareForInteractionListReferral(const transformer &transform)
Break the topology and store the particle position so that the.
An ordered pair of two objects of type <T> with first() and second() elements.
const labelUList & faceCells() const
Return face-cell addressing.
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.
const dimensionedScalar mu
Atomic mass unit.
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.
word name(const complex &)
Return a string representation of a complex.
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.
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 provide 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.
void type(const direction i, const rootType t)
Set the type of the i-th root.