single_element_grid/
single_element_grid.rs1use ndelement::types::ReferenceCellType;
2use ndgrid::grid::local_grid::SingleElementGridBuilder;
3use ndgrid::traits::{Builder, Entity, Geometry, Grid, Point, Topology};
4
5fn main() {
11 let mut b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Quadrilateral, 1));
14 b.add_point(0, &[0.0, 0.0, 0.0]);
16 b.add_point(1, &[1.0, 0.0, 0.0]);
17 b.add_point(2, &[2.0, 0.0, 0.2]);
18 b.add_point(3, &[0.0, 1.0, 0.0]);
19 b.add_point(4, &[1.0, 1.0, -0.2]);
20 b.add_point(5, &[2.0, 1.0, 0.0]);
21 b.add_cell(0, &[0, 1, 3, 4]);
23 b.add_cell(1, &[1, 2, 4, 5]);
24 let grid = b.create_grid();
26
27 let mut coords = vec![0.0; grid.geometry_dim()];
29 for point in grid.entity_iter(ReferenceCellType::Point) {
30 point.geometry().points().collect::<Vec<_>>()[0].coords(coords.as_mut_slice());
31 println!("point {}: {:#?}", point.local_index(), coords);
32 }
33
34 for cell in grid.entity_iter(ReferenceCellType::Quadrilateral) {
36 println!(
37 "cell {}: {:?} ",
38 cell.local_index(),
39 cell.topology()
40 .sub_entity_iter(ReferenceCellType::Point)
41 .collect::<Vec<_>>()
42 );
43 }
44}