Struct Features

Source
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 edge
  • e – 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 face
  • f – 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:

  1. Here, a boundary point is such that it belongs to a boundary edge or a boundary face
  2. An interior point is such that it belongs to an interior edge or an interior face
  3. 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:

  1. In 2D, a boundary edge is such that it is shared by one 2D cell only (1D cells are ignored)
  2. In 3D, a boundary edge belongs to a boundary face
  3. In 2D, an interior edge is such that it is shared by more than one 2D cell (1D cells are ignored)
  4. 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:

  1. A boundary face is such that it is shared by one 3D cell only (2D cells are ignored)
  2. 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>

Source

pub fn new(mesh: &'a Mesh, extract_all: bool) -> Self

Extracts features

§Input
  • mesh – the mesh
  • extract_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
Source

pub fn get_edge(&self, a: usize, b: usize) -> &Feature

Returns an edge or panics

Source

pub fn get_face(&self, a: usize, b: usize, c: usize, d: usize) -> &Feature

Returns an face or panics

Source

pub fn get_neighbors_2d(&self, cell_id: CellId) -> Vec<(usize, CellId, usize)>

Returns all neighbors of a 2D cell

§Input
  • mesh – the mesh
  • edges – the edge-to-cells map
  • e – 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 contact
  • neigh_cell_id – is the ID of the neighbor cell
  • neigh_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(())
}
Source

pub fn search_point_ids<F>( &self, at: At, filter: F, ) -> Result<Vec<PointId>, StrError>
where F: FnMut(&[f64]) -> bool,

Searches point ids

§Input
  • at – the constraint
  • filter – function fn(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
Source

pub fn search_edge_keys<F>( &self, at: At, filter: F, ) -> Result<Vec<EdgeKey>, StrError>
where F: FnMut(&[f64]) -> bool,

Searches edge keys

§Input
  • at – the constraint
  • filter – function fn(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
Source

pub fn search_face_keys<F>( &self, at: At, filter: F, ) -> Result<Vec<FaceKey>, StrError>
where F: FnMut(&[f64]) -> bool,

Searches face keys

§Input
  • at – the constraint
  • filter – function fn(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
Source

pub fn search_edges<F>( &self, at: At, filter: F, ) -> Result<Vec<&Feature>, StrError>
where F: FnMut(&[f64]) -> bool,

Searches edges

§Input
  • at – the constraint
  • filter – function fn(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
Source

pub fn search_faces<F>( &self, at: At, filter: F, ) -> Result<Vec<&Feature>, StrError>
where F: FnMut(&[f64]) -> bool,

Searches faces

§Input
  • at – the constraint
  • filter – function fn(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
Source

pub fn search_many_edges<F>( &self, ats: &[At], filter: F, ) -> Result<Vec<&Feature>, StrError>
where F: FnMut(&[f64]) -> bool,

Searches many edges using a list of constraints

§Input
  • at – the constraint
  • filter – function fn(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 the ats must generate at least one edge, otherwise an error will occur.
Source

pub fn search_many_faces<F>( &self, ats: &[At], filter: F, ) -> Result<Vec<&Feature>, StrError>
where F: FnMut(&[f64]) -> bool,

Search many faces using a list of constraints

§Input
  • at – the constraint
  • filter – function fn(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 the ats must generate at least one face, otherwise an error will occur.

Auto Trait Implementations§

§

impl<'a> Freeze for Features<'a>

§

impl<'a> RefUnwindSafe for Features<'a>

§

impl<'a> Send for Features<'a>

§

impl<'a> Sync for Features<'a>

§

impl<'a> Unpin for Features<'a>

§

impl<'a> UnwindSafe for Features<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V