PLUME-MoM-TSM  1.0
VolcanicPlumeModel
moments.f90
Go to the documentation of this file.
1 !********************************************************************************
3 !
9 !********************************************************************************
10 
12 
13  USE variables, ONLY : wp
14 
15  IMPLICIT NONE
16 
18  INTEGER :: n_nodes
19 
21  INTEGER, PARAMETER :: max_nmom = 20
22 
24  INTEGER :: n_mom
25 
26  INTEGER :: n_sections
27 
28 CONTAINS
29 
30 
31  !******************************************************************************
33  !
42  !******************************************************************************
43 
44  REAL(wp) FUNCTION beta_function(z,w)
45 
46  IMPLICIT NONE
47 
48  REAL(wp), INTENT(IN):: w,z
49 
50  REAL(wp):: gamln_z , gamln_w , gamln_zw
51 
52  gamln_z = gammln(z)
53  gamln_w = gammln(w)
54  gamln_zw = gammln(z+w)
55 
56  beta_function = exp( gamln_z + gamln_w - gamln_zw )
57 
58  RETURN
59 
60  END FUNCTION beta_function
61 
62  !******************************************************************************
64  !
72  !******************************************************************************
73 
74  FUNCTION gammln(xx)
75 
76  IMPLICIT NONE
77 
78  REAL(wp) :: gammln,xx
79 
80  INTEGER :: j
81 
82  REAL(wp) :: ser , tmp , x , y , cof(14)
83 
84  cof(1) = 57.1562356658629235
85  cof(2) = -59.5979603554754912
86  cof(3) = 14.1360979747417471
87  cof(4) = -0.491913816097620199
88  cof(5) = 0.339946499848118887e-4_wp
89  cof(6) = 0.465236289270485756e-4_wp
90  cof(7) = -0.983744753048795646e-4_wp
91  cof(8) = 0.158088703224912494e-3_wp
92  cof(9) = -0.210264441724104883e-3_wp
93  cof(10) = 0.217439618115212643e-3_wp
94  cof(11) = -0.164318106536763890e-3_wp
95  cof(12) = 0.844182239838527433e-4_wp
96  cof(13) = -0.261908384015814087e-4_wp
97  cof(14) = .368991826595316234e-5_wp
98 
99  IF (xx .LE. 0) THEN
100 
101  WRITE(*,*) "bad arg in gammln"
102  gammln = 0.0_wp
103 
104  ELSE
105 
106  x = xx
107  y = x
108 
109  tmp = x + 5.2421875_wp
110  tmp = ( x + 0.5_wp ) * log(tmp) - tmp
111 
112  ser = 0.999999999999997092
113 
114  DO j=1,14
115 
116  y = y+1.0_wp
117  ser = ser + cof(j)/y
118 
119  END DO
120 
121  gammln = tmp + log(2.5066282746310005*ser/x)
122 
123  END IF
124 
125  RETURN
126 
127  END FUNCTION gammln
128 
129 ! lgwt.m
130 !
131 ! This script is for computing definite integrals using Legendre-Gauss
132 ! Quadrature. Computes the Legendre-Gauss nodes and weights on an interval
133 ! [a,b] with truncation order N
134 !
135 
136  subroutine gaulegf(x1, x2, x, w, n)
137 
138  implicit none
139  integer, intent(in) :: n
140  REAL(wp), intent(in) :: x1, x2
141  REAL(wp), dimension(n), intent(out) :: x, w
142  integer :: i, j, m
143  REAL(wp) :: p1, p2, p3, pp, xl, xm, z, z1
144  REAL(wp), parameter :: eps=3.0e-14_wp
145 
146  m = (n+1)/2
147  xm = 0.5_wp*(x2+x1)
148  xl = 0.5_wp*(x2-x1)
149  do i=1,m
150  z = cos(3.141592654_wp*(i-0.25_wp)/(n+0.5_wp))
151  z1 = 0.0_wp
152  do while(abs(z-z1) .gt. eps)
153  p1 = 1.0_wp
154  p2 = 0.0_wp
155  do j=1,n
156  p3 = p2
157  p2 = p1
158  p1 = ((2.0_wp*j-1.0_wp)*z*p2-(j-1.0_wp)*p3)/j
159  end do
160  pp = n*(z*p1-p2)/(z*z-1.0_wp)
161  z1 = z
162  z = z1 - p1/pp
163  end do
164  x(i) = xm - xl*z
165  x(n+1-i) = xm + xl*z
166  w(i) = (2.0_wp*xl)/((1.0_wp-z*z)*pp*pp)
167  w(n+1-i) = w(i)
168  end do
169  end subroutine gaulegf
170 
171 !linear_reconstruction Linear reconstruction from the moments mom
172 ! This function computes the coefficients of the linear reconstruction of
173 ! the ndf on the interval [Ml;Mr] from the moments mom. Only the first
174 ! two moments are used. The procedure follows what presented in Nguyen et
175 ! al. 2016, Table E.7
176 
177  SUBROUTINE linear_reconstruction( Ml,Mr,mom, Ma,Mb,alfa,beta,gamma1,gamma2 )
179  IMPLICIT NONE
180 
181  REAL(wp), INTENT(IN) :: Ml
182  REAL(wp), INTENT(IN) :: Mr
183  REAL(wp), INTENT(IN) :: mom(0:1)
184  REAL(wp), INTENT(OUT) :: Ma
185  REAL(wp), INTENT(OUT) :: Mb
186  REAL(wp), INTENT(OUT) :: alfa
187  REAL(wp), INTENT(OUT) :: beta
188  REAL(wp), INTENT(OUT) :: gamma1
189  REAL(wp), INTENT(OUT) :: gamma2
190 
191  REAL(wp) :: M , N , Mmax , Mmin
192 
193  m = mom(1)
194  n = mom(0)
195 
196  mmin = ( mr + 2.0_wp*ml ) / 3.0_wp
197  mmax = ( 2.0_wp*mr + ml ) / 3.0_wp
198 
199 
200  IF ( n*m == 0 ) THEN
201 
202  alfa = 0.0_wp
203  beta = 0.0_wp
204  gamma1 = 0.0_wp
205  gamma2 = 0.0_wp
206 
207  ELSEIF ( m/n .LT. mmin) THEN
208 
209  alfa = (n*(m - n*mr))/((ml - mr)*(m - n*ml))
210  beta = alfa
211  gamma1 = (n*ml - 2*m + n*mr)/(m - n*ml)
212  gamma2 = 0.0_wp
213 
214  ELSEIF ( m/n .GT. mmax ) THEN
215 
216  alfa = 0.0_wp
217  beta = (n*(m - n*ml))/((ml - mr)*(m - n*mr))
218  gamma1 = 0.0_wp
219  gamma2 = (n*ml - 2*m + n*mr)/(m - n*mr)
220 
221  ELSE
222 
223  alfa = (2.0_wp*(n*ml - 3.0_wp*m + 2.0_wp*n*mr))/(ml - mr)**2
224  beta = -(2.0_wp*(2.0_wp*n*ml - 3.0_wp*m + n*mr))/(ml - mr)**2
225  gamma1 = 0.0_wp
226  gamma2 = 1.0_wp
227 
228  END IF
229 
230  RETURN
231 
232  END SUBROUTINE linear_reconstruction
233 
234 
235 
236 
237 
238 END MODULE moments_module
integer n_mom
Number of moments.
Definition: moments.f90:24
integer, parameter max_nmom
Maximum number of moments.
Definition: moments.f90:21
subroutine linear_reconstruction(Ml, Mr, mom, Ma, Mb, alfa, beta, gamma1, gamma2)
Definition: moments.f90:178
real(wp) function gammln(xx)
Gamma function logarithm.
Definition: moments.f90:75
integer n_sections
Definition: moments.f90:26
integer n_nodes
Number of nodes for the quadrature.
Definition: moments.f90:18
subroutine gaulegf(x1, x2, x, w, n)
Definition: moments.f90:137
Method of Moments module.
Definition: moments.f90:11
integer, parameter wp
working precision
Definition: variables.f90:21
real(wp) function beta_function(z, w)
Beta function.
Definition: moments.f90:45
Global variables.
Definition: variables.f90:10