-
Notifications
You must be signed in to change notification settings - Fork 25
[Phys][GRSPH] Add metric terms #1552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
y-lapeyre
wants to merge
26
commits into
Shamrock-code:main
Choose a base branch
from
y-lapeyre:GR/RHS
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
2af27f4
add Kerr basis
y-lapeyre b09bf76
authors
y-lapeyre 872650e
add a tag dispatch
y-lapeyre 3b87262
Merge branch 'main' into GR/RHS
y-lapeyre ab2cc36
add metric params in struct
y-lapeyre 9b95b00
Merge branch 'GR/RHS' of github.com:y-lapeyre/Shamrock into GR/RHS
y-lapeyre ab8d786
Merge branch 'main' into GR/RHS
y-lapeyre 80e26b8
[gh-action] trigger CI with empty commit
github-actions[bot] 73afce8
Merge branch 'main' into GR/RHS
y-lapeyre a6c2863
move to mdspan type for the metric
y-lapeyre 777133d
add GR utils
y-lapeyre 7c62866
[autofix.ci] automatic fix: pre-commit hooks
autofix-ci[bot] d8087e2
implemented utils
y-lapeyre 4a6d358
Merge branch 'GR/RHS' of github.com:y-lapeyre/Shamrock into GR/RHS
y-lapeyre a5cda85
get ADM components
y-lapeyre 0af5a27
fix typos and bad calls
y-lapeyre 5aad031
Merge branch 'main' into GR/RHS
y-lapeyre d794403
fix typo
y-lapeyre 3250afc
Merge branch 'GR/RHS' of github.com:y-lapeyre/Shamrock into GR/RHS
y-lapeyre 6b4825e
incorporate reviews
y-lapeyre 3ac5486
Merge branch 'main' into GR/RHS
y-lapeyre b641a16
add beta, gamma_ij
y-lapeyre c264e22
fix typos and wrong indexes
y-lapeyre 51ad55f
[gh-action] trigger CI with empty commit
github-actions[bot] 35f0c62
[autofix.ci] automatic fix: pre-commit hooks
autofix-ci[bot] 851b9d4
fix typos + add doc
y-lapeyre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,274 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // SHAMROCK code for hydrodynamics | ||
| // Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me> | ||
| // SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1 | ||
| // Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information | ||
| // | ||
| // -------------------------------------------------------// | ||
|
|
||
| #pragma once | ||
|
|
||
| /** | ||
| * @file GRUtils.hpp | ||
| * @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) | ||
| * @brief | ||
| */ | ||
|
|
||
| #include "shambase/aliases_int.hpp" | ||
| #include "shambase/assert.hpp" | ||
| #include "shambackends/math.hpp" | ||
| #include "shamunits/Constants.hpp" | ||
| #include <experimental/mdspan> | ||
| #include <shambackends/sycl.hpp> | ||
|
|
||
| namespace shamphys { | ||
|
|
||
| template< | ||
| class Tvec, | ||
| class Tscal, | ||
| class SizeType, | ||
| class Layout1, | ||
| class Layout2, | ||
| class Accessor1, | ||
| class Accessor2> | ||
| struct GR_physics { | ||
|
|
||
| /** | ||
| * @brief Compute the alpha factor from the spacetime metric. | ||
| * | ||
| * Alpha is defined as 1 / sqrt(-g00) where g00 is the | ||
| * 0,0 component of the spacetime metric. | ||
| * | ||
| * @param gcon The spacetime metric as a 4x4 matrix. | ||
| * @return The alpha factor. | ||
| */ | ||
| inline static constexpr Tscal get_alpha( | ||
| std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcon) { | ||
| // alpha = 1 / sqrt(-g00) | ||
| return 1. / sycl::sqrt(-gcon(0, 0)); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the betaUP factor from the spacetime metric. | ||
| * | ||
| * BetaUP is defined as (g01, g02, g03) / (alpha^2) where | ||
| * g0i is the i-th component of the first row of the spacetime | ||
| * metric and alpha is the Lorentz factor. | ||
| * | ||
| * @param gcon The spacetime metric as a 4x4 matrix. | ||
| * @return The betaUP factor. | ||
| */ | ||
| inline static constexpr Tvec get_betaUP( | ||
| std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcon) { | ||
| Tscal alpha = get_alpha(gcon); | ||
| Tscal alpha2 = alpha * alpha; | ||
| Tvec betaUP = {0., 0., 0.}; | ||
|
|
||
| betaUP[0] = gcon(0, 1) * alpha2; | ||
| betaUP[1] = gcon(0, 2) * alpha2; | ||
| betaUP[2] = gcon(0, 3) * alpha2; | ||
|
|
||
| return betaUP; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the betaDOWN factor from the spacetime metric. | ||
| * | ||
| * BetaDOWN is defined as (g01, g02, g03) where g0i is the i-th | ||
| * component of the first row of the spacetime metric. | ||
| * | ||
| * @param gcov The spacetime metric as a 4x4 matrix. | ||
| * @return The betaDOWN factor. | ||
| */ | ||
| inline static constexpr Tvec get_betaDOWN( | ||
| std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcov) { | ||
| Tvec betaDOWN = {0., 0., 0.}; | ||
|
|
||
| betaDOWN[0] = gcov(0, 1); | ||
| betaDOWN[1] = gcov(0, 2); | ||
| betaDOWN[2] = gcov(0, 3); | ||
|
|
||
| return betaDOWN; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the dot product of two vectors in the spacetime metric. | ||
| * | ||
| * @param a The first vector. | ||
| * @param b The second vector. | ||
| * @param gcov The spacetime metric as a 4x4 matrix. | ||
| * @return The dot product of the two vectors in the spacetime metric. | ||
| */ | ||
| inline static constexpr Tscal GR_dot( | ||
| Tvec a, | ||
| Tvec b, | ||
| std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcov) { | ||
|
|
||
| Tscal result = 0; | ||
| for (int i = 0; i < 4; i++) { | ||
| for (int j = 0; j < 4; j++) { | ||
| result += gcov(i + 1, j + 1) * a[i] * b[j]; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the dot product of two spatial vectors in the spacetime metric. | ||
| * | ||
| * @param a The first spatial vector. | ||
| * @param b The second spatial vector. | ||
| * @param gamma_ij The spatial part of the spacetime metric as a 3x3 matrix. | ||
| * @return The dot product of the two spatial vectors in the spacetime metric. | ||
| */ | ||
| inline static constexpr Tscal GR_dot_spatial( | ||
| Tvec a, | ||
| Tvec b, | ||
| std::mdspan<Tscal, std::extents<SizeType, 3, 3>, Layout2, Accessor2> gamma_ij) { | ||
|
|
||
| Tscal result = 0; | ||
| for (int i = 0; i < 3; i++) { | ||
| for (int j = 0; j < 3; j++) { | ||
| result += gamma_ij(i + 1, j + 1) * a[i] * b[j]; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the spatial part of the spacetime metric from the full 4x4 metric. | ||
| * | ||
| * @param gcov The spacetime metric as a 4x4 matrix. | ||
| * @return The spatial part of the spacetime metric as a 3x3 matrix. | ||
| */ | ||
| inline static constexpr std::mdspan<Tscal, std::extents<SizeType, 3, 3>, Layout2, Accessor2> | ||
| get_gammaijDOWN(std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcov) { | ||
|
|
||
| std::mdspan<Tscal, std::extents<SizeType, 3, 3>, Layout2, Accessor2> gamma_ij; | ||
| for (int i = 1; i < 4; i++) { | ||
| for (int j = 1; j < 4; j++) { | ||
| gamma_ij(i - 1, j - 1) = gcov(i, j); | ||
| } | ||
| } | ||
|
|
||
| return gamma_ij; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the contravariant spatial part of the spacetime metric from the full 4x4 | ||
| * metric. | ||
| * | ||
| * @param gcon The spacetime metric as a 4x4 matrix. | ||
| * @return The contravariant spatial part of the spacetime metric as a 3x3 matrix. | ||
| */ | ||
| inline static constexpr std::mdspan<Tscal, std::extents<SizeType, 3, 3>, Layout2, Accessor2> | ||
| get_gammaijUP(std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcon) { | ||
|
|
||
| Tscal alpha = get_alpha(gcon); | ||
| Tvec betaUP = get_betaUP(gcon); | ||
| std::mdspan<Tscal, std::extents<SizeType, 3, 3>, Layout2, Accessor2> gamma_ij; | ||
| for (int i = 1; i < 4; i++) { | ||
| for (int j = 1; j < 4; j++) { | ||
| gamma_ij(i - 1, j - 1) | ||
| = gcon(i, j) + betaUP[i - 1] * betaUP[j - 1] / (-gcon(0, 0)); | ||
| } | ||
| } | ||
|
|
||
| return gamma_ij; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the determinant of the spatial part of the spacetime metric. | ||
| * | ||
| * This function takes a 3x3 matrix representing the spatial part of the | ||
| * spacetime metric and returns its determinant. | ||
| * | ||
| * @param gamma_ij The spatial part of the spacetime metric as a 3x3 matrix. | ||
| * @return The determinant of the spatial part of the spacetime metric. | ||
| */ | ||
| inline static constexpr Tscal get_gamma( | ||
| std::mdspan<Tscal, std::extents<SizeType, 3, 3>, Layout2, Accessor2> gamma_ij) { | ||
|
|
||
| return mat_det_33(gamma_ij); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the Lorentz factor of a fluid element given its momentum and the spacetime | ||
| * metric. | ||
| * | ||
| * This function takes the momentum of a fluid element, its enthalpy, and the spacetime | ||
| * metric as inputs and returns the Lorentz factor of the fluid element. | ||
| * | ||
| * @param momentum The momentum of the fluid element. | ||
| * @param enthalpy The enthalpy of the fluid element. | ||
| * @param gcov The spacetime metric as a 4x4 matrix. | ||
| * @return The Lorentz factor of the fluid element. | ||
| */ | ||
| inline static constexpr Tscal get_lorentz_factor( | ||
| Tvec momentum, | ||
| Tscal enthalpy, | ||
| std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcov) { | ||
|
|
||
| return sycl::sqrt(1. + GR_dot(momentum, momentum, gcov) / (enthalpy * enthalpy)); | ||
| } | ||
|
|
||
| /// @brief Compute the time component of the 4-velocity of a fluid element given its | ||
| /// momentum, enthalpy, and the spacetime metric. | ||
| /// | ||
| /// This function takes the momentum of a fluid element, its enthalpy, and the spacetime | ||
| /// metric as inputs and returns the time component of the 4-velocity of the fluid element. | ||
| /// | ||
| /// @param momentum The momentum of the fluid element. | ||
| /// @param enthalpy The enthalpy of the fluid element. | ||
| /// @param gcon The spacetime metric as a 4x4 matrix. | ||
| /// @param gcov The spacetime metric as a 4x4 matrix. | ||
| /// @return The time component of the 4-velocity of the fluid element. | ||
| inline static constexpr Tscal get_U0( | ||
| Tvec momentum, | ||
| Tscal enthalpy, | ||
| std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcon, | ||
| std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcov) { | ||
|
|
||
| Tscal alpha = get_alpha(gcon); | ||
| Tscal lorentz_factor = get_lorentz_factor(momentum, enthalpy, gcov); | ||
| return lorentz_factor / alpha; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Compute the fluid velocity in the local rest frame. | ||
| * | ||
| * This function takes the fluid velocity in the global frame and the spacetime metric as | ||
| * inputs and returns the fluid velocity in the local rest frame. | ||
| * | ||
| * @param vxyz The fluid velocity in the global frame. | ||
| * @param gcon The spacetime metric as a 4x4 matrix. | ||
| * @return The fluid velocity in the local rest frame. | ||
| */ | ||
| inline static constexpr Tvec get_V( | ||
| Tvec vxyz, std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcon) { | ||
| Tscal alpha = get_alpha(gcon); | ||
| Tvec betaUP = get_betaUP(gcon); | ||
| Tvec V = (vxyz + betaUP) / alpha; | ||
|
|
||
| return V; | ||
| } | ||
|
|
||
| /// placeholder function for more complex metrics | ||
| inline static constexpr Tscal get_sqrt_g( | ||
| Tvec vxyz, std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcov) { | ||
| // for unusual metric, need to compute the determinant | ||
| // for now (Kerr), this is enough | ||
| return 1; | ||
| } | ||
|
|
||
| /// placeholder function for more complex metrics | ||
| inline static constexpr Tscal get_sqrt_gamma( | ||
y-lapeyre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Tvec vxyz, std::mdspan<Tscal, std::extents<SizeType, 4, 4>, Layout2, Accessor2> gcov) { | ||
| // for unusual metric, need to compute the determinant of the spatial metric | ||
| // for now (Kerr), this is enough | ||
| return 1; | ||
| } | ||
| }; | ||
|
|
||
| } // namespace shamphys | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.