Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
ComputeJ.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
17
25#include <fmt/ranges.h>
26
27template<class Tvec, template<class> class SPHKernel>
29
31 auto edges = get_edges();
32
33 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
34 edges.J.ensure_sizes(edges.part_counts.indexes);
35
37 dev_sched,
39 edges.xyz.get_spans(),
40 edges.hpart.get_spans(),
41 edges.neigh_cache.neigh_cache,
42 edges.omega.get_spans(),
43 edges.B_on_rho.get_spans()},
44 sham::DDMultiRef{edges.J.get_spans()},
45 edges.part_counts.indexes,
46 [part_mass = this->part_mass, mu_0 = this->mu_0](
47 u32 id_a,
48 const Tvec *r,
49 const Tscal *hpart,
50 const auto ploop_ptrs,
51 const Tscal *omega,
52 const Tvec *B_on_rho,
53 Tvec *J) {
54 shamrock::tree::ObjectCacheIterator particle_looper(ploop_ptrs);
55
56 using namespace shamrock::sph;
57 using namespace shamrock::sph::mhd;
58
59 Tvec xyz_a = r[id_a]; // could be recovered from lambda
60
61 Tscal h_a = hpart[id_a];
62
63 Tscal rho_a = rho_h(part_mass, h_a, SPHKernel<Tscal>::hfactd);
64 Tscal rho_a_sq = rho_a * rho_a;
65
66 Tvec B_a = B_on_rho[id_a] * rho_a;
67 Tscal omega_a = omega[id_a];
68 Tscal sub_fact_a = rho_a * omega_a;
69
70 Tscal part_omega_sum = 0;
71 Tvec J_sum{0, 0, 0};
72
73 constexpr Tscal rker2 = SPHKernel<Tscal>::Rkern * SPHKernel<Tscal>::Rkern;
74
75 particle_looper.for_each_object(id_a, [&](u32 id_b) {
76 Tvec dr = xyz_a - r[id_b];
77 Tscal rab2 = sycl::dot(dr, dr);
78 Tscal h_b = hpart[id_b];
79
80 if (rab2 > h_a * h_a * rker2 && rab2 > h_b * h_b * rker2) {
81 return;
82 }
83
84 Tscal rab = sycl::sqrt(rab2);
85 Tscal rho_b = rho_h(part_mass, h_b, SPHKernel<Tscal>::hfactd);
86 // if (id_a == 0) {
87 // logger::raw_ln("@@@@@@ h_b", h_b);
88 // logger::raw_ln("idb", id_b);
89 // logger::raw_ln("@@@@@@ xyz_b", r[id_b]);
90 // }
91 Tvec B_b = B_on_rho[id_b] * rho_b;
92
93 Tscal Fab_a = SPHKernel<Tscal>::dW_3d(rab, h_a);
94 Tvec r_ab_unit = dr * sham::inv_sat_positive(rab);
95 Tvec nabla_Wab_ha = r_ab_unit * Fab_a;
96
97 J_sum += shamrock::sph::mhd::mag_current_j_sum(
98 part_mass, B_a, B_b, nabla_Wab_ha, sub_fact_a, mu_0);
99 });
100
101 J[id_a] = J_sum; //* 4 * _pi / c;
102 });
103}
104
105template<class Tvec, template<class> class SPHKernel>
109
110using namespace shammath;
114
std::uint32_t u32
32 bit unsigned integer
virtual std::string _impl_get_tex() const
get the tex of the node
Definition ComputeJ.cpp:106
void _impl_evaluate_internal()
evaluate the node
Definition ComputeJ.cpp:28
T inv_sat_positive(T v, T minvsat=T{1e-9}, T satval=T{0.}) noexcept
inverse saturated (positive numbers only)
Definition math.hpp:841
void distributed_data_kernel_call(sham::DeviceScheduler_ptr dev_sched, RefIn in, RefOut in_out, const shambase::DistributedData< index_t > &thread_counts, Functor &&func)
A variant of sham::kernel_call for distributed data.
namespace for math utility
Definition AABB.hpp:26
file containing formulas for sphmhd forces, evolution of magnetic and divergence cleaning fields.
This file contains the definition for the stacktrace related functionality.
#define __shamrock_stack_entry()
Macro to create a stack entry.
A variant of sham::MultiRef for distributed data.