31 auto edges = get_edges();
33 auto &thread_counts = edges.sizes.indexes;
35 edges.neigh_cache.check_sizes(thread_counts);
36 edges.positions.check_sizes(thread_counts);
37 edges.old_h.check_sizes(thread_counts);
38 edges.new_h.check_sizes(thread_counts);
39 edges.eps_h.check_sizes(thread_counts);
41 auto &neigh_cache = edges.neigh_cache.neigh_cache;
42 auto &positions = edges.positions.get_spans();
43 auto &old_h = edges.old_h.get_spans();
44 auto &new_h = edges.new_h.get_spans();
45 auto &eps_h = edges.eps_h.get_spans();
47 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
49 static constexpr Tscal Rkern = SPHKernel::Rkern;
56 [gpart_mass = this->gpart_mass,
57 h_evol_max = this->h_evol_max,
58 h_evol_iter_max = this->h_evol_iter_max](
61 const Tvec *__restrict r,
62 const Tscal *__restrict h_old,
63 Tscal *__restrict h_new,
64 Tscal *__restrict eps) {
68 Tscal part_mass = gpart_mass;
69 Tscal h_max_tot_max_evol = h_evol_max;
70 Tscal h_max_evol_p = h_evol_iter_max;
71 Tscal h_max_evol_m = 1 / h_evol_iter_max;
74 if (eps[id_a] > 1e-6) {
78 Tscal h_a = h_new[id_a];
79 Tscal dint = h_a * h_a * Rkern * Rkern;
84 particle_looper.for_each_object(id_a, [&](
u32 id_b) {
85 Tvec dr = xyz_a - r[id_b];
86 Tscal rab2 = sycl::dot(dr, dr);
92 Tscal rab = sycl::sqrt(rab2);
94 rho_sum += part_mass * SPHKernel::W_3d(rab, h_a);
95 sumdWdh += part_mass * SPHKernel::dhW_3d(rab, h_a);
98 using namespace shamrock::sph;
100 Tscal rho_ha = rho_h(part_mass, h_a, SPHKernel::hfactd);
101 Tscal new_h = newton_iterate_new_h(rho_ha, rho_sum, sumdWdh, h_a);
103 if (new_h < h_a * h_max_evol_m)
104 new_h = h_max_evol_m * h_a;
105 if (new_h > h_a * h_max_evol_p)
106 new_h = h_max_evol_p * h_a;
108 Tscal ha_0 = h_old[id_a];
110 if (new_h < ha_0 * h_max_tot_max_evol) {
112 eps[id_a] = sycl::fabs(new_h - h_a) / ha_0;
114 h_new[id_a] = ha_0 * h_max_tot_max_evol;
123 auto sizes = get_ro_edge_base(0).get_tex_symbol();
124 auto neigh_cache = get_ro_edge_base(1).get_tex_symbol();
125 auto positions = get_ro_edge_base(2).get_tex_symbol();
126 auto old_h = get_ro_edge_base(3).get_tex_symbol();
127 auto new_h = get_rw_edge_base(0).get_tex_symbol();
128 auto eps_h = get_rw_edge_base(1).get_tex_symbol();
130 std::string tex = R
"tex(
131 Iterate smoothing length and density
134 \rho_i &= \sum_{j \in \mathcal{N}_i} m_j W(r_{ij}, h_i) \\
135 \frac{\partial \rho_i}{\partial h_i} &= \sum_{j \in \mathcal{N}_i} m_j \frac{\partial W}{\partial h}(r_{ij}, h_i) \\
136 h_i^{\rm new} &= h_i - \frac{\rho_i - \rho_h(m_i, h_i)}{\frac{\partial \rho_i}{\partial h_i} + \frac{3\rho_h(m_i, h_i)}{h_i}} \\
137 \epsilon_i &= \frac{|h_i^{\rm new} - h_i|}{h_i^{\rm old}}
142 \item $\mathcal{N}_i$ is the set of neighbors of particle $i$
143 \item $W(r, h)$ is the SPH kernel function
144 \item $\rho_h(m, h) = m \left(\frac{h_{\rm fact}}{h}\right)^3$ is the target density
145 \item $h_{\rm fact} = {hfact}$ is the kernel factor
146 \item $R_{\rm kern} = {Rkern}$ is the kernel radius
149 Input: ${sizes}$, ${neigh_cache}$, ${positions}$, ${old_h}$
150 Output: ${new_h}$, ${eps_h}$
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.