-
Notifications
You must be signed in to change notification settings - Fork 34
[Staging PR] Tweak sinks behavior in SPH (better conservation) #1737
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
Draft
tdavidcl
wants to merge
30
commits into
Shamrock-code:main
Choose a base branch
from
tdavidcl:torque-free-sink
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.
Draft
Changes from 8 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
9dc5b6d
[SPH] modernize sink accretion routine
tdavidcl b0a59e7
start implementing everything
tdavidcl 2be5d2a
clean sping accretion
tdavidcl e861974
niiiiice
tdavidcl 6e65816
yeaaaaah
tdavidcl 888c68a
tmp do not commit this one
tdavidcl ca0e8ed
Merge branch 'main' into torque-free-sink
tdavidcl 4b65140
Merge branch 'main' into torque-free-sink
tdavidcl 87394bb
Merge branch 'main' into torque-free-sink
tdavidcl 394be15
sync with main
tdavidcl caab6f7
Merge branch 'main' into torque-free-sink
tdavidcl a5b075f
progress
tdavidcl 8f92e4c
whoops
tdavidcl 27e6452
Merge branch 'main' into torque-free-sink
tdavidcl ccc0d07
early exit
tdavidcl 1d06a8d
Merge branch 'main' into torque-free-sink
tdavidcl 6d4c0f3
noicer
tdavidcl 8a4e27d
Merge branch 'main' into torque-free-sink
tdavidcl 4445c0b
noicer
tdavidcl 8655017
more orbits
tdavidcl 1c495c1
more orbits
tdavidcl 4be91bc
fix
tdavidcl 573a5b7
add analysis
tdavidcl 598c9b2
update
tdavidcl 4c44fa6
boost radisu is now a param
tdavidcl ffb4633
whoops
tdavidcl 81eafee
ensure validity of the boost vector
tdavidcl 966e1f3
upload
tdavidcl 6bd4346
fix
tdavidcl 464fca1
fix
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
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
96 changes: 96 additions & 0 deletions
96
src/shammodels/sph/include/shammodels/sph/modules/AnalysisAngularMomentum.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,96 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // 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 AnalysisAngularMomentum.hpp | ||
| * @author Timothée David--Cléris (tim.shamrock@proton.me) | ||
| * @brief AnalysisTotalMomentum class with one method AnalysisTotalMomentum.get_total_momentum() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| * | ||
| */ | ||
|
|
||
| #include "shambase/memory.hpp" | ||
| #include "shamalgs/primitives/reduction.hpp" | ||
| #include "shambackends/DeviceQueue.hpp" | ||
| #include "shambackends/DeviceScheduler.hpp" | ||
| #include "shammodels/sph/Model.hpp" | ||
| #include "shamrock/scheduler/PatchScheduler.hpp" | ||
| #include "shamrock/scheduler/ShamrockCtx.hpp" | ||
| #include <shambackends/sycl.hpp> | ||
|
|
||
| namespace shammodels::sph::modules { | ||
|
|
||
| template<class Tvec, template<class> class SPHKernel> | ||
| class AnalysisAngularMomentum { | ||
| public: | ||
| using Tscal = shambase::VecComponent<Tvec>; | ||
| static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension; | ||
|
|
||
| using Solver = Solver<Tvec, SPHKernel>; | ||
|
|
||
| Model<Tvec, SPHKernel> &model; | ||
| Solver &solver; | ||
| ShamrockCtx &ctx; | ||
|
|
||
| AnalysisAngularMomentum(Model<Tvec, SPHKernel> &model) | ||
| : model(model), ctx(model.ctx), solver(model.solver) {}; | ||
|
|
||
| auto get_angular_momentum() -> Tvec { | ||
| PatchScheduler &sched = shambase::get_check_ref(ctx.sched); | ||
| auto dev_sched_ptr = shamsys::instance::get_compute_scheduler_ptr(); | ||
| sham::DeviceQueue &q = shambase::get_check_ref(dev_sched_ptr).get_queue(); | ||
|
|
||
| const u32 ivxyz = sched.pdl_old().template get_field_idx<Tvec>("vxyz"); | ||
| const u32 ixyz = sched.pdl_old().template get_field_idx<Tvec>("xyz"); | ||
| const Tscal pmass = solver.solver_config.gpart_mass; | ||
|
|
||
| Tvec angular_momentum = {}; | ||
|
|
||
| sham::DeviceBuffer<Tvec> total_momentum_part(0, dev_sched_ptr); | ||
|
|
||
| sched.for_each_patchdata_nonempty( | ||
| [&](const shamrock::patch::Patch p, shamrock::patch::PatchDataLayer &pdat) { | ||
| u32 len = pdat.get_obj_cnt(); | ||
|
|
||
| total_momentum_part.resize(len); | ||
|
|
||
| sham::DeviceBuffer<Tvec> &xyz_buf = pdat.get_field_buf_ref<Tvec>(ixyz); | ||
| sham::DeviceBuffer<Tvec> &vxyz_buf = pdat.get_field_buf_ref<Tvec>(ivxyz); | ||
|
|
||
| sham::kernel_call( | ||
| q, | ||
| sham::MultiRef{xyz_buf, vxyz_buf}, | ||
| sham::MultiRef{total_momentum_part}, | ||
| len, | ||
| [pmass]( | ||
| u32 i, | ||
| const Tvec *__restrict xyz, | ||
| const Tvec *__restrict vxyz, | ||
| Tvec *__restrict total_momentum_part) { | ||
| total_momentum_part[i] = pmass * sycl::cross(xyz[i], vxyz[i]); | ||
| }); | ||
|
|
||
| angular_momentum | ||
| += shamalgs::primitives::sum(dev_sched_ptr, total_momentum_part, 0, len); | ||
| }); | ||
|
|
||
| Tvec tot_angular_momentum = shamalgs::collective::allreduce_sum(angular_momentum); | ||
|
|
||
| if (!solver.storage.sinks.is_empty()) { | ||
| for (auto &sink : solver.storage.sinks.get()) { | ||
| tot_angular_momentum | ||
| += sink.mass * sycl::cross(sink.pos, sink.velocity) + sink.angular_momentum; | ||
| } | ||
| } | ||
|
|
||
| return tot_angular_momentum; | ||
| } | ||
| }; | ||
| } // namespace shammodels::sph::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
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.
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.
The file
sinks.jsonis loaded multiple times in this script. Consider loading it once and reusing thesinksvariable to improve efficiency.