Skip to main content

oxiphysics_gpu/kernels/rigid/
integratevelocitykernel_traits.rs

1//! # IntegrateVelocityKernel - Trait Implementations
2//!
3//! This module contains trait implementations for `IntegrateVelocityKernel`.
4//!
5//! ## Implemented Traits
6//!
7//! - `ComputeKernel`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11#[allow(unused_imports)]
12use super::functions::*;
13use crate::compute::ComputeKernel;
14
15use super::types::IntegrateVelocityKernel;
16
17#[allow(clippy::needless_range_loop)]
18impl ComputeKernel for IntegrateVelocityKernel {
19    fn name(&self) -> &str {
20        "IntegrateVelocityKernel"
21    }
22    fn execute(&self, inputs: &[&[f64]], outputs: &mut [Vec<f64>], work_size: usize) {
23        if inputs.len() < 4 || outputs.is_empty() {
24            return;
25        }
26        let vel = inputs[0];
27        let force = inputs[1];
28        let inv_mass = inputs[2];
29        let dt = inputs[3][0];
30        let n = work_size;
31        let mut new_vel = vec![0.0; n * 3];
32        for i in 0..n {
33            let im = inv_mass[i];
34            new_vel[i * 3] = vel[i * 3] + force[i * 3] * im * dt;
35            new_vel[i * 3 + 1] = vel[i * 3 + 1] + force[i * 3 + 1] * im * dt;
36            new_vel[i * 3 + 2] = vel[i * 3 + 2] + force[i * 3 + 2] * im * dt;
37        }
38        outputs[0] = new_vel;
39    }
40}