squid_n_core/model/
section.rs1use super::*;
7
8pub fn rect_shear_area(area: f64) -> f64 {
9 area * 5.0 / 6.0
10}
11
12#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
13pub struct Section {
14 pub id: SectionId,
15 pub name: String,
17 #[serde(default)]
26 pub floor: Option<String>,
27 pub area: f64,
28 pub iy: f64,
29 pub iz: f64,
30 pub j: f64,
31 #[serde(default)]
32 pub depth: f64,
33 #[serde(default)]
34 pub width: f64,
35 #[serde(default)]
36 pub as_y: f64,
37 #[serde(default)]
38 pub as_z: f64,
39 #[serde(default)]
40 pub panel_thickness: Option<f64>,
41 #[serde(default)]
42 pub thickness: Option<f64>,
43 #[serde(default)]
46 pub shape: Option<crate::section_shape::SectionShape>,
47 #[serde(default)]
56 pub material: Option<MaterialId>,
57 #[serde(default)]
59 pub rebar_material: Option<MaterialId>,
60 #[serde(default)]
67 pub shear_rebar_material: Option<MaterialId>,
68 #[serde(default)]
70 pub steel_material: Option<MaterialId>,
71}
72
73pub type SectionKey<'a> = (&'a str, Option<&'a str>);
75
76impl Section {
77 pub fn zero(id: SectionId, name: String) -> Self {
90 Self {
91 id,
92 name,
93 floor: None,
94 area: 0.0,
95 iy: 0.0,
96 iz: 0.0,
97 j: 0.0,
98 depth: 0.0,
99 width: 0.0,
100 as_y: 0.0,
101 as_z: 0.0,
102 panel_thickness: None,
103 thickness: None,
104 shape: None,
105 material: None,
106 rebar_material: None,
107 shear_rebar_material: None,
108 steel_material: None,
109 }
110 }
111
112 pub fn key(&self) -> SectionKey<'_> {
114 (self.name.as_str(), self.floor.as_deref())
115 }
116
117 pub fn display_name(&self) -> String {
119 match &self.floor {
120 Some(f) => format!("{} ({})", self.name, f),
121 None => self.name.clone(),
122 }
123 }
124
125 pub fn properties_eq(&self, other: &Section) -> bool {
132 self.area == other.area
133 && self.iy == other.iy
134 && self.iz == other.iz
135 && self.j == other.j
136 && self.depth == other.depth
137 && self.width == other.width
138 && self.as_y == other.as_y
139 && self.as_z == other.as_z
140 && self.panel_thickness == other.panel_thickness
141 && self.thickness == other.thickness
142 && self.shape == other.shape
143 && self.material == other.material
144 && self.rebar_material == other.rebar_material
145 && self.shear_rebar_material == other.shear_rebar_material
146 && self.steel_material == other.steel_material
147 }
148}
149
150pub fn section_key_taken(sections: &[Section], key: SectionKey<'_>, skip: Option<usize>) -> bool {
155 sections
156 .iter()
157 .enumerate()
158 .any(|(i, s)| Some(i) != skip && s.key() == key)
159}
160
161impl Model {
162 pub fn element_section(&self, elem: &ElementData) -> Option<&Section> {
164 self.sections.get(elem.section?.index())
165 }
166
167 pub fn element_material(&self, elem: &ElementData) -> Option<&Material> {
173 self.materials
174 .get(self.element_section(elem)?.material?.index())
175 }
176
177 pub fn secondary_material(&self, sm: &SecondaryMember) -> Option<&Material> {
180 let sec = self.sections.get(sm.section?.index())?;
181 self.materials.get(sec.material?.index())
182 }
183
184 pub fn element_rebar_material(&self, elem: &ElementData) -> Option<&Material> {
186 self.materials
187 .get(self.element_section(elem)?.rebar_material?.index())
188 }
189
190 pub fn element_shear_rebar_material(&self, elem: &ElementData) -> Option<&Material> {
192 self.materials
193 .get(self.element_section(elem)?.shear_rebar_material?.index())
194 }
195
196 pub fn element_steel_material(&self, elem: &ElementData) -> Option<&Material> {
198 self.materials
199 .get(self.element_section(elem)?.steel_material?.index())
200 }
201}