Skip to content

Commit

Permalink
Include our own ERF
Browse files Browse the repository at this point in the history
  • Loading branch information
william-dawson committed Dec 17, 2024
1 parent 0252acb commit 5d5d264
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Source/Fortran/FermiOperatorModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -625,5 +625,24 @@ SUBROUTINE ComputeCStep(X, A, W, pool, threshold, Out)
CALL DestructMatrix(XA)

END SUBROUTINE ComputeCStep
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> ERF is a Fortran2008 feature, and we just need a crude approximation here
!! so we implement it with the Abramowitz and Stegun approximation
!! (credit ChatGPT).
FUNCTION ERF(x)
REAL(NTREAL) :: x, erf
REAL(NTREAL) :: t, z, tau
REAL(NTREAL), PARAMETER :: a1 = 0.254829592_NTREAL
REAL(NTREAL), PARAMETER :: a2 = -0.284496736_NTREAL
REAL(NTREAL), PARAMETER :: a3 = 1.421413741_NTREAL
REAL(NTREAL), PARAMETER :: a4 = -1.453152027_NTREAL
REAL(NTREAL), PARAMETER :: a5 = 1.061405429_NTREAL
REAL(NTREAL), PARAMETER :: p = 0.3275911_NTREAL

z = ABS(x)
t = 1.0_NTREAL / (1.0_NTREAL + p * z)
tau = t * (a1 + t * (a2 + t * (a3 + t * (a4 + t * a5))))
erf = SIGN(1.0_NTREAL, x) * (1.0_NTREAL - tau * EXP(-z * z))
END FUNCTION ERF
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
END MODULE FermiOperatorModule

0 comments on commit 5d5d264

Please sign in to comment.