1
- //! Serial implementation of a grid
1
+ //! Flat triangle grid
2
2
3
3
use crate :: grid:: traits:: Ownership ;
4
4
use crate :: grid:: traits:: { Geometry , GeometryEvaluator , Grid , Topology } ;
@@ -22,10 +22,11 @@ use rlst_dense::{
22
22
use rlst_proc_macro:: rlst_static_type;
23
23
use std:: collections:: HashMap ;
24
24
25
- /// A serial grid
25
+ /// A flat triangle grid
26
26
pub struct SerialFlatTriangleGrid < T : Float + Scalar < Real = T > > {
27
27
index_map : Vec < usize > ,
28
28
29
+ // Geometry information
29
30
pub ( crate ) coordinates : Array < T , BaseArray < T , VectorContainer < T > , 2 > , 2 > ,
30
31
pub ( crate ) element : CiarletElement < T > ,
31
32
midpoints : Vec < rlst_static_type ! ( T , 3 ) > ,
@@ -35,11 +36,13 @@ pub struct SerialFlatTriangleGrid<T: Float + Scalar<Real = T>> {
35
36
pub ( crate ) jacobians : Vec < rlst_static_type ! ( T , 3 , 2 ) > ,
36
37
cell_indices : Vec < usize > ,
37
38
39
+ // Topology information
38
40
entities_to_vertices : Vec < Vec < Vec < usize > > > ,
39
41
pub ( crate ) cells_to_entities : Vec < Vec < Vec < usize > > > ,
40
42
entities_to_cells : Vec < Vec < Vec < CellLocalIndexPair < usize > > > > ,
41
43
entity_types : Vec < ReferenceCellType > ,
42
44
45
+ // Point and cell ids
43
46
point_indices_to_ids : Vec < usize > ,
44
47
point_ids_to_indices : HashMap < usize , usize > ,
45
48
cell_indices_to_ids : Vec < usize > ,
@@ -50,6 +53,7 @@ impl<T: Float + Scalar<Real = T>> SerialFlatTriangleGrid<T>
50
53
where
51
54
for < ' a > Array < T , ArrayViewMut < ' a , T , BaseArray < T , VectorContainer < T > , 2 > , 2 > , 2 > : MatrixInverse ,
52
55
{
56
+ /// Create a flat triangle grid
53
57
pub fn new (
54
58
coordinates : Array < T , BaseArray < T , VectorContainer < T > , 2 > , 2 > ,
55
59
cells : & [ usize ] ,
@@ -182,8 +186,6 @@ where
182
186
183
187
Self {
184
188
index_map,
185
-
186
- // Geometry
187
189
coordinates,
188
190
element,
189
191
midpoints,
@@ -192,14 +194,10 @@ where
192
194
normals,
193
195
jacobians,
194
196
cell_indices,
195
-
196
- // Topology
197
197
entities_to_vertices,
198
198
cells_to_entities,
199
199
entities_to_cells,
200
200
entity_types,
201
-
202
- // ids
203
201
point_indices_to_ids,
204
202
point_ids_to_indices,
205
203
cell_indices_to_ids,
@@ -315,12 +313,14 @@ impl<T: Float + Scalar<Real = T>> Geometry for SerialFlatTriangleGrid<T> {
315
313
}
316
314
}
317
315
316
+ /// Geometry evaluator for a flat triangle grid
318
317
pub struct GeometryEvaluatorFlatTriangle < ' a , T : Float + Scalar < Real = T > > {
319
318
grid : & ' a SerialFlatTriangleGrid < T > ,
320
319
points : SliceArray < ' a , T , 2 > ,
321
320
}
322
321
323
322
impl < ' a , T : Float + Scalar < Real = T > > GeometryEvaluatorFlatTriangle < ' a , T > {
323
+ /// Create a geometry evaluator
324
324
fn new ( grid : & ' a SerialFlatTriangleGrid < T > , points : & ' a [ T ] ) -> Self {
325
325
let tdim = reference_cell:: dim ( grid. element . cell_type ( ) ) ;
326
326
assert_eq ! ( points. len( ) % tdim, 0 ) ;
@@ -459,6 +459,7 @@ mod test {
459
459
} ;
460
460
461
461
fn example_grid_flat ( ) -> SerialFlatTriangleGrid < f64 > {
462
+ //! Create a flat test grid
462
463
let mut points = rlst_dynamic_array2 ! ( f64 , [ 4 , 3 ] ) ;
463
464
points[ [ 0 , 0 ] ] = 0.0 ;
464
465
points[ [ 0 , 1 ] ] = 0.0 ;
@@ -484,6 +485,7 @@ mod test {
484
485
}
485
486
486
487
fn example_grid_3d ( ) -> SerialFlatTriangleGrid < f64 > {
488
+ //! Create a non-flat test grid
487
489
let mut points = rlst_dynamic_array2 ! ( f64 , [ 4 , 3 ] ) ;
488
490
points[ [ 0 , 0 ] ] = 0.0 ;
489
491
points[ [ 0 , 1 ] ] = 0.0 ;
@@ -508,8 +510,19 @@ mod test {
508
510
)
509
511
}
510
512
513
+ fn triangle_points ( ) -> Array < f64 , BaseArray < f64 , VectorContainer < f64 > , 2 > , 2 > {
514
+ //! Create a set of points inside the reference triangle
515
+ let mut points = rlst_dynamic_array2 ! ( f64 , [ 2 , 2 ] ) ;
516
+ * points. get_mut ( [ 0 , 0 ] ) . unwrap ( ) = 0.2 ;
517
+ * points. get_mut ( [ 0 , 1 ] ) . unwrap ( ) = 0.5 ;
518
+ * points. get_mut ( [ 1 , 0 ] ) . unwrap ( ) = 0.6 ;
519
+ * points. get_mut ( [ 1 , 1 ] ) . unwrap ( ) = 0.1 ;
520
+ points
521
+ }
522
+
511
523
#[ test]
512
524
fn test_cell_points ( ) {
525
+ //! Test that the cell points are correct
513
526
let g = example_grid_flat ( ) ;
514
527
for ( cell_i, points) in [
515
528
vec ! [
@@ -539,17 +552,9 @@ mod test {
539
552
}
540
553
}
541
554
542
- fn triangle_points ( ) -> Array < f64 , BaseArray < f64 , VectorContainer < f64 > , 2 > , 2 > {
543
- let mut points = rlst_dynamic_array2 ! ( f64 , [ 2 , 2 ] ) ;
544
- * points. get_mut ( [ 0 , 0 ] ) . unwrap ( ) = 0.2 ;
545
- * points. get_mut ( [ 0 , 1 ] ) . unwrap ( ) = 0.5 ;
546
- * points. get_mut ( [ 1 , 0 ] ) . unwrap ( ) = 0.6 ;
547
- * points. get_mut ( [ 1 , 1 ] ) . unwrap ( ) = 0.1 ;
548
- points
549
- }
550
-
551
555
#[ test]
552
556
fn test_compute_point_flat ( ) {
557
+ //! Test the compute_point function of an evaluator
553
558
let g = example_grid_flat ( ) ;
554
559
let points = triangle_points ( ) ;
555
560
@@ -573,6 +578,7 @@ mod test {
573
578
574
579
#[ test]
575
580
fn test_compute_point_3d ( ) {
581
+ //! Test the compute_point function of an evaluator
576
582
let g = example_grid_3d ( ) ;
577
583
let points = triangle_points ( ) ;
578
584
let evaluator = g. get_evaluator ( points. data ( ) ) ;
@@ -596,6 +602,7 @@ mod test {
596
602
597
603
#[ test]
598
604
fn test_compute_jacobian_3d ( ) {
605
+ //! Test the compute_jacobian function of an evaluator
599
606
let g = example_grid_3d ( ) ;
600
607
let points = triangle_points ( ) ;
601
608
let evaluator = g. get_evaluator ( points. data ( ) ) ;
@@ -624,6 +631,7 @@ mod test {
624
631
}
625
632
#[ test]
626
633
fn test_compute_normal_3d ( ) {
634
+ //! Test the compute_normal function of an evaluator
627
635
let g = example_grid_3d ( ) ;
628
636
let points = triangle_points ( ) ;
629
637
let evaluator = g. get_evaluator ( points. data ( ) ) ;
@@ -658,6 +666,7 @@ mod test {
658
666
659
667
#[ test]
660
668
fn test_midpoint_flat ( ) {
669
+ //! Test midpoints
661
670
let g = example_grid_flat ( ) ;
662
671
663
672
let mut midpoint = vec ! [ 0.0 ; 3 ] ;
@@ -677,6 +686,7 @@ mod test {
677
686
678
687
#[ test]
679
688
fn test_midpoint_3d ( ) {
689
+ //! Test midpoints
680
690
let g = example_grid_3d ( ) ;
681
691
682
692
let mut midpoint = vec ! [ 0.0 ; 3 ] ;
@@ -696,6 +706,7 @@ mod test {
696
706
697
707
#[ test]
698
708
fn test_counts ( ) {
709
+ //! Test the entity counts
699
710
let g = example_grid_flat ( ) ;
700
711
assert_eq ! ( Topology :: dim( & g) , 2 ) ;
701
712
assert_eq ! ( Geometry :: dim( & g) , 3 ) ;
@@ -708,7 +719,8 @@ mod test {
708
719
}
709
720
710
721
#[ test]
711
- fn test_cell_entities_points ( ) {
722
+ fn test_cell_entities_vertices ( ) {
723
+ //! Test the cell vertices
712
724
let t = example_grid_3d ( ) ;
713
725
for ( i, vertices) in [ [ 0 , 1 , 2 ] , [ 0 , 2 , 3 ] ] . iter ( ) . enumerate ( ) {
714
726
let c = t. cell_to_entities ( i, 0 ) . unwrap ( ) ;
@@ -718,7 +730,8 @@ mod test {
718
730
}
719
731
720
732
#[ test]
721
- fn test_cell_entities_intervals ( ) {
733
+ fn test_cell_entities_edges ( ) {
734
+ //! Test the cell edges
722
735
let t = example_grid_3d ( ) ;
723
736
for ( i, edges) in [ [ 0 , 1 , 2 ] , [ 3 , 4 , 1 ] ] . iter ( ) . enumerate ( ) {
724
737
let c = t. cell_to_entities ( i, 1 ) . unwrap ( ) ;
@@ -728,7 +741,8 @@ mod test {
728
741
}
729
742
730
743
#[ test]
731
- fn test_cell_entities_triangles ( ) {
744
+ fn test_cell_entities_cells ( ) {
745
+ //! Test the cells
732
746
let t = example_grid_3d ( ) ;
733
747
for i in 0 ..2 {
734
748
let c = t. cell_to_entities ( i, 2 ) . unwrap ( ) ;
@@ -738,7 +752,8 @@ mod test {
738
752
}
739
753
740
754
#[ test]
741
- fn test_entities_to_cells_points ( ) {
755
+ fn test_entities_to_cells_vertices ( ) {
756
+ //! Test the cell-to-vertex connectivity
742
757
let t = example_grid_3d ( ) ;
743
758
let c_to_e = ( 0 ..t. entity_count ( ReferenceCellType :: Triangle ) )
744
759
. map ( |i| t. cell_to_entities ( i, 0 ) . unwrap ( ) )
@@ -767,6 +782,7 @@ mod test {
767
782
768
783
#[ test]
769
784
fn test_entities_to_cells_edges ( ) {
785
+ //! Test the cell-to-edge connectivity
770
786
let t = example_grid_3d ( ) ;
771
787
let c_to_e = ( 0 ..t. entity_count ( ReferenceCellType :: Triangle ) )
772
788
. map ( |i| t. cell_to_entities ( i, 1 ) . unwrap ( ) )
0 commit comments