Skip to main content

FunctionSpaceImpl

Struct FunctionSpaceImpl 

Source
pub struct FunctionSpaceImpl<'a, T: RlstScalar, TMesh: RlstScalar, E: Debug + PartialEq + Eq + Clone + Copy + Hash, G: Mesh<EntityDescriptor = E, T = TMesh>, F: MappedFiniteElement<CellType = E, T = T>> { /* private fields */ }
Expand description

Function space.

Implementations§

Source§

impl<'a, T: RlstScalar, TMesh: RlstScalar, G: Mesh<EntityDescriptor = ReferenceCellType, T = TMesh>, F: MappedFiniteElement<CellType = ReferenceCellType, T = T>> FunctionSpaceImpl<'a, T, TMesh, ReferenceCellType, G, F>

Source

pub fn new<EF: ElementFamily<FiniteElement = F, CellType = ReferenceCellType>>( mesh: &'a G, family: &EF, ) -> Self

Create a new serial function space

Examples found in repository?
ndfunctionspace/examples/test_parallel_space.rs (line 30)
16fn test_parallel_function_space<C: Communicator>(comm: &C) {
17    let mesh = unit_cube_distributed::<f64, _>(
18        comm,
19        GraphPartitioner::None,
20        4,
21        4,
22        4,
23        ReferenceCellType::Tetrahedron,
24    );
25
26    let family =
27        LagrangeElementFamily::<f64>::new(2, Continuity::Standard, LagrangeVariant::Equispaced);
28    let space = ParallelFunctionSpaceImpl::new(&mesh, &family);
29    let serial_mesh = unit_cube::<f64>(4, 4, 4, ReferenceCellType::Tetrahedron);
30    let serial_space = FunctionSpaceImpl::new(&serial_mesh, &family);
31
32    assert_eq!(space.global_size(), serial_space.global_size());
33}
More examples
Hide additional examples
ndfunctionspace/examples/test_mass_matrix.rs (line 23)
18fn test_lagrange_mass_matrix() {
19    let mesh = regular_sphere(0, ReferenceCellType::Triangle);
20
21    let family =
22        LagrangeElementFamily::<f64>::new(1, Continuity::Standard, LagrangeVariant::Equispaced);
23    let space = FunctionSpaceImpl::new(&mesh, &family);
24
25    let mut mass_matrix = rlst_dynamic_array!(f64, [space.process_size(), space.process_size()]);
26
27    let element = &space.elements()[0];
28
29    let (p, w) = single_integral_quadrature(
30        QuadratureRule::XiaoGimbutas,
31        Domain::Triangle,
32        2 * element.lagrange_superdegree(),
33    )
34    .unwrap();
35    let npts = w.len();
36    let mut pts = rlst_dynamic_array!(f64, [2, npts]);
37    for i in 0..w.len() {
38        for j in 0..2 {
39            *pts.get_mut([j, i]).unwrap() = p[3 * i + j];
40        }
41    }
42    let wts = w.iter().map(|i| *i / 2.0).collect::<Vec<_>>();
43
44    let mut table = DynArray::<f64, 4>::from_shape(element.tabulate_array_shape(0, npts));
45    element.tabulate(&pts, 0, &mut table);
46
47    let gmap = mesh.geometry_map(ReferenceCellType::Triangle, 1, &pts);
48    let mut jacobians = rlst_dynamic_array!(f64, [mesh.geometry_dim(), mesh.topology_dim(), npts]);
49    let mut jinv = rlst_dynamic_array!(f64, [mesh.topology_dim(), mesh.geometry_dim(), npts]);
50    let mut jdets = vec![0.0; npts];
51
52    for cell in mesh.entity_iter(ReferenceCellType::Triangle) {
53        let dofs = space
54            .entity_closure_dofs(ReferenceCellType::Triangle, cell.local_index())
55            .unwrap();
56        gmap.jacobians_inverses_dets(cell.local_index(), &mut jacobians, &mut jinv, &mut jdets);
57        for (test_i, test_dof) in dofs.iter().enumerate() {
58            for (trial_i, trial_dof) in dofs.iter().enumerate() {
59                *mass_matrix.get_mut([*test_dof, *trial_dof]).unwrap() += wts
60                    .iter()
61                    .enumerate()
62                    .map(|(i, w)| {
63                        jdets[i]
64                            * *w
65                            * *table.get([0, i, test_i, 0]).unwrap()
66                            * *table.get([0, i, trial_i, 0]).unwrap()
67                    })
68                    .sum::<f64>();
69            }
70        }
71    }
72
73    // Compare matrix entries to values from Bempp
74    for i in 0..6 {
75        assert_relative_eq!(mass_matrix[[i, i]], 0.5773502691896255, epsilon = 1e-10);
76    }
77    for i in 0..6 {
78        for j in 0..6 {
79            if i != j && mass_matrix[[i, j]].abs() > 0.001 {
80                assert_relative_eq!(mass_matrix[[i, j]], 0.1443375672974061, epsilon = 1e-10);
81            }
82        }
83    }
84}
85
86/// Test values in Raviart-Thomas mass matrix
87fn test_rt_mass_matrix() {
88    let mesh = regular_sphere(0, ReferenceCellType::Triangle);
89
90    let family = RaviartThomasElementFamily::<f64>::new(1, Continuity::Standard);
91    let space = FunctionSpaceImpl::new(&mesh, &family);
92
93    let mut mass_matrix = rlst_dynamic_array!(f64, [space.process_size(), space.process_size()]);
94
95    let element = &space.elements()[0];
96
97    let (p, w) = single_integral_quadrature(
98        QuadratureRule::XiaoGimbutas,
99        Domain::Triangle,
100        2 * element.lagrange_superdegree(),
101    )
102    .unwrap();
103    let npts = w.len();
104    let mut pts = rlst_dynamic_array!(f64, [2, npts]);
105    for i in 0..w.len() {
106        for j in 0..2 {
107            *pts.get_mut([j, i]).unwrap() = p[3 * i + j];
108        }
109    }
110    let wts = w.iter().map(|i| *i / 2.0).collect::<Vec<_>>();
111
112    let mut table = DynArray::<f64, 4>::from_shape(element.tabulate_array_shape(0, npts));
113    element.tabulate(&pts, 0, &mut table);
114    let mut pushed_table = rlst_dynamic_array!(
115        f64,
116        [table.shape()[0], table.shape()[1], table.shape()[2], 3]
117    );
118
119    let gmap = mesh.geometry_map(ReferenceCellType::Triangle, 1, &pts);
120    let mut jacobians = rlst_dynamic_array!(f64, [mesh.geometry_dim(), mesh.topology_dim(), npts]);
121    let mut jinv = rlst_dynamic_array!(f64, [mesh.topology_dim(), mesh.geometry_dim(), npts]);
122    let mut jdets = vec![0.0; npts];
123
124    for cell in mesh.entity_iter(ReferenceCellType::Triangle) {
125        let dofs = space
126            .entity_closure_dofs(ReferenceCellType::Triangle, cell.local_index())
127            .unwrap();
128        gmap.jacobians_inverses_dets(cell.local_index(), &mut jacobians, &mut jinv, &mut jdets);
129        element.push_forward(&table, 0, &jacobians, &jdets, &jinv, &mut pushed_table);
130
131        for (test_i, test_dof) in dofs.iter().enumerate() {
132            for (trial_i, trial_dof) in dofs.iter().enumerate() {
133                *mass_matrix.get_mut([*test_dof, *trial_dof]).unwrap() += wts
134                    .iter()
135                    .enumerate()
136                    .map(|(i, w)| {
137                        jdets[i]
138                            * *w
139                            * (0..3)
140                                .map(|j| {
141                                    *pushed_table.get([0, i, test_i, j]).unwrap()
142                                        * *pushed_table.get([0, i, trial_i, j]).unwrap()
143                                })
144                                .sum::<f64>()
145                    })
146                    .sum::<f64>();
147            }
148        }
149    }
150
151    // Compare matrix entries to FEniCS
152    for i in 0..12 {
153        assert_relative_eq!(mass_matrix[[i, i]], 0.4811252243246884, epsilon = 1e-10);
154    }
155    for i in 0..12 {
156        for j in 0..12 {
157            if i != j && mass_matrix[[i, j]].abs() > 0.001 {
158                assert_relative_eq!(
159                    mass_matrix[[i, j]].abs(),
160                    0.0481125224324689,
161                    epsilon = 1e-10
162                );
163            }
164        }
165    }
166}

Trait Implementations§

Source§

impl<'a, T: RlstScalar, TMesh: RlstScalar, E: Debug + PartialEq + Eq + Clone + Copy + Hash, G: Mesh<EntityDescriptor = E, T = TMesh>, F: MappedFiniteElement<CellType = E, T = T>> FunctionSpace for FunctionSpaceImpl<'a, T, TMesh, E, G, F>

Source§

type T = T

Scalar type
Source§

type TMesh = TMesh

Scalar type for geometry
Source§

type EntityDescriptor = E

Type used as identifier of different entity types
Source§

type Mesh = G

The type for the mesh this function space is defined on
Source§

type FiniteElement = F

The type for the finite element this mesh is defined by
Source§

fn mesh(&self) -> &G

The mesh that this function space is defined on
Source§

fn elements(&self) -> &[F]

The finite elements used in this function space
Source§

fn entities_by_element(&self, element_index: usize) -> Option<&[usize]>

A list of entity indices that use the element with the given index
Source§

fn entity_dofs(&self, entity_type: E, entity_number: usize) -> Option<&[usize]>

Get the process DOF numbers associated with the given entity
Source§

fn entity_closure_dofs( &self, entity_type: E, entity_number: usize, ) -> Option<&[usize]>

Get the process DOF numbers associated with the closure of the given entity Read more
Source§

fn process_size(&self) -> usize

Get the number of process DOFs Read more
Source§

fn process_owned_size(&self) -> usize

Get the number of owned process DOFs
Source§

fn global_size(&self) -> usize

Get the number of DOFs on all processes
Source§

fn global_dof_index(&self, process_dof_index: usize) -> usize

Get the global DOF index associated with a process DOF index
Source§

fn ownership(&self, _process_dof_index: usize) -> Ownership

Get ownership of a process DOF

Auto Trait Implementations§

§

impl<'a, T, TMesh, E, G, F> Freeze for FunctionSpaceImpl<'a, T, TMesh, E, G, F>

§

impl<'a, T, TMesh, E, G, F> RefUnwindSafe for FunctionSpaceImpl<'a, T, TMesh, E, G, F>

§

impl<'a, T, TMesh, E, G, F> Send for FunctionSpaceImpl<'a, T, TMesh, E, G, F>
where G: Sync, F: Send, E: Send,

§

impl<'a, T, TMesh, E, G, F> Sync for FunctionSpaceImpl<'a, T, TMesh, E, G, F>
where G: Sync, F: Sync, E: Sync,

§

impl<'a, T, TMesh, E, G, F> Unpin for FunctionSpaceImpl<'a, T, TMesh, E, G, F>
where F: Unpin, E: Unpin,

§

impl<'a, T, TMesh, E, G, F> UnsafeUnpin for FunctionSpaceImpl<'a, T, TMesh, E, G, F>

§

impl<'a, T, TMesh, E, G, F> UnwindSafe for FunctionSpaceImpl<'a, T, TMesh, E, G, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

§

type Err = NoError

The error type produced by a failed conversion.
§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T, Dst> ConvAsUtil<Dst> for T

§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
§

impl<T> ConvUtil for T

§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<Src> TryFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<Src> ValueFrom<Src> for Src

§

type Err = NoError

The error type produced by a failed conversion.
§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more