Debian Codegraph @

src/kernels.f90

raw
1 !-----------------------------------------------------------------
2 !
3 ! This file is (or was) part of SPLASH, a visualisation tool
4 ! for Smoothed Particle Hydrodynamics written by Daniel Price:
5 !
6 ! http://users.monash.edu.au/~dprice/splash
7 !
8 ! SPLASH comes with ABSOLUTELY NO WARRANTY.
9 ! This is free software; and you are welcome to redistribute
10 ! it under the terms of the GNU General Public License
11 ! (see LICENSE file for details) and the provision that
12 ! this notice remains intact. If you modify this file, please
13 ! note section 2a) of the GPLv2 states that:
14 !
15 ! a) You must cause the modified files to carry prominent notices
16 ! stating that you changed the files and the date of any change.
17 !
18 ! Copyright (C) 2005-2018 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 !-------------------------------------------------------------
24 !
25 ! Module containing kernel functions used for interpolation
26 !
27 !-------------------------------------------------------------
28 module kernels
29 implicit none
30 integer, parameter, public :: nkernels = 6
31 character(len=24), dimension(0:nkernels), parameter, public :: kernelname = &
32 (/'default [cubic] ', &
33 'M4 cubic spline (2h) ', &
34 'M5 quartic (2.5h)', &
35 'M6 quintic spline (3h) ', &
36 'Wendland C2 (2h) ', &
37 'Wendland C4 (2h) ', &
38 'Wendland C6 (2h) '/)
39
40 real, parameter :: pi = 4.*atan(1.)
41 integer, public :: ikernel = 0
42 real, public :: radkernel = 2.
43 real, public :: radkernel2 = 4.
44 real, public :: cnormk1D = 2./3.
45 real, public :: cnormk2D = 10./(7.*pi)
46 real, public :: cnormk3D = 1./pi
47 integer, parameter :: doub_prec = kind(0.d0)
48
49 procedure(k_func), pointer, public :: wfunc
50 procedure(k_func), pointer, public :: dwfunc
51
52 abstract interface
53 pure function k_func(q)
54 real, intent(in) :: q
55 real :: k_func
56 end function k_func
57 end interface
58
59 public :: select_kernel, select_kernel_by_name
60 public :: pint,wallint,soft_func
61
62 private
63
64 contains
65
66 !-----------------------------------------------
67 !
68 ! Kernel selection routine, sets radkernel,
69 ! cnormk values and pointer to kernel function
70 !
71 !--------------------------------------
72 subroutine select_kernel(j)
73 integer, intent(in) :: j
74
75 if (j >= 1 .and. j <= nkernels) then
76 !--print only if NOT using the default kernel
77 print "(a,/)",' Using '//trim(kernelname(j))//' kernel'
78 endif
79
80 select case(j)
81 case(6) ! Wendland 3D C6
82 ikernel = 6
83 radkernel = 2.
84 cnormk1D = 15./16.
85 cnormk2D = 39./(14.*pi)
86 cnormk3D = 1365./(512.*pi)
87 wfunc => w_wendlandc6
88 case(5) ! Wendland 3D C4
89 ikernel = 5
90 radkernel = 2.
91 cnormk1D = 27./32.
92 cnormk2D = 9./(4.*pi)
93 cnormk3D = 495./(256.*pi)
94 wfunc => w_wendlandc4
95 case(4) ! Wendland 3D C2
96 ikernel = 4
97 radkernel = 2.
98 cnormk1D = 0.75
99 cnormk2D = 7./(4.*pi)
100 cnormk3D = 21./(16.*pi)
101 wfunc => w_wendlandc2
102 case(3) ! M6 quintic, 3h
103 ikernel = 3
104 radkernel = 3.0
105 cnormk1D = 1./120.
106 cnormk2D = 7./(478*pi)
107 cnormk3D = 1./(120.*pi)
108 wfunc => w_quintic
109 case(2) ! M5 quartic, 2.5h
110 ikernel = 2
111 radkernel = 2.5
112 cnormk1D = 1./24.
113 cnormk2D = 96./(1199.*pi)
114 cnormk3D = 1./(20.*pi)
115 wfunc => w_quartic
116 case default !-- cubic spline kernel
117 if (j==1) then
118 ikernel = 1 ! deliberately chose cubic spline
119 else
120 ikernel = 0 ! just whatever is the default
121 endif
122 radkernel = 2.0
123 cnormk1D = 2./3.
124 cnormk2D = 10./(7.*pi)
125 cnormk3D = 1./pi
126 wfunc => w_cubic
127 dwfunc => dw_cubic
128 end select
129 radkernel2 = radkernel*radkernel
130
131 end subroutine select_kernel
132
133 !--------------------------------------
134 !
135 ! Kernel selection based on string
136 !
137 !--------------------------------------
138 subroutine select_kernel_by_name(string)
139 use asciiutils, only:lcase
140 character(len=*), intent(in) :: string
141 integer :: i,jkern
142
143 jkern = 0
144 !
145 !--check if string exactly matches a kernel name
146 !
147 do i=1,nkernels
148 if (trim(adjustl(lcase(string)))==trim(adjustl(lcase(kernelname(i))))) then
149 jkern = i
150 endif
151 enddo
152 !
153 !--if no match to a kernel name, look for other possible strings
154 !
155 if (ikernel==0) then
156 select case(trim(adjustl(lcase(string))))
157 case('wendlandc6','wendland c6','6th order wendland','wendland 3d c6','w6','wendland6')
158 jkern = 6
159 case('wendlandc4','wendland c4','4th order wendland','wendland 3d c4','w4','wendland4')
160 jkern = 5
161 case('wendlandc2','wendland c2','2nd order wendland','wendland 3d c2','w2','wendland2')
162 jkern = 4
163 case('quintic','quintic spline','m6','quintic b-spline')
164 jkern = 3
165 case('quartic','quartic spline','m5','quartic b-spline')
166 jkern = 2
167 case('cubic','cubic spline','m4','cubic b-spline')
168 jkern = 1
169 end select
170 endif
171
172 call select_kernel(jkern)
173
174 end subroutine select_kernel_by_name
175
176 !---------------------------------------
177 !
178 ! Functional forms of various kernels
179 !
180 !--------------------------------------
181 pure real function w_cubic(q2)
182 real, intent(in) :: q2
183 real :: q
184
185 if (q2 < 1.0) then
186 q = sqrt(q2)
187 w_cubic = 1.-1.5*q2 + 0.75*q2*q
188 elseif (q2 < 4.0) then
189 q = sqrt(q2)
190 w_cubic = 0.25*(2.-q)**3
191 else
192 w_cubic = 0.
193 endif
194
195 end function w_cubic
196
197 pure real function dw_cubic(q2)
198 real, intent(in) :: q2
199 real :: q
200
201 if (q2 < 1.0) then
202 q = sqrt(q2)
203 dw_cubic = q*(2.25*q - 3.)
204 elseif (q2 < 4.0) then
205 q = sqrt(q2)
206 dw_cubic = -0.75*(2.-q)**2
207 else
208 dw_cubic = 0.
209 endif
210
211 end function dw_cubic
212
213 pure real function w_quartic(q2)
214 real, intent(in) :: q2
215 real :: q
216
217 q = sqrt(q2)
218 if (q < 0.5) then
219 w_quartic = (2.5-q)**4 - 5.*(1.5-q)**4 + 10.*(0.5-q)**4
220 elseif (q < 1.5) then
221 w_quartic = (2.5-q)**4 - 5.*(1.5-q)**4
222 elseif (q < 2.5) then
223 w_quartic = (2.5-q)**4
224 else
225 w_quartic = 0.
226 endif
227
228 end function w_quartic
229
230 pure real function w_quintic(q2)
231 real, intent(in) :: q2
232 real :: q,q4
233
234 if (q2 < 1.0) then
235 q = sqrt(q2)
236 q4 = q2*q2
237 w_quintic = 66.-60.*q2 + 30.*q4 - 10.*q4*q
238 elseif ((q2 >= 1.0).and.(q2 < 4.0)) then
239 q = sqrt(q2)
240 w_quintic = (3.-q)**5 - 6.*(2.-q)**5
241 elseif ((q2 >= 4.0).and.(q2 < 9.0)) then
242 q = sqrt(q2)
243 w_quintic = (3.-q)**5
244 else
245 w_quintic = 0.0
246 endif
247
248 end function w_quintic
249
250 pure real function w_quartic2h(q2)
251 real, intent(in) :: q2
252 real :: q
253
254 q = sqrt(q2)
255 if (q < 0.4) then
256 w_quartic2h = (2.-q)**4 - 5.*(1.2-q)**4 + 10.*(0.4-q)**4
257 elseif (q < 1.2) then
258 w_quartic2h = (2.-q)**4 - 5.*(1.2-q)**4
259 elseif (q < 2.) then
260 w_quartic2h = (2.-q)**4
261 else
262 w_quartic2h = 0.
263 endif
264
265 end function w_quartic2h
266
267 pure real function w_wendlandc2(q2)
268 real, intent(in) :: q2
269 real :: q
270
271 if (q2 < 4.) then
272 q = sqrt(q2)
273 w_wendlandc2 = (1. - 0.5*q)**4*(2.*q + 1.)
274 else
275 w_wendlandc2 = 0.
276 endif
277
278 end function w_wendlandc2
279
280 pure real function w_wendlandc4(q2)
281 real, intent(in) :: q2
282 real :: q
283
284 if (q2 < 4.) then
285 q = sqrt(q2)
286 w_wendlandc4 = (1. - 0.5*q)**6*(35./12.*q2 + 3.*q + 1.)
287 else
288 w_wendlandc4 = 0.
289 endif
290
291 end function w_wendlandc4
292
293 pure real function w_wendlandc6(q2)
294 real, intent(in) :: q2
295 real :: q
296
297 if (q2 < 4.) then
298 q = sqrt(q2)
299 w_wendlandc6 = (1. - 0.5*q)**8*(4.*q2*q + 25./4.*q2 + 4.*q + 1.)
300 else
301 w_wendlandc6 = 0.
302 endif
303
304 end function w_wendlandc6
305
306 !---------------------------------------
307 !
308 ! Integrals of the kernel, used
309 ! when performing exact interpolation
310 ! See Petkova, Laibe & Bonnell (2018)
311 !
312 !---------------------------------------
313 pure real function pint(r0, d1, d2, hi1)
314 real, intent(in) :: r0, d1, d2, hi1
315 real :: ar0,q0,tphi1,tphi2,phi1,phi2
316
317 if (abs(r0) < tiny(0.)) then
318 pint = 0.
319 return
320 elseif (r0 > 0.) then
321 pint = 1.
322 ar0 = r0
323 else
324 pint = -1.
325 ar0 = -r0
326 endif
327 q0 = ar0*hi1
328 tphi1 = abs(d1)/ar0
329 tphi2 = abs(d2)/ar0
330 phi1 = atan(tphi1)
331 phi2 = atan(tphi2)
332
333 if (d1*d2 >= 0.) then
334 pint = pint*(full_2d_mod(phi1,tphi1,q0) + full_2d_mod(phi2,tphi2,q0))
335 else
336 if (abs(d1) < abs(d2)) then
337 pint = pint*(full_2d_mod(phi2,tphi2,q0) - full_2d_mod(phi1,tphi1,q0))
338 else
339 pint = pint*(full_2d_mod(phi1,tphi1,q0) - full_2d_mod(phi2,tphi2,q0))
340 endif
341 endif
342
343 end function pint
344
345 !---------------------------------------
346 !
347 ! Helper functions for kernel integrals
348 ! See Petkova, Laibe & Bonnell (2018)
349 !
350 !---------------------------------------
351 pure real function full_2d_mod(phi,tphi,q0)
352 real, intent(in) :: phi,tphi,q0
353 real :: q, phi1, phi2, tphi1, tphi2, cphi, cphi1, cphi2
354
355 if (q0 <= 1.0) then
356 cphi = cos(phi)
357 q = q0/cphi
358
359 if (q <= 1.0) then
360 full_2d_mod = F1_2d(phi,tphi,cphi,q0)
361 elseif (q <= 2.0) then
362 cphi1 = q0
363 phi1 = acos(q0)
364 tphi1 = tan(phi1) ! tan (acos x) = sqrt(1-x**2)/x
365 full_2d_mod = F2_2d(phi,tphi,cphi,q0) - F2_2d(phi1,tphi1,cphi1,q0) &
366 + F1_2d(phi1,tphi1,cphi1,q0)
367 else
368 cphi1 = q0
369 phi1 = acos(q0)
370 cphi2 = 0.5*q0
371 phi2 = acos(0.5*q0)
372 tphi1 = tan(phi1)
373 tphi2 = tan(phi2)
374 full_2d_mod = F3_2d(phi) - F3_2d(phi2) + F2_2d(phi2,tphi2,cphi2,q0) &
375 - F2_2d(phi1,tphi1,cphi1,q0) &
376 + F1_2d(phi1,tphi1,cphi1,q0)
377 endif
378 elseif (q0 <= 2.0) then
379 cphi = cos(phi)
380 q = q0/cphi
381
382 if (q <= 2.0) then
383 full_2d_mod = F2_2d(phi,tphi,cphi,q0)
384 else
385 cphi2 = 0.5*q0
386 phi2 = acos(0.5*q0)
387 tphi2 = tan(phi2)
388 full_2d_mod = F3_2d(phi) - F3_2d(phi2) + F2_2d(phi2,tphi2,cphi2,q0)
389 endif
390 else ! q0 > 2
391 full_2d_mod = F3_2d(phi)
392 endif
393
394 end function full_2d_mod
395
396 pure real function F1_2d(phi,tphi,cphi,q0)
397 real, intent(in) :: phi,tphi,cphi,q0
398 real :: I2, I4, I5, logs, cphi2, q02, q03
399
400 !tphi = tan(phi)
401 !cphi = cos(phi)
402 cphi2 = cphi*cphi
403
404 q02 = q0*q0
405 q03 = q02*q0
406
407 logs = log(tan(phi/2.+pi/4.))
408
409 I2 = tphi
410 I4 = 1./3. * tphi*(2. + 1./cphi2)
411
412 I5 = 1./16. * (0.5*(11.*sin(phi) + 3.*sin(3.*phi))/cphi2/cphi2 + 6.*logs)
413
414 F1_2d = 5./7.*q02/pi * (I2 - 3./4.*q02 *I4 + 0.3*q03 *I5)
415
416 end function F1_2d
417
418 pure real function F2_2d(phi, tphi, cphi, q0)
419 real, intent(in) :: phi, tphi, cphi, q0
420 real :: I0, I2, I3, I4, I5, logs, cphi2, q02, q03
421
422 ! tphi = tan(phi)
423 ! cphi = cos(phi)
424 cphi2 = cphi*cphi
425
426 q02 = q0*q0
427 q03 = q02*q0
428
429 logs = log(tan(phi/2.+pi/4.))
430
431 I0 = phi
432 I2 = tphi
433 I4 = 1./3. * tphi*(2. + 1./(cphi2))
434
435 I3 = 1./2. * (tphi/cphi + logs)
436 I5 = 1./16. * (0.5*(11.*sin(phi) + 3.*sin(3.*phi))/cphi2/cphi2 + 6.*logs)
437
438 F2_2d = 5./7.*q02/pi * (2.*I2 - 2.*q0 *I3 + 3./4.*q02 *I4 - 1./10.*q03 *I5 &
439 - 1./10./q02 *I0)
440
441 end function F2_2d
442
443 pure real function F3_2d(phi)
444 real, intent(in) :: phi
445 real :: I0
446
447 I0 = phi
448 F3_2d = 0.5/pi *I0
449
450 end function F3_2d
451
452 !------------------------------------------------------------
453 ! 3D functions to evaluate exact overlap of kernel with wall boundaries
454 ! see Petkova, Laibe & Bonnell (2018), J. Comp. Phys
455 !------------------------------------------------------------
456 real function wallint(r0, xp, yp, xc, yc, pixwidthx, pixwidthy, hi)
457 real, intent(in) :: r0, xp, yp, xc, yc, pixwidthx, pixwidthy, hi
458 real(doub_prec) :: R_0, d1, d2, dx, dy, h
459
460 wallint = 0.0
461 dx = xc - xp
462 dy = yc - yp
463 h = hi
464
465 !
466 ! Contributions from each of the 4 sides of a cell wall
467 !
468 R_0 = 0.5*pixwidthy + dy
469 d1 = 0.5*pixwidthx - dx
470 d2 = 0.5*pixwidthx + dx
471 wallint = wallint + pint3D(r0, R_0, d1, d2, h)
472
473 R_0 = 0.5*pixwidthy - dy
474 d1 = 0.5*pixwidthx + dx
475 d2 = 0.5*pixwidthx - dx
476 wallint = wallint + pint3D(r0, R_0, d1, d2, h)
477
478 R_0 = 0.5*pixwidthx + dx
479 d1 = 0.5*pixwidthy + dy
480 d2 = 0.5*pixwidthy - dy
481 wallint = wallint + pint3D(r0, R_0, d1, d2, h)
482
483 R_0 = 0.5*pixwidthx - dx
484 d1 = 0.5*pixwidthy - dy
485 d2 = 0.5*pixwidthy + dy
486 wallint = wallint + pint3D(r0, R_0, d1, d2, h)
487
488 end function wallint
489
490
491 real function pint3D(r0, R_0, d1, d2, hi)
492
493 real(doub_prec), intent(in) :: R_0, d1, d2, hi
494 real, intent(in) :: r0
495 real(doub_prec) :: ar0, aR_0
496 real(doub_prec) :: int1, int2
497
498 if (abs(r0) < tiny(0.)) then
499 pint3D = 0.d0
500 return
501 endif
502
503 if (r0 > 0.d0) then
504 pint3D = 1.d0
505 ar0 = r0
506 else
507 pint3D = -1.d0
508 ar0 = -r0
509 endif
510
511 if (R_0 > 0.d0) then
512 aR_0 = R_0
513 else
514 pint3D = -pint3D
515 aR_0 = -R_0
516 endif
517
518 int1 = full_integral_3D(d1, ar0, aR_0, hi)
519 int2 = full_integral_3D(d2, ar0, aR_0, hi)
520
521 if (int1 < 0.d0) int1 = 0.d0
522 if (int2 < 0.d0) int2 = 0.d0
523
524 if (d1*d2 >= 0) then
525 pint3D = pint3D*(int1 + int2)
526 if (int1 + int2 < 0.d0) pint3D = 0. !print*, 'Error: int1 + int2 < 0'
527 elseif (abs(d1) < abs(d2)) then
528 pint3D = pint3D*(int2 - int1)
529 if (int2 - int1 < 0.d0) pint3D = 0.! print*, 'Error: int2 - int1 < 0: ', int1, int2, '(', d1, d2,')'
530 else
531 pint3D = pint3D*(int1 - int2)
532 if (int1 - int2 < 0.d0) pint3D = 0. !print*, 'Error: int1 - int2 < 0: ', int1, int2, '(', d1, d2,')'
533 endif
534
535 end function pint3D
536
537 real(doub_prec) function full_integral_3D(d, r0, R_0, h)
538
539 real(doub_prec), intent(in) :: d, r0, R_0, h
540 real(doub_prec) :: B1, B2, B3, a, h2
541 real(doub_prec), parameter :: pi = 4.*atan(1.)
542 real(doub_prec) :: tanphi, phi, a2, cosp, r0h, r03, r0h2, r0h3, r0h_2, r0h_3
543 real(doub_prec) :: r2, R_, linedist2, cosphi
544 real(doub_prec) :: I0, I1, I_2, I_3, I_4, I_5
545 real(doub_prec) :: D2, D3
546
547 r0h = r0/h
548 tanphi = abs(d)/R_0
549 phi = atan(tanphi)
550
551 if (abs(r0h) < tiny(0.) .or. abs(R_0/h) < tiny(0.) .or. abs(phi) < tiny(0.)) then
552 full_integral_3D = 0.0
553 return
554 endif
555
556 h2 = h*h
557 r03 = r0*r0*r0
558 r0h2 = r0h*r0h
559 r0h3 = r0h2*r0h
560 r0h_2 = 1./r0h2
561 r0h_3 = 1./r0h3
562
563 if (r0 >= 2.0*h) then
564 B3 = 0.25*h2*h
565 elseif (r0 > h) then
566 B3 = 0.25*r03 *(-4./3. + (r0h) - 0.3*r0h2 + 1./30.*r0h3 - 1./15. *r0h_3+ 8./5.*r0h_2)
567 B2 = 0.25*r03 *(-4./3. + (r0h) - 0.3*r0h2 + 1./30.*r0h3 - 1./15. *r0h_3)
568 else
569 B3 = 0.25*r03 *(-2./3. + 0.3*r0h2 - 0.1*r0h3 + 7./5.*r0h_2)
570 B2 = 0.25*r03 *(-2./3. + 0.3*r0h2 - 0.1*r0h3 - 1./5.*r0h_2)
571 B1 = 0.25*r03 *(-2./3. + 0.3*r0h2 - 0.1*r0h3)
572 endif
573
574 a = R_0/r0
575 a2 = a*a
576
577 linedist2 = (r0*r0 + R_0*R_0)
578 cosphi = cos(phi)
579 R_ = R_0/cosphi
580 r2 = (r0*r0 + R_*R_)
581
582 D2 = 0.0
583 D3 = 0.0
584
585 if (linedist2 < h2) then
586 !////// phi1 business /////
587 cosp = R_0/sqrt(h2-r0*r0)
588 call get_I_terms(cosp,a2,a,I0,I1,I_2,I_3,I_4,I_5)
589
590 D2 = -1./6.*I_2 + 0.25*(r0h) *I_3 - 0.15*r0h2 *I_4 + 1./30.*r0h3 *I_5 - 1./60. *r0h_3 *I1 + (B1-B2)/r03 *I0
591 endif
592 if (linedist2 < 4.*h2) then
593 !////// phi2 business /////
594 cosp = R_0/sqrt(4.0*h2-r0*r0)
595 call get_I_terms(cosp,a2,a,I0,I1,I_2,I_3,I_4,I_5)
596
597 D3 = 1./3.*I_2 - 0.25*(r0h) *I_3 + 3./40.*r0h2 *I_4 - 1./120.*r0h3 *I_5 + 4./15. *r0h_3 *I1 + (B2-B3)/r03 *I0 + D2
598 endif
599
600 !//////////////////////////////
601 call get_I_terms(cosphi,a2,a,I0,I1,I_2,I_3,I_4,I_5,phi=phi,tanphi=tanphi)
602
603 if (r2 < h2) then
604 full_integral_3D = r0h3/pi * (1./6. *I_2 - 3./40.*r0h2 *I_4 + 1./40.*r0h3 *I_5 + B1/r03 *I0)
605 elseif (r2 < 4.*h2) then
606 full_integral_3D= r0h3/pi * (0.25 * (4./3. *I_2 - (r0/h) *I_3 + 0.3*r0h2 *I_4 - &
607 & 1./30.*r0h3 *I_5 + 1./15. *r0h_3 *I1) + B2/r03 *I0 + D2)
608 else
609 full_integral_3D = r0h3/pi * (-0.25*r0h_3 *I1 + B3/r03 *I0 + D3)
610 endif
611
612 end function full_integral_3D
613
614 subroutine get_I_terms(cosp,a2,a,I0,I1,I_2,I_3,I_4,I_5,phi,tanphi)
615 real(doub_prec), intent(in) :: cosp,a2,a
616 real(doub_prec), intent(out) :: I0,I1,I_2,I_3,I_4,I_5
617 real(doub_prec), intent(in), optional :: phi,tanphi
618 real(doub_prec) :: cosp2,p,tanp,u2,u,logs,I_1,mu2_1,fac
619
620 cosp2 = cosp*cosp
621 if (present(phi)) then
622 p = phi
623 tanp = tanphi
624 else
625 p = acos(cosp)
626 tanp = sqrt(1.-cosp2)/cosp ! tan(p)
627 endif
628
629 mu2_1 = 1. / (1. + cosp2/a2)
630 I0 = p
631 I_2 = p + a2 * tanp
632 I_4 = p + 2.*a2 * tanp + 1./3.*a2*a2 * tanp*(2. + 1./cosp2)
633
634 u2 = (1.-cosp2)*mu2_1
635 u = sqrt(u2)
636 logs = log((1.+u)/(1.-u))
637 I1 = atan2(u,a)
638
639 fac = 1./(1.-u2)
640 I_1 = 0.5*a*logs + I1
641 I_3 = I_1 + a*0.25*(1.+a2)*(2.*u*fac + logs)
642 I_5 = I_3 + a*(1.+a2)*(1.+a2)/16. *( (10.*u - 6.*u*u2)*fac*fac + 3.*logs)
643
644 end subroutine get_I_terms
645
646 !------------------------------------------------------------
647 ! function to return a soft maximum for 1/x with no bias
648 ! for x >> eps using the cubic spline kernel softening
649 ! i.e. something equivalent to 1/sqrt(x**2 + eps**2) but
650 ! with compact support, i.e. f=1/x when x > 2*eps
651 !------------------------------------------------------------
652 pure elemental real function soft_func(x,eps) result(f)
653 real, intent(in) :: x,eps
654 real :: q,q2,q4
655
656 q = x/eps
657 q2 = q*q
658 if (q < 1.) then
659 q4 = q2*q2
660 f = (1./eps)*(q4*q/10. - 3.*q4/10. + 2.*q2/3. - 7./5.)
661 elseif (q < 2.) then
662 q4 = q2*q2
663 f = (1./eps)*(q*(-q4*q + 9.*q4 - 30.*q2*q + 40.*q2 - 48.) + 2.)/(30.*q)
664 else
665 f = -1./x
666 endif
667 f = -f
668
669 end function soft_func
670
671 end module kernels