Octopus
stencil_star.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
26 use debug_oct_m
27 use global_oct_m
28 use math_oct_m
33
34 implicit none
35
36 private
37 public :: &
46
47contains
48
49 ! ---------------------------------------------------------
50 integer function stencil_star_size_lapl(dim, order)
51 integer, intent(in) :: dim
52 integer, intent(in) :: order
53
55
56 stencil_star_size_lapl = 2*dim*order + 1
57
59 end function stencil_star_size_lapl
60
61
62 ! ---------------------------------------------------------
63 subroutine stencil_star_get_lapl(this, dim, order)
64 type(stencil_t), intent(inout) :: this
65 integer, intent(in) :: dim
66 integer, intent(in) :: order
67
68 integer :: ii, jj, nn
69 logical :: got_center
70
71 push_sub(stencil_star_get_lapl)
72
73 call stencil_allocate(this, dim, stencil_star_size_lapl(dim, order))
74
75 got_center = .false.
76
77 nn = 0
78 do ii = 1, dim
79 do jj = -order, order
80
81 if (jj == 0) then
82 if (got_center) then
83 cycle
84 else
85 got_center = .true.
86 end if
87 end if
88
89 nn = nn + 1
90 this%points(ii, nn) = jj
91 end do
92 end do
93
94 call stencil_init_center(this)
95
97 end subroutine stencil_star_get_lapl
98
99
100 ! ---------------------------------------------------------
101 subroutine stencil_star_polynomials_lapl(dim, order, pol)
102 integer, intent(in) :: dim
103 integer, intent(in) :: order
104 integer, intent(out) :: pol(:,:)
105
106 integer :: i, j, n
107
109
110 n = 1
111 pol(:,:) = 0
112 do i = 1, dim
113 do j = 1, 2*order
114 n = n + 1
115 pol(i, n) = j
116 end do
117 end do
120 end subroutine stencil_star_polynomials_lapl
121
122
123 ! ---------------------------------------------------------
124 subroutine stencil_star_coeff_lapl(dim, order, h, lapl)
125 integer, intent(in) :: dim
126 integer, intent(in) :: order
127 real(real64), intent(in) :: h(:)
128 type(nl_operator_t), intent(inout) :: lapl
129
130 integer :: k, i, j, morder
131 real(real64), allocatable :: cc(:,:,:)
132
134
135 assert(order >= 1)
136
137 morder = 2*order
138 safe_allocate(cc(0:morder, 0:morder, 0:2))
139 call weights(2, morder, cc)
140 lapl%w(1,:) = cc(0, morder, 2)*sum(1/h(1:dim)**2)
141
142 k = 1
143 do i = 1, dim
144 do j = -order, -1
145 k = k + 1
146 lapl%w(k,:) = cc(-2*j-1, morder, 2) / h(i)**2
147 end do
148
149 do j = 1, order
150 k = k + 1
151 lapl%w(k,:) = cc( 2*j, morder, 2) / h(i)**2
152 end do
153 end do
154
155 safe_deallocate_a(cc)
158 end subroutine stencil_star_coeff_lapl
159
160
162
163 ! ---------------------------------------------------------
164 integer function stencil_star_size_grad(order)
165 integer, intent(in) :: order
166
167 push_sub(stencil_star_size_grad)
168
169 stencil_star_size_grad = 2*order + 1
170
172 end function stencil_star_size_grad
173
174
175 ! ---------------------------------------------------------
176 subroutine stencil_star_get_grad(this, dim, dir, order)
177 type(stencil_t), intent(inout) :: this
178 integer, intent(in) :: dim
179 integer, intent(in) :: dir
180 integer, intent(in) :: order
181
182 integer :: i, n
183
184 push_sub(stencil_star_get_grad)
185
186 call stencil_allocate(this, dim, stencil_star_size_grad(order))
187
188 n = 1
189 do i = -order, order
190 this%points(dir, n) = i
191 n = n + 1
192 end do
193
195
196 pop_sub(stencil_star_get_grad)
197 end subroutine stencil_star_get_grad
198
199
200 ! ---------------------------------------------------------
201 subroutine stencil_star_polynomials_grad(dir, order, pol)
202 integer, intent(in) :: dir
203 integer, intent(in) :: order
204 integer, intent(out) :: pol(:,:)
205
206 integer :: j
207
209
210 pol(:,:) = 0
211 do j = 0, 2*order
212 pol(dir, j+1) = j
213 end do
214
216 end subroutine stencil_star_polynomials_grad
218
219 ! ---------------------------------------------------------
220 subroutine stencil_star_coeff_grad(order, h, grad)
221 integer, intent(in) :: order
222 real(real64), intent(in) :: h
223 type(nl_operator_t), intent(inout) :: grad
224
225 integer :: j, k, morder
226 real(real64), allocatable :: cc(:,:,:)
227
229
230 assert(order >= 1)
231
232 morder = 2*order
233 safe_allocate(cc(0:morder, 0:morder, 0:1))
234 call weights(1, morder, cc)
235
236 k = 1
237 do j = -order, -1
238 grad%w(k,:) = cc(-2*j-1, morder, 1) / h
239 k = k + 1
240 end do
241
242 grad%w(k,:) = cc(0, morder, 1) / h
243
244 do j = 1, order
245 k = k + 1
246 grad%w(k,:) = cc(2*j, morder, 1) / h
247 end do
248
249 safe_deallocate_a(cc)
250
252 end subroutine stencil_star_coeff_grad
253
254end module stencil_star_oct_m
255
256!! Local Variables:
257!! mode: f90
258!! coding: utf-8
259!! End:
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:115
subroutine, public weights(N, M, cc, side)
Compute the weights for finite-difference calculations:
Definition: math.F90:522
This module defines non-local operators.
This module defines stencils used in Octopus.
Definition: stencil.F90:135
subroutine, public stencil_allocate(this, dim, size)
Definition: stencil.F90:178
subroutine, public stencil_init_center(this)
Definition: stencil.F90:275
This module defines routines, generating operators for a star stencil.
subroutine, public stencil_star_coeff_grad(order, h, grad)
subroutine, public stencil_star_get_grad(this, dim, dir, order)
integer function, public stencil_star_size_grad(order)
now come the gradient routines
subroutine, public stencil_star_coeff_lapl(dim, order, h, lapl)
subroutine, public stencil_star_get_lapl(this, dim, order)
subroutine, public stencil_star_polynomials_grad(dir, order, pol)
subroutine, public stencil_star_polynomials_lapl(dim, order, pol)
integer function, public stencil_star_size_lapl(dim, order)
data type for non local operators
The class representing the stencil, which is used for non-local mesh operations.
Definition: stencil.F90:163
int true(void)