Struct funspace::fourier::FourierC2c[][src]

pub struct FourierC2c<A> {
    pub n: usize,
    pub m: usize,
    pub x: Array1<A>,
    pub k: Array1<Complex<A>>,
    pub fft_handler: FftHandler<A>,
    // some fields omitted
}
Expand description

Fields

n: usize

Number of coefficients in physical space

m: usize

Number of coefficients in spectral space

x: Array1<A>

Grid coordinates of fourier nodes

k: Array1<Complex<A>>

Complex wavenumber vector

fft_handler: FftHandler<A>

Handles discrete cosine transform

Implementations

Returns a new Fourier Basis

Return equispaced points on intervall [0, 2pi[

Panics

Panics when conversion f64 to generic A fails

Differentiate 1d Array n_times

Example

Differentiate along lane

use funspace::fourier::FourierC2c;
use funspace::utils::approx_eq_complex;
use ndarray::prelude::*;
let fo = FourierC2c::<f64>::new(5);
let mut k = fo.k.clone();
let expected = k.mapv(|x| x.powf(2.));
fo.differentiate_lane(&mut k, 1);
approx_eq_complex(&k, &expected);

Panics

When type conversion fails ( safe )

Trait Implementations

Size in physical space

Size in spectral space

Coordinates in physical space

Return mass matrix (= eye)

Return transform kind

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Perform differentiation in spectral space

Return differentiated array

Differentiate on input array

Perform differentiation in spectral space

Return differentiated array

Differentiate on input array

Performs the conversion.

Return itself

Return itself

Return itself

Return itself

Return itself

Return itself

Return itself

Return itself

Laplacian ( = |k^2| ) diagonal matrix

Pseudoinverse Laplacian for FourierC2c basis ( = 1 / |k^2| ) diagonal matrix

use funspace::fourier::FourierC2c;
use funspace::LaplacianInverse;
use ndarray::prelude::*;
use funspace::utils::approx_eq;
let fo = FourierC2c::<f64>::new(4);
let mut laplacian = fo.laplace();
let result = fo.laplace_inv().dot(&laplacian);
approx_eq(
    &fo.laplace_inv_eye(), &result.slice(s![1..,..]).to_owned()
);

Pseudoidentity matrix (= eye matrix with removed first row for FourierC2c)

Example

Forward transform along first axis

use funspace::fourier::FourierC2c;
use funspace::Transform;
use funspace::utils::approx_eq_complex;
use num_complex::Complex;
use ndarray::prelude::*;
let mut fo = FourierC2c::new(4);
let mut input = array![
    Complex::new(1., 1.),
    Complex::new(2., 2.),
    Complex::new(3., 3.),
    Complex::new(4., 4.)
];
let expected = array![
    Complex::new(10., 10.),
    Complex::new(-4., 0.),
    Complex::new(-2., -2.),
    Complex::new(0., -4.)
];
let output = fo.forward(&mut input, 0);
approx_eq_complex(&output, &expected);

Example

Backward transform along first axis

use funspace::fourier::FourierC2c;
use funspace::Transform;
use funspace::utils::approx_eq_complex;
use num_complex::Complex;
use ndarray::prelude::*;
let mut fo = FourierC2c::new(4);
let mut input = array![
    Complex::new(10., 10.),
    Complex::new(-4., 0.),
    Complex::new(-2., -2.),
    Complex::new(0., -4.)
];
let expected = array![
    Complex::new(1., 1.),
    Complex::new(2., 2.),
    Complex::new(3., 3.),
    Complex::new(4., 4.)
];
let output = fo.backward(&mut input, 0);
approx_eq_complex(&output, &expected);

See FourierC2c::backward

Panics

Panics when input type cannot be cast from f64.

Example

Forward transform along first axis

use funspace::fourier::FourierC2c;
use funspace::TransformPar;
use funspace::utils::approx_eq_complex;
use num_complex::Complex;
use ndarray::prelude::*;
let mut fo = FourierC2c::new(4);
let mut input = array![
    Complex::new(1., 1.),
    Complex::new(2., 2.),
    Complex::new(3., 3.),
    Complex::new(4., 4.)
];
let expected = array![
    Complex::new(10., 10.),
    Complex::new(-4., 0.),
    Complex::new(-2., -2.),
    Complex::new(0., -4.)
];
let output = fo.forward_par(&mut input, 0);
approx_eq_complex(&output, &expected);

Example

Backward transform along first axis

use funspace::fourier::FourierC2c;
use funspace::TransformPar;
use funspace::utils::approx_eq_complex;
use num_complex::Complex;
use ndarray::prelude::*;
let mut fo = FourierC2c::new(4);
let mut input = array![
    Complex::new(10., 10.),
    Complex::new(-4., 0.),
    Complex::new(-2., -2.),
    Complex::new(0., -4.)
];
let expected = array![
    Complex::new(1., 1.),
    Complex::new(2., 2.),
    Complex::new(3., 3.),
    Complex::new(4., 4.)
];
let output = fo.backward_par(&mut input, 0);
approx_eq_complex(&output, &expected);

See FourierC2c::backward_par

Panics

Panics when input type cannot be cast from f64.

Scalar type in physical space (before transform)

Scalar type in spectral space (after transfrom)

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.