GmshExport

Trait GmshExport 

Source
pub trait GmshExport: Grid {
    // Required method
    fn to_gmsh_string(&self) -> String;

    // Provided method
    fn export_as_gmsh(&self, filename: &str) { ... }
}
Expand description

Grid export for Gmsh

Required Methods§

Source

fn to_gmsh_string(&self) -> String

Generate the Gmsh string for a grid

Provided Methods§

Source

fn export_as_gmsh(&self, filename: &str)

Export as Gmsh

Examples found in repository?
ndgrid/examples/io.rs (line 50)
13fn main() {
14    // Create a grid using the shapes module: unit_cube_boundary will mesh the surface of a cube
15    let g = shapes::unit_cube_boundary::<f64>(4, 5, 4, ReferenceCellType::Triangle);
16
17    // If the serde option is used, the raw grid data can be exported in RON format
18    g.export_as_ron("_unit_cube_boundary.ron");
19
20    // A grid can be re-imported from raw RON data
21    let g2 = SingleElementGrid::<f64, CiarletElement<f64, IdentityMap>>::import_from_ron(
22        "_unit_cube_boundary.ron",
23    );
24
25    // Print the first 5 cells of each grid
26    println!("The first 5 cells of the grids");
27    for (cell, cell2) in izip!(
28        g.entity_iter(ReferenceCellType::Triangle),
29        g2.entity_iter(ReferenceCellType::Triangle)
30    )
31    .take(5)
32    {
33        println!(
34            "{:?} {:?}",
35            cell.topology()
36                .sub_entity_iter(ReferenceCellType::Point)
37                .collect::<Vec<_>>(),
38            cell2
39                .topology()
40                .sub_entity_iter(ReferenceCellType::Point)
41                .collect::<Vec<_>>(),
42        );
43    }
44
45    println!();
46
47    // Alternatively, grids can be exported and imported to/from Gmsh files
48
49    // Export the grid as a Gmsh .msh file
50    g.export_as_gmsh("_unit_cube_boundary.msh");
51
52    // To import from a Gmsh .msh file, a builder is used
53    let mut b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Triangle, 1));
54    b.import_from_gmsh("_unit_cube_boundary.msh");
55    let g3 = b.create_grid();
56
57    // Print the first 5 cells of each grid
58    println!("The first 5 cells of the grids");
59    for (cell, cell3) in izip!(
60        g.entity_iter(ReferenceCellType::Triangle),
61        g3.entity_iter(ReferenceCellType::Triangle)
62    )
63    .take(5)
64    {
65        println!(
66            "{:?} {:?}",
67            cell.topology()
68                .sub_entity_iter(ReferenceCellType::Point)
69                .collect::<Vec<_>>(),
70            cell3
71                .topology()
72                .sub_entity_iter(ReferenceCellType::Point)
73                .collect::<Vec<_>>(),
74        );
75    }
76}
More examples
Hide additional examples
ndgrid/examples/mixed_grid.rs (line 67)
9fn main() {
10    // When creating the grid builder, we give the physical/geometric dimension (3)
11    let mut b = MixedGridBuilder::<f64>::new(2);
12    // Add nine points with ids 0 to 8
13    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    // Add a linear triangle cell. The inputs to add_cell are
23    // (id, (cell type, cell degree, vertices))
24    b.add_cell(0, (ReferenceCellType::Triangle, 1, &[2, 7, 6]));
25    // Add a quadratic triangle cell. The edge that is shared with cell 0 is straight to ensure
26    // that there are no discontinuities in the grid.
27    b.add_cell(1, (ReferenceCellType::Triangle, 2, &[0, 2, 6, 5, 4, 1]));
28    // Add a quadrilateral cell
29    b.add_cell(2, (ReferenceCellType::Quadrilateral, 1, &[2, 3, 7, 8]));
30    // Create the grid
31    let grid = b.create_grid();
32
33    // Print the vertices of each triangle cell: this will only include the three points
34    // for each cell as these are the topological vertices (ie the 0-dimensional entities at
35    // each corner of the cell), not the geometric points
36    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    // Print the geometric points that definie each cells position in space. Note that
46    // The indexing of these points may differ from the indexing used for the topological vertices.
47    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    // Print the vertices of each quadrilateral cell
56    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    // Export the mesh in Gmsh format
67    grid.export_as_gmsh("_mixed.msh");
68}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<G: Grid<EntityDescriptor = ReferenceCellType>> GmshExport for G