use crate::material::Material;
use crate::section::Section;
use crate::section_properties::SectionProperties;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SectionClass {
Class1 = 1,
Class2 = 2,
Class3 = 3,
Class4 = 4,
}
impl PartialOrd for SectionClass {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for SectionClass {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
(*self as u8).cmp(&(*other as u8)).reverse()
}
}
impl SectionClass {
pub fn can_plastic_moment(&self) -> bool {
matches!(self, SectionClass::Class1 | SectionClass::Class2)
}
pub fn can_plastic_rotation(&self) -> bool {
matches!(self, SectionClass::Class1)
}
pub fn requires_effective_section(&self) -> bool {
matches!(self, SectionClass::Class4)
}
pub fn description(&self) -> &'static str {
match self {
SectionClass::Class1 => "Class 1 - Plastic (rotation capacity)",
SectionClass::Class2 => "Class 2 - Compact (plastic moment)",
SectionClass::Class3 => "Class 3 - Semi-compact (elastic moment)",
SectionClass::Class4 => "Class 4 - Slender (local buckling)",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum StressDistribution {
UniformCompression,
Bending,
BendingAndCompression { alpha: f64 }, FlangeBendingAndCompression { psi: f64 }, }
impl StressDistribution {
pub fn pure_bending() -> Self {
StressDistribution::Bending
}
pub fn pure_compression() -> Self {
StressDistribution::UniformCompression
}
pub fn web_bending_compression(alpha: f64) -> Self {
StressDistribution::BendingAndCompression { alpha }
}
pub fn flange_bending_compression(psi: f64) -> Self {
StressDistribution::FlangeBendingAndCompression { psi }
}
}
#[derive(Debug, Clone, Copy)]
pub struct ClassLimit {
pub class1: f64,
pub class2: f64,
pub class3: f64,
}
impl ClassLimit {
pub fn classify(&self, c_t: f64) -> SectionClass {
if c_t <= self.class1 {
SectionClass::Class1
} else if c_t <= self.class2 {
SectionClass::Class2
} else if c_t <= self.class3 {
SectionClass::Class3
} else {
SectionClass::Class4
}
}
}
fn web_limits(eps: f64, stress: StressDistribution) -> ClassLimit {
match stress {
StressDistribution::UniformCompression => ClassLimit {
class1: 33.0 * eps,
class2: 38.0 * eps,
class3: 42.0 * eps,
},
StressDistribution::Bending => ClassLimit {
class1: 72.0 * eps,
class2: 83.0 * eps,
class3: 124.0 * eps,
},
StressDistribution::BendingAndCompression { alpha } => {
let alpha = alpha.clamp(0.0, 1.0);
let psi = 4.0 * alpha - 3.0;
let (class1, class2) = if alpha > 0.5 {
(
396.0 * eps / (13.0 * alpha - 1.0),
456.0 * eps / (13.0 * alpha - 1.0),
)
} else if alpha > 0.0 {
(36.0 * eps / alpha, 41.5 * eps / alpha)
} else {
(f64::MAX, f64::MAX)
};
let class3_denom = 0.67 + 0.33 * psi;
let class3 = if class3_denom > 0.0 {
42.0 * eps / class3_denom
} else {
f64::MAX
};
ClassLimit {
class1,
class2,
class3,
}
}
StressDistribution::FlangeBendingAndCompression { .. } => {
ClassLimit {
class1: 0.0,
class2: 0.0,
class3: 0.0,
}
}
}
}
fn outstand_flange_limits(eps: f64, stress: StressDistribution) -> ClassLimit {
match stress {
StressDistribution::UniformCompression => ClassLimit {
class1: 9.0 * eps,
class2: 10.0 * eps,
class3: 14.0 * eps,
},
StressDistribution::Bending => ClassLimit {
class1: 9.0 * eps,
class2: 10.0 * eps,
class3: 14.0 * eps,
},
StressDistribution::BendingAndCompression { .. } => {
ClassLimit {
class1: 9.0 * eps,
class2: 10.0 * eps,
class3: 14.0 * eps,
}
}
StressDistribution::FlangeBendingAndCompression { psi } => {
let class1 = 9.0 * eps / (1.0 + psi).sqrt().max(0.1);
let class2 = 10.0 * eps / (1.0 + psi).sqrt().max(0.1);
let class3 = 14.0 * eps / (1.0 + psi).sqrt().max(0.1);
ClassLimit {
class1,
class2,
class3,
}
}
}
}
fn internal_flange_limits(eps: f64) -> ClassLimit {
ClassLimit {
class1: 33.0 * eps,
class2: 38.0 * eps,
class3: 42.0 * eps,
}
}
#[derive(Debug, Clone)]
pub struct SectionClassification {
pub overall_class: SectionClass,
pub web_class: SectionClass,
pub flange_class: SectionClass,
pub tension_flange_class: SectionClass,
pub web_c_t: f64,
pub flange_c_t: f64,
pub epsilon: f64,
pub web_stress: StressDistribution,
pub flange_stress: StressDistribution,
pub is_class4: bool,
}
impl SectionClassification {
pub fn can_plastic_moment(&self) -> bool {
self.overall_class.can_plastic_moment()
}
pub fn can_plastic_rotation(&self) -> bool {
self.overall_class.can_plastic_rotation()
}
pub fn governing_element(&self) -> &'static str {
let classes = [
(self.web_class, "web"),
(self.flange_class, "compression flange"),
(self.tension_flange_class, "tension flange"),
];
classes
.iter()
.max_by_key(|(c, _)| *c as u8)
.map(|(_, name)| *name)
.unwrap_or("unknown")
}
pub fn summary(&self) -> String {
format!(
"Overall: {} (governed by {}) | Web: c/t={:.1} ({}) | Flange: c/t={:.1} ({}) | ε={:.3}",
self.overall_class.description(),
self.governing_element(),
self.web_c_t,
self.web_class.description(),
self.flange_c_t,
self.flange_class.description(),
self.epsilon
)
}
}
pub fn classify_i_section(
section: &Section,
material: &Material,
stress: StressDistribution,
) -> SectionClassification {
let fy = material.yield_strength;
let eps = (235e6 / fy).sqrt();
let props = SectionProperties::from_section(section);
let bounds = section.bounds();
let _h = bounds.3 - bounds.2; let b = bounds.1 - bounds.0;
let (tw, tf, hw) = estimate_i_section_dimensions(section, &props);
let web_c_t = hw / tw;
let flange_c_t = (b - tw) / (2.0 * tf);
let web_limits = web_limits(eps, stress);
let web_class = web_limits.classify(web_c_t);
let flange_limits = outstand_flange_limits(eps, stress);
let flange_class = flange_limits.classify(flange_c_t);
let tension_flange_class = SectionClass::Class1;
let overall_class = [web_class, flange_class, tension_flange_class]
.iter()
.min()
.copied()
.unwrap_or(SectionClass::Class4);
SectionClassification {
overall_class,
web_class,
flange_class,
tension_flange_class,
web_c_t,
flange_c_t,
epsilon: eps,
web_stress: stress,
flange_stress: stress,
is_class4: overall_class == SectionClass::Class4,
}
}
pub fn classify_hollow_section(
section: &Section,
material: &Material,
stress: StressDistribution,
) -> SectionClassification {
let fy = material.yield_strength;
let eps = (235e6 / fy).sqrt();
let props = SectionProperties::from_section(section);
let bounds = section.bounds();
let h = bounds.3 - bounds.2; let b = bounds.1 - bounds.0;
let is_circular = (h - b).abs() / h.max(b) < 0.05;
if is_circular {
let area = props.area;
let d = h; let t = area / (std::f64::consts::PI * d);
let d_t = d / t;
let limits = ClassLimit {
class1: 50.0 * eps * eps,
class2: 70.0 * eps * eps,
class3: 90.0 * eps * eps,
};
let overall_class = limits.classify(d_t);
SectionClassification {
overall_class,
web_class: overall_class,
flange_class: overall_class,
tension_flange_class: overall_class,
web_c_t: d_t,
flange_c_t: d_t,
epsilon: eps,
web_stress: stress,
flange_stress: stress,
is_class4: overall_class == SectionClass::Class4,
}
} else {
let area = props.area;
let peri = 2.0 * (h + b);
let t = area / peri;
let web_c_t = (h - 2.0 * t) / t;
let flange_c_t = (b - 2.0 * t) / t;
let web_limits = web_limits(eps, stress);
let flange_limits = internal_flange_limits(eps);
let web_class = web_limits.classify(web_c_t);
let flange_class = flange_limits.classify(flange_c_t);
let tension_flange_class = SectionClass::Class1;
let overall_class = [web_class, flange_class, tension_flange_class]
.iter()
.min()
.copied()
.unwrap_or(SectionClass::Class4);
SectionClassification {
overall_class,
web_class,
flange_class,
tension_flange_class,
web_c_t,
flange_c_t,
epsilon: eps,
web_stress: stress,
flange_stress: stress,
is_class4: overall_class == SectionClass::Class4,
}
}
}
pub fn classify_angle_section(section: &Section, material: &Material) -> SectionClassification {
let fy = material.yield_strength;
let eps = (235e6 / fy).sqrt();
let bounds = section.bounds();
let h = bounds.3 - bounds.2; let b = bounds.1 - bounds.0;
let props = SectionProperties::from_section(section);
let area = props.area;
let _peri = section.outer.vertices.len() as f64; let t = area / (h + b);
let c_t_leg1 = h / t;
let c_t_leg2 = b / t;
let limits = outstand_flange_limits(eps, StressDistribution::UniformCompression);
let class1 = limits.classify(c_t_leg1);
let class2 = limits.classify(c_t_leg2);
let overall_class = [class1, class2]
.iter()
.min()
.copied()
.unwrap_or(SectionClass::Class4);
SectionClassification {
overall_class,
web_class: class1,
flange_class: class2,
tension_flange_class: SectionClass::Class1,
web_c_t: c_t_leg1,
flange_c_t: c_t_leg2,
epsilon: eps,
web_stress: StressDistribution::UniformCompression,
flange_stress: StressDistribution::UniformCompression,
is_class4: overall_class == SectionClass::Class4,
}
}
pub fn classify_channel_section(
section: &Section,
material: &Material,
stress: StressDistribution,
) -> SectionClassification {
let fy = material.yield_strength;
let eps = (235e6 / fy).sqrt();
let props = SectionProperties::from_section(section);
let bounds = section.bounds();
let _h = bounds.3 - bounds.2; let b = bounds.1 - bounds.0;
let (tw, tf, hw) = estimate_i_section_dimensions(section, &props);
let web_c_t = hw / tw;
let flange_c_t = b / tf;
let web_limits = web_limits(eps, stress);
let flange_limits = outstand_flange_limits(eps, stress);
let web_class = web_limits.classify(web_c_t);
let flange_class = flange_limits.classify(flange_c_t);
let tension_flange_class = SectionClass::Class1;
let overall_class = [web_class, flange_class, tension_flange_class]
.iter()
.min()
.copied()
.unwrap_or(SectionClass::Class4);
SectionClassification {
overall_class,
web_class,
flange_class,
tension_flange_class,
web_c_t,
flange_c_t,
epsilon: eps,
web_stress: stress,
flange_stress: stress,
is_class4: overall_class == SectionClass::Class4,
}
}
pub fn classify_tee_section(
section: &Section,
material: &Material,
stress: StressDistribution,
) -> SectionClassification {
let fy = material.yield_strength;
let eps = (235e6 / fy).sqrt();
let props = SectionProperties::from_section(section);
let bounds = section.bounds();
let _h = bounds.3 - bounds.2; let b = bounds.1 - bounds.0;
let (tw, tf, hw) = estimate_i_section_dimensions(section, &props);
let web_c_t = hw / tw;
let flange_c_t = (b - tw) / (2.0 * tf);
let web_limits = web_limits(eps, stress);
let flange_limits = outstand_flange_limits(eps, stress);
let web_class = web_limits.classify(web_c_t);
let flange_class = flange_limits.classify(flange_c_t);
let tension_flange_class = SectionClass::Class1;
let overall_class = [web_class, flange_class, tension_flange_class]
.iter()
.min()
.copied()
.unwrap_or(SectionClass::Class4);
SectionClassification {
overall_class,
web_class,
flange_class,
tension_flange_class,
web_c_t,
flange_c_t,
epsilon: eps,
web_stress: stress,
flange_stress: stress,
is_class4: overall_class == SectionClass::Class4,
}
}
pub fn classify_section(
section: &Section,
material: &Material,
stress: StressDistribution,
) -> SectionClassification {
let props = SectionProperties::from_section(section);
let bounds = section.bounds();
let h = bounds.3 - bounds.2; let b = bounds.1 - bounds.0; let area = props.area;
if !section.holes.is_empty() {
return classify_hollow_section(section, material, stress);
}
let _peri = section.outer.vertices.len() as f64;
let _t_est = area / (2.0 * (h + b));
if area / (h * b) < 0.15 && section.holes.is_empty() {
}
let n_verts = section.outer.vertices.len();
if n_verts <= 6 {
if section.is_symmetric_about_x() && section.is_symmetric_about_y() {
if section.holes.is_empty() && area / (h * b) > 0.3 {
return classify_i_section(section, material, stress);
}
} else if section.is_symmetric_about_x() || section.is_symmetric_about_y() {
return classify_tee_section(section, material, stress);
} else {
return classify_angle_section(section, material);
}
}
classify_i_section(section, material, stress)
}
fn estimate_i_section_dimensions(section: &Section, props: &SectionProperties) -> (f64, f64, f64) {
let bounds = section.bounds();
let h = bounds.3 - bounds.2; let b = bounds.1 - bounds.0; let _area = props.area;
let mut x_coords: Vec<f64> = section.outer.vertices.iter().map(|v| v.x).collect();
let mut y_coords: Vec<f64> = section.outer.vertices.iter().map(|v| v.y).collect();
x_coords.sort_by(|a, b| a.partial_cmp(b).unwrap());
y_coords.sort_by(|a, b| a.partial_cmp(b).unwrap());
let center_x = (bounds.0 + bounds.1) / 2.0;
let mut x_abs: Vec<f64> = section
.outer
.vertices
.iter()
.filter(|v| (v.x - center_x).abs() < b * 0.25)
.map(|v| (v.x - center_x).abs())
.filter(|x| *x > 1e-9)
.collect();
x_abs.sort_by(|a, b| a.partial_cmp(b).unwrap());
let tw = if !x_abs.is_empty() {
x_abs[0] * 2.0
} else {
b * 0.1
};
let top_vertices: Vec<f64> = section
.outer
.vertices
.iter()
.filter(|v| v.y > bounds.3 - h * 0.1)
.map(|v| v.y)
.collect();
let tf = if top_vertices.len() >= 2 {
top_vertices
.iter()
.max_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap()
- top_vertices
.iter()
.min_by(|a, b| a.partial_cmp(b).unwrap())
.unwrap()
} else {
h * 0.05
};
let hw = h - 2.0 * tf;
(tw.max(1e-6), tf.max(1e-6), hw.max(1e-6))
}
pub mod effective {
use super::*;
use crate::geometry::Point;
use crate::section::Section;
use crate::section_properties::SectionProperties;
#[derive(Debug, Clone)]
pub struct EffectiveProperties {
pub area_eff: f64,
pub centroid_eff: Point,
pub ix_eff: f64,
pub iy_eff: f64,
pub ixy_eff: f64,
pub classification: SectionClassification,
pub reduction_factors: ElementReductions,
}
#[derive(Debug, Clone, Default)]
pub struct ElementReductions {
pub web_rho: f64,
pub flange_rho: f64,
}
pub fn effective_section(
section: &Section,
material: &Material,
stress: StressDistribution,
) -> EffectiveProperties {
let classification = classify_section(section, material, stress);
if !classification.is_class4 {
let props = SectionProperties::from_section(section);
return EffectiveProperties {
area_eff: props.area,
centroid_eff: props.centroid,
ix_eff: props.ix,
iy_eff: props.iy,
ixy_eff: props.ixy,
classification,
reduction_factors: ElementReductions::default(),
};
}
let fy = material.yield_strength;
let eps = (235e6 / fy).sqrt();
let mut rho_web = 1.0;
let mut rho_flange = 1.0;
if classification.web_class == SectionClass::Class4 {
let lambda_p = classification.web_c_t / (33.0 * eps); if lambda_p > 0.673 {
rho_web = (lambda_p - 0.22) / lambda_p;
rho_web = rho_web.clamp(0.0, 1.0);
}
}
if classification.flange_class == SectionClass::Class4 {
let lambda_p = classification.flange_c_t / (9.0 * eps);
if lambda_p > 0.673 {
rho_flange = (lambda_p - 0.22) / lambda_p;
rho_flange = rho_flange.clamp(0.0, 1.0);
}
}
let props = SectionProperties::from_section(section);
let area_red = 1.0 - (1.0 - rho_web) * 0.3 - (1.0 - rho_flange) * 0.2; let ix_red = 1.0 - (1.0 - rho_web) * 0.5 - (1.0 - rho_flange) * 0.3;
EffectiveProperties {
area_eff: props.area * area_red,
centroid_eff: props.centroid,
ix_eff: props.ix * ix_red,
iy_eff: props.iy * ix_red, ixy_eff: props.ixy * ix_red,
classification,
reduction_factors: ElementReductions {
web_rho: rho_web,
flange_rho: rho_flange,
},
}
}
}
trait SectionSymmetryCheck {
fn is_symmetric_about_x(&self) -> bool;
fn is_symmetric_about_y(&self) -> bool;
}
impl SectionSymmetryCheck for Section {
fn is_symmetric_about_x(&self) -> bool {
for v in &self.outer.vertices {
let found = self
.outer
.vertices
.iter()
.any(|v2| (v2.x - v.x).abs() < 1e-6 && (v2.y + v.y).abs() < 1e-6);
if !found {
return false;
}
}
true
}
fn is_symmetric_about_y(&self) -> bool {
for v in &self.outer.vertices {
let found = self
.outer
.vertices
.iter()
.any(|v2| (v2.y - v.y).abs() < 1e-6 && (v2.x + v.x).abs() < 1e-6);
if !found {
return false;
}
}
true
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::material::presets::STEEL_S355;
use crate::section_library::ParametricSection;
use crate::section_library::steel::ISection;
#[test]
fn classify_i_section_class1() {
let i = ISection::from_designation("IPE300").unwrap();
let section = i.build();
let classification =
classify_i_section(§ion, &STEEL_S355, StressDistribution::pure_bending());
assert!(classification.overall_class >= SectionClass::Class2);
assert!(classification.can_plastic_moment());
}
#[test]
fn classify_i_section_class4() {
let i = ISection::new(1.0, 0.2, 0.003, 0.005, 0.01); let section = i.build();
let classification =
classify_i_section(§ion, &STEEL_S355, StressDistribution::pure_bending());
assert_eq!(classification.overall_class, SectionClass::Class4);
assert!(classification.is_class4);
}
#[test]
fn classify_chs() {
let chs = crate::section_library::steel::CircularHollowSectionLib::new(0.219, 0.008);
let section = chs.build();
let classification =
classify_hollow_section(§ion, &STEEL_S355, StressDistribution::pure_bending());
assert!(classification.overall_class >= SectionClass::Class2);
}
#[test]
fn classify_rhs() {
let rhs = crate::section_library::steel::RectangularHollowSection::new(
0.2, 0.1, 0.008, 0.012, 0.004,
);
let section = rhs.build();
let classification =
classify_hollow_section(§ion, &STEEL_S355, StressDistribution::pure_bending());
assert!(classification.overall_class >= SectionClass::Class2);
}
#[test]
fn classify_angle() {
let angle = crate::section_library::steel::AngleSection::equal_leg(0.1, 0.01);
let section = angle.build();
let classification = classify_angle_section(§ion, &STEEL_S355);
assert!(classification.overall_class <= SectionClass::Class1);
}
#[test]
fn epsilon_calculation() {
let eps_s235: f64 = (235.0e6_f64 / 235.0e6_f64).sqrt();
assert!((eps_s235 - 1.0).abs() < 1e-6);
let eps_s355: f64 = (235.0e6_f64 / 355.0e6_f64).sqrt();
assert!((eps_s355 - 0.814).abs() < 0.01);
let eps_s460: f64 = (235.0e6_f64 / 460.0e6_f64).sqrt();
assert!((eps_s460 - 0.715).abs() < 0.01);
}
#[test]
fn effective_section_class4() {
let i = ISection::new(0.5, 0.15, 0.003, 0.008, 0.01);
let section = i.build();
let effective =
effective::effective_section(§ion, &STEEL_S355, StressDistribution::pure_bending());
assert!(effective.classification.is_class4);
assert!(effective.area_eff < effective.classification.web_c_t * 0.001); assert!(effective.reduction_factors.web_rho < 1.0);
}
#[test]
fn class_hierarchy() {
assert!(SectionClass::Class1 > SectionClass::Class2);
assert!(SectionClass::Class2 > SectionClass::Class3);
assert!(SectionClass::Class3 > SectionClass::Class4);
assert!(SectionClass::Class1.can_plastic_moment());
assert!(SectionClass::Class2.can_plastic_moment());
assert!(!SectionClass::Class3.can_plastic_moment());
assert!(!SectionClass::Class4.can_plastic_moment());
assert!(SectionClass::Class1.can_plastic_rotation());
assert!(!SectionClass::Class2.can_plastic_rotation());
}
#[test]
fn stress_distribution_variants() {
let bending = StressDistribution::pure_bending();
let compression = StressDistribution::pure_compression();
let _web_bc = StressDistribution::web_bending_compression(0.5);
let _flange_bc = StressDistribution::flange_bending_compression(-0.5);
assert_eq!(bending, StressDistribution::Bending);
assert_eq!(compression, StressDistribution::UniformCompression);
}
#[test]
fn web_bending_compression_limits_pure_compression() {
let eps = 1.0;
let bc = web_limits(eps, StressDistribution::web_bending_compression(1.0));
let uc = web_limits(eps, StressDistribution::pure_compression());
assert!((bc.class1 - uc.class1).abs() < 1e-10);
assert!((bc.class2 - uc.class2).abs() < 1e-10);
assert!((bc.class3 - uc.class3).abs() < 1e-10);
}
#[test]
fn web_bending_compression_limits_pure_bending() {
let eps = 1.0;
let bc = web_limits(eps, StressDistribution::web_bending_compression(0.5));
let bending = web_limits(eps, StressDistribution::pure_bending());
assert!((bc.class1 - bending.class1).abs() < 1e-10);
assert!((bc.class2 - bending.class2).abs() < 1e-10);
assert!((bc.class3 - bending.class3).abs() < 1.0); }
#[test]
fn web_bending_compression_limits_intermediate() {
let eps = 1.0;
let bc = web_limits(eps, StressDistribution::web_bending_compression(0.75));
assert!((bc.class1 - 396.0 / 8.75).abs() < 1e-10);
assert!((bc.class2 - 456.0 / 8.75).abs() < 1e-10);
assert!((bc.class3 - 42.0 / 0.67).abs() < 1e-10);
}
#[test]
fn web_bending_compression_limits_zero_alpha() {
let eps = 1.0;
let bc = web_limits(eps, StressDistribution::web_bending_compression(0.0));
assert_eq!(bc.class1, f64::MAX);
assert_eq!(bc.class2, f64::MAX);
}
}