roche/vel_transform.rs
1use crate::errors::RocheError;
2
3///
4/// vtrans computes two velocity transforms, (1) a straight transform
5/// from rotating to inertial frame and (2) an inertial frame velocity
6/// in the disc.
7///
8/// When translating to inertial, the accretor velocity is added.
9/// If you want the velocity relative to this you must add
10/// mu = q/(1+q) to tvy before using it.
11///
12/// Arguments:
13///
14/// * `q`: mass ratio M2/M1
15/// * `transform_type`: integer representing velocity transform.
16/// 1: rotating frame -> inertial frame
17/// 2: rotating frame to inertial frame velocity of disc
18/// 3: rotating frame (i.e. gived out what you entered)
19/// * `x`: x-coordinate where transform is performed for
20/// * `y`: y-coordinate where transform is performed for
21/// * `vx`: velocity in x-axis in the rotating frame to transform
22/// * `vy`: velocity in y-axis in the rotating frame to transform
23///
24/// Returns:
25///
26/// * `vx`: velocity in x-axis transformed to the chosen frame
27/// * `vy`: velocity in y-axis tranformed to the chosen frame
28///
29pub fn vel_transform(
30 q: f64,
31 transform_type: i32,
32 x: f64,
33 y: f64,
34 vx: f64,
35 vy: f64,
36) -> Result<(f64, f64), RocheError> {
37 let mu: f64 = q / (1.0 + q);
38 let rad: f64 = (x * x + y * y).sqrt();
39 let vkep: f64 = 1.0 / ((1.0 + q) * rad).sqrt();
40
41 match transform_type {
42 1 => Ok((vx - y, vy + x - mu)),
43 2 => Ok((-vkep * y / rad, vkep * x / rad - mu)),
44 3 => Ok((vx, vy)),
45 _ => Err(RocheError::ParameterError(format!(
46 "{} is not a valid transform_type.",
47 transform_type
48 ))),
49 }
50}