Struct RodMechanics

Source
pub struct RodMechanics<F, const D: usize> {
    pub pos: Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>,
    pub vel: Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>,
    pub diffusion_constant: F,
    pub spring_tension: F,
    pub rigidity: F,
    pub spring_length: F,
    pub damping: F,
}
Expand description

A mechanical model for Bacterial Rods

See the Bacterial Rods example for a detailed example.

§Parameters & Variables

SymbolStruct FieldDescription
$\gamma$spring_tensionTension of the springs connecting the vertices.
$D$diffusion_constantDiffusion constant corresponding to brownian motion.
$\lambda$dampingDamping constant.
$l$spring_lengthLength of an individual segment between two vertices.
$\eta$rigidityRigidity with respect to bending the rod.

§Equations

The vertices which are being modeled are stored in the pos struct field and their corresponding velocities in the vel field.

\begin{equation} \vec{v}_i= \text{\texttt{rod\_mechanics.pos.row(i)}} \end{equation}

We define the edge $\vec{c}_i:=\vec{v}_i-\vec{v}_{i-1}$. The first force acts between the vertices $v_i$ of the model and aims to maintain an equal distance between all vertices via

\begin{equation} \vec{F}_{i,\text{springs}} = -\gamma\left(1-\frac{l}{||\vec{c}_i||}\right)\vec{c}_i +\gamma\left(1-\frac{l}{||\vec{c}_{i+1}||}\right)\vec{c}_{i+1}. \end{equation}

We assume the properties of a simple elastic rod. With the angle $\alpha_i$ between adjacent edges $\vec{c}_{i-1},\vec{c}_i$ we can formulate the bending force which is proportional to the curvature $\kappa_i$ at vertex $i$

\begin{equation} \kappa_i = 2\tan\left(\frac{\alpha_i}{2}\right). \end{equation}

The resulting force acts along the angle bisector which can be calculated from the edge vectors. The forces acting on vertices $\vec{v}_i,\vec{v}_{i-1},\vec{v}_{i+1}$ are given by

\begin{align} \vec{F}_{i,\text{curvature}} &= \eta\kappa_i \frac{\vec{c}_i - \vec{c}_{i+1}}{|\vec{c}_i-\vec{c}_{i+1}|}\\ \vec{F}_{i-1,\text{curvature}} &= -\frac{1}{2}\vec{F}_{i,\text{curvature}}\\ \vec{F}_{i+1,\text{curvature}} &= -\frac{1}{2}\vec{F}_{i,\text{curvature}} \end{align}

where $\eta_i$ is the angle curvature at vertex $\vec{v}_i$. The total force $\vec{F}_{i,\text{total}}$ at vertex $i$ consists of multiple contributions.

\begin{equation} \vec{F}_{i,\text{total}} = \vec{F}_{i,\text{springs}} + \vec{F}_{i,\text{curvature}} + \vec{F}_{i,\text{external}} \end{equation}

§References

Fields§

§pos: Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>

The current position

§vel: Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>

The current velocity

§diffusion_constant: F

Controls magnitude of stochastic motion

§spring_tension: F

Spring tension between individual vertices

§rigidity: F

Stiffness at each joint connecting two edges

§spring_length: F

Target spring length

§damping: F

Daming constant

Implementations§

Source§

impl<F, const D: usize> RodMechanics<F, D>

Source

pub fn divide(&mut self, radius: F) -> Result<RodMechanics<F, D>, DivisionError>
where F: Float + RealField + FromPrimitive + Sum,

Divides a RodMechanics struct into two thus separating their positions

use nalgebra::MatrixXx2;
let n_vertices = 7;
let mut pos = MatrixXx2::zeros(n_vertices);
pos
    .row_iter_mut()
    .enumerate()
    .for_each(|(n_row, mut r)| r[0] += n_row as f32 * 0.5);
let mut m1 = RodMechanics {
    pos,
    vel: MatrixXx2::zeros(n_vertices),
    diffusion_constant: 0.0,
    spring_tension: 0.1,
    rigidity: 0.05,
    spring_length: 0.5,
    damping: 0.0,
};
let radius = 0.25;
let m2 = m1.divide(radius)?;

let last_pos_m1 = m1.pos.row(6);
let first_pos_m2 = m2.pos.row(0);
assert!(((last_pos_m1 - first_pos_m2).norm() - 2.0 * radius).abs() < 1e-3);

Trait Implementations§

Source§

impl<F: Clone, const D: usize> Clone for RodMechanics<F, D>

Source§

fn clone(&self) -> RodMechanics<F, D>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug, const D: usize> Debug for RodMechanics<F, D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, F, const D: usize> Deserialize<'de> for RodMechanics<F, D>
where F: Scalar + for<'a> Deserialize<'a>,

Source§

fn deserialize<De>(deserializer: De) -> Result<Self, De::Error>
where De: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<F, const D: usize> Mechanics<Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, F> for RodMechanics<F, D>
where F: RealField + Clone + Float, StandardNormal: Distribution<F>,

Source§

fn calculate_increment( &self, force: Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, ) -> Result<(Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>), CalcError>

Calculate the time-derivative of force and velocity given all the forces that act on the cell. Simple damping effects should be included in this trait if not explicitly given by the SubDomainForce trait.
Source§

fn get_random_contribution( &self, rng: &mut ChaCha8Rng, dt: F, ) -> Result<(Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>), RngError>

Define a new random variable in case that the mechanics type contains a random aspect to its motion. By default this function does nothing.
Source§

impl<F: PartialEq, const D: usize> PartialEq for RodMechanics<F, D>

Source§

fn eq(&self, other: &RodMechanics<F, D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Clone, const D: usize> Position<Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>> for RodMechanics<F, D>

Source§

fn pos(&self) -> Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>

Gets the cells current position.
Source§

fn set_pos( &mut self, position: &Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, )

Gets the cells current velocity.
Source§

impl<F, const D: usize> Serialize for RodMechanics<F, D>
where F: Scalar + Serialize,

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<F: Clone, const D: usize> Velocity<Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>> for RodMechanics<F, D>

Source§

fn velocity(&self) -> Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>

Gets the cells current velocity.
Source§

fn set_velocity( &mut self, velocity: &Matrix<F, Dyn, Const<D>, VecStorage<F, Dyn, Const<D>>>, )

Sets the cells current velocity.
Source§

impl<F, const D: usize> StructuralPartialEq for RodMechanics<F, D>

Auto Trait Implementations§

§

impl<F, const D: usize> Freeze for RodMechanics<F, D>
where F: Freeze,

§

impl<F, const D: usize> RefUnwindSafe for RodMechanics<F, D>
where F: RefUnwindSafe,

§

impl<F, const D: usize> Send for RodMechanics<F, D>
where F: Send,

§

impl<F, const D: usize> Sync for RodMechanics<F, D>
where F: Sync,

§

impl<F, const D: usize> Unpin for RodMechanics<F, D>
where F: Unpin,

§

impl<F, const D: usize> UnwindSafe for RodMechanics<F, D>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

impl<T> Ungil for T
where T: Send,