V3FIT
erf.f
1  FUNCTION erf(x)
2  USE stel_kinds, ONLY: rprec
3 !-------------------------------------------------------------------------------
4 !ERF evaluates the error function erf(x)
5 !References:
6 ! M.Abramowitz, L.A.Stegun, Handbook of Math. Functions, p. 299
7 ! W.A.Houlberg 7/2003
8 !Comments:
9 ! The error function can consume a lot of time deep in the multiple species
10 ! loop so a very efficient calculation is called for
11 ! Time consumption is much more critical than accuracy as suggested by T.Amano
12 ! A three term expansion from Abramowitz is not sufficiently accurate because
13 ! it generates viscosities with singularities in the vicinity of the BP-PS
14 ! transition for ions
15 !-------------------------------------------------------------------------------
16 
17 !Declaration of input variables
18  REAL(rprec), INTENT(IN) :: x !argument of error function [-]
19 
20 !Declaration of output variables
21  REAL(rprec) :: ERF !value of error function [-]
22 
23 !Declaration of local variables
24  REAL(rprec) :: t
25 
26  REAL(rprec), PARAMETER :: one=1, p=0.3275911_rprec,
27  1 a1=0.254829592_rprec,
28  2 a2=-0.284496736_rprec,
29  3 a3=1.421413741_rprec,
30  4 a4=-1.453152027_rprec,
31  5 a5=1.061405429_rprec
32 !-------------------------------------------------------------------------------
33 !Apply fit
34 !-------------------------------------------------------------------------------
35  t=one/(one + p*x)
36  erf = one - ( a1
37  1 + ( a2
38  2 + ( a3
39  3 + ( a4
40  4 + a5*t)*t)*t)*t)*t*exp(-x**2)
41 
42  END FUNCTION erf