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_point_parametric_coords(&mut self, _id: usize, _entity_dim: usize, _coords: &[Self::T]);
30
31 fn add_cell(&mut self, id: usize, cell_data: Self::CellData<'_>);
33
34 fn add_cell_from_nodes_and_type(
36 &mut self,
37 id: usize,
38 nodes: &[usize],
39 cell_type: Self::EntityDescriptor,
40 cell_degree: usize,
41 );
42
43 fn create_grid(&self) -> Self::Grid;
45
46 fn point_count(&self) -> usize;
48
49 fn cell_count(&self) -> usize;
51
52 fn point_indices_to_ids(&self) -> &[usize];
54
55 fn cell_indices_to_ids(&self) -> &[usize];
57
58 fn cell_points(&self, index: usize) -> &[usize];
60
61 fn cell_vertices(&self, index: usize) -> &[usize];
63
64 fn point(&self, index: usize) -> &[Self::T];
66
67 fn points(&self) -> &[Self::T];
69
70 fn point_parametric_coords(&self, _index: usize) -> Option<(usize, &[Self::T])>;
72
73 fn cell_type(&self, index: usize) -> Self::EntityDescriptor;
75
76 fn cell_degree(&self, index: usize) -> usize;
78
79 fn gdim(&self) -> usize;
81
82 fn tdim(&self) -> usize;
84
85 fn npts(&self, cell_type: Self::EntityDescriptor, degree: usize) -> usize;
87}
88
89pub(crate) trait GeometryBuilder: Builder {
94 type GridGeometry;
96
97 fn create_geometry(
99 &self,
100 point_ids: &[usize],
101 coordinates: &[Self::T],
102 cell_points: &[usize],
103 cell_types: &[Self::EntityDescriptor],
104 cell_degrees: &[usize],
105 ) -> Self::GridGeometry;
106}
107
108pub(crate) trait TopologyBuilder: Builder {
113 type GridTopology;
115
116 fn create_topology(
118 &self,
119 vertex_ids: Vec<usize>,
120 cell_ids: Vec<usize>,
121 cells: &[usize],
122 cell_types: &[Self::EntityDescriptor],
123 ) -> Self::GridTopology;
124
125 fn extract_vertices(
127 &self,
128 cell_points: &[usize],
129 cell_types: &[Self::EntityDescriptor],
130 cell_degrees: &[usize],
131 ) -> Vec<usize>;
132}
133
134pub(crate) trait GridBuilder: Builder + GeometryBuilder + TopologyBuilder {
139 fn create_grid_from_topology_geometry(
141 &self,
142 topology: <Self as TopologyBuilder>::GridTopology,
143 geometry: <Self as GeometryBuilder>::GridGeometry,
144 ) -> <Self as Builder>::Grid;
145}
146
147#[cfg(feature = "mpi")]
149pub trait ParallelBuilder: Builder {
150 type ParallelGrid<'a, C: Communicator + 'a>: ParallelGrid<C = C>
152 where
153 Self: 'a;
154
155 fn create_parallel_grid_root<'a, C: Communicator>(
157 &self,
158 comm: &'a C,
159 partitioner: GraphPartitioner,
160 ) -> Self::ParallelGrid<'a, C>;
161
162 fn create_parallel_grid<'a, C: Communicator>(
164 &self,
165 comm: &'a C,
166 root_rank: i32,
167 ) -> Self::ParallelGrid<'a, C>;
168}