Skip to main content

DiagonalOperator

Struct DiagonalOperator 

Source
pub struct DiagonalOperator<Input, Output> {
    pub diagonal: DVector<f64>,
    /* private fields */
}
Expand description

A diagonal matrix operator.

See MatrixOperator and the crate-level docs for more details.

Fields§

§diagonal: DVector<f64>

The diagonal values of the matrix, stored as a vector.

Modifying the dimension of this vector will result in runtime errors.

Values of the diagonal can also be accessed by indexing with SimplexViews / DualCellViews corresponding to the output type of the operator:

type P = Cochain<1, Primal>;
type D = Cochain<2, Dual>;

let star: DiagonalOperator<P, D> = mesh_3d.star();
let star_dual: DiagonalOperator<D, P> = mesh_3d.star();

for edge in mesh_3d.simplices::<1>() {
    // these stars are inverses of each other so they should multiply to 1
    assert!((star_dual[edge] * star[edge.dual()] - 1.).abs() < 1e-6);
}

This can be handy to e.g. retrieve values of material parameters stored in an operator created with SimplicialMesh::scaling.

Implementations§

Source§

impl<Input, Output> DiagonalOperator<Input, Output>
where Input: Operand, Output: Operand,

Source

pub fn exclude_subset( self, set: &SubsetImpl<<<Self as Operator>::Output as Operand>::Dimension, <<Self as Operator>::Output as Operand>::Primality>, ) -> Self

Set a subset of elements in the output cochain to zero when this operator is applied (i.e. set a subset of rows in the operator matrix to zero). useful for boundary conditions.

Source

pub fn restrict_to_subset( self, set: &SubsetImpl<<<Self as Operator>::Output as Operand>::Dimension, <<Self as Operator>::Output as Operand>::Primality>, ) -> Self

Set all output elements that aren’t part of the given subset to zero.

Source

pub fn inverse(&self) -> DiagonalOperator<Output, Input>

The matrix inverse of this diagonal operator (i.e. simply the reciprocals of the elements).

At the type level, this swaps the input and output types. If you need the types to remain the same, use recip instead. Note also that this is not always the same as the dual Hodge star, since it can differ from the matrix inverse by a sign.

Source

pub fn recip(&self) -> Self

The matrix inverse of this operator, but unlike inverse, keeping the input and output types unchanged.

This and inverse are both simply more convenient ways to write DiagonalOperator::from(my_op.diagonal.map(|el| 1. / el)), which is still a useful pattern if you need more esoteric manipulations than simple scalings or inverses.

Source

pub fn inner_product(&self, lhs: &Input, rhs: &Input) -> f64

Compute the inner product between two cochains defined by this operator, i.e. the matrix product a^T D b, where D is this operator and a,b are cochains of its input type.

Note: this does not check that the operator is positive definite, so the operation may not actually be an inner product.

Source

pub fn norm(&self, c: &Input) -> f64

Compute the norm of a cochain defined by this operator, i.e. its inner_product with itself.

The same caveat applies as to inner_product: this does not check that the operator is positive definite, so the operation may not actually be a norm.

Trait Implementations§

Source§

impl<Input: Clone, Output: Clone> Clone for DiagonalOperator<Input, Output>

Source§

fn clone(&self) -> DiagonalOperator<Input, Output>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Input: Debug, Output: Debug> Debug for DiagonalOperator<Input, Output>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Input, Output> From<DiagonalOperator<Input, Output>> for MatrixOperator<Input, Output>
where DiagonalOperator<Input, Output>: Operator,

Source§

fn from(s: DiagonalOperator<Input, Output>) -> Self

Converts to this type from the input type.
Source§

impl<Input, Output> From<Matrix<f64, Dyn, Const<1>, VecStorage<f64, Dyn, Const<1>>>> for DiagonalOperator<Input, Output>

Source§

fn from(diagonal: DVector<f64>) -> Self

Converts to this type from the input type.
Source§

impl<'a, In, OutDim, const MESH_DIM: usize> Index<DualCellView<'a, OutDim, MESH_DIM>> for DiagonalOperator<In, CochainImpl<OutDim, Dual>>
where OutDim: DimName, Const<MESH_DIM>: DimNameSub<OutDim>,

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: DualCellView<'a, OutDim, MESH_DIM>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, In, OutDim, const MESH_DIM: usize> Index<SimplexView<'a, OutDim, MESH_DIM>> for DiagonalOperator<In, CochainImpl<OutDim, Primal>>
where OutDim: DimName, Const<MESH_DIM>: DimNameSub<OutDim>,

Source§

type Output = f64

The returned type after indexing.
Source§

fn index(&self, index: SimplexView<'a, OutDim, MESH_DIM>) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, In, OutDim, const MESH_DIM: usize> IndexMut<DualCellView<'a, OutDim, MESH_DIM>> for DiagonalOperator<In, CochainImpl<OutDim, Dual>>
where OutDim: DimName, Const<MESH_DIM>: DimNameSub<OutDim>,

Source§

fn index_mut( &mut self, index: DualCellView<'a, OutDim, MESH_DIM>, ) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, In, OutDim, const MESH_DIM: usize> IndexMut<SimplexView<'a, OutDim, MESH_DIM>> for DiagonalOperator<In, CochainImpl<OutDim, Primal>>
where OutDim: DimName, Const<MESH_DIM>: DimNameSub<OutDim>,

Source§

fn index_mut( &mut self, index: SimplexView<'a, OutDim, MESH_DIM>, ) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<Out, D, P> Mul<&CochainImpl<D, P>> for &DiagonalOperator<CochainImpl<D, P>, Out>
where Out: Operand,

Source§

type Output = Out

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &CochainImpl<D, P>) -> Self::Output

Performs the * operation. Read more
Source§

impl<Out, D, P> Mul<&CochainImpl<D, P>> for DiagonalOperator<CochainImpl<D, P>, Out>
where Out: Operand,

Source§

type Output = Out

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &CochainImpl<D, P>) -> Self::Output

Performs the * operation. Read more
Source§

impl<Input, Output> Mul<DiagonalOperator<Input, Output>> for f64

Source§

type Output = DiagonalOperator<Input, Output>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: DiagonalOperator<Input, Output>) -> Self::Output

Performs the * operation. Read more
Source§

impl<In, Out, OtherIn> Mul<DiagonalOperator<OtherIn, In>> for DiagonalOperator<In, Out>
where In: Operand, Out: Operand, OtherIn: Operand,

Source§

type Output = DiagonalOperator<OtherIn, Out>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: DiagonalOperator<OtherIn, In>) -> Self::Output

Performs the * operation. Read more
Source§

impl<In, Out, OtherIn> Mul<MatrixOperator<OtherIn, In>> for DiagonalOperator<In, Out>
where In: Operand, Out: Operand, OtherIn: Operand,

Source§

type Output = MatrixOperator<OtherIn, Out>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: MatrixOperator<OtherIn, In>) -> Self::Output

Performs the * operation. Read more
Source§

impl<Input, Output> Neg for DiagonalOperator<Input, Output>

Source§

type Output = DiagonalOperator<Input, Output>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<Input, Output> Operator for DiagonalOperator<Input, Output>
where Input: Operand, Output: Operand,

Source§

type Input = Input

The type of cochain this operator takes as an input.
Source§

type Output = Output

The type of cochain this operator produces as an output.
Source§

fn apply(&self, input: &Self::Input) -> Self::Output

Apply this operator to an input cochain.
Source§

fn into_csr(self) -> CsrMatrix<f64>

Convert this operator into a CSR matrix.
Source§

impl<Input, Output> PartialEq for DiagonalOperator<Input, Output>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<Input, Output> Freeze for DiagonalOperator<Input, Output>

§

impl<Input, Output> RefUnwindSafe for DiagonalOperator<Input, Output>
where Input: RefUnwindSafe, Output: RefUnwindSafe,

§

impl<Input, Output> Send for DiagonalOperator<Input, Output>
where Input: Send, Output: Send,

§

impl<Input, Output> Sync for DiagonalOperator<Input, Output>
where Input: Sync, Output: Sync,

§

impl<Input, Output> Unpin for DiagonalOperator<Input, Output>
where Input: Unpin, Output: Unpin,

§

impl<Input, Output> UnsafeUnpin for DiagonalOperator<Input, Output>

§

impl<Input, Output> UnwindSafe for DiagonalOperator<Input, Output>
where Input: UnwindSafe, Output: UnwindSafe,

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
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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

fn from_subset(element: &SS) -> SP

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
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.
Source§

impl<T> ClosedNeg for T
where T: Neg<Output = T>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,