#[cfg(feature = "extern")]
pub mod ex;
#[cfg(feature = "python")]
pub mod py;
mod test;
use std::f64::consts::PI;
use crate::physics::
{
PLANCK_CONSTANT,
BOLTZMANN_CONSTANT
};
pub struct FJC
{
pub hinge_mass: f64,
pub link_length: f64,
pub number_of_links: u8
}
pub fn helmholtz_free_energy(number_of_links: &u8, link_length: &f64, hinge_mass: &f64, force: &f64, temperature: &f64) -> f64
{
let nondimensional_force = force/BOLTZMANN_CONSTANT/temperature*link_length;
(*number_of_links as f64)*BOLTZMANN_CONSTANT*temperature*(nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln() - (8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln())
}
pub fn helmholtz_free_energy_per_link(link_length: &f64, hinge_mass: &f64, force: &f64, temperature: &f64) -> f64
{
let nondimensional_force = force/BOLTZMANN_CONSTANT/temperature*link_length;
BOLTZMANN_CONSTANT*temperature*(nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln() - (8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln())
}
pub fn relative_helmholtz_free_energy(number_of_links: &u8, link_length: &f64, force: &f64, temperature: &f64) -> f64
{
let nondimensional_force = force/BOLTZMANN_CONSTANT/temperature*link_length;
(*number_of_links as f64)*BOLTZMANN_CONSTANT*temperature*(nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln())
}
pub fn relative_helmholtz_free_energy_per_link(link_length: &f64, force: &f64, temperature: &f64) -> f64
{
let nondimensional_force = force/BOLTZMANN_CONSTANT/temperature*link_length;
BOLTZMANN_CONSTANT*temperature*(nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln())
}
pub fn nondimensional_helmholtz_free_energy(number_of_links: &u8, link_length: &f64, hinge_mass: &f64, nondimensional_force: &f64, temperature: &f64) -> f64
{
(*number_of_links as f64)*(nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln() - (8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln())
}
pub fn nondimensional_helmholtz_free_energy_per_link(link_length: &f64, hinge_mass: &f64, nondimensional_force: &f64, temperature: &f64) -> f64
{
nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln() - (8.0*PI.powi(2)*hinge_mass*link_length.powi(2)*BOLTZMANN_CONSTANT*temperature/PLANCK_CONSTANT.powi(2)).ln()
}
pub fn nondimensional_relative_helmholtz_free_energy(number_of_links: &u8, nondimensional_force: &f64) -> f64
{
(*number_of_links as f64)*(nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln())
}
pub fn nondimensional_relative_helmholtz_free_energy_per_link(nondimensional_force: &f64) -> f64
{
nondimensional_force/nondimensional_force.tanh() - 1.0 - (nondimensional_force.sinh()/nondimensional_force).ln()
}
impl FJC
{
pub fn init(number_of_links: u8, link_length: f64, hinge_mass: f64) -> Self
{
FJC
{
hinge_mass,
link_length,
number_of_links
}
}
pub fn helmholtz_free_energy(&self, force: &f64, temperature: &f64) -> f64
{
helmholtz_free_energy(&self.number_of_links, &self.link_length, &self.hinge_mass, force, temperature)
}
pub fn helmholtz_free_energy_per_link(&self, force: &f64, temperature: &f64) -> f64
{
helmholtz_free_energy_per_link(&self.link_length, &self.hinge_mass, force, temperature)
}
pub fn relative_helmholtz_free_energy(&self, force: &f64, temperature: &f64) -> f64
{
relative_helmholtz_free_energy(&self.number_of_links, &self.link_length, force, temperature)
}
pub fn relative_helmholtz_free_energy_per_link(&self, force: &f64, temperature: &f64) -> f64
{
relative_helmholtz_free_energy_per_link(&self.link_length, force, temperature)
}
pub fn nondimensional_helmholtz_free_energy(&self, nondimensional_force: &f64, temperature: &f64) -> f64
{
nondimensional_helmholtz_free_energy(&self.number_of_links, &self.link_length, &self.hinge_mass, nondimensional_force, temperature)
}
pub fn nondimensional_helmholtz_free_energy_per_link(&self, nondimensional_force: &f64, temperature: &f64) -> f64
{
nondimensional_helmholtz_free_energy_per_link(&self.link_length, &self.hinge_mass, nondimensional_force, temperature)
}
pub fn nondimensional_relative_helmholtz_free_energy(&self, nondimensional_force: &f64) -> f64
{
nondimensional_relative_helmholtz_free_energy(&self.number_of_links, nondimensional_force)
}
pub fn nondimensional_relative_helmholtz_free_energy_per_link(&self, nondimensional_force: &f64) -> f64
{
nondimensional_relative_helmholtz_free_energy_per_link(nondimensional_force)
}
}