Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit 6336c0c

Browse files
authored
Updates to the documentation (#103)
* WIP: Docs * Added example to doc landing site
1 parent 0986d51 commit 6336c0c

File tree

14 files changed

+251
-81
lines changed

14 files changed

+251
-81
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ blas-src = { version = "0.14", features = ["blis"]}
4444
paste = "1.*"
4545
approx = "0.5"
4646

47+
[build]
48+
rustdocflags = [ "--html-in-header", "katex-header.html" ]
49+
50+
4751
[build-dependencies]
4852
cbindgen = "0.29.*"
4953

5054
[package.metadata.docs.rs]
5155
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
56+
rustdoc-args = [ "--html-in-header", "katex-header.html" ]
5257

5358
[lints.clippy]
5459
wildcard_imports = "forbid"

examples/element_family.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn main() {
1111
let element = family.element(ReferenceCellType::Triangle);
1212
println!("Cell: {:?}", element.cell_type());
1313

14-
// Get the element in the family on a triangle
14+
// Get the element in the family on a quadrilateral
1515
let element = family.element(ReferenceCellType::Quadrilateral);
1616
println!("Cell: {:?}", element.cell_type());
1717
}

katex-header.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/katex.min.css" integrity="sha384-WcoG4HRXMzYzfCgiyfrySxx90XSl2rxY5mnVY5TwtWE6KLrArNKn0T/mOgNL0Mmi" crossorigin="anonymous">
2+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/katex.min.js" integrity="sha384-J+9dG2KMoiR9hqcFao0IBLwxt6zpcyN68IgwzsCSkbreXUjmNVRhPFTssqdSGjwQ" crossorigin="anonymous"></script>
3+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.25/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"></script>
4+
<script>
5+
document.addEventListener("DOMContentLoaded", function() {
6+
renderMathInElement(document.body, {
7+
// customised options
8+
// • auto-render specific keys, e.g.:
9+
delimiters: [
10+
{left: '$$', right: '$$', display: true},
11+
{left: '$', right: '$', display: false},
12+
{left: '\\(', right: '\\)', display: false},
13+
{left: '\\[', right: '\\]', display: true}
14+
],
15+
// • rendering keys, e.g.:
16+
throwOnError : false
17+
});
18+
});
19+
</script>

src/bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ pub mod ciarlet {
686686
field(arg = 0, name = "element", wrapper = "CiarletElementT", replace_with = ["CiarletElement<{{dtype}}, {{maptype}}>"])
687687
)]
688688
pub fn ciarlet_element_embedded_superdegree<E: FiniteElement>(element: &E) -> usize {
689-
element.embedded_superdegree()
689+
element.lagrange_superdegree()
690690
}
691691

692692
#[concretise_types(

src/ciarlet.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ impl<T: RlstScalar, M: Map> CiarletElement<T, M>
7272
where
7373
DynArray<T, 2>: Inverse<Output = DynArray<T, 2>>,
7474
{
75-
/// Create a Ciarlet element
75+
/// Create a Ciarlet element.
76+
///
77+
/// This should not be used directly. Instead users should call the `create`
78+
/// function for one of the following special cases of a general Ciarlet element.
79+
/// - [crate::ciarlet::lagrange::create]: Create a new Lagrange element.
80+
/// - [crate::ciarlet::nedelec::create]: Create a new Nedelec element.
81+
/// - [crate::ciarlet::raviart_thomas::create]: Create a Raviart-Thomas element.
7682
#[allow(clippy::too_many_arguments)]
7783
pub fn create(
7884
family_name: String,
@@ -603,7 +609,7 @@ impl<T: RlstScalar, M: Map> FiniteElement for CiarletElement<T, M> {
603609
fn cell_type(&self) -> ReferenceCellType {
604610
self.cell_type
605611
}
606-
fn embedded_superdegree(&self) -> usize {
612+
fn lagrange_superdegree(&self) -> usize {
607613
self.embedded_superdegree
608614
}
609615
fn dim(&self) -> usize {

src/ciarlet/lagrange.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rlst::dense::linalg::lapack::interface::{getrf::Getrf, getri::Getri};
1010
use rlst::{RlstScalar, rlst_dynamic_array};
1111
use std::marker::PhantomData;
1212

13-
/// Create a Lagrange element
13+
/// Create a Lagrange element.
1414
pub fn create<T: RlstScalar + Getrf + Getri>(
1515
cell_type: ReferenceCellType,
1616
degree: usize,
@@ -268,15 +268,17 @@ pub fn create<T: RlstScalar + Getrf + Getri>(
268268
)
269269
}
270270

271-
/// Lagrange element family
271+
/// Lagrange element family.
272+
///
273+
/// A factory structure to create new Lagrange elements.
272274
pub struct LagrangeElementFamily<T: RlstScalar + Getrf + Getri> {
273275
degree: usize,
274276
continuity: Continuity,
275277
_t: PhantomData<T>,
276278
}
277279

278280
impl<T: RlstScalar + Getrf + Getri> LagrangeElementFamily<T> {
279-
/// Create new family
281+
/// Create new family with given `degree` and `continuity`.
280282
pub fn new(degree: usize, continuity: Continuity) -> Self {
281283
Self {
282284
degree,

src/ciarlet/nedelec.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,16 @@ pub fn create<T: RlstScalar + Getrf + Getri>(
640640
}
641641

642642
/// Nedelec (first kind) element family
643+
///
644+
/// A factory structure to create new Nedelec elements.
643645
pub struct NedelecFirstKindElementFamily<T: RlstScalar + Getrf + Getri> {
644646
degree: usize,
645647
continuity: Continuity,
646648
_t: PhantomData<T>,
647649
}
648650

649651
impl<T: RlstScalar + Getrf + Getri> NedelecFirstKindElementFamily<T> {
650-
/// Create new family
652+
/// Create new family with given `degree` and `continuity`.
651653
pub fn new(degree: usize, continuity: Continuity) -> Self {
652654
Self {
653655
degree,

src/ciarlet/raviart_thomas.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,16 @@ pub fn create<T: RlstScalar + Getrf + Getri>(
483483
}
484484

485485
/// Raviart-Thomas element family
486+
///
487+
/// A factory structure to create new Raviart-Thomas elements.
486488
pub struct RaviartThomasElementFamily<T: RlstScalar + Getrf + Getri> {
487489
degree: usize,
488490
continuity: Continuity,
489491
_t: PhantomData<T>,
490492
}
491493

492494
impl<T: RlstScalar + Getrf + Getri> RaviartThomasElementFamily<T> {
493-
/// Create new family
495+
/// Create new family with given `degree` and `continuity`.
494496
pub fn new(degree: usize, continuity: Continuity) -> Self {
495497
Self {
496498
degree,

src/lib.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
1-
//! n-dimensional grid
1+
//! A library for the definition and tabulation of finite elements in Rust.
2+
//!
3+
//! `ndelement` provides definition of many frequently used low and high order finite elements
4+
//! and provides routines for the tabulation of their values.
5+
//!
6+
//! The following presents a simple example of how to use `ndelement`.
7+
//!
8+
//! ```
9+
//! use ndelement::ciarlet::LagrangeElementFamily;
10+
//! use ndelement::traits::{ElementFamily, FiniteElement};
11+
//! use ndelement::types::{Continuity, ReferenceCellType};
12+
//! use rlst::DynArray;
13+
//!
14+
//! // Create the degree 2 Lagrange element family. A family is a set of finite elements with the
15+
//! // same family type, degree, and continuity across a set of cells
16+
//! let family = LagrangeElementFamily::<f64>::new(2, Continuity::Standard);
17+
//!
18+
//! // Get the element in the family on a triangle
19+
//! let element = family.element(ReferenceCellType::Triangle);
20+
//! println!("Cell: {:?}", element.cell_type());
21+
//!
22+
//! // Get the element in the family on a quadrilateral
23+
//! let element = family.element(ReferenceCellType::Quadrilateral);
24+
//! println!("Cell: {:?}", element.cell_type());
25+
//!
26+
//! // Create an array to store the basis function values
27+
//! let mut basis_values = DynArray::<f64, 4>::from_shape(element.tabulate_array_shape(0, 1));
28+
//! // Create array containing the point [1/2, 1/2]
29+
//! let mut points = DynArray::<f64, 2>::from_shape([2, 1]);
30+
//! points[[0, 0]] = 1.0 / 2.0;
31+
//! points[[1, 0]] = 1.0 / 2.0;
32+
//! // Tabulate the element's basis functions at the point
33+
//! element.tabulate(&points, 0, &mut basis_values);
34+
//! println!(
35+
//! "The values of the basis functions at the point (1/2, 1/2) are: {:?}",
36+
//! basis_values.data()
37+
//! );
38+
//! ```
239
#![cfg_attr(feature = "strict", deny(warnings), deny(unused_crate_dependencies))]
340
#![warn(missing_docs)]
441

src/map.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use crate::traits::Map;
33
use rlst::{Array, MutableArrayImpl, RlstScalar, ValueArrayImpl};
44

55
/// Identity map
6+
///
7+
/// An identity map pushes values from the reference to the physical
8+
/// cell without modifying them.
69
pub struct IdentityMap {}
710

811
impl Map for IdentityMap {
@@ -51,7 +54,17 @@ impl Map for IdentityMap {
5154
}
5255
}
5356

54-
/// CovariantPiola map
57+
/// Covariant Piola map.
58+
///
59+
/// Let $F$ be the map from the reference cell to the physical cell
60+
/// and let $J$ be its Jacobian. Let $\Phi$ be the function values
61+
/// on the reference cell. The covariant Piola map is defined by
62+
/// $$
63+
/// J^{-T}\Phi\circ F^{-1}
64+
/// $$
65+
/// The coviariant Piola map preserves tangential continuity. If $J$
66+
/// is a rectangular matrix then the pseudo-inverse is used instead of
67+
/// the inverse.
5568
pub struct CovariantPiolaMap {}
5669

5770
impl Map for CovariantPiolaMap {
@@ -138,7 +151,15 @@ impl Map for CovariantPiolaMap {
138151
}
139152
}
140153

141-
/// ContravariantPiola map
154+
/// Contravariant Piola map.
155+
///
156+
/// Let $F$ be the map from the reference cell to the physical cell
157+
/// and let $J$ be its Jacobian. Let $\Phi$ be the function values
158+
/// on the reference cell. The contravariant Piola map is defined by
159+
/// $$
160+
/// \frac{1}{\sqrt{\det{J^TJ}}}J\Phi\circ F^{-1}
161+
/// $$
162+
/// The contravariant Piola map preserves normal continuity.
142163
pub struct ContravariantPiolaMap {}
143164

144165
impl Map for ContravariantPiolaMap {

0 commit comments

Comments
 (0)