use crate::error::IntegrateError;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub struct StefanConfig {
pub nx: usize,
pub dt: f64,
pub stefan_number: f64,
pub diffusivity: f64,
pub melting_temp: f64,
pub wall_temp: f64,
pub l_max: f64,
pub max_time: f64,
pub output_every: usize,
}
impl Default for StefanConfig {
fn default() -> Self {
Self {
nx: 100,
dt: 1e-4,
stefan_number: 1.0,
diffusivity: 1.0,
melting_temp: 0.0,
wall_temp: 1.0,
l_max: 5.0,
max_time: 1.0,
output_every: 10,
}
}
}
impl StefanConfig {
pub fn validate(&self) -> Result<(), IntegrateError> {
if self.nx < 4 {
return Err(IntegrateError::InvalidInput(
"nx must be at least 4".to_string(),
));
}
if self.dt <= 0.0 {
return Err(IntegrateError::InvalidInput(
"dt must be positive".to_string(),
));
}
if self.stefan_number <= 0.0 {
return Err(IntegrateError::InvalidInput(
"stefan_number must be positive".to_string(),
));
}
if self.diffusivity <= 0.0 {
return Err(IntegrateError::InvalidInput(
"diffusivity must be positive".to_string(),
));
}
if self.wall_temp <= self.melting_temp {
return Err(IntegrateError::InvalidInput(
"wall_temp must be strictly greater than melting_temp".to_string(),
));
}
if self.l_max <= 0.0 {
return Err(IntegrateError::InvalidInput(
"l_max must be positive".to_string(),
));
}
if self.max_time <= 0.0 {
return Err(IntegrateError::InvalidInput(
"max_time must be positive".to_string(),
));
}
if self.output_every == 0 {
return Err(IntegrateError::InvalidInput(
"output_every must be at least 1".to_string(),
));
}
Ok(())
}
}
#[derive(Debug, Clone)]
pub struct StefanResult {
pub times: Vec<f64>,
pub interface_positions: Vec<f64>,
pub temperature_fields: Vec<Vec<f64>>,
pub grid: Vec<f64>,
}