1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::atoms::Node;
use crate::containers::mesh::{Mesh, SubMesh};
use crate::error::Result;
/// Build a POI1 mesh holding exactly `nodes`, **one cell per node**, in the
/// given order.
///
/// The [`Coords`](crate::coords::Coords) is taken from the nodes themselves
/// — every [`Node`] carries its own — so no `Coords` argument is needed. The
/// result has a single submesh. Errors if `nodes` is empty (no `Coords` to
/// attach to).
///
/// The companion of [`from_live_nodes`](super::from_live_nodes()), which takes
/// every node of a `Coords` instead of a chosen list, and of
/// [`to_poi1`](super::to_poi1()), which takes an existing mesh.
///
/// ```
/// use pyrucast::atoms::Node;
/// use pyrucast::coords::Coords;
/// use pyrucast::handle::Handle;
/// use pyrucast::ops::mesh::poi1_from_nodes;
///
/// let coords = Handle::new(Coords::new(2).unwrap());
/// let a = Node::create_in(coords.clone(), &[0.0, 0.0]).unwrap();
/// let b = Node::create_in(coords, &[1.0, 0.0]).unwrap();
///
/// let poi1 = poi1_from_nodes(&[a, b]).unwrap();
/// assert_eq!(poi1.cell_counts().unwrap(), vec![2]);
/// ```
pub fn poi1_from_nodes(nodes: &[Node]) -> Result<Mesh> {
Ok(Mesh::from_submesh(SubMesh::poi1_from_nodes(nodes)?))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::atoms::ElementType;
use crate::coords::Coords;
use crate::handle::Handle;
#[test]
fn builds_one_cell_per_node() {
let coords = Handle::new(Coords::new(2).unwrap());
let a = Node::create_in(coords.clone(), &[0.0, 0.0]).unwrap();
let b = Node::create_in(coords.clone(), &[1.0, 0.0]).unwrap();
let m = poi1_from_nodes(&[a, b]).unwrap();
assert_eq!(m.cell_counts().unwrap(), vec![2]);
assert_eq!(m.element_types().unwrap(), vec![ElementType::POI1]);
}
#[test]
fn empty_list_errors() {
assert!(poi1_from_nodes(&[]).is_err());
}
}