Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/shammodels/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,31 @@
#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 "shamrock/scheduler/ShamrockCtx.hpp"
#include <pybind11/numpy.h>
#include <pybind11/pytypes.h>

namespace shammodels::sph::modules {
namespace shammodels::common::modules {

template<class Tvec, class Tfield, template<class> class SPHKernel>
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
class CartesianRender {
public:
using Tscal = shambase::VecComponent<Tvec>;
static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
using Kernel = SPHKernel<Tscal>;

using Config = SolverConfig<Tvec, SPHKernel>;
using Storage = SolverStorage<Tvec, u32>;
using RenderConfig = shammodels::common::RenderConfig<Tscal>;
using Storage = TStorage;//SolverStorage<Tvec, u32>;

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<Tfield> &(
const shamrock::patch::Patch cur_p, shamrock::patch::PatchDataLayer &pdat);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// -------------------------------------------------------//
//
// 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 RenderConfig.hpp

* @author Yona Lapeyre (yona.lapeyre@ens-lyon.fr)
* @brief
*
*/


namespace shammodels::common {

template<class Tscal>
struct RenderConfig;

template<class Tscal>
struct RenderConfig {
//Tscal hfact;
Tscal gpart_mass;
unsigned int tree_reduction_level;

};
Comment on lines +23 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The forward declaration template<class Tscal> struct RenderConfig; on line 24 is redundant since the struct is defined immediately after. Also, the struct definition has inconsistent indentation. I'd also recommend adding a newline at the end of the file for consistency with other files.

template<class Tscal>
struct RenderConfig {
    //Tscal hfact;
    Tscal gpart_mass;
    unsigned int tree_reduction_level;
};


}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pybind11/pytypes.h>

namespace shammodels::sph::modules {
namespace shammodels::common::modules {

template<class Tvec, class Tfield, template<class> class SPHKernel>
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
class RenderFieldGetter {
public:
using Tscal = shambase::VecComponent<Tvec>;
static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
using Kernel = SPHKernel<Tscal>;

using Config = SolverConfig<Tvec, SPHKernel>;
using Storage = SolverStorage<Tvec, u32>;
using RenderConfig = common::RenderConfig<Tscal>;
using Storage = TStorage;//SolverStorage<Tvec, u32>;

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<Tfield> &(
const shamrock::patch::Patch cur_p, shamrock::patch::PatchDataLayer &pdat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
#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 "shamtree/KarrasRadixTreeField.hpp"
#include "shamtree/RadixTree.hpp"
#include "shamtree/TreeTraversal.hpp"
#include "shammodels/common/modules/render/RenderFieldGetter.hpp"
#include "shamrock/scheduler/SchedulerUtility.hpp"

namespace shammodels::sph::modules {
namespace shammodels::common::modules {

template<class Tvec>
sham::DeviceBuffer<Tvec> pixel_to_positions(
Expand Down Expand Up @@ -95,8 +98,8 @@ namespace shammodels::sph::modules {
return ret;
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_slice(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_slice(
std::string field_name,
const sham::DeviceBuffer<Tvec> &positions,
std::optional<std::function<py::array_t<Tfield>(size_t, pybind11::dict &)>> custom_getter)
Expand All @@ -114,7 +117,7 @@ namespace shammodels::sph::modules {
shambase::Timer t;
t.start();

auto ret = RenderFieldGetter<Tvec, Tfield, SPHKernel>(context, solver_config, storage)
auto ret = RenderFieldGetter<Tvec, Tfield, SPHKernel, TStorage>(context, render_config, storage)
.runner_function(
field_name,
[&](auto field_getter) -> sham::DeviceBuffer<Tfield> {
Expand All @@ -132,8 +135,8 @@ namespace shammodels::sph::modules {
return ret;
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_column_integ(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_column_integ(
std::string field_name,
const sham::DeviceBuffer<shammath::Ray<Tvec>> &rays,
std::optional<std::function<py::array_t<Tfield>(size_t, pybind11::dict &)>> custom_getter)
Expand All @@ -151,7 +154,7 @@ namespace shammodels::sph::modules {
shambase::Timer t;
t.start();

auto ret = RenderFieldGetter<Tvec, Tfield, SPHKernel>(context, solver_config, storage)
auto ret = RenderFieldGetter<Tvec, Tfield, SPHKernel, TStorage>(context, render_config, storage)
.runner_function(
field_name,
[&](auto field_getter) -> sham::DeviceBuffer<Tfield> {
Expand All @@ -169,8 +172,8 @@ namespace shammodels::sph::modules {
return ret;
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_azymuthal_integ(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_azymuthal_integ(
std::string field_name,
const sham::DeviceBuffer<shammath::RingRay<Tvec>> &ring_rays,
std::optional<std::function<py::array_t<Tfield>(size_t, pybind11::dict &)>> custom_getter)
Expand All @@ -188,7 +191,7 @@ namespace shammodels::sph::modules {
shambase::Timer t;
t.start();

auto ret = RenderFieldGetter<Tvec, Tfield, SPHKernel>(context, solver_config, storage)
auto ret = RenderFieldGetter<Tvec, Tfield, SPHKernel, TStorage>(context, render_config, storage)
.runner_function(
field_name,
[&](auto field_getter) -> sham::DeviceBuffer<Tfield> {
Expand All @@ -206,8 +209,8 @@ namespace shammodels::sph::modules {
return ret;
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_slice(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_slice(
std::function<field_getter_t> field_getter, const sham::DeviceBuffer<Tvec> &positions)
-> sham::DeviceBuffer<Tfield> {

Expand Down Expand Up @@ -240,7 +243,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());
Expand Down Expand Up @@ -269,7 +272,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) {
Expand Down Expand Up @@ -320,8 +323,8 @@ namespace shammodels::sph::modules {
return ret;
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_column_integ(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_column_integ(
std::function<field_getter_t> field_getter,
const sham::DeviceBuffer<shammath::Ray<Tvec>> &rays) -> sham::DeviceBuffer<Tfield> {

Expand Down Expand Up @@ -354,7 +357,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());
Expand Down Expand Up @@ -383,7 +386,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<Tfield>::get_zero();
Expand Down Expand Up @@ -435,8 +438,8 @@ namespace shammodels::sph::modules {
return ret;
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_azymuthal_integ(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_azymuthal_integ(
std::function<field_getter_t> field_getter,
const sham::DeviceBuffer<shammath::RingRay<Tvec>> &ring_rays)
-> sham::DeviceBuffer<Tfield> {
Expand Down Expand Up @@ -470,7 +473,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());
Expand Down Expand Up @@ -499,7 +502,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) {
Expand Down Expand Up @@ -560,8 +563,8 @@ namespace shammodels::sph::modules {
return ret;
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_slice(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_slice(
std::function<field_getter_t> field_getter,
Tvec center,
Tvec delta_x,
Expand All @@ -574,8 +577,8 @@ namespace shammodels::sph::modules {
return compute_slice(field_getter, positions);
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_column_integ(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_column_integ(
std::function<field_getter_t> field_getter,
Tvec center,
Tvec delta_x,
Expand All @@ -588,8 +591,8 @@ namespace shammodels::sph::modules {
return compute_column_integ(field_getter, rays);
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_slice(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_slice(
std::string field_name,
Tvec center,
Tvec delta_x,
Expand All @@ -602,8 +605,8 @@ namespace shammodels::sph::modules {
return compute_slice(field_name, positions, custom_getter);
}

template<class Tvec, class Tfield, template<class> class SPHKernel>
auto CartesianRender<Tvec, Tfield, SPHKernel>::compute_column_integ(
template<class Tvec, class Tfield, template<class> class SPHKernel, class TStorage>
auto CartesianRender<Tvec, Tfield, SPHKernel, TStorage>::compute_column_integ(
std::string field_name,
Tvec center,
Tvec delta_x,
Expand All @@ -617,20 +620,3 @@ namespace shammodels::sph::modules {
}

} // namespace shammodels::sph::modules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The namespace in this comment is incorrect after refactoring. It should be updated to reflect the new common namespace.

Suggested change
} // namespace shammodels::sph::modules
} // namespace shammodels::common::modules


using namespace shammath;
template class shammodels::sph::modules::CartesianRender<f64_3, f64, M4>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64, M6>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64, M8>;

template class shammodels::sph::modules::CartesianRender<f64_3, f64, C2>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64, C4>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64, C6>;

template class shammodels::sph::modules::CartesianRender<f64_3, f64_3, M4>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64_3, M6>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64_3, M8>;

template class shammodels::sph::modules::CartesianRender<f64_3, f64_3, C2>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64_3, C4>;
template class shammodels::sph::modules::CartesianRender<f64_3, f64_3, C6>;
Loading
Loading