aeon_tk/element/
operations.rs1use crate::element::BasisFunction;
2
3pub trait LinearOperator<const N: usize> {
4 fn num_operations(&self) -> usize;
5 fn apply(&self, i: usize, basis: &impl BasisFunction<N>) -> f64;
6}
7
8pub struct Value<const N: usize>([f64; N]);
9
10impl<const N: usize> Value<N> {
11 pub fn new(position: [f64; N]) -> Self {
12 Value(position)
13 }
14}
15
16impl<const N: usize> LinearOperator<N> for Value<N> {
17 fn num_operations(&self) -> usize {
18 1
19 }
20
21 fn apply(&self, _: usize, basis: &impl BasisFunction<N>) -> f64 {
22 basis.value(self.0)
23 }
24}
25
26pub struct Values<'a, const N: usize>(pub &'a [[f64; N]]);
27
28impl<'a, const N: usize> LinearOperator<N> for Values<'a, N> {
29 fn num_operations(&self) -> usize {
30 self.0.len()
31 }
32
33 fn apply(&self, i: usize, basis: &impl BasisFunction<N>) -> f64 {
34 basis.value(self.0[i])
35 }
36}
37
38pub struct ProductValue<const N: usize>([f64; N]);
39
40impl<const N: usize> ProductValue<N> {
41 pub fn new(position: [f64; N]) -> Self {
42 ProductValue(position)
43 }
44}
45
46impl<const N: usize> LinearOperator<1> for ProductValue<N> {
47 fn num_operations(&self) -> usize {
48 N
49 }
50
51 fn apply(&self, i: usize, basis: &impl BasisFunction<1>) -> f64 {
52 basis.value([self.0[i]])
53 }
54}