File: spefun.f90

package info (click to toggle)
code-saturne 4.3.3%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 77,992 kB
  • sloc: ansic: 281,257; f90: 122,305; python: 56,490; makefile: 3,915; xml: 3,285; cpp: 3,183; sh: 1,139; lex: 176; yacc: 101; sed: 16
file content (200 lines) | stat: -rw-r--r-- 5,857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
!-------------------------------------------------------------------------------

! This file is part of Code_Saturne, a general-purpose CFD tool.
!
! Copyright (C) 1998-2016 EDF S.A.
!
! 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 2 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, write to the Free Software Foundation, Inc., 51 Franklin
! Street, Fifth Floor, Boston, MA 02110-1301, USA.

!-------------------------------------------------------------------------------

!> \file spefun.f90
!> \brief Atmospheric module - Module for specific math functions

module spefun
!> \defgroup at_spefun
!=============================================================================

use entsor

implicit none

!=============================================================================

contains

  !=============================================================================

  !> \brief  Gamma function
  function tgamma(x)

    double precision, intent(in) :: x
    double precision tgamma

    call csgamma(x, tgamma)

  end function tgamma

  !=============================================================================

  !> \brief Erf function
  function ferf(x)

    double precision, intent(in) :: x
    double precision ferf

    call cserf(x, ferf)

  end function ferf

  !=============================================================================

  !> \brief Hypergeometric function
  !> (see http://mathworld.wolfram.com/hypergeometricfunction.html
  !>   for definition)
  function hypgeo (a, b, c, x)

    double precision, intent(in) :: a, b, c, x
    double precision hypgeo

    ! Local variables

    double precision pp, y1, y2, hyp1, hyp2
    double precision gammaa, gammab, gammac
    double precision gammabma, gammaamb, gammacma, gammacmb
    parameter        (pp=0.1)

    ! Initialization

    gammaa   = tgamma(a)
    gammab   = tgamma(b)
    gammac   = tgamma(c)
    gammabma = tgamma(b-a)
    gammacma = tgamma(c-a)
    gammaamb = tgamma(a-b)
    gammacmb = tgamma(c-b)

    ! Compute hypergeometric function by convergent series for |x|<1

    if (x.ge.-1.+pp) then
      hypgeo = hypser(a, b, c, x)

    else if (x.le.-1-pp) then
      y1     = hypser( a, a+1.-c, a+1.-b, 1.d0/x )
      y2     = hypser( b, b+1.-c, b+1.-a, 1.d0/x )
      hypgeo = (gammac*gammabma*y1*(-1.d0/x)**a)/(gammab*gammacma)              &
             + (gammac*gammaamb*y2*(-1.d0/x)**b)/(gammaa*gammacmb)
    else
      y1     = hypser(a, a+1.-c, a+1.-b, 1.d0/(-1.-pp))
      y2     = hypser(b, b+1.-c, b+1.-a, 1.d0/(-1.-pp))
      hyp1   = (gammac*gammabma*y1*(-1.d0/(-1.-pp))**a)/(gammab*gammacma)       &
             + (gammac*gammaamb*y2*(-1.d0/(-1.-pp))**b)/(gammaa*gammacmb)
      hyp2   = hypser(a, b, c, -1.+pp)
      hypgeo = hyp1 + (x - (-1.-pp))*(hyp2 - hyp1)/(2.d0*pp)

    endif

  end function hypgeo

  !=============================================================================

  !> \brief  Calcul de la fonction hypergeometrique pour |x| < 1 par une serie
  !>     (cf. pour la definition de cette fonction, voir par exemple :
  !>     http://mathworld.wolfram.com/hypergeometricfunction.html )

  function hypser (a, b, c, x)

    use entsor

    implicit none

    double precision, intent(in) :: a, b, c, x
    double precision hypser

    !---------------------------------------------------------------------------

    ! Local variables

    integer          nn
    double precision fac,aa,bb,cc,temp
    integer,parameter :: maxiter=10000
    double precision,parameter :: error=1.d-08

    !---------------------------------------------------------------------------

    if (abs(x).ge.1.) then
      write (nfecra,1120) x
      call csexit(1)
    endif

    fac = 1
    temp = fac
    aa  = a
    bb  = b
    cc  = c

    do nn = 1, maxiter, 1
      fac    = ((aa*bb)/cc)*fac
      fac    = fac*x/nn
      hypser = fac + temp
      if (abs(hypser - temp).le. error) then
        return
      endif
      temp   = hypser
      aa     = aa +1
      bb     = bb +1
      cc     = cc +1
    enddo

    ! Formats
    !--------

#if defined(_CS_LANG_FR)

1120 format (                                                     &
'@                                                            ',/,&
'@ @@ ERREUR : dans la fonction hypser                        ',/,&
'@    ======                                                  ',/,&
'@  Le parametre x doit verifier |x| < 1,  x = ',E12.5         ,/,&
'@                                                            '  )

#else

 1120 format (                                                    &
'@                                                            ',/,&
'@ @@ ERROR: in hypser function                               ',/,&
'@    =====                                                   ',/,&
'@  The x parameter should verify |x| < 1,  x = ', E12.5       ,/,&
'@                                                            '  )

#endif

  end function hypser

  !=============================================================================

  !> \brief Beta function: beta(x,y) = gamma(x)*gamma(y)/gamma(x+y)
  function beta(x, y)

    double precision, intent(in) :: x, y
    double precision beta

    beta = tgamma(x)*tgamma(y)/tgamma(x + y)

  end function beta

  !=============================================================================

end module spefun