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.
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.
Utility function to construct a Poisson2D matrix.
| Type | Intent | Optional | 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. |
Corresponding Poisson2D matrix.
Cnvert a matrix of type Poisson2D to its dense representation as a
standard rank-2 array.
B = dense(A)
A : Matrix of Poisson2D type. It is an intent(in) argument.
B : Rank-2 real array corresponding to the dense representation
of A.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Input matrix. |
Dense representation.
This interface overloads the eigh interface from stdlib_linalg
to compute the eigenvalues and eigenvectors of the Poisson2D
matrix .
call eigh(A, lambda, vectors)
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.
| Type | Intent | Optional | 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(:,:) |
This interface overloads the eigvalsh interface from stdlib_linalg
to compute the eigenvalues of the Poisson2D matrix .
lambda = eigvalsh(A)
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Input matrix. |
Eigenvalues.
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.
y = matmul(A, x)
Compute the matrix-vector product for a Poisson2D matrix .
Both x and y are rank-1 arrays with the same kind as A.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(in), | target | :: | x(:) |
Input vector. |
Output vector.
Compute the matrix-matrix product for a Poisson2D matrix .
and are rank-2 arrays of appropriate size with the same kind as .
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(in), | target, contiguous | :: | x(:,:) |
Input vectors. |
Output vectors.
Utility function to return the shape a Poisson2D matrix .
Utility function to get the shape of the Poisson2D matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Input matrix. |
Shape of the matrix.
Utility function to return the size of a Poisson2D matrix
along a given dimension.
Utility function to return the size of a Poisson2D matrix along a given dimension.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Input matrix. |
||
| integer(kind=ilp), | intent(in), | optional | :: | dim |
Queried dimension. |
Corresponding size.
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.
x = solve(A, b)
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.
Solve the linear system using a fast Poisson solver.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Coefficient matrix. |
||
| real(kind=dp), | intent(in) | :: | b(:,:) |
Right-hand side vectors. |
Solution vectors.
Solve the linear system using a fast Poisson solver.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Poisson2D), | intent(in) | :: | A |
Coefficient matrix. |
||
| real(kind=dp), | intent(in) | :: | b(:) |
Right-hand side vector. |
Solution vector.
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 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.
| private pure, module function initialize (nx, ny, Lx, Ly) | Utility function to construct a |