Octopus
spline_filter.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use debug_oct_m
23 use global_oct_m
24 use io_oct_m
25 use, intrinsic :: iso_fortran_env
29
30 implicit none
31
32 private
33
34 public :: &
39
40 integer, parameter :: mask_n = 201
41 real(real64) :: mask_x(mask_n), mask_y(mask_n)
42
43contains
44
54 !
55 !----------------------------------------------------------------------------
56 subroutine spline_filter_ft(spl, threshold, fs, rs)
57 type(spline_t), intent(inout) :: spl
58 real(real64), intent(in) :: threshold
59 real(real64), optional, intent(in) :: fs(2)
60 real(real64), optional, intent(in) :: rs(2)
61
62 type(spline_t) :: splw
63
64 push_sub(spline_filter_ft)
65
66 if (present(fs)) then
67 call spline_init(splw)
68 call spline_3dft(spl, splw, threshold, m_two*fs(1))
69 call spline_cut(splw, fs(1), fs(2))
70 call spline_3dft(splw, spl, threshold)
71 call spline_times(real(m_one/(m_two*m_pi)**3, real64), spl, threshold)
72 call spline_end(splw)
73 end if
74 if (present(rs)) then
75 call spline_cut(spl, rs(1), rs(2), threshold)
76 end if
77
78 pop_sub(spline_filter_ft)
79 end subroutine spline_filter_ft
80
81
82 !----------------------------------------------------------------------------
83 subroutine spline_filter_bessel(spl, l, qmax, alpha, beta_fs, rcut, beta_rs, threshold)
84 type(spline_t), intent(inout) :: spl
85 integer, intent(in) :: l
86 real(real64), intent(in) :: qmax, alpha, beta_fs, rcut, beta_rs
87 real(real64), intent(in) :: threshold
88
89 type(spline_t) :: splw
90
91 push_sub(spline_filter_bessel)
92
93 call spline_init(splw)
94 call spline_besselft(spl, splw, l, gmax=m_four*qmax)
95 call spline_cut(splw, alpha*qmax, beta_fs)
96 call spline_besselft(splw, spl, l)
97 call spline_end(splw)
98 call spline_cut(spl, rcut, beta_rs, threshold)
99
100 pop_sub(spline_filter_bessel)
101 end subroutine spline_filter_bessel
102
103
104 !----------------------------------------------------------------------------
105 subroutine spline_filter_mask_init()
106
107 integer :: iunit, i
108
110
111 iunit = io_open(trim(conf%share)//"/filter_mask.data", action='read', status='old', die=.true.)
112
113 do i = 1, mask_n
114 read(iunit, *) mask_x(i), mask_y(i)
115 end do
116
117 call io_close(iunit)
118
120 end subroutine spline_filter_mask_init
121
122
123 !----------------------------------------------------------------------------
124 subroutine spline_filter_mask(spl, l, rmax, qmax, alpha, gamma, threshold)
125 type(spline_t), intent(inout) :: spl
126 integer, intent(in) :: l
127 real(real64), intent(in) :: rmax
128 real(real64), intent(in) :: qmax
129 real(real64), intent(in) :: alpha
130 real(real64), intent(in) :: gamma
131 real(real64), intent(in) :: threshold
132
133 type(spline_t) :: mask, splw
134 real(real64) :: local_mask_x(mask_n), rcut, beta
135
136 push_sub(spline_filter_mask)
137
138 rcut = gamma*rmax
139
140 ! If rut is zero, the code below fails
141 assert(rcut > m_epsilon)
142
143 ! we define the mask function as f(r/rcut)
144 local_mask_x = mask_x*rcut
145 call spline_fit(mask_n, local_mask_x, mask_y, mask)
146
147 ! apply the mask function
148 call spline_div(spl, mask)
150 ! transform to bessel space
151 call spline_init(splw)
152 call spline_besselft(spl, splw, l, gmax=m_four*qmax)
153
154 ! apply a cutoff
155 beta = log(1.e5_real64)/(alpha - m_one)**2
156 call spline_cut(splw, qmax/alpha, beta)
157
158 ! transform back to real space
159 call spline_besselft(splw, spl, l)
160 call spline_end(splw)
161
162 ! remove the mask function
163 call spline_mult(spl, mask, threshold)
164
165 call spline_end(mask)
166
167 pop_sub(spline_filter_mask)
168
169 end subroutine spline_filter_mask
170
171end module spline_filter_oct_m
172
173!! Local Variables:
174!! mode: f90
175!! coding: utf-8
176!! End:
Some operations may be done for one spline-function, or for an array of them.
Definition: splines.F90:179
double log(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_two
Definition: global.F90:189
real(real64), parameter, public m_four
Definition: global.F90:191
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:185
real(real64), parameter, public m_epsilon
Definition: global.F90:203
type(conf_t), public conf
Global instance of Octopus configuration.
Definition: global.F90:177
real(real64), parameter, public m_one
Definition: global.F90:188
Definition: io.F90:114
subroutine, public io_close(iunit, grp)
Definition: io.F90:468
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:395
subroutine, public spline_filter_mask(spl, l, rmax, qmax, alpha, gamma, threshold)
subroutine, public spline_filter_ft(spl, threshold, fs, rs)
The function spline_filter_ft permits to filter out high-values of a given spline function,...
subroutine, public spline_filter_mask_init()
subroutine, public spline_filter_bessel(spl, l, qmax, alpha, beta_fs, rcut, beta_rs, threshold)
subroutine, public spline_fit(nrc, rofi, ffit, spl, threshold)
Definition: splines.F90:413
subroutine, public spline_3dft(spl, splw, threshold, gmax)
Definition: splines.F90:599
subroutine, public spline_besselft(spl, splw, l, threshold, gmax)
Definition: splines.F90:677
subroutine, public spline_cut(spl, cutoff, beta, threshold)
Definition: splines.F90:748
subroutine, public spline_div(spla, splb, threshold)
Returns the values of spla divided by the values of splb.
Definition: splines.F90:797
subroutine, public spline_times(a, spl, threshold)
Definition: splines.F90:510
subroutine, public spline_mult(spla, splb, threshold)
Definition: splines.F90:875
the basic spline datatype
Definition: splines.F90:156
int true(void)