use crate::numerical::matrix::Matrix;
use crate::physics::physics_sim::linear_elasticity;
#[unsafe(no_mangle)]
pub extern "C" fn rssn_physics_sim_linear_elasticity_simulate_cantilever() -> *mut Matrix<f64> {
let beam_length = 10.0;
let beam_height = 2.0;
let nx = 10;
let ny = 2;
let mut nodes = Vec::new();
for j in 0..=ny {
for i in 0..=nx {
nodes.push((
i as f64 * beam_length / nx as f64,
j as f64 * beam_height / ny as f64,
));
}
}
let mut elements = Vec::new();
for j in 0..ny {
for i in 0..nx {
let n1 = j * (nx + 1) + i;
let n2 = j * (nx + 1) + i + 1;
let n3 = (j + 1) * (nx + 1) + i + 1;
let n4 = (j + 1) * (nx + 1) + i;
elements.push([n1, n2, n3, n4]);
}
}
let fixed_nodes: Vec<usize> = (0..=ny).map(|j| j * (nx + 1)).collect();
let loads = vec![((ny / 2) * (nx + 1) + nx, 0.0, -1e3)];
let params = linear_elasticity::ElasticityParameters {
nodes,
elements,
youngs_modulus: 1e7,
poissons_ratio: 0.3,
fixed_nodes,
loads,
};
match linear_elasticity::run_elasticity_simulation(¶ms) {
| Ok(d) => {
let n = d.len() / 2;
Box::into_raw(Box::new(Matrix::new(n, 2, d)))
},
| Err(_) => std::ptr::null_mut(),
}
}