1use ndelement::types::ReferenceCellType;
2use ndgrid::grid::local_grid::MixedGridBuilder;
3use ndgrid::traits::{Builder, Entity, Geometry, GmshExport, Grid, Point, Topology};
4
5fn main() {
10 let mut b = MixedGridBuilder::<f64>::new(2);
12 b.add_point(0, &[0.0, 0.0]);
14 b.add_point(1, &[0.5, -0.3]);
15 b.add_point(2, &[1.0, 0.0]);
16 b.add_point(3, &[2.0, 0.0]);
17 b.add_point(4, &[-0.3, 0.5]);
18 b.add_point(5, &[0.5, 0.5]);
19 b.add_point(6, &[0.0, 1.0]);
20 b.add_point(7, &[1.0, 1.0]);
21 b.add_point(8, &[2.0, 1.0]);
22 b.add_cell(0, (ReferenceCellType::Triangle, 1, &[2, 7, 6]));
25 b.add_cell(1, (ReferenceCellType::Triangle, 2, &[0, 2, 6, 5, 4, 1]));
28 b.add_cell(2, (ReferenceCellType::Quadrilateral, 1, &[2, 3, 7, 8]));
30 let grid = b.create_grid();
32
33 for cell in grid.entity_iter(ReferenceCellType::Triangle) {
37 println!(
38 "triangle cell {}: {:?}",
39 cell.local_index(),
40 cell.topology()
41 .sub_entity_iter(ReferenceCellType::Point)
42 .collect::<Vec<_>>(),
43 );
44 }
45 let mut coords = vec![0.0; 2];
48 for cell in grid.entity_iter(ReferenceCellType::Triangle) {
49 println!("triangle cell {}:", cell.local_index());
50 for p in cell.geometry().points() {
51 p.coords(&mut coords);
52 println!(" point {}: {:?}", p.index(), coords);
53 }
54 }
55 for cell in grid.entity_iter(ReferenceCellType::Quadrilateral) {
57 println!(
58 "quadrilateral cell {}: {:?} ",
59 cell.local_index(),
60 cell.topology()
61 .sub_entity_iter(ReferenceCellType::Point)
62 .collect::<Vec<_>>()
63 );
64 }
65
66 grid.export_as_gmsh("_mixed.msh");
68}