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

Adding LinearAlgebraUtility #199

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/modules/Utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ TARGET_SOURCES(
${src_path}/EigenUtility.F90
${src_path}/SymUtility.F90
${src_path}/TriagUtility.F90
${src_path}/LinearAlgebraUtility.F90
${src_path}/Utility.F90
)
)
49 changes: 49 additions & 0 deletions src/modules/Utility/src/LinearAlgebraUtility.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
! This program is a part of EASIFEM library
! Copyright (C) 2020-2021 Vikas Sharma, Ph.D
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <https: //www.gnu.org/licenses/>
!

MODULE LinearAlgebraUtility
USE GlobalData
IMPLICIT NONE
PRIVATE

!----------------------------------------------------------------------------
! InvHilbertMatrix@Methods
!----------------------------------------------------------------------------

INTERFACE
MODULE PURE FUNCTION InvHilbertMatrix(n) RESULT(Ans)
INTEGER(I4B), INTENT(IN) :: n
REAL(DFP) :: Ans(n, n)
END FUNCTION InvHilbertMatrix
END INTERFACE

PUBLIC :: InvHilbertMatrix

!----------------------------------------------------------------------------
! HilbertMatrix@Methods
!----------------------------------------------------------------------------

INTERFACE
MODULE PURE FUNCTION HilbertMatrix(n) RESULT(Ans)
INTEGER(I4B), INTENT(IN) :: n
REAL(DFP) :: Ans(n, n)
END FUNCTION HilbertMatrix
END INTERFACE

PUBLIC :: HilbertMatrix

END MODULE LinearAlgebraUtility
1 change: 1 addition & 0 deletions src/modules/Utility/src/Utility.F90
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ MODULE Utility
USE ArangeUtility
USE SymUtility
USE TriagUtility
USE LinearAlgebraUtility

!----------------------------------------------------------------------------
!
Expand Down
1 change: 1 addition & 0 deletions src/submodules/Utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ TARGET_SOURCES(
${src_path}/EigenUtility@Methods.F90
${src_path}/SymUtility@Methods.F90
${src_path}/TriagUtility@Methods.F90
${src_path}/LinearAlgebraUtility@Methods.F90
)
65 changes: 65 additions & 0 deletions src/submodules/Utility/src/LinearAlgebraUtility@Methods.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
! This program is a part of EASIFEM library
! Copyright (C) 2020-2021 Vikas Sharma, Ph.D
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <https: //www.gnu.org/licenses/>
!

SUBMODULE(LinearAlgebraUtility) Methods
IMPLICIT NONE
CONTAINS

!----------------------------------------------------------------------------
! IntHilbertMatrix
!----------------------------------------------------------------------------

MODULE PROCEDURE InvHilbertMatrix
REAL(DFP) :: p
REAL(DFP) :: r
INTEGER(I4B) :: i
INTEGER(I4B) :: j
INTEGER(I4B) :: ip1

p = REAL(n, kind=DFP)

DO i = 1, n
IF (i .NE. 1) p = (REAL(n - i + 1, DFP) * p * REAL(n + i - 1, DFP)) / REAL(i - 1, DFP)**2
r = p * p
ans(i, i) = r / REAL(2 * i - 1, DFP)
IF (i .EQ. n) CYCLE
ip1 = i + 1
DO j = ip1, n
r = (-1) * (REAL(n - j + 1, DFP) * r * (n + j - 1)) / REAL(j - 1, DFP)**2
ans(i, j) = r / REAL(i + j - 1, DFP)
ans(j, i) = ans(i, j)
END DO
END DO
END PROCEDURE InvHilbertMatrix

!----------------------------------------------------------------------------
! HilbertMatrix
!----------------------------------------------------------------------------

MODULE PROCEDURE HilbertMatrix
INTEGER(I4B) :: ii, jj
REAL(DFP) :: avar

DO jj = 1, n
DO ii = 1, n
avar = REAL(ii + jj - 1, KIND=DFP)
ans(ii, jj) = 1.0_DFP / avar
END DO
END DO
END PROCEDURE HilbertMatrix

END SUBMODULE Methods