pub struct Tri6 {
pub el_id: usize,
pub coords: [[f64; 6]; 2],
pub node_ids: [usize; 6],
pub elastic_modulus: f64,
pub shear_modulus: f64,
pub density: f64,
}Expand description
Six-noded quadratic triangular finite element.
Node ordering: [v0, v1, v2, mid01, mid12, mid20] where v0,v1,v2 are vertices and midXX are mid-edge nodes.
Fields§
§el_id: usizeElement id
coords: [[f64; 6]; 2]Coordinates: coords[0] = x[0..6], coords[1] = y[0..6]
node_ids: [usize; 6]Global node ids
elastic_modulus: f64Elastic modulus
shear_modulus: f64Shear modulus
density: f64Density
Implementations§
Source§impl Tri6
impl Tri6
Sourcepub fn from_points(
el_id: usize,
points: [Point; 6],
node_ids: [usize; 6],
em: f64,
gm: f64,
rho: f64,
) -> Result<Self, FemError>
pub fn from_points( el_id: usize, points: [Point; 6], node_ids: [usize; 6], em: f64, gm: f64, rho: f64, ) -> Result<Self, FemError>
Create a Tri6 element from 6 points and node ids.
Validates that the element has positive orientation (CCW winding).
Returns Err(FemError::InvalidElementOrientation) if the element
is degenerate or has negative Jacobian (CW winding).
Examples found in repository?
5fn main() {
6 let points = [
7 Point::new(0.0, 0.0), // node 0
8 Point::new(1.0, 0.0), // node 1
9 Point::new(0.0, 1.0), // node 2
10 Point::new(0.5, 0.0), // node 3 (mid 0-1)
11 Point::new(0.5, 0.5), // node 4 (mid 1-2)
12 Point::new(0.0, 0.5), // node 5 (mid 2-0)
13 ];
14
15 let tri6 = Tri6::from_points(0, points, [0, 1, 2, 3, 4, 5], 1.0, 1.0, 1.0).unwrap();
16
17 let (k_el, f_el, c_el) = tri6.torsion_properties();
18
19 println!("=== Tri6 Element Matrices on Unit Triangle (C_e with 7-point rule) ===");
20 println!("\nC_e (6x1):");
21 for i in 0..6 {
22 println!(" C[{}] = {:.10}", i, c_el[i]);
23 }
24 let c_sum: f64 = c_el.iter().sum();
25 println!("Sum C_e = {:.10} (expected 0.5)", c_sum);
26
27 // Expected with correct 7-point rule:
28 // C_corner = A/12 = 0.5/12 = 0.041666...
29 // C_mid = A/6 = 0.5/6 = 0.08333...
30 println!(
31 "\nExpected: corner = {:.10}, mid = {:.10}",
32 0.5 / 12.0,
33 0.5 / 6.0
34 );
35}More examples
34fn main() {
35 // Create a simple channel-like element for comparison
36 let points = [
37 Point::new(0.0, 0.0),
38 Point::new(10.0, 0.0),
39 Point::new(0.0, 2.0),
40 Point::new(5.0, 0.0),
41 Point::new(5.0, 1.0),
42 Point::new(0.0, 1.0),
43 ];
44
45 let tri6 = Tri6::from_points(
46 0,
47 points,
48 [0, 1, 2, 3, 4, 5],
49 200_000.0, // E = 200 GPa
50 76_923.0, // G
51 7850.0, // density
52 )
53 .unwrap();
54
55 let (k_el, f_el, c_el) = tri6.torsion_properties();
56 let gps = gauss_points(6);
57
58 // Compute Gauss point details
59 let mut gauss_details = String::new();
60 for i in 0..6 {
61 let sf = shape_function(&tri6.coords, (gps[i].1, gps[i].2, gps[i].3));
62 let n_str = format_array(&sf.n);
63 let b0_str = format_array(&sf.b[0]);
64 let b1_str = format_array(&sf.b[1]);
65
66 gauss_details.push_str(&format!(
67 " {{\n \"w\": {:.10},\n \"eta\": {:.10},\n \"xi\": {:.10},\n \"zeta\": {:.10},\n \"n\": [{}],\n \"b\": [\n [{}],\n [{}]\n ],\n \"j\": {:.10},\n \"x\": {:.10},\n \"y\": {:.10}\n }}{}\n",
68 gps[i].0, gps[i].1, gps[i].2, gps[i].3,
69 n_str, b0_str, b1_str,
70 sf.j, sf.x, sf.y,
71 if i < 5 { "," } else { "" }
72 ));
73 }
74
75 // Write to JSON file
76 let mut file = File::create("element_data.json").unwrap();
77 writeln!(file, "{{").unwrap();
78 writeln!(file, " \"coords\": {{").unwrap();
79 writeln!(
80 file,
81 " \"x\": [{}],",
82 format_array(&[
83 tri6.coords[0][0],
84 tri6.coords[0][1],
85 tri6.coords[0][2],
86 tri6.coords[0][3],
87 tri6.coords[0][4],
88 tri6.coords[0][5]
89 ])
90 )
91 .unwrap();
92 writeln!(
93 file,
94 " \"y\": [{}]",
95 format_array(&[
96 tri6.coords[1][0],
97 tri6.coords[1][1],
98 tri6.coords[1][2],
99 tri6.coords[1][3],
100 tri6.coords[1][4],
101 tri6.coords[1][5]
102 ])
103 )
104 .unwrap();
105 writeln!(file, " }},").unwrap();
106
107 writeln!(file, " \"k_el\": [\n{} ],", format_matrix(&k_el)).unwrap();
108 writeln!(file, " \"f_el\": [{}],", format_array(&f_el)).unwrap();
109 writeln!(file, " \"c_el\": [{}]", format_array(&c_el)).unwrap();
110 writeln!(file, ",").unwrap();
111
112 // Gauss points
113 writeln!(file, " \"gauss_points\": [").unwrap();
114 for i in 0..6 {
115 writeln!(
116 file,
117 " [{:.10}, {:.10}, {:.10}, {:.10}]{}",
118 gps[i].0,
119 gps[i].1,
120 gps[i].2,
121 gps[i].3,
122 if i < 5 { "," } else { "" }
123 )
124 .unwrap();
125 }
126 writeln!(file, " ],").unwrap();
127
128 writeln!(file, " \"gauss_details\": [\n{}\n ]", gauss_details).unwrap();
129 writeln!(file, "}}").unwrap();
130
131 println!("Element data exported to element_data.json");
132}Sourcepub fn geometric_properties(&self) -> (f64, f64, f64, f64, f64, f64)
pub fn geometric_properties(&self) -> (f64, f64, f64, f64, f64, f64)
Calculate geometric properties: (area, qx, qy, ixx, iyy, ixy).
Sourcepub fn torsion_properties(&self) -> ([[f64; 6]; 6], [f64; 6], [f64; 6])
pub fn torsion_properties(&self) -> ([[f64; 6]; 6], [f64; 6], [f64; 6])
Calculate torsion stiffness matrix (6×6), load vector (6), and constraint vector (6).
Examples found in repository?
5fn main() {
6 let points = [
7 Point::new(0.0, 0.0), // node 0
8 Point::new(1.0, 0.0), // node 1
9 Point::new(0.0, 1.0), // node 2
10 Point::new(0.5, 0.0), // node 3 (mid 0-1)
11 Point::new(0.5, 0.5), // node 4 (mid 1-2)
12 Point::new(0.0, 0.5), // node 5 (mid 2-0)
13 ];
14
15 let tri6 = Tri6::from_points(0, points, [0, 1, 2, 3, 4, 5], 1.0, 1.0, 1.0).unwrap();
16
17 let (k_el, f_el, c_el) = tri6.torsion_properties();
18
19 println!("=== Tri6 Element Matrices on Unit Triangle (C_e with 7-point rule) ===");
20 println!("\nC_e (6x1):");
21 for i in 0..6 {
22 println!(" C[{}] = {:.10}", i, c_el[i]);
23 }
24 let c_sum: f64 = c_el.iter().sum();
25 println!("Sum C_e = {:.10} (expected 0.5)", c_sum);
26
27 // Expected with correct 7-point rule:
28 // C_corner = A/12 = 0.5/12 = 0.041666...
29 // C_mid = A/6 = 0.5/6 = 0.08333...
30 println!(
31 "\nExpected: corner = {:.10}, mid = {:.10}",
32 0.5 / 12.0,
33 0.5 / 6.0
34 );
35}More examples
34fn main() {
35 // Create a simple channel-like element for comparison
36 let points = [
37 Point::new(0.0, 0.0),
38 Point::new(10.0, 0.0),
39 Point::new(0.0, 2.0),
40 Point::new(5.0, 0.0),
41 Point::new(5.0, 1.0),
42 Point::new(0.0, 1.0),
43 ];
44
45 let tri6 = Tri6::from_points(
46 0,
47 points,
48 [0, 1, 2, 3, 4, 5],
49 200_000.0, // E = 200 GPa
50 76_923.0, // G
51 7850.0, // density
52 )
53 .unwrap();
54
55 let (k_el, f_el, c_el) = tri6.torsion_properties();
56 let gps = gauss_points(6);
57
58 // Compute Gauss point details
59 let mut gauss_details = String::new();
60 for i in 0..6 {
61 let sf = shape_function(&tri6.coords, (gps[i].1, gps[i].2, gps[i].3));
62 let n_str = format_array(&sf.n);
63 let b0_str = format_array(&sf.b[0]);
64 let b1_str = format_array(&sf.b[1]);
65
66 gauss_details.push_str(&format!(
67 " {{\n \"w\": {:.10},\n \"eta\": {:.10},\n \"xi\": {:.10},\n \"zeta\": {:.10},\n \"n\": [{}],\n \"b\": [\n [{}],\n [{}]\n ],\n \"j\": {:.10},\n \"x\": {:.10},\n \"y\": {:.10}\n }}{}\n",
68 gps[i].0, gps[i].1, gps[i].2, gps[i].3,
69 n_str, b0_str, b1_str,
70 sf.j, sf.x, sf.y,
71 if i < 5 { "," } else { "" }
72 ));
73 }
74
75 // Write to JSON file
76 let mut file = File::create("element_data.json").unwrap();
77 writeln!(file, "{{").unwrap();
78 writeln!(file, " \"coords\": {{").unwrap();
79 writeln!(
80 file,
81 " \"x\": [{}],",
82 format_array(&[
83 tri6.coords[0][0],
84 tri6.coords[0][1],
85 tri6.coords[0][2],
86 tri6.coords[0][3],
87 tri6.coords[0][4],
88 tri6.coords[0][5]
89 ])
90 )
91 .unwrap();
92 writeln!(
93 file,
94 " \"y\": [{}]",
95 format_array(&[
96 tri6.coords[1][0],
97 tri6.coords[1][1],
98 tri6.coords[1][2],
99 tri6.coords[1][3],
100 tri6.coords[1][4],
101 tri6.coords[1][5]
102 ])
103 )
104 .unwrap();
105 writeln!(file, " }},").unwrap();
106
107 writeln!(file, " \"k_el\": [\n{} ],", format_matrix(&k_el)).unwrap();
108 writeln!(file, " \"f_el\": [{}],", format_array(&f_el)).unwrap();
109 writeln!(file, " \"c_el\": [{}]", format_array(&c_el)).unwrap();
110 writeln!(file, ",").unwrap();
111
112 // Gauss points
113 writeln!(file, " \"gauss_points\": [").unwrap();
114 for i in 0..6 {
115 writeln!(
116 file,
117 " [{:.10}, {:.10}, {:.10}, {:.10}]{}",
118 gps[i].0,
119 gps[i].1,
120 gps[i].2,
121 gps[i].3,
122 if i < 5 { "," } else { "" }
123 )
124 .unwrap();
125 }
126 writeln!(file, " ],").unwrap();
127
128 writeln!(file, " \"gauss_details\": [\n{}\n ]", gauss_details).unwrap();
129 writeln!(file, "}}").unwrap();
130
131 println!("Element data exported to element_data.json");
132}Sourcepub fn shear_load_vectors(
&self,
ixx: f64,
iyy: f64,
ixy: f64,
nu: f64,
) -> ([f64; 6], [f64; 6])
pub fn shear_load_vectors( &self, ixx: f64, iyy: f64, ixy: f64, nu: f64, ) -> ([f64; 6], [f64; 6])
Calculate shear load vectors f_psi and f_phi.
Sourcepub fn shear_warping_integrals(
&self,
ixx: f64,
iyy: f64,
ixy: f64,
omega: &[f64; 6],
) -> (f64, f64, f64, f64, f64, f64)
pub fn shear_warping_integrals( &self, ixx: f64, iyy: f64, ixy: f64, omega: &[f64; 6], ) -> (f64, f64, f64, f64, f64, f64)
Calculate shear centre and warping integrals.
Returns (sc_xint, sc_yint, q_omega, i_omega, i_xomega, i_yomega).
Sourcepub fn shear_coefficients(
&self,
ixx: f64,
iyy: f64,
ixy: f64,
psi_shear: &[f64; 6],
phi_shear: &[f64; 6],
nu: f64,
) -> (f64, f64, f64)
pub fn shear_coefficients( &self, ixx: f64, iyy: f64, ixy: f64, psi_shear: &[f64; 6], phi_shear: &[f64; 6], nu: f64, ) -> (f64, f64, f64)
Calculate shear deformation coefficients (kappa_x, kappa_y, kappa_xy).
Sourcepub fn monosymmetry_integrals(&self, phi: f64) -> (f64, f64, f64, f64)
pub fn monosymmetry_integrals(&self, phi: f64) -> (f64, f64, f64, f64)
Calculate monosymmetry integrals (int_x, int_y, int_11, int_22).
phi is the principal axis angle in radians.
Sourcepub fn torsion_shear_stress(&self, omega: &[f64; 6]) -> (f64, (f64, f64))
pub fn torsion_shear_stress(&self, omega: &[f64; 6]) -> (f64, (f64, f64))
Calculate the St. Venant shear-stress factor at Gauss points.
For pure torsion with torque T, the stress is T / J times the
returned factor: (∂ω/∂x - y, ∂ω/∂y + x).
Returns (max_shear_stress_magnitude, max_shear_stress_vector) where max_shear_stress_vector = (tau_x, tau_y) at the point of max magnitude.
Sourcepub fn element_stress(
&self,
n: f64,
mxx: f64,
myy: f64,
m11: f64,
m22: f64,
mzz: f64,
vx: f64,
vy: f64,
ea: f64,
cx: f64,
cy: f64,
ixx: f64,
iyy: f64,
ixy: f64,
i11: f64,
i22: f64,
phi: f64,
j: f64,
nu: f64,
omega: &[f64; 6],
psi_shear: &[f64; 6],
phi_shear: &[f64; 6],
delta_s: f64,
) -> [[f64; 6]; 11]
pub fn element_stress( &self, n: f64, mxx: f64, myy: f64, m11: f64, m22: f64, mzz: f64, vx: f64, vy: f64, ea: f64, cx: f64, cy: f64, ixx: f64, iyy: f64, ixy: f64, i11: f64, i22: f64, phi: f64, j: f64, nu: f64, omega: &[f64; 6], psi_shear: &[f64; 6], phi_shear: &[f64; 6], delta_s: f64, ) -> [[f64; 6]; 11]
Calculate element stresses at the 6 Gauss points, extrapolated to nodes.
Returns 11 nodal stress arrays (each length 6): (sig_zz_n, sig_zz_mxx, sig_zz_myy, sig_zz_m11, sig_zz_m22, sig_zx_mzz, sig_zy_mzz, sig_zx_vx, sig_zy_vx, sig_zx_vy, sig_zy_vy)