-
Notifications
You must be signed in to change notification settings - Fork 34
[SPH] 1Pn disc-sink interactions #1923
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
AugustinDart
wants to merge
10
commits into
Shamrock-code:main
Choose a base branch
from
AugustinDart:interaction_PN_sink_disk
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
10 commits
Select commit
Hold shift + click to select a range
1769c97
Interaction 1Pn added
AugustinDart 8f92590
eps_grav added to avoid r=0
AugustinDart 00d63c7
Merge branch 'main' into interaction_PN_sink_disk
AugustinDart d00e694
Using inv_sat_zero
AugustinDart 562c382
Merge branch 'main' into interaction_PN_sink_disk
y-lapeyre 01132c5
formatting
y-lapeyre 6fc62da
fix bad import, now compiling
y-lapeyre 3321cab
add tex formula
y-lapeyre cbc1daf
fix potential division by 0
y-lapeyre 3130948
Merge branch 'main' into interaction_PN_sink_disk
tdavidcl 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
149 changes: 149 additions & 0 deletions
149
src/shammodels/common/include/shammodels/common/modules/AddForce1PN.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,149 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // 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 AddForce1PN.hpp | ||
| * @author Timothée David--Cléris (tim.shamrock@proton.me) | ||
| * @brief Adds the 1PN force acceleration. | ||
| * | ||
| */ | ||
|
|
||
| #include "shambackends/kernel_call_distrib.hpp" | ||
| #include "shambackends/math.hpp" | ||
| #include "shamrock/solvergraph/IFieldSpan.hpp" | ||
| #include "shamrock/solvergraph/Indexes.hpp" | ||
| #include "shamsolvergraph/edge/IDataEdge.hpp" | ||
| #include "shamsolvergraph/node/INode.hpp" | ||
| #include "shamsys/NodeInstance.hpp" | ||
|
|
||
| #define NODE_EDGES(X_RO, X_RW) \ | ||
| /* ------------------- inputs ------------------- */ \ | ||
| X_RO(shamrock::solvergraph::IDataEdge<Tscal>, constant_G) \ | ||
| X_RO(shamrock::solvergraph::IDataEdge<Tscal>, constant_c) \ | ||
| X_RO(shamrock::solvergraph::IDataEdge<Tscal>, central_mass) \ | ||
| X_RO(shamrock::solvergraph::IDataEdge<Tvec>, central_pos) \ | ||
| X_RO(shamrock::solvergraph::IDataEdge<Tvec>, central_vel) \ | ||
| X_RO(shamrock::solvergraph::IFieldSpan<Tvec>, spans_positions) \ | ||
| X_RO(shamrock::solvergraph::IFieldSpan<Tvec>, spans_velocities) \ | ||
| X_RO(shamrock::solvergraph::Indexes<u32>, sizes) \ | ||
| \ | ||
| /* ------------------- outputs ------------------- */ \ | ||
| X_RW(shamrock::solvergraph::IFieldSpan<Tvec>, spans_accel_ext) | ||
|
|
||
| namespace shammodels::common::modules { | ||
|
|
||
| template<class Tvec> | ||
| class AddForce1PN : public shamrock::solvergraph::INode { | ||
|
|
||
| using Tscal = shambase::VecComponent<Tvec>; | ||
|
|
||
| public: | ||
| AddForce1PN() = default; | ||
|
|
||
| EXPAND_NODE_EDGES(NODE_EDGES) | ||
|
|
||
| inline void _impl_evaluate_internal() { | ||
|
|
||
| __shamrock_stack_entry(); | ||
|
|
||
| auto edges = get_edges(); | ||
|
|
||
| edges.spans_positions.check_sizes(edges.sizes.indexes); | ||
| edges.spans_accel_ext.ensure_sizes(edges.sizes.indexes); | ||
|
|
||
| Tscal G = edges.constant_G.data; | ||
| Tscal c = edges.constant_c.data; | ||
| Tscal cmass = edges.central_mass.data; | ||
| Tvec cpos = edges.central_pos.data; | ||
| Tvec cvel = edges.central_vel.data; | ||
| Tscal GM = cmass * G; | ||
|
|
||
| sham::distributed_data_kernel_call( | ||
| shamsys::instance::get_compute_scheduler_ptr(), | ||
|
|
||
| sham::DDMultiRef{ | ||
| edges.spans_positions.get_spans(), edges.spans_velocities.get_spans()}, | ||
|
|
||
| sham::DDMultiRef{edges.spans_accel_ext.get_spans()}, | ||
|
|
||
| edges.sizes.indexes, | ||
|
|
||
| [cpos, cvel, GM, c](u32 gid, const Tvec *xyz, const Tvec *vxyz, Tvec *axyz_ext) { | ||
| Tvec r_a = xyz[gid] - cpos; | ||
| Tvec v_a = vxyz[gid] - cvel; | ||
|
|
||
| Tscal r = sycl::length(r_a); | ||
| Tscal inv_r = sham::inv_sat_zero(r); | ||
| Tscal inv_r2 = sham::inv_sat_zero(r * r); | ||
| Tvec r_hat = r_a * inv_r; | ||
|
|
||
| Tscal v2 = sham::dot(v_a, v_a); | ||
|
|
||
| Tscal vr = sham::dot(v_a, r_hat); | ||
|
|
||
| Tvec acc_1PN = -GM * inv_r2 | ||
| * ((v2 / (c * c) - 4 * GM * inv_r / (c * c)) * r_hat | ||
|
|
||
| - | ||
|
|
||
| (4 * vr / (c * c)) * v_a); | ||
|
|
||
| axyz_ext[gid] += acc_1PN; | ||
| }); | ||
| } | ||
|
|
||
| inline virtual std::string _impl_get_label() const { return "AddForce1PN"; }; | ||
|
|
||
| inline virtual std::string _impl_get_tex() const { | ||
| auto constant_G = get_ro_edge_base(0).get_tex_symbol(); | ||
| auto constant_c = get_ro_edge_base(1).get_tex_symbol(); | ||
| auto central_mass = get_ro_edge_base(2).get_tex_symbol(); | ||
| auto central_pos = get_ro_edge_base(3).get_tex_symbol(); | ||
| auto central_vel = get_ro_edge_base(4).get_tex_symbol(); | ||
| auto positions = get_ro_edge_base(5).get_tex_symbol(); | ||
| auto velocities = get_ro_edge_base(6).get_tex_symbol(); | ||
| auto axyz_ext = get_rw_edge_base(0).get_tex_symbol(); | ||
|
|
||
| std::string tex = R"tex( | ||
| Add force (1PN) | ||
|
|
||
| \begin{align} | ||
| \mathbf{r}_i &= {positions}_i - {central_pos}_i\\ | ||
| \mathbf{v}_i &= {velocities}_i - {central_vel}_i\\ | ||
| r &= \sqrt{\sum_i r_i^2}\\ | ||
| \hat{\mathbf{r}}_i &= \mathbf{r}_i / r\\ | ||
| v^2 &= \sum_i v_i^2\\ | ||
| v_r &= \sum_i v_i \hat{\mathbf{r}}_i\\ | ||
| {axyz_ext}_i &\mathrel{+}= -\frac{{constant_G} {central_mass}}{r^2} | ||
| \left[ | ||
| \left(\frac{v^2}{{constant_c}^2} | ||
| - \frac{4 {constant_G} {central_mass}}{r {constant_c}^2}\right)\hat{\mathbf{r}}_i | ||
| - \frac{4 v_r}{{constant_c}^2}\mathbf{v}_i | ||
| \right] | ||
| \end{align} | ||
| )tex"; | ||
|
|
||
| shambase::replace_all(tex, "{constant_G}", constant_G); | ||
| shambase::replace_all(tex, "{constant_c}", constant_c); | ||
| shambase::replace_all(tex, "{central_mass}", central_mass); | ||
| shambase::replace_all(tex, "{central_pos}", central_pos); | ||
| shambase::replace_all(tex, "{central_vel}", central_vel); | ||
| shambase::replace_all(tex, "{positions}", positions); | ||
| shambase::replace_all(tex, "{velocities}", velocities); | ||
| shambase::replace_all(tex, "{axyz_ext}", axyz_ext); | ||
|
|
||
| return tex; | ||
| }; | ||
| }; | ||
|
|
||
| } // namespace shammodels::common::modules | ||
|
|
||
| #undef NODE_EDGES | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Validate the velocity span before kernel execution.
The kernel indexes
vxyz[gid], but onlyspans_positionsis checked againstsizes. Ifspans_velocitieshas a different shape, the kernel can read outside its span.Proposed fix
edges.spans_positions.check_sizes(edges.sizes.indexes); +edges.spans_velocities.check_sizes(edges.sizes.indexes); edges.spans_accel_ext.ensure_sizes(edges.sizes.indexes);📝 Committable suggestion
🤖 Prompt for AI Agents