25template<
class Tvec,
template<
class>
class SPHKernel>
26void shammodels::sph::modules::UpdateViscosity<Tvec, SPHKernel>::update_artificial_viscosity(
29 using Cfg_AV =
typename Config::AVConfig;
31 using None =
typename Cfg_AV::None;
32 using Constant =
typename Cfg_AV::Constant;
33 using VaryingMM97 =
typename Cfg_AV::VaryingMM97;
34 using VaryingCD10 =
typename Cfg_AV::VaryingCD10;
35 using ConstantDisc =
typename Cfg_AV::ConstantDisc;
36 if (None *v = std::get_if<None>(&solver_config.artif_viscosity.config)) {
37 shamlog_debug_ln(
"UpdateViscosity",
"skipping artif viscosity update (No viscosity mode)");
38 }
else if (Constant *v = std::get_if<Constant>(&solver_config.artif_viscosity.config)) {
39 shamlog_debug_ln(
"UpdateViscosity",
"skipping artif viscosity update (Constant mode)");
40 }
else if (VaryingMM97 *v = std::get_if<VaryingMM97>(&solver_config.artif_viscosity.config)) {
41 update_artificial_viscosity_mm97(dt, *v);
42 }
else if (VaryingCD10 *v = std::get_if<VaryingCD10>(&solver_config.artif_viscosity.config)) {
43 update_artificial_viscosity_cd10(dt, *v);
44 }
else if (ConstantDisc *v = std::get_if<ConstantDisc>(&solver_config.artif_viscosity.config)) {
45 shamlog_debug_ln(
"UpdateViscosity",
"skipping artif viscosity update (constant AV)");
51template<
class Tvec,
template<
class>
class SPHKernel>
52void shammodels::sph::modules::UpdateViscosity<Tvec, SPHKernel>::update_artificial_viscosity_mm97(
53 Tscal dt,
typename Config::AVConfig::VaryingMM97 cfg) {
55 shamlog_debug_ln(
"UpdateViscosity",
"Updating alpha viscosity (Morris & Monaghan 1997)");
57 using namespace shamrock::patch;
77 u32 obj_cnt = pdat.get_obj_cnt();
79 sham::DeviceQueue &queue = shamsys::instance::get_compute_scheduler().get_queue();
84 auto cs = buf_cs.get_read_access(depends_list);
85 auto h = buf_h.get_read_access(depends_list);
86 auto alpha_AV = buf_alpha_AV.get_read_access(depends_list);
87 auto alpha_AV_updated = buf_alpha_AV_updated.get_write_access(depends_list);
89 auto e = queue.
submit(depends_list, [&, dt](sycl::handler &cgh) {
90 Tscal sigma_decay = cfg.sigma_decay;
91 Tscal alpha_min = cfg.alpha_min;
92 Tscal alpha_max = cfg.alpha_max;
94 cgh.parallel_for(sycl::range<1>{obj_cnt}, [=](sycl::item<1> item) {
95 Tscal cs_a = cs[item];
97 Tscal alpha_a = alpha_AV[item];
98 Tscal divv_a = divv[item];
101 Tscal inv_tau_a = vsig * sigma_decay / h_a;
102 Tscal fact_t = dt * inv_tau_a;
103 Tscal euler_impl_fact = 1 / (1 + fact_t);
105 Tscal source = sham::max<Tscal>(0., -divv_a);
107 Tscal new_alpha = (alpha_a + source * dt + fact_t * alpha_min) * euler_impl_fact;
109 alpha_AV_updated[item] = sham::min(alpha_max, new_alpha);
114 buf_cs.complete_event_state(e);
115 buf_h.complete_event_state(e);
116 buf_alpha_AV.complete_event_state(e);
117 buf_alpha_AV_updated.complete_event_state(e);
121template<
class Tvec,
template<
class>
class SPHKernel>
122void shammodels::sph::modules::UpdateViscosity<Tvec, SPHKernel>::update_artificial_viscosity_cd10(
123 Tscal dt,
typename Config::AVConfig::VaryingCD10 cfg) {
126 shamlog_debug_ln(
"UpdateViscosity",
"Updating alpha viscosity (Cullen & Dehnen 2010)");
128 using namespace shamrock::patch;
151 u32 obj_cnt = pdat.get_obj_cnt();
157 sham::MultiRef{buf_divv, buf_curlv, buf_dtdivv, buf_cs, buf_h, buf_alpha_AV},
160 [sigma_decay = cfg.sigma_decay,
161 alpha_min = cfg.alpha_min,
162 alpha_max = cfg.alpha_max,
165 const Tscal *__restrict divv,
166 const Tvec *__restrict curlv,
167 const Tscal *__restrict dtdivv,
168 const Tscal *__restrict cs,
169 const Tscal *__restrict h,
170 const Tscal *__restrict alpha_AV,
171 Tscal *__restrict alpha_AV_updated) {
174 Tscal alpha_a = alpha_AV[i];
175 Tscal divv_a = divv[i];
176 Tvec curlv_a = curlv[i];
177 Tscal dtdivv_a = dtdivv[i];
180 Tscal inv_tau_a = vsig * sigma_decay / h_a;
181 Tscal fact_t = dt * inv_tau_a;
182 Tscal euler_impl_fact = 1 / (1 + fact_t);
191 auto xi_lim = [](Tscal divv, Tvec curlv) {
192 auto fac = sham::max(-divv, Tscal{0});
194 auto traceS = sycl::dot(curlv, curlv);
195 if (fac + traceS > shambase::get_epsilon<Tscal>()) {
196 return fac / (fac + traceS);
200 Tscal balsara_corec = xi_lim(divv_a, curlv_a);
202 Tscal A_a = balsara_corec * sham::max<Tscal>(-dtdivv_a, 0);
204 Tscal temp = cs_a * cs_a;
207 = sham::min((cs_a > 0) ? 10 * h_a * h_a * A_a / (temp) : alpha_min, alpha_max);
209 alpha_loc_a = (temp > shambase::get_epsilon<Tscal>()) ? alpha_loc_a : alpha_min;
212 Tscal new_alpha = (alpha_a + alpha_loc_a * fact_t) * euler_impl_fact;
214 if (alpha_loc_a > alpha_a) {
215 new_alpha = alpha_loc_a;
218 alpha_AV_updated[i] = new_alpha;
std::uint32_t u32
32 bit unsigned integer
A buffer allocated in USM (Unified Shared Memory).
void complete_event_state(sycl::event e) const
Complete the event state of the buffer.
const T * get_read_access(sham::EventList &depends_list, SourceLocation src_loc=SourceLocation{}) const
Get a read-only pointer to the buffer's data.
A SYCL queue associated with a device and a context.
sycl::event submit(Fct &&fct)
Submits a kernel to the SYCL queue.
Class to manage a list of SYCL events.
u32 get_field_idx(const std::string &field_name) const
Get the field id if matching name & type.
PatchDataLayer container class, the layout is described in patchdata_layout.
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.
T & get_check_ref(const std::unique_ptr< T > &ptr, SourceLocation loc=SourceLocation())
Takes a std::unique_ptr and returns a reference to the object it holds. It throws a std::runtime_erro...
void throw_unimplemented(SourceLocation loc=SourceLocation{})
Throw a std::runtime_error saying that the function is unimplemented.
namespace for math utility
file containing formulas for sph forces
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
A class that references multiple buffers or similar objects.
Patch object that contain generic patch information.
u64 id_patch
unique key that identify the patch