1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
//! Isotropic linear-elastic material definition.
//!
//! All values in SI base units (Pa, kg/m³, /K).
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Material {
/// Young's modulus `Pa`
pub youngs_modulus: f64,
/// Shear modulus `Pa`
pub shear_modulus: f64,
/// Poisson's ratio [-]
pub poissons_ratio: f64,
/// Density [kg/m³]
pub density: f64,
/// Coefficient of thermal expansion [1/K]
pub thermal_expansion: f64,
/// Yield strength `Pa` (for plastic analysis)
pub yield_strength: f64,
/// Ultimate tensile strength `Pa`
pub ultimate_strength: f64,
/// Optional: identifier/name for display
pub name: &'static str,
/// Optional: color for visualization (RGB 0-255)
pub color: Option<(u8, u8, u8)>,
}
impl Material {
/// 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`](Self::is_valid) to verify that the
/// resulting material has physically admissible properties.
pub fn new(youngs_modulus: f64, poissons_ratio: f64, density: f64, name: &'static str) -> Self {
let shear_modulus = youngs_modulus / (2.0 * (1.0 + poissons_ratio));
Self {
youngs_modulus,
shear_modulus,
poissons_ratio,
density,
thermal_expansion: 0.0,
yield_strength: 0.0,
ultimate_strength: 0.0,
name,
color: None,
}
}
/// Create a new material with all properties specified.
///
/// This is an **unchecked constructor** — it does not validate the
/// inputs. Call [`is_valid`](Self::is_valid) to verify that the
/// resulting material has physically admissible properties.
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 {
Self {
youngs_modulus,
shear_modulus,
poissons_ratio,
density,
thermal_expansion,
yield_strength,
ultimate_strength,
name,
color: None,
}
}
/// Set thermal expansion coefficient.
pub fn with_thermal_expansion(mut self, alpha: f64) -> Self {
self.thermal_expansion = alpha;
self
}
/// Set yield strength.
pub fn with_yield_strength(mut self, fy: f64) -> Self {
self.yield_strength = fy;
self
}
/// Set ultimate strength.
pub fn with_ultimate_strength(mut self, fu: f64) -> Self {
self.ultimate_strength = fu;
self
}
/// Set visualization color (RGB).
pub fn with_color(mut self, r: u8, g: u8, b: u8) -> Self {
self.color = Some((r, g, b));
self
}
/// Get modular ratio relative to another material (n = E_this / E_ref).
pub fn modular_ratio(&self, ref_material: &Material) -> f64 {
self.youngs_modulus / ref_material.youngs_modulus
}
/// 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 > 0` and finite
/// * `G > 0` and finite
/// * `-1 < ν < 0.5` (strict on both sides: ν = -1 gives G = ∞,
/// ν = 0.5 gives infinite bulk modulus)
/// * `ρ ≥ 0` and finite (zero density is admissible for a massless
/// placeholder)
pub fn is_valid(&self) -> bool {
self.youngs_modulus.is_finite()
&& self.youngs_modulus > 0.0
&& self.shear_modulus.is_finite()
&& self.shear_modulus > 0.0
&& self.poissons_ratio.is_finite()
&& self.poissons_ratio > -1.0
&& self.poissons_ratio < 0.5
&& self.density.is_finite()
&& self.density >= 0.0
}
}
impl Default for Material {
/// Default to generic structural steel (S355).
fn default() -> Self {
presets::STEEL_S355
}
}
impl fmt::Display for Material {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{} (E={:.0} GPa, ν={:.2}, ρ={:.0} kg/m³)",
self.name,
self.youngs_modulus / 1e9,
self.poissons_ratio,
self.density
)
}
}
/// Common structural materials (SI units).
pub mod presets {
use super::Material;
// Steel
/// Generic structural steel S235 (EN 10025)
pub const STEEL_S235: Material = Material {
youngs_modulus: 200e9,
shear_modulus: 76.923e9,
poissons_ratio: 0.3,
density: 7850.0,
thermal_expansion: 12e-6,
yield_strength: 235e6,
ultimate_strength: 360e6,
name: "S235",
color: Some((120, 120, 140)),
};
/// Generic structural steel S275 (EN 10025)
pub const STEEL_S275: Material = Material {
youngs_modulus: 200e9,
shear_modulus: 76.923e9,
poissons_ratio: 0.3,
density: 7850.0,
thermal_expansion: 12e-6,
yield_strength: 275e6,
ultimate_strength: 430e6,
name: "S275",
color: Some((130, 130, 150)),
};
/// Generic structural steel S355 (EN 10025) - most common
pub const STEEL_S355: Material = Material {
youngs_modulus: 200e9,
shear_modulus: 76.923e9,
poissons_ratio: 0.3,
density: 7850.0,
thermal_expansion: 12e-6,
yield_strength: 355e6,
ultimate_strength: 510e6,
name: "S355",
color: Some((140, 140, 160)),
};
/// Generic structural steel S460 (EN 10025)
pub const STEEL_S460: Material = Material {
youngs_modulus: 200e9,
shear_modulus: 76.923e9,
poissons_ratio: 0.3,
density: 7850.0,
thermal_expansion: 12e-6,
yield_strength: 460e6,
ultimate_strength: 620e6,
name: "S460",
color: Some((150, 150, 170)),
};
/// Stainless steel 304 (EN 1.4301)
pub const STAINLESS_304: Material = Material {
youngs_modulus: 193e9,
shear_modulus: 74.23e9,
poissons_ratio: 0.3,
density: 7930.0,
thermal_expansion: 17.2e-6,
yield_strength: 215e6,
ultimate_strength: 505e6,
name: "304 Stainless",
color: Some((180, 180, 190)),
};
/// Stainless steel 316 (EN 1.4401)
pub const STAINLESS_316: Material = Material {
youngs_modulus: 193e9,
shear_modulus: 74.23e9,
poissons_ratio: 0.3,
density: 7980.0,
thermal_expansion: 15.9e-6,
yield_strength: 205e6,
ultimate_strength: 515e6,
name: "316 Stainless",
color: Some((185, 185, 195)),
};
// Aluminum
/// Aluminum 6061-T6
pub const ALUMINUM_6061_T6: Material = Material {
youngs_modulus: 68.9e9,
shear_modulus: 26.0e9,
poissons_ratio: 0.33,
density: 2700.0,
thermal_expansion: 23.6e-6,
yield_strength: 276e6,
ultimate_strength: 310e6,
name: "6061-T6 Al",
color: Some((200, 200, 210)),
};
/// Aluminum 6063-T5
pub const ALUMINUM_6063_T5: Material = Material {
youngs_modulus: 68.3e9,
shear_modulus: 25.7e9,
poissons_ratio: 0.33,
density: 2700.0,
thermal_expansion: 23.4e-6,
yield_strength: 145e6,
ultimate_strength: 186e6,
name: "6063-T5 Al",
color: Some((205, 205, 215)),
};
/// Aluminum 7075-T6
pub const ALUMINUM_7075_T6: Material = Material {
youngs_modulus: 71.7e9,
shear_modulus: 26.9e9,
poissons_ratio: 0.33,
density: 2810.0,
thermal_expansion: 23.6e-6,
yield_strength: 503e6,
ultimate_strength: 572e6,
name: "7075-T6 Al",
color: Some((210, 210, 220)),
};
// Concrete
/// Concrete C25/30 (EN 1992)
pub const CONCRETE_C25_30: Material = Material {
youngs_modulus: 31e9,
shear_modulus: 12.9e9,
poissons_ratio: 0.2,
density: 2400.0,
thermal_expansion: 10e-6,
yield_strength: 25e6, // f_ck
ultimate_strength: 30e6,
name: "C25/30 Concrete",
color: Some((180, 170, 160)),
};
/// Concrete C30/37
pub const CONCRETE_C30_37: Material = Material {
youngs_modulus: 33e9,
shear_modulus: 13.75e9,
poissons_ratio: 0.2,
density: 2400.0,
thermal_expansion: 10e-6,
yield_strength: 30e6,
ultimate_strength: 37e6,
name: "C30/37 Concrete",
color: Some((175, 165, 155)),
};
/// Concrete C40/50
pub const CONCRETE_C40_50: Material = Material {
youngs_modulus: 35e9,
shear_modulus: 14.58e9,
poissons_ratio: 0.2,
density: 2450.0,
thermal_expansion: 10e-6,
yield_strength: 40e6,
ultimate_strength: 50e6,
name: "C40/50 Concrete",
color: Some((170, 160, 150)),
};
// Timber (GL24h)
/// Glued laminated timber GL24h (EN 14080).
///
/// **G is an independently specified engineering constant, NOT computed
/// from the isotropic relation** `G = E/(2(1+ν))`. Timber is orthotropic:
/// `E` is the mean modulus parallel to grain (`E₀,mean = 11.6 GPa`),
/// `G` is the mean shear modulus (`G,mean ≈ 0.725 GPa`), and `ν` is the
/// Poisson's ratio. The isotropic formula would give `G ≈ 4.30 GPa`,
/// which is ~6× too high and would produce incorrect torsional stiffness.
///
/// Source: EN 14080:2013, GL24h strength class. The shear modulus value
/// (0.725 GPa) is consistent with the EN 14080 range (0.65–0.72 GPa)
/// used in timber engineering practice.
pub const TIMBER_GL24H: Material = Material {
youngs_modulus: 11.6e9,
shear_modulus: 0.725e9,
poissons_ratio: 0.35,
density: 420.0,
thermal_expansion: 5e-6,
yield_strength: 24e6, // f_m,k
ultimate_strength: 24e6,
name: "GL24h Timber",
color: Some((200, 170, 120)),
};
// Titanium
/// Titanium Grade 5 (Ti-6Al-4V)
pub const TITANIUM_GR5: Material = Material {
youngs_modulus: 113.8e9,
shear_modulus: 44.0e9,
poissons_ratio: 0.342,
density: 4430.0,
thermal_expansion: 8.6e-6,
yield_strength: 880e6,
ultimate_strength: 950e6,
name: "Ti-6Al-4V",
color: Some((160, 160, 170)),
};
}
/// Material group for composite sections (transformed section method).
///
/// Groups elements sharing the same material reference for stiffness assembly.
#[derive(Debug, Clone, PartialEq)]
pub struct MaterialGroup {
pub material: Material,
/// List of polygon indices belonging to this material group
pub polygon_indices: Vec<usize>,
}
impl MaterialGroup {
pub fn new(material: Material, polygon_indices: Vec<usize>) -> Self {
Self {
material,
polygon_indices,
}
}
}
#[cfg(test)]
mod tests {
use super::presets::*;
use super::*;
#[test]
fn steel_material_properties() {
let mat = STEEL_S355;
assert!((mat.youngs_modulus - 200e9).abs() < 1e6);
assert!((mat.poissons_ratio - 0.3).abs() < 1e-9);
assert!(mat.is_valid());
}
#[test]
fn modular_ratio() {
let steel = STEEL_S355;
let concrete = CONCRETE_C30_37;
let n = steel.modular_ratio(&concrete);
assert!((n - 200.0 / 33.0).abs() < 0.1); // ≈ 6.06
}
#[test]
fn material_builder() {
let mat = Material::new(210e9, 0.3, 7850.0, "Custom Steel")
.with_yield_strength(400e6)
.with_color(255, 0, 0);
assert_eq!(mat.yield_strength, 400e6);
assert_eq!(mat.color, Some((255, 0, 0)));
}
/// Regression test: TIMBER_GL24H stores independently specified
/// engineering constants (orthotropic timber), NOT isotropic G.
///
/// Timber is orthotropic — `G` is the mean shear modulus from EN 14080,
/// not `E/(2(1+ν))`. This test protects the intended values against
/// accidental "fixes" that would replace G with the isotropic relation.
#[test]
fn timber_gl24h_orthotropic_constants() {
let mat = TIMBER_GL24H;
// Exact values from EN 14080 GL24h.
assert!((mat.youngs_modulus - 11.6e9).abs() < 1e3, "E = 11.6 GPa");
assert!((mat.shear_modulus - 0.725e9).abs() < 1e3, "G = 0.725 GPa");
assert!((mat.poissons_ratio - 0.35).abs() < 1e-9, "nu = 0.35");
assert!((mat.density - 420.0).abs() < 1e-6, "rho = 420 kg/m³");
// G must NOT equal the isotropic relation E/(2(1+ν)).
let g_isotropic = mat.youngs_modulus / (2.0 * (1.0 + mat.poissons_ratio));
assert!(
(mat.shear_modulus - g_isotropic).abs() > 1e9,
"TIMBER_GL24H G ({:.3} GPa) must differ from isotropic G ({:.3} GPa)",
mat.shear_modulus / 1e9,
g_isotropic / 1e9
);
// Material must pass validation.
assert!(mat.is_valid(), "TIMBER_GL24H must be valid");
}
}