use gmt_dos_clients_fem::{DiscreteStateSpace, solvers::ExponentialMatrix};
use nalgebra as na;
use super::Include;
#[derive(Debug, Default, Clone)]
pub struct M1SegmentFigure {
pub(crate) transforms: Option<Vec<na::DMatrix<f64>>>,
pub(crate) keep_rbm: bool,
pub(crate) mode_2_force_transforms: Option<Vec<na::DMatrix<f64>>>,
}
impl M1SegmentFigure {
pub fn new() -> Self {
Default::default()
}
pub fn transforms(mut self, transforms: Vec<na::DMatrix<f64>>) -> Self {
self.transforms = Some(transforms);
self
}
pub fn keep_rigid_body_motions(mut self) -> Self {
self.keep_rbm = true;
self
}
pub fn modes_to_forces(mut self, transforms: Vec<na::DMatrix<f64>>) -> Self {
self.mode_2_force_transforms = Some(transforms);
self
}
pub(crate) fn transforms_view<'a>(&'a mut self) -> Option<Vec<na::DMatrixView<'a, f64>>> {
self.transforms
.as_ref()
.map(|transforms| transforms.iter().map(|t| t.as_view()).collect())
}
}
impl<'a> Include<'a, M1SegmentFigure> for DiscreteStateSpace<'a, ExponentialMatrix> {
fn including(
self,
m1_segment_figure: Option<&'a mut M1SegmentFigure>,
) -> Result<Self, gmt_dos_clients_fem::StateSpaceError>
where
Self: 'a + Sized,
{
let Some(m1_segment_figure) = m1_segment_figure else {
return Ok(self);
};
let names: Vec<_> = (1..=7).map(|i| format!("M1_segment_{i}_axial_d")).collect();
match (
m1_segment_figure.keep_rbm,
m1_segment_figure.transforms_view(),
) {
(true, None) => self.outs_by_name(names),
(true, Some(transforms)) => self.outs_with_by_name(names, transforms),
(false, None) => self.set_m1_figure_nodes()?.outs_by_name(names),
(false, Some(transforms)) => self
.set_m1_figure_nodes()?
.set_m1_figure_transforms(transforms)
.outs_by_name(names),
}
}
}