use crate::containers::mesh::Mesh;
use crate::error::Result;
pub fn sweep_solid(mesh_a: &Mesh, mesh_b: &Mesh, n_layers: usize) -> Result<Mesh> {
crate::ops::mesh::sweep_kernel::solid_between(mesh_a, mesh_b, n_layers)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::ElementType;
use crate::atoms::Node;
use crate::containers::mesh::{Mesh, SubMesh};
use crate::coords::Coords;
use crate::handle::Handle;
fn tri(coords: &crate::handle::Handle<Coords>, pts: [[f64; 3]; 3]) -> (Mesh, [Node; 3]) {
let n0 = Node::create_in(coords.clone(), &pts[0]).unwrap();
let n1 = Node::create_in(coords.clone(), &pts[1]).unwrap();
let n2 = Node::create_in(coords.clone(), &pts[2]).unwrap();
let mut m = Mesh::from_submesh(SubMesh::new(coords.clone(), ElementType::TRI3));
m.add_cell(&[n0.id(), n1.id(), n2.id()]).unwrap();
(m, [n0, n1, n2])
}
#[test]
fn sweep_tri3_to_penta6() {
let coords = Handle::new(Coords::new(3).unwrap());
let (a, na) = tri(&coords, [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]);
let (b, nb) = tri(&coords, [[0.0, 0.0, 2.0], [1.0, 0.0, 2.0], [0.0, 1.0, 2.0]]);
let solid = sweep_solid(&a, &b, 2).unwrap();
assert_eq!(solid.element_types().unwrap(), vec![ElementType::PENTA6]);
assert_eq!(solid.cell_count(), 2);
assert_eq!(solid.node(0, 0, 0).unwrap().id(), na[0].id());
assert_eq!(solid.node(0, 0, 1).unwrap().id(), na[1].id());
assert_eq!(solid.node(0, 0, 2).unwrap().id(), na[2].id());
assert_eq!(solid.node(0, 1, 3).unwrap().id(), nb[0].id());
assert_eq!(solid.node(0, 1, 4).unwrap().id(), nb[1].id());
assert_eq!(solid.node(0, 1, 5).unwrap().id(), nb[2].id());
let mid = solid.node(0, 0, 3).unwrap();
assert!((mid.position().unwrap()[2] - 1.0).abs() < 1e-12);
}
#[test]
fn sweep_shared_edge_stays_shared() {
let coords = Handle::new(Coords::new(3).unwrap());
let a0 = Node::create_in(coords.clone(), &[0.0, 0.0, 0.0]).unwrap();
let a1 = Node::create_in(coords.clone(), &[1.0, 0.0, 0.0]).unwrap();
let a2 = Node::create_in(coords.clone(), &[0.0, 1.0, 0.0]).unwrap();
let a3 = Node::create_in(coords.clone(), &[1.0, 1.0, 0.0]).unwrap();
let mut a = Mesh::from_submesh(SubMesh::new(coords.clone(), ElementType::TRI3));
a.add_cell(&[a0.id(), a1.id(), a2.id()]).unwrap();
a.add_cell(&[a1.id(), a3.id(), a2.id()]).unwrap();
let b0 = Node::create_in(coords.clone(), &[0.0, 0.0, 1.0]).unwrap();
let b1 = Node::create_in(coords.clone(), &[1.0, 0.0, 1.0]).unwrap();
let b2 = Node::create_in(coords.clone(), &[0.0, 1.0, 1.0]).unwrap();
let b3 = Node::create_in(coords.clone(), &[1.0, 1.0, 1.0]).unwrap();
let mut b = Mesh::from_submesh(SubMesh::new(coords.clone(), ElementType::TRI3));
b.add_cell(&[b0.id(), b1.id(), b2.id()]).unwrap();
b.add_cell(&[b1.id(), b3.id(), b2.id()]).unwrap();
let solid = sweep_solid(&a, &b, 3).unwrap();
assert_eq!(solid.cell_count(), 6);
assert_eq!(
solid.node(0, 0, 1).unwrap().id(), solid.node(0, 1, 0).unwrap().id(), );
}
#[test]
fn sweep_rejects_zero_layers() {
let coords = Handle::new(Coords::new(3).unwrap());
let (a, _) = tri(&coords, [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]);
assert!(sweep_solid(&a, &a, 0).is_err());
}
#[test]
fn sweep_rejects_mismatched_types() {
let coords = Handle::new(Coords::new(3).unwrap());
let (a, _) = tri(&coords, [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]);
let q0 = Node::create_in(coords.clone(), &[0.0, 0.0, 1.0]).unwrap();
let q1 = Node::create_in(coords.clone(), &[1.0, 0.0, 1.0]).unwrap();
let q2 = Node::create_in(coords.clone(), &[1.0, 1.0, 1.0]).unwrap();
let q3 = Node::create_in(coords.clone(), &[0.0, 1.0, 1.0]).unwrap();
let mut q = Mesh::from_submesh(SubMesh::new(coords.clone(), ElementType::QUA4));
q.add_cell(&[q0.id(), q1.id(), q2.id(), q3.id()]).unwrap();
assert!(sweep_solid(&a, &q, 1).is_err());
}
}