unit_cube_boundary

Function unit_cube_boundary 

Source
pub fn unit_cube_boundary<T: Scalar>(
    nx: usize,
    ny: usize,
    nz: usize,
    cell_type: ReferenceCellType,
) -> SingleElementGrid<T, CiarletElement<T, IdentityMap, T>>
Expand description

Create a grid of the boundary of a unit cube

The unit cube is the cube with corners at (0,0,0), (1,0,0), (0,1,0), (1,1,0), (0,0,1), (1,0,1), (0,1,1) and (1,1,1)

Examples found in repository?
ndgrid/examples/parallel_io.rs (line 24)
17fn main() {
18    let universe: Universe = mpi::initialize().unwrap();
19    let comm = universe.world();
20    let rank = comm.rank();
21
22    let g = if rank == 0 {
23        // Create a grid using the shapes module: unit_cube_boundary will mesh the surface of a cube
24        let serial_g = shapes::unit_cube_boundary::<f64>(4, 5, 4, ReferenceCellType::Triangle);
25
26        // Distribute this grid across processes
27        serial_g.distribute(&comm, GraphPartitioner::None)
28    } else {
29        let b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Triangle, 1));
30        b.create_parallel_grid(&comm, 0)
31    };
32
33    // If the serde option is used, the raw grid data can be exported in RON format
34    g.export_as_ron("_unit_cube_boundary_parallel.ron");
35
36    // Wait for export to finish
37    comm.barrier();
38
39    // A grid can be re-imported from raw RON data. Note that it must be imported on the same number of processes as it was exported using
40    let g2 = ParallelGridImpl::<'_, _, SingleElementGrid::<f64, CiarletElement<f64, IdentityMap>>>::import_from_ron(&comm, "_unit_cube_boundary_parallel.ron");
41
42    // Print the first 5 cells of each grid on process 0
43    if rank == 0 {
44        println!("The first 5 cells of the grids");
45        for (cell, cell2) in izip!(
46            g.local_grid().entity_iter(ReferenceCellType::Triangle),
47            g2.local_grid().entity_iter(ReferenceCellType::Triangle)
48        )
49        .take(5)
50        {
51            println!(
52                "{:?} {:?}",
53                cell.topology()
54                    .sub_entity_iter(ReferenceCellType::Point)
55                    .collect::<Vec<_>>(),
56                cell2
57                    .topology()
58                    .sub_entity_iter(ReferenceCellType::Point)
59                    .collect::<Vec<_>>(),
60            );
61        }
62    }
63}
More examples
Hide additional examples
ndgrid/examples/io.rs (line 15)
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}