SpectraRust/src/math/sbfhmi_old.rs
2026-03-19 22:16:23 +08:00

110 lines
2.8 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! H⁻ 束缚-自由截面 (旧版本)。
//!
//! 重构自 TLUSTY `sbfhmi_old.f`
//!
//! 负氢离子的束缚-自由光致电离截面。
/// H⁻ 束缚-自由截面 (旧版本)。
///
/// 计算负氢离子的束缚-自由光致电离截面。
///
/// # 参数
///
/// * `fr` - 频率 (Hz)
///
/// # 返回值
///
/// 截面 (cm²),如果频率低于阈值则返回 0。
///
/// # 备注
///
/// 阈值频率 FR0 = 1.8259×10¹⁴ Hz (对应 H⁻ 的束缚能)。
/// 使用两个不同的多项式拟合:
/// - 低于 2.111×10¹⁴ Hz: 使用 X = c × (1/FR0 - 1/FR) 的多项式
/// - 高于 2.111×10¹⁴ Hz: 使用 X = c/FR 的多项式
pub fn sbfhmi_old(fr: f64) -> f64 {
const FR0: f64 = 1.8259e14;
const C: f64 = 2.997925e15; // 光速 (Å/s)
// 低于阈值
if fr < FR0 {
return 0.0;
}
if fr < 2.111e14 {
// 低于 2.111×10¹⁴ Hz 的多项式
let x = C * (1.0 / FR0 - 1.0 / fr);
let sbfhmi = (2.69818e-1 + x * (2.2019e-1 + x * (-4.11288e-2 + x * 2.73236e-3)))
* x
* 1e-17;
sbfhmi
} else {
// 高于 2.111×10¹⁴ Hz 的多项式
let x = C / fr;
let sbfhmi = (6.80133e-3
+ x * (1.78708e-1 + x * (1.6479e-1 + x * (-2.04842e-2 + x * 5.95244e-4))))
* 1e-17;
sbfhmi
}
}
#[cfg(test)]
mod tests {
use super::*;
use approx::assert_relative_eq;
#[test]
fn test_sbfhmi_old_below_threshold() {
// 低于阈值
let result = sbfhmi_old(1e14);
assert_relative_eq!(result, 0.0, epsilon = 1e-30);
}
#[test]
fn test_sbfhmi_old_at_threshold() {
// 在阈值处 (x=0结果为 0)
let result = sbfhmi_old(1.8259e14);
assert_relative_eq!(result, 0.0, epsilon = 1e-30);
}
#[test]
fn test_sbfhmi_old_low_frequency() {
// 低频区 (1.8259e14 < fr < 2.111e14)
let result = sbfhmi_old(2.0e14);
assert!(result > 0.0);
assert!(result.is_finite());
}
#[test]
fn test_sbfhmi_old_transition() {
// 在过渡点 (2.111e14)
let result = sbfhmi_old(2.111e14);
assert!(result > 0.0);
assert!(result.is_finite());
}
#[test]
fn test_sbfhmi_old_high_frequency() {
// 高频区 (fr > 2.111e14)
let result = sbfhmi_old(5e14);
assert!(result > 0.0);
assert!(result.is_finite());
}
#[test]
fn test_sbfhmi_old_visible() {
// 可见光范围
let result = sbfhmi_old(5.45e14); // 550 nm
assert!(result > 0.0);
assert!(result.is_finite());
}
#[test]
fn test_sbfhmi_old_uv() {
// 紫外范围
let result = sbfhmi_old(1e15);
assert!(result > 0.0);
assert!(result.is_finite());
}
}