use crate::DType;
use numr::runtime::Runtime;
use numr::tensor::Tensor;
#[derive(Debug, Clone)]
pub struct Grid2D {
pub nx: usize,
pub ny: usize,
pub dx: f64,
pub dy: f64,
pub x_range: [f64; 2],
pub y_range: [f64; 2],
}
#[derive(Debug, Clone)]
pub struct Grid3D {
pub nx: usize,
pub ny: usize,
pub nz: usize,
pub dx: f64,
pub dy: f64,
pub dz: f64,
pub x_range: [f64; 2],
pub y_range: [f64; 2],
pub z_range: [f64; 2],
}
#[derive(Debug, Clone)]
pub enum BoundaryCondition<R: Runtime<DType = DType>> {
Dirichlet(Tensor<R>),
Neumann(Tensor<R>),
Periodic,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BoundarySide {
Left,
Right,
Bottom,
Top,
Front,
Back,
All,
}
#[derive(Debug, Clone)]
pub struct BoundarySpec<R: Runtime<DType = DType>> {
pub side: BoundarySide,
pub condition: BoundaryCondition<R>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum SparseSolver {
#[default]
Cg,
Gmres,
BiCgStab,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Preconditioner {
#[default]
None,
Ilu0,
Ic0,
}
#[derive(Debug, Clone)]
pub struct FdmOptions {
pub solver: SparseSolver,
pub preconditioner: Preconditioner,
pub max_iter: usize,
pub tolerance: f64,
}
impl Default for FdmOptions {
fn default() -> Self {
Self {
solver: SparseSolver::Cg,
preconditioner: Preconditioner::None,
max_iter: 10000,
tolerance: 1e-10,
}
}
}
#[derive(Debug, Clone)]
pub struct TimeDependentOptions {
pub t_span: [f64; 2],
pub dt: Option<f64>,
pub save_every: usize,
}
#[derive(Debug, Clone)]
pub struct FdmResult<R: Runtime<DType = DType>> {
pub solution: Tensor<R>,
pub iterations: usize,
pub residual_norm: f64,
}
#[derive(Debug, Clone)]
pub struct TimeResult<R: Runtime<DType = DType>> {
pub times: Tensor<R>,
pub solutions: Vec<Tensor<R>>,
}
#[derive(Debug, Clone)]
pub struct FemResult<R: Runtime<DType = DType>> {
pub solution: Tensor<R>,
pub nodes: Tensor<R>,
pub iterations: usize,
pub residual_norm: f64,
}
#[derive(Debug, Clone)]
pub struct SpectralResult<R: Runtime<DType = DType>> {
pub solution: Tensor<R>,
pub nodes: Tensor<R>,
}