pub use codegen::FromSaved;
use substrate::schematic::ExportsNestedData;
use crate::schematic::Cell;
use crate::simulation::{Analysis, SimulationContext, Simulator};
pub trait FromSaved<S: Simulator, A: Analysis> {
type SavedKey;
fn from_saved(output: &<A as Analysis>::Output, key: &Self::SavedKey) -> Self;
}
impl<S, A1, A2, O1, O2> FromSaved<S, (A1, A2)> for (O1, O2)
where
S: Simulator,
A1: Analysis,
A2: Analysis,
O1: FromSaved<S, A1>,
O2: FromSaved<S, A2>,
(A1, A2): Analysis<Output = (A1::Output, A2::Output)>,
{
type SavedKey = (
<O1 as FromSaved<S, A1>>::SavedKey,
<O2 as FromSaved<S, A2>>::SavedKey,
);
fn from_saved(output: &<(A1, A2) as Analysis>::Output, key: &Self::SavedKey) -> Self {
let o1 = <O1 as FromSaved<S, A1>>::from_saved(&output.0, &key.0);
let o2 = <O2 as FromSaved<S, A2>>::from_saved(&output.1, &key.1);
(o1, o2)
}
}
pub type SavedKey<S, A, T> = <T as FromSaved<S, A>>::SavedKey;
impl<S: Simulator, A: Analysis, T: FromSaved<S, A>> FromSaved<S, A> for Vec<T> {
type SavedKey = Vec<<T as FromSaved<S, A>>::SavedKey>;
fn from_saved(output: &<A as Analysis>::Output, key: &Self::SavedKey) -> Self {
key.iter().map(|key| T::from_saved(output, key)).collect()
}
}
pub trait Save<S: Simulator, A: Analysis, T>: FromSaved<S, A> {
fn save(
ctx: &SimulationContext<S>,
to_save: T,
opts: &mut <S as Simulator>::Options,
) -> <Self as FromSaved<S, A>>::SavedKey;
}
pub trait SaveTb<S: Simulator, A: Analysis, T: FromSaved<S, A>>: ExportsNestedData {
fn save_tb(
ctx: &SimulationContext<S>,
cell: &Cell<Self>,
opts: &mut <S as Simulator>::Options,
) -> <T as FromSaved<S, A>>::SavedKey;
}
pub mod tran {
use serde::{Deserialize, Serialize};
use std::ops::Deref;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Voltage(pub Arc<Vec<f64>>);
impl Deref for Voltage {
type Target = Vec<f64>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Current(pub Arc<Vec<f64>>);
impl Deref for Current {
type Target = Vec<f64>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Time(pub Arc<Vec<f64>>);
impl Deref for Time {
type Target = Vec<f64>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
}
pub mod ac {
use num::complex::Complex64;
use serde::{Deserialize, Serialize};
use std::ops::Deref;
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Voltage(pub Arc<Vec<Complex64>>);
impl Deref for Voltage {
type Target = Vec<Complex64>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Current(pub Arc<Vec<Complex64>>);
impl Deref for Current {
type Target = Vec<Complex64>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Freq(pub Arc<Vec<f64>>);
impl Deref for Freq {
type Target = Vec<f64>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
}