summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/mod.rs5
-rw-r--r--src/simulation/time_evolution.rs11
-rw-r--r--src/simulation/two_level.rs26
3 files changed, 42 insertions, 0 deletions
diff --git a/src/simulation/mod.rs b/src/simulation/mod.rs
new file mode 100644
index 0000000..290c3e6
--- /dev/null
+++ b/src/simulation/mod.rs
@@ -0,0 +1,5 @@
+pub mod time_evolution;
+pub mod two_level;
+
+#[allow(non_camel_case_types)]
+pub(crate) type c64 = num_complex::Complex<f64>;
diff --git a/src/simulation/time_evolution.rs b/src/simulation/time_evolution.rs
new file mode 100644
index 0000000..61c609e
--- /dev/null
+++ b/src/simulation/time_evolution.rs
@@ -0,0 +1,11 @@
+use super::c64;
+use ndarray::{Array1, Array2};
+
+pub trait MatrixGen {
+ fn gen(t: f64) -> Array2<c64>;
+}
+
+pub trait State {
+ fn fibrate(&self) -> Array1<c64>;
+ fn evolve<G: MatrixGen>(self, t: f64) -> Self;
+}
diff --git a/src/simulation/two_level.rs b/src/simulation/two_level.rs
new file mode 100644
index 0000000..38a65d9
--- /dev/null
+++ b/src/simulation/two_level.rs
@@ -0,0 +1,26 @@
+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) -> Array1<c64> {
+ self.state.clone()
+ }
+
+ fn evolve<G: super::time_evolution::MatrixGen>(mut self, t: f64) -> Self {
+ self.state = self.state.dot(&G::gen(t));
+ self
+ }
+}