Skip to main content

section_properties/section_library/
concrete.rs

1//! Concrete sections (EN 1992, ACI 318, etc.)
2
3use crate::geometry::{Point, Polygon};
4use crate::material::Material;
5use crate::section::Section;
6use crate::section_library::{
7    ParametricSection, circle_polygon, rectangle_polygon, rounded_rectangle_polygon,
8};
9use std::f64::consts::PI;
10
11/// Rectangular concrete section.
12#[derive(Debug, Clone, Copy, PartialEq)]
13pub struct RectangularConcreteSection {
14    pub width: f64,  // b
15    pub height: f64, // h
16}
17
18impl RectangularConcreteSection {
19    pub fn new(width: f64, height: f64) -> Self {
20        assert!(width > 0.0 && height > 0.0, "Dimensions must be positive");
21        Self { width, height }
22    }
23}
24
25impl ParametricSection for RectangularConcreteSection {
26    fn build(&self) -> Section {
27        Section::new(rectangle_polygon(self.width, self.height), Vec::new())
28    }
29
30    fn designation(&self) -> String {
31        format!(
32            "CONC RECT {:.0}x{:.0}",
33            self.width * 1000.0,
34            self.height * 1000.0
35        )
36    }
37}
38
39/// Circular concrete section.
40#[derive(Debug, Clone, Copy, PartialEq)]
41pub struct CircularConcreteSection {
42    pub diameter: f64,
43    pub n_vertices: usize,
44}
45
46impl CircularConcreteSection {
47    pub fn new(diameter: f64) -> Self {
48        Self::with_vertices(diameter, 128)
49    }
50
51    pub fn with_vertices(diameter: f64, n_vertices: usize) -> Self {
52        assert!(diameter > 0.0, "Diameter must be positive");
53        assert!(n_vertices >= 8, "At least 8 vertices");
54        Self {
55            diameter,
56            n_vertices,
57        }
58    }
59}
60
61impl ParametricSection for CircularConcreteSection {
62    fn build(&self) -> Section {
63        Section::new(
64            circle_polygon(self.diameter / 2.0, self.n_vertices),
65            Vec::new(),
66        )
67    }
68
69    fn designation(&self) -> String {
70        format!("CONC CIRC Ø{:.0}", self.diameter * 1000.0)
71    }
72}
73
74/// T-beam concrete section (flanged beam).
75#[derive(Debug, Clone, Copy, PartialEq)]
76pub struct TBeamConcreteSection {
77    pub flange_width: f64,     // b_f (effective flange width)
78    pub web_width: f64,        // b_w
79    pub height: f64,           // h
80    pub flange_thickness: f64, // h_f
81}
82
83impl TBeamConcreteSection {
84    pub fn new(flange_width: f64, web_width: f64, height: f64, flange_thickness: f64) -> Self {
85        assert!(flange_width > 0.0 && web_width > 0.0 && height > 0.0 && flange_thickness > 0.0);
86        assert!(
87            web_width <= flange_width,
88            "Web width cannot exceed flange width"
89        );
90        assert!(
91            flange_thickness < height,
92            "Flange thickness must be less than height"
93        );
94        Self {
95            flange_width,
96            web_width,
97            height,
98            flange_thickness,
99        }
100    }
101}
102
103impl ParametricSection for TBeamConcreteSection {
104    fn build(&self) -> Section {
105        let bf = self.flange_width;
106        let bw = self.web_width;
107        let h = self.height;
108        let hf = self.flange_thickness;
109
110        let bf2 = bf / 2.0;
111        let bw2 = bw / 2.0;
112        let hh = h / 2.0;
113
114        let vertices = vec![
115            Point::new(-bw2, -hh),
116            Point::new(bw2, -hh),
117            Point::new(bw2, hh - hf),
118            Point::new(bf2, hh - hf),
119            Point::new(bf2, hh),
120            Point::new(-bf2, hh),
121            Point::new(-bf2, hh - hf),
122            Point::new(-bw2, hh - hf),
123        ];
124
125        Section::new(Polygon::new(vertices), Vec::new())
126    }
127
128    fn designation(&self) -> String {
129        format!(
130            "CONC T {:.0}x{:.0}x{:.0}x{:.0}",
131            self.flange_width * 1000.0,
132            self.web_width * 1000.0,
133            self.height * 1000.0,
134            self.flange_thickness * 1000.0
135        )
136    }
137}
138
139/// L-beam concrete section (edge beam).
140#[derive(Debug, Clone, Copy, PartialEq)]
141pub struct LBeamConcreteSection {
142    pub flange_width: f64,
143    pub web_width: f64,
144    pub height: f64,
145    pub flange_thickness: f64,
146}
147
148impl LBeamConcreteSection {
149    pub fn new(flange_width: f64, web_width: f64, height: f64, flange_thickness: f64) -> Self {
150        assert!(flange_width > 0.0 && web_width > 0.0 && height > 0.0 && flange_thickness > 0.0);
151        assert!(
152            web_width <= flange_width,
153            "Web width cannot exceed flange width"
154        );
155        assert!(
156            flange_thickness < height,
157            "Flange thickness must be less than height"
158        );
159        Self {
160            flange_width,
161            web_width,
162            height,
163            flange_thickness,
164        }
165    }
166}
167
168impl ParametricSection for LBeamConcreteSection {
169    fn build(&self) -> Section {
170        let bf = self.flange_width;
171        let bw = self.web_width;
172        let h = self.height;
173        let hf = self.flange_thickness;
174
175        let hh = h / 2.0;
176
177        let vertices = vec![
178            Point::new(0.0, -hh),
179            Point::new(bw, -hh),
180            Point::new(bw, hh - hf),
181            Point::new(bf, hh - hf),
182            Point::new(bf, hh),
183            Point::new(0.0, hh),
184        ];
185
186        Section::new(Polygon::new(vertices), Vec::new())
187    }
188
189    fn designation(&self) -> String {
190        format!(
191            "CONC L {:.0}x{:.0}x{:.0}x{:.0}",
192            self.flange_width * 1000.0,
193            self.web_width * 1000.0,
194            self.height * 1000.0,
195            self.flange_thickness * 1000.0
196        )
197    }
198}
199
200/// Hollow rectangular concrete section (box girder).
201#[derive(Debug, Clone, Copy, PartialEq)]
202pub struct BoxConcreteSection {
203    pub outer_width: f64,
204    pub outer_height: f64,
205    pub wall_thickness: f64,
206    pub bottom_thickness: f64, // can be different
207    pub top_thickness: f64,
208    pub outer_radius: f64,
209    pub inner_radius: f64,
210}
211
212impl BoxConcreteSection {
213    pub fn new(
214        outer_width: f64,
215        outer_height: f64,
216        wall_thickness: f64,
217        bottom_thickness: f64,
218        top_thickness: f64,
219        outer_radius: f64,
220        inner_radius: f64,
221    ) -> Self {
222        assert!(outer_width > 0.0 && outer_height > 0.0);
223        assert!(wall_thickness > 0.0 && bottom_thickness > 0.0 && top_thickness > 0.0);
224        assert!(2.0 * wall_thickness < outer_width);
225        assert!(top_thickness + bottom_thickness < outer_height);
226        Self {
227            outer_width,
228            outer_height,
229            wall_thickness,
230            bottom_thickness,
231            top_thickness,
232            outer_radius,
233            inner_radius,
234        }
235    }
236
237    pub fn uniform(outer_width: f64, outer_height: f64, thickness: f64) -> Self {
238        Self::new(
239            outer_width,
240            outer_height,
241            thickness,
242            thickness,
243            thickness,
244            0.0,
245            0.0,
246        )
247    }
248}
249
250impl ParametricSection for BoxConcreteSection {
251    fn build(&self) -> Section {
252        let bw = self.outer_width;
253        let bh = self.outer_height;
254        let tw = self.wall_thickness;
255        let tb = self.bottom_thickness;
256        let tt = self.top_thickness;
257        let r_out = self.outer_radius;
258        let r_in = self.inner_radius;
259
260        // Outer polygon
261        let outer = if r_out > 0.0 {
262            rounded_rectangle_polygon(bw, bh, r_out, 8)
263        } else {
264            rectangle_polygon(bw, bh)
265        };
266
267        // Inner polygon (hole)
268        let inner_w = bw - 2.0 * tw;
269        let inner_h = bh - tt - tb;
270        let inner = if r_in > 0.0 {
271            rounded_rectangle_polygon(inner_w, inner_h, r_in, 8)
272        } else {
273            rectangle_polygon(inner_w, inner_h)
274        };
275
276        // Need to center the inner polygon
277        let inner_centered = Polygon::new(
278            inner
279                .vertices
280                .iter()
281                .map(|v| Point::new(v.x, v.y + (tb - tt) / 2.0))
282                .collect(),
283        );
284
285        Section::new(outer, vec![inner_centered])
286    }
287
288    fn designation(&self) -> String {
289        format!(
290            "CONC BOX {:.0}x{:.0} t{:.0}/{:.0}/{:.0}",
291            self.outer_width * 1000.0,
292            self.outer_height * 1000.0,
293            self.wall_thickness * 1000.0,
294            self.bottom_thickness * 1000.0,
295            self.top_thickness * 1000.0
296        )
297    }
298}
299
300/// Concrete section with reinforcement (rebar).
301#[derive(Debug)]
302pub struct ReinforcedConcreteSection {
303    pub concrete_section: Box<dyn ParametricSection>,
304    pub reinforcement: Vec<RebarLayer>,
305}
306
307#[derive(Debug, Clone, Copy, PartialEq)]
308pub struct RebarLayer {
309    pub y: f64,        // Distance from centroid (positive up)
310    pub z: f64,        // Distance from centroid (positive right)
311    pub diameter: f64, // Bar diameter
312    pub count: usize,  // Number of bars
313    pub material: Material,
314}
315
316impl ReinforcedConcreteSection {
317    pub fn new(concrete_section: impl ParametricSection + 'static) -> Self {
318        Self {
319            concrete_section: Box::new(concrete_section),
320            reinforcement: Vec::new(),
321        }
322    }
323
324    pub fn add_rebar(
325        mut self,
326        y: f64,
327        z: f64,
328        diameter: f64,
329        count: usize,
330        material: Material,
331    ) -> Self {
332        self.reinforcement.push(RebarLayer {
333            y,
334            z,
335            diameter,
336            count,
337            material,
338        });
339        self
340    }
341
342    pub fn add_rebar_layer(mut self, layer: RebarLayer) -> Self {
343        self.reinforcement.push(layer);
344        self
345    }
346
347    /// Build as composite section with transformed steel areas
348    pub fn build_composite(&self) -> crate::section_library::CompositeSection {
349        let concrete_sec = self.concrete_section.build();
350        let concrete_mat = crate::material::presets::CONCRETE_C30_37;
351
352        let mut material_groups = vec![crate::material::MaterialGroup::new(
353            concrete_mat,
354            vec![0], // concrete is group 0
355        )];
356
357        // Add each rebar layer as a material group
358        // For simplicity, we represent rebar as equivalent transformed area
359        // In full implementation, this would create small circular polygons for each bar
360        for (i, layer) in self.reinforcement.iter().enumerate() {
361            let n = layer.material.modular_ratio(&concrete_mat);
362            // Create a transformed area polygon (equivalent rectangle)
363            let bar_area = PI * (layer.diameter / 2.0).powi(2) * layer.count as f64;
364            let _transformed_area = bar_area * n;
365            // For now just add to material groups - actual geometry would need mesh
366            material_groups.push(crate::material::MaterialGroup::new(
367                layer.material,
368                vec![i + 1],
369            ));
370        }
371
372        crate::section_library::CompositeSection::new(
373            concrete_sec.outer,
374            concrete_sec.holes,
375            material_groups,
376        )
377    }
378}
379
380/// Precast hollow core slab.
381#[derive(Debug, Clone, Copy, PartialEq)]
382pub struct HollowCoreSlab {
383    pub width: f64,
384    pub height: f64,
385    pub core_diameter: f64,
386    pub core_spacing: f64,
387    pub n_cores: usize,
388    pub bottom_flange: f64,
389    pub top_flange: f64,
390}
391
392impl HollowCoreSlab {
393    pub fn new(
394        width: f64,
395        height: f64,
396        core_diameter: f64,
397        core_spacing: f64,
398        n_cores: usize,
399        bottom_flange: f64,
400        top_flange: f64,
401    ) -> Self {
402        assert!(width > 0.0 && height > 0.0);
403        assert!(core_diameter > 0.0 && core_spacing > core_diameter);
404        assert!(n_cores > 0);
405        assert!(bottom_flange > 0.0 && top_flange > 0.0);
406        assert!(core_diameter + top_flange + bottom_flange < height);
407        Self {
408            width,
409            height,
410            core_diameter,
411            core_spacing,
412            n_cores,
413            bottom_flange,
414            top_flange,
415        }
416    }
417}
418
419impl ParametricSection for HollowCoreSlab {
420    fn build(&self) -> Section {
421        let w = self.width;
422        let h = self.height;
423        let d = self.core_diameter;
424        let spacing = self.core_spacing;
425        let n = self.n_cores;
426        let bf = self.bottom_flange;
427        let tf = self.top_flange;
428
429        let hw = w / 2.0;
430        let hh = h / 2.0;
431
432        // Outer polygon
433        let mut outer_vertices = Vec::new();
434        outer_vertices.push(Point::new(-hw, -hh + bf));
435        outer_vertices.push(Point::new(hw, -hh + bf));
436        outer_vertices.push(Point::new(hw, hh - tf));
437        outer_vertices.push(Point::new(-hw, hh - tf));
438        let outer = Polygon::new(outer_vertices);
439
440        // Core holes
441        let mut holes = Vec::new();
442        let start_x = -hw + spacing / 2.0 + (w - spacing * (n - 1) as f64) / 2.0;
443        for i in 0..n {
444            let cx = start_x + i as f64 * spacing;
445            let cy = 0.0; // centered vertically
446            let mut core_vertices = Vec::new();
447            let nv = 64;
448            for j in (0..nv).rev() {
449                // CW for hole
450                let theta = 2.0 * PI * j as f64 / nv as f64;
451                core_vertices.push(Point::new(
452                    cx + d / 2.0 * theta.cos(),
453                    cy + d / 2.0 * theta.sin(),
454                ));
455            }
456            holes.push(Polygon::new(core_vertices));
457        }
458
459        Section::new(outer, holes)
460    }
461
462    fn designation(&self) -> String {
463        format!(
464            "HOLLOWCORE {:.0}x{:.0} Ø{:.0}x{}",
465            self.width * 1000.0,
466            self.height * 1000.0,
467            self.core_diameter * 1000.0,
468            self.n_cores
469        )
470    }
471}
472
473/// Concrete pile section.
474#[derive(Debug, Clone, Copy, PartialEq)]
475pub struct ConcretePile {
476    pub diameter: f64,
477    pub wall_thickness: f64, // 0 for solid
478    pub n_vertices: usize,
479}
480
481impl ConcretePile {
482    pub fn solid(diameter: f64) -> Self {
483        Self::with_vertices(diameter, 0.0, 128)
484    }
485
486    pub fn hollow(diameter: f64, wall_thickness: f64) -> Self {
487        Self::with_vertices(diameter, wall_thickness, 128)
488    }
489
490    pub fn with_vertices(diameter: f64, wall_thickness: f64, n_vertices: usize) -> Self {
491        assert!(diameter > 0.0);
492        assert!(wall_thickness >= 0.0);
493        assert!(2.0 * wall_thickness <= diameter);
494        assert!(n_vertices >= 8);
495        Self {
496            diameter,
497            wall_thickness,
498            n_vertices,
499        }
500    }
501}
502
503impl ParametricSection for ConcretePile {
504    fn build(&self) -> Section {
505        use crate::section_library::{circle_polygon, hollow_circle_polygon};
506        if self.wall_thickness > 0.0 {
507            let ro = self.diameter / 2.0;
508            let ri = ro - self.wall_thickness;
509            let (outer, inner) = hollow_circle_polygon(ro, ri, self.n_vertices);
510            Section::new(outer, vec![inner])
511        } else {
512            Section::new(
513                circle_polygon(self.diameter / 2.0, self.n_vertices),
514                Vec::new(),
515            )
516        }
517    }
518
519    fn designation(&self) -> String {
520        if self.wall_thickness > 0.0 {
521            format!(
522                "PILE Ø{:.0}x{:.0}",
523                self.diameter * 1000.0,
524                self.wall_thickness * 1000.0
525            )
526        } else {
527            format!("PILE Ø{:.0}", self.diameter * 1000.0)
528        }
529    }
530}
531
532#[cfg(test)]
533mod tests {
534    use super::*;
535    use crate::material::presets::*;
536    use std::f64::consts::PI;
537
538    #[test]
539    fn rectangular_concrete() {
540        let rc = RectangularConcreteSection::new(0.3, 0.5);
541        let sec = rc.build();
542        assert!((sec.area() - 0.15).abs() < 1e-10);
543    }
544
545    #[test]
546    fn circular_concrete() {
547        let cc = CircularConcreteSection::new(0.4);
548        let sec = cc.build();
549        assert!((sec.area() - PI * 0.04).abs() < 1e-4);
550    }
551
552    #[test]
553    fn t_beam_concrete() {
554        let tb = TBeamConcreteSection::new(1.0, 0.3, 0.6, 0.15);
555        let sec = tb.build();
556        let expected = 1.0 * 0.15 + 0.3 * 0.45;
557        assert!((sec.area() - expected).abs() < 1e-10);
558    }
559
560    #[test]
561    fn l_beam_concrete() {
562        let lb = LBeamConcreteSection::new(0.6, 0.3, 0.5, 0.12);
563        let sec = lb.build();
564        let expected = 0.6 * 0.12 + 0.3 * 0.38;
565        assert!((sec.area() - expected).abs() < 1e-10);
566    }
567
568    #[test]
569    fn box_concrete() {
570        let box_sec = BoxConcreteSection::uniform(1.0, 1.5, 0.1);
571        let sec = box_sec.build();
572        let expected = 1.0 * 1.5 - 0.8 * 1.3;
573        assert!((sec.area() - expected).abs() < 1e-6);
574    }
575
576    #[test]
577    fn hollow_core_slab() {
578        let hc = HollowCoreSlab::new(1.2, 0.2, 0.1, 0.15, 6, 0.03, 0.03);
579        let sec = hc.build();
580        let outer = 1.2 * 0.2 - 1.2 * 0.06; // minus flanges
581        let holes = 6.0 * PI * 0.05_f64.powi(2);
582        let expected = outer - holes;
583        assert!((sec.area() - expected).abs() < 1e-4);
584    }
585
586    #[test]
587    fn concrete_pile_solid() {
588        let pile = ConcretePile::solid(0.4);
589        let sec = pile.build();
590        assert!((sec.area() - PI * 0.04).abs() < 1e-4);
591    }
592
593    #[test]
594    fn concrete_pile_hollow() {
595        let pile = ConcretePile::hollow(0.5, 0.05);
596        let sec = pile.build();
597        let expected = PI * (0.25_f64.powi(2) - 0.20_f64.powi(2));
598        assert!((sec.area() - expected).abs() < 1e-4);
599    }
600
601    #[test]
602    fn reinforced_concrete_section() {
603        let rc = RectangularConcreteSection::new(0.3, 0.5);
604        let rcs = ReinforcedConcreteSection::new(rc)
605            .add_rebar(-0.2, -0.1, 0.02, 4, STEEL_S355)
606            .add_rebar(0.2, -0.1, 0.02, 4, STEEL_S355)
607            .add_rebar(-0.2, 0.1, 0.016, 2, STEEL_S355)
608            .add_rebar(0.2, 0.1, 0.016, 2, STEEL_S355);
609
610        let comp = rcs.build_composite();
611        assert_eq!(comp.material_groups.len(), 5); // concrete + 4 rebar layers
612    }
613}