-
Notifications
You must be signed in to change notification settings - Fork 32
[GRSPH] Conservative to primitive variable swap module #1657
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
14
commits into
Shamrock-code:main
Choose a base branch
from
y-lapeyre:GR/cons2prime
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 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8e5898b
baseline
y-lapeyre 8b6fcf5
enthalpy iterator
y-lapeyre 6a2996c
fix types and typos
y-lapeyre c91b588
from PR1
y-lapeyre c71fcc3
compiling first version
y-lapeyre e1bffc1
Merge branch 'main' into GR/cons2prime
y-lapeyre 9d8aab0
[autofix.ci] automatic fix: pre-commit hooks
autofix-ci[bot] db029f5
[gh-action] trigger CI with empty commit
github-actions[bot] 840323c
new solvergraph edges intro
y-lapeyre b42c17d
finished implementation of enthalpy iterator
y-lapeyre 6f4bd2f
debugged
y-lapeyre d38d045
utils update
y-lapeyre 2a4ae22
add metric as edge
y-lapeyre dcafee7
add the contravariant metric to edges
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
76 changes: 76 additions & 0 deletions
76
src/shammodels/sph/include/shammodels/sph/modules/ConsToPrim.hpp
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,76 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // 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 ConsToPrim.hpp | ||
| * @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) | ||
| * @brief get conserved variables (rho*, momentum, entropy) from primitive variables (rho, vel, | ||
| * internal energy) | ||
|
y-lapeyre marked this conversation as resolved.
Outdated
y-lapeyre marked this conversation as resolved.
Outdated
|
||
| */ | ||
|
|
||
| #include "shambackends/vec.hpp" | ||
| #include "shamrock/solvergraph/IFieldSpan.hpp" | ||
| #include "shamrock/solvergraph/INode.hpp" | ||
| #include "shamrock/solvergraph/Indexes.hpp" | ||
|
|
||
| namespace shammodels::basegodunov::modules { | ||
| template<class Tvec> | ||
| class NodeConsToPrim : public shamrock::solvergraph::INode { | ||
|
y-lapeyre marked this conversation as resolved.
|
||
| using Tscal = shambase::VecComponent<Tvec>; | ||
| u32 block_size; | ||
| Tscal gamma; | ||
|
|
||
| public: | ||
| NodeConsToPrim(u32 block_size, Tscal gamma) : block_size(block_size), gamma(gamma) {} | ||
|
|
||
|
y-lapeyre marked this conversation as resolved.
|
||
| struct Edges { | ||
| const shamrock::solvergraph::Indexes<u32> &sizes; | ||
| const shamrock::solvergraph::IFieldSpan<Tscal> &spans_rhostar; | ||
| const shamrock::solvergraph::IFieldSpan<Tvec> &spans_momentum; | ||
| const shamrock::solvergraph::IFieldSpan<Tscal> &spans_K; | ||
| shamrock::solvergraph::IFieldSpan<Tscal> &spans_rho; | ||
| shamrock::solvergraph::IFieldSpan<Tvec> &spans_vel; | ||
| shamrock::solvergraph::IFieldSpan<Tscal> &spans_u; | ||
| shamrock::solvergraph::IFieldSpan<Tscal> &spans_P; | ||
| }; | ||
|
|
||
| inline void set_edges( | ||
| std::shared_ptr<shamrock::solvergraph::Indexes<u32>> sizes, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> spans_rhostar, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tvec>> spans_momentum, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> spans_K, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> spans_rho, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tvec>> spans_vel, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> spans_u, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> spans_P) { | ||
| __internal_set_ro_edges({sizes, spans_rhostar, spans_momentum, spans_K}); | ||
| __internal_set_rw_edges({spans_rho, spans_vel, spans_u, spans_P}); | ||
| } | ||
|
|
||
| inline Edges get_edges() { | ||
| return Edges{ | ||
| get_ro_edge<shamrock::solvergraph::Indexes<u32>>(0), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(1), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tvec>>(2), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(3), | ||
| get_rw_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(0), | ||
| get_rw_edge<shamrock::solvergraph::IFieldSpan<Tvec>>(1), | ||
| get_rw_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(2), | ||
| get_rw_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(3)}; | ||
| } | ||
|
y-lapeyre marked this conversation as resolved.
Outdated
|
||
|
|
||
| void _impl_evaluate_internal(); | ||
|
|
||
| inline virtual std::string _impl_get_label() const { return "ConsToPrim"; }; | ||
|
|
||
| virtual std::string _impl_get_tex() const; | ||
| }; | ||
| } // namespace shammodels::basegodunov::modules | ||
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,129 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // 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 | ||
| // | ||
| // -------------------------------------------------------// | ||
|
|
||
| /** | ||
| * @file ConsToPrim.cpp | ||
| * @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) | ||
| * @brief | ||
| * | ||
| */ | ||
|
|
||
| #include "shammodels/sph/modules/ConsToPrim.hpp" | ||
| #include "shambackends/kernel_call_distrib.hpp" | ||
| #include "shamcomm/logs.hpp" | ||
| #include "shammath/riemann.hpp" | ||
| #include "shamrock/patch/PatchDataField.hpp" | ||
| #include "shamsys/NodeInstance.hpp" | ||
|
|
||
| namespace { | ||
|
|
||
| template<class Tvec> | ||
| struct KernelConsToPrim { | ||
| using Tscal = shambase::VecComponent<Tvec>; | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| namespace shammodels::basegodunov::modules { | ||
|
|
||
| template<class Tvec> | ||
| void NodeConsToPrim<Tvec>::_impl_evaluate_internal() { | ||
| auto edges = get_edges(); | ||
| auto &thread_counts = edges.sizes.indexes; | ||
|
|
||
| edges.spans_rhostar.check_sizes(thread_counts); | ||
| edges.spans_momentum.check_sizes(thread_counts); | ||
| edges.spans_K.check_sizes(thread_counts); | ||
|
|
||
| edges.spans_rho.check_sizes(thread_counts); | ||
| edges.spans_vel.check_sizes(thread_counts); | ||
| edges.spans_u.check_sizes(thread_counts); | ||
| edges.spans_P.check_sizes(thread_counts); | ||
|
|
||
| auto &rhostar = edges.spans_rhostar.get_spans(); | ||
| auto &momentum = edges.spans_momentum.get_spans(); | ||
| auto &K = edges.spans_K.get_spans(); | ||
|
|
||
| auto &rho = edges.spans_rho.get_spans(); | ||
| auto &vel = edges.spans_vel.get_spans(); | ||
| auto &u = edges.spans_u.get_spans(); | ||
| auto &P = edges.spans_P.get_spans(); | ||
|
|
||
| auto dev_sched = shamsys::instance::get_compute_scheduler_ptr(); | ||
|
|
||
| sham::distributed_data_kernel_call( | ||
| dev_sched, | ||
| sham::DDMultiRef{rhostar, momentum, K}, | ||
| sham::DDMultiRef{rho, vel, u, P}, | ||
| thread_counts, | ||
| [gamma = this->gamma]( | ||
| u32 id_a, | ||
| Tscal *__restrict rhostar, | ||
| Tvec *__restrict momentum, | ||
| Tscal *__restrict K, | ||
|
|
||
| Tscal *__restrict rho, | ||
| Tvec *__restrict vel, | ||
| Tscal *__restrict u, | ||
| Tscal *__restrict P) { | ||
| // on patch, no need of neighbours | ||
|
|
||
| // get metric | ||
| Tscal sqrt_g = get_sqrtg(gcov); | ||
| Tscal inv_sqrt_g = 1. / sqrt_g; | ||
| Tscal sqrt_gamma = get_sqrt_gamma(gcov); | ||
| Tscal sqrt_gamma_inv = alpha * inv_sqrt_g; | ||
|
y-lapeyre marked this conversation as resolved.
Outdated
|
||
|
|
||
| // guess enthalpy w, with adiabatic EOS and previous values | ||
| Tscal w = gamma / (gamma - 1) * P[id_a] / rhostar[id_a]; | ||
| bool converged = false; | ||
| // compute u | ||
| // iterate | ||
| u32 Niter = 0; | ||
| do { | ||
| // get values of density and pressure from alod w | ||
| Tscal lorentz_factor | ||
| = sycl::sqrt(1. + sycl::dot(momentum[id_a], momentum[id_a] / (w * w))); | ||
|
|
||
| rho[id_a] = sqrt_gamma_inv * rhostar[id_a] / lorentz_factor; | ||
| Tscal polyk = 1.; | ||
| P[id_a] = (gamma - 1.) * rho[id_a] * polyk; | ||
|
|
||
| Tscal new_w = 1; | ||
|
|
||
| converged = sycl::fabs(new_w - w) < 1e-6; | ||
| w = new_w; | ||
| Niter++; | ||
| } while (Niter < 100 or converged); | ||
|
|
||
| if (converged) { | ||
| Tvec v3d = alpha * momentum[id_a] / (w * lorentz_factor) - betadown; | ||
| // Raise index from down to up | ||
| for (u32 i = 0; i < 4; i++) { | ||
| vel[id_a][i] = sycl::dot(gammaijUP[:, i], v3d); | ||
| } | ||
| } else { | ||
| logger::err_ln( | ||
| "GRSPH", | ||
| "the enthalpy iterator is not converged after", | ||
| Niter, | ||
| "iterations"); | ||
| } | ||
|
y-lapeyre marked this conversation as resolved.
|
||
| }); | ||
| } | ||
|
|
||
| template<class Tvec> | ||
| std::string NodeConsToPrim<Tvec>::_impl_get_tex() const { | ||
|
|
||
| return "TODO"; | ||
| } | ||
|
|
||
| } // namespace shammodels::basegodunov::modules | ||
|
|
||
| template class shammodels::basegodunov::modules::NodeConsToPrim<f64_3>; | ||
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.