* @brief Computes the 4x4 metric matrix for the given 4-vector positions * * @param pos af::dim4(4, N) * @return af::array af::dim4(4, 4, 1, N) */
| 455 | * @return af::array af::dim4(4, 4, 1, N) |
| 456 | */ |
| 457 | af::array metric4(const af::array& pos) { |
| 458 | if (pos.dims()[0] != 4) |
| 459 | throw make_error("Arrays must have 4 principal coordinates"); |
| 460 | |
| 461 | auto dims = pos.dims(); |
| 462 | |
| 463 | af::array t = af::moddims(pos(0, af::span), 1, 1, dims[1]); |
| 464 | af::array r = af::moddims(pos(1, af::span), 1, 1, dims[1]); |
| 465 | af::array o = af::moddims(pos(2, af::span), 1, 1, dims[1]); |
| 466 | af::array p = af::moddims(pos(3, af::span), 1, 1, dims[1]); |
| 467 | |
| 468 | af::array gtt, gtr, gto, gtp, grt, grr, gro, grp, got, gor, goo, gop, gpt, |
| 469 | gpr, gpo, gpp; |
| 470 | |
| 471 | switch (scene) { |
| 472 | // ******* Kerr Black Hole Metric ******* |
| 473 | case Scene::ROTATE_BH: { |
| 474 | auto rs = 2.0 * M; |
| 475 | auto a = J / M; |
| 476 | auto delta = (r - rs) * r + a * a; |
| 477 | auto sigma = r * r + af::pow(a * af::cos(o), 2); |
| 478 | |
| 479 | gtt = 1.0 - r * rs / sigma; |
| 480 | gtr = af::constant(0.0, 1, 1, dims[1], f64); |
| 481 | gto = af::constant(0.0, 1, 1, dims[1], f64); |
| 482 | gtp = rs * r * a * af::pow(af::sin(o), 2.0) / sigma; |
| 483 | grr = -sigma / delta; |
| 484 | gro = af::constant(0.0, 1, 1, dims[1], f64); |
| 485 | grp = af::constant(0.0, 1, 1, dims[1], f64); |
| 486 | goo = -sigma; |
| 487 | gop = af::constant(0.0, 1, 1, dims[1], f64); |
| 488 | gpp = |
| 489 | -(r * r + a * a + rs * r * af::pow(a * af::sin(o), 2) / sigma) * |
| 490 | af::pow(af::sin(o), 2); |
| 491 | |
| 492 | break; |
| 493 | } |
| 494 | |
| 495 | // ******* Schwarzchild Black Hole Metric ******* |
| 496 | case Scene::STATIC_BH: { |
| 497 | gtt = 1.0 - 2.0 * M / r; |
| 498 | gtr = af::constant(0.0, 1, 1, dims[1], f64); |
| 499 | gto = af::constant(0.0, 1, 1, dims[1], f64); |
| 500 | gtp = af::constant(0.0, 1, 1, dims[1], f64); |
| 501 | grr = -1.0 / (1.0 - 2.0 * M / r); |
| 502 | gro = af::constant(0.0, 1, 1, dims[1], f64); |
| 503 | grp = af::constant(0.0, 1, 1, dims[1], f64); |
| 504 | goo = -r * r; |
| 505 | gop = af::constant(0.0, 1, 1, dims[1], f64); |
| 506 | gpp = -af::pow(r * af::sin(o), 2); |
| 507 | |
| 508 | break; |
| 509 | } |
| 510 | |
| 511 | // ******* Ellis Wormhole Metric ******* |
| 512 | case Scene::WORMHOLE: { |
| 513 | gtt = af::constant(1.0, 1, 1, dims[1], f64); |
| 514 | gtr = af::constant(0.0, 1, 1, dims[1], f64); |
no test coverage detected