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

Commit 9b718bd

Browse files
authored
Remove assumption that geometry uses real scalars (#141)
* remove assumption that everything is real * use branch of ndelement * main branch
1 parent eff029e commit 9b718bd

20 files changed

Lines changed: 139 additions & 145 deletions

File tree

src/geometry/geometry_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Geometry map
2-
use crate::{traits::GeometryMap as GeometryMapTrait, types::RealScalar};
2+
use crate::{traits::GeometryMap as GeometryMapTrait, types::Scalar};
33
use ndelement::{reference_cell, traits::MappedFiniteElement, types::ReferenceCellType};
44
use rlst::{Array, DynArray, RlstScalar, ValueArrayImpl};
55

@@ -43,7 +43,7 @@ fn cross<T: RlstScalar>(mat: &[T], result: &mut [T]) {
4343
}
4444
}
4545

46-
impl<'a, T: RealScalar, B2D: ValueArrayImpl<T, 2>, C2D: ValueArrayImpl<usize, 2>>
46+
impl<'a, T: Scalar, B2D: ValueArrayImpl<T, 2>, C2D: ValueArrayImpl<usize, 2>>
4747
GeometryMap<'a, T, B2D, C2D>
4848
{
4949
/// Create new
@@ -71,7 +71,7 @@ impl<'a, T: RealScalar, B2D: ValueArrayImpl<T, 2>, C2D: ValueArrayImpl<usize, 2>
7171
}
7272
}
7373

74-
impl<T: RealScalar, B2D: ValueArrayImpl<T, 2>, C2D: ValueArrayImpl<usize, 2>> GeometryMapTrait
74+
impl<T: Scalar, B2D: ValueArrayImpl<T, 2>, C2D: ValueArrayImpl<usize, 2>> GeometryMapTrait
7575
for GeometryMap<'_, T, B2D, C2D>
7676
{
7777
type T = T;

src/geometry/mixed/entity_geometry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ use super::MixedGeometry;
33
use crate::{
44
geometry::{Point, PointIter},
55
traits::Geometry,
6-
types::RealScalar,
6+
types::Scalar,
77
};
88
use ndelement::traits::MappedFiniteElement;
99

1010
/// Geometry of an entity
1111
#[derive(Debug)]
12-
pub struct MixedEntityGeometry<'a, T: RealScalar, E: MappedFiniteElement> {
12+
pub struct MixedEntityGeometry<'a, T: Scalar, E: MappedFiniteElement> {
1313
geometry: &'a MixedGeometry<T, E>,
1414
element_index: usize,
1515
cell_index: usize,
1616
sub_entity_dim: usize,
1717
sub_entity_index: usize,
1818
}
1919

20-
impl<'a, T: RealScalar, E: MappedFiniteElement> MixedEntityGeometry<'a, T, E> {
20+
impl<'a, T: Scalar, E: MappedFiniteElement> MixedEntityGeometry<'a, T, E> {
2121
/// Create new
2222
pub fn new(
2323
geometry: &'a MixedGeometry<T, E>,
@@ -36,7 +36,7 @@ impl<'a, T: RealScalar, E: MappedFiniteElement> MixedEntityGeometry<'a, T, E> {
3636
}
3737
}
3838

39-
impl<T: RealScalar, E: MappedFiniteElement> Geometry for MixedEntityGeometry<'_, T, E> {
39+
impl<T: Scalar, E: MappedFiniteElement> Geometry for MixedEntityGeometry<'_, T, E> {
4040
type T = T;
4141
type Point<'a>
4242
= Point<'a, T>

src/geometry/mixed/geometry.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Geometry where each entity of a given dimension is represented by the same element
22
#[cfg(feature = "serde")]
33
use crate::traits::ConvertToSerializable;
4-
use crate::types::RealScalar;
4+
use crate::types::Scalar;
55
use itertools::izip;
66
#[cfg(feature = "serde")]
77
use ndelement::{
@@ -19,15 +19,15 @@ use std::collections::HashMap;
1919
use std::fmt::{Debug, Formatter};
2020

2121
/// Single element geometry
22-
pub struct MixedGeometry<T: RealScalar, E: MappedFiniteElement> {
22+
pub struct MixedGeometry<T: Scalar, E: MappedFiniteElement> {
2323
points: DynArray<T, 2>,
2424
cells: Vec<DynArray<usize, 2>>,
2525
elements: Vec<HashMap<ReferenceCellType, E>>,
2626
pub(crate) insertion_indices_to_element_indices: Vec<usize>,
2727
pub(crate) insertion_indices_to_cell_indices: Vec<usize>,
2828
}
2929

30-
impl<T: RealScalar, E: MappedFiniteElement> Debug for MixedGeometry<T, E> {
30+
impl<T: Scalar, E: MappedFiniteElement> Debug for MixedGeometry<T, E> {
3131
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
3232
f.debug_struct("MixedGeometry")
3333
.field("points", &self.points)
@@ -39,7 +39,7 @@ impl<T: RealScalar, E: MappedFiniteElement> Debug for MixedGeometry<T, E> {
3939
#[cfg(feature = "serde")]
4040
#[derive(serde::Serialize, Debug, serde::Deserialize)]
4141
#[serde(bound = "for<'de2> T: serde::Deserialize<'de2>")]
42-
pub struct SerializableGeometry<T: RealScalar + serde::Serialize>
42+
pub struct SerializableGeometry<T: Scalar + serde::Serialize>
4343
where
4444
for<'de2> T: serde::Deserialize<'de2>,
4545
{
@@ -51,8 +51,8 @@ where
5151
}
5252

5353
#[cfg(feature = "serde")]
54-
impl<T: RealScalar + serde::Serialize> ConvertToSerializable
55-
for MixedGeometry<T, CiarletElement<T, IdentityMap>>
54+
impl<T: Scalar + serde::Serialize> ConvertToSerializable
55+
for MixedGeometry<T, CiarletElement<T, IdentityMap, T>>
5656
where
5757
for<'de2> T: serde::Deserialize<'de2>,
5858
{
@@ -115,7 +115,7 @@ where
115115
}
116116
}
117117

118-
impl<T: RealScalar, E: MappedFiniteElement> MixedGeometry<T, E> {
118+
impl<T: Scalar, E: MappedFiniteElement> MixedGeometry<T, E> {
119119
/// Create single element geometry
120120
pub fn new(
121121
cell_types_in: &[ReferenceCellType],

src/geometry/point.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
//! Point
2-
use crate::{traits::Point as PointTrait, types::RealScalar};
2+
use crate::{traits::Point as PointTrait, types::Scalar};
33

44
/// A points
55
#[derive(Debug, Clone, Copy)]
6-
pub struct Point<'a, T: RealScalar> {
6+
pub struct Point<'a, T: Scalar> {
77
index: usize,
88
coordinates: &'a [T],
99
}
1010

11-
impl<'a, T: RealScalar> Point<'a, T> {
11+
impl<'a, T: Scalar> Point<'a, T> {
1212
/// Create new
1313
pub fn new(index: usize, coordinates: &'a [T]) -> Self {
1414
Self { index, coordinates }
1515
}
1616
}
17-
impl<T: RealScalar> PointTrait for Point<'_, T> {
17+
impl<T: Scalar> PointTrait for Point<'_, T> {
1818
type T = T;
1919

2020
fn index(&self) -> usize {
@@ -32,17 +32,17 @@ impl<T: RealScalar> PointTrait for Point<'_, T> {
3232

3333
/// Iterator over points
3434
#[derive(Debug)]
35-
pub struct PointIter<'a, T: RealScalar> {
35+
pub struct PointIter<'a, T: Scalar> {
3636
points: Vec<(usize, &'a [T])>,
3737
index: usize,
3838
}
39-
impl<'a, T: RealScalar> PointIter<'a, T> {
39+
impl<'a, T: Scalar> PointIter<'a, T> {
4040
/// Create new
4141
pub fn new(points: Vec<(usize, &'a [T])>) -> Self {
4242
Self { points, index: 0 }
4343
}
4444
}
45-
impl<'a, T: RealScalar> Iterator for PointIter<'a, T> {
45+
impl<'a, T: Scalar> Iterator for PointIter<'a, T> {
4646
type Item = Point<'a, T>;
4747

4848
fn next(&mut self) -> Option<Point<'a, T>> {

src/geometry/single_element/entity_geometry.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ use super::SingleElementGeometry;
33
use crate::{
44
geometry::{Point, PointIter},
55
traits::Geometry,
6-
types::RealScalar,
6+
types::Scalar,
77
};
88
use ndelement::traits::MappedFiniteElement;
99

1010
/// Geometry of an entity
1111
#[derive(Debug)]
12-
pub struct SingleElementEntityGeometry<'a, T: RealScalar, E: MappedFiniteElement> {
12+
pub struct SingleElementEntityGeometry<'a, T: Scalar, E: MappedFiniteElement> {
1313
geometry: &'a SingleElementGeometry<T, E>,
1414
cell_index: usize,
1515
sub_entity_dimension: usize,
1616
sub_entity_index: usize,
1717
}
1818

19-
impl<'a, T: RealScalar, E: MappedFiniteElement> SingleElementEntityGeometry<'a, T, E> {
19+
impl<'a, T: Scalar, E: MappedFiniteElement> SingleElementEntityGeometry<'a, T, E> {
2020
/// Create new
2121
pub fn new(
2222
geometry: &'a SingleElementGeometry<T, E>,
@@ -33,7 +33,7 @@ impl<'a, T: RealScalar, E: MappedFiniteElement> SingleElementEntityGeometry<'a,
3333
}
3434
}
3535

36-
impl<T: RealScalar, E: MappedFiniteElement> Geometry for SingleElementEntityGeometry<'_, T, E> {
36+
impl<T: Scalar, E: MappedFiniteElement> Geometry for SingleElementEntityGeometry<'_, T, E> {
3737
type T = T;
3838
type Point<'a>
3939
= Point<'a, T>

src/geometry/single_element/geometry.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Geometry where each entity of a given dimension is represented by the same element
22
#[cfg(feature = "serde")]
33
use crate::traits::ConvertToSerializable;
4-
use crate::types::RealScalar;
4+
use crate::types::Scalar;
55
#[cfg(feature = "serde")]
66
use ndelement::{
77
ciarlet::{CiarletElement, lagrange},
@@ -18,13 +18,13 @@ use rlst::{DynArray, rlst_dynamic_array};
1818
use std::fmt::{Debug, Formatter};
1919

2020
/// Single element geometry
21-
pub struct SingleElementGeometry<T: RealScalar, E: MappedFiniteElement> {
21+
pub struct SingleElementGeometry<T: Scalar, E: MappedFiniteElement> {
2222
points: DynArray<T, 2>,
2323
cells: DynArray<usize, 2>,
2424
elements: Vec<E>,
2525
}
2626

27-
impl<T: RealScalar, E: MappedFiniteElement> Debug for SingleElementGeometry<T, E> {
27+
impl<T: Scalar, E: MappedFiniteElement> Debug for SingleElementGeometry<T, E> {
2828
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
2929
f.debug_struct("SingleElementGeometry")
3030
.field("points", &self.points)
@@ -36,7 +36,7 @@ impl<T: RealScalar, E: MappedFiniteElement> Debug for SingleElementGeometry<T, E
3636
#[cfg(feature = "serde")]
3737
#[derive(serde::Serialize, Debug, serde::Deserialize)]
3838
#[serde(bound = "for<'de2> T: serde::Deserialize<'de2>")]
39-
pub struct SerializableGeometry<T: RealScalar + serde::Serialize>
39+
pub struct SerializableGeometry<T: Scalar + serde::Serialize>
4040
where
4141
for<'de2> T: serde::Deserialize<'de2>,
4242
{
@@ -46,8 +46,8 @@ where
4646
}
4747

4848
#[cfg(feature = "serde")]
49-
impl<T: RealScalar + serde::Serialize> ConvertToSerializable
50-
for SingleElementGeometry<T, CiarletElement<T, IdentityMap>>
49+
impl<T: Scalar + serde::Serialize> ConvertToSerializable
50+
for SingleElementGeometry<T, CiarletElement<T, IdentityMap, T>>
5151
where
5252
for<'de2> T: serde::Deserialize<'de2>,
5353
{
@@ -86,7 +86,7 @@ where
8686
}
8787
}
8888

89-
impl<T: RealScalar, E: MappedFiniteElement> SingleElementGeometry<T, E> {
89+
impl<T: Scalar, E: MappedFiniteElement> SingleElementGeometry<T, E> {
9090
/// Create single element geometry
9191
pub fn new(
9292
cell_type: ReferenceCellType,

src/grid/local_grid/mixed/builder.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
geometry::MixedGeometry,
66
topology::mixed::MixedTopology,
77
traits::{Builder, GeometryBuilder, GridBuilder, TopologyBuilder},
8-
types::RealScalar,
8+
types::Scalar,
99
};
1010
use itertools::izip;
1111
use ndelement::{
@@ -20,10 +20,10 @@ use std::collections::{HashMap, HashSet};
2020

2121
/// Grid builder for a grid with a mixture of element types
2222
#[derive(Debug)]
23-
pub struct MixedGridBuilder<T: RealScalar> {
23+
pub struct MixedGridBuilder<T: Scalar> {
2424
gdim: usize,
2525
element_indices: HashMap<(ReferenceCellType, usize), usize>,
26-
elements: Vec<CiarletElement<T, IdentityMap>>,
26+
elements: Vec<CiarletElement<T, IdentityMap, T>>,
2727
points_per_cell: Vec<usize>,
2828
pub(crate) points: Vec<T>,
2929
cells: Vec<usize>,
@@ -39,7 +39,7 @@ pub struct MixedGridBuilder<T: RealScalar> {
3939
cell_indices: HashSet<usize>,
4040
}
4141

42-
impl<T: RealScalar> MixedGridBuilder<T> {
42+
impl<T: Scalar> MixedGridBuilder<T> {
4343
/// Create a new grid builder
4444
pub fn new(gdim: usize) -> Self {
4545
Self {
@@ -63,8 +63,8 @@ impl<T: RealScalar> MixedGridBuilder<T> {
6363
}
6464
}
6565

66-
impl<T: RealScalar> Builder for MixedGridBuilder<T> {
67-
type Grid = MixedGrid<T, CiarletElement<T, IdentityMap>>;
66+
impl<T: Scalar> Builder for MixedGridBuilder<T> {
67+
type Grid = MixedGrid<T, CiarletElement<T, IdentityMap, T>>;
6868
type T = T;
6969
type CellData<'a> = (ReferenceCellType, usize, &'a [usize]);
7070
type EntityDescriptor = ReferenceCellType;
@@ -89,7 +89,7 @@ impl<T: RealScalar> Builder for MixedGridBuilder<T> {
8989
.entry((cell_data.0, cell_data.1))
9090
.or_insert_with(|| {
9191
let n = self.cell_indices_to_ids.len();
92-
self.elements.push(lagrange::create::<T>(
92+
self.elements.push(lagrange::create::<T, T>(
9393
cell_data.0,
9494
cell_data.1,
9595
Continuity::Standard,
@@ -127,7 +127,7 @@ impl<T: RealScalar> Builder for MixedGridBuilder<T> {
127127
self.add_cell(id, (cell_type, cell_degree, nodes));
128128
}
129129

130-
fn create_grid(&self) -> MixedGrid<T, CiarletElement<T, IdentityMap>> {
130+
fn create_grid(&self) -> MixedGrid<T, CiarletElement<T, IdentityMap, T>> {
131131
let cell_vertices =
132132
self.extract_vertices(&self.cells, &self.cell_types, &self.cell_degrees);
133133

@@ -209,16 +209,16 @@ impl<T: RealScalar> Builder for MixedGridBuilder<T> {
209209
}
210210
}
211211

212-
impl<T: RealScalar> GeometryBuilder for MixedGridBuilder<T> {
213-
type GridGeometry = MixedGeometry<T, CiarletElement<T, IdentityMap>>;
212+
impl<T: Scalar> GeometryBuilder for MixedGridBuilder<T> {
213+
type GridGeometry = MixedGeometry<T, CiarletElement<T, IdentityMap, T>>;
214214
fn create_geometry(
215215
&self,
216216
point_ids: &[usize],
217217
coordinates: &[Self::T],
218218
cell_points: &[usize],
219219
cell_types: &[ReferenceCellType],
220220
cell_degrees: &[usize],
221-
) -> MixedGeometry<T, CiarletElement<T, IdentityMap>> {
221+
) -> MixedGeometry<T, CiarletElement<T, IdentityMap, T>> {
222222
let npts = point_ids.len();
223223
let mut points = rlst_dynamic_array!(T, [self.gdim(), npts]);
224224
points.data_mut().unwrap().copy_from_slice(coordinates);
@@ -229,15 +229,15 @@ impl<T: RealScalar> GeometryBuilder for MixedGridBuilder<T> {
229229
for degree in cell_degrees {
230230
cell_families.push(*ef_indices.entry(*degree).or_insert_with(|| {
231231
let n = element_families.len();
232-
element_families.push(LagrangeElementFamily::<T>::new(
232+
element_families.push(LagrangeElementFamily::<T, T>::new(
233233
*degree,
234234
Continuity::Standard,
235235
));
236236
n
237237
}))
238238
}
239239

240-
MixedGeometry::<T, CiarletElement<T, IdentityMap>>::new(
240+
MixedGeometry::<T, CiarletElement<T, IdentityMap, T>>::new(
241241
cell_types,
242242
points,
243243
cell_points,
@@ -247,7 +247,7 @@ impl<T: RealScalar> GeometryBuilder for MixedGridBuilder<T> {
247247
}
248248
}
249249

250-
impl<T: RealScalar> TopologyBuilder for MixedGridBuilder<T> {
250+
impl<T: Scalar> TopologyBuilder for MixedGridBuilder<T> {
251251
type GridTopology = MixedTopology;
252252
fn create_topology(
253253
&self,
@@ -297,7 +297,7 @@ impl<T: RealScalar> TopologyBuilder for MixedGridBuilder<T> {
297297
}
298298
}
299299

300-
impl<T: RealScalar> GridBuilder for MixedGridBuilder<T> {
300+
impl<T: Scalar> GridBuilder for MixedGridBuilder<T> {
301301
fn create_grid_from_topology_geometry(
302302
&self,
303303
topology: <Self as TopologyBuilder>::GridTopology,

0 commit comments

Comments
 (0)