specialmatrices_poisson2D Module


Uses


Interfaces

public interface Poisson2D

Constructor for generating a Poisson2D matrix. The matrix corresponds to the standard second-order accurate finite-difference approximation of the Laplace operator with homogeneous Dirichlet boundary conditions.

Syntax

  • Construct the finite-difference approximation of the Laplace operator on the rectangular domain using 128 points in the horizontal direction and 256 in the vertical one.
   type(Poisson2D)     :: A
   integer, parameter  :: nx = 128, ny = 256
   real(dp), parameter :: Lx = 1.0_dp, Ly = 2.0_dp

   A = Poisson2D(nx, ny, Lx, Ly)

Note

Only doube precision is currently supported for this matrix type.

Note

Note that Lx and Ly are optional. If not specified, they default to 1.0_dp.

  • private pure module function initialize(nx, ny, Lx, Ly) result(A)

    Utility function to construct a Poisson2D matrix.

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=ilp), intent(in) :: nx

    Number of grid points in each direction.

    integer(kind=ilp), intent(in) :: ny

    Number of grid points in each direction.

    real(kind=dp), intent(in), optional :: Lx

    Physical extent of each dimension.

    real(kind=dp), intent(in), optional :: Ly

    Physical extent of each dimension.

    Return Value type(Poisson2D)

    Corresponding Poisson2D matrix.

public interface dense

Cnvert a matrix of type Poisson2D to its dense representation as a standard rank-2 array.

Syntax

   B = dense(A)

Arguments

  • A : Matrix of Poisson2D type. It is an intent(in) argument.

  • B : Rank-2 real array corresponding to the dense representation of A.

  • private pure module function dense_rdp(A) result(B)

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp), allocatable, (:,:)

    Dense representation.

public interface det

This interface overloads the det interface from stdlib_linalg to compute the determinant of a Poisson2D matrix .

Syntax

   d = det(A)

Arguments

  • A : Matrix of Poisson2D type. It is an intent(in) argument.

  • d : Determinant of the matrix.

  • private pure module function det_rdp(A) result(d)

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp)

    Determinant of the matrix.

public interface eigh

This interface overloads the eigh interface from stdlib_linalg to compute the eigenvalues and eigenvectors of the Poisson2D matrix .

Syntax

   call eigh(A, lambda, vectors)

Arguments

  • A : Matrix of Poisson2D type. It is an intent(in) argument.

  • lambda: Rank-1 real array returning the eigenvalues of A in increasing order. It is an intent(out) argument.

  • vectors: Rank-2 real array returning the eigenvectors of A. It is an intent(out) argument.

Note

Both the eigenvalues and eigenvectors of the Poisson2D matrix are known analytically and can thus be constructed efficiently.

  • private module subroutine eigh_rdp(A, lambda, vectors)

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(out), allocatable, target :: lambda(:)

    Eigenvalues.

    real(kind=dp), intent(out), allocatable :: vectors(:,:)

public interface eigvalsh

This interface overloads the eigvalsh interface from stdlib_linalg to compute the eigenvalues of the Poisson2D matrix .

Syntax

   lambda = eigvalsh(A)

Arguments

  • A : Matrix of Poisson2D type. It is an intent(in) argument.

  • lambda : Rank-1 real array returning the eigenvalues of A in increasing order.

Note

The eigenvalues of the Poisson2D matrix are known analytically and can thus be computed efficiently.

  • private module function eigvalsh_rdp(A) result(lambda)

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp), allocatable, target, (:)

    Eigenvalues.

public interface matmul

This interface overloads the Fortran intrinsic matmul for a Poisson2D matrixn, both for matrix-vector and matrix-matrix products. For a matrix-matrix product , only the matrix has to be a Poisson2D matrix. Both and are standard Fortran rank-2 arrays.

Syntax

   y = matmul(A, x)
  • private module function spmv(A, x) result(y)

    Compute the matrix-vector product for a Poisson2D matrix . Both x and y are rank-1 arrays with the same kind as A.

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(in), target :: x(:)

    Input vector.

    Return Value real(kind=dp), allocatable, target, (:)

    Output vector.

  • private module function spmvs(A, x) result(y)

    Compute the matrix-matrix product for a Poisson2D matrix . and are rank-2 arrays of appropriate size with the same kind as .

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    real(kind=dp), intent(in), target, contiguous :: x(:,:)

    Input vectors.

    Return Value real(kind=dp), allocatable, target, (:,:)

    Output vectors.

public interface shape

Utility function to return the shape a Poisson2D matrix .

  • private pure module function shape_rdp(A) result(arr_shape)

    Utility function to get the shape of the Poisson2D matrix.

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    Return Value integer(kind=ilp), (2)

    Shape of the matrix.

public interface size

Utility function to return the size of a Poisson2D matrix along a given dimension.

  • private pure module function size_rdp(A, dim) result(arr_size)

    Utility function to return the size of a Poisson2D matrix along a given dimension.

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    integer(kind=ilp), intent(in), optional :: dim

    Queried dimension.

    Return Value integer(kind=ilp)

    Corresponding size.

public interface solve

This interface overloads the solve interface from stdlib_linalg for solving a system where is a Poisson2D matrix. It also enables to solve a linear system with multiple right-hand sides.

Syntax

   x = solve(A, b)

Arguments

  • A : Matrix of type Poisson2D. It is an intent(in) argument.

  • b : Rank-1 or rank-2 array defining the right-hand side(s). It is an intent(in) argument.

  • x : Solution of the linear system. It has the same type and shape as b.

Note

It uses a fast Poisson solver leveraging the discrete sine transform provided by fftpack. Only homogeneous Dirichlet boundary conditions are handled by default. If non-homogeneous Dirichlet boundary conditions need to be used, they can be implemented by modifiying the right-hand side vector. Neuman-type boundary conditions are not supported at all.

  • private pure module function solve_multi_rhs(A, b) result(x)

    Solve the linear system using a fast Poisson solver.

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Coefficient matrix.

    real(kind=dp), intent(in) :: b(:,:)

    Right-hand side vectors.

    Return Value real(kind=dp), allocatable, target, (:,:)

    Solution vectors.

  • private pure module function solve_single_rhs(A, b) result(x)

    Solve the linear system using a fast Poisson solver.

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Coefficient matrix.

    real(kind=dp), intent(in) :: b(:)

    Right-hand side vector.

    Return Value real(kind=dp), allocatable, target, (:)

    Solution vector.

public interface trace

This interace overloads the trace interface from stdlib_linalg to compute the trace of a Poisson2D matrix .

Syntax

   tr = trace(A)

Arguments

  • A : Matrix of Poisson2D type. It is an intent(in) argument.

  • tr: Trace of the matrix.

  • private pure module function trace_rdp(A) result(tr)

    Arguments

    Type IntentOptional Attributes Name
    type(Poisson2D), intent(in) :: A

    Input matrix.

    Return Value real(kind=dp)

    Trace of the matrix.


Derived Types

type, public ::  Poisson2D

Base type used to define a Poisson2D matrix on a rectangular domain discretized with nx and ny points in each direction and corresponding grid spacings dx and dy.

Constructor

Constructor for generating a Poisson2D matrix. The matrix corresponds to the standard second-order accurate finite-difference approximation of the Laplace operator with homogeneous Dirichlet boundary conditions.

Read more…
private pure, module function initialize (nx, ny, Lx, Ly)

Utility function to construct a Poisson2D matrix.