use super::*;
#[derive(Clone, Debug)]
pub struct Bunge{
ori: Array2<f64>,
}
impl Bunge{
pub fn new(size: usize) -> Bunge{
assert!(size > 0, "Size inputted: {}, was not greater than 0", size);
let ori = Array2::<f64>::zeros((3, size).f());
Bunge{
ori,
}
}
pub fn new_init(ori: Array2<f64>) -> Bunge{
let nrow = ori.rows();
assert!(nrow == 3, "Number of rows of array was: {}, which is not equal to 3", nrow);
{
let strides = ori.strides();
assert!(strides[0] == 1, "The memory stride is not column major (f order)");
}
Bunge{
ori,
}
}
pub fn ori_view(&self) -> ArrayView2<f64>{
self.ori.view()
}
pub fn ori_view_mut(&mut self) -> ArrayViewMut2<f64>{
self.ori.view_mut()
}
}
impl ParallelOriConv for Bunge{
fn par_to_bunge(&self) -> Bunge{
self.clone()
}
fn par_to_rmat(&self) -> RMat{
let nelems = self.ori.len_of(Axis(1));
let mut ori = Array3::<f64>::zeros((3, 3, nelems).f());
par_azip!(mut rmat (ori.axis_iter_mut(Axis(2))), ref bunge (self.ori.axis_iter(Axis(1))) in {
let s1 = bunge[0].sin();
let c1 = bunge[0].cos();
let s2 = bunge[1].sin();
let c2 = bunge[1].cos();
let s3 = bunge[2].sin();
let c3 = bunge[2].cos();
rmat[[0, 0]] = c1 * c3 - s1 * s3 * c2;
rmat[[1, 0]] = -c1 * s3 - s1 * c2 * c3;
rmat[[2, 0]] = s1 * s2;
rmat[[0, 1]] = s1 * c3 + c1 * c2 * s3;
rmat[[1, 1]] = -s1 * s3 + c1 * c2 * c3;
rmat[[2, 1]] = -c1 * s2;
rmat[[0, 2]] = s2 * s3;
rmat[[1, 2]] = s2 * c3;
rmat[[2, 2]] = c2;
});
RMat::new_init(ori)
}
fn par_to_ang_axis(&self) -> AngAxis{
let rmat = self.par_to_rmat();
rmat.par_to_ang_axis()
}
fn par_to_ang_axis_comp(&self) -> AngAxisComp{
let rmat = self.par_to_rmat();
rmat.par_to_ang_axis_comp()
}
fn par_to_rod_vec(&self) -> RodVec{
let rmat = self.par_to_rmat();
rmat.par_to_rod_vec()
}
fn par_to_rod_vec_comp(&self) -> RodVecComp{
let rmat = self.par_to_rmat();
rmat.par_to_rod_vec_comp()
}
fn par_to_quat(&self) -> Quat{
let rmat = self.par_to_rmat();
rmat.par_to_quat()
}
fn par_to_homochoric(&self) -> Homochoric{
let ang_axis = self.par_to_ang_axis();
ang_axis.par_to_homochoric()
}
fn par_to_bunge_inplace(&self, bunge: &mut Bunge){
let ori = self.ori_view();
let mut new_ori = bunge.ori_view_mut();
let new_nelem = new_ori.len_of(Axis(1));
let nelem = ori.len_of(Axis(1));
assert!(new_nelem == nelem,
"The number of elements in the original ori field do no match up with the new field.
The old field had {} elements, and the new field has {} elements",
nelem, new_nelem);
new_ori.assign(&ori);
}
fn par_to_rmat_inplace(&self, rmat: &mut RMat){
let mut ori = rmat.ori_view_mut();
let new_nelem = ori.len_of(Axis(2));
let nelem = self.ori.len_of(Axis(1));
assert!(new_nelem == nelem,
"The number of elements in the original ori field do no match up with the new field.
The old field had {} elements, and the new field has {} elements",
nelem, new_nelem);
par_azip!(mut rmat (ori.axis_iter_mut(Axis(2))), ref bunge (self.ori.axis_iter(Axis(1))) in {
let s1 = bunge[0].sin();
let c1 = bunge[0].cos();
let s2 = bunge[1].sin();
let c2 = bunge[1].cos();
let s3 = bunge[2].sin();
let c3 = bunge[2].cos();
rmat[[0, 0]] = c1 * c3 - s1 * s3 * c2;
rmat[[1, 0]] = -c1 * s3 - s1 * c2 * c3;
rmat[[2, 0]] = s1 * s2;
rmat[[0, 1]] = s1 * c3 + c1 * c2 * s3;
rmat[[1, 1]] = -s1 * s3 + c1 * c2 * c3;
rmat[[2, 1]] = -c1 * s2;
rmat[[0, 2]] = s2 * s3;
rmat[[1, 2]] = s2 * c3;
rmat[[2, 2]] = c2;
});
}
fn par_to_ang_axis_inplace(&self, ang_axis: &mut AngAxis){
let rmat = self.par_to_rmat();
rmat.par_to_ang_axis_inplace(ang_axis);
}
fn par_to_ang_axis_comp_inplace(&self, ang_axis_comp: &mut AngAxisComp){
let rmat = self.par_to_rmat();
rmat.par_to_ang_axis_comp_inplace(ang_axis_comp);
}
fn par_to_rod_vec_inplace(&self, rod_vec: &mut RodVec){
let rmat = self.par_to_rmat();
rmat.par_to_rod_vec_inplace(rod_vec);
}
fn par_to_rod_vec_comp_inplace(&self, rod_vec_comp: &mut RodVecComp){
let rmat = self.par_to_rmat();
rmat.par_to_rod_vec_comp_inplace(rod_vec_comp);
}
fn par_to_quat_inplace(&self, quat: &mut Quat){
let rmat = self.par_to_rmat();
rmat.par_to_quat_inplace(quat);
}
fn par_to_homochoric_inplace(&self, homochoric: &mut Homochoric){
let ang_axis = self.par_to_ang_axis();
ang_axis.par_to_homochoric_inplace(homochoric);
}
}