| 1 |
! This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
! License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
! file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 |
module mbd_damping |
| 5 |
!! Damping functions. |
| 6 |
|
| 7 |
use mbd_constants |
| 8 |
use mbd_defaults |
| 9 |
use mbd_gradients, only: grad_scalar_t, grad_request_t |
| 10 |
use mbd_utils, only: lower, exception_t |
| 11 |
|
| 12 |
implicit none |
| 13 |
|
| 14 |
private |
| 15 |
public :: damping_fermi, damping_sqrtfermi, op1minus_grad |
| 16 |
|
| 17 |
type, public :: damping_t |
| 18 |
!! Represents a damping function. |
| 19 |
character(len=20) :: version |
| 20 |
real(dp) :: beta = 0d0 |
| 21 |
real(dp) :: a = MBD_DAMPING_A |
| 22 |
real(dp) :: ts_d = TS_DAMPING_D |
| 23 |
real(dp) :: ts_sr = 0d0 |
| 24 |
real(dp) :: mayer_scaling = 1d0 |
| 25 |
real(dp), allocatable :: r_vdw(:) |
| 26 |
real(dp), allocatable :: sigma(:) |
| 27 |
real(dp), allocatable :: damping_custom(:, :) |
| 28 |
real(dp), allocatable :: potential_custom(:, :, :, :) |
| 29 |
contains |
| 30 |
procedure :: set_params_from_xc => damping_set_params_from_xc |
| 31 |
end type |
| 32 |
|
| 33 |
contains |
| 34 |
|
| 35 |
real(dp) function damping_fermi(r, s_vdw, d, df, grad) result(f) |
| 36 |
!! $$ |
| 37 |
!! \begin{gathered} |
| 38 |
!! f_{(ij)}=\frac1{1+\exp\big({-}a(\eta-1)\big)},\qquad |
| 39 |
!! \eta=\frac{R_{(ij)}}{S_{\text{vdW}(ij)}}\equiv |
| 40 |
!! \frac{R_{(ij)}}{\beta R_{\text{vdW}(ij)}} |
| 41 |
!! \\ \frac{\mathrm df}{\mathrm dR_c}= |
| 42 |
!! \frac a{2+2\cosh\big(a(\eta-1)\big)}\frac{\mathrm d\eta}{\mathrm dR_c},\qquad |
| 43 |
!! \frac{\mathrm d\eta}{\mathrm dR_c}= |
| 44 |
!! \frac{R_c}{RS_\text{vdW}}- |
| 45 |
!! \frac{R}{S_\text{vdW}^2}\frac{\mathrm dS_\text{vdW}}{\mathrm dR_c} |
| 46 |
!! \end{gathered} |
| 47 |
!! $$ |
| 48 |
real(dp), intent(in) :: r(3) |
| 49 |
real(dp), intent(in) :: s_vdw |
| 50 |
real(dp), intent(in) :: d |
| 51 |
type(grad_scalar_t), intent(out), optional :: df |
| 52 |
type(grad_request_t), intent(in), optional :: grad |
| 53 |
|
| 54 |
real(dp) :: pre, eta, r_1 |
| 55 |
|
| 56 |
r_1 = sqrt(sum(r**2)) |
| 57 |
eta = r_1 / s_vdw |
| 58 |
f = 1d0 / (1 + exp(-d * (eta - 1))) |
| 59 |
if (.not. present(grad)) return |
| 60 |
pre = d / (2 + 2 * cosh(d - d * eta)) |
| 61 |
if (grad%dcoords) df%dr = pre * r / (r_1 * s_vdw) |
| 62 |
if (grad%dr_vdw) df%dvdw = -pre * r_1 / s_vdw**2 |
| 63 |
end function |
| 64 |
|
| 65 |
real(dp) function damping_sqrtfermi(r, s_vdw, d) result(f) |
| 66 |
real(dp), intent(in) :: r(3) |
| 67 |
real(dp), intent(in) :: s_vdw |
| 68 |
real(dp), intent(in) :: d |
| 69 |
|
| 70 |
f = sqrt(damping_fermi(r, s_vdw, d)) |
| 71 |
end function |
| 72 |
|
| 73 |
subroutine op1minus_grad(f, df) |
| 74 |
real(dp), intent(inout) :: f |
| 75 |
type(grad_scalar_t), intent(inout) :: df |
| 76 |
|
| 77 |
f = 1 - f |
| 78 |
if (allocated(df%dr)) df%dr = -df%dr |
| 79 |
if (allocated(df%dvdw)) df%dvdw = -df%dvdw |
| 80 |
end subroutine |
| 81 |
|
| 82 |
type(exception_t) function damping_set_params_from_xc(this, xc, variant) result(exc) |
| 83 |
class(damping_t), intent(inout) :: this |
| 84 |
character(len=*), intent(in) :: xc |
| 85 |
character(len=*), intent(in) :: variant |
| 86 |
|
| 87 |
select case (lower(variant)) |
| 88 |
case ('ts') |
| 89 |
select case (lower(xc)) |
| 90 |
case ('pbe') |
| 91 |
this%ts_sr = 0.94d0 |
| 92 |
case ('pbe0') |
| 93 |
this%ts_sr = 0.96d0 |
| 94 |
case ('hse') |
| 95 |
this%ts_sr = 0.96d0 |
| 96 |
case ('blyp') |
| 97 |
this%ts_sr = 0.62d0 |
| 98 |
case ('b3lyp') |
| 99 |
this%ts_sr = 0.84d0 |
| 100 |
case ('revpbe') |
| 101 |
this%ts_sr = 0.60d0 |
| 102 |
case ('am05') |
| 103 |
this%ts_sr = 0.84d0 |
| 104 |
case default |
| 105 |
exc%code = MBD_EXC_DAMPING |
| 106 |
exc%msg = 'Damping parameter S_r of method TS unknown for '//trim(xc) |
| 107 |
end select |
| 108 |
case ('mbd-rsscs') |
| 109 |
select case (lower(xc)) |
| 110 |
case ('pbe') |
| 111 |
this%beta = 0.83d0 |
| 112 |
case ('pbe0') |
| 113 |
this%beta = 0.85d0 |
| 114 |
case ('hse') |
| 115 |
this%beta = 0.85d0 |
| 116 |
case default |
| 117 |
exc%code = MBD_EXC_DAMPING |
| 118 |
exc%msg = 'Damping parameter beta of method MBD@rsSCS unknown for '//trim(xc) |
| 119 |
end select |
| 120 |
case ('mbd-nl') |
| 121 |
select case (lower(xc)) |
| 122 |
case ('pbe') |
| 123 |
this%beta = 0.81d0 |
| 124 |
case ('pbe0') |
| 125 |
this%beta = 0.83d0 |
| 126 |
case ('hse') |
| 127 |
this%beta = 0.83d0 |
| 128 |
case default |
| 129 |
exc%code = MBD_EXC_DAMPING |
| 130 |
exc%msg = 'Damping parameter beta of method MBD-NL unknown for '//trim(xc) |
| 131 |
end select |
| 132 |
case ('mbd-ts') |
| 133 |
select case (lower(xc)) |
| 134 |
case ('pbe') |
| 135 |
this%beta = 0.81d0 |
| 136 |
case ('pbe0') |
| 137 |
this%beta = 0.83d0 |
| 138 |
case ('hse') |
| 139 |
this%beta = 0.83d0 |
| 140 |
case default |
| 141 |
exc%code = MBD_EXC_DAMPING |
| 142 |
exc%msg = 'Damping parameter beta of method MBD@TS unknown for '//trim(xc) |
| 143 |
end select |
| 144 |
case ('mbd-scs') |
| 145 |
select case (lower(xc)) |
| 146 |
case ('pbe') |
| 147 |
this%a = 2.56d0 |
| 148 |
case ('pbe0') |
| 149 |
this%a = 2.53d0 |
| 150 |
case ('hse') |
| 151 |
this%a = 2.53d0 |
| 152 |
case default |
| 153 |
exc%code = MBD_EXC_DAMPING |
| 154 |
exc%msg = 'Damping parameter a of method MBD@SCS unknown for '//trim(xc) |
| 155 |
end select |
| 156 |
case default |
| 157 |
exc%code = MBD_EXC_DAMPING |
| 158 |
exc%msg = 'Damping paramters of method '//trim(variant)//' unkonwn for '//trim(xc) |
| 159 |
end select |
| 160 |
end function |
| 161 |
|
| 162 |
end module |