Skip to main content

conspire/mechanics/
mod.rs

1//! Mechanics aliases.
2#[cfg(test)]
3pub mod test;
4
5use crate::units::{
6    Fluidity, ForcePerLength, ForcePerVelocity, Length, PowerPerArea, PowerPerLengthTemperature,
7    Rate, ReciprocalLength, Stress, TemperaturePerLength, Velocity, Viscosity,
8};
9
10use crate::math::{Current, Intermediate, Reference};
11
12use crate::math::{
13    Rank2, Style, StyledError, Tensor, TensorRank1, TensorRank1List, TensorRank1List2D,
14    TensorRank1RefVec, TensorRank1Vec, TensorRank1Vec2D, TensorRank2, TensorRank2List,
15    TensorRank2List2D, TensorRank2Vec, TensorRank2Vec2D, TensorRank4, TensorRank4List,
16    TensorRank4Vec, styled_error,
17};
18
19pub use crate::math::Scalar;
20
21/// Possible errors for deformation gradients.
22pub enum DeformationError {
23    InvalidJacobian(Scalar),
24}
25
26impl StyledError for DeformationError {
27    fn message(&self, style: &Style) -> String {
28        let (h, c) = (style.headline, style.frame);
29        match self {
30            Self::InvalidJacobian(jacobian) => {
31                format!("{h}Invalid Jacobian: {jacobian:.6e}.{c}")
32            }
33        }
34    }
35}
36
37styled_error!(DeformationError);
38
39/// Methods for deformation gradients.
40pub trait Deformation<I, J> {
41    /// Calculates and returns the Jacobian.
42    ///
43    /// ```math
44    /// J = \mathrm{det}(\mathbf{F})
45    /// ```
46    fn jacobian(&self) -> Result<Scalar, DeformationError>;
47    /// Calculates and returns the left Cauchy-Green deformation.
48    ///
49    /// ```math
50    /// \mathbf{B} = \mathbf{F}\cdot\mathbf{F}^T
51    /// ```
52    fn left_cauchy_green(&self) -> TensorRank2<3, I, I>;
53    /// Calculates and returns the right Cauchy-Green deformation.
54    ///
55    /// ```math
56    /// \mathbf{C} = \mathbf{F}^T\cdot\mathbf{F}
57    /// ```
58    fn right_cauchy_green(&self) -> TensorRank2<3, J, J>;
59}
60
61impl<I, J> Deformation<I, J> for DeformationGradientGeneral<I, J> {
62    fn jacobian(&self) -> Result<Scalar, DeformationError> {
63        let jacobian = self.determinant();
64        if jacobian > 0.0 {
65            Ok(jacobian)
66        } else {
67            Err(DeformationError::InvalidJacobian(jacobian))
68        }
69    }
70    fn left_cauchy_green(&self) -> TensorRank2<3, I, I> {
71        self.iter()
72            .map(|deformation_gradient_i| {
73                self.iter()
74                    .map(|deformation_gradient_j| deformation_gradient_i * deformation_gradient_j)
75                    .collect()
76            })
77            .collect()
78    }
79    fn right_cauchy_green(&self) -> TensorRank2<3, J, J> {
80        let deformation_gradient_transpose = self.transpose();
81        deformation_gradient_transpose
82            .iter()
83            .map(|deformation_gradient_transpose_i| {
84                deformation_gradient_transpose
85                    .iter()
86                    .map(|deformation_gradient_transpose_j| {
87                        deformation_gradient_transpose_i * deformation_gradient_transpose_j
88                    })
89                    .collect()
90            })
91            .collect()
92    }
93}
94
95/// A basis.
96pub type Basis = TensorRank1List<3, Current, 3, Length>;
97
98/// A list of bases.
99pub type Bases<const N: usize> = TensorRank1List2D<3, Current, 3, N, Length>;
100
101/// The Cauchy stress $`\boldsymbol{\sigma}`$.
102pub type CauchyStress = TensorRank2<3, Current, Current, Stress>;
103
104/// A list of Cauchy stresses.
105pub type CauchyStresses<const W: usize> = TensorRank2List<3, Current, Current, W, Stress>;
106
107/// The tangent stiffness associated with the Cauchy stress $`\boldsymbol{\mathcal{T}}`$.
108pub type CauchyTangentStiffness = TensorRank4<3, Current, Current, Current, Reference, Stress>;
109
110/// The tangent stiffness associated with the Cauchy stress $`\boldsymbol{\mathcal{T}}_1`$.
111pub type CauchyTangentStiffness1 = TensorRank4<3, Current, Current, Current, Intermediate, Stress>;
112
113/// The tangent stiffness associated with the elastic Cauchy stress $`\boldsymbol{\mathcal{T}}_\mathrm{e}`$.
114pub type CauchyTangentStiffnessElastic =
115    TensorRank4<3, Current, Current, Current, Intermediate, Stress>;
116
117/// The tangent stiffness of the Cauchy stress with respect to the plastic deformation gradient.
118pub type CauchyTangentStiffnessPlastic =
119    TensorRank4<3, Current, Current, Intermediate, Reference, Stress>;
120
121/// The tangent stiffness of the elastic Mandel stress with respect to the deformation gradient.
122pub type MandelStressTangentElastic =
123    TensorRank4<3, Intermediate, Intermediate, Current, Reference, Stress>;
124
125/// The tangent stiffness of the elastic Mandel stress with respect to the plastic deformation gradient.
126pub type MandelStressTangentElasticPlastic =
127    TensorRank4<3, Intermediate, Intermediate, Intermediate, Reference, Stress>;
128
129/// The tangent stiffness of the first Piola-Kirchhoff stress with respect to the plastic deformation gradient.
130pub type FirstPiolaKirchhoffTangentStiffnessPlastic =
131    TensorRank4<3, Current, Reference, Intermediate, Reference, Stress>;
132
133/// The rate tangent stiffness associated with the Cauchy stress $`\boldsymbol{\mathcal{V}}`$.
134pub type CauchyRateTangentStiffness =
135    TensorRank4<3, Current, Current, Current, Reference, Viscosity>;
136
137/// A coordinate.
138pub type Coordinate<I> = TensorRank1<3, I, Length>;
139
140/// A list of coordinates.
141pub type CoordinateList<I, const N: usize> = TensorRank1List<3, I, N, Length>;
142
143/// A vector of coordinates.
144pub type Coordinates<I> = TensorRank1Vec<3, I, Length>;
145
146/// A vector of references to coordinates.
147pub type CoordinatesRef<'a, I> = TensorRank1RefVec<'a, 3, I, Length>;
148
149/// A coordinate in the current configuration.
150pub type CurrentCoordinate = TensorRank1<3, Current, Length>;
151
152/// A list of coordinates in the current configuration.
153pub type CurrentCoordinates<const W: usize> = TensorRank1List<3, Current, W, Length>;
154
155/// A vector of references to current coordinates.
156pub type CurrentCoordinatesRef<'a> = TensorRank1RefVec<'a, 3, Current, Length>;
157
158/// A velocity in the current configuration.
159pub type CurrentVelocity = TensorRank1<3, Current, Velocity>;
160
161/// A list of velocities in the current configuration.
162pub type CurrentVelocities<const W: usize> = TensorRank1List<3, Current, W, Velocity>;
163
164/// The deformation gradient $`\mathbf{F}`$.
165pub type DeformationGradient = TensorRank2<3, Current, Reference>;
166
167/// The second deformation gradient $`\mathbf{F}_2`$.
168pub type DeformationGradient2 = TensorRank2<3, Intermediate, Reference>;
169
170/// The elastic deformation gradient $`\mathbf{F}_\mathrm{e}`$.
171pub type DeformationGradientElastic = TensorRank2<3, Current, Intermediate>;
172
173/// A general deformation gradient.
174pub type DeformationGradientGeneral<I, J> = TensorRank2<3, I, J>;
175
176/// The plastic deformation gradient $`\mathbf{F}_\mathrm{p}`$.
177pub type DeformationGradientPlastic = TensorRank2<3, Intermediate, Reference>;
178
179/// The deformation gradient rate $`\dot{\mathbf{F}}`$.
180pub type DeformationGradientRate = TensorRank2<3, Current, Reference, Rate>;
181
182/// The plastic deformation gradient rate $`\dot{\mathbf{F}}_\mathrm{p}`$.
183pub type DeformationGradientRatePlastic = TensorRank2<3, Intermediate, Reference, Rate>;
184
185/// A list of deformation gradients.
186pub type DeformationGradientList<const W: usize> = TensorRank2List<3, Current, Reference, W>;
187
188/// A list of deformation gradient rates.
189pub type DeformationGradientRateList<const W: usize> =
190    TensorRank2List<3, Current, Reference, W, Rate>;
191
192/// A vector of deformation gradients.
193pub type DeformationGradients = TensorRank2Vec<3, Current, Reference>;
194
195/// A vector of plastic deformation gradients.
196pub type DeformationGradientsPlastic = TensorRank2Vec<3, Intermediate, Reference>;
197
198/// A vector of deformation gradient rates.
199pub type DeformationGradientRates = TensorRank2Vec<3, Current, Reference, Rate>;
200
201/// A vector of plastic deformation gradient rates.
202pub type DeformationGradientRatesPlastic = TensorRank2Vec<3, Intermediate, Reference, Rate>;
203
204/// A displacement.
205pub type Displacement = TensorRank1<3, Current, Length>;
206
207/// The first Piola-Kirchhoff stress $`\mathbf{P}`$.
208pub type FirstPiolaKirchhoffStress = TensorRank2<3, Current, Reference, Stress>;
209
210/// The first Piola-Kirchhoff stress $`\mathbf{P}_1`$.
211pub type FirstPiolaKirchhoffStress1 = TensorRank2<3, Current, Intermediate, Stress>;
212
213/// The first Piola-Kirchhoff stress $`\mathbf{P}_2`$.
214pub type FirstPiolaKirchhoffStress2 = TensorRank2<3, Intermediate, Reference, Stress>;
215
216/// The elastic first Piola-Kirchhoff stress $`\mathbf{P}_\mathrm{e}`$.
217pub type FirstPiolaKirchhoffStressElastic = FirstPiolaKirchhoffStress1;
218
219/// A list of first Piola-Kirchhoff stresses.
220pub type FirstPiolaKirchhoffStressList<const N: usize> =
221    TensorRank2List<3, Current, Reference, N, Stress>;
222
223/// A vector of first Piola-Kirchhoff stresses.
224pub type FirstPiolaKirchhoffStresses = TensorRank2Vec<3, Current, Reference, Stress>;
225
226/// The tangent stiffness associated with the first Piola-Kirchhoff stress $`\boldsymbol{\mathcal{C}}`$.
227pub type FirstPiolaKirchhoffTangentStiffness =
228    TensorRank4<3, Current, Reference, Current, Reference, Stress>;
229
230/// The first tangent stiffness associated with the first Piola-Kirchhoff stress $`\boldsymbol{\mathcal{C}}_1`$.
231pub type FirstPiolaKirchhoffTangentStiffness1 =
232    TensorRank4<3, Current, Intermediate, Current, Intermediate, Stress>;
233
234/// The second tangent stiffness associated with the first Piola-Kirchhoff stress $`\boldsymbol{\mathcal{C}}_2`$.
235pub type FirstPiolaKirchhoffTangentStiffness2 =
236    TensorRank4<3, Intermediate, Reference, Intermediate, Reference, Stress>;
237
238/// The elastic tangent stiffness associated with the first Piola-Kirchhoff stress $`\boldsymbol{\mathcal{C}}_\mathrm{e}`$.
239pub type FirstPiolaKirchhoffTangentStiffnessElastic = FirstPiolaKirchhoffTangentStiffness1;
240
241/// A list of first Piola-Kirchhoff tangent stiffnesses.
242pub type FirstPiolaKirchhoffTangentStiffnessList<const N: usize> =
243    TensorRank4List<3, Current, Reference, Current, Reference, N, Stress>;
244
245/// A vector of first Piola-Kirchhoff tangent stiffnesses.
246pub type FirstPiolaKirchhoffTangentStiffnesses =
247    TensorRank4Vec<3, Current, Reference, Current, Reference, Stress>;
248
249/// The rate tangent stiffness associated with the first Piola-Kirchhoff stress $`\boldsymbol{\mathcal{U}}`$.
250pub type FirstPiolaKirchhoffRateTangentStiffness =
251    TensorRank4<3, Current, Reference, Current, Reference, Viscosity>;
252
253/// A list of first Piola-Kirchhoff rate tangent stiffnesses.
254pub type FirstPiolaKirchhoffRateTangentStiffnessList<const W: usize> =
255    TensorRank4List<3, Current, Reference, Current, Reference, W, Viscosity>;
256
257/// A vector of first Piola-Kirchhoff rate tangent stiffnesses.
258pub type FirstPiolaKirchhoffRateTangentStiffnesses =
259    TensorRank4Vec<3, Current, Reference, Current, Reference, Viscosity>;
260
261/// A force.
262pub type Force = TensorRank1<3, Current, crate::units::Force>;
263
264/// A list of forces.
265pub type ForceList<const N: usize> = TensorRank1List<3, Current, N, crate::units::Force>;
266
267/// A vector of forces.
268pub type Forces = TensorRank1Vec<3, Current, crate::units::Force>;
269
270/// The frame spin $`\mathbf{\Omega}=\dot{\mathbf{Q}}\cdot\mathbf{Q}^T`$.
271pub type FrameSpin = TensorRank2<3, Current, Current, Rate>;
272
273/// The heat flux.
274pub type HeatFlux = TensorRank1<3, Reference, PowerPerArea>;
275
276/// A list of heat fluxes.
277pub type HeatFluxes<const N: usize> = TensorRank1List<3, Reference, N, PowerPerArea>;
278
279/// The heat flux tangent.
280pub type HeatFluxTangent = TensorRank2<3, Reference, Reference, PowerPerLengthTemperature>;
281
282/// A list of heat flux tangents.
283pub type HeatFluxTangents<const N: usize> =
284    TensorRank2List<3, Reference, Reference, N, PowerPerLengthTemperature>;
285
286/// The left Cauchy-Green deformation $`\mathbf{B}`$.
287pub type LeftCauchyGreenDeformation = TensorRank2<3, Current, Current>;
288
289/// The Mandel stress $`\mathbf{M}`$.
290pub type MandelStress = TensorRank2<3, Reference, Reference, Stress>;
291
292/// The elastic stress $`\mathbf{M}_e`$.
293pub type MandelStressElastic = TensorRank2<3, Intermediate, Intermediate, Stress>;
294
295/// A normal.
296pub type Normal = TensorRank1<3, Current>;
297
298/// A list of normals.
299pub type Normals<const N: usize> = TensorRank1List<3, Current, N>;
300
301/// A list of normal gradients.
302pub type NormalGradients<const O: usize, const P: usize> =
303    TensorRank2List2D<3, Current, Current, O, P, ReciprocalLength>;
304
305/// A normal rate.
306pub type NormalRate = TensorRank1<3, Current, Rate>;
307
308/// A list of normal rates.
309pub type NormalRates<const N: usize> = TensorRank1List<3, Current, N, Rate>;
310
311/// A coordinate in the reference configuration.
312pub type ReferenceCoordinate = TensorRank1<3, Reference, Length>;
313
314/// A list of coordinates in the reference configuration.
315pub type ReferenceCoordinates<const W: usize> = TensorRank1List<3, Reference, W, Length>;
316
317/// A reference normal.
318pub type ReferenceNormal = TensorRank1<3, Reference>;
319
320/// A list of reference normals.
321pub type ReferenceNormals<const N: usize> = TensorRank1List<3, Reference, N>;
322
323/// The right Cauchy-Green deformation $`\mathbf{C}`$.
324pub type RightCauchyGreenDeformation = TensorRank2<3, Reference, Reference>;
325
326/// The rotation of the current configuration $`\mathbf{Q}`$.
327pub type RotationCurrentConfiguration = TensorRank2<3, Current, Current>;
328
329/// A list of rotations of the current configuration.
330pub type RotationCurrentConfigurationList<const N: usize> = TensorRank2List<3, Current, Current, N>;
331
332/// The rate of rotation of the current configuration $`\dot{\mathbf{Q}}`$.
333pub type RotationRateCurrentConfiguration = TensorRank2<3, Current, Current, Rate>;
334
335/// The rotation of the reference configuration $`\mathbf{Q}_0`$.
336pub type RotationReferenceConfiguration = TensorRank2<3, Reference, Reference>;
337
338/// A separation.
339pub type Separation = Displacement;
340
341/// The second Piola-Kirchhoff stress $`\mathbf{S}`$.
342pub type SecondPiolaKirchhoffStress = TensorRank2<3, Reference, Reference, Stress>;
343
344/// The elastic second Piola-Kirchhoff stress $`\mathbf{S}`$.
345pub type SecondPiolaKirchhoffStressElastic = TensorRank2<3, Intermediate, Intermediate, Stress>;
346
347/// The tangent stiffness associated with the second Piola-Kirchhoff stress $`\boldsymbol{\mathcal{G}}`$.
348pub type SecondPiolaKirchhoffTangentStiffness =
349    TensorRank4<3, Reference, Reference, Current, Reference, Stress>;
350
351/// The elastic tangent stiffness associated with the second Piola-Kirchhoff stress $`\boldsymbol{\mathcal{G}}_\mathrm{e}`$.
352pub type SecondPiolaKirchhoffTangentStiffnessElastic =
353    TensorRank4<3, Intermediate, Intermediate, Current, Intermediate, Stress>;
354
355/// The rate tangent stiffness associated with the second Piola-Kirchhoff stress $`\boldsymbol{\mathcal{W}}`$.
356pub type SecondPiolaKirchhoffRateTangentStiffness =
357    TensorRank4<3, Reference, Reference, Current, Reference, Viscosity>;
358
359/// A stiffness resulting from a force.
360pub type Stiffness = TensorRank2<3, Current, Current, ForcePerLength>;
361
362/// A list of stiffnesses.
363pub type StiffnessList<const N: usize> = TensorRank2List<3, Current, Current, N, ForcePerLength>;
364
365/// A 2D list of stiffnesses.
366pub type StiffnessList2D<const N: usize> =
367    TensorRank2List2D<3, Current, Current, N, N, ForcePerLength>;
368
369/// A damping resulting from a force per unit rate.
370pub type Damping = TensorRank2<3, Current, Current, ForcePerVelocity>;
371
372/// A list of two-dimensional lists of dampings.
373pub type DampingList2D<const N: usize> =
374    TensorRank2List2D<3, Current, Current, N, N, ForcePerVelocity>;
375
376/// A vector of two-dimensional vectors of dampings.
377pub type Dampings = TensorRank2Vec2D<3, Current, Current, ForcePerVelocity>;
378
379/// A vector of stiffnesses.
380pub type Stiffnesses = TensorRank2Vec2D<3, Current, Current, ForcePerLength>;
381
382/// The stretching rate $`\mathbf{D}`$.
383pub type StretchingRate = TensorRank2<3, Current, Current, Rate>;
384
385/// The plastic stretching rate $`\mathbf{D}^\mathrm{p}`$.
386pub type StretchingRatePlastic = TensorRank2<3, Intermediate, Intermediate, Rate>;
387
388/// The tangent of the plastic stretching rate with respect to the deviatoric Mandel stress.
389pub type StretchingRatePlasticTangent =
390    TensorRank4<3, Intermediate, Intermediate, Intermediate, Intermediate, Fluidity>;
391
392/// The tangent of the plastic stretching rate with respect to the yield stress.
393pub type StretchingRatePlasticTangentYield = TensorRank2<3, Intermediate, Intermediate, Fluidity>;
394
395/// A surface basis.
396pub type SurfaceBasis<I> = TensorRank1List<3, I, 2, Length>;
397
398/// A list of surface bases.
399pub type SurfaceBases<I, const N: usize> = TensorRank1List2D<3, I, 2, N, Length>;
400
401/// A surface dual basis.
402pub type SurfaceDualBasis<I> = TensorRank1List<3, I, 2, ReciprocalLength>;
403
404/// A list of surface dual bases.
405pub type SurfaceDualBases<I, const N: usize> = TensorRank1List2D<3, I, 2, N, ReciprocalLength>;
406
407/// The temperature gradient.
408pub type TemperatureGradient = TensorRank1<3, Reference, TemperaturePerLength>;
409
410/// A list of temperature gradients.
411pub type TemperatureGradients<const N: usize> =
412    TensorRank1List<3, Reference, N, TemperaturePerLength>;
413
414/// A vector of times.
415pub type Times = crate::math::integrate::Times;
416
417/// A traction.
418pub type Traction = TensorRank1<3, Current, Stress>;
419
420/// A list of tractions.
421pub type TractionList<const N: usize> = TensorRank1List<3, Current, N, Stress>;
422
423/// A vector.
424pub type Vector<I> = TensorRank1<3, I>;
425
426/// A list of vectors.
427pub type VectorList<I, const W: usize> = TensorRank1List<3, I, W>;
428
429/// A 2D list of vectors.
430pub type VectorList2D<I, const W: usize, const X: usize> = TensorRank1List2D<3, I, W, X>;
431
432/// A vector of vectors.
433pub type Vectors<I> = TensorRank1Vec<3, I>;
434
435/// A 2D vector of vectors.
436pub type Vectors2D<I> = TensorRank1Vec2D<3, I>;