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{
23 fn get_sens(&self) -> Vec<HostArray> {
24 self.y_sens
25 .iter()
26 .map(|s| {
27 let mut s = s.clone();
28 s.resize_cols(self.ts.len());
29 (*s.inner()).clone().to_host_array()
30 })
31 .collect()
32 }
33
34 fn get_ts(&self) -> HostArray {
35 (*V::from_slice(&self.ts, V::C::default()).inner())
36 .clone()
37 .to_host_array()
38 }
39
40 fn get_ys(&self) -> HostArray {
41 let mut ys = self.ys.clone();
42 ys.resize_cols(self.ts.len());
43 (*ys.inner()).clone().to_host_array()
44 }
45}