conspire/constitutive/solid/hyperelastic/
mod.rs

1//! Hyperelastic constitutive models.
2//!
3//! ---
4//!
5#![doc = include_str!("doc.md")]
6
7#[cfg(test)]
8pub mod test;
9
10mod arruda_boyce;
11mod fung;
12mod gent;
13mod mooney_rivlin;
14mod neo_hookean;
15mod saint_venant_kirchhoff;
16mod yeoh;
17
18pub use self::{
19    arruda_boyce::ArrudaBoyce, fung::Fung, gent::Gent, mooney_rivlin::MooneyRivlin,
20    neo_hookean::NeoHookean, saint_venant_kirchhoff::SaintVenantKirchhoff, yeoh::Yeoh,
21};
22use super::{
23    elastic::{AppliedLoad, Elastic},
24    *,
25};
26use crate::math::{
27    Matrix, TensorVec, Vector,
28    optimize::{EqualityConstraint, NewtonRaphson, OptimizeError, SecondOrderOptimization},
29};
30use std::fmt::Debug;
31
32/// Required methods for hyperelastic constitutive models.
33pub trait Hyperelastic
34where
35    Self: Elastic,
36{
37    /// Calculates and returns the Helmholtz free energy density.
38    ///
39    /// ```math
40    /// a = a(\mathbf{F})
41    /// ```
42    fn helmholtz_free_energy_density(
43        &self,
44        deformation_gradient: &DeformationGradient,
45    ) -> Result<Scalar, ConstitutiveError>;
46    /// Solve for the unknown components of the deformation gradient under an applied load.
47    ///
48    /// ```math
49    /// \Pi(\mathbf{F},\boldsymbol{\lambda}) = a(\mathbf{F}) - \boldsymbol{\lambda}:(\mathbf{F} - \mathbf{F}_0) - \mathbf{P}_0:\mathbf{F}
50    /// ```
51    fn minimize(&self, applied_load: AppliedLoad) -> Result<DeformationGradient, OptimizeError> {
52        let solver = NewtonRaphson {
53            ..Default::default()
54        };
55        match applied_load {
56            AppliedLoad::UniaxialStress(deformation_gradient_11) => {
57                let mut matrix = Matrix::zero(4, 9);
58                let mut vector = Vector::zero(4);
59                matrix[0][0] = 1.0;
60                matrix[1][1] = 1.0;
61                matrix[2][2] = 1.0;
62                matrix[3][5] = 1.0;
63                vector[0] = deformation_gradient_11;
64                solver.minimize(
65                    |deformation_gradient: &DeformationGradient| {
66                        Ok(self.helmholtz_free_energy_density(deformation_gradient)?)
67                    },
68                    |deformation_gradient: &DeformationGradient| {
69                        Ok(self.first_piola_kirchhoff_stress(deformation_gradient)?)
70                    },
71                    |deformation_gradient: &DeformationGradient| {
72                        Ok(self.first_piola_kirchhoff_tangent_stiffness(deformation_gradient)?)
73                    },
74                    DeformationGradient::identity(),
75                    EqualityConstraint::Linear(matrix, vector),
76                    None,
77                )
78            }
79            AppliedLoad::BiaxialStress(deformation_gradient_11, deformation_gradient_22) => {
80                let mut matrix = Matrix::zero(5, 9);
81                let mut vector = Vector::zero(5);
82                matrix[0][0] = 1.0;
83                matrix[1][1] = 1.0;
84                matrix[2][2] = 1.0;
85                matrix[3][5] = 1.0;
86                matrix[4][4] = 1.0;
87                vector[0] = deformation_gradient_11;
88                vector[4] = deformation_gradient_22;
89                solver.minimize(
90                    |deformation_gradient: &DeformationGradient| {
91                        Ok(self.helmholtz_free_energy_density(deformation_gradient)?)
92                    },
93                    |deformation_gradient: &DeformationGradient| {
94                        Ok(self.first_piola_kirchhoff_stress(deformation_gradient)?)
95                    },
96                    |deformation_gradient: &DeformationGradient| {
97                        Ok(self.first_piola_kirchhoff_tangent_stiffness(deformation_gradient)?)
98                    },
99                    DeformationGradient::identity(),
100                    EqualityConstraint::Linear(matrix, vector),
101                    None,
102                )
103            }
104        }
105    }
106}