10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-06-28 16:12:40 +02:00

Merge pull request #218 from Ydrnan/qp2_add

2 by 2 diag
This commit is contained in:
Anthony Scemama 2022-11-03 15:27:06 +01:00 committed by GitHub
commit 9ed77a0f9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -411,3 +411,28 @@ subroutine lowercase(txt,n)
enddo
end
subroutine v2_over_x(v,x,res)
!BEGIN_DOC
! Two by two diagonalization to avoid the divergence in v^2/x when x goes to 0
!END_DOC
implicit none
double precision, intent(in) :: v, x
double precision, intent(out) :: res
double precision :: delta_E, tmp, val
res = 0d0
delta_E = x
if (v == 0.d0) return
val = 2d0 * v
tmp = dsqrt(delta_E * delta_E + val * val)
if (delta_E < 0.d0) then
tmp = -tmp
endif
res = 0.5d0 * (tmp - delta_E)
end