3 use iso_fortran_env
, only: output_unit, error_unit
8 Real (Kind=Kind(0.d0)) :: lambda, center, log_lambda
9 Real (Kind=Kind(0.d0)) :: range
10 Real (Kind=Kind(0.d0)) :: om_st, om_en, dom
11 Real (Kind=Kind(0.d0)) :: precision
13 Real (Kind=Kind(0.d0)),
pointer :: xom(:),dxom(:)
14 Character(len=10) :: type
18 module procedure lookup_log_mesh_r, lookup_log_mesh_c
21 module procedure inter_log_mesh_r, inter_log_mesh_c
28 subroutine make_log_mesh ( Mesh, Lambda, Center, Rng, Type, Nw_1 )
33 Real (Kind=Kind(0.d0)) :: lambda, center, rng
34 Integer,
Optional :: nw_1
36 Character(len=10) :: type
38 Real (Kind=Kind(0.d0)) :: dom, om_st, om_en
42 If (str_to_upper(type) ==
"LOG" )
Then 49 if (
Present(nw_1) )
then 52 nw = nint(10.d0*log(10.d0)/log(lambda))
56 mesh%Log_Lambda = log(lambda)
57 Allocate ( mesh%Xom(2*nw + 3), mesh%DXom(2*nw+3) )
59 mesh%xom (n+1 ) = center - rng * (lambda**(
61 mesh%xom (nw+2 ) = center
63 mesh%xom(nw+3 +(nw-n) ) = center + rng * (lambda**(-n
65 mesh%Precision = mesh%Lambda**(-mesh%Nw)
66 elseif (str_to_upper(type) ==
"LIN" )
then 68 If (
Present(nw_1) )
then 73 Allocate ( mesh%Xom(2*nw + 1), mesh%DXom(2*nw+1) )
81 mesh%xom(n) = om_st + dble(n-1)*dom
84 Write(error_unit,*)
'Make_log_mesh: You need to include Nw for the Lin Mesh' 85 Call terminate_on_error(error_generic,__file__,__line__)
88 Write(error_unit,*)
'Make_log_mesh: Mesh has no type!!' 89 Call terminate_on_error(error_generic,__file__,__line__)
92 mesh%DXom(n) = mesh%xom (n+1) - mesh%xom (n )
95 end subroutine make_log_mesh
97 subroutine clear_log_mesh ( Mesh )
102 deallocate ( mesh%Xom, mesh%DXom )
104 end subroutine clear_log_mesh
106 Integer Function m_find(X,Mesh)
111 Real (Kind=Kind(0.d0)) :: x
114 if ( str_to_upper(mesh%Type) ==
"LOG" )
then 115 if ( x > (mesh%OM_en) .or. x < (mesh%Om_st) )
then 118 if ( x < mesh%Xom(mesh%Nw+1) )
then 119 m = 2 - int( log( (mesh%Center - x)/mesh%Range ) / mesh%Log_Lambda
121 elseif ( x > mesh%Xom(mesh%Nw+3) )
then 122 m = 2*mesh%Nw + 3 + int( log( (x- mesh%Center) /mesh%Range
124 elseif ( x > mesh%Center )
then 132 m_find = int((x - mesh%Om_st)/mesh%dom) + 2
133 if (m_find > mesh%Nom) m_find=mesh%Nom
134 if (m_find < 2 ) m_find=2
148 Real(Kind=Kind(0.d0)) Function lookup_log_mesh_r(f, x,Mesh,m_1)
153 Real (Kind=Kind(0.d0)),
dimension(:) :: f
154 Real (Kind=Kind(0.d0)) :: x
155 Integer ,
Optional :: m_1
158 Real (Kind=Kind(0.d0)) :: x1,x2,y1,y2,a,b
162 lookup_log_mesh_r = 0.d0
169 b = (x1*y2 - x2*y1)/(x1-x2)
170 lookup_log_mesh_r = a*x + b
173 If (
Present(m_1) ) m_1 = m
175 end Function lookup_log_mesh_r
210 Complex (Kind=Kind(0.d0)) Function lookup_log_mesh_c(f, x,Mesh,m_1)
215 Complex (Kind=Kind(0.d0)),
dimension(:) :: f
216 Real (Kind=Kind(0.d0)) :: x
217 Integer ,
Optional :: m_1
221 Complex (Kind=Kind(0.d0)) :: z1,z2, z
222 Real (Kind=Kind(0.d0)) :: x1,x2,t
226 lookup_log_mesh_c = cmplx(0.d0, 0.d0, kind(0.d0))
234 lookup_log_mesh_c = z
237 If (
Present(m_1) ) m_1 = m
239 end Function lookup_log_mesh_c
243 Real (Kind=Kind(0.d0)) Function inter_log_mesh_r(f,Mesh)
248 Real (Kind=Kind(0.d0)),
dimension(:) :: f
249 Real (Kind=Kind(0.d0)) :: x
254 x = x + mesh%DXom(n) * (f(n+1) + f(n) )
256 inter_log_mesh_r = x / 2.d0
258 end Function inter_log_mesh_r
261 Complex (Kind=Kind(0.d0)) Function inter_log_mesh_c(f,Mesh)
266 Complex (Kind=Kind(0.d0)),
dimension(:) :: f
267 Complex (Kind=Kind(0.d0)) :: z
270 z = cmplx(0.d0, 0.d0, kind(0.d0))
272 z = z + mesh%DXom(n) * ( f(n+1) + f(n) )
274 inter_log_mesh_c = z /2.d0
276 end Function inter_log_mesh_c
280 subroutine print_log_mesh(Mesh)
288 If (str_to_upper(mesh%Type) ==
"LOG" )
Then 289 Open (unit=10,file=
"Log_Mesh", status=
"unknown" )
290 Write(10,*)
'# Log Mesh : ' 291 Write(10,*)
'# Lambda : ', mesh%Lambda
292 Write(10,*)
'# Range : ', mesh%Range
293 Write(10,*)
'# Center : ', mesh%Center
294 Write(10,*)
'# Nom : ', mesh%Nom
295 Write(10,*)
'# Precision : ', mesh%Lambda**(-mesh%Nw)
297 write(10,
"(F16.8)") mesh%xom(n)
302 If (str_to_upper(mesh%Type) ==
"LIN" )
Then 303 Open (unit=10,file=
"Lin_Mesh", status=
"unknown" )
304 Write(10,*)
'# Lin Mesh : ' 305 Write(10,*)
'# Range : ', mesh%Range
306 Write(10,*)
'# Center : ', mesh%Center
307 Write(10,*)
'# Nom : ', mesh%Nom
308 Write(10,*)
'# Dom : ', mesh%dom
310 write(10,
"(F16.8)") mesh%xom(n)
317 end subroutine print_log_mesh