Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major refactoring of the codebase. #92

Merged
merged 33 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
eee8024
successful exit only written to debug log
Simkern Jun 10, 2024
2972834
added module name parameter
Simkern Jun 10, 2024
e398ec0
add module name parameter
Simkern Jun 10, 2024
390e17f
Revert "successful exit only written to debug log"
Simkern Jun 10, 2024
81ad097
Revert "add module name parameter"
Simkern Jun 10, 2024
37083e7
success logged only in debug mode
Simkern Jun 10, 2024
c319b06
add module name as private variable for logging
Simkern Jun 10, 2024
7cc3fcf
set inout on linop argument for k_exptA
Simkern Jun 10, 2024
451fe80
added `innerprod_vector`. Changed the interface for consistency. BREA…
Simkern Jun 11, 2024
ba15765
Added orthonormalisation routines for vectors and bases sp/dp/csp/cdp…
Simkern Jun 11, 2024
133f076
Merge branch 'logging' into add_tools_LightROM
Simkern Jun 12, 2024
d43a894
Improved error handling for orthonormalization
Simkern Jun 12, 2024
758cf1e
moved one/zero defs to Constants
Simkern Jun 12, 2024
158b7ab
included EVP tests again
Simkern Jun 12, 2024
687bc6e
Corrected miscellaneous error message and added eighs
Simkern Jun 12, 2024
bcc11a2
fixed typos and added one/zero
Simkern Jun 12, 2024
b5a4685
fixed typo in error string
Simkern Jun 12, 2024
805f13d
typo
Simkern Jun 12, 2024
91ec3fe
added zero/one, suggestion for eigvec tests
Simkern Jun 12, 2024
489323f
added zero/one
Simkern Jun 12, 2024
2842b95
added one/zero (apart from TestVectors). Uniformization of fypp.
Simkern Jun 12, 2024
9d1b3f2
Added assert variation for vectors
Simkern Jun 12, 2024
ef52462
Added error handling for orthogonalization routine
Simkern Jun 12, 2024
f160a59
Refactoring of orthogonalization routines & deployment in QR, Arnoldi…
Simkern Jun 12, 2024
3cc5236
Cleanup
Simkern Jun 12, 2024
e0227a8
deployed new orthogonalization routines
Simkern Jun 12, 2024
8a699bd
fixed typo
Simkern Jun 12, 2024
707e240
Homogenized code
Simkern Jun 12, 2024
f71ebc2
Streamlined Tests to reduce the number of solves.
Simkern Jun 12, 2024
b93e9a0
Added basis orthonormality test for QR
Simkern Jun 12, 2024
18ad185
Added eigenvector checks for eigenvalue solvers and svd, including or…
Simkern Jun 12, 2024
f159b94
Logger.f90: added logging for orthonormality check within orthonormal…
Simkern Jun 13, 2024
549d4d5
Basekrylov.f90:
Simkern Jun 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion example/ginzburg_landau/Ginzburg_Landau.f90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Ginzburg_Landau
use stdlib_optval, only : optval
implicit none

private
character*128, parameter, private :: this_module = 'Ginzburg_Landau'

public :: nx
public :: initialize_parameters

Expand Down
4 changes: 3 additions & 1 deletion example/ginzburg_landau/main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ program demo
use Ginzburg_Landau
implicit none

character*128, parameter :: this_module = 'Example Ginzburg_Landau'

!------------------------------------------------
!----- LINEAR OPERATOR INVESTIGATED -----
!------------------------------------------------
Expand Down Expand Up @@ -56,7 +58,7 @@ program demo

!> Call to LightKrylov.
call eigs(A, X, lambda, residuals, info)
call check_info(info, 'eigs', module='example Ginzburg-Landau', procedure='main')
call check_info(info, 'eigs', module=this_module, procedure='main')

!> Transform eigenspectrum from unit-disk to standard complex plane.
lambda = log(lambda) / tau
Expand Down
3 changes: 2 additions & 1 deletion src/AbstractLinops.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module lightkrylov_AbstractLinops
use lightkrylov_utils
use lightkrylov_AbstractVectors
implicit none
private

character*128, parameter, private :: this_module = 'Lightkrylov_AbstractLinops'

type, abstract, public :: abstract_linop
contains
Expand Down
33 changes: 17 additions & 16 deletions src/AbstractLinops.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module lightkrylov_AbstractLinops
use lightkrylov_utils
use lightkrylov_AbstractVectors
implicit none
private

character*128, parameter, private :: this_module = 'Lightkrylov_AbstractLinops'

type, abstract, public :: abstract_linop
contains
Expand All @@ -18,46 +19,46 @@ module lightkrylov_AbstractLinops



#:for k1, t1 in RC_KINDS_TYPES
#:for kind, type in RC_KINDS_TYPES
!------------------------------------------------------------------------------
!----- Definition of an abstract ${t1}$ operator with kind=${k1}$ -----
!----- Definition of an abstract ${type}$ operator with kind=${kind}$ -----
!------------------------------------------------------------------------------
type, abstract, extends(abstract_linop), public :: abstract_linop_${t1[0]}$${k1}$
type, abstract, extends(abstract_linop), public :: abstract_linop_${type[0]}$${kind}$
!! Base type to define an abstract linear operator. All other types defined in
!! `LightKrylov` derive from this fundamental one.
contains
private
procedure(abstract_matvec_${t1[0]}$${k1}$), pass(self), deferred, public :: matvec
procedure(abstract_matvec_${type[0]}$${kind}$), pass(self), deferred, public :: matvec
!! Procedure to compute the matrix-vector product \( \mathbf{y} = \mathbf{Ax} \).
procedure(abstract_matvec_${t1[0]}$${k1}$), pass(self), deferred, public :: rmatvec
procedure(abstract_matvec_${type[0]}$${kind}$), pass(self), deferred, public :: rmatvec
!! Procedure to compute the reversed matrix-vector product \( \mathbf{y} = \mathbf{A}^H \mathbf{x} \).
end type

abstract interface
subroutine abstract_matvec_${t1[0]}$${k1}$(self, vec_in, vec_out)
subroutine abstract_matvec_${type[0]}$${kind}$(self, vec_in, vec_out)
!! Interface for the matrix-vector product.
use lightkrylov_AbstractVectors
import abstract_linop_${t1[0]}$${k1}$
class(abstract_linop_${t1[0]}$${k1}$) , intent(in) :: self
import abstract_linop_${type[0]}$${kind}$
class(abstract_linop_${type[0]}$${kind}$) , intent(in) :: self
!! Linear operator \(\mathbf{A}\).
class(abstract_vector_${t1[0]}$${k1}$), intent(in) :: vec_in
class(abstract_vector_${type[0]}$${kind}$), intent(in) :: vec_in
!! Vector to be multiplied by \(\mathbf{A}\).
class(abstract_vector_${t1[0]}$${k1}$), intent(out) :: vec_out
class(abstract_vector_${type[0]}$${kind}$), intent(out) :: vec_out
!! Result of the matrix-vector product.
end subroutine abstract_matvec_${t1[0]}$${k1}$
end subroutine abstract_matvec_${type[0]}$${kind}$
end interface

type, extends(abstract_linop_${t1[0]}$${k1}$), public :: adjoint_linop_${t1[0]}$${k1}$
type, extends(abstract_linop_${type[0]}$${kind}$), public :: adjoint_linop_${type[0]}$${kind}$
!! Utility type to define an adjoint linear operator. The definition of `matvec` and `rmatvec`
!! are directly inherited from those used to define `A`. Note that this utility does not
!! compute the adjoint for you. It simply provides a utility to define a new operator
!! with `matvec` and `rmatvec` being switched.
class(abstract_linop_${t1[0]}$${k1}$), allocatable :: A
class(abstract_linop_${type[0]}$${kind}$), allocatable :: A
!! Linear operator whose adjoint needs to be defined.
contains
private
procedure, pass(self), public :: matvec => adjoint_matvec_${t1[0]}$${k1}$
procedure, pass(self), public :: rmatvec => adjoint_rmatvec_${t1[0]}$${k1}$
procedure, pass(self), public :: matvec => adjoint_matvec_${type[0]}$${kind}$
procedure, pass(self), public :: rmatvec => adjoint_rmatvec_${type[0]}$${kind}$
end type


Expand Down
87 changes: 84 additions & 3 deletions src/AbstractVectors.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ module lightkrylov_AbstractVectors
use lightkrylov_constants
use lightkrylov_utils
implicit none
private

public :: innerprod_matrix
character*128, parameter, private :: this_module = 'Lightkrylov_AbstractVectors'

public :: innerprod
public :: linear_combination
public :: axpby_basis
public :: zero_basis
public :: copy_basis

interface innerprod_matrix
interface innerprod
module procedure innerprod_vector_rsp
module procedure innerprod_matrix_rsp
module procedure innerprod_vector_rdp
module procedure innerprod_matrix_rdp
module procedure innerprod_vector_csp
module procedure innerprod_matrix_csp
module procedure innerprod_vector_cdp
module procedure innerprod_matrix_cdp
end interface

Expand Down Expand Up @@ -574,6 +579,25 @@ subroutine linear_combination_matrix_rsp(Y, X, B)
return
end subroutine linear_combination_matrix_rsp

subroutine innerprod_vector_rsp(v, X, y)
!! Computes the inner product vector \( \mathbf{v} = \mathbf{X}^H \mathbf{v} \) between
!! a basis `X` of `abstract_vector` and `v`, a single `abstract_vector`.
class(abstract_vector_rsp), intent(in) :: X(:), y
!! Bases of `abstract_vector` whose inner products need to be computed.
real(sp), intent(out) :: v(size(X))
!! Resulting inner-product vector.

! Local variables.
integer :: i

v = 0.0_sp
do i = 1, size(X)
v(i) = X(i)%dot(y)
enddo

return
end subroutine innerprod_vector_rsp

subroutine innerprod_matrix_rsp(M, X, Y)
!! Computes the inner product matrix \( \mathbf{M} = \mathbf{X}^H \mathbf{Y} \) between
!! two bases of `abstract_vector`.
Expand Down Expand Up @@ -718,6 +742,25 @@ subroutine linear_combination_matrix_rdp(Y, X, B)
return
end subroutine linear_combination_matrix_rdp

subroutine innerprod_vector_rdp(v, X, y)
!! Computes the inner product vector \( \mathbf{v} = \mathbf{X}^H \mathbf{v} \) between
!! a basis `X` of `abstract_vector` and `v`, a single `abstract_vector`.
class(abstract_vector_rdp), intent(in) :: X(:), y
!! Bases of `abstract_vector` whose inner products need to be computed.
real(dp), intent(out) :: v(size(X))
!! Resulting inner-product vector.

! Local variables.
integer :: i

v = 0.0_dp
do i = 1, size(X)
v(i) = X(i)%dot(y)
enddo

return
end subroutine innerprod_vector_rdp

subroutine innerprod_matrix_rdp(M, X, Y)
!! Computes the inner product matrix \( \mathbf{M} = \mathbf{X}^H \mathbf{Y} \) between
!! two bases of `abstract_vector`.
Expand Down Expand Up @@ -862,6 +905,25 @@ subroutine linear_combination_matrix_csp(Y, X, B)
return
end subroutine linear_combination_matrix_csp

subroutine innerprod_vector_csp(v, X, y)
!! Computes the inner product vector \( \mathbf{v} = \mathbf{X}^H \mathbf{v} \) between
!! a basis `X` of `abstract_vector` and `v`, a single `abstract_vector`.
class(abstract_vector_csp), intent(in) :: X(:), y
!! Bases of `abstract_vector` whose inner products need to be computed.
complex(sp), intent(out) :: v(size(X))
!! Resulting inner-product vector.

! Local variables.
integer :: i

v = 0.0_sp
do i = 1, size(X)
v(i) = X(i)%dot(y)
enddo

return
end subroutine innerprod_vector_csp

subroutine innerprod_matrix_csp(M, X, Y)
!! Computes the inner product matrix \( \mathbf{M} = \mathbf{X}^H \mathbf{Y} \) between
!! two bases of `abstract_vector`.
Expand Down Expand Up @@ -1006,6 +1068,25 @@ subroutine linear_combination_matrix_cdp(Y, X, B)
return
end subroutine linear_combination_matrix_cdp

subroutine innerprod_vector_cdp(v, X, y)
!! Computes the inner product vector \( \mathbf{v} = \mathbf{X}^H \mathbf{v} \) between
!! a basis `X` of `abstract_vector` and `v`, a single `abstract_vector`.
class(abstract_vector_cdp), intent(in) :: X(:), y
!! Bases of `abstract_vector` whose inner products need to be computed.
complex(dp), intent(out) :: v(size(X))
!! Resulting inner-product vector.

! Local variables.
integer :: i

v = 0.0_dp
do i = 1, size(X)
v(i) = X(i)%dot(y)
enddo

return
end subroutine innerprod_vector_cdp

subroutine innerprod_matrix_cdp(M, X, Y)
!! Computes the inner product matrix \( \mathbf{M} = \mathbf{X}^H \mathbf{Y} \) between
!! two bases of `abstract_vector`.
Expand Down
Loading
Loading