-
Notifications
You must be signed in to change notification settings - Fork 18
[SPH] Add luminosity field (as its own module) #1486
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
y-lapeyre
wants to merge
34
commits into
Shamrock-code:main
Choose a base branch
from
y-lapeyre:dumping/luminosity2
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 all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
c1f8764
added magnetic terms to conservative checks
y-lapeyre d50a194
correct bugs
y-lapeyre 98f16da
Merge branch 'main' into MHD/debug_cleaning
y-lapeyre 4f8d220
add missing mu_0 + reorder terms
y-lapeyre 4a6eb49
Merge branch 'MHD/debug_cleaning' of github.com:y-lapeyre/Shamrock in…
y-lapeyre 8826089
remove unnecessary data copy
y-lapeyre a5d6112
no implicit capture of this
y-lapeyre be281cc
make LLVM happy! (this pointer thingy)
y-lapeyre 95b67d0
clean up + comments
y-lapeyre 634b27e
removed old dv_terms function
y-lapeyre 98aceab
split hydro + mhd kernels for conservative checks
y-lapeyre d5eba73
Merge branch 'main' into MHD/debug_cleaning
y-lapeyre c0f8b4f
Merge branch 'main' into MHD/debug_cleaning
y-lapeyre dae6e1a
move to new interface (eventlist -> kernel_call)
y-lapeyre d4d979f
Merge branch 'MHD/debug_cleaning' of github.com:y-lapeyre/Shamrock in…
y-lapeyre 193dafd
Merge branch 'main' into MHD/debug_cleaning
y-lapeyre e63d2f2
Merge branch 'main' into MHD/debug_cleaning
y-lapeyre 83f45a0
clean up
y-lapeyre 3252b5e
[MHD] Add energy terms to conservative checks. (#1349)
y-lapeyre c02d05c
Merge branch 'Shamrock-code:main' into main
y-lapeyre c91c2d9
Merge branch 'Shamrock-code:main' into main
y-lapeyre 7209adf
Merge branch 'Shamrock-code:main' into main
y-lapeyre d698530
Merge branch 'Shamrock-code:main' into main
y-lapeyre fe9125e
Merge branch 'Shamrock-code:main' into main
y-lapeyre 5713bbb
Merge branch 'Shamrock-code:main' into main
y-lapeyre 72fa665
baseline
y-lapeyre b1491e2
Module done
y-lapeyre 3c7f9e3
bindings
y-lapeyre aa10691
clean up
y-lapeyre 0ade030
solvergraph sucks
y-lapeyre d5a9891
vector size mismatch in compute_luminosity
y-lapeyre da002a3
linting
y-lapeyre 992bc97
authors update
y-lapeyre 0adcd49
debug stuff
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
Some comments aren't visible on the classic Files Changed page.
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
83 changes: 83 additions & 0 deletions
83
src/shammodels/sph/include/shammodels/sph/modules/ComputeLuminosity.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,83 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // SHAMROCK code for hydrodynamics | ||
| // Copyright (c) 2021-2025 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 ComputeLuminosity.hpp | ||
| * @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) | ||
| * @brief | ||
| * | ||
| */ | ||
|
|
||
| #include "shambackends/typeAliasVec.hpp" | ||
| #include "shambackends/vec.hpp" | ||
| #include "shammodels/sph/SolverConfig.hpp" | ||
| #include "shammodels/sph/modules/SolverStorage.hpp" | ||
| #include "shamrock/scheduler/ShamrockCtx.hpp" | ||
|
|
||
| namespace shammodels::sph::modules { | ||
|
|
||
| template<class Tvec, template<class> class SPHKernel> | ||
| class NodeComputeLuminosity : public shamrock::solvergraph::INode { | ||
|
|
||
| using Tscal = shambase::VecComponent<Tvec>; | ||
|
|
||
| static constexpr Tscal kernel_radius = SPHKernel<Tscal>::Rkern; | ||
| Tscal part_mass; | ||
| Tscal alpha_u; | ||
|
|
||
| public: | ||
| NodeComputeLuminosity(Tscal part_mass, Tscal alpha_u) | ||
| : part_mass(part_mass), alpha_u(alpha_u) {} | ||
|
|
||
| struct Edges { | ||
| const shamrock::solvergraph::Indexes<u32> &part_counts; | ||
| const shammodels::sph::solvergraph::NeighCache &neigh_cache; | ||
| const shamrock::solvergraph::IFieldSpan<Tvec> &xyz; | ||
| const shamrock::solvergraph::IFieldSpan<Tscal> &hpart; | ||
| const shamrock::solvergraph::IFieldSpan<Tscal> ω | ||
| const shamrock::solvergraph::IFieldSpan<Tscal> &uint; | ||
| const shamrock::solvergraph::IFieldSpan<Tscal> &pressure; | ||
| shamrock::solvergraph::IFieldSpan<Tscal> &luminosity; | ||
| }; | ||
|
|
||
| inline void set_edges( | ||
| std::shared_ptr<shamrock::solvergraph::Indexes<u32>> part_counts, | ||
| std::shared_ptr<shammodels::sph::solvergraph::NeighCache> neigh_cache, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tvec>> xyz, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> hpart, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> omega, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> uint, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> pressure, | ||
| std::shared_ptr<shamrock::solvergraph::IFieldSpan<Tscal>> luminosity) { | ||
| __internal_set_ro_edges({part_counts, neigh_cache, xyz, hpart, omega, uint, pressure}); | ||
| __internal_set_rw_edges({luminosity}); | ||
| } | ||
|
|
||
| inline Edges get_edges() { | ||
| return Edges{ | ||
| get_ro_edge<shamrock::solvergraph::Indexes<u32>>(0), | ||
| get_ro_edge<shammodels::sph::solvergraph::NeighCache>(1), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tvec>>(2), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(3), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(4), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(5), | ||
| get_ro_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(6), | ||
| get_rw_edge<shamrock::solvergraph::IFieldSpan<Tscal>>(0)}; | ||
| } | ||
|
|
||
| void _impl_evaluate_internal(); | ||
|
|
||
| inline virtual std::string _impl_get_label() const { return "ComputeLuminosity"; }; | ||
|
|
||
| virtual std::string _impl_get_tex() const; | ||
| }; | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -46,6 +46,7 @@ | |||
| #include "shammodels/sph/modules/BuildTrees.hpp" | ||||
| #include "shammodels/sph/modules/ComputeEos.hpp" | ||||
| #include "shammodels/sph/modules/ComputeLoadBalanceValue.hpp" | ||||
| #include "shammodels/sph/modules/ComputeLuminosity.hpp" | ||||
| #include "shammodels/sph/modules/ComputeNeighStats.hpp" | ||||
| #include "shammodels/sph/modules/ComputeOmega.hpp" | ||||
| #include "shammodels/sph/modules/ConservativeCheck.hpp" | ||||
|
|
@@ -2000,6 +2001,92 @@ shammodels::sph::TimestepLog shammodels::sph::Solver<Tvec, Kern>::evolve_once() | |||
|
|
||||
| update_derivs(); | ||||
|
|
||||
| bool has_luminosity = solver_config.compute_luminosity; | ||||
|
|
||||
| if (has_luminosity) { | ||||
| const u32 iluminosity = pdl.get_field_idx<Tscal>("luminosity"); | ||||
|
|
||||
| shambase::get_check_ref(storage.hpart_with_ghosts) | ||||
| .set_refs(storage.merged_xyzh.get() | ||||
| .template map<std::reference_wrapper<PatchDataField<Tscal>>>( | ||||
| [&](u64 id, shamrock::patch::PatchDataLayer &mpdat) { | ||||
| return std::ref(mpdat.get_field<Tscal>( | ||||
| 1)); // hpart is at index 1 in merged_xyzh | ||||
| })); | ||||
|
|
||||
| auto uint_with_ghost = shamrock::solvergraph::FieldRefs<Tscal>::make_shared("", ""); | ||||
|
|
||||
| shambase::get_check_ref(storage.hpart_with_ghosts) | ||||
| .set_refs(storage.merged_xyzh.get() | ||||
| .template map<std::reference_wrapper<PatchDataField<Tscal>>>( | ||||
| [&](u64 id, shamrock::patch::PatchDataLayer &mpdat) { | ||||
| return std::ref(mpdat.get_field<Tscal>(1)); | ||||
| })); | ||||
|
|
||||
| shamrock::solvergraph::NodeSetEdge<shamrock::solvergraph::FieldRefs<Tscal>> | ||||
| set_uint_with_ghost_refs( | ||||
| [&](shamrock::solvergraph::FieldRefs<Tscal> &field_uint_with_ghost_edge) { | ||||
| shambase::DistributedData<PatchDataLayer> &mpdats | ||||
| = storage.merged_patchdata_ghost.get(); | ||||
|
|
||||
| shamrock::solvergraph::DDPatchDataFieldRef<Tscal> field_uint_with_ghost_refs | ||||
| = {}; | ||||
|
|
||||
| scheduler().for_each_patchdata_nonempty( | ||||
| [&](const Patch p, PatchDataLayer &pdat) { | ||||
| PatchDataLayer &mpdat = mpdats.get(p.id_patch); | ||||
|
|
||||
| auto &field = mpdat.get_field<Tscal>(iuint_interf); | ||||
| field_uint_with_ghost_refs.add_obj(p.id_patch, std::ref(field)); | ||||
| }); | ||||
|
|
||||
| field_uint_with_ghost_edge.set_refs(field_uint_with_ghost_refs); | ||||
| }); | ||||
|
|
||||
| set_uint_with_ghost_refs.set_edges(uint_with_ghost); | ||||
| // @@@@@@@@@@@@@@@@ | ||||
|
|
||||
| auto luminosity = shamrock::solvergraph::FieldRefs<Tscal>::make_shared("", ""); | ||||
|
|
||||
| shamrock::solvergraph::NodeSetEdge<shamrock::solvergraph::FieldRefs<Tscal>> | ||||
| set_luminosity_refs( | ||||
| [&](shamrock::solvergraph::FieldRefs<Tscal> &field_luminosity_edge) { | ||||
| shambase::DistributedData<PatchDataLayer> &mpdats | ||||
| = storage.merged_patchdata_ghost.get(); | ||||
|
|
||||
| shamrock::solvergraph::DDPatchDataFieldRef<Tscal> field_luminosity_refs | ||||
| = {}; | ||||
|
|
||||
| scheduler().for_each_patchdata_nonempty( | ||||
| [&](const Patch p, PatchDataLayer &pdat) { | ||||
| auto &field = pdat.get_field<Tscal>(iluminosity); | ||||
| field_luminosity_refs.add_obj(p.id_patch, std::ref(field)); | ||||
| }); | ||||
| field_luminosity_edge.set_refs(field_luminosity_refs); | ||||
| }); | ||||
|
|
||||
| set_luminosity_refs.set_edges(luminosity); | ||||
|
|
||||
| set_uint_with_ghost_refs.evaluate(); | ||||
| set_luminosity_refs.evaluate(); | ||||
|
|
||||
| Tscal alpha_u = 1; | ||||
|
Member
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. you can do something similar to this to fetch alpha_u
Add a getter it in the AVConfig and that should do it |
||||
|
|
||||
| modules::NodeComputeLuminosity<Tvec, Kern> compute_luminosity{ | ||||
| solver_config.gpart_mass, alpha_u}; | ||||
|
|
||||
| compute_luminosity.set_edges( | ||||
| storage.part_counts_with_ghost, | ||||
| storage.neigh_cache, | ||||
| storage.positions_with_ghosts, | ||||
| storage.hpart_with_ghosts, | ||||
| storage.omega, | ||||
| uint_with_ghost, | ||||
| storage.pressure, | ||||
| luminosity); | ||||
| compute_luminosity.evaluate(); | ||||
| } | ||||
|
|
||||
| modules::ConservativeCheck<Tvec, Kern> cv_check(context, solver_config, storage); | ||||
| cv_check.check_conservation(); | ||||
|
|
||||
|
|
||||
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,115 @@ | ||
| // -------------------------------------------------------// | ||
| // | ||
| // SHAMROCK code for hydrodynamics | ||
| // Copyright (c) 2021-2025 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 ComputeLuminosity.cpp | ||
| * @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) | ||
| * @brief | ||
| * | ||
| */ | ||
|
|
||
| #include "shambase/stacktrace.hpp" | ||
| #include "shambackends/kernel_call_distrib.hpp" | ||
| #include "shammodels/sph/SPHUtilities.hpp" | ||
| #include "shammodels/sph/math/forces.hpp" | ||
| #include "shammodels/sph/modules/ComputeLuminosity.hpp" | ||
| #include "shamrock/scheduler/SchedulerUtility.hpp" | ||
| #include "shamrock/solvergraph/IFieldSpan.hpp" | ||
|
|
||
| template<class Tvec, template<class> class SPHKernel> | ||
| void shammodels::sph::modules::NodeComputeLuminosity<Tvec, SPHKernel>::_impl_evaluate_internal() { | ||
|
|
||
| __shamrock_stack_entry(); | ||
|
|
||
| auto edges = get_edges(); | ||
|
|
||
| auto dev_sched = shamsys::instance::get_compute_scheduler_ptr(); | ||
|
|
||
| edges.luminosity.ensure_sizes(edges.part_counts.indexes); | ||
|
|
||
| sham::distributed_data_kernel_call( | ||
| dev_sched, | ||
| sham::DDMultiRef{ | ||
| edges.xyz.get_spans(), | ||
| edges.hpart.get_spans(), | ||
| edges.omega.get_spans(), | ||
| edges.uint.get_spans(), | ||
| edges.pressure.get_spans(), | ||
| edges.neigh_cache.neigh_cache}, | ||
| sham::DDMultiRef{edges.luminosity.get_spans()}, | ||
| edges.part_counts.indexes, | ||
| [part_mass = this->part_mass, alpha_u = this->alpha_u]( | ||
| u32 id_a, | ||
| const Tvec *r, | ||
| const Tscal *hpart, | ||
| const Tscal *omega, | ||
| const Tscal *uint, | ||
| const Tscal *pressure, | ||
| const auto ploop_ptrs, | ||
| Tscal *luminosity) { | ||
| shamrock::tree::ObjectCacheIterator particle_looper(ploop_ptrs); | ||
|
|
||
| using namespace shamrock::sph; | ||
| logger::raw_ln("first batch of loads"); | ||
| Tscal h_a = hpart[id_a]; | ||
| Tvec xyz_a = r[id_a]; | ||
| const Tscal u_a = uint[id_a]; | ||
| const Tscal omega_a = omega[id_a]; | ||
| const Tscal rho_a = rho_h(part_mass, h_a, SPHKernel<Tscal>::hfactd); | ||
| const Tscal P_a = pressure[id_a]; | ||
| Tscal omega_a_rho_a_inv = 1 / (omega_a * rho_a); | ||
| logger::raw_ln("passed first batch of loads"); | ||
| Tscal tmp_luminosity = 0; | ||
|
|
||
| particle_looper.for_each_object(id_a, [&](u32 id_b) { | ||
| logger::raw_ln("second batch of loads"); | ||
| const Tscal u_b = uint[id_b]; | ||
| logger::raw_ln("PB u"); | ||
| const Tscal h_b = hpart[id_b]; | ||
| logger::raw_ln("PB h"); | ||
| const Tscal omega_b = omega[id_b]; | ||
| logger::raw_ln("PB omega"); | ||
| const Tscal P_b = pressure[id_b]; | ||
| logger::raw_ln("PB pressure"); | ||
| const Tscal rho_b = rho_h(part_mass, h_b, SPHKernel<Tscal>::hfactd); | ||
| Tvec dr = xyz_a - r[id_b]; | ||
| Tscal rab2 = sycl::dot(dr, dr); | ||
| Tscal rab = sycl::sqrt(rab2); | ||
| logger::raw_ln("passed second batch of loads"); | ||
| Tscal vsigu = vsig_u(P_a, P_b, rho_a, rho_b); | ||
| Tscal Fab_a = SPHKernel<Tscal>::dW_3d(rab, h_a); | ||
| Tscal Fab_b = SPHKernel<Tscal>::dW_3d(rab, h_b); | ||
|
|
||
| tmp_luminosity += lambda_shock_conductivity( | ||
| part_mass, | ||
| alpha_u, | ||
| vsigu, | ||
| u_a - u_b, | ||
| Fab_a * omega_a_rho_a_inv, | ||
| Fab_b / (rho_b * omega_b)); | ||
| }); | ||
|
|
||
| luminosity[id_a] = tmp_luminosity; | ||
| }); | ||
| } | ||
|
|
||
| template<class Tvec, template<class> class SPHKernel> | ||
| std::string shammodels::sph::modules::NodeComputeLuminosity<Tvec, SPHKernel>::_impl_get_tex() | ||
| const { | ||
| return "TODO"; | ||
| } | ||
|
|
||
| using namespace shammath; | ||
| template class shammodels::sph::modules::NodeComputeLuminosity<f64_3, M4>; | ||
| template class shammodels::sph::modules::NodeComputeLuminosity<f64_3, M6>; | ||
| template class shammodels::sph::modules::NodeComputeLuminosity<f64_3, M8>; | ||
|
|
||
| template class shammodels::sph::modules::NodeComputeLuminosity<f64_3, C2>; | ||
| template class shammodels::sph::modules::NodeComputeLuminosity<f64_3, C4>; | ||
| template class shammodels::sph::modules::NodeComputeLuminosity<f64_3, C6>; |
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.
Why did you add this ? I'm not sure that i see any use of it in the rest of the PR