From 67894afd3d9d8525c0db3bcd77158db7d4c77faa Mon Sep 17 00:00:00 2001 From: Yona Lapeyre Date: Tue, 17 Mar 2026 19:14:31 +0900 Subject: [PATCH 1/3] baseline --- src/shammodels/common/CMakeLists.txt | 3 + .../include/shammodels/common}/density.hpp | 0 .../modules/render/CartesianRender.hpp | 18 +-- .../common/modules/render/RenderConfig.hpp | 34 ++++++ .../modules/render/RenderFieldGetter.hpp | 18 +-- .../src/modules/render/CartesianRender.cpp | 113 ++++++++++-------- .../src/modules/render/RenderFieldGetter.cpp | 57 +++++---- .../gsph/include/shammodels/gsph/Model.hpp | 2 +- .../gsph/include/shammodels/gsph/Solver.hpp | 2 +- .../gsph/src/modules/UpdateDerivs.cpp | 2 +- src/shammodels/sph/CMakeLists.txt | 4 +- .../sph/include/shammodels/sph/Model.hpp | 2 +- .../include/shammodels/sph/SPHUtilities.hpp | 2 +- src/shammodels/sph/src/Solver.cpp | 2 +- .../sph/src/modules/AnalysisDisc.cpp | 2 +- .../sph/src/modules/AnalysisSodTube.cpp | 2 +- src/shammodels/sph/src/modules/ComputeEos.cpp | 2 +- .../sph/src/modules/ConservativeCheck.cpp | 2 +- .../sph/src/modules/DiffOperator.cpp | 2 +- .../sph/src/modules/DiffOperatorDtDivv.cpp | 2 +- .../modules/IterateSmoothingLengthDensity.cpp | 2 +- .../IterateSmoothingLengthDensityNeighLim.cpp | 2 +- .../NodeUpdateDerivsVaryingAlphaAV.cpp | 2 +- .../sph/src/modules/UpdateDerivs.cpp | 2 +- src/shammodels/sph/src/modules/io/VTKDump.cpp | 2 +- .../sph/src/modules/setup/GeneratorMCDisc.cpp | 2 +- .../modules/setup/ModifierApplyCustomWarp.cpp | 2 +- .../modules/setup/ModifierApplyDiscWarp.cpp | 2 +- .../sph/src/modules/setup/ModifierFilter.cpp | 2 +- 29 files changed, 180 insertions(+), 109 deletions(-) rename src/shammodels/{sph/include/shammodels/sph/math => common/include/shammodels/common}/density.hpp (100%) rename src/shammodels/{sph/include/shammodels/sph => common/include/shammodels/common}/modules/render/CartesianRender.hpp (92%) create mode 100644 src/shammodels/common/include/shammodels/common/modules/render/RenderConfig.hpp rename src/shammodels/{sph/include/shammodels/sph => common/include/shammodels/common}/modules/render/RenderFieldGetter.hpp (79%) rename src/shammodels/{sph => common}/src/modules/render/CartesianRender.cpp (82%) rename src/shammodels/{sph => common}/src/modules/render/RenderFieldGetter.cpp (71%) diff --git a/src/shammodels/common/CMakeLists.txt b/src/shammodels/common/CMakeLists.txt index 84caa8fc2b..c0d24a65cd 100644 --- a/src/shammodels/common/CMakeLists.txt +++ b/src/shammodels/common/CMakeLists.txt @@ -17,6 +17,8 @@ set(Sources src/pyAMRGrid.cpp src/modules/AddForceCentralGravPotential.cpp src/timestep_report.cpp + src/modules/render/CartesianRender.cpp + src/modules/render/RenderFieldGetter.cpp ) if(SHAMROCK_USE_SHARED_LIB) @@ -35,6 +37,7 @@ target_link_libraries(shammodels_common PUBLIC shammath) target_link_libraries(shammodels_common PUBLIC shamphys) target_link_libraries(shammodels_common PUBLIC shamsys) target_link_libraries(shammodels_common PUBLIC nlohmann_json::nlohmann_json) +target_link_libraries(shammodels_common PUBLIC shampylib) target_include_directories(shammodels_common PUBLIC "$" diff --git a/src/shammodels/sph/include/shammodels/sph/math/density.hpp b/src/shammodels/common/include/shammodels/common/density.hpp similarity index 100% rename from src/shammodels/sph/include/shammodels/sph/math/density.hpp rename to src/shammodels/common/include/shammodels/common/density.hpp diff --git a/src/shammodels/sph/include/shammodels/sph/modules/render/CartesianRender.hpp b/src/shammodels/common/include/shammodels/common/modules/render/CartesianRender.hpp similarity index 92% rename from src/shammodels/sph/include/shammodels/sph/modules/render/CartesianRender.hpp rename to src/shammodels/common/include/shammodels/common/modules/render/CartesianRender.hpp index 1693f244ba..cb88db2b26 100644 --- a/src/shammodels/sph/include/shammodels/sph/modules/render/CartesianRender.hpp +++ b/src/shammodels/common/include/shammodels/common/modules/render/CartesianRender.hpp @@ -20,29 +20,31 @@ #include "shambackends/typeAliasVec.hpp" #include "shambackends/vec.hpp" #include "shammodels/sph/SolverConfig.hpp" -#include "shammodels/sph/modules/SolverStorage.hpp" +#include "shammodels/common/modules/render/RenderConfig.hpp" #include "shamrock/scheduler/ShamrockCtx.hpp" #include #include -namespace shammodels::sph::modules { +namespace shammodels::common::modules { - template class SPHKernel> + template class SPHKernel, class TStorage> class CartesianRender { public: using Tscal = shambase::VecComponent; static constexpr u32 dim = shambase::VectorProperties::dimension; using Kernel = SPHKernel; - using Config = SolverConfig; - using Storage = SolverStorage; + using RenderConfig = shammodels::common::RenderConfig; + using Storage = TStorage;//SolverStorage; ShamrockCtx &context; - Config &solver_config; + RenderConfig &render_config; Storage &storage; - CartesianRender(ShamrockCtx &context, Config &solver_config, Storage &storage) - : context(context), solver_config(solver_config), storage(storage) {} + + + CartesianRender(ShamrockCtx &context, RenderConfig &render_config, Storage &storage) + : context(context), render_config(render_config), storage(storage) {} using field_getter_t = const sham::DeviceBuffer &( const shamrock::patch::Patch cur_p, shamrock::patch::PatchDataLayer &pdat); diff --git a/src/shammodels/common/include/shammodels/common/modules/render/RenderConfig.hpp b/src/shammodels/common/include/shammodels/common/modules/render/RenderConfig.hpp new file mode 100644 index 0000000000..990cea4a1e --- /dev/null +++ b/src/shammodels/common/include/shammodels/common/modules/render/RenderConfig.hpp @@ -0,0 +1,34 @@ +// -------------------------------------------------------// +// +// SHAMROCK code for hydrodynamics +// Copyright (c) 2021-2026 Timothée David--Cléris +// 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 RenderConfig.hpp + + * @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr) + * @brief + * + */ + + +namespace shammodels::common { + + template + struct RenderConfig; + + template + struct RenderConfig { + //Tscal hfact; + Tscal gpart_mass; + unsigned int tree_reduction_level; + + }; + +} \ No newline at end of file diff --git a/src/shammodels/sph/include/shammodels/sph/modules/render/RenderFieldGetter.hpp b/src/shammodels/common/include/shammodels/common/modules/render/RenderFieldGetter.hpp similarity index 79% rename from src/shammodels/sph/include/shammodels/sph/modules/render/RenderFieldGetter.hpp rename to src/shammodels/common/include/shammodels/common/modules/render/RenderFieldGetter.hpp index 6e9934a7b8..ffacf78c4f 100644 --- a/src/shammodels/sph/include/shammodels/sph/modules/render/RenderFieldGetter.hpp +++ b/src/shammodels/common/include/shammodels/common/modules/render/RenderFieldGetter.hpp @@ -19,30 +19,30 @@ #include "shambackends/DeviceBuffer.hpp" #include "shambackends/typeAliasVec.hpp" #include "shambackends/vec.hpp" -#include "shammodels/sph/SolverConfig.hpp" -#include "shammodels/sph/modules/SolverStorage.hpp" +#include "shammodels/common/modules/render/RenderConfig.hpp" +#include "shammath/sphkernels.hpp" #include "shampylib/PatchDataToPy.hpp" #include "shamrock/scheduler/ShamrockCtx.hpp" #include -namespace shammodels::sph::modules { +namespace shammodels::common::modules { - template class SPHKernel> + template class SPHKernel, class TStorage> class RenderFieldGetter { public: using Tscal = shambase::VecComponent; static constexpr u32 dim = shambase::VectorProperties::dimension; using Kernel = SPHKernel; - using Config = SolverConfig; - using Storage = SolverStorage; + using RenderConfig = common::RenderConfig; + using Storage = TStorage;//SolverStorage; ShamrockCtx &context; - Config &solver_config; + RenderConfig &render_config; Storage &storage; - RenderFieldGetter(ShamrockCtx &context, Config &solver_config, Storage &storage) - : context(context), solver_config(solver_config), storage(storage) {} + RenderFieldGetter(ShamrockCtx &context, RenderConfig &render_config, Storage &storage) + : context(context), render_config(render_config), storage(storage) {} using field_getter_t = const sham::DeviceBuffer &( const shamrock::patch::Patch cur_p, shamrock::patch::PatchDataLayer &pdat); diff --git a/src/shammodels/sph/src/modules/render/CartesianRender.cpp b/src/shammodels/common/src/modules/render/CartesianRender.cpp similarity index 82% rename from src/shammodels/sph/src/modules/render/CartesianRender.cpp rename to src/shammodels/common/src/modules/render/CartesianRender.cpp index 8987f950ba..cc99275cdf 100644 --- a/src/shammodels/sph/src/modules/render/CartesianRender.cpp +++ b/src/shammodels/common/src/modules/render/CartesianRender.cpp @@ -18,12 +18,12 @@ #include "shambase/exception.hpp" #include "shambackends/kernel_call.hpp" #include "shammath/AABB.hpp" -#include "shammodels/sph/math/density.hpp" -#include "shammodels/sph/modules/render/CartesianRender.hpp" -#include "shammodels/sph/modules/render/RenderFieldGetter.hpp" +#include "shammodels/common/density.hpp" +#include "shammodels/common/modules/render/CartesianRender.hpp" +#include "shammodels/common/modules/render/RenderFieldGetter.hpp" #include "shamrock/scheduler/SchedulerUtility.hpp" -namespace shammodels::sph::modules { +namespace shammodels::common::modules { template sham::DeviceBuffer pixel_to_positions( @@ -95,8 +95,8 @@ namespace shammodels::sph::modules { return ret; } - template class SPHKernel> - auto CartesianRender::compute_slice( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_slice( std::string field_name, const sham::DeviceBuffer &positions, std::optional(size_t, pybind11::dict &)>> custom_getter) @@ -114,7 +114,7 @@ namespace shammodels::sph::modules { shambase::Timer t; t.start(); - auto ret = RenderFieldGetter(context, solver_config, storage) + auto ret = RenderFieldGetter(context, render_config, storage) .runner_function( field_name, [&](auto field_getter) -> sham::DeviceBuffer { @@ -132,8 +132,8 @@ namespace shammodels::sph::modules { return ret; } - template class SPHKernel> - auto CartesianRender::compute_column_integ( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_column_integ( std::string field_name, const sham::DeviceBuffer> &rays, std::optional(size_t, pybind11::dict &)>> custom_getter) @@ -151,7 +151,7 @@ namespace shammodels::sph::modules { shambase::Timer t; t.start(); - auto ret = RenderFieldGetter(context, solver_config, storage) + auto ret = RenderFieldGetter(context, render_config, storage) .runner_function( field_name, [&](auto field_getter) -> sham::DeviceBuffer { @@ -169,8 +169,8 @@ namespace shammodels::sph::modules { return ret; } - template class SPHKernel> - auto CartesianRender::compute_azymuthal_integ( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_azymuthal_integ( std::string field_name, const sham::DeviceBuffer> &ring_rays, std::optional(size_t, pybind11::dict &)>> custom_getter) @@ -188,7 +188,7 @@ namespace shammodels::sph::modules { shambase::Timer t; t.start(); - auto ret = RenderFieldGetter(context, solver_config, storage) + auto ret = RenderFieldGetter(context, render_config, storage) .runner_function( field_name, [&](auto field_getter) -> sham::DeviceBuffer { @@ -206,8 +206,8 @@ namespace shammodels::sph::modules { return ret; } - template class SPHKernel> - auto CartesianRender::compute_slice( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_slice( std::function field_getter, const sham::DeviceBuffer &positions) -> sham::DeviceBuffer { @@ -240,7 +240,7 @@ namespace shammodels::sph::modules { {box.lower, box.upper}, buf_xyz, obj_cnt, - solver_config.tree_reduction_level); + render_config.tree_reduction_level); tree.compute_cell_ibounding_box(shamsys::instance::get_compute_queue()); tree.convert_bounding_box(shamsys::instance::get_compute_queue()); @@ -269,7 +269,7 @@ namespace shammodels::sph::modules { constexpr Tscal Rker2 = Kernel::Rkern * Kernel::Rkern; - Tscal partmass = solver_config.gpart_mass; + Tscal partmass = render_config.gpart_mass; shambase::parallel_for( cgh, positions.get_size(), "compute slice render", [=](u32 gid) { @@ -320,8 +320,8 @@ namespace shammodels::sph::modules { return ret; } - template class SPHKernel> - auto CartesianRender::compute_column_integ( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_column_integ( std::function field_getter, const sham::DeviceBuffer> &rays) -> sham::DeviceBuffer { @@ -354,7 +354,7 @@ namespace shammodels::sph::modules { {box.lower, box.upper}, buf_xyz, obj_cnt, - solver_config.tree_reduction_level); + render_config.tree_reduction_level); tree.compute_cell_ibounding_box(shamsys::instance::get_compute_queue()); tree.convert_bounding_box(shamsys::instance::get_compute_queue()); @@ -383,7 +383,7 @@ namespace shammodels::sph::modules { constexpr Tscal Rker2 = Kernel::Rkern * Kernel::Rkern; - Tscal partmass = solver_config.gpart_mass; + Tscal partmass = render_config.gpart_mass; shambase::parallel_for(cgh, rays.get_size(), "compute slice render", [=](u32 gid) { Tfield ret = sham::VectorProperties::get_zero(); @@ -435,8 +435,8 @@ namespace shammodels::sph::modules { return ret; } - template class SPHKernel> - auto CartesianRender::compute_azymuthal_integ( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_azymuthal_integ( std::function field_getter, const sham::DeviceBuffer> &ring_rays) -> sham::DeviceBuffer { @@ -470,7 +470,7 @@ namespace shammodels::sph::modules { {box.lower, box.upper}, buf_xyz, obj_cnt, - solver_config.tree_reduction_level); + render_config.tree_reduction_level); tree.compute_cell_ibounding_box(shamsys::instance::get_compute_queue()); tree.convert_bounding_box(shamsys::instance::get_compute_queue()); @@ -499,7 +499,7 @@ namespace shammodels::sph::modules { constexpr Tscal Rker2 = Kernel::Rkern * Kernel::Rkern; - Tscal partmass = solver_config.gpart_mass; + Tscal partmass = render_config.gpart_mass; shambase::parallel_for( cgh, ring_rays.get_size(), "compute slice render", [=](u32 gid) { @@ -560,8 +560,8 @@ namespace shammodels::sph::modules { return ret; } - template class SPHKernel> - auto CartesianRender::compute_slice( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_slice( std::function field_getter, Tvec center, Tvec delta_x, @@ -574,8 +574,8 @@ namespace shammodels::sph::modules { return compute_slice(field_getter, positions); } - template class SPHKernel> - auto CartesianRender::compute_column_integ( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_column_integ( std::function field_getter, Tvec center, Tvec delta_x, @@ -588,8 +588,8 @@ namespace shammodels::sph::modules { return compute_column_integ(field_getter, rays); } - template class SPHKernel> - auto CartesianRender::compute_slice( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_slice( std::string field_name, Tvec center, Tvec delta_x, @@ -602,8 +602,8 @@ namespace shammodels::sph::modules { return compute_slice(field_name, positions, custom_getter); } - template class SPHKernel> - auto CartesianRender::compute_column_integ( + template class SPHKernel, class TStorage> + auto CartesianRender::compute_column_integ( std::string field_name, Tvec center, Tvec delta_x, @@ -619,18 +619,35 @@ namespace shammodels::sph::modules { } // namespace shammodels::sph::modules using namespace shammath; -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; - -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; - -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; - -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; -template class shammodels::sph::modules::CartesianRender; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +//gsph +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; \ No newline at end of file diff --git a/src/shammodels/sph/src/modules/render/RenderFieldGetter.cpp b/src/shammodels/common/src/modules/render/RenderFieldGetter.cpp similarity index 71% rename from src/shammodels/sph/src/modules/render/RenderFieldGetter.cpp rename to src/shammodels/common/src/modules/render/RenderFieldGetter.cpp index d3ed2ccecb..40f4587c9f 100644 --- a/src/shammodels/sph/src/modules/render/RenderFieldGetter.cpp +++ b/src/shammodels/common/src/modules/render/RenderFieldGetter.cpp @@ -15,14 +15,13 @@ * */ -#include "shammodels/sph/modules/render/RenderFieldGetter.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/modules/render/RenderFieldGetter.hpp" #include "shampylib/PatchDataToPy.hpp" #include "shamrock/scheduler/SchedulerUtility.hpp" -namespace shammodels::sph::modules { - template class SPHKernel> - auto RenderFieldGetter::runner_function( +namespace shammodels::common::modules { + template class SPHKernel, class TStorage> + auto RenderFieldGetter::runner_function( std::string field_name, lamda_runner lambda, std::optional(size_t, pybind11::dict &)>> custom_getter) @@ -55,12 +54,12 @@ namespace shammodels::sph::modules { auto acc_rho = buf_rho.get_write_access(depends_list); auto e = q.submit(depends_list, [&](sycl::handler &cgh) { - const Tscal part_mass = solver_config.gpart_mass; + const Tscal part_mass = render_config.gpart_mass; cgh.parallel_for( sycl::range<1>{pdat.get_obj_cnt()}, [=](sycl::item<1> item) { u32 gid = (u32) item.get_id(); - using namespace shamrock::sph; + Tscal rho_ha = rho_h(part_mass, acc_h[gid], Kernel::hfactd); acc_rho[gid] = rho_ha; }); @@ -102,7 +101,7 @@ namespace shammodels::sph::modules { cgh.parallel_for( sycl::range<1>{pdat.get_obj_cnt()}, [=](sycl::item<1> item) { u32 gid = (u32) item.get_id(); - using namespace shamrock::sph; + using namespace sph; acc_inv_hpart[gid] = 1.0 / acc_h[gid]; }); }); @@ -198,18 +197,36 @@ namespace shammodels::sph::modules { } // namespace shammodels::sph::modules using namespace shammath; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + + +//gsph +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; -template class shammodels::sph::modules::RenderFieldGetter; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; diff --git a/src/shammodels/gsph/include/shammodels/gsph/Model.hpp b/src/shammodels/gsph/include/shammodels/gsph/Model.hpp index 50387ad5ba..c2901d1194 100644 --- a/src/shammodels/gsph/include/shammodels/gsph/Model.hpp +++ b/src/shammodels/gsph/include/shammodels/gsph/Model.hpp @@ -35,7 +35,7 @@ #include "shamcomm/logs.hpp" #include "shammodels/common/setup/generators.hpp" #include "shammodels/gsph/Solver.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shamrock/io/ShamrockDump.hpp" #include "shamrock/patch/PatchDataLayer.hpp" #include "shamrock/scheduler/ReattributeDataUtility.hpp" diff --git a/src/shammodels/gsph/include/shammodels/gsph/Solver.hpp b/src/shammodels/gsph/include/shammodels/gsph/Solver.hpp index a1b9c54c24..f917513e08 100644 --- a/src/shammodels/gsph/include/shammodels/gsph/Solver.hpp +++ b/src/shammodels/gsph/include/shammodels/gsph/Solver.hpp @@ -73,7 +73,7 @@ namespace shammodels::gsph { using Config = SolverConfig; - using u_morton = u32; + using u_morton = typename Config::u_morton; static constexpr Tscal Rkern = Kernel::Rkern; diff --git a/src/shammodels/gsph/src/modules/UpdateDerivs.cpp b/src/shammodels/gsph/src/modules/UpdateDerivs.cpp index 4f396b75f0..48772a377f 100644 --- a/src/shammodels/gsph/src/modules/UpdateDerivs.cpp +++ b/src/shammodels/gsph/src/modules/UpdateDerivs.cpp @@ -32,7 +32,7 @@ #include "shammodels/gsph/config/FieldNames.hpp" #include "shammodels/gsph/math/forces.hpp" #include "shammodels/gsph/math/riemann/iterative.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shamsys/legacy/log.hpp" #include "shamtree/TreeTraversal.hpp" diff --git a/src/shammodels/sph/CMakeLists.txt b/src/shammodels/sph/CMakeLists.txt index 295ff990ca..c892ab735e 100644 --- a/src/shammodels/sph/CMakeLists.txt +++ b/src/shammodels/sph/CMakeLists.txt @@ -61,8 +61,6 @@ set(Sources src/modules/self_gravity/SGMMPlummer.cpp src/modules/self_gravity/SGFMMPlummer.cpp src/modules/self_gravity/SGSFMMPlummer.cpp - src/modules/render/CartesianRender.cpp - src/modules/render/RenderFieldGetter.cpp src/modules/io/VTKDump.cpp ) @@ -81,8 +79,8 @@ target_link_libraries(shammodels_sph PUBLIC shamlib) target_link_libraries(shammodels_sph PUBLIC shammath) target_link_libraries(shammodels_sph PUBLIC shamphys) target_link_libraries(shammodels_sph PUBLIC shamsys) -target_link_libraries(shammodels_sph PUBLIC shammodels_common) target_link_libraries(shammodels_sph PUBLIC shampylib) +target_link_libraries(shammodels_sph PUBLIC shammodels_common) target_link_libraries(shammodels_sph PUBLIC nlohmann_json::nlohmann_json) target_include_directories(shammodels_sph PUBLIC diff --git a/src/shammodels/sph/include/shammodels/sph/Model.hpp b/src/shammodels/sph/include/shammodels/sph/Model.hpp index 41dbc517ac..6610f27fee 100644 --- a/src/shammodels/sph/include/shammodels/sph/Model.hpp +++ b/src/shammodels/sph/include/shammodels/sph/Model.hpp @@ -28,7 +28,7 @@ #include "shammodels/common/setup/generators.hpp" #include "shammodels/sph/Solver.hpp" #include "shammodels/sph/io/PhantomDump.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/ComputeLoadBalanceValue.hpp" #include "shammodels/sph/modules/SPHSetup.hpp" #include "shamrock/io/ShamrockDump.hpp" diff --git a/src/shammodels/sph/include/shammodels/sph/SPHUtilities.hpp b/src/shammodels/sph/include/shammodels/sph/SPHUtilities.hpp index af5f17a9bd..77777526ee 100644 --- a/src/shammodels/sph/include/shammodels/sph/SPHUtilities.hpp +++ b/src/shammodels/sph/include/shammodels/sph/SPHUtilities.hpp @@ -17,7 +17,7 @@ */ #include "shammodels/sph/BasicSPHGhosts.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shamrock/scheduler/PatchScheduler.hpp" #include "shamtree/RadixTree.hpp" #include "shamtree/TreeTraversal.hpp" diff --git a/src/shammodels/sph/src/Solver.cpp b/src/shammodels/sph/src/Solver.cpp index d783cef926..f0255de671 100644 --- a/src/shammodels/sph/src/Solver.cpp +++ b/src/shammodels/sph/src/Solver.cpp @@ -40,7 +40,7 @@ #include "shammodels/sph/Solver.hpp" #include "shammodels/sph/SolverConfig.hpp" #include "shammodels/sph/io/PhantomDump.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/math/forces.hpp" #include "shammodels/sph/math/q_ab.hpp" #include "shammodels/sph/modules/BuildTrees.hpp" diff --git a/src/shammodels/sph/src/modules/AnalysisDisc.cpp b/src/shammodels/sph/src/modules/AnalysisDisc.cpp index a9b7f81e70..2b9be36447 100644 --- a/src/shammodels/sph/src/modules/AnalysisDisc.cpp +++ b/src/shammodels/sph/src/modules/AnalysisDisc.cpp @@ -24,7 +24,7 @@ #include "shambackends/kernel_call.hpp" #include "shamcomm/wrapper.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/AnalysisDisc.hpp" #include #include diff --git a/src/shammodels/sph/src/modules/AnalysisSodTube.cpp b/src/shammodels/sph/src/modules/AnalysisSodTube.cpp index 4b2f645276..108e453e81 100644 --- a/src/shammodels/sph/src/modules/AnalysisSodTube.cpp +++ b/src/shammodels/sph/src/modules/AnalysisSodTube.cpp @@ -17,7 +17,7 @@ #include "shambase/exception.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/AnalysisSodTube.hpp" #include "shamphys/eos.hpp" #include "shamrock/scheduler/PatchScheduler.hpp" diff --git a/src/shammodels/sph/src/modules/ComputeEos.cpp b/src/shammodels/sph/src/modules/ComputeEos.cpp index ded3f9b76a..d1dba40192 100644 --- a/src/shammodels/sph/src/modules/ComputeEos.cpp +++ b/src/shammodels/sph/src/modules/ComputeEos.cpp @@ -20,7 +20,7 @@ #include "shambase/exception.hpp" #include "shambackends/kernel_call.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/ComputeEos.hpp" #include "shamphys/eos.hpp" #include "shamrock/patch/PatchDataLayer.hpp" diff --git a/src/shammodels/sph/src/modules/ConservativeCheck.cpp b/src/shammodels/sph/src/modules/ConservativeCheck.cpp index a6d8bcd714..b670518c81 100644 --- a/src/shammodels/sph/src/modules/ConservativeCheck.cpp +++ b/src/shammodels/sph/src/modules/ConservativeCheck.cpp @@ -18,7 +18,7 @@ #include "shammodels/sph/modules/ConservativeCheck.hpp" #include "shamcomm/logs.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shamsys/legacy/log.hpp" template class SPHKernel> diff --git a/src/shammodels/sph/src/modules/DiffOperator.cpp b/src/shammodels/sph/src/modules/DiffOperator.cpp index d24dfb015a..5e92bb8282 100644 --- a/src/shammodels/sph/src/modules/DiffOperator.cpp +++ b/src/shammodels/sph/src/modules/DiffOperator.cpp @@ -17,7 +17,7 @@ #include "shambase/stacktrace.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/DiffOperator.hpp" #include "shamrock/scheduler/InterfacesUtility.hpp" diff --git a/src/shammodels/sph/src/modules/DiffOperatorDtDivv.cpp b/src/shammodels/sph/src/modules/DiffOperatorDtDivv.cpp index 4bcd7e0973..ab3363838e 100644 --- a/src/shammodels/sph/src/modules/DiffOperatorDtDivv.cpp +++ b/src/shammodels/sph/src/modules/DiffOperatorDtDivv.cpp @@ -18,7 +18,7 @@ #include "shambase/memory.hpp" #include "shammath/matrix_legacy.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/DiffOperatorDtDivv.hpp" #include "shamrock/patch/PatchDataField.hpp" #include "shamrock/scheduler/InterfacesUtility.hpp" diff --git a/src/shammodels/sph/src/modules/IterateSmoothingLengthDensity.cpp b/src/shammodels/sph/src/modules/IterateSmoothingLengthDensity.cpp index 41f7681cc3..fd012beb33 100644 --- a/src/shammodels/sph/src/modules/IterateSmoothingLengthDensity.cpp +++ b/src/shammodels/sph/src/modules/IterateSmoothingLengthDensity.cpp @@ -18,7 +18,7 @@ #include "shambackends/kernel_call_distrib.hpp" #include "shamcomm/logs.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/IterateSmoothingLengthDensity.hpp" #include "shamrock/patch/PatchDataField.hpp" diff --git a/src/shammodels/sph/src/modules/IterateSmoothingLengthDensityNeighLim.cpp b/src/shammodels/sph/src/modules/IterateSmoothingLengthDensityNeighLim.cpp index 0a8c743fc0..ec98f631a8 100644 --- a/src/shammodels/sph/src/modules/IterateSmoothingLengthDensityNeighLim.cpp +++ b/src/shammodels/sph/src/modules/IterateSmoothingLengthDensityNeighLim.cpp @@ -18,7 +18,7 @@ #include "shambackends/kernel_call_distrib.hpp" #include "shamcomm/logs.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/IterateSmoothingLengthDensityNeighLim.hpp" #include "shamrock/patch/PatchDataField.hpp" diff --git a/src/shammodels/sph/src/modules/NodeUpdateDerivsVaryingAlphaAV.cpp b/src/shammodels/sph/src/modules/NodeUpdateDerivsVaryingAlphaAV.cpp index 2dc785a82c..69bdcad308 100644 --- a/src/shammodels/sph/src/modules/NodeUpdateDerivsVaryingAlphaAV.cpp +++ b/src/shammodels/sph/src/modules/NodeUpdateDerivsVaryingAlphaAV.cpp @@ -17,7 +17,7 @@ #include "shammodels/sph/modules/NodeUpdateDerivsVaryingAlphaAV.hpp" #include "shambackends/kernel_call_distrib.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/math/forces.hpp" #include "shammodels/sph/math/q_ab.hpp" #include "shamrock/patch/PatchDataField.hpp" diff --git a/src/shammodels/sph/src/modules/UpdateDerivs.cpp b/src/shammodels/sph/src/modules/UpdateDerivs.cpp index 809c5f7e2b..a60c3233bf 100644 --- a/src/shammodels/sph/src/modules/UpdateDerivs.cpp +++ b/src/shammodels/sph/src/modules/UpdateDerivs.cpp @@ -22,7 +22,7 @@ #include "shambackends/math.hpp" #include "shamcomm/logs.hpp" #include "shammath/sphkernels.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/math/forces.hpp" #include "shammodels/sph/math/mhd.hpp" #include "shammodels/sph/math/q_ab.hpp" diff --git a/src/shammodels/sph/src/modules/io/VTKDump.cpp b/src/shammodels/sph/src/modules/io/VTKDump.cpp index 0e7bfd73ba..186fb717f9 100644 --- a/src/shammodels/sph/src/modules/io/VTKDump.cpp +++ b/src/shammodels/sph/src/modules/io/VTKDump.cpp @@ -19,7 +19,7 @@ #include "shammodels/sph/modules/io/VTKDump.hpp" #include "shambackends/kernel_call.hpp" #include "shammodels/common/io/VTKDumpUtils.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shamrock/io/LegacyVtkWritter.hpp" #include "shamrock/patch/PatchDataFieldSpan.hpp" #include "shamrock/scheduler/SchedulerUtility.hpp" diff --git a/src/shammodels/sph/src/modules/setup/GeneratorMCDisc.cpp b/src/shammodels/sph/src/modules/setup/GeneratorMCDisc.cpp index 3c486cb5cb..2d65bf7f04 100644 --- a/src/shammodels/sph/src/modules/setup/GeneratorMCDisc.cpp +++ b/src/shammodels/sph/src/modules/setup/GeneratorMCDisc.cpp @@ -18,7 +18,7 @@ #include "shambase/constants.hpp" #include "shamalgs/collective/indexing.hpp" #include "shamalgs/random.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/setup/GeneratorMCDisc.hpp" template class SPHKernel> diff --git a/src/shammodels/sph/src/modules/setup/ModifierApplyCustomWarp.cpp b/src/shammodels/sph/src/modules/setup/ModifierApplyCustomWarp.cpp index ee42a6d54a..a73e1fcf34 100644 --- a/src/shammodels/sph/src/modules/setup/ModifierApplyCustomWarp.cpp +++ b/src/shammodels/sph/src/modules/setup/ModifierApplyCustomWarp.cpp @@ -19,7 +19,7 @@ #include "shamalgs/collective/indexing.hpp" #include "shamcomm/logs.hpp" #include "shammodels/sph/Solver.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/setup/ISPHSetupNode.hpp" #include "shammodels/sph/modules/setup/ModifierApplyCustomWarp.hpp" #include "shamrock/scheduler/ShamrockCtx.hpp" diff --git a/src/shammodels/sph/src/modules/setup/ModifierApplyDiscWarp.cpp b/src/shammodels/sph/src/modules/setup/ModifierApplyDiscWarp.cpp index 282a0bcf36..1dbab7a792 100644 --- a/src/shammodels/sph/src/modules/setup/ModifierApplyDiscWarp.cpp +++ b/src/shammodels/sph/src/modules/setup/ModifierApplyDiscWarp.cpp @@ -18,7 +18,7 @@ #include "shambase/constants.hpp" #include "shamalgs/collective/indexing.hpp" #include "shammodels/sph/Solver.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/setup/ISPHSetupNode.hpp" #include "shammodels/sph/modules/setup/ModifierApplyDiscWarp.hpp" #include "shamrock/scheduler/ShamrockCtx.hpp" diff --git a/src/shammodels/sph/src/modules/setup/ModifierFilter.cpp b/src/shammodels/sph/src/modules/setup/ModifierFilter.cpp index dfac7680c6..ed59238297 100644 --- a/src/shammodels/sph/src/modules/setup/ModifierFilter.cpp +++ b/src/shammodels/sph/src/modules/setup/ModifierFilter.cpp @@ -20,7 +20,7 @@ #include "shambackends/DeviceBuffer.hpp" #include "shamcomm/logs.hpp" #include "shammodels/sph/Solver.hpp" -#include "shammodels/sph/math/density.hpp" +#include "shammodels/common/density.hpp" #include "shammodels/sph/modules/setup/ISPHSetupNode.hpp" #include "shammodels/sph/modules/setup/ModifierFilter.hpp" #include "shamrock/scheduler/ShamrockCtx.hpp" From 12654adb92aa08568536a6d9afad9504af4446d4 Mon Sep 17 00:00:00 2001 From: Yona Lapeyre Date: Wed, 18 Mar 2026 00:45:58 +0900 Subject: [PATCH 2/3] move instanciations to specific solvers --- .../common/modules/render/CartesianRender.hpp | 1 - .../src/modules/render/CartesianRender.cpp | 37 +--- .../src/modules/render/RenderFieldGetter.cpp | 36 ---- src/shammodels/gsph/CMakeLists.txt | 1 + .../modules/render/RenderInstanciations.cpp | 49 +++++ src/shammodels/gsph/src/pyGSPHModel.cpp | 173 +++++++++++++++++- src/shammodels/sph/CMakeLists.txt | 1 + .../modules/render/RenderInstanciations.cpp | 49 +++++ src/shammodels/sph/src/pySPHModel.cpp | 67 ++++--- 9 files changed, 321 insertions(+), 93 deletions(-) create mode 100644 src/shammodels/gsph/src/modules/render/RenderInstanciations.cpp create mode 100644 src/shammodels/sph/src/modules/render/RenderInstanciations.cpp diff --git a/src/shammodels/common/include/shammodels/common/modules/render/CartesianRender.hpp b/src/shammodels/common/include/shammodels/common/modules/render/CartesianRender.hpp index cb88db2b26..843330fd12 100644 --- a/src/shammodels/common/include/shammodels/common/modules/render/CartesianRender.hpp +++ b/src/shammodels/common/include/shammodels/common/modules/render/CartesianRender.hpp @@ -19,7 +19,6 @@ #include "shambackends/DeviceBuffer.hpp" #include "shambackends/typeAliasVec.hpp" #include "shambackends/vec.hpp" -#include "shammodels/sph/SolverConfig.hpp" #include "shammodels/common/modules/render/RenderConfig.hpp" #include "shamrock/scheduler/ShamrockCtx.hpp" #include diff --git a/src/shammodels/common/src/modules/render/CartesianRender.cpp b/src/shammodels/common/src/modules/render/CartesianRender.cpp index cc99275cdf..420cd34a98 100644 --- a/src/shammodels/common/src/modules/render/CartesianRender.cpp +++ b/src/shammodels/common/src/modules/render/CartesianRender.cpp @@ -20,6 +20,9 @@ #include "shammath/AABB.hpp" #include "shammodels/common/density.hpp" #include "shammodels/common/modules/render/CartesianRender.hpp" +#include "shamtree/KarrasRadixTreeField.hpp" +#include "shamtree/RadixTree.hpp" +#include "shamtree/TreeTraversal.hpp" #include "shammodels/common/modules/render/RenderFieldGetter.hpp" #include "shamrock/scheduler/SchedulerUtility.hpp" @@ -617,37 +620,3 @@ namespace shammodels::common::modules { } } // namespace shammodels::sph::modules - -using namespace shammath; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; - -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; - -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; - -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; - -//gsph -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; - -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; - -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; - -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; -template class shammodels::common::modules::CartesianRender>; \ No newline at end of file diff --git a/src/shammodels/common/src/modules/render/RenderFieldGetter.cpp b/src/shammodels/common/src/modules/render/RenderFieldGetter.cpp index 40f4587c9f..8ce7975519 100644 --- a/src/shammodels/common/src/modules/render/RenderFieldGetter.cpp +++ b/src/shammodels/common/src/modules/render/RenderFieldGetter.cpp @@ -101,7 +101,6 @@ namespace shammodels::common::modules { cgh.parallel_for( sycl::range<1>{pdat.get_obj_cnt()}, [=](sycl::item<1> item) { u32 gid = (u32) item.get_id(); - using namespace sph; acc_inv_hpart[gid] = 1.0 / acc_h[gid]; }); }); @@ -195,38 +194,3 @@ namespace shammodels::common::modules { return lambda(field_source_getter); } } // namespace shammodels::sph::modules - -using namespace shammath; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; - -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; - -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; - -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; - - -//gsph -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; - -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; - -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; - -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; -template class shammodels::common::modules::RenderFieldGetter>; diff --git a/src/shammodels/gsph/CMakeLists.txt b/src/shammodels/gsph/CMakeLists.txt index 26ccebdb2f..15a6b6fbba 100644 --- a/src/shammodels/gsph/CMakeLists.txt +++ b/src/shammodels/gsph/CMakeLists.txt @@ -20,6 +20,7 @@ set(Sources src/modules/UpdateDerivs.cpp src/modules/GSPHGhostHandler.cpp src/modules/io/VTKDump.cpp + src/render/RenderInstanciations.cpp ) if(SHAMROCK_USE_SHARED_LIB) diff --git a/src/shammodels/gsph/src/modules/render/RenderInstanciations.cpp b/src/shammodels/gsph/src/modules/render/RenderInstanciations.cpp new file mode 100644 index 0000000000..b528d33a2a --- /dev/null +++ b/src/shammodels/gsph/src/modules/render/RenderInstanciations.cpp @@ -0,0 +1,49 @@ +#include "shambase/aliases_float.hpp" +#include "shammodels/common/modules/render/RenderFieldGetter.hpp" +#include "shammodels/common/modules/render/CartesianRender.hpp" +#include "shammodels/gsph/modules/SolverStorage.hpp" +#include "shambackends/DeviceBuffer.hpp" +#include "shambackends/typeAliasVec.hpp" +#include "shambackends/vec.hpp" +#include "shammodels/common/modules/render/RenderConfig.hpp" +#include "shammath/sphkernels.hpp" +#include "shampylib/PatchDataToPy.hpp" +#include "shamrock/scheduler/ShamrockCtx.hpp" +#include + +#pragma once + +using namespace shammath; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +//gsph +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; \ No newline at end of file diff --git a/src/shammodels/gsph/src/pyGSPHModel.cpp b/src/shammodels/gsph/src/pyGSPHModel.cpp index 4604936c87..aab49b204a 100644 --- a/src/shammodels/gsph/src/pyGSPHModel.cpp +++ b/src/shammodels/gsph/src/pyGSPHModel.cpp @@ -32,6 +32,17 @@ #include "shammodels/common/shamrock_json_to_py_json.hpp" #include "shammodels/gsph/Model.hpp" #include "shamrock/scheduler/PatchScheduler.hpp" +#include "shammodels/sph/Model.hpp" +#include "shammodels/sph/io/PhantomDump.hpp" +#include "shammodels/sph/modules/AnalysisBarycenter.hpp" +#include "shammodels/sph/modules/AnalysisDisc.hpp" +#include "shammodels/sph/modules/AnalysisEnergyKinetic.hpp" +#include "shammodels/sph/modules/AnalysisEnergyPotential.hpp" +#include "shammodels/sph/modules/AnalysisSodTube.hpp" +#include "shammodels/sph/modules/AnalysisTotalMomentum.hpp" +#include "shammodels/common/modules/render/CartesianRender.hpp" +#include "shammodels/common/modules/render/RenderConfig.hpp" + #include #include #include @@ -44,6 +55,8 @@ void add_gsph_instance(py::module &m, std::string name_config, std::string name_ using T = Model; using TConfig = typename T::SolverConfig; + using custom_getter_t = std::function(size_t, pybind11::dict &)>; + using RenderConfig = shammodels::common::RenderConfig; shamlog_debug_ln("[Py]", "registering class :", name_config, typeid(T).name()); shamlog_debug_ln("[Py]", "registering class :", name_model, typeid(T).name()); @@ -410,7 +423,165 @@ void add_gsph_instance(py::module &m, std::string name_config, std::string name_ Example ------- >>> model.dump("checkpoint.shamrock") -)=="); +)==") +.def( + "render_cartesian_slice", + [](T &self, + const std::string &name, + const std::string &field_type, + Tvec center, + Tvec delta_x, + Tvec delta_y, + u32 nx, + u32 ny, + const std::optional &custom_getter) + -> std::variant> { + + shammodels::common::RenderConfig rc{ + self.solver.solver_config.gpart_mass, + self.solver.solver_config.tree_reduction_level + }; + if (custom_getter.has_value()) { + if (!(name == "custom" && field_type == "f64")) { + throw shambase::make_except_with_loc( + "custom_getter only available for name=custom and field_type=f64"); + } + } + + if (field_type == "f64") { + py::array_t ret({ny, nx}); + + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); + + std::vector slice + = render + .compute_slice(name, center, delta_x, delta_y, nx, ny, custom_getter) + .copy_to_stdvec(); + + for (u32 iy = 0; iy < ny; iy++) { + for (u32 ix = 0; ix < nx; ix++) { + ret.mutable_at(iy, ix) = slice[ix + nx * iy]; + } + } + + return ret; + } + + if (field_type == "f64_3") { + py::array_t ret({ny, nx, 3_u32}); + + shammodels::common::modules::CartesianRender> render( + self.ctx, + rc, + self.solver.storage); + + std::vector slice + = render.compute_slice(name, center, delta_x, delta_y, nx, ny, std::nullopt) + .copy_to_stdvec(); + + for (u32 iy = 0; iy < ny; iy++) { + for (u32 ix = 0; ix < nx; ix++) { + ret.mutable_at(iy, ix, 0) = slice[ix + nx * iy][0]; + ret.mutable_at(iy, ix, 1) = slice[ix + nx * iy][1]; + ret.mutable_at(iy, ix, 2) = slice[ix + nx * iy][2]; + } + } + + return ret; + } + + shambase::throw_with_loc("unknown field type"); + return py::array_t({nx, ny}); + }, + py::arg("name"), + py::arg("field_type"), + py::arg("center"), + py::arg("delta_x"), + py::arg("delta_y"), + py::arg("nx"), + py::arg("ny"), + py::arg("custom_getter") = std::nullopt) + .def( + "render_cartesian_column_integ", + [](T &self, + const std::string &name, + const std::string &field_type, + Tvec center, + Tvec delta_x, + Tvec delta_y, + u32 nx, + u32 ny, + const std::optional &custom_getter) + -> std::variant> { + shammodels::common::RenderConfig rc{ + self.solver.solver_config.gpart_mass, + self.solver.solver_config.tree_reduction_level + }; + if (custom_getter.has_value()) { + if (!(name == "custom" && field_type == "f64")) { + throw shambase::make_except_with_loc( + "custom_getter only available for name=custom and field_type=f64"); + } + } + + if (field_type == "f64") { + py::array_t ret({ny, nx}); + + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); + + std::vector slice + = render + .compute_column_integ( + name, center, delta_x, delta_y, nx, ny, custom_getter) + .copy_to_stdvec(); + + for (u32 iy = 0; iy < ny; iy++) { + for (u32 ix = 0; ix < nx; ix++) { + ret.mutable_at(iy, ix) = slice[ix + nx * iy]; + } + } + + return ret; + } + + if (field_type == "f64_3") { + py::array_t ret({ny, nx, 3_u32}); + + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); + + std::vector slice + = render + .compute_column_integ( + name, center, delta_x, delta_y, nx, ny, std::nullopt) + .copy_to_stdvec(); + + for (u32 iy = 0; iy < ny; iy++) { + for (u32 ix = 0; ix < nx; ix++) { + ret.mutable_at(iy, ix, 0) = slice[ix + nx * iy][0]; + ret.mutable_at(iy, ix, 1) = slice[ix + nx * iy][1]; + ret.mutable_at(iy, ix, 2) = slice[ix + nx * iy][2]; + } + } + + return ret; + } + + shambase::throw_with_loc("unknown field type"); + return py::array_t({nx, ny}); + }, + py::arg("name"), + py::arg("field_type"), + py::arg("center"), + py::arg("delta_x"), + py::arg("delta_y"), + py::arg("nx"), + py::arg("ny"), + py::arg("custom_getter") = std::nullopt) + +; } using namespace shammodels::gsph; diff --git a/src/shammodels/sph/CMakeLists.txt b/src/shammodels/sph/CMakeLists.txt index c892ab735e..e02c33cf52 100644 --- a/src/shammodels/sph/CMakeLists.txt +++ b/src/shammodels/sph/CMakeLists.txt @@ -62,6 +62,7 @@ set(Sources src/modules/self_gravity/SGFMMPlummer.cpp src/modules/self_gravity/SGSFMMPlummer.cpp src/modules/io/VTKDump.cpp + src/modules/render/RenderInstanciations.cpp ) if(SHAMROCK_USE_SHARED_LIB) diff --git a/src/shammodels/sph/src/modules/render/RenderInstanciations.cpp b/src/shammodels/sph/src/modules/render/RenderInstanciations.cpp new file mode 100644 index 0000000000..ffe7dc6048 --- /dev/null +++ b/src/shammodels/sph/src/modules/render/RenderInstanciations.cpp @@ -0,0 +1,49 @@ +#include "shambase/aliases_float.hpp" +#include "shammodels/common/modules/render/RenderFieldGetter.hpp" +#include "shammodels/common/modules/render/CartesianRender.hpp" +#include "shammodels/sph/modules/SolverStorage.hpp" +#include "shambackends/DeviceBuffer.hpp" +#include "shambackends/typeAliasVec.hpp" +#include "shambackends/vec.hpp" +#include "shammodels/common/modules/render/RenderConfig.hpp" +#include "shammath/sphkernels.hpp" +#include "shampylib/PatchDataToPy.hpp" +#include "shamrock/scheduler/ShamrockCtx.hpp" +#include + +#pragma once + +using namespace shammath; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; +template class shammodels::common::modules::RenderFieldGetter>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; +template class shammodels::common::modules::CartesianRender>; + diff --git a/src/shammodels/sph/src/pySPHModel.cpp b/src/shammodels/sph/src/pySPHModel.cpp index 74da727ebb..3c169e4eb6 100644 --- a/src/shammodels/sph/src/pySPHModel.cpp +++ b/src/shammodels/sph/src/pySPHModel.cpp @@ -24,6 +24,7 @@ #include "shammath/sphkernels.hpp" #include "shammodels/common/shamrock_json_to_py_json.hpp" #include "shammodels/sph/Model.hpp" +#include "shammodels/common/modules/render/RenderConfig.hpp" #include "shammodels/sph/io/PhantomDump.hpp" #include "shammodels/sph/modules/AnalysisBarycenter.hpp" #include "shammodels/sph/modules/AnalysisDisc.hpp" @@ -31,7 +32,7 @@ #include "shammodels/sph/modules/AnalysisEnergyPotential.hpp" #include "shammodels/sph/modules/AnalysisSodTube.hpp" #include "shammodels/sph/modules/AnalysisTotalMomentum.hpp" -#include "shammodels/sph/modules/render/CartesianRender.hpp" +#include "shammodels/common/modules/render/CartesianRender.hpp" #include "shamphys/SodTube.hpp" #include "shamrock/scheduler/PatchScheduler.hpp" #include @@ -52,12 +53,15 @@ void add_instance(py::module &m, std::string name_config, std::string name_model using TAnalysisDisc = shammodels::sph::modules::AnalysisDisc; using TSPHSetup = shammodels::sph::modules::SPHSetup; using TConfig = typename T::Solver::Config; + using RenderConfig = shammodels::common::RenderConfig; using custom_getter_t = std::function(size_t, pybind11::dict &)>; shamlog_debug_ln("[Py]", "registering class :", name_config, typeid(T).name()); shamlog_debug_ln("[Py]", "registering class :", name_model, typeid(T).name()); + + py::class_ config_cls(m, name_config.c_str()); shammodels::common::add_json_defs(config_cls); @@ -571,6 +575,7 @@ void add_instance(py::module &m, std::string name_config, std::string name_model py::arg("use_new_setup") = true); py::class_(m, name_model.c_str()) + .def(py::init([](ShamrockCtx &ctx) { return std::make_unique(ctx); })) @@ -858,6 +863,10 @@ void add_instance(py::module &m, std::string name_config, std::string name_model const std::vector &positions, const std::optional &custom_getter) -> std::variant, std::vector> { + shammodels::common::RenderConfig rc{ + self.solver.solver_config.gpart_mass, + self.solver.solver_config.tree_reduction_level + }; if (custom_getter.has_value()) { if (!(name == "custom" && field_type == "f64")) { throw shambase::make_except_with_loc( @@ -866,14 +875,14 @@ void add_instance(py::module &m, std::string name_config, std::string name_model } if (field_type == "f64") { - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); return render.compute_slice(name, positions, custom_getter).copy_to_stdvec(); } if (field_type == "f64_3") { - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); return render.compute_slice(name, positions, std::nullopt).copy_to_stdvec(); } @@ -891,6 +900,10 @@ void add_instance(py::module &m, std::string name_config, std::string name_model const std::vector> &rays, const std::optional &custom_getter) -> std::variant, std::vector> { + shammodels::common::RenderConfig rc{ + self.solver.solver_config.gpart_mass, + self.solver.solver_config.tree_reduction_level + }; if (custom_getter.has_value()) { if (!(name == "custom" && field_type == "f64")) { throw shambase::make_except_with_loc( @@ -899,14 +912,14 @@ void add_instance(py::module &m, std::string name_config, std::string name_model } if (field_type == "f64") { - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); return render.compute_column_integ(name, rays, custom_getter).copy_to_stdvec(); } if (field_type == "f64_3") { - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); return render.compute_column_integ(name, rays, std::nullopt).copy_to_stdvec(); } @@ -924,6 +937,10 @@ void add_instance(py::module &m, std::string name_config, std::string name_model const std::vector> &ring_rays, const std::optional &custom_getter) -> std::variant, std::vector> { + shammodels::common::RenderConfig rc{ + self.solver.solver_config.gpart_mass, + self.solver.solver_config.tree_reduction_level + }; if (custom_getter.has_value()) { if (!(name == "custom" && field_type == "f64")) { throw shambase::make_except_with_loc( @@ -932,15 +949,15 @@ void add_instance(py::module &m, std::string name_config, std::string name_model } if (field_type == "f64") { - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); return render.compute_azymuthal_integ(name, ring_rays, custom_getter) .copy_to_stdvec(); } if (field_type == "f64_3") { - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); return render.compute_azymuthal_integ(name, ring_rays, std::nullopt) .copy_to_stdvec(); } @@ -963,6 +980,10 @@ void add_instance(py::module &m, std::string name_config, std::string name_model u32 ny, const std::optional &custom_getter) -> std::variant> { + shammodels::common::RenderConfig rc{ + self.solver.solver_config.gpart_mass, + self.solver.solver_config.tree_reduction_level + }; if (custom_getter.has_value()) { if (!(name == "custom" && field_type == "f64")) { throw shambase::make_except_with_loc( @@ -973,8 +994,8 @@ void add_instance(py::module &m, std::string name_config, std::string name_model if (field_type == "f64") { py::array_t ret({ny, nx}); - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); std::vector slice = render @@ -993,8 +1014,8 @@ void add_instance(py::module &m, std::string name_config, std::string name_model if (field_type == "f64_3") { py::array_t ret({ny, nx, 3_u32}); - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); std::vector slice = render.compute_slice(name, center, delta_x, delta_y, nx, ny, std::nullopt) @@ -1034,6 +1055,10 @@ void add_instance(py::module &m, std::string name_config, std::string name_model u32 ny, const std::optional &custom_getter) -> std::variant> { + shammodels::common::RenderConfig rc{ + self.solver.solver_config.gpart_mass, + self.solver.solver_config.tree_reduction_level + }; if (custom_getter.has_value()) { if (!(name == "custom" && field_type == "f64")) { throw shambase::make_except_with_loc( @@ -1044,8 +1069,8 @@ void add_instance(py::module &m, std::string name_config, std::string name_model if (field_type == "f64") { py::array_t ret({ny, nx}); - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); std::vector slice = render @@ -1065,8 +1090,8 @@ void add_instance(py::module &m, std::string name_config, std::string name_model if (field_type == "f64_3") { py::array_t ret({ny, nx, 3_u32}); - modules::CartesianRender render( - self.ctx, self.solver.solver_config, self.solver.storage); + shammodels::common::modules::CartesianRender> render( + self.ctx, rc, self.solver.storage); std::vector slice = render From d8f535d259be4773f18a57ec9525330a605400e1 Mon Sep 17 00:00:00 2001 From: Yona Lapeyre Date: Wed, 18 Mar 2026 00:47:41 +0900 Subject: [PATCH 3/3] typo in CMakelist --- src/shammodels/gsph/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shammodels/gsph/CMakeLists.txt b/src/shammodels/gsph/CMakeLists.txt index 15a6b6fbba..81a8d24ab3 100644 --- a/src/shammodels/gsph/CMakeLists.txt +++ b/src/shammodels/gsph/CMakeLists.txt @@ -20,7 +20,7 @@ set(Sources src/modules/UpdateDerivs.cpp src/modules/GSPHGhostHandler.cpp src/modules/io/VTKDump.cpp - src/render/RenderInstanciations.cpp + src/modules/render/RenderInstanciations.cpp ) if(SHAMROCK_USE_SHARED_LIB)