mod_matrix_structure Module

Module that contains the datastructure for a linked-list matrix representation.



Derived Types

type, public ::  matrix_t

General matrix type, represents the linked list implementation

Components

Type Visibility Attributes Name Initial
integer, public :: matrix_dim

dimension of the matrix, number of rows

type(row_t), public, allocatable :: rows(:)

array containing the various rows

character(len=:), private, allocatable :: label

label to distinguish between different matrix instances

Type-Bound Procedures

procedure, public :: add_element
procedure, public :: set_label
procedure, public :: get_complex_element
procedure, public :: get_total_nb_elements
procedure, public :: get_label
procedure, public :: get_nb_diagonals
procedure, public :: copy
procedure, public :: delete_matrix

Functions

public pure function new_matrix(nb_rows, label) result(matrix)

Constructor for a new matrix matrix with a given number of rows. Allocates and initialises the matrix datatype.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nb_rows

number of rows in the matrix

character(len=*), intent(in), optional :: label

label of the matrix

Return Value type(matrix_t)

matrix datatype with rows/columns in a linked list

private function is_valid_element(element) result(is_valid)

Checks if a given element is valid in order to add it to the matrix. Returns .true. if the element is of type real or complex, .false. otherwise.

Arguments

Type IntentOptional Attributes Name
class(*), intent(in) :: element

Matrix element that is to be added

Return Value logical

private function is_valid_index(matrix, index) result(is_valid)

Checks if a given index is valid for the current matrix datastructure. Returns .true. if the index (either row or column) is larger than 0 and smaller than the dimension of the matrix. Returns .false. otherwise.

Arguments

Type IntentOptional Attributes Name
type(matrix_t), intent(in) :: matrix

matrix datastructure object

integer, intent(in) :: index

index to check

Return Value logical

private function get_complex_element(this, row, column) result(element)

Returns the complex element associated with the linked-list node at position (row, column) in the matrix datastructure. Non-existing nodes correspond to zero values, so when a node at (row, column) is not found this function returns (complex) zero.

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(in) :: this

type instance

integer, intent(in) :: row

row position of the needed element

integer, intent(in) :: column

column position of the needed element

Return Value complex(kind=dp)

the element at position (row, column) in the matrix

private pure function get_total_nb_elements(this) result(total_nb_elements)

Returns the total number of elements (nodes) across the various rows.

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(in) :: this

type instance

Return Value integer

total number of (non-zero) elements in this matrix

private pure function get_label(this) result(label)

Returns the current label.

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(in) :: this

type instance

Return Value character(len=len(this%label))

current matrix label

private function copy(matrix_in) result(matrix_out)

Dedicated function to copy a matrix structure into a new matrix structure. The datastructure contains pointers, such that simply setting matrix1 = matrix2 may result in pointer target losses (and wrong results).

Read more…

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(in) :: matrix_in

the original matrix

Return Value type(matrix_t)

copy from the original matrix


Subroutines

private subroutine add_element(this, row, column, element)

Adds a given element at a certain (row, column) position to the matrix datastructure. Elements that are zero are not added, sanity checks are done on the row and column indices.

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(inout) :: this

type instance

integer, intent(in) :: row

row position of the element

integer, intent(in) :: column

column position of the element

class(*), intent(in) :: element

polymorphic variable to add to the matrix

private pure subroutine set_label(this, label)

Sets the label of the current matrix.

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(inout) :: this

type instance

character(len=*), intent(in) :: label

label to set

private subroutine get_nb_diagonals(this, ku, kl)

Subroutine to get the number of super- and sub-diagonals in the matrix.

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(in) :: this

type instance

integer, intent(out) :: ku

number of superdiagonals

integer, intent(out) :: kl

number of subdiagonals

private pure subroutine delete_matrix(this)

Deallocates the matrix datastructure, nullifies all corresponding pointers and deallocates the various nodes in the rows.

Arguments

Type IntentOptional Attributes Name
class(matrix_t), intent(inout) :: this