Skip to content

Commit e38f4c2

Browse files
Implement support for gmsh files with parametric nodes (#29)
* feat: Add support for importing parametric coordinates from Gmsh 4.1 mesh files. * refactor: Extract common Gmsh node parsing and element node permutation logic into helper functions. * minor: fix styling * minor: handle clippy error --------- Co-authored-by: Matthew Scroggs <matthew.w.scroggs@gmail.com>
1 parent 0137405 commit e38f4c2

File tree

8 files changed

+314
-124
lines changed

8 files changed

+314
-124
lines changed

ndgrid/src/grid/local_grid/mixed/builder.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct MixedGridBuilder<T: Scalar> {
3737
cell_ids_to_indices: HashMap<usize, usize>,
3838
point_indices: HashSet<usize>,
3939
cell_indices: HashSet<usize>,
40+
parametric_coords: HashMap<usize, (usize, Vec<T>)>,
4041
}
4142

4243
impl<T: Scalar> MixedGridBuilder<T> {
@@ -59,6 +60,7 @@ impl<T: Scalar> MixedGridBuilder<T> {
5960
cell_ids_to_indices: HashMap::new(),
6061
point_indices: HashSet::new(),
6162
cell_indices: HashSet::new(),
63+
parametric_coords: HashMap::new(),
6264
}
6365
}
6466
}
@@ -207,6 +209,19 @@ impl<T: Scalar> Builder for MixedGridBuilder<T> {
207209
fn npts(&self, cell_type: Self::EntityDescriptor, degree: usize) -> usize {
208210
self.points_per_cell[self.element_indices[&(cell_type, degree)]]
209211
}
212+
213+
fn add_point_parametric_coords(&mut self, id: usize, entity_dim: usize, coords: &[T]) {
214+
if let Some(&index) = self.point_ids_to_indices.get(&id) {
215+
self.parametric_coords
216+
.insert(index, (entity_dim, coords.to_vec()));
217+
}
218+
}
219+
220+
fn point_parametric_coords(&self, index: usize) -> Option<(usize, &[T])> {
221+
self.parametric_coords
222+
.get(&index)
223+
.map(|(dim, coords)| (*dim, coords.as_slice()))
224+
}
210225
}
211226

212227
impl<T: Scalar> GeometryBuilder for MixedGridBuilder<T> {

ndgrid/src/grid/local_grid/single_element/builder.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct SingleElementGridBuilder<T: Scalar> {
5454
cell_ids_to_indices: HashMap<usize, usize>,
5555
point_indices: HashSet<usize>,
5656
cell_indices: HashSet<usize>,
57+
parametric_coords: HashMap<usize, (usize, Vec<T>)>,
5758
}
5859

5960
impl<T: Scalar> SingleElementGridBuilder<T> {
@@ -84,6 +85,7 @@ impl<T: Scalar> SingleElementGridBuilder<T> {
8485
cell_ids_to_indices: HashMap::new(),
8586
point_indices: HashSet::new(),
8687
cell_indices: HashSet::new(),
88+
parametric_coords: HashMap::new(),
8789
}
8890
}
8991
}
@@ -214,6 +216,19 @@ impl<T: Scalar> Builder for SingleElementGridBuilder<T> {
214216
fn npts(&self, _cell_type: Self::EntityDescriptor, _degree: usize) -> usize {
215217
self.points_per_cell
216218
}
219+
220+
fn add_point_parametric_coords(&mut self, id: usize, entity_dim: usize, coords: &[T]) {
221+
if let Some(&index) = self.point_ids_to_indices.get(&id) {
222+
self.parametric_coords
223+
.insert(index, (entity_dim, coords.to_vec()));
224+
}
225+
}
226+
227+
fn point_parametric_coords(&self, index: usize) -> Option<(usize, &[T])> {
228+
self.parametric_coords
229+
.get(&index)
230+
.map(|(dim, coords)| (*dim, coords.as_slice()))
231+
}
217232
}
218233

219234
impl<T: Scalar> GeometryBuilder for SingleElementGridBuilder<T> {

0 commit comments

Comments
 (0)