代码整理

This commit is contained in:
fengmengqi
2026-03-25 18:34:41 +08:00
parent 3416c491ad
commit ddfe08cb93
313 changed files with 2817 additions and 777 deletions
+5 -5
View File
@@ -6,7 +6,7 @@
//!
//! 设置光致电离截面数组,用于辐射转移计算。
use crate::tlusty::math::sigk::{sigk, SigkParams};
use crate::tlusty::math::{sigk, SigkParams, OpData};
use crate::tlusty::state::atomic::AtomicData;
use crate::tlusty::state::constants::{MCROSS, MFREQ};
@@ -115,7 +115,7 @@ pub fn croset(params: &CrosetParams) -> Vec<Vec<f64>> {
itr: it,
mode: 0,
atomic,
opdata: &crate::tlusty::math::topbas::OpData::default(),
opdata: &crate::tlusty::math::OpData::default(),
};
cross[it][ij] = sigk(&sigk_params);
}
@@ -128,7 +128,7 @@ pub fn croset(params: &CrosetParams) -> Vec<Vec<f64>> {
itr: it,
mode: 1,
atomic,
opdata: &crate::tlusty::math::topbas::OpData::default(),
opdata: &crate::tlusty::math::OpData::default(),
};
cross[it][ij] = sigk(&sigk_params);
@@ -226,7 +226,7 @@ pub fn crosew(params: &CrosewParams) -> Vec<Vec<f64>> {
itr: it,
mode: 0,
atomic,
opdata: &crate::tlusty::math::topbas::OpData::default(),
opdata: &crate::tlusty::math::OpData::default(),
};
cross[it][ij] = sigk(&sigk_params);
}
@@ -239,7 +239,7 @@ pub fn crosew(params: &CrosewParams) -> Vec<Vec<f64>> {
itr: it,
mode: 1,
atomic,
opdata: &crate::tlusty::math::topbas::OpData::default(),
opdata: &crate::tlusty::math::OpData::default(),
};
cross[it][ij] = sigk(&sigk_params);
+1 -1
View File
@@ -7,7 +7,7 @@
//! - 最多 10 个 Doppler 宽度
//! - 共 MVOI=2001 个点
use crate::tlusty::math::interp::interp;
use crate::tlusty::math::interp;
/// Voigt 表步长 (每 Doppler 宽度的步数)
const VSTEPS: f64 = 200.0;
+3 -3
View File
@@ -379,7 +379,7 @@ fn setup_simpson(
_itr: i32,
) -> anyhow::Result<()> {
if n % 2 != 1 {
return Err(crate::tlusty::math::quit::quit_error(
return Err(crate::tlusty::math::quit_error(
"even number of points in Simpson - LINSET",
n as i32,
n as i32,
@@ -424,7 +424,7 @@ fn setup_modified_simpson(
m: usize,
) -> anyhow::Result<()> {
if n % 2 != 1 {
return Err(crate::tlusty::math::quit::quit_error(
return Err(crate::tlusty::math::quit_error(
"even number of points in MSimpson - LINSET",
n as i32,
n as i32,
@@ -473,7 +473,7 @@ fn setup_modified_simpson(
// 处理 XMAX < 0 的情况(非对称)
if n % 4 != 1 {
return Err(crate::tlusty::math::quit::quit_error(
return Err(crate::tlusty::math::quit_error(
"conflict in MSimpson - LINSET",
n as i32,
n as i32,
+2 -2
View File
@@ -10,8 +10,8 @@
use std::path::Path;
use super::{FortranReader, IoError, Result};
use crate::tlusty::math::rayset::rayset;
use crate::tlusty::math::rayleigh::{rayleigh, RayleighParams};
use crate::tlusty::math::rayset;
use crate::tlusty::math::{rayleigh, RayleighParams};
use crate::tlusty::state::constants::{MDEPTH, MTABR, MTABT};
use crate::tlusty::state::model::{EosPar, NumbOpac, RaySct, RayTbl, TabLop, Vectors};
use crate::tlusty::state::config::BasNum;
+25
View File
@@ -0,0 +1,25 @@
//! ali module
mod alifr1;
mod alifr3;
mod alifr6;
mod alifrk;
mod alisk1;
mod alisk2;
mod alist1;
mod alist2;
mod ijali2;
mod ijalis;
mod taufr1;
pub use alifr1::*;
pub use alifr3::*;
pub use alifr6::*;
pub use alifrk::*;
pub use alisk1::*;
pub use alisk2::*;
pub use alist1::*;
pub use alist2::*;
pub use ijali2::*;
pub use ijalis::*;
pub use taufr1::*;
@@ -9,7 +9,7 @@
//! 1. 给定主量子数 n 内的所有态合并
//! 2. 单重态和三重态分别合并
use super::cheavj::cheavj;
use crate::tlusty::math::cheavj;
// ============================================================================
// 核心计算函数
@@ -3,7 +3,7 @@
//! 重构自 TLUSTY `dietot.f`
//! 遍历所有离子和深度点,计算双电子复合速率和伪截面。
use crate::tlusty::math::dielrc::dielrc;
use crate::tlusty::math::dielrc;
use crate::tlusty::state::atomic::{AtoPar, IonPar, LevPar};
use crate::tlusty::state::config::{BasNum, InpPar};
use crate::tlusty::state::model::{LevAdd, ModPar};
+33
View File
@@ -0,0 +1,33 @@
//! atomic module
mod chctab;
mod cheav;
mod cheavj;
mod cion;
mod cross;
mod dielrc;
mod dietot;
mod ffcros;
mod gfree;
mod gntk;
mod vern16;
mod vern18;
mod vern20;
mod vern26;
mod verner;
pub use chctab::*;
pub use cheav::*;
pub use cheavj::*;
pub use cion::*;
pub use cross::*;
pub use dielrc::*;
pub use dietot::*;
pub use ffcros::*;
pub use gfree::*;
pub use gntk::*;
pub use vern16::*;
pub use vern18::*;
pub use vern20::*;
pub use vern26::*;
pub use verner::*;
+33
View File
@@ -0,0 +1,33 @@
//! continuum module
mod opacf0;
mod opacf1;
mod opacfa;
mod opacfd;
mod opacfl;
mod opact1;
mod opactd;
mod opactr;
mod opadd;
mod opadd0;
mod opahst;
mod opaini;
mod opctab;
mod opdata;
mod opfrac;
pub use opacf0::*;
pub use opacf1::*;
pub use opacfa::*;
pub use opacfd::*;
pub use opacfl::*;
pub use opact1::*;
pub use opactd::*;
pub use opactr::*;
pub use opadd::*;
pub use opadd0::*;
pub use opahst::*;
pub use opaini::*;
pub use opctab::*;
pub use opdata::*;
pub use opfrac::*;
@@ -294,13 +294,13 @@ fn crossd(
/// 计算 H⁻ 自由-自由不透明度 SFFHMI
fn sffhmi(popul_h: f64, fr: f64, t: f64) -> f64 {
// 调用 sffhmi 模块的函数
crate::tlusty::math::sffhmi::sffhmi(popul_h, fr, t)
crate::tlusty::math::sffhmi(popul_h, fr, t)
}
/// 计算自由-自由截面 FFCROS
fn ffcros(ion: i32, it: i32, t: f64, fr: f64) -> f64 {
// 调用 ffcros 模块的函数
crate::tlusty::math::ffcros::ffcros(ion, it, t, fr)
crate::tlusty::math::ffcros(ion, it, t, fr)
}
/// 计算氢 Gaunt 因子 GFREE1
@@ -4,7 +4,7 @@
//!
//! 对于给定频率点,计算所有深度点的吸收、发射和散射系数。
use super::opctab::{opctab, OpctabParams, OpctabTableData, OpctabModelState, OpctabOutput};
use crate::tlusty::math::{opctab, OpctabParams, OpctabTableData, OpctabModelState, OpctabOutput};
use crate::tlusty::state::constants::{HK, UN};
/// OPACT1 输入参数
@@ -18,7 +18,7 @@ pub struct Opact1Params<'a> {
/// 选项表标志 (<0: 添加电子散射, >0: 使用选项表)
pub ioptab: i32,
/// Rayleigh 参数 (当 ifrayl > 0 时需要)
pub rayleigh_params: Option<&'a super::rayleigh::RayleighParams<'a>>,
pub rayleigh_params: Option<&'a crate::tlusty::math::RayleighParams<'a>>,
}
/// OPACT1 模型状态
@@ -4,7 +4,7 @@
//!
//! 与 OPACT1 类似,但额外计算温度和密度导数。
use super::opctab::{opctab, OpctabParams, OpctabTableData, OpctabModelState, OpctabOutput};
use crate::tlusty::math::{opctab, OpctabParams, OpctabTableData, OpctabModelState, OpctabOutput};
use crate::tlusty::state::constants::{HK, UN};
/// 微分步长
@@ -26,7 +26,7 @@ pub struct OpactdParams<'a> {
/// 选项表标志
pub ioptab: i32,
/// Rayleigh 参数
pub rayleigh_params: Option<&'a super::rayleigh::RayleighParams<'a>>,
pub rayleigh_params: Option<&'a crate::tlusty::math::RayleighParams<'a>>,
}
/// OPACTD 模型状态
@@ -11,8 +11,8 @@
//! - CH 和 OH 连续不透明度
//! - CIA (碰撞诱导吸收) 不透明度
use super::{cia_h2h, cia_h2h2, cia_h2he, cia_hhe, h2minus, sbfch, sbfoh};
use crate::tlusty::math::sffhmi::sffhmi;
use crate::tlusty::math::{cia_h2h, cia_h2h2, cia_h2he, cia_hhe, h2minus, sbfch, sbfoh, CiaH2h2Data, CiaH2heData, CiaH2hData, CiaHheData};
use crate::tlusty::math::sffhmi;
// ============================================================================
// 常量
@@ -146,13 +146,13 @@ pub struct OpaddModel<'a> {
/// 连续跃迁计数
pub ncon: usize,
/// CIA H2-H2 数据
pub cia_h2h2_data: &'a cia_h2h2::CiaH2h2Data,
pub cia_h2h2_data: &'a CiaH2h2Data,
/// CIA H2-He 数据
pub cia_h2he_data: &'a cia_h2he::CiaH2heData,
pub cia_h2he_data: &'a CiaH2heData,
/// CIA H2-H 数据
pub cia_h2h_data: &'a cia_h2h::CiaH2hData,
pub cia_h2h_data: &'a CiaH2hData,
/// CIA H-He 数据
pub cia_hhe_data: &'a cia_hhe::CiaHheData,
pub cia_hhe_data: &'a CiaHheData,
}
/// OPADD 输出结果。
@@ -10,7 +10,7 @@
//! - H2+ 束缚-自由和自由-自由
//! - He- 自由-自由
use crate::tlusty::math::sbfhmi::sbfhmi;
use crate::tlusty::math::sbfhmi;
/// 常量 (从 Fortran PARAMETER 语句)
/// H I Rayleigh 散射阈值频率
@@ -7,7 +7,7 @@
//! - 配置 M1FILE 和 M2FILE 数组
//! - 计算 Stark 参数
use crate::tlusty::math::stark0::stark0;
use crate::tlusty::math::stark0;
/// 最大谱线数(与 Fortran NLMX 一致)
pub const NLMX: usize = 30;
@@ -9,7 +9,7 @@
//!
//! 这是一个简化版本,所有插值都是线性的,fortran中也是线性插值。
use crate::tlusty::math::rayleigh::{rayleigh, RayleighParams};
use crate::tlusty::math::{rayleigh, RayleighParams};
use crate::tlusty::state::model::{EosPar, RaySct};
/// 参考频率 (FRRAY0)
@@ -18,9 +18,9 @@
//! 求解得到的 DELTA(对数温度梯度)用于更新温度结构。
use crate::tlusty::state::constants::{HALF, PCK, SIG4P, UN};
use super::convec::{convec, ConvecConfig, ConvecParams};
use super::cubic::{cubic, CubicCon};
use super::conout::format_conout_header;
use crate::tlusty::math::{convec, ConvecConfig, ConvecParams};
use crate::tlusty::math::{cubic, CubicCon};
use crate::tlusty::math::format_conout_header;
// ============================================================================
// 常量
@@ -9,10 +9,10 @@
//! - 考虑辐射耗散效应
//! - 参考 Mihalas 恒星大气理论
use super::trmder::{trmder, TrmderConfig, TrmderParams};
use super::trmdrt::{trmdrt, TrmdrtParams};
use super::prsent::{prsent, PrsentParams, ThermTables};
use super::eldens::EldensConfig;
use crate::tlusty::math::{trmder, TrmderConfig, TrmderParams};
use crate::tlusty::math::{trmdrt, TrmdrtParams};
use crate::tlusty::math::{prsent, PrsentParams, ThermTables};
use crate::tlusty::math::EldensConfig;
use crate::tlusty::state::constants::{UN, HALF};
// ============================================================================
+15
View File
@@ -0,0 +1,15 @@
//! convection module
mod concor;
mod conout;
mod conref;
mod contmd;
mod contmp;
mod convec;
pub use concor::*;
pub use conout::*;
pub use conref::*;
pub use contmd::*;
pub use contmp::*;
pub use convec::*;
@@ -7,9 +7,9 @@
//! - 分析各元素对电子密度的贡献
//! - 输出电子供体信息
use crate::tlusty::math::moleq::{moleq_pure, MoleqParams};
use crate::tlusty::math::rhonen::{rhonen_pure, RhonenParams};
use crate::tlusty::math::state::{state_pure, StateParams};
use crate::tlusty::math::{moleq_pure, MoleqParams};
use crate::tlusty::math::{rhonen_pure, RhonenParams};
use crate::tlusty::math::{state_pure, StateParams};
use crate::tlusty::state::constants::{MDEPTH, MLEVEL};
/// 最大温度表点数
@@ -8,10 +8,10 @@
//! - 计算电荷守恒和粒子守恒
//! - 计算内能和熵
use crate::tlusty::math::lineqs::lineqs;
use crate::tlusty::math::moleq::{moleq_pure, MoleqParams, MoleculeEqData};
use crate::tlusty::math::mpartf::{mpartf, MpartfResult};
use crate::tlusty::math::state::{state_pure, StateParams};
use crate::tlusty::math::lineqs;
use crate::tlusty::math::{moleq_pure, MoleqParams, MoleculeEqData};
use crate::tlusty::math::{mpartf, MpartfResult};
use crate::tlusty::math::{state_pure, StateParams};
use crate::tlusty::state::constants::{BOLK, HMASS, UN, TWO, HALF};
/// ELDENS 配置参数
@@ -2,7 +2,7 @@
//!
//! 重构自 TLUSTY `entene.f`。
use crate::tlusty::math::mpartf::mpartf;
use crate::tlusty::math::mpartf;
const EV2ERG: f64 = 1.6018e-12;
const ENTCON: f64 = 103.973;
+19
View File
@@ -0,0 +1,19 @@
//! eos module
mod eldenc;
mod eldens;
mod entene;
mod moleq;
mod rhoeos;
mod rhonen;
mod russel;
mod steqeq;
pub use eldenc::*;
pub use eldens::*;
pub use entene::*;
pub use moleq::*;
pub use rhoeos::*;
pub use rhonen::*;
pub use russel::*;
pub use steqeq::*;
@@ -7,8 +7,8 @@
//! - 计算电子密度、熵、内能
//! - 计算质量密度和平均分子量
use crate::tlusty::math::mpartf::{mpartf, MpartfResult};
use crate::tlusty::math::russel::{russel, MoleculeData, RusselParams, RusselOutput, MAX_ELEM, MAX_MOL};
use crate::tlusty::math::{mpartf, MpartfResult};
use crate::tlusty::math::{russel, MoleculeData, RusselParams, RusselOutput, MAX_ELEM, MAX_MOL};
use crate::tlusty::state::constants::{BOLK, HMASS};
/// 常量
@@ -13,7 +13,7 @@
//! 2. 使用牛顿迭代法求解密度,使得计算的压力等于给定压力
//! 3. 收敛条件:相对误差 < 1e-5 或达到最大迭代次数
use super::{prsent, PrsentParams, ThermTables};
use crate::tlusty::math::{prsent, PrsentParams, ThermTables};
use crate::tlusty::state::constants::BOLK;
/// 平均分子量相关常数(氢原子质量 / 2.3)
@@ -6,7 +6,7 @@
//! - 从给定的温度和质量密度迭代求解总粒子密度和电子密度
//! - 使用 eldens 计算电子密度
use crate::tlusty::math::eldens::{eldens_pure, EldensConfig, EldensOutput, EldensParams};
use crate::tlusty::math::{eldens_pure, EldensConfig, EldensOutput, EldensParams};
use crate::tlusty::state::constants::{HMASS, UN};
/// RHONEN 输入参数
@@ -7,7 +7,7 @@
//! - 使用 Newton-Raphson 方法求解 Russell 方程
//! - 计算电离平衡分布
use crate::tlusty::math::mpartf::mpartf;
use crate::tlusty::math::mpartf;
/// 常量
const ECONST: f64 = 4.3426e-1;
@@ -5,10 +5,10 @@
//! 计算氢的碰撞电离和碰撞激发速率。
//! 标准表达式来自 Mihalas, Heasley, and Auer (1975)。
use super::butler::butler;
use super::ceh12::ceh12;
use super::cspec::cspec;
use super::irc::irc;
use crate::tlusty::math::butler;
use crate::tlusty::math::ceh12;
use crate::tlusty::math::cspec;
use crate::tlusty::math::irc;
use crate::tlusty::data::{COLH_CCOOL, COLH_CHOT};
use crate::tlusty::state::constants::{EH, HK, TWO, UN};
@@ -9,11 +9,11 @@
//! - 支持多种碰撞速率公式(Seaton、Allen、Van Regemorter 等)
//! - 处理表格化碰撞数据
use super::cion::cion;
use super::colh::{colh, ColhAtomicData, ColhOutput, ColhParams};
use super::cspec::cspec;
use super::irc::irc;
use super::ylintp::ylintp;
use crate::tlusty::math::cion;
use crate::tlusty::math::{colh, ColhAtomicData, ColhOutput, ColhParams};
use crate::tlusty::math::cspec;
use crate::tlusty::math::irc;
use crate::tlusty::math::ylintp;
use crate::tlusty::state::constants::{EH, HK, TWO, UN};
// ============================================================================
@@ -6,7 +6,7 @@
//! 使用 Bell 1980 的数据表进行双线性插值计算 H⁻ 自由-自由吸收系数。
use crate::tlusty::data::{H2MINUS_FFKAPP, H2MINUS_FFLAMB, H2MINUS_FFTHET};
use crate::tlusty::math::locate::locate;
use crate::tlusty::math::locate;
// 常量
const BOLK: f64 = 1.380649e-16; // 玻尔兹曼常数 (erg/K)
@@ -8,8 +8,8 @@
//! 3. 状态方程
//! 4. z-m 关系
use crate::tlusty::math::erfcx::erfcx;
use crate::tlusty::math::matinv::matinv;
use crate::tlusty::math::erfcx;
use crate::tlusty::math::matinv;
const UN: f64 = 1.0;
const HALF: f64 = 0.5;
@@ -7,11 +7,11 @@
//! - 使用 Newton-Raphson 迭代方法
//! - 给定声速(总压力/密度),求解压力和深度分布
use crate::tlusty::math::erfcx::erfcx;
use crate::tlusty::math::matinv::matinv;
use crate::tlusty::math::rhonen::{rhonen_pure, RhonenParams};
use crate::tlusty::math::steqeq::{steqeq_pure, SteqeqConfig, SteqeqParams};
use crate::tlusty::math::wnstor::wnstor;
use crate::tlusty::math::erfcx;
use crate::tlusty::math::matinv;
use crate::tlusty::math::{rhonen_pure, RhonenParams};
use crate::tlusty::math::{steqeq_pure, SteqeqConfig, SteqeqParams};
use crate::tlusty::math::wnstor;
use crate::tlusty::state::constants::{HALF, MDEPTH, TWO, UN};
/// HESOLV 辅助参数(PRSAUX COMMON 块)
@@ -185,7 +185,7 @@ pub fn lymlin(params: &mut LymlinParams, cache: &mut LymlinCache) {
let adh = cache.ad0[j][id];
let divh = cache.div0[j][id];
let sg = super::starka::starka(beta, TWO, adh, betad, divh) * cache.fid[j][id];
let sg = crate::tlusty::math::starka(beta, TWO, adh, betad, divh) * cache.fid[j][id];
ablym[id] += sg * cache.abtr[j][id];
emlym[id] += sg * cache.emtr[j][id];
}
@@ -212,7 +212,7 @@ fn initialize_cache(params: &LymlinParams, cache: &mut LymlinCache) {
// 计算 j=2..30 的 Stark 参数
for j in 2..=30 {
let (xkij0, wl00, fij0) = super::stark0::stark0(1, j, 1);
let (xkij0, wl00, fij0) = crate::tlusty::math::stark0(1, j, 1);
cache.xkijl[j] = xkij0;
cache.fijl[j] = fij0;
cache.wl0l[j] = wl00;
@@ -264,7 +264,7 @@ fn initialize_cache(params: &LymlinParams, cache: &mut LymlinCache) {
let betad = dop * dbeta;
// 调用 divstr
let (adh, divh) = super::divstr::divstr(betad, 1);
let (adh, divh) = crate::tlusty::math::divstr(betad, 1);
cache.ad0[j][id] = adh;
cache.div0[j][id] = divh;
+69
View File
@@ -0,0 +1,69 @@
//! hydrogen module
mod bhe;
mod bre;
mod brez;
mod brte;
mod brtez;
mod colh;
mod colhe;
mod colis;
mod collhe;
mod ctdata;
mod ghydop;
mod h2minus;
mod hedif;
mod hephot;
mod hesol6;
mod hesolv;
mod hidalg;
mod inthyd;
mod lymlin;
mod sbfch;
mod sbfhe1;
mod sbfhmi;
mod sbfhmi_old;
mod sbfoh;
mod sffhmi;
mod sffhmi_add;
mod sgmer;
mod sgmer1;
mod sigave;
mod sigk;
mod sigmar;
mod spsigk;
mod szirc;
pub use bhe::*;
pub use bre::*;
pub use brez::*;
pub use brte::*;
pub use brtez::*;
pub use colh::*;
pub use colhe::*;
pub use colis::*;
pub use collhe::*;
pub use ctdata::*;
pub use ghydop::*;
pub use h2minus::*;
pub use hedif::*;
pub use hephot::*;
pub use hesol6::*;
pub use hesolv::*;
pub use hidalg::*;
pub use inthyd::*;
pub use lymlin::*;
pub use sbfch::*;
pub use sbfhe1::*;
pub use sbfhmi::*;
pub use sbfhmi_old::*;
pub use sbfoh::*;
pub use sffhmi::*;
pub use sffhmi_add::*;
pub use sgmer::*;
pub use sgmer1::*;
pub use sigave::*;
pub use sigk::*;
pub use sigmar::*;
pub use spsigk::*;
pub use szirc::*;
@@ -5,7 +5,7 @@
//! 计算中性氦 n = 1, 2, 3, 4 态的光电离截面。
//! 使用 Opacity Project 截面的适当平均 (由 HEPHOT 计算) 或 Koester 拟合。
use super::{ckoest, hephot};
use crate::tlusty::math::{ckoest, hephot};
/// 计算 He I 光电离截面。
///
@@ -22,14 +22,14 @@
//! - H-: SBFHMI
//! - He I: SBFHE1
use super::gaunt;
use super::gntk;
use super::sbfhe1;
use super::sbfhmi;
use super::spsigk;
use super::topbas::{self, TopbasParams, OpData};
use super::verner;
use super::ylintp;
use crate::tlusty::math::gaunt;
use crate::tlusty::math::gntk;
use crate::tlusty::math::sbfhe1;
use crate::tlusty::math::sbfhmi;
use crate::tlusty::math::spsigk;
use crate::tlusty::math::{topbas, TopbasParams, OpData};
use crate::tlusty::math::verner;
use crate::tlusty::math::ylintp;
use crate::tlusty::state::atomic::AtomicData;
// ============================================================================
@@ -284,7 +284,7 @@ pub fn sigk(params: &SigkParams) -> f64 {
typly,
opdata,
};
sigk_result = topbas::topbas(&topbas_params);
sigk_result = topbas(&topbas_params);
}
// IBF > 100: 从直接输入数据插值
@@ -7,7 +7,7 @@
//!
//! 参考: Krolik, Chapter 7
use super::laguer::laguer;
use crate::tlusty::math::laguer;
use num_complex::Complex64;
/// 计算表面质量密度。

Some files were not shown because too many files have changed in this diff Show More