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.ensure_sizes(thread_counts);
39 edges.eps_h.ensure_sizes(thread_counts);
40 edges.was_limited.ensure_sizes(thread_counts);
42 auto &neigh_cache = edges.neigh_cache.neigh_cache;
43 auto &positions = edges.positions.get_spans();
44 auto &old_h = edges.old_h.get_spans();
45 auto &new_h = edges.new_h.get_spans();
46 auto &eps_h = edges.eps_h.get_spans();
47 auto &was_limited = edges.was_limited.get_spans();
49 auto dev_sched = shamsys::instance::get_compute_scheduler_ptr();
51 static constexpr Tscal Rkern = SPHKernel::Rkern;
58 [gpart_mass = this->gpart_mass,
59 h_evol_max = this->h_evol_max,
60 h_evol_iter_max = this->h_evol_iter_max,
61 trigger_threshold = this->trigger_threshold](
64 const Tvec *__restrict r,
65 const Tscal *__restrict h_old,
66 Tscal *__restrict h_new,
67 Tscal *__restrict eps,
68 u32 *__restrict was_limited) {
72 Tscal part_mass = gpart_mass;
73 Tscal h_max_tot_max_evol = h_evol_max;
74 Tscal h_max_evol_p = h_evol_iter_max;
75 Tscal h_max_evol_m = 1 / h_evol_iter_max;
78 if (eps[id_a] > 1e-6) {
82 Tscal h_a = h_new[id_a];
83 Tscal dint = h_a * h_a * Rkern * Rkern;
89 u32 count_within_next = 0;
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);
95 if (rab2 <= dint * h_max_evol_p * h_max_evol_p) {
103 Tscal rab = sycl::sqrt(rab2);
105 rho_sum += part_mass * SPHKernel::W_3d(rab, h_a);
106 sumdWdh += part_mass * SPHKernel::dhW_3d(rab, h_a);
111 using namespace shamrock::sph;
113 Tscal rho_ha = rho_h(part_mass, h_a, SPHKernel::hfactd);
114 Tscal new_h = newton_iterate_new_h(rho_ha, rho_sum, sumdWdh, h_a);
116 bool exceed_inner_threshold = count_within > trigger_threshold;
117 bool exceed_outer_threshold = count_within_next > trigger_threshold;
119 if (exceed_inner_threshold) {
120 h_new[id_a] = h_max_evol_m * h_a;
122 was_limited[id_a] = 1;
126 if (exceed_outer_threshold && new_h > h_a) {
128 was_limited[id_a] = 1;
132 if (new_h < h_a * h_max_evol_m)
133 new_h = h_max_evol_m * h_a;
134 if (new_h > h_a * h_max_evol_p)
135 new_h = h_max_evol_p * h_a;
137 Tscal ha_0 = h_old[id_a];
139 if (new_h < ha_0 * h_max_tot_max_evol) {
141 eps[id_a] = sycl::fabs(new_h - h_a) / ha_0;
143 h_new[id_a] = ha_0 * h_max_tot_max_evol;
146 was_limited[id_a] = 0;