Skip to content

Commit

Permalink
Replace nalgebra types in the input and output data by plain arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
stfnp committed Aug 27, 2024
1 parent ef65673 commit cceea9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
19 changes: 9 additions & 10 deletions solver/src/bow/output.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::fs::File;
use std::io::{BufReader, Write};
use std::path::Path;
use nalgebra::{SMatrix, SVector};
use serde::{Deserialize, Serialize};
use soa_derive::StructOfArray;
use rmpv::Value;
Expand Down Expand Up @@ -129,16 +128,16 @@ pub struct State {
pub time: f64,
pub draw_length: f64,

pub limb_pos: Vec<SVector<f64, 3>>, // x, y, φ
pub limb_vel: Vec<SVector<f64, 3>>, // x, y, φ
pub limb_acc: Vec<SVector<f64, 3>>, // x, y, φ
pub limb_pos: Vec<[f64; 3]>, // x, y, φ
pub limb_vel: Vec<[f64; 3]>, // x, y, φ
pub limb_acc: Vec<[f64; 3]>, // x, y, φ

pub string_pos: Vec<SVector<f64, 2>>, // x, y
pub string_vel: Vec<SVector<f64, 2>>, // x, y
pub string_acc: Vec<SVector<f64, 2>>, // x, y
pub string_pos: Vec<[f64; 2]>, // x, y
pub string_vel: Vec<[f64; 2]>, // x, y
pub string_acc: Vec<[f64; 2]>, // x, y

pub limb_strain: Vec<SVector<f64, 3>>, // epsilon, kappa, gamma
pub limb_force: Vec<SVector<f64, 3>>, // N, M, Q
pub limb_strain: Vec<[f64; 3]>, // epsilon, kappa, gamma
pub limb_force: Vec<[f64; 3]>, // N, M, Q

pub layer_strain: Vec<Vec<(f64, f64)>>, // layer, point, back/belly
pub layer_stress: Vec<Vec<(f64, f64)>>, // layer, point, back/belly
Expand Down Expand Up @@ -166,7 +165,7 @@ pub struct LimbSetup {

// Geometry at eval points
pub length: Vec<f64>,
pub position: Vec<SVector<f64, 3>>, // x, y, φ
pub position: Vec<[f64; 3]>, // x, y, φ
pub width: Vec<f64>,
pub height: Vec<f64>,
}
Expand Down
28 changes: 14 additions & 14 deletions solver/src/bow/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'a> Simulation<'a> {
// Additional setup data
let limb_position = s_eval.iter().map(|&s| {
let position = profile.position(s);
vector![position[0], position[1], profile.angle(s)]
[position[0], position[1], profile.angle(s)]
}).collect();
let limb_width = s_eval.iter().map(|&s| { section.width(s) }).collect();
let limb_height = s_eval.iter().map(|&s| { section.height(s) }).collect();
Expand Down Expand Up @@ -306,13 +306,13 @@ impl<'a> Simulation<'a> {
let limb_tip = self.limb_nodes.last().unwrap();

let string_pos = self.string_node.map(|node| vec![
vector![ system.get_displacement(limb_tip.x()), system.get_displacement(limb_tip.y()) ],
vector![ system.get_displacement(node.x()), system.get_displacement(node.y()) ],
[ system.get_displacement(limb_tip.x()), system.get_displacement(limb_tip.y()) ],
[ system.get_displacement(node.x()), system.get_displacement(node.y()) ],
]).unwrap_or_default();

let string_vel = self.string_node.map(|node| vec![
vector![ system.get_velocity(limb_tip.x()), system.get_velocity(limb_tip.y()) ],
vector![ system.get_velocity(node.x()), system.get_velocity(node.y()) ],
[ system.get_velocity(limb_tip.x()), system.get_velocity(limb_tip.y()) ],
[ system.get_velocity(node.x()), system.get_velocity(node.y()) ],
]).unwrap_or_default();

/*
Expand All @@ -324,15 +324,15 @@ impl<'a> Simulation<'a> {

// Evaluate positions, forces and strains at the limb's evaluation points

let mut limb_pos = Vec::new(); // TODO: Capacity
let mut limb_strain = Vec::<SVector<f64, 3>>::new(); // TODO: Capacity
let mut limb_force = Vec::<SVector<f64, 3>>::new(); // TODO: Capacity
let mut limb_pos = Vec::<[f64; 3]>::new(); // TODO: Capacity
let mut limb_strain = Vec::<[f64; 3]>::new(); // TODO: Capacity
let mut limb_force = Vec::<[f64; 3]>::new(); // TODO: Capacity

for &element in &self.limb_elements {
let element = system.element_ref::<BeamElementCoRot>(element);
element.eval_positions().for_each(|u| limb_pos.push(u));
element.eval_strains().for_each(|e| limb_strain.push(e));
element.eval_forces().for_each(|f| limb_force.push(f));
element.eval_positions().for_each(|u| limb_pos.push(u.into()));
element.eval_strains().for_each(|e| limb_strain.push(e.into()));
element.eval_forces().for_each(|f| limb_force.push(f.into()));
}

// The grip force is the y component of the forces at the start of the limb.
Expand All @@ -355,12 +355,12 @@ impl<'a> Simulation<'a> {
draw_length,

limb_pos,
limb_vel: vec![SVector::zeros(); self.model.settings.n_limb_eval_points],
limb_acc: vec![SVector::zeros(); self.model.settings.n_limb_eval_points],
limb_vel: vec![[0.0; 3]; self.model.settings.n_limb_eval_points],
limb_acc: vec![[0.0; 3]; self.model.settings.n_limb_eval_points],

string_pos,
string_vel,
string_acc: vec![SVector::zeros(); 2],
string_acc: vec![[0.0; 2]; 2],

limb_strain,
limb_force,
Expand Down

0 comments on commit cceea9c

Please sign in to comment.