601 lines
15 KiB
Rust
601 lines
15 KiB
Rust
//! 运行时配置参数。
|
||
//!
|
||
//! 重构自 TLUSTY `BASICS.FOR` 中的控制 COMMON 块。
|
||
|
||
use super::constants::*;
|
||
|
||
// ============================================================================
|
||
// BASNUM - 基本数值计数器
|
||
// ============================================================================
|
||
|
||
/// 基本数值计数器。
|
||
/// 对应 COMMON /BASNUM/
|
||
#[derive(Debug, Clone)]
|
||
pub struct BasNum {
|
||
/// 显式原子数
|
||
pub natom: i32,
|
||
/// 显式离子数
|
||
pub nion: i32,
|
||
/// 显式能级数
|
||
pub nlevel: i32,
|
||
/// 跃迁数
|
||
pub ntrans: i32,
|
||
/// 深度点数
|
||
pub nd: i32,
|
||
/// 频率点数
|
||
pub nfreq: i32,
|
||
/// 连续谱频率数
|
||
pub nfreqc: i32,
|
||
/// 线性化频率数
|
||
pub nfreqe: i32,
|
||
|
||
// 各种选项标志
|
||
pub ioptab: i32,
|
||
pub idisk: i32,
|
||
pub izscal: i32,
|
||
pub idmfix: i32,
|
||
pub iheso6: i32,
|
||
pub ifmol: i32,
|
||
pub ifentr: i32,
|
||
pub nfreql: i32,
|
||
pub nlev0: i32,
|
||
pub icolhn: i32,
|
||
pub ioscor: i32,
|
||
pub ilgder: i32,
|
||
pub ifryb: i32,
|
||
pub ifrset: i32,
|
||
pub nfread: i32,
|
||
pub nelsc: i32,
|
||
pub ntranc: i32,
|
||
pub iover: i32,
|
||
pub jali: i32,
|
||
pub ibc: i32,
|
||
pub iubc: i32,
|
||
pub intens: i32,
|
||
pub irder: i32,
|
||
pub ilmcor: i32,
|
||
pub ifdiel: i32,
|
||
pub ifalih: i32,
|
||
pub iftene: i32,
|
||
pub itndre: i32,
|
||
pub ilpsct: i32,
|
||
pub ilasct: i32,
|
||
pub irte: i32,
|
||
pub idlte: i32,
|
||
pub ibfint: i32,
|
||
pub intrpl: i32,
|
||
pub ichang: i32,
|
||
pub natoms: i32,
|
||
pub ipslte: i32,
|
||
pub ispodf: i32,
|
||
pub itlucy: i32,
|
||
pub nretc: i32,
|
||
pub ifrayl: i32,
|
||
pub ifprad: i32,
|
||
}
|
||
|
||
impl Default for BasNum {
|
||
fn default() -> Self {
|
||
Self {
|
||
natom: 0, nion: 0, nlevel: 0, ntrans: 0,
|
||
nd: 0, nfreq: 0, nfreqc: 0, nfreqe: 0,
|
||
ioptab: 0, idisk: 0, izscal: 0, idmfix: 0,
|
||
iheso6: 0, ifmol: 0, ifentr: 0, nfreql: 0,
|
||
nlev0: 0, icolhn: 0, ioscor: 0, ilgder: 0,
|
||
ifryb: 0, ifrset: 0, nfread: 0, nelsc: 0,
|
||
ntranc: 0, iover: 0, jali: 0, ibc: 0,
|
||
iubc: 0, intens: 0, irder: 0, ilmcor: 0,
|
||
ifdiel: 0, ifalih: 0, iftene: 0, itndre: 0,
|
||
ilpsct: 0, ilasct: 0, irte: 0, idlte: 0,
|
||
ibfint: 0, intrpl: 0, ichang: 0, natoms: 0,
|
||
ipslte: 0, ispodf: 0, itlucy: 0, nretc: 0,
|
||
ifrayl: 0, ifprad: 0,
|
||
}
|
||
}
|
||
}
|
||
|
||
// ============================================================================
|
||
// CENTRL - 中心点参数
|
||
// ============================================================================
|
||
|
||
/// 中心点参数。
|
||
/// 对应 COMMON /CENTRL/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct Centrl {
|
||
/// 中心平面几何距离
|
||
pub znd: f64,
|
||
/// Z 修正迭代控制
|
||
pub ifz0: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// INPPAR - 输入参数
|
||
// ============================================================================
|
||
|
||
/// 输入参数。
|
||
/// 对应 COMMON /INPPAR/
|
||
#[derive(Debug, Clone)]
|
||
pub struct InpPar {
|
||
/// 有效温度 (K)
|
||
pub teff: f64,
|
||
/// 表面重力 (cm/s²)
|
||
pub grav: f64,
|
||
|
||
/// 总 He 丰度 (质量分数)
|
||
pub ytot: Vec<f64>,
|
||
/// 平均分子量
|
||
pub wmm: Vec<f64>,
|
||
/// He 质量分数
|
||
pub wmy: Vec<f64>,
|
||
/// 分子温度极限
|
||
pub tmolim: f64,
|
||
|
||
// 恒星风参数
|
||
pub xmstar: f64,
|
||
pub xmdot: f64,
|
||
pub rstar: f64,
|
||
pub alpha0: f64,
|
||
pub reynum: f64,
|
||
|
||
// 引力相关
|
||
pub qgrav: f64,
|
||
pub edisc: f64,
|
||
pub dzeta: f64,
|
||
pub reldst: f64,
|
||
|
||
// 粘性参数
|
||
pub visc: f64,
|
||
pub zeta0: f64,
|
||
pub zeta1: f64,
|
||
pub dmvisc: f64,
|
||
pub fractv: f64,
|
||
|
||
// 自转参数
|
||
pub omeg32: f64,
|
||
pub wbarm: f64,
|
||
pub wbar: f64,
|
||
pub alphav: f64,
|
||
pub pgas0: f64,
|
||
|
||
// 控制参数
|
||
pub bergfc: f64, // β 引力因子 (wn.f 使用)
|
||
pub cutlym: f64,
|
||
pub cutbal: f64,
|
||
|
||
// 选项标志
|
||
pub isplin: i32,
|
||
pub irsplt: i32,
|
||
pub ivisc: i32,
|
||
pub ibche: i32,
|
||
pub lte: bool,
|
||
pub ltgrey: bool,
|
||
pub lchc: bool,
|
||
pub lresc: bool,
|
||
}
|
||
|
||
impl InpPar {
|
||
pub fn new() -> Self {
|
||
Self {
|
||
teff: 10000.0,
|
||
grav: 4.44, // log g = 4.44 (太阳)
|
||
ytot: vec![0.0; MDEPTH],
|
||
wmm: vec![0.0; MDEPTH],
|
||
wmy: vec![0.0; MDEPTH],
|
||
tmolim: 0.0,
|
||
xmstar: 0.0, xmdot: 0.0, rstar: 0.0, alpha0: 0.0, reynum: 0.0,
|
||
qgrav: 0.0, edisc: 0.0, dzeta: 0.0, reldst: 0.0,
|
||
visc: 0.0, zeta0: 0.0, zeta1: 0.0, dmvisc: 0.0, fractv: 0.0,
|
||
omeg32: 0.0, wbarm: 0.0, wbar: 0.0, alphav: 0.0, pgas0: 0.0,
|
||
bergfc: 1.0, // 默认值
|
||
cutlym: 0.0, cutbal: 0.0,
|
||
isplin: 0, irsplt: 0, ivisc: 0, ibche: 0,
|
||
lte: false, ltgrey: false, lchc: false, lresc: false,
|
||
}
|
||
}
|
||
}
|
||
|
||
impl Default for InpPar {
|
||
fn default() -> Self {
|
||
Self::new()
|
||
}
|
||
}
|
||
|
||
// ============================================================================
|
||
// MATKEY - 材料键
|
||
// ============================================================================
|
||
|
||
/// 材料键。
|
||
/// 对应 COMMON /MATKEY/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct MatKey {
|
||
pub nn: i32,
|
||
pub nn0: i32,
|
||
pub inhe: i32,
|
||
pub inre: i32,
|
||
pub inpc: i32,
|
||
pub inse: i32,
|
||
pub inzd: i32,
|
||
pub inmp: i32,
|
||
pub ndre: i32,
|
||
pub insel: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// RUNKEY - 运行控制
|
||
// ============================================================================
|
||
|
||
/// 运行控制键。
|
||
/// 对应 COMMON /RUNKEY/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct RunKey {
|
||
pub chmax: f64,
|
||
pub iter: i32,
|
||
pub niter: i32,
|
||
pub nitzer: i32,
|
||
pub init: i32,
|
||
pub lac2: i32,
|
||
pub lfin: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// CONKEY - 收敛控制
|
||
// ============================================================================
|
||
|
||
/// 收敛控制键。
|
||
/// 对应 COMMON /CONKEY/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct ConKey {
|
||
pub hmix0: f64,
|
||
pub crflim: f64,
|
||
pub nconit: i32,
|
||
pub iconv: i32,
|
||
pub indl: i32,
|
||
pub ipress: i32,
|
||
pub itemp: i32,
|
||
pub icbeg: i32,
|
||
pub itmcor: i32,
|
||
pub iconre: i32,
|
||
pub ideepc: i32,
|
||
pub ndcgap: i32,
|
||
pub idconz: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// FIXDEN - 固定密度标志
|
||
// ============================================================================
|
||
|
||
/// 固定密度标志。
|
||
/// 对应 COMMON /FIXDEN/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct FixDen {
|
||
pub ifixde: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// INVINT - 逆积分参数
|
||
// ============================================================================
|
||
|
||
/// 逆积分参数。
|
||
/// 对应 COMMON /INVINT/
|
||
#[derive(Debug, Clone)]
|
||
pub struct InvInt {
|
||
pub xi2: Vec<f64>,
|
||
pub xi3: Vec<f64>,
|
||
}
|
||
|
||
impl Default for InvInt {
|
||
fn default() -> Self {
|
||
Self {
|
||
xi2: vec![0.0; NLMX],
|
||
xi3: vec![0.0; NLMX],
|
||
}
|
||
}
|
||
}
|
||
|
||
// ============================================================================
|
||
// OPCKEY - 不透明度控制键
|
||
// ============================================================================
|
||
|
||
/// 不透明度控制键。
|
||
/// 对应 COMMON /OPCKEY/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct OpcKey {
|
||
pub ncon: i32,
|
||
pub iophl1: i32,
|
||
pub iophl2: i32,
|
||
pub iphe2c: i32,
|
||
pub ifmoff: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// PSILIM - Ψ 限制参数
|
||
// ============================================================================
|
||
|
||
/// Ψ 限制参数。
|
||
/// 对应 COMMON /PSILIM/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct PsiLim {
|
||
pub dpsilg: f64,
|
||
pub dpsilt: f64,
|
||
pub dpsiln: f64,
|
||
pub dpsild: f64,
|
||
}
|
||
|
||
// ============================================================================
|
||
// COMITE - 迭代控制键
|
||
// ============================================================================
|
||
|
||
/// 迭代控制参数。
|
||
/// 对应 COMMON /COMITE/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct Comite {
|
||
pub ncfor1: i32,
|
||
pub ncfor2: i32,
|
||
pub nccoup: i32,
|
||
pub ncitot: i32,
|
||
pub ncfull: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// MLCONS - 混合长度常数
|
||
// ============================================================================
|
||
|
||
/// 混合长度常数。
|
||
/// 对应 COMMON /MLCONS/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct MlCons {
|
||
pub aconml: f64,
|
||
pub bconml: f64,
|
||
pub cconml: f64,
|
||
}
|
||
|
||
// ============================================================================
|
||
// TAURSL - 光学深度表
|
||
// ============================================================================
|
||
|
||
/// 光学深度表。
|
||
/// 对应 COMMON /TAURSL/
|
||
#[derive(Debug, Clone)]
|
||
pub struct TaurSl {
|
||
pub taurs: Vec<f64>,
|
||
}
|
||
|
||
impl Default for TaurSl {
|
||
fn default() -> Self {
|
||
Self {
|
||
taurs: vec![0.0; MDEPTH],
|
||
}
|
||
}
|
||
}
|
||
|
||
// ============================================================================
|
||
// IPRKEY - 打印键
|
||
// ============================================================================
|
||
|
||
/// 打印键。
|
||
/// 对应 COMMON /IPRKEY/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct IprKey {
|
||
pub iprybh: i32,
|
||
pub ipelch: i32,
|
||
pub ipeldo: i32,
|
||
pub ipconf: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// OPCPAR - 额外不透明度控制
|
||
// ============================================================================
|
||
|
||
/// 额外不透明度控制。
|
||
/// 对应 COMMON /OPCPAR/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct OpcPar {
|
||
pub iopadd: i32,
|
||
pub iophmi: i32, // H⁻
|
||
pub ioph2p: i32, // H₂⁺
|
||
pub iophem: i32, // He⁻
|
||
pub iopch: i32, // CH
|
||
pub iopoh: i32, // OH
|
||
pub ioph2m: i32, // H₂⁻
|
||
pub ioh2h2: i32, // H₂-H₂ CIA
|
||
pub ioh2he: i32, // H₂-He CIA
|
||
pub ioh2h: i32, // H₂-H CIA
|
||
pub iohhe: i32, // H-He CIA
|
||
pub iophli: i32, // H⁻ 自由-自由
|
||
pub irsct: i32, // 汤姆逊散射
|
||
pub irsche: i32, // He 散射
|
||
pub irsch2: i32, // H₂ 散射
|
||
pub keepop: i32,
|
||
pub iopold: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// PRINTS - 打印控制
|
||
// ============================================================================
|
||
|
||
/// 打印控制。
|
||
/// 对应 COMMON /PRINTS/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct Prints {
|
||
pub iprint: i32,
|
||
pub ipring: i32,
|
||
pub iprind: i32,
|
||
pub iprinp: i32,
|
||
pub icoolp: i32,
|
||
pub ichckp: i32,
|
||
pub ipopac: i32,
|
||
pub iprini: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// ANGLES - 角度设置
|
||
// ============================================================================
|
||
|
||
/// 角度设置。
|
||
/// 对应 COMMON /ANGLES/
|
||
#[derive(Debug, Clone)]
|
||
pub struct Angles {
|
||
/// 角度余弦值
|
||
pub amu: Vec<f64>,
|
||
/// 角度权重
|
||
pub wtmu: Vec<f64>,
|
||
/// 角度函数
|
||
pub fmu: Vec<f64>,
|
||
/// 角度点数
|
||
pub nmu: i32,
|
||
}
|
||
|
||
impl Default for Angles {
|
||
fn default() -> Self {
|
||
Self {
|
||
amu: vec![0.0; MMU],
|
||
wtmu: vec![0.0; MMU],
|
||
fmu: vec![0.0; MMU],
|
||
nmu: 0,
|
||
}
|
||
}
|
||
}
|
||
|
||
// ============================================================================
|
||
// COMPTN - Compton 散射角度参数
|
||
// ============================================================================
|
||
|
||
/// Compton 散射角度参数。
|
||
/// 对应 COMMON /COMPTN/ 和 /ANGNUM/
|
||
#[derive(Debug, Clone)]
|
||
pub struct Comptn {
|
||
/// 角度余弦值
|
||
pub amuc: Vec<f64>,
|
||
/// 角度权重
|
||
pub wtmuc: Vec<f64>,
|
||
/// amuc * wtmuc
|
||
pub amuc1: Vec<f64>,
|
||
/// amuc² * wtmuc
|
||
pub amuc2: Vec<f64>,
|
||
/// amuc³ * wtmuc
|
||
pub amuc3: Vec<f64>,
|
||
/// 角度相关量
|
||
pub amuj: Vec<f64>,
|
||
pub amuk: Vec<f64>,
|
||
pub amuh: Vec<f64>,
|
||
pub amun: Vec<f64>,
|
||
/// Compton 散射 α 系数
|
||
pub calph: Vec<Vec<f64>>,
|
||
/// Compton 散射 β 系数
|
||
pub cbeta: Vec<Vec<f64>>,
|
||
/// Compton 散射 γ 系数
|
||
pub cgamm: Vec<Vec<f64>>,
|
||
/// 辐射零点
|
||
pub radzer: f64,
|
||
/// Compton 频率
|
||
pub frlcom: f64,
|
||
/// Compton 截面
|
||
pub sigec: Vec<f64>,
|
||
/// 原始频率索引
|
||
pub ijorig: Vec<i32>,
|
||
/// Compton 角度点数
|
||
pub nmuc: i32,
|
||
}
|
||
|
||
impl Default for Comptn {
|
||
fn default() -> Self {
|
||
Self {
|
||
amuc: vec![0.0; MMUC],
|
||
wtmuc: vec![0.0; MMUC],
|
||
amuc1: vec![0.0; MMUC],
|
||
amuc2: vec![0.0; MMUC],
|
||
amuc3: vec![0.0; MMUC],
|
||
amuj: vec![0.0; MMUC],
|
||
amuk: vec![0.0; MMUC],
|
||
amuh: vec![0.0; MMUC],
|
||
amun: vec![0.0; MMUC],
|
||
calph: vec![vec![0.0; MMUC]; MMUC],
|
||
cbeta: vec![vec![0.0; MMUC]; MMUC],
|
||
cgamm: vec![vec![0.0; MMUC]; MMUC],
|
||
radzer: 0.0,
|
||
frlcom: 0.0,
|
||
sigec: vec![0.0; MFREQ],
|
||
ijorig: vec![0; MFREQ],
|
||
nmuc: 0,
|
||
}
|
||
}
|
||
}
|
||
|
||
// ============================================================================
|
||
// COMPTI - Compton 散射控制参数
|
||
// ============================================================================
|
||
|
||
/// Compton 散射控制参数。
|
||
/// 对应 COMMON /COMPTI/
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct Compti {
|
||
pub nedd: i32,
|
||
pub nsti: i32,
|
||
pub islab: i32,
|
||
pub ilbc: i32,
|
||
pub icompt: i32,
|
||
pub icomst: i32,
|
||
pub icomde: i32,
|
||
pub icombc: i32,
|
||
pub icmdra: i32,
|
||
pub knish: i32,
|
||
pub itcomp: i32,
|
||
pub icomve: i32,
|
||
pub icomrt: i32,
|
||
pub ichcoo: i32,
|
||
pub icomgr: i32,
|
||
}
|
||
|
||
// ============================================================================
|
||
// 综合配置结构
|
||
// ============================================================================
|
||
|
||
/// TLUSTY 综合配置。
|
||
/// 包含所有控制参数。
|
||
#[derive(Debug, Clone, Default)]
|
||
pub struct TlustyConfig {
|
||
pub basnum: BasNum,
|
||
pub inppar: InpPar,
|
||
pub matkey: MatKey,
|
||
pub runkey: RunKey,
|
||
pub conkey: ConKey,
|
||
pub opcpar: OpcPar,
|
||
pub prints: Prints,
|
||
pub angles: Angles,
|
||
pub comptn: Comptn,
|
||
pub centrl: Centrl,
|
||
pub compti: Compti,
|
||
pub opckey: OpcKey,
|
||
pub invint: InvInt,
|
||
pub fixden: FixDen,
|
||
pub psilim: PsiLim,
|
||
pub comite: Comite,
|
||
pub mlcons: MlCons,
|
||
pub taursl: TaurSl,
|
||
pub iprkey: IprKey,
|
||
}
|
||
|
||
impl TlustyConfig {
|
||
pub fn new() -> Self {
|
||
Self::default()
|
||
}
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
|
||
#[test]
|
||
fn test_config_creation() {
|
||
let config = TlustyConfig::new();
|
||
assert_eq!(config.basnum.natom, 0);
|
||
assert_eq!(config.inppar.teff, 10000.0);
|
||
}
|
||
|
||
#[test]
|
||
fn test_inppar_arrays() {
|
||
let inppar = InpPar::new();
|
||
assert_eq!(inppar.ytot.len(), MDEPTH);
|
||
}
|
||
}
|