Skip to main content

aeon_tk/element/
basis.rs

1use crate::geometry::IndexSpace;
2
3pub trait Basis<const N: usize> {
4    type Function: BasisFunction<N>;
5
6    fn order(&self) -> usize;
7    fn func(&self, deg: usize) -> Self::Function;
8}
9
10pub trait BasisFunction<const N: usize> {
11    fn value(&self, point: [f64; N]) -> f64;
12}
13
14pub struct Monomials<const N: usize>([usize; N]);
15
16impl<const N: usize> Monomials<N> {
17    pub fn new(degree: [usize; N]) -> Self {
18        Self(degree)
19    }
20}
21
22impl<const N: usize> Basis<N> for Monomials<N> {
23    type Function = Monomial<N>;
24
25    fn order(&self) -> usize {
26        self.0.iter().product()
27    }
28
29    fn func(&self, deg: usize) -> Self::Function {
30        let degree = IndexSpace::new(self.0).cartesian_from_linear(deg);
31        Monomial(degree)
32    }
33}
34
35pub struct Monomial<const N: usize>([usize; N]);
36
37impl<const N: usize> BasisFunction<N> for Monomial<N> {
38    fn value(&self, point: [f64; N]) -> f64 {
39        let mut result = 1.0;
40        for i in 0..N {
41            result *= point[i].powi(self.0[i] as i32);
42        }
43        result
44    }
45}