A toolkit for civil engineering and steel structure design.
test "axial member design" {
// Axial tension member: N=1000kN, A=0.01m², Q235 steel
// σ = N/A = 1000×10³/0.01 = 100MPa < 215MPa (Q235 design strength)
let sigma = axial_tension_strength(1000.0 * KN_TO_N, 0.01, F_Q235 * MPA_TO_PA)
assert_eq(approx_equal(sigma / MPA_TO_PA, 100.0, 1.0), true)
// Check if design is satisfied
let check = axial_tension_check(1000.0 * KN_TO_N, 0.01, F_Q235 * MPA_TO_PA)
assert_eq(check, true)
// Axial compression with stability: N=2000kN, A=0.02m², φ=0.8, Q235
let sigma_comp = axial_compression_stability(
2000.0 * KN_TO_N, 0.8, 0.02, F_Q235 * MPA_TO_PA
)
assert_eq(approx_equal(sigma_comp / MPA_TO_PA, 125.0, 1.0), true)
}test "beam design" {
// Bending stress: M=500kN·m, W=0.005m³, Q235 steel
// σ = M/W = 500×10³/0.005 = 100MPa < 215MPa
let sigma = bending_stress(500.0 * KN_TO_N, 0.005, F_Q235 * MPA_TO_PA)
assert_eq(approx_equal(sigma / MPA_TO_PA, 100.0, 1.0), true)
// Check bending stress
let check = bending_stress_check(500.0 * KN_TO_N, 0.005, F_Q235 * MPA_TO_PA)
assert_eq(check, true)
// Shear stress in beam: V=300kN, S=0.001m³, I=0.0001m⁴, t_w=0.01m
let tau = shear_stress_beam(
300.0 * KN_TO_N, 0.001, 0.0001, 0.01, FV_Q235 * MPA_TO_PA
)
assert_eq(tau > 0.0, true)
}test "beam column analysis" {
// Beam-column: N=1000kN, A=0.01m², M=200kN·m, W=0.002m³, Q235
// σ = N/A + M/W = 100 + 100 = 200MPa < 215MPa
let sigma = beam_column_strength(
1000.0 * KN_TO_N, 0.01, 200.0 * KN_TO_N, 0.002, F_Q235 * MPA_TO_PA
)
assert_eq(approx_equal(sigma / MPA_TO_PA, 200.0, 5.0), true)
// In-plane stability check
let stability_check = beam_column_in_plane_stability_check(
1000.0 * KN_TO_N, 0.9, 0.01, 200.0 * KN_TO_N, 0.85, 0.002, F_Q235 * MPA_TO_PA
)
assert_eq(stability_check, false)
}test "connection design" {
// Butt weld tension: N=500kN, l_w=0.5m, t=0.01m, Q235 weld
let sigma_weld = butt_weld_tension(
500.0 * KN_TO_N, 0.5, 0.01, FTW_Q235 * MPA_TO_PA
)
assert_eq(approx_equal(sigma_weld / MPA_TO_PA, 100.0, 1.0), true)
// Fillet weld strength: σ_f=50MPa, τ_f=50MPa, Q235 weld
// √(50² + 50²) = 70.7MPa < 160MPa (Q235 fillet weld strength)
let weld_stress = fillet_weld_strength(
50.0 * MPA_TO_PA, 50.0 * MPA_TO_PA, FFW_Q235 * MPA_TO_PA
)
assert_eq(approx_equal(weld_stress / MPA_TO_PA, 70.7, 1.0), true)
// Effective fillet weld thickness: h_f=0.01m, h_e=0.7×h_f=0.007m
let he = fillet_weld_effective_thickness(0.01)
assert_eq(approx_equal(he, 0.007, 0.0001), true)
}test "bolted connections" {
// Ordinary bolt shear capacity: n_v=2, d=0.02m, f_v^b=140MPa (4.6级)
let n_v_bolt = bolt_shear_capacity(2, 0.02, FVB_46 * MPA_TO_PA)
assert_eq(n_v_bolt > 0.0, true)
// Ordinary bolt bearing capacity: d=0.02m, Σt=0.04m, f_c^b=305MPa
let n_c_bolt = bolt_bearing_capacity(0.02, 0.04, FCB_46 * MPA_TO_PA)
assert_eq(n_c_bolt > 0.0, true)
// High-strength bolt friction capacity: n_f=2, μ=0.4, P=100kN
let n_hsb = hsb_friction_shear_capacity(2, 0.4, 100.0 * KN_TO_N)
assert_eq(n_hsb > 0.0, true)
// High-strength bolt preload: A_s=π×d²/4, f_u=400MPa
let area_s = PI * 0.02 * 0.02 / 4.0 // 螺纹有效面积
let preload = hsb_preload(area_s, FTB_88 * MPA_TO_PA)
assert_eq(preload > 0.0, true)
}moon testfn axial_compression_capacity(phi : Double, a : Double, f : Double) -> Doublefn axial_compression_stability(n : Double, phi : Double, a : Double, f : Double) -> Doublefn axial_compression_stability_check(n : Double, phi : Double, a : Double, f : Double) -> Boolfn axial_compression_strength(n : Double, a : Double, f : Double) -> Doublefn axial_tension_check(n : Double, a : Double, f : Double) -> Boolfn axial_tension_strength(n : Double, a : Double, f : Double) -> Doublefn beam_column_in_plane_stability(n : Double, phi_x : Double, a : Double, mx : Double, gamma_x : Double, wx : Double, f : Double) -> Doublefn beam_column_in_plane_stability_check(n : Double, phi_x : Double, a : Double, mx : Double, gamma_x : Double, wx : Double, f : Double) -> Boolfn beam_column_out_plane_stability(n : Double, phi_y : Double, a : Double, mx : Double, phi_b : Double, wx : Double, f : Double) -> Doublefn beam_column_out_plane_stability_check(n : Double, phi_y : Double, a : Double, mx : Double, phi_b : Double, wx : Double, f : Double) -> Boolfn beam_column_strength(n : Double, a : Double, m : Double, w : Double, f : Double) -> Doublefn beam_column_strength_check(n : Double, a : Double, m : Double, w : Double, f : Double) -> Boolfn bending_overall_stability(m : Double, phi_b : Double, w : Double, f : Double) -> Doublefn bending_overall_stability_check(m : Double, phi_b : Double, w : Double, f : Double) -> Boolfn bending_stress(m : Double, w : Double, f : Double) -> Doublefn bending_stress_check(m : Double, w : Double, f : Double) -> Boolfn bolt_bearing_capacity(d : Double, sum_t : Double, fcb : Double) -> Doublefn bolt_connection_capacity(nv : Double, nc : Double) -> Doublefn bolt_edge_distance_check(e : Double, d : Double, t : Double) -> Boolfn bolt_shear_capacity(nv : Int, d : Double, fvb : Double) -> Doublefn bolt_spacing_check(s : Double, d : Double, t : Double) -> Boolfn bolt_tension_capacity(de : Double, ftb : Double) -> Doublefn butt_weld_shear(v : Double, lw : Double, t : Double, fvw : Double) -> Doublefn butt_weld_shear_check(v : Double, lw : Double, t : Double, fvw : Double) -> Boolfn butt_weld_tension(n : Double, lw : Double, t : Double, ftw : Double) -> Doublefn butt_weld_tension_check(n : Double, lw : Double, t : Double, ftw : Double) -> Boolfn deflection_check(f_actual : Double, f_limit : Double) -> Boolfn effective_width(b : Double, rho : Double) -> Doublefn effective_width_coefficient(b_t_ratio : Double, limit : Double) -> Doublefn equivalent_slenderness_ratio(lambda : Double, lambda1 : Double) -> Doublefn fatigue_allowable_stress_amplitude(c : Double, n : Double, beta : Double) -> Doublefn fatigue_strength_check(delta_sigma : Double, delta_sigma_limit : Double) -> Boolfn fillet_weld_effective_length(l : Double, hf : Double) -> Doublefn fillet_weld_effective_thickness(hf : Double) -> Doublefn fillet_weld_strength(sigma_f : Double, tau_f : Double, ffw : Double) -> Doublefn fillet_weld_strength_check(sigma_f : Double, tau_f : Double, ffw : Double) -> Boolfn fire_protection_thickness(fire_resistance_time : Double, steel_section_factor : Double) -> Doublefn fire_resistance_check(t : Double, t_critical : Double) -> Boolfn hsb_friction_shear_capacity(nf : Int, mu : Double, p : Double) -> Doublefn hsb_preload(area_s : Double, fu : Double) -> Doublefn i_section_area(b : Double, tf : Double, hw : Double, tw : Double) -> Doublefn i_section_inertia_x(b : Double, h : Double, tf : Double, tw : Double) -> Doublefn i_section_modulus(i : Double, h : Double) -> Doublefn load_combination_basic(g : Double, q : Double, gamma_g : Double, gamma_q : Double) -> Doublefn load_combination_standard(g : Double, q : Double) -> Doublefn local_stability_check(b_t_ratio : Double, limit : Double) -> Boolfn local_stability_flange(b_t_ratio : Double, limit : Double) -> Boolfn local_stability_web(h_t_ratio : Double, limit : Double) -> Boolfn overall_stability_coefficient_beam(lambda_y : Double, eta_b : Double) -> Doublefn plastic_development_coefficient(section_class : String) -> Doublefn rect_section_modulus(b : Double, h : Double) -> Doublefn section_classification(b_t_ratio : Double, limit_s3 : Double, limit_s4 : Double) -> Stringfn shear_stress_beam(v : Double, s : Double, i : Double, tw : Double, fv : Double) -> Doublefn shear_stress_beam_check(v : Double, s : Double, i : Double, tw : Double, fv : Double) -> Boolfn stability_coefficient_approx(lambda : Double) -> Doublefn steel_temperature(t0 : Double, q : Double, rho : Double, c : Double, v : Double) -> Doublefn stiffener_required(h_t_ratio : Double, limit : Double) -> Boolfn stress_amplitude(sigma_max : Double, sigma_min : Double) -> DoubleInstall
Download zipA toolkit for civil engineering and steel structure design.