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

Commit 829c151

Browse files
committed
Add documentation
1 parent d6c7cc9 commit 829c151

29 files changed

+251
-75
lines changed

src/grid/common.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::grid::traits::Geometry;
44
use rlst_common::types::Scalar;
55
use rlst_dense::traits::{Shape, UnsafeRandomAccessByRef};
66

7+
/// Compute a physical point
78
pub fn compute_point<T: Scalar, Table: UnsafeRandomAccessByRef<4, Item = T> + Shape<4>>(
89
geometry: &impl Geometry<T = T>,
910
table: Table,
@@ -26,6 +27,7 @@ pub fn compute_point<T: Scalar, Table: UnsafeRandomAccessByRef<4, Item = T> + Sh
2627
}
2728
}
2829

30+
/// Compute a Jacobian
2931
pub fn compute_jacobian<T: Scalar, Table: UnsafeRandomAccessByRef<4, Item = T> + Shape<4>>(
3032
geometry: &impl Geometry<T = T>,
3133
table: Table,
@@ -52,6 +54,7 @@ pub fn compute_jacobian<T: Scalar, Table: UnsafeRandomAccessByRef<4, Item = T> +
5254
}
5355
}
5456

57+
/// Compute a normal from a Jacobian of a cell with topological dimension 2 and geometric dimension 3
5558
pub fn compute_normal_from_jacobian23<T: Scalar>(jacobian: &[T], normal: &mut [T]) {
5659
assert_eq!(jacobian.len(), 6);
5760
assert_eq!(normal.len(), 3);

src/grid/flat_triangle_grid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! A flat triangle grid
2+
//!
3+
//! In this grid, every cell is a flat triangle
4+
15
mod builder;
26
mod grid;
37

src/grid/flat_triangle_grid/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rlst_dense::{
1313
};
1414
use std::collections::HashMap;
1515

16+
/// Grid builder for a flat triangle grid
1617
pub struct SerialFlatTriangleGridBuilder<T: Float + Scalar<Real = T>> {
1718
points: Vec<T>,
1819
cells: Vec<usize>,

src/grid/flat_triangle_grid/grid.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Serial implementation of a grid
1+
//! Flat triangle grid
22
33
use crate::grid::traits::Ownership;
44
use crate::grid::traits::{Geometry, GeometryEvaluator, Grid, Topology};
@@ -22,10 +22,11 @@ use rlst_dense::{
2222
use rlst_proc_macro::rlst_static_type;
2323
use std::collections::HashMap;
2424

25-
/// A serial grid
25+
/// A flat triangle grid
2626
pub struct SerialFlatTriangleGrid<T: Float + Scalar<Real = T>> {
2727
index_map: Vec<usize>,
2828

29+
// Geometry information
2930
pub(crate) coordinates: Array<T, BaseArray<T, VectorContainer<T>, 2>, 2>,
3031
pub(crate) element: CiarletElement<T>,
3132
midpoints: Vec<rlst_static_type!(T, 3)>,
@@ -35,11 +36,13 @@ pub struct SerialFlatTriangleGrid<T: Float + Scalar<Real = T>> {
3536
pub(crate) jacobians: Vec<rlst_static_type!(T, 3, 2)>,
3637
cell_indices: Vec<usize>,
3738

39+
// Topology information
3840
entities_to_vertices: Vec<Vec<Vec<usize>>>,
3941
pub(crate) cells_to_entities: Vec<Vec<Vec<usize>>>,
4042
entities_to_cells: Vec<Vec<Vec<CellLocalIndexPair<usize>>>>,
4143
entity_types: Vec<ReferenceCellType>,
4244

45+
// Point and cell ids
4346
point_indices_to_ids: Vec<usize>,
4447
point_ids_to_indices: HashMap<usize, usize>,
4548
cell_indices_to_ids: Vec<usize>,
@@ -50,6 +53,7 @@ impl<T: Float + Scalar<Real = T>> SerialFlatTriangleGrid<T>
5053
where
5154
for<'a> Array<T, ArrayViewMut<'a, T, BaseArray<T, VectorContainer<T>, 2>, 2>, 2>: MatrixInverse,
5255
{
56+
/// Create a flat triangle grid
5357
pub fn new(
5458
coordinates: Array<T, BaseArray<T, VectorContainer<T>, 2>, 2>,
5559
cells: &[usize],
@@ -182,8 +186,6 @@ where
182186

183187
Self {
184188
index_map,
185-
186-
// Geometry
187189
coordinates,
188190
element,
189191
midpoints,
@@ -192,14 +194,10 @@ where
192194
normals,
193195
jacobians,
194196
cell_indices,
195-
196-
// Topology
197197
entities_to_vertices,
198198
cells_to_entities,
199199
entities_to_cells,
200200
entity_types,
201-
202-
// ids
203201
point_indices_to_ids,
204202
point_ids_to_indices,
205203
cell_indices_to_ids,
@@ -315,12 +313,14 @@ impl<T: Float + Scalar<Real = T>> Geometry for SerialFlatTriangleGrid<T> {
315313
}
316314
}
317315

316+
/// Geometry evaluator for a flat triangle grid
318317
pub struct GeometryEvaluatorFlatTriangle<'a, T: Float + Scalar<Real = T>> {
319318
grid: &'a SerialFlatTriangleGrid<T>,
320319
points: SliceArray<'a, T, 2>,
321320
}
322321

323322
impl<'a, T: Float + Scalar<Real = T>> GeometryEvaluatorFlatTriangle<'a, T> {
323+
/// Create a geometry evaluator
324324
fn new(grid: &'a SerialFlatTriangleGrid<T>, points: &'a [T]) -> Self {
325325
let tdim = reference_cell::dim(grid.element.cell_type());
326326
assert_eq!(points.len() % tdim, 0);
@@ -459,6 +459,7 @@ mod test {
459459
};
460460

461461
fn example_grid_flat() -> SerialFlatTriangleGrid<f64> {
462+
//! Create a flat test grid
462463
let mut points = rlst_dynamic_array2!(f64, [4, 3]);
463464
points[[0, 0]] = 0.0;
464465
points[[0, 1]] = 0.0;
@@ -484,6 +485,7 @@ mod test {
484485
}
485486

486487
fn example_grid_3d() -> SerialFlatTriangleGrid<f64> {
488+
//! Create a non-flat test grid
487489
let mut points = rlst_dynamic_array2!(f64, [4, 3]);
488490
points[[0, 0]] = 0.0;
489491
points[[0, 1]] = 0.0;
@@ -508,8 +510,19 @@ mod test {
508510
)
509511
}
510512

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+
511523
#[test]
512524
fn test_cell_points() {
525+
//! Test that the cell points are correct
513526
let g = example_grid_flat();
514527
for (cell_i, points) in [
515528
vec![
@@ -539,17 +552,9 @@ mod test {
539552
}
540553
}
541554

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-
551555
#[test]
552556
fn test_compute_point_flat() {
557+
//! Test the compute_point function of an evaluator
553558
let g = example_grid_flat();
554559
let points = triangle_points();
555560

@@ -573,6 +578,7 @@ mod test {
573578

574579
#[test]
575580
fn test_compute_point_3d() {
581+
//! Test the compute_point function of an evaluator
576582
let g = example_grid_3d();
577583
let points = triangle_points();
578584
let evaluator = g.get_evaluator(points.data());
@@ -596,6 +602,7 @@ mod test {
596602

597603
#[test]
598604
fn test_compute_jacobian_3d() {
605+
//! Test the compute_jacobian function of an evaluator
599606
let g = example_grid_3d();
600607
let points = triangle_points();
601608
let evaluator = g.get_evaluator(points.data());
@@ -624,6 +631,7 @@ mod test {
624631
}
625632
#[test]
626633
fn test_compute_normal_3d() {
634+
//! Test the compute_normal function of an evaluator
627635
let g = example_grid_3d();
628636
let points = triangle_points();
629637
let evaluator = g.get_evaluator(points.data());
@@ -658,6 +666,7 @@ mod test {
658666

659667
#[test]
660668
fn test_midpoint_flat() {
669+
//! Test midpoints
661670
let g = example_grid_flat();
662671

663672
let mut midpoint = vec![0.0; 3];
@@ -677,6 +686,7 @@ mod test {
677686

678687
#[test]
679688
fn test_midpoint_3d() {
689+
//! Test midpoints
680690
let g = example_grid_3d();
681691

682692
let mut midpoint = vec![0.0; 3];
@@ -696,6 +706,7 @@ mod test {
696706

697707
#[test]
698708
fn test_counts() {
709+
//! Test the entity counts
699710
let g = example_grid_flat();
700711
assert_eq!(Topology::dim(&g), 2);
701712
assert_eq!(Geometry::dim(&g), 3);
@@ -708,7 +719,8 @@ mod test {
708719
}
709720

710721
#[test]
711-
fn test_cell_entities_points() {
722+
fn test_cell_entities_vertices() {
723+
//! Test the cell vertices
712724
let t = example_grid_3d();
713725
for (i, vertices) in [[0, 1, 2], [0, 2, 3]].iter().enumerate() {
714726
let c = t.cell_to_entities(i, 0).unwrap();
@@ -718,7 +730,8 @@ mod test {
718730
}
719731

720732
#[test]
721-
fn test_cell_entities_intervals() {
733+
fn test_cell_entities_edges() {
734+
//! Test the cell edges
722735
let t = example_grid_3d();
723736
for (i, edges) in [[0, 1, 2], [3, 4, 1]].iter().enumerate() {
724737
let c = t.cell_to_entities(i, 1).unwrap();
@@ -728,7 +741,8 @@ mod test {
728741
}
729742

730743
#[test]
731-
fn test_cell_entities_triangles() {
744+
fn test_cell_entities_cells() {
745+
//! Test the cells
732746
let t = example_grid_3d();
733747
for i in 0..2 {
734748
let c = t.cell_to_entities(i, 2).unwrap();
@@ -738,7 +752,8 @@ mod test {
738752
}
739753

740754
#[test]
741-
fn test_entities_to_cells_points() {
755+
fn test_entities_to_cells_vertices() {
756+
//! Test the cell-to-vertex connectivity
742757
let t = example_grid_3d();
743758
let c_to_e = (0..t.entity_count(ReferenceCellType::Triangle))
744759
.map(|i| t.cell_to_entities(i, 0).unwrap())
@@ -767,6 +782,7 @@ mod test {
767782

768783
#[test]
769784
fn test_entities_to_cells_edges() {
785+
//! Test the cell-to-edge connectivity
770786
let t = example_grid_3d();
771787
let c_to_e = (0..t.entity_count(ReferenceCellType::Triangle))
772788
.map(|i| t.cell_to_entities(i, 1).unwrap())

src/grid/mixed_grid.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! A mixed grid
2+
//!
3+
//! In this grid, cells can be of any type, and the grid may contain multiple cell types
4+
15
mod builder;
26
mod geometry;
37
mod grid;

src/grid/mixed_grid/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rlst_dense::{
1616
};
1717
use std::collections::HashMap;
1818

19+
/// Grid builder for a mixed grid
1920
pub struct SerialMixedGridBuilder<const GDIM: usize, T: Float + Scalar<Real = T>> {
2021
elements_to_npoints: HashMap<(ReferenceCellType, usize), usize>,
2122
points: Vec<T>,

src/grid/mixed_grid/geometry.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct SerialMixedGeometry<T: Float + Scalar> {
3636
unsafe impl<T: Float + Scalar> Sync for SerialMixedGeometry<T> {}
3737

3838
impl<T: Float + Scalar> SerialMixedGeometry<T> {
39+
/// Create a geometry
3940
pub fn new(
4041
coordinates: Array<T, BaseArray<T, VectorContainer<T>, 2>, 2>,
4142
cells_input: &[usize],
@@ -225,13 +226,15 @@ impl<T: Float + Scalar> Geometry for SerialMixedGeometry<T> {
225226
}
226227
}
227228

229+
/// Geometry evaluator for a mixed grid
228230
pub struct GeometryEvaluatorMixed<'a, T: Float + Scalar> {
229231
geometry: &'a SerialMixedGeometry<T>,
230232
tdim: usize,
231233
tables: Vec<Array<T, BaseArray<T, VectorContainer<T>, 4>, 4>>,
232234
}
233235

234236
impl<'a, T: Float + Scalar> GeometryEvaluatorMixed<'a, T> {
237+
/// Create a geometry evaluator
235238
fn new(geometry: &'a SerialMixedGeometry<T>, points: &'a [T]) -> Self {
236239
let tdim = reference_cell::dim(geometry.elements[0].cell_type());
237240
assert_eq!(points.len() % tdim, 0);
@@ -304,6 +307,7 @@ mod test {
304307
use rlst_dense::{rlst_dynamic_array2, traits::RandomAccessMut};
305308

306309
fn example_geometry() -> SerialMixedGeometry<f64> {
310+
//! A geometry with a single cell type
307311
let p1triangle = create_element(
308312
ElementFamily::Lagrange,
309313
bempp_element::cell::ReferenceCellType::Triangle,
@@ -331,6 +335,7 @@ mod test {
331335
}
332336

333337
fn example_geometry_mixed() -> SerialMixedGeometry<f64> {
338+
//! A geometry with a mixture of cell types
334339
let p1triangle = create_element(
335340
ElementFamily::Lagrange,
336341
bempp_element::cell::ReferenceCellType::Triangle,
@@ -367,13 +372,15 @@ mod test {
367372

368373
#[test]
369374
fn test_counts() {
375+
//! Test the point and cell counts
370376
let g = example_geometry();
371377
assert_eq!(g.point_count(), 4);
372378
assert_eq!(g.cell_count(), 2);
373379
}
374380

375381
#[test]
376382
fn test_cell_points() {
383+
//! Test the cell points
377384
let g = example_geometry();
378385
for (cell_i, points) in [
379386
vec![vec![0.0, 0.0], vec![1.0, 0.0], vec![1.0, 1.0]],
@@ -397,13 +404,15 @@ mod test {
397404

398405
#[test]
399406
fn test_counts_mixed() {
407+
//! Test the point and cell counts
400408
let g = example_geometry_mixed();
401409
assert_eq!(g.point_count(), 5);
402410
assert_eq!(g.cell_count(), 2);
403411
}
404412

405413
#[test]
406414
fn test_cell_points_mixed() {
415+
//! Test the cell points
407416
let g = example_geometry_mixed();
408417
for (cell_i, points) in [
409418
(
@@ -432,6 +441,7 @@ mod test {
432441

433442
#[test]
434443
fn test_midpoint() {
444+
//! Test midpoints
435445
let g = example_geometry();
436446

437447
let mut midpoint = vec![0.0; 2];
@@ -448,6 +458,7 @@ mod test {
448458

449459
#[test]
450460
fn test_midpoint_mixed() {
461+
//! Test midpoints
451462
let g = example_geometry_mixed();
452463

453464
let mut midpoint = vec![0.0; 2];

src/grid/mixed_grid/grid.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Serial implementation of a grid
1+
//! Mixed grid
22
33
use crate::grid::mixed_grid::{geometry::SerialMixedGeometry, topology::SerialMixedTopology};
44
use crate::grid::traits::Grid;
@@ -17,7 +17,7 @@ use rlst_dense::{
1717
};
1818
use std::collections::HashMap;
1919

20-
/// A serial grid
20+
/// A mixed grid
2121
pub struct SerialMixedGrid<T: Float + Scalar> {
2222
topology: SerialMixedTopology,
2323
geometry: SerialMixedGeometry<T>,
@@ -27,6 +27,7 @@ impl<T: Float + Scalar> SerialMixedGrid<T>
2727
where
2828
for<'a> Array<T, ArrayViewMut<'a, T, BaseArray<T, VectorContainer<T>, 2>, 2>, 2>: MatrixInverse,
2929
{
30+
/// Create a mixed grid
3031
pub fn new(
3132
points: Array<T, BaseArray<T, VectorContainer<T>, 2>, 2>,
3233
cells: &[usize],

0 commit comments

Comments
 (0)