1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Python wrapper for [`crate::atoms::Element`].
use crate::atoms::Element;
use crate::py::cell::PyCell;
use crate::py::node::PyNode;
use pyo3::prelude::*;
/// A single finite element — its geometry together with the interpolation
/// and quadrature of its space.
///
/// A read-only view obtained by indexing a finite-element subspace
/// (`fes[i][j]`); not constructed directly.
#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pyclass)]
#[pyclass(name = "Element")]
pub struct PyElement {
pub(crate) inner: Element,
}
#[cfg_attr(feature = "stub-gen", pyo3_stub_gen::derive::gen_stub_pymethods)]
#[pymethods]
impl PyElement {
/// Index of this element within its subspace.
#[getter]
fn index(&self) -> usize {
self.inner.index()
}
/// Number of nodes of this element.
#[getter]
fn nodes_per_cell(&self) -> usize {
self.inner.nodes_per_cell()
}
/// Spatial dimension the element lives in.
#[getter]
fn space_dim(&self) -> usize {
self.inner.space_dim()
}
/// Reference (parametric) dimension of the element.
#[getter]
fn ref_dim(&self) -> usize {
self.inner.ref_dim()
}
/// Number of Gauss (quadrature) points.
#[getter]
fn gauss_count(&self) -> usize {
self.inner.gauss_count()
}
/// Underlying mesh cell view.
fn cell(&self) -> PyResult<PyCell> {
let c = self.inner.cell()?;
Ok(PyCell { inner: c })
}
/// Materialised nodes of this element (each refcounted on the
/// Coords) — symmetric with `Cell.nodes()`.
fn nodes(&self) -> PyResult<Vec<PyNode>> {
let nodes = self.inner.cell()?.nodes()?;
Ok(nodes.into_iter().map(PyNode::from_node).collect())
}
/// Reference coordinates of the `g`-th Gauss point.
fn gauss_xi(&self, g: usize) -> PyResult<Vec<f64>> {
Ok(self.inner.gauss_xi(g)?)
}
/// Weight of the `g`-th Gauss point.
fn gauss_weight(&self, g: usize) -> PyResult<f64> {
Ok(self.inner.gauss_weight(g)?)
}
/// `N_i(ξ_g)` at the `g`-th Gauss point (length `nodes_per_cell`).
fn n_at_g(&self, g: usize) -> PyResult<Vec<f64>> {
Ok(self.inner.n_at_g(g)?)
}
/// `∂N_i/∂ξ_j(ξ_g)` at the `g`-th Gauss point.
///
/// Flat row-major: index `[i * ref_dim + j]`.
fn dn_at_g(&self, g: usize) -> PyResult<Vec<f64>> {
Ok(self.inner.dn_at_g(g)?)
}
/// Jacobian `J = ∂x/∂ξ` at the `g`-th Gauss point.
fn jacobian(&self, g: usize) -> PyResult<Vec<f64>> {
Ok(self.inner.jacobian(g)?)
}
/// `|J|` at the `g`-th Gauss point.
fn det_jacobian(&self, g: usize) -> PyResult<f64> {
Ok(self.inner.det_jacobian(g)?)
}
/// Physical derivatives `∂N_i/∂x_a` at the `g`-th Gauss point.
fn dn_dx(&self, g: usize) -> PyResult<Vec<f64>> {
Ok(self.inner.dn_dx(g)?)
}
}
crate::impl_dump_pymethod!(value PyElement, inner);