32 class AnalysisEnergyPotential {
34 using Tscal = shambase::VecComponent<Tvec>;
35 static constexpr u32 dim = shambase::VectorProperties<Tvec>::dimension;
44 : model(model), ctx(model.ctx), solver(model.solver) {};
46 auto get_potential_energy() -> Tscal {
48 auto dev_sched_ptr = shamsys::instance::get_compute_scheduler_ptr();
51 const u32 ixyz = sched.pdl_old().template get_field_idx<Tvec>(
"xyz");
52 const Tscal pmass = solver.solver_config.gpart_mass;
61 std::vector<GravSource> grav_sources;
66 for (
size_t i = 0; i < pos.size(); i++) {
67 grav_sources.push_back({pos[i], mass[i]});
72 using EF_PointMass =
typename SolverConfigExtForce::PointMass;
73 using EF_LenseThirring =
typename SolverConfigExtForce::LenseThirring;
74 using EF_ShearingBoxForce =
typename SolverConfigExtForce::ShearingBoxForce;
76 for (
const auto &var_force : solver.solver_config.ext_force_config.ext_forces) {
77 if (
const EF_PointMass *ext_force = std::get_if<EF_PointMass>(&var_force.val)) {
78 grav_sources.push_back({Tvec{}, ext_force->central_mass});
80 const EF_LenseThirring *ext_force
81 = std::get_if<EF_LenseThirring>(&var_force.val)) {
82 grav_sources.push_back({Tvec{}, ext_force->central_mass});
86 if (!grav_sources.empty()) {
88 using Tscal4 = sycl::vec<Tscal, 4>;
89 std::vector<Tscal4> sources{};
91 for (
const auto &grav_source : grav_sources) {
104 u32 len = pdat.get_obj_cnt();
115 G = solver.solver_config.get_constant_G(),
116 source_count = sources.size()](
118 const Tvec *__restrict xyz,
119 const Tscal4 *__restrict sources,
120 Tscal *__restrict epot_part) {
126 for (u32 j = 0; j < source_count; ++j) {
127 Tscal4 source = sources[j];
130 sink_pos = {source.x(), source.y(), source.z()};
132 loc_epot += -pmass * G * smass / sycl::length(xyz[i] - sink_pos);
134 epot_part[i] = loc_epot;
141 Tscal tot_epot = shamalgs::collective::allreduce_sum(epot);
143 Tscal G = solver.solver_config.get_constant_G();
145 for (
size_t i = 0; i < grav_sources.size(); ++i) {
146 for (
size_t j = i + 1; j < grav_sources.size(); ++j) {
147 const auto &sink1 = grav_sources[i];
148 const auto &sink2 = grav_sources[j];
150 Tvec delta = sink1.pos - sink2.pos;
151 Tscal d = sycl::length(delta);
void kernel_call(sham::DeviceQueue &q, RefIn in, RefOut in_out, u32 n, Functor &&func, SourceLocation &&callsite=SourceLocation{})
Submit a kernel to a SYCL queue.