MCPcopy Create free account
hub / github.com/OpenFOAM/OpenFOAM-dev / locate

Function locate

src/lagrangian/basic/particle/particle.C:437–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435
436
437void Foam::particle::locate
438(
439 const vector& position,
440 const vector* direction,
441 const label celli,
442 const bool boundaryFail,
443 const string boundaryMsg
444)
445{
446 celli_ = celli;
447
448 // Find the cell, if it has not been given
449 if (celli_ < 0)
450 {
451 celli_ = mesh_.cellTree().findInside(position);
452 }
453 if (celli_ < 0)
454 {
455 FatalErrorInFunction
456 << "Cell not found for particle position " << position << "."
457 << exit(FatalError);
458 }
459
460 // Put the particle at the cell centre and in a random tet
461 coordinates_ = barycentric(1, 0, 0, 0);
462 tetFacei_ = mesh_.cells()[celli_][0];
463 tetPti_ = 1;
464 facei_ = -1;
465
466 // Track to the injection point
467 track(position - mesh_.cellCentres()[celli_], 0);
468 if (!onFace())
469 {
470 return;
471 }
472
473 // We hit a boundary ...
474 if (boundaryFail)
475 {
476 FatalErrorInFunction << boundaryMsg << exit(FatalError);
477 }
478 else
479 {
480 // Re-do the track, but this time do the bit tangential to the
481 // direction/patch first. This gets us as close as possible to the
482 // original path/position.
483
484 if (direction == nullptr)
485 {
486 const polyPatch& p = mesh_.boundaryMesh()[patch()];
487 direction = &p.faceNormals()[p.whichFace(facei_)];
488 }
489
490 const vector n = *direction/mag(*direction);
491 const vector s = position - mesh_.cellCentres()[celli_];
492 const vector sN = (s & n)*n;
493 const vector sT = s - sN;
494

Callers 4

barycentricCoordsFunction · 0.85
autoMapFunction · 0.85

Calls 4

whichFaceMethod · 0.80
exitFunction · 0.50
trackFunction · 0.50
magClass · 0.50

Tested by

no test coverage detected