1#[cfg(test)]
4pub mod test;
5
6use crate::math::{
7 Rank2, Style, StyledError, Tensor, TensorRank1, TensorRank1List, TensorRank1List2D,
8 TensorRank1RefVec, TensorRank1Vec, TensorRank1Vec2D, TensorRank2, TensorRank2List,
9 TensorRank2List2D, TensorRank2Vec, TensorRank2Vec2D, TensorRank4, TensorRank4List,
10 TensorRank4Vec, styled_error,
11};
12
13pub use crate::math::Scalar;
14
15pub enum DeformationError {
17 InvalidJacobian(Scalar),
18}
19
20impl StyledError for DeformationError {
21 fn message(&self, style: &Style) -> String {
22 let (h, c) = (style.headline, style.frame);
23 match self {
24 Self::InvalidJacobian(jacobian) => {
25 format!("{h}Invalid Jacobian: {jacobian:.6e}.{c}")
26 }
27 }
28 }
29}
30
31styled_error!(DeformationError);
32
33pub trait Deformation<const I: usize, const J: usize> {
35 fn jacobian(&self) -> Result<Scalar, DeformationError>;
41 fn left_cauchy_green(&self) -> TensorRank2<3, I, I>;
47 fn right_cauchy_green(&self) -> TensorRank2<3, J, J>;
53}
54
55impl<const I: usize, const J: usize> Deformation<I, J> for DeformationGradientGeneral<I, J> {
56 fn jacobian(&self) -> Result<Scalar, DeformationError> {
57 let jacobian = self.determinant();
58 if jacobian > 0.0 {
59 Ok(jacobian)
60 } else {
61 Err(DeformationError::InvalidJacobian(jacobian))
62 }
63 }
64 fn left_cauchy_green(&self) -> TensorRank2<3, I, I> {
65 self.iter()
66 .map(|deformation_gradient_i| {
67 self.iter()
68 .map(|deformation_gradient_j| deformation_gradient_i * deformation_gradient_j)
69 .collect()
70 })
71 .collect()
72 }
73 fn right_cauchy_green(&self) -> TensorRank2<3, J, J> {
74 let deformation_gradient_transpose = self.transpose();
75 deformation_gradient_transpose
76 .iter()
77 .map(|deformation_gradient_transpose_i| {
78 deformation_gradient_transpose
79 .iter()
80 .map(|deformation_gradient_transpose_j| {
81 deformation_gradient_transpose_i * deformation_gradient_transpose_j
82 })
83 .collect()
84 })
85 .collect()
86 }
87}
88
89pub type Basis = TensorRank1List<3, 1, 3>;
91
92pub type Bases<const N: usize> = TensorRank1List2D<3, 1, 3, N>;
94
95pub type CauchyStress = TensorRank2<3, 1, 1>;
97
98pub type CauchyStresses<const W: usize> = TensorRank2List<3, 1, 1, W>;
100
101pub type CauchyTangentStiffness = TensorRank4<3, 1, 1, 1, 0>;
103
104pub type CauchyTangentStiffness1 = TensorRank4<3, 1, 1, 1, 2>;
106
107pub type CauchyTangentStiffnessElastic = TensorRank4<3, 1, 1, 1, 2>;
109
110pub type CauchyRateTangentStiffness = TensorRank4<3, 1, 1, 1, 0>;
112
113pub type Coordinate<const I: usize> = TensorRank1<3, I>;
115
116pub type CoordinateList<const I: usize, const N: usize> = TensorRank1List<3, I, N>;
118
119pub type Coordinates<const I: usize> = TensorRank1Vec<3, I>;
121
122pub type CoordinatesRef<'a, const I: usize> = TensorRank1RefVec<'a, 3, I>;
124
125pub type CurrentCoordinate = TensorRank1<3, 1>;
127
128pub type CurrentCoordinates<const W: usize> = TensorRank1List<3, 1, W>;
130
131pub type CurrentCoordinatesRef<'a> = TensorRank1RefVec<'a, 3, 1>;
133
134pub type CurrentVelocity = TensorRank1<3, 1>;
136
137pub type DeformationGradient = TensorRank2<3, 1, 0>;
139
140pub type DeformationGradient2 = TensorRank2<3, 2, 0>;
142
143pub type DeformationGradientElastic = TensorRank2<3, 1, 2>;
145
146pub type DeformationGradientGeneral<const I: usize, const J: usize> = TensorRank2<3, I, J>;
148
149pub type DeformationGradientPlastic = TensorRank2<3, 2, 0>;
151
152pub type DeformationGradientRate = TensorRank2<3, 1, 0>;
154
155pub type DeformationGradientRatePlastic = TensorRank2<3, 2, 0>;
157
158pub type DeformationGradientList<const W: usize> = TensorRank2List<3, 1, 0, W>;
160
161pub type DeformationGradientRateList<const W: usize> = TensorRank2List<3, 1, 0, W>;
163
164pub type DeformationGradients = TensorRank2Vec<3, 1, 0>;
166
167pub type DeformationGradientsPlastic = TensorRank2Vec<3, 2, 0>;
169
170pub type DeformationGradientRates = TensorRank2Vec<3, 1, 0>;
172
173pub type DeformationGradientRatesPlastic = TensorRank2Vec<3, 2, 0>;
175
176pub type Displacement = TensorRank1<3, 1>;
178
179pub type FirstPiolaKirchhoffStress = TensorRank2<3, 1, 0>;
181
182pub type FirstPiolaKirchhoffStress1 = TensorRank2<3, 1, 2>;
184
185pub type FirstPiolaKirchhoffStress2 = TensorRank2<3, 2, 0>;
187
188pub type FirstPiolaKirchhoffStressElastic = FirstPiolaKirchhoffStress1;
190
191pub type FirstPiolaKirchhoffStressList<const N: usize> = TensorRank2List<3, 1, 0, N>;
193
194pub type FirstPiolaKirchhoffStresses = TensorRank2Vec<3, 1, 0>;
196
197pub type FirstPiolaKirchhoffTangentStiffness = TensorRank4<3, 1, 0, 1, 0>;
199
200pub type FirstPiolaKirchhoffTangentStiffness1 = TensorRank4<3, 1, 2, 1, 2>;
202
203pub type FirstPiolaKirchhoffTangentStiffness2 = TensorRank4<3, 2, 0, 2, 0>;
205
206pub type FirstPiolaKirchhoffTangentStiffnessElastic = FirstPiolaKirchhoffTangentStiffness1;
208
209pub type FirstPiolaKirchhoffTangentStiffnessList<const N: usize> =
211 TensorRank4List<3, 1, 0, 1, 0, N>;
212
213pub type FirstPiolaKirchhoffTangentStiffnesses = TensorRank4Vec<3, 1, 0, 1, 0>;
215
216pub type FirstPiolaKirchhoffRateTangentStiffness = TensorRank4<3, 1, 0, 1, 0>;
218
219pub type FirstPiolaKirchhoffRateTangentStiffnesses<const W: usize> =
221 TensorRank4List<3, 1, 0, 1, 0, W>;
222
223pub type Force = TensorRank1<3, 1>;
225
226pub type ForceList<const N: usize> = TensorRank1List<3, 1, N>;
228
229pub type Forces = TensorRank1Vec<3, 1>;
231
232pub type FrameSpin = TensorRank2<3, 1, 1>;
234
235pub type HeatFlux = TensorRank1<3, 0>;
237
238pub type HeatFluxes<const N: usize> = TensorRank1List<3, 0, N>;
240
241pub type HeatFluxTangent = TensorRank2<3, 0, 0>;
243
244pub type HeatFluxTangents<const N: usize> = TensorRank2List<3, 0, 0, N>;
246
247pub type LeftCauchyGreenDeformation = TensorRank2<3, 1, 1>;
249
250pub type MandelStress = TensorRank2<3, 0, 0>;
252
253pub type MandelStressElastic = TensorRank2<3, 2, 2>;
255
256pub type Normal = TensorRank1<3, 1>;
258
259pub type Normals<const N: usize> = TensorRank1List<3, 1, N>;
261
262pub type NormalGradients<const O: usize, const P: usize> = TensorRank2List2D<3, 1, 1, O, P>;
264
265pub type NormalRate = TensorRank1<3, 1>;
267
268pub type NormalRates<const N: usize> = TensorRank1List<3, 1, N>;
270
271pub type ReferenceCoordinate = TensorRank1<3, 0>;
273
274pub type ReferenceCoordinates<const W: usize> = TensorRank1List<3, 0, W>;
276
277pub type ReferenceNormal = TensorRank1<3, 0>;
279
280pub type ReferenceNormals<const N: usize> = TensorRank1List<3, 0, N>;
282
283pub type RightCauchyGreenDeformation = TensorRank2<3, 0, 0>;
285
286pub type RotationCurrentConfiguration = TensorRank2<3, 1, 1>;
288
289pub type RotationCurrentConfigurationList<const N: usize> = TensorRank2List<3, 1, 1, N>;
291
292pub type RotationRateCurrentConfiguration = TensorRank2<3, 1, 1>;
294
295pub type RotationReferenceConfiguration = TensorRank2<3, 0, 0>;
297
298pub type Separation = Displacement;
300
301pub type SecondPiolaKirchhoffStress = TensorRank2<3, 0, 0>;
303
304pub type SecondPiolaKirchhoffStressElastic = TensorRank2<3, 2, 2>;
306
307pub type SecondPiolaKirchhoffTangentStiffness = TensorRank4<3, 0, 0, 1, 0>;
309
310pub type SecondPiolaKirchhoffTangentStiffnessElastic = TensorRank4<3, 2, 2, 1, 2>;
312
313pub type SecondPiolaKirchhoffRateTangentStiffness = TensorRank4<3, 0, 0, 1, 0>;
315
316pub type Stiffness = TensorRank2<3, 1, 1>;
318
319pub type StiffnessList<const N: usize> = TensorRank2List<3, 1, 1, N>;
321
322pub type StiffnessList2D<const N: usize> = TensorRank2List2D<3, 1, 1, N, N>;
324
325pub type Stiffnesses = TensorRank2Vec2D<3, 1, 1>;
327
328pub type StretchingRate = TensorRank2<3, 1, 1>;
330
331pub type StretchingRatePlastic = TensorRank2<3, 2, 2>;
333
334pub type SurfaceBasis<const I: usize> = TensorRank1List<3, I, 2>;
336
337pub type SurfaceBases<const I: usize, const N: usize> = TensorRank1List2D<3, I, 2, N>;
339
340pub type TemperatureGradient = TensorRank1<3, 0>;
342
343pub type TemperatureGradients<const N: usize> = TensorRank1List<3, 0, N>;
345
346pub type Times = crate::math::Vector;
348
349pub type Traction = TensorRank1<3, 1>;
351
352pub type TractionList<const N: usize> = TensorRank1List<3, 1, N>;
354
355pub type Vector<const I: usize> = TensorRank1<3, I>;
357
358pub type VectorList<const I: usize, const W: usize> = TensorRank1List<3, I, W>;
360
361pub type VectorList2D<const I: usize, const W: usize, const X: usize> =
363 TensorRank1List2D<3, I, W, X>;
364
365pub type Vectors<const I: usize> = TensorRank1Vec<3, I>;
367
368pub type Vectors2D<const I: usize> = TensorRank1Vec2D<3, I>;