Octopus
potential_interpolation.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
25 use math_oct_m
26 use mesh_oct_m
31
32 implicit none
33
34 private
35 public :: &
47
49 private
50 real(real64), allocatable, public :: v_old(:, :, :)
51 real(real64), allocatable, public :: vtau_old(:, :, :)
52 logical :: mgga_with_exc
54
55 integer :: interpolation_steps
56
57contains
58
59 ! ---------------------------------------------------------
60 subroutine potential_interpolation_copy(vkso, vksi)
61 type(potential_interpolation_t), intent(inout) :: vkso
62 type(potential_interpolation_t), intent(in) :: vksi
63
65
66 safe_allocate_source_a(vkso%v_old, vksi%v_old)
67 safe_allocate_source_a(vkso%vtau_old, vksi%vtau_old)
68 vkso%mgga_with_exc = vksi%mgga_with_exc
69
71 end subroutine potential_interpolation_copy
72 ! ---------------------------------------------------------
73
74 ! ---------------------------------------------------------
75 subroutine potential_interpolation_init(potential_interpolation, np, nspin, mgga_with_exc, order)
76 type(potential_interpolation_t), intent(inout) :: potential_interpolation
77 integer, intent(in) :: np, nspin
78 logical, intent(in) :: mgga_with_exc
79 integer, optional, intent(in) :: order
80
82
83 interpolation_steps = optional_default(order, 3)
84
85 safe_allocate(potential_interpolation%v_old(1:np, 1:nspin, 0:interpolation_steps))
86 potential_interpolation%v_old(:, :, :) = m_zero
87
88 potential_interpolation%mgga_with_exc = mgga_with_exc
89
90 if (potential_interpolation%mgga_with_exc) then
91
92 safe_allocate(potential_interpolation%vtau_old(1:np, 1:nspin, 0:interpolation_steps))
93 potential_interpolation%vtau_old(:, :, :) = m_zero
94
95 end if
96
98 end subroutine potential_interpolation_init
99 ! ---------------------------------------------------------
100
101 ! ---------------------------------------------------------
102 subroutine potential_interpolation_end(potential_interpolation)
103 type(potential_interpolation_t), intent(inout) :: potential_interpolation
104
106
107 assert(allocated(potential_interpolation%v_old))
108 safe_deallocate_a(potential_interpolation%v_old)
109 safe_deallocate_a(potential_interpolation%vtau_old)
110
112 end subroutine potential_interpolation_end
113 ! ---------------------------------------------------------
114
115 ! ---------------------------------------------------------
116 subroutine potential_interpolation_run_zero_iter(potential_interpolation, np, nspin, vhxc, vtau)
117 type(potential_interpolation_t), intent(inout) :: potential_interpolation
118 integer, intent(in) :: np, nspin
119 real(real64), intent(in) :: vhxc(:, :)
120 real(real64), optional, intent(in) :: vtau(:, :)
121
122 integer :: i, ispin, ip
123
125
126 do i = 1, interpolation_steps
127 do ispin = 1, nspin
128 do ip = 1, np
129 potential_interpolation%v_old(ip, ispin, i) = vhxc(ip, ispin)
130 end do
131 end do
132 end do
133
134 if (potential_interpolation%mgga_with_exc) then
135 assert(present(vtau))
136 do i = 1, interpolation_steps
137 do ispin = 1, nspin
138 do ip = 1, np
139 potential_interpolation%vtau_old(ip, ispin, i) = vtau(ip, ispin)
140 end do
141 end do
142 end do
143 end if
144
147 ! ---------------------------------------------------------
148
149 ! ---------------------------------------------------------
150 subroutine potential_interpolation_new(potential_interpolation, np, nspin, time, dt, vhxc, vtau)
151 type(potential_interpolation_t), intent(inout) :: potential_interpolation
152 integer, intent(in) :: np, nspin
153 real(real64), intent(in) :: time, dt
154 real(real64), contiguous, intent(in) :: vhxc(:, :)
155 real(real64), contiguous, optional, intent(in) :: vtau(:, :)
156
157 real(real64), allocatable :: times(:)
158 integer :: j
159
161
162 safe_allocate(times(1:interpolation_steps))
163 do j = 1, interpolation_steps
164 times(j) = time - j*dt
165 end do
166
167 do j = interpolation_steps, 2, -1
168 call lalg_copy(np, nspin, potential_interpolation%v_old(:, :, j-1), potential_interpolation%v_old(:, :, j))
169 end do
170 call lalg_copy(np, nspin, vhxc(:, :), potential_interpolation%v_old(:, :, 1))
171 call interpolate( times, potential_interpolation%v_old(:, :, 1:interpolation_steps), &
172 time, potential_interpolation%v_old(:, :, 0))
173
174 if (potential_interpolation%mgga_with_exc) then
175 assert(present(vtau))
176 do j = interpolation_steps, 2, -1
177 call lalg_copy(np, nspin, potential_interpolation%vtau_old(:, :, j-1), potential_interpolation%vtau_old(:, :, j))
178 end do
179 call lalg_copy(np, nspin, vtau(:, :), potential_interpolation%vtau_old(:, :, 1))
180 call interpolate( times, potential_interpolation%vtau_old(:, :, 1:interpolation_steps), &
181 time, potential_interpolation%vtau_old(:, :, 0))
182 end if
183
184 safe_deallocate_a(times)
186 end subroutine potential_interpolation_new
187 ! ---------------------------------------------------------
188
189 ! ---------------------------------------------------------
190 subroutine potential_interpolation_set(potential_interpolation, np, nspin, i, vhxc, vtau)
191 type(potential_interpolation_t), intent(inout) :: potential_interpolation
192 integer, intent(in) :: np, nspin
193 integer, intent(in) :: i
194 real(real64), contiguous, intent(in) :: vhxc(:, :)
195 real(real64), contiguous, optional,intent(in) :: vtau(:, :)
196
198
199 call lalg_copy(np, nspin, vhxc, potential_interpolation%v_old(:, :, i))
200
201 if (potential_interpolation%mgga_with_exc) then
202 assert(present(vtau))
203 call lalg_copy(np, nspin, vtau, potential_interpolation%vtau_old(:, :, i))
204 end if
205
207 end subroutine potential_interpolation_set
208 ! ---------------------------------------------------------
209
210 ! ---------------------------------------------------------
211 subroutine potential_interpolation_get(potential_interpolation, np, nspin, i, vhxc, vtau)
212 type(potential_interpolation_t), intent(inout) :: potential_interpolation
213 integer, intent(in) :: np, nspin
214 integer, intent(in) :: i
215 real(real64), contiguous, intent(inout) :: vhxc(:, :)
216 real(real64), optional, contiguous, intent(inout) :: vtau(:, :)
217
219
220 call lalg_copy(np, nspin, potential_interpolation%v_old(:, :, i), vhxc)
221
222 if (potential_interpolation%mgga_with_exc) then
223 assert(present(vtau))
224 call lalg_copy(np, nspin, potential_interpolation%vtau_old(:, :, i), vtau)
225 end if
226
228 end subroutine potential_interpolation_get
229 ! ---------------------------------------------------------
230
231
232 ! ---------------------------------------------------------
233 subroutine potential_interpolation_interpolate(potential_interpolation, order, time, dt, t, vhxc, vtau)
234 type(potential_interpolation_t), intent(inout) :: potential_interpolation
235 integer, intent(in) :: order
236 real(real64), intent(in) :: time, dt, t
237 real(real64), contiguous, intent(inout) :: vhxc(:, :)
238 real(real64), contiguous, optional, intent(inout) :: vtau(:, :)
239
240 integer :: j
241 real(real64), allocatable :: times(:)
242
244
245 safe_allocate(times(1:interpolation_steps))
246 do j = 1, interpolation_steps
247 times(j) = time - (j-1)*dt
248 end do
249
250 call interpolate( times(1:order), potential_interpolation%v_old(:, :, 0:order-1), t, vhxc(:, :))
251
252 if (potential_interpolation%mgga_with_exc) then
253 assert(present(vtau))
254 call interpolate( times(1:order), potential_interpolation%vtau_old(:, :, 0:order-1), t, vtau(:, :))
255 end if
256
257 safe_deallocate_a(times)
260 ! ---------------------------------------------------------
261
262 ! ---------------------------------------------------------
263 subroutine potential_interpolation_dump(potential_interpolation, restart, mesh, nspin, err2)
264 type(potential_interpolation_t), intent(in) :: potential_interpolation
265 type(restart_t), intent(in) :: restart
266 class(mesh_t), intent(in) :: mesh
267 integer, intent(in) :: nspin
268 integer, intent(out) :: err2
269
270 integer :: ii, is, err
271 character(len=256) :: filename
272 !type(mpi_grp_t) :: mpi_grp
273
275
276 err2 = 0
277 do ii = 1, interpolation_steps - 1
278 do is = 1, nspin
279 write(filename,'(a6,i2.2,i3.3)') 'vprev_', ii, is
280 call restart%write_mesh_function(filename, mesh, &
281 potential_interpolation%v_old(1:mesh%np, is, ii), err)
282 ! the unit is energy actually, but this only for restart, and can be kept in atomic units
283 ! for simplicity
284 if (err /= 0) err2 = err2 + 1
285 end do
286 end do
287
288
289 if (potential_interpolation%mgga_with_exc) then
290 err2 = 0
291 do ii = 1, interpolation_steps - 1
292 do is = 1, nspin
293 write(filename,'(a9,i2.2,i3.3)') 'vtauprev_', ii, is
294 call restart%write_mesh_function(filename, mesh, &
295 potential_interpolation%vtau_old(1:mesh%np, is, ii), err)
296 ! the unit is energy actually, but this only for restart, and can be kept in atomic units
297 ! for simplicity
298 if (err /= 0) err2 = err2 + 1
299 end do
300 end do
301 end if
302
304 end subroutine potential_interpolation_dump
305 ! ---------------------------------------------------------
307 ! ---------------------------------------------------------
308 subroutine potential_interpolation_load(potential_interpolation, namespace, restart, mesh, nspin, err2)
309 type(potential_interpolation_t), intent(inout) :: potential_interpolation
310 type(namespace_t), intent(in) :: namespace
311 type(restart_t), intent(in) :: restart
312 class(mesh_t), intent(in) :: mesh
313 integer, intent(in) :: nspin
314 integer, intent(out) :: err2
315
316 integer :: ii, is, err
317 character(len=256) :: filename
318
320
321 err2 = 0
322 do ii = 1, interpolation_steps - 1
323 do is = 1, nspin
324 write(filename,'(a,i2.2,i3.3)') 'vprev_', ii, is
325 call restart%read_mesh_function(filename, mesh, &
326 potential_interpolation%v_old(1:mesh%np, is, ii), err)
327 if (err /= 0) then
328 err2 = err2 + 1
329 message(1) = "Unable to read VKS restart file '" // trim(filename) // "'"
330 call messages_warning(1, namespace=namespace)
331 end if
332 end do
333 end do
334
335 if (potential_interpolation%mgga_with_exc) then
336 err2 = 0
337 do ii = 1, interpolation_steps - 1
338 do is = 1, nspin
339 write(filename,'(a,i2.2,i3.3)') 'vtauprev_', ii, is
340 call restart%read_mesh_function(filename, mesh, &
341 potential_interpolation%vtau_old(1:mesh%np, is, ii), err)
342 if (err /= 0) then
343 err2 = err2 + 1
344 message(1) = "Unable to read VKS restart file '" // trim(filename) // "'"
345 call messages_warning(1, namespace=namespace)
346 end if
347 end do
348 end do
349 end if
350
352 end subroutine potential_interpolation_load
353 ! ---------------------------------------------------------
354
356
357!! Local Variables:
358!! mode: f90
359!! coding: utf-8
360!! End:
Copies a vector x, to a vector y.
Definition: lalg_basic.F90:188
This is the common interface to a simple-minded polynomical interpolation procedure (simple use of th...
Definition: math.F90:189
real(real64), parameter, public m_zero
Definition: global.F90:191
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:525
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public potential_interpolation_copy(vkso, vksi)
subroutine, public potential_interpolation_end(potential_interpolation)
subroutine, public potential_interpolation_interpolate(potential_interpolation, order, time, dt, t, vhxc, vtau)
subroutine, public potential_interpolation_set(potential_interpolation, np, nspin, i, vhxc, vtau)
subroutine, public potential_interpolation_new(potential_interpolation, np, nspin, time, dt, vhxc, vtau)
subroutine, public potential_interpolation_run_zero_iter(potential_interpolation, np, nspin, vhxc, vtau)
subroutine, public potential_interpolation_load(potential_interpolation, namespace, restart, mesh, nspin, err2)
subroutine, public potential_interpolation_get(potential_interpolation, np, nspin, i, vhxc, vtau)
subroutine, public potential_interpolation_dump(potential_interpolation, restart, mesh, nspin, err2)
subroutine, public potential_interpolation_init(potential_interpolation, np, nspin, mgga_with_exc, order)
Describes mesh distribution to nodes.
Definition: mesh.F90:187