#[cfg(feature = "python")]
pub mod py;
mod test;
pub mod isometric;
pub mod isotensional;
pub mod modified_canonical;
use std::f64::consts::PI;
pub struct FJC
{
pub hinge_mass: f64,
pub link_length: f64,
pub number_of_links: u8,
pub isometric: isometric::FJC,
pub isotensional: isotensional::FJC,
pub modified_canonical: modified_canonical::FJC
}
impl FJC
{
pub fn init(number_of_links: u8, link_length: f64, hinge_mass: f64) -> Self
{
FJC
{
hinge_mass,
link_length,
number_of_links,
isometric: isometric::FJC::init(number_of_links, link_length, hinge_mass),
isotensional: isotensional::FJC::init(number_of_links, link_length, hinge_mass),
modified_canonical: modified_canonical::FJC::init(number_of_links, link_length, hinge_mass)
}
}
}
fn treloar_sums(number_of_links: &u8, nondimensional_end_to_end_length_per_link: &f64, orders: &[i32]) -> Vec<f64>
{
let number_of_links_f64 = *number_of_links as f64;
let n = *number_of_links as u128;
let p: i32 = (number_of_links - 2).into();
let m = -*nondimensional_end_to_end_length_per_link*0.5 + 0.5;
let k = (number_of_links_f64*m).ceil() as u128;
orders.iter().map(|order| (0..=k-1).collect::<Vec::<u128>>().iter().map(|s| (-1.0_f64).powf(*s as f64)*(((1..=n).product::<u128>()/(1..=*s).product::<u128>()/(1..=n-s).product::<u128>()) as f64)*(m - (*s as f64)/number_of_links_f64).powi(p - order)).sum()).collect()
}
fn treloar_sum_0_with_prefactor(number_of_links: &u8, nondimensional_end_to_end_length_per_link: &f64) -> f64
{
let number_of_links_f64 = *number_of_links as f64;
let n = *number_of_links as u128;
let p: i32 = (number_of_links - 2).into();
let m = -*nondimensional_end_to_end_length_per_link*0.5 + 0.5;
let k = (number_of_links_f64*m).ceil() as u128;
0.125/PI/nondimensional_end_to_end_length_per_link*(n.pow(n as u32) as f64)/((1..=n-2).product::<u128>() as f64)*(0..=k-1).collect::<Vec::<u128>>().iter().map(|s| (-1.0_f64).powf(*s as f64)*(((1..=n).product::<u128>()/(1..=*s).product::<u128>()/(1..=n-s).product::<u128>()) as f64)*(m - (*s as f64)/number_of_links_f64).powi(p)).sum::<f64>()
}