Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 4e20832

Browse files
committed
ids for mixed element grid
1 parent 1015f7f commit 4e20832

File tree

5 files changed

+117
-34
lines changed

5 files changed

+117
-34
lines changed

src/grid/mixed_grid/builder.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pub struct SerialMixedGridBuilder<const GDIM: usize, T: Float + Scalar<Real = T>
2323
cell_types: Vec<ReferenceCellType>,
2424
cell_degrees: Vec<usize>,
2525
point_indices_to_ids: Vec<usize>,
26-
cell_indices_to_ids: Vec<usize>,
2726
point_ids_to_indices: HashMap<usize, usize>,
27+
cell_indices_to_ids: Vec<usize>,
2828
cell_ids_to_indices: HashMap<usize, usize>,
2929
}
3030

@@ -46,8 +46,8 @@ where
4646
cell_types: vec![],
4747
cell_degrees: vec![],
4848
point_indices_to_ids: vec![],
49-
cell_indices_to_ids: vec![],
5049
point_ids_to_indices: HashMap::new(),
50+
cell_indices_to_ids: vec![],
5151
cell_ids_to_indices: HashMap::new(),
5252
}
5353
}
@@ -60,8 +60,8 @@ where
6060
cell_types: vec![],
6161
cell_degrees: vec![],
6262
point_indices_to_ids: Vec::with_capacity(npoints),
63-
cell_indices_to_ids: Vec::with_capacity(ncells),
6463
point_ids_to_indices: HashMap::new(),
64+
cell_indices_to_ids: Vec::with_capacity(ncells),
6565
cell_ids_to_indices: HashMap::new(),
6666
}
6767
}
@@ -110,6 +110,14 @@ where
110110
[npts, 3],
111111
[1, npts]
112112
));
113-
SerialMixedGrid::new(points, &self.cells, &self.cell_types, &self.cell_degrees)
113+
SerialMixedGrid::new(
114+
points,
115+
&self.cells,
116+
&self.cell_types,
117+
&self.cell_degrees,
118+
self.point_indices_to_ids,
119+
self.point_ids_to_indices,
120+
self.cell_indices_to_ids,
121+
)
114122
}
115123
}

src/grid/mixed_grid/geometry.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rlst_dense::{
1414
rlst_array_from_slice2, rlst_dynamic_array4,
1515
traits::{RandomAccessByRef, Shape, UnsafeRandomAccessByRef},
1616
};
17+
use std::collections::HashMap;
1718

1819
/// Geometry of a serial grid
1920
pub struct SerialMixedGeometry<T: Float + Scalar> {
@@ -26,6 +27,10 @@ pub struct SerialMixedGeometry<T: Float + Scalar> {
2627
diameters: Vec<Vec<T>>,
2728
volumes: Vec<Vec<T>>,
2829
cell_indices: Vec<Vec<(usize, usize)>>,
30+
point_indices_to_ids: Vec<usize>,
31+
point_ids_to_indices: HashMap<usize, usize>,
32+
cell_indices_to_ids: HashMap<(usize, usize), usize>,
33+
cell_ids_to_indices: HashMap<usize, (usize, usize)>,
2934
}
3035

3136
unsafe impl<T: Float + Scalar> Sync for SerialMixedGeometry<T> {}
@@ -36,12 +41,18 @@ impl<T: Float + Scalar> SerialMixedGeometry<T> {
3641
cells_input: &[usize],
3742
elements: Vec<CiarletElement<T>>,
3843
cell_elements: &[usize],
44+
point_indices_to_ids: Vec<usize>,
45+
point_ids_to_indices: HashMap<usize, usize>,
46+
grid_cell_indices_to_ids: &[usize],
3947
) -> Self {
4048
let dim = coordinates.shape()[1];
4149
let mut index_map = vec![(0, 0); cell_elements.len()];
4250
let mut cells = vec![];
4351
let mut cell_indices = vec![];
4452

53+
let mut cell_indices_to_ids = HashMap::new();
54+
let mut cell_ids_to_indices = HashMap::new();
55+
4556
for (element_index, _e) in elements.iter().enumerate() {
4657
let mut start = 0;
4758

@@ -55,6 +66,8 @@ impl<T: Float + Scalar> SerialMixedGeometry<T> {
5566
index_map[cell_i] = cell_index;
5667
cell_indices[element_index].push(cell_index);
5768
cells[element_index].extend_from_slice(&cells_input[start..start + size]);
69+
cell_indices_to_ids.insert(cell_index, grid_cell_indices_to_ids[cell_i]);
70+
cell_ids_to_indices.insert(grid_cell_indices_to_ids[cell_i], cell_index);
5871
}
5972
start += size;
6073
}
@@ -106,6 +119,10 @@ impl<T: Float + Scalar> SerialMixedGeometry<T> {
106119
diameters,
107120
volumes,
108121
cell_indices,
122+
point_indices_to_ids,
123+
point_ids_to_indices,
124+
cell_indices_to_ids,
125+
cell_ids_to_indices,
109126
}
110127
}
111128
}
@@ -195,18 +212,16 @@ impl<T: Float + Scalar> Geometry for SerialMixedGeometry<T> {
195212
}
196213

197214
fn point_index_to_id(&self, index: usize) -> usize {
198-
panic!();
215+
self.point_indices_to_ids[index]
199216
}
200-
201217
fn cell_index_to_id(&self, index: (usize, usize)) -> usize {
202-
panic!();
218+
self.cell_indices_to_ids[&index]
203219
}
204-
205220
fn point_id_to_index(&self, id: usize) -> usize {
206-
panic!();
221+
self.point_ids_to_indices[&id]
207222
}
208223
fn cell_id_to_index(&self, id: usize) -> (usize, usize) {
209-
panic!();
224+
self.cell_ids_to_indices[&id]
210225
}
211226
}
212227

@@ -304,7 +319,15 @@ mod test {
304319
*points.get_mut([2, 1]).unwrap() = 1.0;
305320
*points.get_mut([3, 0]).unwrap() = 0.0;
306321
*points.get_mut([3, 1]).unwrap() = 1.0;
307-
SerialMixedGeometry::new(points, &[0, 1, 2, 0, 2, 3], vec![p1triangle], &[0, 0])
322+
SerialMixedGeometry::new(
323+
points,
324+
&[0, 1, 2, 0, 2, 3],
325+
vec![p1triangle],
326+
&[0, 0],
327+
vec![0, 1, 2, 3],
328+
HashMap::from([(0, 0), (1, 1), (2, 2), (3, 3)]),
329+
&[0, 1],
330+
)
308331
}
309332

310333
fn example_geometry_mixed() -> SerialMixedGeometry<f64> {
@@ -336,6 +359,9 @@ mod test {
336359
&[0, 1, 2, 3, 1, 4, 3],
337360
vec![p1quad, p1triangle],
338361
&[0, 1],
362+
vec![0, 1, 2, 3, 4],
363+
HashMap::from([(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]),
364+
&[0, 1],
339365
)
340366
}
341367

src/grid/mixed_grid/grid.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rlst_dense::{
1515
data_container::VectorContainer,
1616
traits::MatrixInverse,
1717
};
18+
use std::collections::HashMap;
1819

1920
/// A serial grid
2021
pub struct SerialMixedGrid<T: Float + Scalar> {
@@ -31,6 +32,9 @@ where
3132
cells: &[usize],
3233
cell_types: &[ReferenceCellType],
3334
cell_degrees: &[usize],
35+
point_indices_to_ids: Vec<usize>,
36+
point_ids_to_indices: HashMap<usize, usize>,
37+
cell_indices_to_ids: Vec<usize>,
3438
) -> Self {
3539
let mut element_info = vec![];
3640
let mut element_numbers = vec![];
@@ -64,8 +68,21 @@ where
6468
start += npoints;
6569
}
6670

67-
let topology = SerialMixedTopology::new(&cell_vertices, cell_types);
68-
let geometry = SerialMixedGeometry::<T>::new(points, cells, elements, &element_numbers);
71+
let topology = SerialMixedTopology::new(
72+
&cell_vertices,
73+
cell_types,
74+
&point_indices_to_ids,
75+
&cell_indices_to_ids,
76+
);
77+
let geometry = SerialMixedGeometry::<T>::new(
78+
points,
79+
cells,
80+
elements,
81+
&element_numbers,
82+
point_indices_to_ids,
83+
point_ids_to_indices,
84+
&cell_indices_to_ids,
85+
);
6986

7087
Self { topology, geometry }
7188
}

src/grid/mixed_grid/topology.rs

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,30 @@ pub struct SerialMixedTopology {
3434
cells_to_entities: Vec<HashMap<ReferenceCellType, Vec<Vec<IndexType>>>>,
3535
entities_to_cells: Vec<HashMap<ReferenceCellType, Vec<Vec<CellLocalIndexPair<IndexType>>>>>,
3636
entity_types: Vec<Vec<ReferenceCellType>>,
37+
vertex_indices_to_ids: HashMap<IndexType, usize>,
38+
vertex_ids_to_indices: HashMap<usize, IndexType>,
39+
cell_indices_to_ids: HashMap<IndexType, usize>,
40+
cell_ids_to_indices: HashMap<usize, IndexType>,
3741
}
3842

3943
unsafe impl Sync for SerialMixedTopology {}
4044

4145
impl SerialMixedTopology {
42-
pub fn new(cells_input: &[usize], cell_types: &[ReferenceCellType]) -> Self {
46+
pub fn new(
47+
cells_input: &[usize],
48+
cell_types: &[ReferenceCellType],
49+
point_indices_to_ids: &[usize],
50+
grid_cell_indices_to_ids: &[usize],
51+
) -> Self {
4352
let mut index_map = vec![(ReferenceCellType::Point, 0); cell_types.len()];
4453
let mut vertices = vec![];
4554
let dim = reference_cell::dim(cell_types[0]);
4655

56+
let mut vertex_indices_to_ids = HashMap::new();
57+
let mut vertex_ids_to_indices = HashMap::new();
58+
let mut cell_indices_to_ids = HashMap::new();
59+
let mut cell_ids_to_indices = HashMap::new();
60+
4761
let mut entity_types = vec![vec![]; 4];
4862

4963
let mut entities_to_vertices = vec![HashMap::new(); dim];
@@ -81,13 +95,21 @@ impl SerialMixedTopology {
8195
let cell = &cells_input[start..start + n];
8296
let cell_i = (*c, cells_to_entities[0][c].len());
8397
index_map[i] = cell_i;
98+
99+
cell_indices_to_ids.insert(cell_i, grid_cell_indices_to_ids[i]);
100+
cell_ids_to_indices.insert(grid_cell_indices_to_ids[i], cell_i);
101+
84102
let mut row = vec![];
85103
for v in cell {
86104
if !vertices.contains(v) {
87105
for (_, ec) in entities_to_cells[0].iter_mut() {
88106
ec.push(vec![]);
89107
}
90108
vertices.push(*v);
109+
vertex_indices_to_ids
110+
.insert((ReferenceCellType::Point, *v), point_indices_to_ids[*v]);
111+
vertex_ids_to_indices
112+
.insert(point_indices_to_ids[*v], (ReferenceCellType::Point, *v));
91113
}
92114
row.push((
93115
ReferenceCellType::Point,
@@ -171,6 +193,10 @@ impl SerialMixedTopology {
171193
cells_to_entities,
172194
entities_to_cells,
173195
entity_types,
196+
vertex_indices_to_ids,
197+
vertex_ids_to_indices,
198+
cell_indices_to_ids,
199+
cell_ids_to_indices,
174200
}
175201
}
176202
}
@@ -263,17 +289,17 @@ impl Topology for SerialMixedTopology {
263289
}
264290
}
265291

266-
fn vertex_index_to_id(&self, index: Self::IndexType) -> usize {
267-
panic!();
292+
fn vertex_index_to_id(&self, index: IndexType) -> usize {
293+
self.vertex_indices_to_ids[&index]
268294
}
269-
fn cell_index_to_id(&self, index: Self::IndexType) -> usize {
270-
panic!();
295+
fn cell_index_to_id(&self, index: IndexType) -> usize {
296+
self.cell_indices_to_ids[&index]
271297
}
272-
fn vertex_id_to_index(&self, id: usize) -> Self::IndexType {
273-
panic!();
298+
fn vertex_id_to_index(&self, id: usize) -> IndexType {
299+
self.vertex_ids_to_indices[&id]
274300
}
275-
fn cell_id_to_index(&self, id: usize) -> Self::IndexType {
276-
panic!();
301+
fn cell_id_to_index(&self, id: usize) -> IndexType {
302+
self.cell_ids_to_indices[&id]
277303
}
278304
}
279305

@@ -282,7 +308,24 @@ mod test {
282308
use super::*;
283309

284310
fn example_topology() -> SerialMixedTopology {
285-
SerialMixedTopology::new(&[0, 1, 2, 2, 1, 3], &[ReferenceCellType::Triangle; 2])
311+
SerialMixedTopology::new(
312+
&[0, 1, 2, 2, 1, 3],
313+
&[ReferenceCellType::Triangle; 2],
314+
&[0, 1, 2, 3],
315+
&[0, 1],
316+
)
317+
}
318+
319+
fn example_topology_mixed() -> SerialMixedTopology {
320+
SerialMixedTopology::new(
321+
&[0, 1, 2, 3, 1, 4, 3],
322+
&[
323+
ReferenceCellType::Quadrilateral,
324+
ReferenceCellType::Triangle,
325+
],
326+
&[0, 1, 2, 3, 4],
327+
&[0, 1],
328+
)
286329
}
287330

288331
#[test]
@@ -339,16 +382,6 @@ mod test {
339382
}
340383
}
341384

342-
fn example_topology_mixed() -> SerialMixedTopology {
343-
SerialMixedTopology::new(
344-
&[0, 1, 2, 3, 1, 4, 3],
345-
&[
346-
ReferenceCellType::Quadrilateral,
347-
ReferenceCellType::Triangle,
348-
],
349-
)
350-
}
351-
352385
#[test]
353386
fn test_mixed_counts() {
354387
let t = example_topology_mixed();

src/grid/single_element_grid/grid.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ impl<T: Float + Scalar> SerialSingleElementGrid<T>
2929
where
3030
for<'a> Array<T, ArrayViewMut<'a, T, BaseArray<T, VectorContainer<T>, 2>, 2>, 2>: MatrixInverse,
3131
{
32-
3332
#[allow(clippy::too_many_arguments)]
3433
pub fn new(
3534
points: Array<T, BaseArray<T, VectorContainer<T>, 2>, 2>,

0 commit comments

Comments
 (0)