| 435 | |
| 436 | |
| 437 | void 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 |
no test coverage detected