32 auto edges = get_edges();
34 auto &thread_counts = edges.sizes.indexes;
36 edges.neigh_cache.check_sizes(thread_counts);
37 edges.positions.check_sizes(thread_counts);
38 edges.old_h.check_sizes(thread_counts);
39 edges.new_h.check_sizes(thread_counts);
40 edges.eps_h.check_sizes(thread_counts);
41 edges.h_bisect_lo.check_sizes(thread_counts);
42 edges.h_bisect_hi.check_sizes(thread_counts);
44 auto &neigh_cache = edges.neigh_cache.neigh_cache;
45 auto &positions = edges.positions.get_spans();
46 auto &old_h = edges.old_h.get_spans();
47 auto &new_h = edges.new_h.get_spans();
48 auto &eps_h = edges.eps_h.get_spans();
49 auto &h_bisect_lo = edges.h_bisect_lo.get_spans();
50 auto &h_bisect_hi = edges.h_bisect_hi.get_spans();
52 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
54 static constexpr Tscal Rkern = SPHKernel::Rkern;
61 [gpart_mass = this->gpart_mass,
62 h_evol_max = this->h_evol_max,
63 h_evol_iter_max = this->h_evol_iter_max,
64 epsilon_h = this->epsilon_h](
67 const Tvec *__restrict r,
68 const Tscal *__restrict h_old,
69 Tscal *__restrict h_new,
70 Tscal *__restrict eps,
71 Tscal *__restrict h_lo,
72 Tscal *__restrict h_hi) {
76 Tscal part_mass = gpart_mass;
77 Tscal h_max_tot_max_evol = h_evol_max;
78 Tscal h_max_evol_p = h_evol_iter_max;
79 Tscal h_max_evol_m = 0.5;
81 if (eps[id_a] > epsilon_h) {
85 Tscal h_a = h_new[id_a];
86 Tscal dint = h_a * h_a * Rkern * Rkern;
91 particle_looper.for_each_object(id_a, [&](
u32 id_b) {
92 Tvec dr = xyz_a - r[id_b];
93 Tscal rab2 = sycl::dot(dr, dr);
99 Tscal rab = sycl::sqrt(rab2);
101 rho_sum += part_mass * SPHKernel::W_3d(rab, h_a);
102 sumdWdh += part_mass * SPHKernel::dhW_3d(rab, h_a);
105 using namespace shamrock::sph;
107 Tscal rho_ha = rho_h(part_mass, h_a, SPHKernel::hfactd);
108 Tscal f_iter = rho_sum - rho_ha;
109 Tscal df_iter = sumdWdh + 3 * rho_ha / h_a;
110 Tscal new_h_nr = h_a - f_iter / df_iter;
112 Tscal lo = h_lo[id_a];
113 Tscal hi = h_hi[id_a];
115 bool accept_nr = lo < new_h_nr && new_h_nr < hi;
127 new_h = (lo + hi) / 2;
130 if (new_h < h_a * h_max_evol_m)
131 new_h = h_max_evol_m * h_a;
132 if (new_h > h_a * h_max_evol_p)
133 new_h = h_max_evol_p * h_a;
138 Tscal ha_0 = h_old[id_a];
140 if (new_h < ha_0 * h_max_tot_max_evol) {
142 eps[id_a] = sycl::fabs(new_h - h_a) / ha_0;
144 h_new[id_a] = ha_0 * h_max_tot_max_evol;