Skip to main content

diffsol_c/
solution.rs

1use std::any::Any;
2
3use diffsol::{
4    DefaultDenseMatrix, DenseMatrix, MatrixCommon, Solution as DiffsolSolution, Vector,
5    VectorCommon,
6};
7
8use crate::host_array::{HostArray, ToHostArray};
9
10pub(crate) trait Solution: Any + Send + Sync {
11    fn get_ys(&self) -> HostArray;
12    fn get_ts(&self) -> HostArray;
13    fn get_sens(&self) -> Vec<HostArray>;
14}
15
16impl<V> Solution for DiffsolSolution<V>
17where
18    V: Vector + DefaultDenseMatrix + Send + Sync + 'static,
19    <V as DefaultDenseMatrix>::M: DenseMatrix + Clone + Send + Sync,
20    <V as VectorCommon>::Inner: ToHostArray<V::T> + Clone,
21    <<V as DefaultDenseMatrix>::M as MatrixCommon>::Inner: ToHostArray<V::T> + Clone,
22    Vec<V::T>: ToHostArray<V::T>,
23{
24    fn get_sens(&self) -> Vec<HostArray> {
25        self.y_sens
26            .iter()
27            .map(|s| {
28                let mut s = s.clone();
29                s.resize_cols(self.ts.len());
30                (*s.inner()).clone().to_host_array()
31            })
32            .collect()
33    }
34
35    fn get_ts(&self) -> HostArray {
36        self.ts.clone().to_host_array()
37    }
38
39    fn get_ys(&self) -> HostArray {
40        let mut ys = self.ys.clone();
41        ys.resize_cols(self.ts.len());
42        (*ys.inner()).clone().to_host_array()
43    }
44}