1use crate::geometry::Point;
7use crate::material::Material;
8use crate::section::Section;
9use crate::section_properties::SectionProperties;
10
11#[derive(Debug, Clone)]
13pub struct PlasticSection {
14 pub section: Section,
15 pub material: Material,
16 pub n_fibers: usize,
18}
19
20impl PlasticSection {
21 pub fn new(section: Section, material: Material) -> Self {
23 Self {
24 section,
25 material,
26 n_fibers: 1000,
27 }
28 }
29
30 pub fn with_fibers(mut self, n: usize) -> Self {
32 self.n_fibers = n.max(100);
33 self
34 }
35
36 pub fn plastic_properties(&self, axis: PlasticAxis) -> PlasticProperties {
38 let fy = self.material.yield_strength;
39 let pna = self.find_plastic_neutral_axis(axis, fy);
40
41 let (z_pl, s_pl) = self.plastic_modulus_about_axis(axis, &pna, fy);
42
43 PlasticProperties {
44 axis,
45 plastic_neutral_axis: pna,
46 plastic_section_modulus: z_pl,
47 plastic_moment_capacity: s_pl,
48 yield_moment: self.yield_moment(axis),
49 }
50 }
51
52 pub fn find_plastic_neutral_axis(&self, axis: PlasticAxis, _fy: f64) -> PlasticNeutralAxis {
57 let (min_coord, max_coord) = self.section_bounds(axis);
58
59 let total_area = self.section.area();
60 let target_area = total_area / 2.0;
61
62 let mut low = min_coord;
64 let mut high = max_coord;
65 let mut pna_pos = (low + high) / 2.0;
66
67 for _ in 0..80 {
68 pna_pos = (low + high) / 2.0;
69 let area_above = exact::exact_area_on_side(&self.section, axis, pna_pos, true);
70
71 if area_above > target_area {
72 low = pna_pos;
73 } else {
74 high = pna_pos;
75 }
76
77 if (high - low).abs() < 1e-12 {
78 break;
79 }
80 }
81
82 PlasticNeutralAxis {
83 position: pna_pos,
84 axis,
85 area_above: exact::exact_area_on_side(&self.section, axis, pna_pos, true),
86 area_below: exact::exact_area_on_side(&self.section, axis, pna_pos, false),
87 }
88 }
89
90 fn plastic_modulus_about_axis(
94 &self,
95 axis: PlasticAxis,
96 pna: &PlasticNeutralAxis,
97 fy: f64,
98 ) -> (f64, f64) {
99 let z_pl = exact::exact_plastic_modulus(&self.section, axis, pna.position);
100 let s_pl = z_pl * fy;
101 (z_pl, s_pl)
102 }
103
104 fn yield_moment(&self, axis: PlasticAxis) -> f64 {
106 let props = SectionProperties::from_section(&self.section);
107 let (ix, _iy) = match axis {
108 PlasticAxis::X => (props.ix, props.iy),
109 PlasticAxis::Y => (props.iy, props.ix),
110 };
111 let fy = self.material.yield_strength;
112
113 let (cx, cy) = (props.centroid.x, props.centroid.y);
115 let max_dist_outer = match axis {
116 PlasticAxis::X => self
117 .section
118 .outer
119 .vertices
120 .iter()
121 .map(|v| (v.y - cy).abs())
122 .fold(0.0, f64::max),
123 PlasticAxis::Y => self
124 .section
125 .outer
126 .vertices
127 .iter()
128 .map(|v| (v.x - cx).abs())
129 .fold(0.0, f64::max),
130 };
131 let max_dist_holes = self
132 .section
133 .holes
134 .iter()
135 .flat_map(|h| h.vertices.iter())
136 .map(|v| match axis {
137 PlasticAxis::X => (v.y - cy).abs(),
138 PlasticAxis::Y => (v.x - cx).abs(),
139 })
140 .fold(0.0, f64::max);
141 let max_dist = max_dist_outer.max(max_dist_holes);
142
143 let z_el = ix / max_dist;
144
145 z_el * fy
146 }
147
148 pub(crate) fn section_bounds(&self, axis: PlasticAxis) -> (f64, f64) {
150 let mut min_v = f64::INFINITY;
151 let mut max_v = f64::NEG_INFINITY;
152
153 for v in &self.section.outer.vertices {
154 let coord = match axis {
155 PlasticAxis::X => v.y,
156 PlasticAxis::Y => v.x,
157 };
158 min_v = min_v.min(coord);
159 max_v = max_v.max(coord);
160 }
161
162 for hole in &self.section.holes {
163 for v in &hole.vertices {
164 let coord = match axis {
165 PlasticAxis::X => v.y,
166 PlasticAxis::Y => v.x,
167 };
168 min_v = min_v.min(coord);
169 max_v = max_v.max(coord);
170 }
171 }
172
173 (min_v, max_v)
174 }
175
176 pub fn area_on_side(&self, axis: PlasticAxis, position: f64, above: bool) -> f64 {
178 let n = 200;
180 let (min_c, max_c) = self.section_bounds(axis);
181 let (min_o, max_o) = self.section_bounds(axis.orthogonal());
182
183 let dc = (max_c - min_c) / n as f64;
184 let do_ = (max_o - min_o) / n as f64;
185
186 let mut area = 0.0;
187
188 for i in 0..n {
189 for j in 0..n {
190 let c = min_c + (i as f64 + 0.5) * dc;
191 let o = min_o + (j as f64 + 0.5) * do_;
192
193 let point = match axis {
194 PlasticAxis::X => Point::new(o, c),
195 PlasticAxis::Y => Point::new(c, o),
196 };
197
198 if self.section.contains_point(point) {
199 let on_side = match axis {
200 PlasticAxis::X => c > position,
201 PlasticAxis::Y => c > position,
202 };
203
204 if on_side == above {
205 area += dc * do_;
206 }
207 }
208 }
209 }
210
211 area
212 }
213
214 pub fn full_plastic_properties(&self) -> FullPlasticProperties {
220 let props_x = self.plastic_properties(PlasticAxis::X);
221 let props_y = self.plastic_properties(PlasticAxis::Y);
222
223 let shape_factor_x =
224 props_x.plastic_section_modulus / (props_x.yield_moment / self.material.yield_strength);
225 let shape_factor_y =
226 props_y.plastic_section_modulus / (props_y.yield_moment / self.material.yield_strength);
227
228 let sect_props = SectionProperties::from_section(&self.section);
230 let principal = sect_props.principal_properties();
231 let phi = principal.phi;
232
233 let (props_11, props_22, sf_11, sf_22) = if phi.abs() < 1e-10 {
234 (props_x, props_y, shape_factor_x, shape_factor_y)
236 } else {
237 let rotated_outer = self.section.outer.rotate(-phi);
239 let rotated_holes: Vec<_> = self.section.holes.iter().map(|h| h.rotate(-phi)).collect();
240 let rotated_section = Section::new(rotated_outer, rotated_holes);
241 let rotated_plastic =
242 PlasticSection::new(rotated_section, self.material).with_fibers(self.n_fibers);
243
244 let p11 = rotated_plastic.plastic_properties(PlasticAxis::X);
245 let p22 = rotated_plastic.plastic_properties(PlasticAxis::Y);
246 let sf11 =
247 p11.plastic_section_modulus / (p11.yield_moment / self.material.yield_strength);
248 let sf22 =
249 p22.plastic_section_modulus / (p22.yield_moment / self.material.yield_strength);
250 (p11, p22, sf11, sf22)
251 };
252
253 let my_xx = props_x.yield_moment;
255 let my_yy = props_y.yield_moment;
256 let my_11 = props_11.yield_moment;
257 let my_22 = props_22.yield_moment;
258
259 let sxx = props_x.plastic_section_modulus;
261 let syy = props_y.plastic_section_modulus;
262 let s11 = props_11.plastic_section_modulus;
263 let s22 = props_22.plastic_section_modulus;
264 let sf_xx_plus = if sect_props.zxx_plus > 1e-15 {
265 sxx / sect_props.zxx_plus
266 } else {
267 0.0
268 };
269 let sf_xx_minus = if sect_props.zxx_minus > 1e-15 {
270 sxx / sect_props.zxx_minus
271 } else {
272 0.0
273 };
274 let sf_yy_plus = if sect_props.zyy_plus > 1e-15 {
275 syy / sect_props.zyy_plus
276 } else {
277 0.0
278 };
279 let sf_yy_minus = if sect_props.zyy_minus > 1e-15 {
280 syy / sect_props.zyy_minus
281 } else {
282 0.0
283 };
284 let sf_11_plus = if sect_props.principal.z11_plus > 1e-15 {
285 s11 / sect_props.principal.z11_plus
286 } else {
287 0.0
288 };
289 let sf_11_minus = if sect_props.principal.z11_minus > 1e-15 {
290 s11 / sect_props.principal.z11_minus
291 } else {
292 0.0
293 };
294 let sf_22_plus = if sect_props.principal.z22_plus > 1e-15 {
295 s22 / sect_props.principal.z22_plus
296 } else {
297 0.0
298 };
299 let sf_22_minus = if sect_props.principal.z22_minus > 1e-15 {
300 s22 / sect_props.principal.z22_minus
301 } else {
302 0.0
303 };
304
305 FullPlasticProperties {
306 x_axis: props_x,
307 y_axis: props_y,
308 shape_factor_x,
309 shape_factor_y,
310 principal_11: props_11,
311 principal_22: props_22,
312 shape_factor_11: sf_11,
313 shape_factor_22: sf_22,
314 principal_angle: phi,
315 plastic_centroid_x: props_y.plastic_neutral_axis.position,
316 plastic_centroid_y: props_x.plastic_neutral_axis.position,
317 plastic_centroid_11: props_11.plastic_neutral_axis.position,
318 plastic_centroid_22: props_22.plastic_neutral_axis.position,
319 my_xx,
320 my_yy,
321 my_11,
322 my_22,
323 sf_xx_plus,
324 sf_xx_minus,
325 sf_yy_plus,
326 sf_yy_minus,
327 sf_11_plus,
328 sf_11_minus,
329 sf_22_plus,
330 sf_22_minus,
331 }
332 }
333}
334
335#[derive(Debug, Clone, Copy, PartialEq, Eq)]
337pub enum PlasticAxis {
338 X, Y, }
341
342impl PlasticAxis {
343 pub fn orthogonal(&self) -> Self {
344 match self {
345 PlasticAxis::X => PlasticAxis::Y,
346 PlasticAxis::Y => PlasticAxis::X,
347 }
348 }
349}
350
351#[derive(Debug, Clone, Copy)]
353pub struct PlasticNeutralAxis {
354 pub position: f64, pub axis: PlasticAxis,
356 pub area_above: f64,
357 pub area_below: f64,
358}
359
360#[derive(Debug, Clone, Copy)]
362pub struct PlasticProperties {
363 pub axis: PlasticAxis,
364 pub plastic_neutral_axis: PlasticNeutralAxis,
365 pub plastic_section_modulus: f64, pub plastic_moment_capacity: f64, pub yield_moment: f64, }
369
370#[derive(Debug, Clone)]
372pub struct FullPlasticProperties {
373 pub x_axis: PlasticProperties,
374 pub y_axis: PlasticProperties,
375 pub shape_factor_x: f64, pub shape_factor_y: f64,
377 pub principal_11: PlasticProperties,
379 pub principal_22: PlasticProperties,
381 pub shape_factor_11: f64,
383 pub shape_factor_22: f64,
385 pub principal_angle: f64,
387 pub plastic_centroid_x: f64,
389 pub plastic_centroid_y: f64,
391 pub plastic_centroid_11: f64,
393 pub plastic_centroid_22: f64,
395 pub my_xx: f64,
397 pub my_yy: f64,
399 pub my_11: f64,
401 pub my_22: f64,
403 pub sf_xx_plus: f64,
405 pub sf_xx_minus: f64,
407 pub sf_yy_plus: f64,
409 pub sf_yy_minus: f64,
411 pub sf_11_plus: f64,
413 pub sf_11_minus: f64,
415 pub sf_22_plus: f64,
417 pub sf_22_minus: f64,
419}
420
421impl FullPlasticProperties {
422 pub fn shape_factor(&self, axis: PlasticAxis) -> f64 {
424 match axis {
425 PlasticAxis::X => self.shape_factor_x,
426 PlasticAxis::Y => self.shape_factor_y,
427 }
428 }
429
430 pub fn shape_factor_principal(&self, axis: PlasticAxis) -> f64 {
432 match axis {
433 PlasticAxis::X => self.shape_factor_11,
434 PlasticAxis::Y => self.shape_factor_22,
435 }
436 }
437
438 pub fn plastic_moment(&self, axis: PlasticAxis) -> f64 {
440 match axis {
441 PlasticAxis::X => self.x_axis.plastic_moment_capacity,
442 PlasticAxis::Y => self.y_axis.plastic_moment_capacity,
443 }
444 }
445
446 pub fn plastic_moment_principal(&self, axis: PlasticAxis) -> f64 {
448 match axis {
449 PlasticAxis::X => self.principal_11.plastic_moment_capacity,
450 PlasticAxis::Y => self.principal_22.plastic_moment_capacity,
451 }
452 }
453}
454
455pub mod exact {
457 use super::*;
458 use crate::geometry::{Point, Polygon};
459
460 pub fn exact_area_on_side(
462 section: &Section,
463 axis: PlasticAxis,
464 pna_pos: f64,
465 above: bool,
466 ) -> f64 {
467 let mut area = 0.0;
468 if let Some(outer_part) = clip_polygon_halfspace(§ion.outer, axis, pna_pos, above) {
469 area += outer_part.area();
470 }
471 for hole in §ion.holes {
472 if let Some(hole_part) = clip_polygon_halfspace(hole, axis, pna_pos, above) {
473 area -= hole_part.area();
474 }
475 }
476 area
477 }
478
479 pub fn exact_plastic_modulus(section: &Section, axis: PlasticAxis, pna_pos: f64) -> f64 {
485 let (above, below) = clip_section_at_pna(section, axis, pna_pos);
486
487 let mut z_pl = 0.0;
488
489 for part in [above, below].into_iter().flatten() {
490 let area = part.area();
491 if area.abs() < 1e-15 {
492 continue;
493 }
494 let centroid = part.centroid();
495 let lever = match axis {
496 PlasticAxis::X => (centroid.y - pna_pos).abs(),
497 PlasticAxis::Y => (centroid.x - pna_pos).abs(),
498 };
499 z_pl += lever * area;
500 }
501
502 for hole in §ion.holes {
503 for above in [true, false].into_iter() {
504 if let Some(hp) = clip_polygon_halfspace(hole, axis, pna_pos, above) {
505 let area = hp.area();
506 if area.abs() < 1e-15 {
507 continue;
508 }
509 let centroid = hp.centroid();
510 let lever = match axis {
511 PlasticAxis::X => (centroid.y - pna_pos).abs(),
512 PlasticAxis::Y => (centroid.x - pna_pos).abs(),
513 };
514 z_pl -= lever * area;
515 }
516 }
517 }
518
519 z_pl
520 }
521
522 pub fn clip_section_at_pna(
528 section: &Section,
529 axis: PlasticAxis,
530 pna_pos: f64,
531 ) -> (Option<Polygon>, Option<Polygon>) {
532 let above = clip_polygon_halfspace(§ion.outer, axis, pna_pos, true)
533 .map(|p| subtract_holes(p, §ion.holes, axis, pna_pos, true));
534 let below = clip_polygon_halfspace(§ion.outer, axis, pna_pos, false)
535 .map(|p| subtract_holes(p, §ion.holes, axis, pna_pos, false));
536
537 (above, below)
538 }
539
540 fn clip_polygon_halfspace(
543 poly: &Polygon,
544 axis: PlasticAxis,
545 pna_pos: f64,
546 above: bool,
547 ) -> Option<Polygon> {
548 let input = &poly.vertices;
549 if input.len() < 3 {
550 return None;
551 }
552
553 let is_inside = |p: &Point| -> bool {
554 match axis {
555 PlasticAxis::X => {
556 if above {
557 p.y >= pna_pos
558 } else {
559 p.y <= pna_pos
560 }
561 }
562 PlasticAxis::Y => {
563 if above {
564 p.x >= pna_pos
565 } else {
566 p.x <= pna_pos
567 }
568 }
569 }
570 };
571
572 let intersect = |p1: &Point, p2: &Point| -> Point {
573 match axis {
574 PlasticAxis::X => {
575 let dy = p2.y - p1.y;
576 if dy.abs() < 1e-15 {
577 Point::new(p1.x, pna_pos)
578 } else {
579 let t = (pna_pos - p1.y) / dy;
580 Point::new(p1.x + t * (p2.x - p1.x), pna_pos)
581 }
582 }
583 PlasticAxis::Y => {
584 let dx = p2.x - p1.x;
585 if dx.abs() < 1e-15 {
586 Point::new(pna_pos, p1.y)
587 } else {
588 let t = (pna_pos - p1.x) / dx;
589 Point::new(pna_pos, p1.y + t * (p2.y - p1.y))
590 }
591 }
592 }
593 };
594
595 let mut output = Vec::new();
596 let n = input.len();
597 let mut prev = input[n - 1];
598 let mut prev_in = is_inside(&prev);
599
600 for i in 0..n {
601 let curr = input[i];
602 let curr_in = is_inside(&curr);
603
604 if curr_in {
605 if !prev_in {
606 output.push(intersect(&prev, &curr));
607 }
608 output.push(curr);
609 } else if prev_in {
610 output.push(intersect(&prev, &curr));
611 }
612
613 prev = curr;
614 prev_in = curr_in;
615 }
616
617 output = deduplicate_vertices(&output);
619
620 if output.len() < 3 {
621 None
622 } else {
623 Some(Polygon::new(output))
624 }
625 }
626
627 fn deduplicate_vertices(verts: &[Point]) -> Vec<Point> {
629 if verts.is_empty() {
630 return Vec::new();
631 }
632 let mut result = Vec::with_capacity(verts.len());
633 let tol = 1e-12;
634 for v in verts {
635 let is_dup = result.last().map_or(false, |last: &Point| {
636 (last.x - v.x).abs() < tol && (last.y - v.y).abs() < tol
637 });
638 if !is_dup {
639 result.push(*v);
640 }
641 }
642 if result.len() > 1 {
644 let first = result[0];
645 let last = result[result.len() - 1];
646 if (first.x - last.x).abs() < tol && (first.y - last.y).abs() < tol {
647 result.pop();
648 }
649 }
650 result
651 }
652
653 fn subtract_holes(
659 outer: Polygon,
660 _holes: &[Polygon],
661 _axis: PlasticAxis,
662 _pna_pos: f64,
663 _above: bool,
664 ) -> Polygon {
665 outer
670 }
671}
672
673#[cfg(test)]
674mod tests {
675 use super::*;
676 use crate::geometry::{Point, Polygon};
677 use crate::material::presets::STEEL_S355;
678 use crate::section::Section;
679 use crate::section_library::ParametricSection;
680
681 #[test]
682 fn plastic_rectangular() {
683 let poly = Polygon::new(vec![
685 Point::new(-0.1, -0.05),
686 Point::new(0.1, -0.05),
687 Point::new(0.1, 0.05),
688 Point::new(-0.1, 0.05),
689 ]);
690 let section = Section::new(poly, vec![]);
691 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
692
693 let props_x = plastic.plastic_properties(PlasticAxis::X);
694 let props_y = plastic.plastic_properties(PlasticAxis::Y);
695
696 let expected_zx = 0.2 * 0.1_f64.powi(2) / 4.0; let expected_zy = 0.1 * 0.2_f64.powi(2) / 4.0; assert!((props_x.plastic_section_modulus - expected_zx).abs() / expected_zx < 0.05);
701 assert!((props_y.plastic_section_modulus - expected_zy).abs() / expected_zy < 0.05);
702
703 assert!(
705 (props_x.plastic_section_modulus / (props_x.yield_moment / STEEL_S355.yield_strength)
706 - 1.5)
707 .abs()
708 < 0.05
709 );
710 }
711
712 #[test]
713 fn plastic_circular() {
714 let poly = crate::section_library::circle_polygon(0.05, 64);
716 let section = Section::new(poly, vec![]);
717 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
718
719 let props = plastic.plastic_properties(PlasticAxis::X);
720
721 let r: f64 = 0.05;
723 let expected_z = 4.0 * r.powi(3) / 3.0;
724
725 assert!((props.plastic_section_modulus - expected_z).abs() / expected_z < 0.05);
726
727 let shape =
729 props.plastic_section_modulus / (props.yield_moment / STEEL_S355.yield_strength);
730 assert!((shape - 16.0 / (3.0 * std::f64::consts::PI)).abs() < 0.05);
731 }
732
733 #[test]
734 fn plastic_i_section() {
735 let i = crate::section_library::steel::ISection::new(0.3, 0.15, 0.007, 0.01, 0.012);
737 let section = i.build();
738 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
739
740 let full = plastic.full_plastic_properties();
741
742 assert!(full.shape_factor_x > 1.05 && full.shape_factor_x < 1.3);
744 assert!(full.shape_factor_y > 1.1 && full.shape_factor_y < 1.6);
745
746 assert!(full.x_axis.plastic_moment_capacity > full.x_axis.yield_moment);
748 assert!(full.y_axis.plastic_moment_capacity > full.y_axis.yield_moment);
749 }
750
751 #[test]
752 fn plastic_principal_axes_symmetric() {
753 let poly = Polygon::new(vec![
755 Point::new(-0.1, -0.05),
756 Point::new(0.1, -0.05),
757 Point::new(0.1, 0.05),
758 Point::new(-0.1, 0.05),
759 ]);
760 let section = Section::new(poly, vec![]);
761 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
762
763 let full = plastic.full_plastic_properties();
764
765 let angle_norm = full.principal_angle.rem_euclid(std::f64::consts::FRAC_PI_2);
767 assert!(angle_norm < 1e-6 || (angle_norm - std::f64::consts::FRAC_PI_2).abs() < 1e-6);
768
769 let p11 = full.principal_11.plastic_section_modulus;
771 let p22 = full.principal_22.plastic_section_modulus;
772 let sx = full.x_axis.plastic_section_modulus;
773 let sy = full.y_axis.plastic_section_modulus;
774
775 let match_a = (p11 - sx).abs() / sx < 0.02 && (p22 - sy).abs() / sy < 0.02;
777 let match_b = (p11 - sy).abs() / sy < 0.02 && (p22 - sx).abs() / sx < 0.02;
778 assert!(match_a || match_b);
779 }
780
781 #[test]
782 fn plastic_principal_axes_angle_section() {
783 let angle = crate::section_library::steel::AngleSection::new(0.1, 0.075, 0.008, 0.0, 0.0);
785 let section = angle.build();
786 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
787
788 let full = plastic.full_plastic_properties();
789
790 assert!(full.principal_angle.abs() > 1e-4);
792
793 assert!(full.principal_11.plastic_moment_capacity > 0.0);
795 assert!(full.principal_22.plastic_moment_capacity > 0.0);
796
797 assert!(full.shape_factor_11 > 1.0);
799 assert!(full.shape_factor_22 > 1.0);
800 }
801
802 #[test]
803 fn plastic_principal_axes_channel() {
804 let channel =
806 crate::section_library::steel::ChannelSection::new(0.2, 0.1, 0.008, 0.008, 0.0, 0.0);
807 let section = channel.build();
808 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
809
810 let full = plastic.full_plastic_properties();
811
812 assert!(full.principal_angle.abs() < 1e-4);
814
815 let ratio_11 =
817 full.principal_11.plastic_section_modulus / full.x_axis.plastic_section_modulus;
818 assert!((ratio_11 - 1.0).abs() < 0.02);
819 }
820
821 #[test]
822 fn exact_plastic_rectangular() {
823 let poly = Polygon::new(vec![
825 Point::new(-0.1, -0.05),
826 Point::new(0.1, -0.05),
827 Point::new(0.1, 0.05),
828 Point::new(-0.1, 0.05),
829 ]);
830 let section = Section::new(poly, vec![]);
831
832 let z_pl = exact::exact_plastic_modulus(§ion, PlasticAxis::X, 0.0);
834
835 let expected = 0.2 * 0.1_f64.powi(2) / 4.0;
837 assert!((z_pl - expected).abs() / expected < 0.01);
838 }
839
840 #[test]
841 fn exact_plastic_rectangular_y_axis() {
842 let poly = Polygon::new(vec![
844 Point::new(-0.1, -0.05),
845 Point::new(0.1, -0.05),
846 Point::new(0.1, 0.05),
847 Point::new(-0.1, 0.05),
848 ]);
849 let section = Section::new(poly, vec![]);
850
851 let z_pl = exact::exact_plastic_modulus(§ion, PlasticAxis::Y, 0.0);
853
854 let expected = 0.1 * 0.2_f64.powi(2) / 4.0;
856 assert!((z_pl - expected).abs() / expected < 0.01);
857 }
858
859 #[test]
860 fn exact_plastic_i_section() {
861 let i = crate::section_library::steel::ISection::new(0.3, 0.15, 0.007, 0.01, 0.012);
863 let section = i.build();
864
865 let props = SectionProperties::from_section(§ion);
867 let z_pl = exact::exact_plastic_modulus(§ion, PlasticAxis::X, props.centroid.y);
868
869 assert!(z_pl > 0.0);
871
872 let plastic = PlasticSection::new(section.clone(), STEEL_S355).with_fibers(500);
874 let fiber_props = plastic.plastic_properties(PlasticAxis::X);
875 let fiber_z = fiber_props.plastic_section_modulus;
876
877 assert!((z_pl - fiber_z).abs() / fiber_z < 0.05);
879 }
880
881 #[test]
882 fn exact_plastic_clip_geometry() {
883 let poly = Polygon::new(vec![
885 Point::new(-0.1, -0.05),
886 Point::new(0.1, -0.05),
887 Point::new(0.1, 0.05),
888 Point::new(-0.1, 0.05),
889 ]);
890 let section = Section::new(poly, vec![]);
891
892 let (above, below) = exact::clip_section_at_pna(§ion, PlasticAxis::X, 0.0);
893
894 assert!(above.is_some());
895 assert!(below.is_some());
896
897 let above_poly = above.unwrap();
898 let below_poly = below.unwrap();
899
900 let half_area = 0.2 * 0.1 / 2.0;
902 assert!((above_poly.area() - half_area).abs() / half_area < 0.01);
903 assert!((below_poly.area() - half_area).abs() / half_area < 0.01);
904 }
905
906 #[test]
907 fn exact_plastic_hollow_rectangular() {
908 let b = 0.2;
909 let h = 0.1;
910 let t = 0.01;
911 let outer = Polygon::new(vec![
912 Point::new(-b / 2.0, -h / 2.0),
913 Point::new(b / 2.0, -h / 2.0),
914 Point::new(b / 2.0, h / 2.0),
915 Point::new(-b / 2.0, h / 2.0),
916 ]);
917 let inner = Polygon::new(vec![
918 Point::new(-(b - 2.0 * t) / 2.0, -(h - 2.0 * t) / 2.0),
919 Point::new((b - 2.0 * t) / 2.0, -(h - 2.0 * t) / 2.0),
920 Point::new((b - 2.0 * t) / 2.0, (h - 2.0 * t) / 2.0),
921 Point::new(-(b - 2.0 * t) / 2.0, (h - 2.0 * t) / 2.0),
922 ]);
923 let section = Section::new(outer, vec![inner]);
924
925 let z_pl = exact::exact_plastic_modulus(§ion, PlasticAxis::X, 0.0);
926
927 let z_outer = b * h * h / 4.0;
928 let z_inner = (b - 2.0 * t) * (h - 2.0 * t).powi(2) / 4.0;
929 let expected = z_outer - z_inner;
930
931 assert!(
932 (z_pl - expected).abs() / expected < 0.01,
933 "Hollow rectangular Z_pl: got {}, expected {}",
934 z_pl,
935 expected
936 );
937 }
938
939 #[test]
940 fn plastic_centroid_symmetric_section() {
941 let poly = Polygon::new(vec![
943 Point::new(-0.05, -0.05),
944 Point::new(0.05, -0.05),
945 Point::new(0.05, 0.05),
946 Point::new(-0.05, 0.05),
947 ]);
948 let section = Section::new(poly, vec![]);
949 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
950
951 let full = plastic.full_plastic_properties();
952 assert!(full.plastic_centroid_x.abs() < 1e-3);
954 assert!(full.plastic_centroid_y.abs() < 1e-3);
955 }
956
957 #[test]
958 fn plastic_centroid_tee_section() {
959 let poly = Polygon::new(vec![
962 Point::new(-0.1, 0.10),
963 Point::new(0.1, 0.10),
964 Point::new(0.1, 0.08),
965 Point::new(0.01, 0.08),
966 Point::new(0.01, 0.0),
967 Point::new(-0.01, 0.0),
968 Point::new(-0.01, 0.08),
969 Point::new(-0.1, 0.08),
970 ]);
971 let section = Section::new(poly, vec![]);
972 let _props = SectionProperties::from_section(§ion);
973 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
974
975 let full = plastic.full_plastic_properties();
976
977 let area = 0.0056_f64;
979 let yc = (0.004 * 0.09 + 0.0016 * 0.04) / area;
980
981 let y_pc_expected = 0.086_f64;
984
985 assert!(
986 (full.plastic_centroid_y - y_pc_expected).abs() < 0.005,
987 "plastic_centroid_y = {}, expected ~{}",
988 full.plastic_centroid_y,
989 y_pc_expected
990 );
991 assert!(
992 (full.plastic_centroid_y - yc).abs() > 0.005,
993 "plastic centroid should differ from geometric centroid for T-section"
994 );
995
996 assert!(full.plastic_centroid_x.abs() < 0.005);
998 }
999
1000 #[test]
1001 fn plastic_centroid_principal_axes() {
1002 let poly = Polygon::new(vec![
1004 Point::new(-0.05, -0.05),
1005 Point::new(0.05, -0.05),
1006 Point::new(0.05, 0.05),
1007 Point::new(-0.05, 0.05),
1008 ]);
1009 let section = Section::new(poly, vec![]);
1010 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
1011
1012 let full = plastic.full_plastic_properties();
1013 assert!(full.plastic_centroid_11.abs() < 1e-3);
1014 assert!(full.plastic_centroid_22.abs() < 1e-3);
1015 }
1016
1017 #[test]
1018 fn yield_moments_match_plastic_properties() {
1019 let poly = Polygon::new(vec![
1020 Point::new(-0.05, -0.05),
1021 Point::new(0.05, -0.05),
1022 Point::new(0.05, 0.05),
1023 Point::new(-0.05, 0.05),
1024 ]);
1025 let section = Section::new(poly, vec![]);
1026 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
1027
1028 let full = plastic.full_plastic_properties();
1029
1030 assert!((full.my_xx - full.x_axis.yield_moment).abs() < 1e-6);
1032 assert!((full.my_yy - full.y_axis.yield_moment).abs() < 1e-6);
1033 assert!((full.my_11 - full.principal_11.yield_moment).abs() < 1e-6);
1034 assert!((full.my_22 - full.principal_22.yield_moment).abs() < 1e-6);
1035
1036 let b = 0.1_f64;
1038 let h = 0.1_f64;
1039 let fy = STEEL_S355.yield_strength;
1040 let z_el = b * h.powi(2) / 6.0;
1041 let my_expected = z_el * fy;
1042 assert!((full.my_xx - my_expected).abs() / my_expected < 0.02);
1043 }
1044
1045 #[test]
1046 fn shape_factors_plus_minus_rectangular() {
1047 let poly = Polygon::new(vec![
1049 Point::new(-0.05, -0.05),
1050 Point::new(0.05, -0.05),
1051 Point::new(0.05, 0.05),
1052 Point::new(-0.05, 0.05),
1053 ]);
1054 let section = Section::new(poly, vec![]);
1055 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
1056
1057 let full = plastic.full_plastic_properties();
1058
1059 assert!((full.sf_xx_plus - 1.5).abs() < 0.05);
1061 assert!((full.sf_xx_minus - 1.5).abs() < 0.05);
1062 assert!((full.sf_yy_plus - 1.5).abs() < 0.05);
1063 assert!((full.sf_yy_minus - 1.5).abs() < 0.05);
1064 }
1065
1066 #[test]
1067 fn shape_factors_plus_minus_tee_section() {
1068 let poly = Polygon::new(vec![
1070 Point::new(-0.1, 0.10),
1071 Point::new(0.1, 0.10),
1072 Point::new(0.1, 0.08),
1073 Point::new(0.01, 0.08),
1074 Point::new(0.01, 0.0),
1075 Point::new(-0.01, 0.0),
1076 Point::new(-0.01, 0.08),
1077 Point::new(-0.1, 0.08),
1078 ]);
1079 let section = Section::new(poly, vec![]);
1080 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
1081
1082 let full = plastic.full_plastic_properties();
1083
1084 assert!(full.sf_xx_plus > 0.0);
1086 assert!(full.sf_xx_minus > 0.0);
1087 assert!((full.sf_xx_plus - full.sf_xx_minus).abs() > 0.01);
1089 assert!(full.sf_xx_minus > 1.0);
1091 }
1092
1093 #[test]
1094 fn yield_moment_hollow_section() {
1095 let outer = Polygon::new(vec![
1098 Point::new(-0.1, -0.05),
1099 Point::new(0.1, -0.05),
1100 Point::new(0.1, 0.05),
1101 Point::new(-0.1, 0.05),
1102 ]);
1103 let inner = Polygon::new(vec![
1104 Point::new(-0.08, -0.03),
1105 Point::new(0.08, -0.03),
1106 Point::new(0.08, 0.03),
1107 Point::new(-0.08, 0.03),
1108 ]);
1109 let section = Section::new(outer, vec![inner]);
1110 let plastic = PlasticSection::new(section, STEEL_S355).with_fibers(500);
1111
1112 let props = plastic.plastic_properties(PlasticAxis::X);
1113
1114 assert!(props.yield_moment > 0.0);
1119
1120 let sf = props.plastic_section_modulus / (props.yield_moment / STEEL_S355.yield_strength);
1122 assert!(sf > 1.0 && sf < 1.5);
1123 }
1124}