pub struct Features<'a> {
pub all_2d_edges: MapEdge2dToCells,
pub all_faces: MapFaceToCells,
pub points: HashSet<PointId>,
pub edges: HashMap<EdgeKey, Feature>,
pub faces: HashMap<FaceKey, Feature>,
pub lines: Vec<CellId>,
pub min: Vec<f64>,
pub max: Vec<f64>,
pub grid: GridSearch,
pub point_to_edges: MapPointToEdges,
pub point_to_faces: MapPointToFaces,
/* private fields */
}
Expand description
Holds points, edges and faces on the mesh boundary or interior
§Examples
§Two-dimensions
use gemlab::mesh::{At, Cell, Features, Mesh, Point};
use gemlab::shapes::GeoKind;
use gemlab::StrError;
fn main() -> Result<(), StrError> {
// 3---------2---------5
// | | |
// | [0] | [1] |
// | | |
// 0---------1---------4
#[rustfmt::skip]
let mesh = Mesh {
ndim: 2,
points: vec![
Point { id: 0, marker: 0, coords: vec![0.0, 0.0] },
Point { id: 1, marker: 0, coords: vec![1.0, 0.0] },
Point { id: 2, marker: 0, coords: vec![1.0, 1.0] },
Point { id: 3, marker: 0, coords: vec![0.0, 1.0] },
Point { id: 4, marker: 0, coords: vec![2.0, 0.0] },
Point { id: 5, marker: 0, coords: vec![2.0, 1.0] },
],
cells: vec![
Cell { id: 0, attribute: 1, kind: GeoKind::Qua4, points: vec![0, 1, 2, 3] },
Cell { id: 1, attribute: 2, kind: GeoKind::Qua4, points: vec![1, 4, 5, 2] },
],
};
let features = Features::new(&mesh, false);
let mut points: Vec<_> = features.points.iter().copied().collect();
points.sort();
assert_eq!(points, [0, 1, 2, 3, 4, 5]);
let mut edges: Vec<_> = features.edges.keys().copied().collect();
edges.sort();
assert_eq!(edges, [(0, 1), (0, 3), (1, 4), (2, 3), (2, 5), (4, 5)]);
Ok(())
}
§Three-dimensions
use gemlab::mesh::{At, Cell, Features, Mesh, Point};
use gemlab::shapes::GeoKind;
use gemlab::StrError;
fn main() -> Result<(), StrError> {
// .4--------------7
// ,' | ,'|
// ,' ,' |
// ,' | ,' |
// 5'==============6' |
// | | |
// | | | |
// | ,0- - - | - - - 3
// | ,' | ,'
// | ,' | ,'
// | ,' | ,'
// 1'--------------2'
#[rustfmt::skip]
let mesh = Mesh {
ndim: 3,
points: vec![
Point { id: 0, marker: 0, coords: vec![0.0, 0.0, 0.0] },
Point { id: 1, marker: 0, coords: vec![1.0, 0.0, 0.0] },
Point { id: 2, marker: 0, coords: vec![1.0, 1.0, 0.0] },
Point { id: 3, marker: 0, coords: vec![0.0, 1.0, 0.0] },
Point { id: 4, marker: 0, coords: vec![0.0, 0.0, 1.0] },
Point { id: 5, marker: 0, coords: vec![1.0, 0.0, 1.0] },
Point { id: 6, marker: 0, coords: vec![1.0, 1.0, 1.0] },
Point { id: 7, marker: 0, coords: vec![0.0, 1.0, 1.0] },
],
cells: vec![
Cell { id: 0, attribute: 1, kind: GeoKind::Hex8,
points: vec![0,1,2,3, 4,5,6,7] },
],
};
let features = Features::new(&mesh, false);
let mut points: Vec<_> = features.points.iter().copied().collect();
points.sort();
assert_eq!(points, (0..8).collect::<Vec<_>>());
let mut edges: Vec<_> = features.edges.keys().copied().collect();
edges.sort();
#[rustfmt::skip]
assert_eq!(
edges,
[
(0, 1), (0, 3), (0, 4), (1, 2),
(1, 5), (2, 3), (2, 6), (3, 7),
(4, 5), (4, 7), (5, 6), (6, 7)
]
);
let mut faces: Vec<_> = features.faces.keys().copied().collect();
faces.sort();
assert_eq!(
faces,
[
(0, 1, 2, 3),
(0, 1, 4, 5),
(0, 3, 4, 7),
(1, 2, 5, 6),
(2, 3, 6, 7),
(4, 5, 6, 7),
]
);
Ok(())
}
Fields§
§all_2d_edges: MapEdge2dToCells
Maps all edge keys to cells sharing the edge (2D only)
Relates edge keys to Vec<(cell_id, e)>
where:
cell_id
– is he id of the cell sharing the edgee
– is the cell’s local edge index
all_faces: MapFaceToCells
Maps all face keys to cells sharing the face (3D only)
Relates face keys to Vec<(cell_id, f)>
where:
cell_id
– is the id of the cell sharing the facef
– is the cell’s local face index
points: HashSet<PointId>
Set of points on the boundary edges/faces, on the interior edges/faces, or both boundary and interior
Notes:
- Here, a boundary point is such that it belongs to a boundary edge or a boundary face
- An interior point is such that it belongs to an interior edge or an interior face
- Thus, for the interior case, we save only the points on interior edges and faces and not inside cells. For example, the central nodes of a Qua9 are not saved.
edges: HashMap<EdgeKey, Feature>
Set of edges on the mesh boundary, interior, or both boundary and interior
Notes:
- In 2D, a boundary edge is such that it is shared by one 2D cell only (1D cells are ignored)
- In 3D, a boundary edge belongs to a boundary face
- In 2D, an interior edge is such that it is shared by more than one 2D cell (1D cells are ignored)
- In 3D, an interior edge belongs to an interior face
faces: HashMap<FaceKey, Feature>
Set of faces on the mesh boundary, interior, or both boundary and interior
Notes:
- A boundary face is such that it is shared by one 3D cell only (2D cells are ignored)
- An interior face is such that it is shared by more than one 3D cell (2D cells are ignored)
lines: Vec<CellId>
Holds the ids of linear cells (GeoKind::Lin) in 2D or 3D
min: Vec<f64>
The minimum coordinates of the points (space_ndim)
max: Vec<f64>
The maximum coordinates of the points (space_ndim)
grid: GridSearch
Tool to quickly search points by coordinates
point_to_edges: MapPointToEdges
Maps a point id to edges sharing the point
point_to_faces: MapPointToFaces
Maps a point id to faces sharing the point
Implementations§
Source§impl<'a> Features<'a>
impl<'a> Features<'a>
Sourcepub fn new(mesh: &'a Mesh, extract_all: bool) -> Self
pub fn new(mesh: &'a Mesh, extract_all: bool) -> Self
Extracts features
§Input
mesh
– the meshextract_all
– if true, will extract the boundary and the interior features. Otherwise, if false, will extract the boundary only
§Notes
- You may want to call Mesh::check_all to capture (some) errors of the mesh first
§Panics
- This function will panic if the mesh data is invalid. For instance, when the cell points array doesn’t contain enough points or the indices are incorrect
Sourcepub fn get_face(&self, a: usize, b: usize, c: usize, d: usize) -> &Feature
pub fn get_face(&self, a: usize, b: usize, c: usize, d: usize) -> &Feature
Returns an face or panics
Sourcepub fn get_neighbors_2d(&self, cell_id: CellId) -> Vec<(usize, CellId, usize)>
pub fn get_neighbors_2d(&self, cell_id: CellId) -> Vec<(usize, CellId, usize)>
Returns all neighbors of a 2D cell
§Input
mesh
– the meshedges
– the edge-to-cells mape
– the index of the edge (see GeoKind::edge_node_id)
§Output
Returns a vector with the pairs (e, neigh_cell_id, neigh_e)
where:
e
– the local edge of this cell through which the neighbor is in contactneigh_cell_id
– is the ID of the neighbor cellneigh_e
– is the neighbor’s local edge through which this cell is in contact
§Examples
use gemlab::mesh::{Cell, Features, Mesh, Point};
use gemlab::shapes::GeoKind;
use gemlab::StrError;
fn main() -> Result<(), StrError> {
// 3---------2---------5
// | | |
// | [0] | [1] |
// | | |
// 0---------1---------4
#[rustfmt::skip]
let mesh = Mesh {
ndim: 2,
points: vec![
Point { id: 0, marker: 0, coords: vec![0.0, 0.0] },
Point { id: 1, marker: 0, coords: vec![1.0, 0.0] },
Point { id: 2, marker: 0, coords: vec![1.0, 1.0] },
Point { id: 3, marker: 0, coords: vec![0.0, 1.0] },
Point { id: 4, marker: 0, coords: vec![2.0, 0.0] },
Point { id: 5, marker: 0, coords: vec![2.0, 1.0] },
],
cells: vec![
Cell { id: 0, attribute: 1, kind: GeoKind::Qua4, points: vec![0, 1, 2, 3] },
Cell { id: 1, attribute: 2, kind: GeoKind::Qua4, points: vec![1, 4, 5, 2] },
],
};
let features = Features::new(&mesh, true);
let neighbors = features.get_neighbors_2d(0);
assert_eq!(neighbors.len(), 1);
assert!(neighbors.contains(&(1, 1, 3)));
let neighbors = features.get_neighbors_2d(1);
assert_eq!(neighbors.len(), 1);
assert!(neighbors.contains(&(3, 0, 1)));
Ok(())
}
Sourcepub fn search_point_ids<F>(
&self,
at: At,
filter: F,
) -> Result<Vec<PointId>, StrError>
pub fn search_point_ids<F>( &self, at: At, filter: F, ) -> Result<Vec<PointId>, StrError>
Searches point ids
§Input
at
– the constraintfilter
– functionfn(x) -> bool
that returns true to keep the coordinate just found (yields only the elements for which the closure returns true). Use|_| true
or crate::util::any_x to allow any point in the resulting array. Example of filter:|x| x[0] > 1.4 && x[0] < 1.6
§Output
- If at least one point has been found, returns a sorted array of point ids.
- Otherwise, returns an error
Sourcepub fn search_edge_keys<F>(
&self,
at: At,
filter: F,
) -> Result<Vec<EdgeKey>, StrError>
pub fn search_edge_keys<F>( &self, at: At, filter: F, ) -> Result<Vec<EdgeKey>, StrError>
Searches edge keys
§Input
at
– the constraintfilter
– functionfn(x) -> bool
that returns true to keep the coordinate just found (yields only the elements for which the closure returns true). Use|_| true
or crate::util::any_x to allow any point in the resulting array. Example of filter:|x| x[0] > 1.4 && x[0] < 1.6
§Output
- If at least one point has been found, returns a sorted array of edge keys
- Otherwise, returns an error
Sourcepub fn search_face_keys<F>(
&self,
at: At,
filter: F,
) -> Result<Vec<FaceKey>, StrError>
pub fn search_face_keys<F>( &self, at: At, filter: F, ) -> Result<Vec<FaceKey>, StrError>
Searches face keys
§Input
at
– the constraintfilter
– functionfn(x) -> bool
that returns true to keep the coordinate just found (yields only the elements for which the closure returns true). Use|_| true
or crate::util::any_x to allow any point in the resulting array. Example of filter:|x| x[0] > 1.4 && x[0] < 1.6
§Output
- If at least one point has been found, returns a sorted array of face keys
- Otherwise, returns an error
Sourcepub fn search_edges<F>(
&self,
at: At,
filter: F,
) -> Result<Vec<&Feature>, StrError>
pub fn search_edges<F>( &self, at: At, filter: F, ) -> Result<Vec<&Feature>, StrError>
Searches edges
§Input
at
– the constraintfilter
– functionfn(x) -> bool
that returns true to keep the coordinate just found (yields only the elements for which the closure returns true). Use|_| true
or crate::util::any_x to allow any point in the resulting array. Example of filter:|x| x[0] > 1.4 && x[0] < 1.6
§Output
- If at least one point has been found, returns an array such that the edge keys are sorted
- Otherwise, returns an error
Sourcepub fn search_faces<F>(
&self,
at: At,
filter: F,
) -> Result<Vec<&Feature>, StrError>
pub fn search_faces<F>( &self, at: At, filter: F, ) -> Result<Vec<&Feature>, StrError>
Searches faces
§Input
at
– the constraintfilter
– functionfn(x) -> bool
that returns true to keep the coordinate just found (yields only the elements for which the closure returns true). Use|_| true
or crate::util::any_x to allow any point in the resulting array. Example of filter:|x| x[0] > 1.4 && x[0] < 1.6
§Output
- If at least one point has been found, returns an array such that the face keys are sorted
- Otherwise, returns an error
Sourcepub fn search_many_edges<F>(
&self,
ats: &[At],
filter: F,
) -> Result<Vec<&Feature>, StrError>
pub fn search_many_edges<F>( &self, ats: &[At], filter: F, ) -> Result<Vec<&Feature>, StrError>
Searches many edges using a list of constraints
§Input
at
– the constraintfilter
– functionfn(x) -> bool
that returns true to keep the coordinate just found (yields only the elements for which the closure returns true). Use|_| true
or crate::util::any_x to allow any point in the resulting array. Example of filter:|x| x[0] > 1.4 && x[0] < 1.6
§Output
- Returns edges sorted by keys
- Warning Every
At
in theats
must generate at least one edge, otherwise an error will occur.
Sourcepub fn search_many_faces<F>(
&self,
ats: &[At],
filter: F,
) -> Result<Vec<&Feature>, StrError>
pub fn search_many_faces<F>( &self, ats: &[At], filter: F, ) -> Result<Vec<&Feature>, StrError>
Search many faces using a list of constraints
§Input
at
– the constraintfilter
– functionfn(x) -> bool
that returns true to keep the coordinate just found (yields only the elements for which the closure returns true). Use|_| true
or crate::util::any_x to allow any point in the resulting array. Example of filter:|x| x[0] > 1.4 && x[0] < 1.6
§Output
- Returns faces sorted by keys
- Warning Every
At
in theats
must generate at least one face, otherwise an error will occur.