pub struct Material {
pub youngs_modulus: f64,
pub shear_modulus: f64,
pub poissons_ratio: f64,
pub density: f64,
pub thermal_expansion: f64,
pub yield_strength: f64,
pub ultimate_strength: f64,
pub name: &'static str,
pub color: Option<(u8, u8, u8)>,
}Fields§
§youngs_modulus: f64Young’s modulus Pa
shear_modulus: f64Shear modulus Pa
poissons_ratio: f64Poisson’s ratio [-]
density: f64Density [kg/m³]
thermal_expansion: f64Coefficient of thermal expansion [1/K]
yield_strength: f64Yield strength Pa (for plastic analysis)
ultimate_strength: f64Ultimate tensile strength Pa
name: &'static strOptional: identifier/name for display
color: Option<(u8, u8, u8)>Optional: color for visualization (RGB 0-255)
Implementations§
Source§impl Material
impl Material
Sourcepub fn new(
youngs_modulus: f64,
poissons_ratio: f64,
density: f64,
name: &'static str,
) -> Self
pub fn new( youngs_modulus: f64, poissons_ratio: f64, density: f64, name: &'static str, ) -> Self
Create a new material from E and ν (computes G = E / (2(1+ν))).
This is an unchecked constructor — it does not validate the
inputs. Call is_valid to verify that the
resulting material has physically admissible properties.
Examples found in repository?
20fn main() -> Result<(), Box<dyn std::error::Error>> {
21 let (e, a, i, l, p) = (1.0, 1.0, 1.0, 1.0, 100.0);
22
23 // --- model ---------------------------------------------------------------
24 let mut model = BeamModel::new();
25 model.add_node(BeamNode::new(0, 0.0, 0.0));
26 model.add_node(BeamNode::new(1, l, 0.0));
27 model.add_element(BeamElement::new(
28 0,
29 1,
30 Material::new(e, 0.3, 1.0, "unit"),
31 BeamSection::new(a, i),
32 )?);
33 model.fix_node(0); // clamp node 0 (ux = uy = rz = 0)
34 model.add_nodal_force(1, 1, -p); // global uy = -P at the free tip
35
36 // --- solve ---------------------------------------------------------------
37 let mut solver = BeamSolver::from_model(&model)?;
38 solver.solve_configured()?; // default SolverSelection::Auto
39 let res = solver.results();
40
41 // --- results -------------------------------------------------------------
42 // Typed DOF accessors on the solver (equivalent to the raw-index API):
43 // solver.displacement_dof(1, Dof::Uy) == solver.displacement(1, 1).unwrap()
44 let uy = solver.displacement_dof(1, Dof::Uy)?;
45 let rz = solver.displacement_dof(1, Dof::Rz)?;
46 let ry = solver.reaction_dof(0, Dof::Uy)?;
47 let moment = solver.reaction_dof(0, Dof::Rz)?;
48
49 println!("solver backend : {:?}", res.solver_name());
50 println!(
51 "tip uy : {:+.6} (analytical {:+.6})",
52 uy,
53 -p * l.powi(3) / (3.0 * e * i)
54 );
55 println!(
56 "tip rz : {:+.6} (analytical {:+.6})",
57 rz,
58 -p * l.powi(2) / (2.0 * e * i)
59 );
60 println!("reaction Ry : {:+.6} (analytical {:+.6})", ry, p);
61 println!(
62 "reaction Rz : {:+.6} (analytical {:+.6})",
63 moment,
64 p * l
65 );
66
67 let end = res.element_end_forces(0)?;
68 println!("element end forces [N_i,V_i,M_i,N_j,V_j,M_j] = {end:?}");
69 println!(
70 "internal section moment at the fixed end M(0) = {:+.6} (analytical -P L = {:+.6})",
71 res.section_forces(0, 0.0)?.moment,
72 -p * l
73 );
74
75 Ok(())
76}More examples
19fn main() -> Result<(), Box<dyn std::error::Error>> {
20 let (e, a, i, l, q) = (1.0, 1.0, 1.0, 1.0, 100.0);
21 let n_elem = 4;
22
23 // --- model ---------------------------------------------------------------
24 let mut model = BeamModel::new();
25 let dx = l / n_elem as f64;
26 for k in 0..=n_elem {
27 model.add_node(BeamNode::new(k, k as f64 * dx, 0.0));
28 }
29 for k in 0..n_elem {
30 model.add_element(BeamElement::new(
31 k,
32 k + 1,
33 Material::new(e, 0.3, 1.0, "unit"),
34 BeamSection::new(a, i),
35 )?);
36 // uniform downward load, local qy < 0, applied to every element
37 model.add_distributed_load(k, 0.0, -q)?;
38 }
39 model.fix_node(0);
40
41 // --- solve ---------------------------------------------------------------
42 let mut solver = BeamSolver::from_model(&model)?;
43 solver.solve_configured()?;
44 let res = solver.results();
45
46 // --- results -------------------------------------------------------------
47 // Typed DOF accessors on the solver (equivalent to the raw-index API).
48 let tip_uy = solver.displacement_dof(n_elem, Dof::Uy)?;
49 let tip_rz = solver.displacement_dof(n_elem, Dof::Rz)?;
50 let ry = solver.reaction_dof(0, Dof::Uy)?;
51 let rz = solver.reaction_dof(0, Dof::Rz)?;
52
53 println!("solver backend : {:?}", res.solver_name());
54 println!(
55 "tip uy : {:+.6} (analytical {:+.6})",
56 tip_uy,
57 -q * l.powi(4) / (8.0 * e * i)
58 );
59 println!(
60 "tip rz : {:+.6} (analytical {:+.6})",
61 tip_rz,
62 -q * l.powi(3) / (6.0 * e * i)
63 );
64 println!(
65 "reaction Ry : {:+.6} (analytical q L = {:+.6})",
66 ry,
67 q * l
68 );
69 println!(
70 "reaction Rz : {:+.6} (analytical q L^2 / 2 = {:+.6})",
71 rz,
72 q * l * l / 2.0
73 );
74
75 // Each element's end forces are element-on-node forces; the total transverse
76 // end-force resultant across the beam balances the applied load q·L.
77 let mut total_vy = 0.0;
78 for k in 0..n_elem {
79 let fe = res.element_end_forces(k)?;
80 total_vy += fe[1] + fe[4];
81 }
82 println!(
83 "Σ element end shear = {:+.6}; applied load = {:+.6} (counted once)",
84 total_vy,
85 -q * l
86 );
87
88 Ok(())
89}13fn main() -> Result<(), Box<dyn std::error::Error>> {
14 let (e, a, i) = (200e9, 5e-3, 2e-5);
15 let (h, w) = (3.0, 4.0);
16 let lateral = 20e3; // N, +X
17 let udl = -8e3; // N/m, downward in member-local +y
18
19 // --- model -----------------------------------------------------------------
20 let mut frame = FrameModel::new();
21 let base_left = frame.add_node(0.0, 0.0)?;
22 let top_left = frame.add_node(0.0, h)?;
23 let top_right = frame.add_node(w, h)?;
24 let base_right = frame.add_node(w, 0.0)?;
25
26 let section = BeamSection::new(a, i);
27 let mat = Material::new(e, 0.3, 7850.0, "Steel");
28 let col_left = frame.add_member(base_left, top_left, mat, section)?;
29 let beam = frame.add_member(top_left, top_right, mat, section)?;
30 let col_right = frame.add_member(top_right, base_right, mat, section)?;
31
32 frame.fix(base_left)?;
33 frame.fix(base_right)?;
34 frame.nodal_load(top_left, lateral, 0.0)?; // global
35 frame.member_udl(beam, 0.0, udl)?; // local
36
37 // --- solve -----------------------------------------------------------------
38 let result = frame.solve_with(SolverSelection::named("sparse_lu"))?;
39 println!("backend : {:?}", result.solver_name());
40 println!(
41 "nodes / members : {} / {}",
42 result.n_nodes(),
43 result.n_members()
44 );
45
46 // --- results ---------------------------------------------------------------
47 println!(
48 "roof sway (ux) : {:+.6e} m",
49 result.displacement(top_left, Dof::Ux)?
50 );
51 println!(
52 "base reactions : Rx={:+.6e} Ry={:+.6e} Mz={:+.6e}",
53 result.reaction(base_left, Dof::Ux)?,
54 result.reaction(base_left, Dof::Uy)?,
55 result.reaction(base_left, Dof::Rz)?
56 );
57 println!(
58 "right base reaction : Rx={:+.6e} Ry={:+.6e}",
59 result.reaction(base_right, Dof::Ux)?,
60 result.reaction(base_right, Dof::Uy)?
61 );
62
63 // Member end forces are element-on-node forces in LOCAL axes:
64 // [N_i, V_i, M_i, N_j, V_j, M_j] = f_equiv - K_e u_e.
65 println!(
66 "beam end forces (local) : {:?}",
67 result.member_end_forces(beam)?
68 );
69 println!(
70 "left column global ends : {:?}",
71 result.member_end_forces_global(col_left)?
72 );
73 println!(
74 "right column global ends : {:?}",
75 result.member_end_forces_global(col_right)?
76 );
77
78 // --- equilibrium -----------------------------------------------------------
79 let eq = result.equilibrium();
80 println!(
81 "equilibrium residual : sumFx={:+.3e} sumFy={:+.3e} sumMz={:+.3e} (about the origin)",
82 eq.fx_residual, eq.fy_residual, eq.mz_residual
83 );
84 println!("balanced : {}", eq.is_balanced());
85
86 Ok(())
87}23fn main() -> Result<(), Box<dyn std::error::Error>> {
24 let (e, a, i, l) = (1.0, 1.0, 1.0, 1.0);
25 let (fx, fy, m) = (50.0, -100.0, 20.0);
26 let angle: f64 = 45.0_f64.to_radians();
27 let (c, s) = (angle.cos(), angle.sin());
28
29 // --- model (element along direction (cos, sin)) --------------------------
30 let mut model = BeamModel::new();
31 model.add_node(BeamNode::new(0, 0.0, 0.0));
32 model.add_node(BeamNode::new(1, l * c, l * s));
33 model.add_element(BeamElement::new(
34 0,
35 1,
36 Material::new(e, 0.3, 1.0, "unit"),
37 BeamSection::new(a, i),
38 )?);
39 model.fix_node(0);
40
41 // Local tip force (fx, fy) expressed in global coordinates: Fg = R(theta)·F.
42 let gx = c * fx - s * fy;
43 let gy = s * fx + c * fy;
44 model.add_nodal_force(1, 0, gx);
45 model.add_nodal_force(1, 1, gy);
46 model.add_applied_moment(1, m)?; // applied moment is a global theta load
47
48 // --- solve ---------------------------------------------------------------
49 let mut solver = BeamSolver::from_model(&model)?;
50 solver.solve_configured()?;
51 let res = solver.results();
52
53 // --- global results ------------------------------------------------------
54 // Typed DOF accessors on the solver (equivalent to the raw-index API).
55 let (dgx, dgy) = (
56 solver.displacement_dof(1, Dof::Ux)?,
57 solver.displacement_dof(1, Dof::Uy)?,
58 );
59 println!("solver backend : {:?}", res.solver_name());
60 println!("global tip ux,uy : {:+.6}, {:+.6}", dgx, dgy);
61
62 // Local tip displacement: u_local = T · u_global.
63 let el = &model.elements[0];
64 let ni = model.nodes[0].point();
65 let nj = model.nodes[1].point();
66 let t = el.transformation_matrix(ni, nj);
67 let ug = [
68 solver.displacements()[3],
69 solver.displacements()[4],
70 solver.displacements()[5],
71 ];
72 let ul = [
73 t[0][0] * ug[0] + t[0][1] * ug[1],
74 t[1][0] * ug[0] + t[1][1] * ug[1],
75 ug[2],
76 ];
77 println!(
78 "local tip u,v : {:+.6}, {:+.6} (analytical {:+.6}, {:+.6})",
79 ul[0],
80 ul[1],
81 fx * l / (e * a),
82 fy * l.powi(3) / (3.0 * e * i) + m * l * l / (2.0 * e * i)
83 );
84 println!(
85 "local tip theta : {:+.6} (analytical {:+.6})",
86 ul[2],
87 fy * l.powi(2) / (2.0 * e * i) + m * l / (e * i)
88 );
89
90 // --- reactions and equilibrium ------------------------------------------
91 let r0 = res.reaction(0)?;
92 println!("reaction Rx,Ry : {:+.6}, {:+.6}", r0.fx, r0.fy);
93 println!("reaction Rz : {:+.6}", r0.mz);
94 println!("ΣFx residual : {:+.3e}", r0.fx + gx);
95 println!("ΣFy residual : {:+.3e}", r0.fy + gy);
96 println!(
97 "ΣMz residual : {:+.3e} (about the fixed node)",
98 r0.mz + m + l * c * gy - l * s * gx
99 );
100
101 // --- element end forces --------------------------------------------------
102 println!("local end forces : {:?}", res.element_end_forces(0)?);
103 println!(
104 "global end forces: {:?}",
105 solver.element_end_forces_global()?[0]
106 );
107
108 Ok(())
109}Sourcepub fn with_all(
youngs_modulus: f64,
shear_modulus: f64,
poissons_ratio: f64,
density: f64,
thermal_expansion: f64,
yield_strength: f64,
ultimate_strength: f64,
name: &'static str,
) -> Self
pub fn with_all( youngs_modulus: f64, shear_modulus: f64, poissons_ratio: f64, density: f64, thermal_expansion: f64, yield_strength: f64, ultimate_strength: f64, name: &'static str, ) -> Self
Create a new material with all properties specified.
This is an unchecked constructor — it does not validate the
inputs. Call is_valid to verify that the
resulting material has physically admissible properties.
Sourcepub fn with_thermal_expansion(self, alpha: f64) -> Self
pub fn with_thermal_expansion(self, alpha: f64) -> Self
Set thermal expansion coefficient.
Sourcepub fn with_yield_strength(self, fy: f64) -> Self
pub fn with_yield_strength(self, fy: f64) -> Self
Set yield strength.
Sourcepub fn with_ultimate_strength(self, fu: f64) -> Self
pub fn with_ultimate_strength(self, fu: f64) -> Self
Set ultimate strength.
Sourcepub fn with_color(self, r: u8, g: u8, b: u8) -> Self
pub fn with_color(self, r: u8, g: u8, b: u8) -> Self
Set visualization color (RGB).
Sourcepub fn modular_ratio(&self, ref_material: &Material) -> f64
pub fn modular_ratio(&self, ref_material: &Material) -> f64
Get modular ratio relative to another material (n = E_this / E_ref).
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Check if material properties are physically valid.
Returns true only when every field is finite and within the
physically admissible range for an isotropic linear-elastic solid:
E > 0and finiteG > 0and finite-1 < ν < 0.5(strict on both sides: ν = -1 gives G = ∞, ν = 0.5 gives infinite bulk modulus)ρ ≥ 0and finite (zero density is admissible for a massless placeholder)