summaryrefslogtreecommitdiff
path: root/src/simulation/two_level.rs
blob: 2d9d459d1f42831f369611d0746d3599c8a10c3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use super::c64;
use super::time_evolution::State;
use ndarray::prelude::*;

pub struct TwoLevel {
    state: Array1<c64>,
}

impl TwoLevel {
    pub fn new(alpha: c64, beta: c64) -> TwoLevel {
        TwoLevel {
            state: array![alpha, beta],
        }
    }
}

impl State for TwoLevel {
    fn fibrate(&self) -> Vec<f64> {
        self.state.iter()
            .flat_map(|c| std::iter::once(c.re).chain(std::iter::once(c.im)))
            .collect()
    }

    fn evolve<G: super::time_evolution::MatrixGen>(mut self, t: f64) -> Self {
        self.state = self.state.dot(&G::gen(t));
        self
    }
}