SingleElementGridBuilder

Struct SingleElementGridBuilder 

Source
pub struct SingleElementGridBuilder<T: Scalar> { /* private fields */ }
Expand description

Grid builder for a single element grid

The following gives an example of creating a new grid consisting of a single triangle.

use ndgrid::traits::Builder;
use ndgrid::SingleElementGridBuilder;
use ndelement::types::ReferenceCellType;

// The geometric dimension of our space is 3.
let gdim = 3;

// We are building a two dimensional surface triangle grid within a three dimensional space.
// Our grid will have three points and one `Triangle` cell of order 1.
let mut builder = SingleElementGridBuilder::new_with_capacity(gdim, 3, 1, (ReferenceCellType::Triangle, 1));
builder.add_point(0, &[0.0, 0.0, 0.0]);
builder.add_point(1, &[1.0, 0.0, 0.0]);
builder.add_point(2, &[0.0, 1.0, 0.0]);
builder.add_cell(0, &[0, 1, 2]);

let grid = builder.create_grid();

Implementations§

Source§

impl<T: Scalar> SingleElementGridBuilder<T>

Source

pub fn new(gdim: usize, data: (ReferenceCellType, usize)) -> Self

Create a new grid builder

Examples found in repository?
ndgrid/examples/test_parallel_io.rs (line 36)
30fn example_single_element_grid<C: Communicator>(
31    comm: &C,
32    n: usize,
33) -> ParallelGridImpl<'_, C, SingleElementGrid<f64, CiarletElement<f64, IdentityMap>>> {
34    let rank = comm.rank();
35
36    let mut b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Quadrilateral, 1));
37
38    if rank == 0 {
39        create_single_element_grid_data(&mut b, n);
40        b.create_parallel_grid_root(comm, GraphPartitioner::None)
41    } else {
42        b.create_parallel_grid(comm, 0)
43    }
44}
More examples
Hide additional examples
ndgrid/examples/test_parallel_grid.rs (line 12)
10fn test_noncontiguous_numbering<C: Communicator>(comm: &C) {
11    let rank = comm.rank();
12    let mut b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Quadrilateral, 1));
13
14    let g = if rank == 0 {
15        let n = 5;
16        for y in 0..n {
17            for x in 0..n {
18                b.add_point(
19                    2 * (y * n + x) + 5,
20                    &[x as f64 / (n - 1) as f64, y as f64 / (n - 1) as f64, 0.0],
21                );
22            }
23        }
24
25        for i in 0..n - 1 {
26            for j in 0..n - 1 {
27                b.add_cell(
28                    3 * (i * (n - 1) + j),
29                    &[
30                        2 * (j * n + i) + 5,
31                        2 * (j * n + i + 1) + 5,
32                        2 * (j * n + i + n) + 5,
33                        2 * (j * n + i + n + 1) + 5,
34                    ],
35                );
36            }
37        }
38
39        b.create_parallel_grid_root(comm, GraphPartitioner::None)
40    } else {
41        b.create_parallel_grid(comm, 0)
42    };
43
44    assert!(g.local_grid().entity_count(ReferenceCellType::Point) > 0);
45}
ndgrid/examples/single_element_grid.rs (line 13)
10fn main() {
11    // When creating the grid builder, we give the physical/geometric dimension (3) and the cell type
12    // and degree of the element
13    let mut b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Quadrilateral, 1));
14    // Add six points with ids 0 to 5
15    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    // Add two cells
22    b.add_cell(0, &[0, 1, 3, 4]);
23    b.add_cell(1, &[1, 2, 4, 5]);
24    // Create the grid
25    let grid = b.create_grid();
26
27    // Print the coordinates or each point in the mesh
28    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    // Print the vertices of each cell
35    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}
ndgrid/examples/parallel_io.rs (line 29)
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}
ndgrid/examples/io.rs (line 53)
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}
ndgrid/examples/test_partitioners.rs (line 16)
13fn run_test<C: Communicator>(comm: &C, partitioner: GraphPartitioner) {
14    let n = 10;
15
16    let mut b = SingleElementGridBuilder::<f64>::new(2, (ReferenceCellType::Quadrilateral, 1));
17
18    let rank = comm.rank();
19    let grid = if rank == 0 {
20        let mut i = 0;
21        for y in 0..n {
22            for x in 0..n {
23                b.add_point(i, &[x as f64 / (n - 1) as f64, y as f64 / (n - 1) as f64]);
24                i += 1;
25            }
26        }
27
28        let mut i = 0;
29        for y in 0..n - 1 {
30            for x in 0..n - 1 {
31                let sw = n * y + x;
32                b.add_cell(i, &[sw, sw + 1, sw + n, sw + n + 1]);
33                i += 1;
34            }
35        }
36
37        b.create_parallel_grid_root(comm, partitioner)
38    } else {
39        b.create_parallel_grid(comm, 0)
40    };
41
42    // Check that owned cells are sorted ahead of ghost cells
43
44    let cell_count_owned = grid
45        .local_grid()
46        .entity_iter(ReferenceCellType::Quadrilateral)
47        .filter(|entity| entity.is_owned())
48        .count();
49
50    // Now check that the first `cell_count_owned` entities are actually owned.
51    for cell in grid
52        .local_grid()
53        .entity_iter(ReferenceCellType::Quadrilateral)
54        .take(cell_count_owned)
55    {
56        assert!(cell.is_owned())
57    }
58
59    // Now make sure that the indices of the global cells are in consecutive order
60
61    let mut cell_global_count = grid.cell_layout().local_range().0;
62
63    for cell in grid
64        .local_grid()
65        .entity_iter(ReferenceCellType::Quadrilateral)
66        .take(cell_count_owned)
67    {
68        assert_eq!(cell.global_index(), cell_global_count);
69        cell_global_count += 1;
70    }
71
72    // Get the global indices.
73
74    let global_vertices = grid
75        .local_grid()
76        .entity_iter(ReferenceCellType::Point)
77        .filter(|e| matches!(e.ownership(), Ownership::Owned))
78        .map(|e| e.global_index())
79        .collect::<Vec<_>>();
80
81    let nvertices = global_vertices.len();
82
83    let global_cells = grid
84        .local_grid()
85        .entity_iter(ReferenceCellType::Quadrilateral)
86        .filter(|e| matches!(e.ownership(), Ownership::Owned))
87        .map(|e| e.global_index())
88        .collect::<Vec<_>>();
89
90    let ncells = global_cells.len();
91
92    let mut total_cells: usize = 0;
93    let mut total_vertices: usize = 0;
94
95    comm.all_reduce_into(&ncells, &mut total_cells, SystemOperation::sum());
96    comm.all_reduce_into(&nvertices, &mut total_vertices, SystemOperation::sum());
97
98    assert_eq!(total_cells, (n - 1) * (n - 1));
99    assert_eq!(total_vertices, n * n);
100}
Source

pub fn new_with_capacity( gdim: usize, npoints: usize, ncells: usize, data: (ReferenceCellType, usize), ) -> Self

Create a new grid builder with capacaty for a given number of points and cells

Trait Implementations§

Source§

impl<T: Scalar> Builder for SingleElementGridBuilder<T>

Source§

type Grid = SingleElementGrid<T, CiarletElement<T, IdentityMap, T>>

The type of the grid that the builder creates
Source§

type T = T

The floating point type used for coordinates
Source§

type CellData<'a> = &'a [usize]

The type of the data that is input to add a cell
Source§

type EntityDescriptor = ReferenceCellType

Type used as identifier of different entity types
Source§

fn add_point(&mut self, id: usize, data: &[T])

Add a point to the grid
Source§

fn add_cell(&mut self, id: usize, cell_data: &[usize])

Add a cell to the grid
Source§

fn add_cell_from_nodes_and_type( &mut self, id: usize, nodes: &[usize], cell_type: ReferenceCellType, cell_degree: usize, )

Add a cell to the grid
Source§

fn create_grid(&self) -> SingleElementGrid<T, CiarletElement<T, IdentityMap, T>>

Create the grid
Source§

fn point_count(&self) -> usize

Number of points
Source§

fn cell_count(&self) -> usize

Number of cells
Source§

fn point_indices_to_ids(&self) -> &[usize]

Get the insertion ids of each point
Source§

fn cell_indices_to_ids(&self) -> &[usize]

Get the insertion ids of each cell
Source§

fn cell_points(&self, index: usize) -> &[usize]

Get the indices of the points of a cell
Source§

fn cell_vertices(&self, index: usize) -> &[usize]

Get the indices of the points of a cell
Source§

fn point(&self, index: usize) -> &[T]

Get the coordinates of a point
Source§

fn points(&self) -> &[T]

Get all points
Source§

fn cell_type(&self, _index: usize) -> ReferenceCellType

Get the type of a cell
Source§

fn cell_degree(&self, _index: usize) -> usize

Get the degree of a cell’s geometry
Source§

fn gdim(&self) -> usize

Geometric dimension
Source§

fn tdim(&self) -> usize

Topoligical dimension
Source§

fn npts(&self, _cell_type: Self::EntityDescriptor, _degree: usize) -> usize

Number of points in a cell with the given type and degree
Source§

impl<T: Debug + Scalar> Debug for SingleElementGridBuilder<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

§

type Err = NoError

The error type produced by a failed conversion.
§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
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
§

impl<T, Dst> ConvAsUtil<Dst> for T

§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
§

impl<T> ConvUtil for T

§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, B> GmshImport for B
where T: FromStr + FromBytes + Debug, <T as FromBytes>::Bytes: Sized, B: Builder<T = T, EntityDescriptor = ReferenceCellType>,

Source§

fn import_from_gmsh_v1(&mut self, s: String)

Generate grid from a Gmsh v1 string
Source§

fn import_from_gmsh_string_v2(&mut self, s: String)

Generate grid from a Gmsh v2 string
Source§

fn import_from_gmsh_binary_v2( &mut self, reader: BufReader<File>, data_size: usize, is_le: bool, )

Generate grid from a Gmsh v2 binary
Source§

fn import_from_gmsh_string_v4(&mut self, s: String)

Generate grid from a Gmsh v4 string
Source§

fn import_from_gmsh_binary_v4( &mut self, reader: BufReader<File>, data_size: usize, is_le: bool, )

Generate grid from a Gmsh v4 binary
Source§

fn import_from_gmsh(&mut self, filename: &str)

Generate grid from Gmsh
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<Src> TryFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
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.
§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
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.
§

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

§

fn vzip(self) -> V

§

impl<Src> ValueFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T, U> Imply<T> for U