1use crate::{traits::Grid, types::Scalar};
3#[cfg(feature = "mpi")]
4use crate::{traits::ParallelGrid, types::GraphPartitioner};
5#[cfg(feature = "mpi")]
6use mpi::traits::Communicator;
7use std::fmt::Debug;
8use std::hash::Hash;
9
10pub trait Builder {
15 type EntityDescriptor: Debug + PartialEq + Eq + Clone + Copy + Hash;
17
18 type Grid: Grid<EntityDescriptor = Self::EntityDescriptor>;
20 type T: Scalar;
22 type CellData<'a>;
24
25 fn add_point(&mut self, id: usize, data: &[Self::T]);
27
28 fn add_cell(&mut self, id: usize, cell_data: Self::CellData<'_>);
30
31 fn add_cell_from_nodes_and_type(
33 &mut self,
34 id: usize,
35 nodes: &[usize],
36 cell_type: Self::EntityDescriptor,
37 cell_degree: usize,
38 );
39
40 fn create_grid(&self) -> Self::Grid;
42
43 fn point_count(&self) -> usize;
45
46 fn cell_count(&self) -> usize;
48
49 fn point_indices_to_ids(&self) -> &[usize];
51
52 fn cell_indices_to_ids(&self) -> &[usize];
54
55 fn cell_points(&self, index: usize) -> &[usize];
57
58 fn cell_vertices(&self, index: usize) -> &[usize];
60
61 fn point(&self, index: usize) -> &[Self::T];
63
64 fn points(&self) -> &[Self::T];
66
67 fn cell_type(&self, index: usize) -> Self::EntityDescriptor;
69
70 fn cell_degree(&self, index: usize) -> usize;
72
73 fn gdim(&self) -> usize;
75
76 fn tdim(&self) -> usize;
78
79 fn npts(&self, cell_type: Self::EntityDescriptor, degree: usize) -> usize;
81}
82
83pub(crate) trait GeometryBuilder: Builder {
88 type GridGeometry;
90
91 fn create_geometry(
93 &self,
94 point_ids: &[usize],
95 coordinates: &[Self::T],
96 cell_points: &[usize],
97 cell_types: &[Self::EntityDescriptor],
98 cell_degrees: &[usize],
99 ) -> Self::GridGeometry;
100}
101
102pub(crate) trait TopologyBuilder: Builder {
107 type GridTopology;
109
110 fn create_topology(
112 &self,
113 vertex_ids: Vec<usize>,
114 cell_ids: Vec<usize>,
115 cells: &[usize],
116 cell_types: &[Self::EntityDescriptor],
117 ) -> Self::GridTopology;
118
119 fn extract_vertices(
121 &self,
122 cell_points: &[usize],
123 cell_types: &[Self::EntityDescriptor],
124 cell_degrees: &[usize],
125 ) -> Vec<usize>;
126}
127
128pub(crate) trait GridBuilder: Builder + GeometryBuilder + TopologyBuilder {
133 fn create_grid_from_topology_geometry(
135 &self,
136 topology: <Self as TopologyBuilder>::GridTopology,
137 geometry: <Self as GeometryBuilder>::GridGeometry,
138 ) -> <Self as Builder>::Grid;
139}
140
141#[cfg(feature = "mpi")]
143pub trait ParallelBuilder: Builder {
144 type ParallelGrid<'a, C: Communicator + 'a>: ParallelGrid<C = C>
146 where
147 Self: 'a;
148
149 fn create_parallel_grid_root<'a, C: Communicator>(
151 &self,
152 comm: &'a C,
153 partitioner: GraphPartitioner,
154 ) -> Self::ParallelGrid<'a, C>;
155
156 fn create_parallel_grid<'a, C: Communicator>(
158 &self,
159 comm: &'a C,
160 root_rank: i32,
161 ) -> Self::ParallelGrid<'a, C>;
162}