Octopus
output.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
22module output_oct_m
23 use accel_oct_m
24 use basins_oct_m
25 use box_oct_m
26 use comm_oct_m
27 use cube_oct_m
30 use debug_oct_m
33 use dos_oct_m
35 use elf_oct_m
38 use fft_oct_m
41 use global_oct_m
42 use grid_oct_m
45 use io_oct_m
47 use ions_oct_m
48 use, intrinsic :: iso_fortran_env
52 use lasers_oct_m
53 use lda_u_oct_m
56 use loct_oct_m
57 use math_oct_m
59 use mesh_oct_m
62 use mpi_oct_m
68 use parser_oct_m
71 use smear_oct_m
72 use space_oct_m
77 use stress_oct_m
78 use string_oct_m
82 use unit_oct_m
84 use utils_oct_m
86 use v_ks_oct_m
87 use xc_oct_m
88 use xc_oep_oct_m
90 use xc_f03_lib_m
91 use xc_vxc_oct_m
92
93 implicit none
94
95 private
96 public :: &
101 output_all, &
103 doutput_lr, &
104 zoutput_lr, &
108
109contains
110
111 subroutine output_init(outp, namespace, space, st, gr, nst, ks)
112 type(output_t), intent(out) :: outp
113 type(namespace_t), intent(in) :: namespace
114 class(space_t), intent(in) :: space
115 type(states_elec_t), intent(in) :: st
116 type(grid_t), intent(in) :: gr
117 integer, intent(in) :: nst
118 type(v_ks_t), intent(inout) :: ks
119
120 type(block_t) :: blk
121 real(real64) :: norm
122 character(len=80) :: nst_string, default
123
124 push_sub(output_init)
125 outp%what = .false.
126
127 call io_function_read_what_how_when(namespace, space, outp%what, outp%how, outp%output_interval)
128
129 if (outp%what(option__output__wfs_fourier)) then
130 if (accel_is_enabled()) then
131 message(1) = "Wave functions in Fourier space not supported on GPUs."
132 call messages_fatal(1, namespace=namespace)
133 end if
134 call messages_experimental("Wave-functions in Fourier space", namespace=namespace)
135 end if
136
137 ! cannot calculate the ELF in 1D
138 if (outp%what(option__output__elf) .or. outp%what(option__output__elf_basins)) then
139 if (space%dim /= 2 .and. space%dim /= 3) then
140 outp%what(option__output__elf) = .false.
141 outp%what(option__output__elf_basins) = .false.
142 write(message(1), '(a)') 'Cannot calculate ELF except in 2D and 3D.'
143 call messages_warning(1, namespace=namespace)
144 end if
145 end if
146
147
148 if (outp%what(option__output__mmb_wfs)) then
149 call messages_experimental("Model many-body wfs", namespace=namespace)
150 end if
151
152 if (outp%what(option__output__xc_torque)) then
153 if (st%d%ispin /= spinors) then
154 write(message(1), '(a)') 'The output xc_torque can only be computed for spinors.'
155 call messages_fatal(1, namespace=namespace)
156 end if
157 if (space%dim /= 3) then
158 write(message(1), '(a)') 'The output xc_torque can only be computed in the 3D case.'
159 call messages_fatal(1, namespace=namespace)
160 end if
161 end if
162 if (outp%what(option__output__mmb_den)) then
163 call messages_experimental("Model many-body density matrix", namespace=namespace)
164 ! NOTES:
165 ! could be made into block to be able to specify which dimensions to trace
166 ! in principle all combinations are interesting, but this means we need to
167 ! be able to output density matrices for multiple particles or multiple
168 ! dimensions. The current 1D 1-particle case is simple.
169 end if
170
171 if (outp%what(option__output__energy_density)) call messages_experimental("'Output = energy_density'", namespace=namespace)
172 if (outp%what(option__output__heat_current)) call messages_experimental("'Output = heat_current'", namespace=namespace)
173
174 if (outp%what(option__output__wfs) .or. outp%what(option__output__wfs_sqmod)) then
175
176 !%Variable OutputWfsNumber
177 !%Type string
178 !%Default all states
179 !%Section Output
180 !%Description
181 !% Which wavefunctions to print, in list form: <i>i.e.</i>, "1-5" to print the first
182 !% five states, "2,3" to print the second and the third state, etc.
183 !% If more states are specified than available, extra ones will be ignored.
184 !%End
185
186 write(nst_string,'(i6)') nst
187 write(default,'(a,a)') "1-", trim(adjustl(nst_string))
188 call parse_variable(namespace, 'OutputWfsNumber', default, outp%wfs_list)
189 end if
190
191 if (parse_block(namespace, 'CurrentThroughPlane', blk) == 0) then
192 if (.not. outp%what(option__output__j_flow)) then
193 outp%what(option__output__j_flow) = .true.
194 call parse_variable(namespace, 'OutputInterval', 50, outp%output_interval(option__output__j_flow))
195 end if
196
197 !%Variable CurrentThroughPlane
198 !%Type block
199 !%Section Output
200 !%Description
201 !% The code can calculate current
202 !% traversing a user-defined portion of a plane, as specified by this block.
203 !% A small plain-text file <tt>current-flow</tt> will be written containing this information.
204 !% Only available for 1D, 2D, or 3D.
205 !% In the format below, <tt>origin</tt> is a point in the plane.
206 !% <tt>u</tt> and <tt>v</tt> are the (dimensionless) vectors defining the plane;
207 !% they will be normalized. <tt>spacing</tt> is the fineness of the mesh
208 !% on the plane. Integers <tt>nu</tt> and <tt>mu</tt> are the length and
209 !% width of the portion of the plane, in units of <tt>spacing</tt>.
210 !% Thus, the grid points included in the plane are
211 !% <tt>x_ij = origin + i*spacing*u + j*spacing*v</tt>,
212 !% for <tt>nu <= i <= mu</tt> and <tt>nv <= j <= mv</tt>.
213 !% Analogously, in the 2D case, the current flow is calculated through a line;
214 !% in the 1D case, the current flow is calculated through a point. Note that the spacing
215 !% can differ from the one used in the main calculation; an interpolation will be performed.
216 !%
217 !% Example (3D):
218 !%
219 !% <tt>%CurrentThroughPlane
220 !% <br>&nbsp;&nbsp; 0.0 | 0.0 | 0.0 # origin
221 !% <br>&nbsp;&nbsp; 0.0 | 1.0 | 0.0 # u
222 !% <br>&nbsp;&nbsp; 0.0 | 0.0 | 1.0 # v
223 !% <br>&nbsp;&nbsp; 0.2 # spacing
224 !% <br>&nbsp;&nbsp; 0 | 50 # nu | mu
225 !% <br>&nbsp;&nbsp; -50 | 50 # nv | mv
226 !% <br>%</tt>
227 !%
228 !% Example (2D):
229 !%
230 !% <tt>%CurrentThroughPlane
231 !% <br>&nbsp;&nbsp; 0.0 | 0.0 # origin
232 !% <br>&nbsp;&nbsp; 1.0 | 0.0 # u
233 !% <br>&nbsp;&nbsp; 0.2 # spacing
234 !% <br>&nbsp;&nbsp; 0 | 50 # nu | mu
235 !% <br>%</tt>
236 !%
237 !% Example (1D):
238 !%
239 !% <tt>%CurrentThroughPlane
240 !% <br>&nbsp;&nbsp; 0.0 # origin
241 !% <br>%</tt>
242 !%
243 !%End
244
245 select case (space%dim)
246 case (3)
247
248 call parse_block_float(blk, 0, 0, outp%plane%origin(1), units_inp%length)
249 call parse_block_float(blk, 0, 1, outp%plane%origin(2), units_inp%length)
250 call parse_block_float(blk, 0, 2, outp%plane%origin(3), units_inp%length)
251 call parse_block_float(blk, 1, 0, outp%plane%u(1))
252 call parse_block_float(blk, 1, 1, outp%plane%u(2))
253 call parse_block_float(blk, 1, 2, outp%plane%u(3))
254 call parse_block_float(blk, 2, 0, outp%plane%v(1))
255 call parse_block_float(blk, 2, 1, outp%plane%v(2))
256 call parse_block_float(blk, 2, 2, outp%plane%v(3))
257 call parse_block_float(blk, 3, 0, outp%plane%spacing, units_inp%length)
258 call parse_block_integer(blk, 4, 0, outp%plane%nu)
259 call parse_block_integer(blk, 4, 1, outp%plane%mu)
260 call parse_block_integer(blk, 5, 0, outp%plane%nv)
261 call parse_block_integer(blk, 5, 1, outp%plane%mv)
262
263 norm = norm2(outp%plane%u(1:3))
264 if (norm < m_epsilon) then
265 write(message(1), '(a)') 'u-vector for CurrentThroughPlane cannot have norm zero.'
266 call messages_fatal(1, namespace=namespace)
267 end if
268 outp%plane%u(1:3) = outp%plane%u(1:3) / norm
269
270 norm = norm2(outp%plane%v(1:3))
271 if (norm < m_epsilon) then
272 write(message(1), '(a)') 'v-vector for CurrentThroughPlane cannot have norm zero.'
273 call messages_fatal(1, namespace=namespace)
274 end if
275 outp%plane%v(1:3) = outp%plane%v(1:3) / norm
276
277 outp%plane%n(1:3) = dcross_product(outp%plane%u(1:3), outp%plane%v(1:3))
278
279 case (2)
280
281 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
282 call parse_block_float(blk, 0, 1, outp%line%origin(2), units_inp%length)
283 call parse_block_float(blk, 1, 0, outp%line%u(1))
284 call parse_block_float(blk, 1, 1, outp%line%u(2))
285 call parse_block_float(blk, 2, 0, outp%line%spacing, units_inp%length)
286 call parse_block_integer(blk, 3, 0, outp%line%nu)
287 call parse_block_integer(blk, 3, 1, outp%line%mu)
288
289 norm = norm2(outp%line%u(1:2))
290 if (norm < m_epsilon) then
291 write(message(1), '(a)') 'u-vector for CurrentThroughPlane cannot have norm zero.'
292 call messages_fatal(1, namespace=namespace)
293 end if
294 outp%line%u(1:2) = outp%line%u(1:2) / norm
295
296 outp%line%n(1) = -outp%line%u(2)
297 outp%line%n(2) = outp%line%u(1)
298
299 case (1)
300
301 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
302
303 case default
304
305 call messages_not_implemented("CurrentThroughPlane for 4D or higher", namespace=namespace)
306
307 end select
308 call parse_block_end(blk)
309 end if
310
311 if (outp%what(option__output__matrix_elements)) then
312 call output_me_init(outp%me, namespace, space, st, gr, nst)
313 else
314 outp%me%what = .false.
315 end if
316
317 if (outp%what(option__output__berkeleygw)) then
318 if (accel_is_enabled()) then
319 message(1) = "BerkeleyGW is not compatible with GPUs."
320 call messages_fatal(1, namespace=namespace)
321 end if
322 call output_berkeleygw_init(nst, namespace, outp%bgw, space%periodic_dim)
323 end if
324
325 ! required for output_hamiltonian()
326 if (outp%what(option__output__potential_gradient) .and. .not. outp%what(option__output__potential)) then
327 outp%what(option__output__potential) = .true.
328 outp%output_interval(option__output__potential) = outp%output_interval(option__output__potential_gradient)
329 end if
330
331
332 !%Variable OutputDuringSCF
333 !%Type logical
334 !%Default no
335 !%Section Output
336 !%Description
337 !% During <tt>gs</tt> and <tt>unocc</tt> runs, if this variable is set to yes,
338 !% output will be written after every <tt>OutputInterval</tt> iterations.
339 !%End
340 call parse_variable(namespace, 'OutputDuringSCF', .false., outp%duringscf)
341
342 if (parse_is_defined(namespace, 'RestartWriteInterval')) then
343 write(message(1), '(a)') 'Input variable RestartWriteInterval is obsolete.'
344 write(message(2), '(a)') 'Restart files are now written in periods of the wallclock time'
345 write(message(3), '(a)') 'given by RestartWallTimePeriod, so you can simply delete this variable.'
346 call messages_fatal(3, only_root_writes=.true., namespace=namespace)
347 end if
348
349 !%Variable OutputIterDir
350 !%Default "output_iter"
351 !%Type string
352 !%Section Output
353 !%Description
354 !% The name of the directory where <tt>Octopus</tt> stores information
355 !% such as the density, forces, etc. requested by variable <tt>Output</tt>
356 !% in the format specified by <tt>OutputFormat</tt>.
357 !% This information is written while iterating <tt>CalculationMode = gs</tt>, <tt>unocc</tt>, or <tt>td</tt>,
358 !% according to <tt>OutputInterval</tt>, and has nothing to do with the restart information.
359 !%End
360 call parse_variable(namespace, 'OutputIterDir', "output_iter", outp%iter_dir)
361 if (any(outp%what) .and. any(outp%output_interval > 0)) then
362 call io_mkdir(outp%iter_dir, namespace)
363 end if
364 call add_last_slash(outp%iter_dir)
365
366 ! At this point, we don`t know whether the states will be real or complex.
367 ! We therefore pass .false. to states_are_real, and need to check for real states later.
368
369 if (output_needs_current(outp, .false.)) then
370 call v_ks_calculate_current(ks, .true.)
371 else
372 call v_ks_calculate_current(ks, .false.)
373 end if
374
375 if (outp%what(option__output__current_dia)) then
376 message(1) = "The diamagnetic current will be calculated only if CalculateDiamagneticCurrent = yes."
377 call messages_warning(1, namespace=namespace)
378 end if
379
380 pop_sub(output_init)
381 end subroutine output_init
382
383 ! ---------------------------------------------------------
384 subroutine output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
385 type(output_t), intent(in) :: outp
386 type(namespace_t), intent(in) :: namespace
387 class(space_t), intent(in) :: space
388 character(len=*), intent(in) :: dir
389 type(grid_t), intent(in) :: gr
390 type(ions_t), intent(in) :: ions
391 integer, intent(in) :: iter
392 type(states_elec_t), intent(inout) :: st
393 type(hamiltonian_elec_t), intent(inout) :: hm
394 type(v_ks_t), intent(inout) :: ks
395
396 integer :: idir, ierr, iunit
397 character(len=MAX_PATH_LEN) :: fname
398
399 push_sub(output_all)
400 call profiling_in("OUTPUT_ALL")
401
402 if (any(outp%what)) then
403 message(1) = "Info: Writing output to " // trim(dir)
404 call messages_info(1, namespace=namespace)
405 call io_mkdir(dir, namespace)
406 end if
407
408 if (outp%what_now(option__output__mesh_r, iter)) then
409 do idir = 1, space%dim
410 write(fname, '(a,a)') 'mesh_r-', index2axis(idir)
411 call dio_function_output(outp%how(option__output__mesh_r), dir, fname, namespace, space, &
412 gr, gr%x_t(:,idir), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
413 end do
414 end if
415
416 call output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
417 call output_hamiltonian(outp, namespace, space, dir, hm, st, gr%der, ions, gr, iter, st%st_kpt_mpi_grp)
418
419 ! We can only test against the theory level here, as it is not set in the call of output_init().
420 if (outp%what_now(option__output__el_pressure, iter)) then
421 if(ks%theory_level /= kohn_sham_dft) then
422 call messages_not_implemented("el_pressure for TheoryLevel different from kohn_sham", namespace=namespace)
423 end if
424 if (st%d%spin_channels > 1) then
425 call messages_not_implemented("el_pressure for spin-polarized or spinors", namespace=namespace)
426 end if
427 end if
428
429 !hm not initialized yet when calling output_init()
430 if (outp%what(option__output__kanamoriu) .and. hm%lda_u_level /= dft_u_acbn0) then
431 message(1) = "kanamoriU output can only be computed for DFTULevel = dft_u_acbn0"
432 call messages_fatal(1, namespace=namespace)
433 end if
434
435
436 call output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
437
438 if (outp%what_now(option__output__j_flow, iter)) then
439 call output_current_flow(outp, namespace, space, dir, gr, st, hm%kpoints)
440 end if
441
442 if (outp%what_now(option__output__geometry, iter)) then
443 if (bitand(outp%how(option__output__geometry), option__outputformat__xcrysden) /= 0) then
444 call write_xsf_geometry_file(dir, "geometry", space, ions%latt, ions%pos, ions%atom, gr, namespace)
445 end if
446 if (bitand(outp%how(option__output__geometry), option__outputformat__xyz) /= 0) then
447 call ions%write_xyz(trim(dir)//'/geometry')
448 if (ions%space%is_periodic()) then
449 call ions%write_crystal(dir)
450 end if
451 end if
452 if (bitand(outp%how(option__output__geometry), option__outputformat__vtk) /= 0) then
453 call ions%write_vtk_geometry(trim(dir)//'/geometry')
454 end if
455 if (bitand(outp%how(option__output__geometry), option__outputformat__poscar) /= 0) then
456 call ions%write_poscar(trim(dir)//'/POSCAR')
457 end if
458 end if
459
460 if (outp%what_now(option__output__forces, iter)) then
461 if (bitand(outp%how(option__output__forces), option__outputformat__bild) /= 0) then
462 call ions%write_bild_forces_file(dir, "forces")
463 else
464 call write_xsf_geometry_file(dir, "forces", space, ions%latt, ions%pos, ions%atom, &
465 gr, namespace, total_forces = ions%tot_force)
466 end if
467 end if
468
469 if (outp%what_now(option__output__matrix_elements, iter)) then
470 call output_me(outp%me, namespace, space, dir, st, gr, ions, hm)
471 end if
472
473 if (outp%what_now(option__output__berkeleygw, iter)) then
474 call output_berkeleygw(outp%bgw, namespace, space, dir, st, gr, ks, hm, ions)
475 end if
476
477 if (outp%what_now(option__output__energy_density, iter)) then
478 call output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
479 end if
480
481 if (outp%what_now(option__output__stress, iter)) then
482 call io_mkdir(dir, namespace)
483 iunit = io_open(trim(dir)//'/stress', namespace, action='write')
484 call output_stress(iunit, space%periodic_dim, st%stress_tensors)
485 call io_close(iunit)
486 end if
487
488 if (hm%lda_u_level /= dft_u_none) then
489 if (outp%what_now(option__output__occ_matrices, iter))&
490 call lda_u_write_occupation_matrices(dir, hm%lda_u, st, namespace)
491
492 if (outp%what_now(option__output__effectiveu, iter))&
493 call lda_u_write_effectiveu(dir, hm%lda_u, st, namespace)
494
495 if (outp%what_now(option__output__magnetization, iter))&
496 call lda_u_write_magnetization(dir, hm%lda_u, ions, gr, st, namespace)
497
498 if (outp%what_now(option__output__local_orbitals, iter))&
499 call output_dftu_orbitals(outp, dir, namespace, space, hm%lda_u, st, gr, ions, hm%phase%is_allocated())
500
501 if (outp%what_now(option__output__kanamoriu, iter))&
502 call lda_u_write_kanamoriu(dir, st, hm%lda_u, namespace)
503
504 if (ks%v_ks_photons%oep_full()) then
505 if (outp%what_now(option__output__photon_correlator, iter)) then
506 write(fname, '(a)') 'photon_correlator'
507 call dio_function_output(outp%how(option__output__photon_correlator), dir, trim(fname), namespace, space, &
508 gr, ks%v_ks_photons%correlator(), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
509 end if
510 end if
511 end if
512
513 ! We can only test against the theory level here, as it is not set in the call of output_init().
514 if (outp%what_now(option__output__xc_torque, iter)) then
515 if (ks%theory_level /= kohn_sham_dft .and. ks%theory_level /= generalized_kohn_sham_dft) then
516 write(message(1), '(a)') 'The output xc_torque can only be computed when there is a xc potential.'
517 call messages_fatal(1, namespace=namespace)
518 end if
519 end if
520
521 call output_xc_torque(outp, namespace, dir, gr, hm, st, ions, ions%space)
522
523 call profiling_out("OUTPUT_ALL")
524 pop_sub(output_all)
525 end subroutine output_all
526
527
528 ! ---------------------------------------------------------
529 subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
530 type(output_t), intent(in) :: outp
531 type(namespace_t), intent(in) :: namespace
532 class(space_t), intent(in) :: space
533 character(len=*), intent(in) :: dir
534 type(states_elec_t), intent(inout) :: st
535 type(hamiltonian_elec_t), intent(in) :: hm
536 type(grid_t), intent(in) :: gr
537 type(ions_t), intent(in) :: ions
538 integer, intent(in) :: iter
539
540 real(real64), allocatable :: f_loc(:,:)
541 character(len=MAX_PATH_LEN) :: fname
542 integer :: is, ierr, imax
543 type(mpi_grp_t) :: mpi_grp
544
546
547 mpi_grp = st%dom_st_kpt_mpi_grp
548
549 ! if SPIN_POLARIZED or SPINORS, the ELF contains one extra channel: the total ELF
550 imax = 1
551 if (st%d%ispin /= unpolarized) imax = 3
552
553 safe_allocate(f_loc(1:gr%np, 1:max(imax, st%d%nspin)))
554
555 ! First the ELF in real space
556 if (outp%what_now(option__output__elf, iter) .or. outp%what_now(option__output__elf_basins, iter)) then
557 assert(space%dim /= 1)
558
559 call elf_calc(space, st, gr, hm%kpoints, f_loc(:, 1:imax))
560
561 ! output ELF in real space
562 if (outp%what_now(option__output__elf, iter)) then
563 write(fname, '(a)') 'elf_rs'
564 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
565 f_loc(:,imax), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
566 ! this quantity is dimensionless
567
568 if (st%d%ispin /= unpolarized) then
569 do is = 1, 2
570 write(fname, '(a,i1)') 'elf_rs-sp', is
571 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
572 f_loc(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
573 ! this quantity is dimensionless
574 end do
575 end if
576 end if
577
578 if (outp%what_now(option__output__elf_basins, iter)) then
579 call out_basins(f_loc(:,imax), "elf_rs_basins", outp%how(option__output__elf_basins))
580 end if
581 end if
582
583 ! Now Bader analysis
584 if (outp%what_now(option__output__bader, iter)) then
585 do is = 1, st%d%nspin
586 call dderivatives_lapl(gr%der, st%rho(:,is), f_loc(:,is))
587
588 fname = get_filename_with_spin('bader', st%d%nspin, is)
589
590 call dio_function_output(outp%how(option__output__bader), dir, trim(fname), namespace, space, gr, &
591 f_loc(:,is), units_out%length**(-2 - space%dim), ierr, &
592 pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
593
594 fname = get_filename_with_spin('bader_basins', st%d%nspin, is)
595 call out_basins(f_loc(:, is), fname, outp%how(option__output__bader))
596 end do
597 end if
598
599 ! Now the pressure
600 if (outp%what_now(option__output__el_pressure, iter)) then
601 call calc_electronic_pressure(st, hm, gr, f_loc(:,1))
602 call dio_function_output(outp%how(option__output__el_pressure), dir, "el_pressure", namespace, space, gr, &
603 f_loc(:,1), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
604 ! this quantity is dimensionless
605 end if
606
607 safe_deallocate_a(f_loc)
608
610
611 contains
612 ! ---------------------------------------------------------
613 subroutine out_basins(ff, filename, output_how)
614 real(real64), contiguous, intent(in) :: ff(:)
615 character(len=*), intent(in) :: filename
616 integer(int64), intent(in) :: output_how
617
618 character(len=MAX_PATH_LEN) :: fname
619 type(basins_t) :: basins
620 integer :: iunit
621
623
624 call basins_init(basins, namespace, gr)
625 call basins_analyze(basins, namespace, gr, ff(:), st%rho(:, 1:st%d%spin_channels), 0.01_real64)
626
627 call dio_function_output(output_how, dir, trim(filename), namespace, space, gr, &
628 real(basins%map, real64) , unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
629 ! this quantity is dimensionless
630
631 write(fname,'(4a)') trim(dir), '/', trim(filename), '.info'
632 iunit = io_open(trim(fname), namespace, action = 'write')
633 call basins_write(basins, gr, iunit)
634 call io_close(iunit)
635
636 call basins_end(basins)
637
639 end subroutine out_basins
640
641 end subroutine output_localization_funct
642
643
644 ! ---------------------------------------------------------
645 subroutine calc_electronic_pressure(st, hm, gr, pressure)
646 type(states_elec_t), intent(inout) :: st
647 type(hamiltonian_elec_t), intent(in) :: hm
648 type(grid_t), intent(in) :: gr
649 real(real64), contiguous, intent(out) :: pressure(:)
650
651 real(real64), allocatable :: rho(:,:), lrho(:), tau(:,:)
652 real(real64) :: p_tf, dens
653 integer :: is, ii
654
656
657 safe_allocate( rho(1:gr%np_part, 1:st%d%nspin))
658 safe_allocate(lrho(1:gr%np))
659 safe_allocate( tau(1:gr%np, 1:st%d%nspin))
660
661 rho = m_zero
662 call density_calc(st, gr, rho)
663 call states_elec_calc_quantities(gr, st, hm%kpoints, .false., kinetic_energy_density = tau)
664
665 pressure = m_zero
666 do is = 1, st%d%spin_channels
667 lrho = m_zero
668 call dderivatives_lapl(gr%der, rho(:, is), lrho)
669
670 pressure(:) = pressure(:) + &
671 tau(:, is)/m_three - lrho(:)/m_four
672 end do
673
674 do ii = 1, gr%np
675 dens = sum(rho(ii,1:st%d%spin_channels))
676
677 p_tf = m_two/m_five*(m_three*m_pi**2)**(m_two/m_three)* &
678 dens**(m_five/m_three)
679
680 ! add XC pressure
681 ! FIXME: Not correct for spinors and spin-polarized here
682 pressure(ii) = pressure(ii) + (dens*hm%ks_pot%vxc(ii,1) - hm%energy%exchange - hm%energy%correlation)
683
684 pressure(ii) = pressure(ii)/p_tf
685 pressure(ii) = m_half*(m_one + pressure(ii)/sqrt(m_one + pressure(ii)**2))
686 end do
687
689 end subroutine calc_electronic_pressure
690
691
692 ! ---------------------------------------------------------
693 subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
694 type(output_t), intent(in) :: outp
695 type(namespace_t), intent(in) :: namespace
696 class(space_t), intent(in) :: space
697 character(len=*), intent(in) :: dir
698 type(hamiltonian_elec_t), intent(in) :: hm
699 type(v_ks_t), intent(inout) :: ks
700 type(states_elec_t), intent(in) :: st
701 type(ions_t), intent(in) :: ions
702 type(grid_t), intent(in) :: gr
703
704 integer :: is, ierr, ip
705 character(len=MAX_PATH_LEN) :: fname
706 type(unit_t) :: fn_unit
707 real(real64), allocatable :: energy_density(:, :)
708 real(real64), allocatable :: ex_density(:)
709 real(real64), allocatable :: ec_density(:)
710 real(real64) :: xc_energy
711
712 push_sub(output_energy_density)
713
714 fn_unit = units_out%energy*units_out%length**(-space%dim)
715 safe_allocate(energy_density(1:gr%np, 1:st%d%nspin))
716
717 ! the kinetic energy density
718 call states_elec_calc_quantities(gr, st, hm%kpoints, .true., kinetic_energy_density = energy_density)
719
720 ! the external potential energy density
721 do is = 1, st%d%spin_channels
722 do ip = 1, gr%np
723 energy_density(ip, is) = energy_density(ip, is) + st%rho(ip, is)*hm%ep%vpsl(ip)
724 end do
725 end do
726
727 ! the hartree energy density
728 do is = 1, st%d%spin_channels
729 do ip = 1, gr%np
730 energy_density(ip, is) = energy_density(ip, is) + m_half*st%rho(ip, is)*hm%ks_pot%vhartree(ip)
731 end do
732 end do
733
734 ! the XC energy density
735 safe_allocate(ex_density(1:gr%np))
736 safe_allocate(ec_density(1:gr%np))
737
738 call xc_get_vxc(gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, st%rho, st%d%ispin, &
739 hm%ions%latt%rcell_volume, ex_density = ex_density, ec_density = ec_density)
740 !$omp parallel do private(ip, is, xc_energy)
741 do ip = 1, gr%np
742 xc_energy = ex_density(ip) + ec_density(ip)
743 do is = 1, st%d%spin_channels
744 energy_density(ip, is) = energy_density(ip, is) + xc_energy
745 end do
746 end do
747
748 safe_deallocate_a(ex_density)
749 safe_deallocate_a(ec_density)
750
751 do is = 1, st%d%spin_channels
752 fname = get_filename_with_spin('energy_density', st%d%nspin, is)
753 call dio_function_output(outp%how(option__output__energy_density), dir, trim(fname), namespace, space, gr, &
754 energy_density(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
755 end do
756 safe_deallocate_a(energy_density)
757
758 pop_sub(output_energy_density)
759 end subroutine output_energy_density
760
761 !--------------------------------------------------------------
762
763 logical function output_need_exchange(outp) result(need_exx)
764 type(output_t), intent(in) :: outp
765
766 need_exx =(outp%what(option__output__berkeleygw) &
767 .or. outp%me%what(option__outputmatrixelements__two_body) &
768 .or. outp%me%what(option__outputmatrixelements__two_body_exc_k))
769 end function output_need_exchange
770
771
772 ! ---------------------------------------------------------
773 subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
774 type(output_t), intent(in) :: outp
775 character(len=*), intent(in) :: dir
776 type(namespace_t), intent(in) :: namespace
777 class(space_t), intent(in) :: space
778 type(lda_u_t), intent(in) :: this
779 type(states_elec_t), intent(in) :: st
780 class(mesh_t), intent(in) :: mesh
781 type(ions_t), intent(in) :: ions
782 logical, intent(in) :: has_phase
783
784 integer :: ios, im, ik, idim, ierr
785 complex(real64), allocatable :: tmp(:)
786 real(real64), allocatable :: dtmp(:)
787 type(orbitalset_t), pointer :: os
788 type(unit_t) :: fn_unit
789 character(len=MAX_PATH_LEN) :: fname
790
791 push_sub(output_dftu_orbitals)
792
793 fn_unit = sqrt(units_out%length**(-space%dim))
794
795 if (this%basis%use_submesh) then
796 if (states_are_real(st)) then
797 safe_allocate(dtmp(1:mesh%np))
798 else
799 safe_allocate(tmp(1:mesh%np))
800 end if
801 end if
802
803 do ios = 1, this%norbsets
804 os => this%orbsets(ios)
805 do ik = st%d%kpt%start, st%d%kpt%end
806 do im = 1, this%orbsets(ios)%norbs
807 do idim = 1, min(os%ndim, st%d%dim)
808 if (st%nik > 1) then
809 if (min(os%ndim, st%d%dim) > 1) then
810 write(fname, '(a,i1,a,i3.3,a,i8.8,a,i1)') 'orb', im, '-os', ios, '-k', ik, '-sp', idim
811 else
812 write(fname, '(a,i1,a,i3.3,a,i8.8)') 'orb', im, '-os', ios, '-k', ik
813 end if
814 else
815 if (min(os%ndim, st%d%dim) > 1) then
816 write(fname, '(a,i1,a,i3.3,a,i1)') 'orb', im, '-os', ios, '-sp', idim
817 else
818 write(fname, '(a,i1,a,i3.3)') 'orb', im, '-os', ios
819 end if
820 end if
821 if (has_phase) then
822 if (.not. this%basis%use_submesh) then
823 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
824 mesh, os%eorb_mesh(1:mesh%np,im,idim,ik), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
825 else
826 tmp = m_z0
827 call submesh_add_to_mesh(os%sphere, os%eorb_submesh(1:os%sphere%np,idim,im,ik), tmp)
828 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
829 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
830 end if
831 else
832 if (.not. this%basis%use_submesh) then
833 if (states_are_real(st)) then
834 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
835 os%dorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
836 else
837 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
838 os%zorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
839 end if
840 else
841 if (states_are_real(st)) then
842 dtmp = m_zero
843 call submesh_add_to_mesh(os%sphere, os%dorb(1:os%sphere%np,idim,im), dtmp)
844 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
845 mesh, dtmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
846 else
847 tmp = m_z0
848 call submesh_add_to_mesh(os%sphere, os%zorb(1:os%sphere%np,idim,im), tmp)
849 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
850 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
851 end if
852 end if
853 end if
854 end do
855 end do
856 end do
857 end do
859 safe_deallocate_a(tmp)
860 safe_deallocate_a(dtmp)
861
862 pop_sub(output_dftu_orbitals)
863 end subroutine output_dftu_orbitals
864
865 ! ---------------------------------------------------------
866 logical function output_needs_current(outp, states_are_real)
867 type(output_t), intent(in) :: outp
868 logical, intent(in) :: states_are_real
869
870 output_needs_current = .false.
871
872 if (outp%what(option__output__current) &
873 .or. outp%what(option__output__current_dia) &
874 .or. outp%what(option__output__heat_current) &
875 .or. outp%what(option__output__current_kpt)) then
876 if (.not. states_are_real) then
878 else
879 message(1) = 'No current density output for real states since it is identically zero.'
880 call messages_warning(1)
881 end if
882 end if
883
884
885 end function
886
887#include "output_states_inc.F90"
888
889#include "output_h_inc.F90"
890
891#include "undef.F90"
892#include "complex.F90"
893#include "output_linear_response_inc.F90"
894
895#include "undef.F90"
896#include "real.F90"
897#include "output_linear_response_inc.F90"
898
899end module output_oct_m
900
901!! Local Variables:
902!! mode: f90
903!! coding: utf-8
904!! End:
pure logical function, public accel_is_enabled()
Definition: accel.F90:414
subroutine, public basins_write(this, mesh, iunit)
Definition: basins.F90:354
subroutine, public basins_init(this, namespace, mesh)
Definition: basins.F90:153
subroutine, public basins_analyze(this, namespace, mesh, f, rho, threshold)
Definition: basins.F90:190
subroutine, public basins_end(this)
Definition: basins.F90:172
This module implements a calculator for the density and defines related functions.
Definition: density.F90:122
subroutine, public density_calc(st, gr, density, istin)
Computes the density from the orbitals in st.
Definition: density.F90:653
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh function
Module that handles computing and output of various density of states.
Definition: dos.F90:118
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
subroutine, public elf_calc(space, st, gr, kpoints, elf, de)
(time-dependent) electron localization function, (TD)ELF.
Definition: elf.F90:169
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:120
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
real(real64), parameter, public m_four
Definition: global.F90:204
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:198
complex(real64), parameter, public m_z0
Definition: global.F90:210
integer, parameter, public generalized_kohn_sham_dft
Definition: global.F90:250
integer, parameter, public kohn_sham_dft
Definition: global.F90:250
real(real64), parameter, public m_epsilon
Definition: global.F90:216
real(real64), parameter, public m_half
Definition: global.F90:206
real(real64), parameter, public m_one
Definition: global.F90:201
real(real64), parameter, public m_three
Definition: global.F90:203
real(real64), parameter, public m_five
Definition: global.F90:205
This module implements the underlying real-space grid.
Definition: grid.F90:119
This module defines classes and functions for interaction partners.
subroutine, public zio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
subroutine, public io_function_read_what_how_when(namespace, space, what, how, output_interval, what_tag_in, how_tag_in, output_interval_tag_in, ignore_error)
subroutine, public dio_function_output(how, dir, fname, namespace, space, mesh, ff, unit, ierr, pos, atoms, grp, root)
Top-level IO routine for functions defined on the mesh.
subroutine, public write_xsf_geometry_file(dir, fname, space, latt, pos, atoms, mesh, namespace, total_forces)
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
subroutine, public io_mkdir(fname, namespace, parents)
Definition: io.F90:361
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
A module to handle KS potential, without the external potential.
subroutine, public lda_u_write_occupation_matrices(dir, this, st, namespace)
Prints the occupation matrices at the end of the scf calculation.
Definition: lda_u_io.F90:158
subroutine, public lda_u_write_kanamoriu(dir, st, this, namespace)
Definition: lda_u_io.F90:352
subroutine, public lda_u_write_effectiveu(dir, this, st, namespace)
Definition: lda_u_io.F90:266
subroutine, public lda_u_write_magnetization(dir, this, ions, mesh, st, namespace)
Definition: lda_u_io.F90:480
integer, parameter, public dft_u_none
Definition: lda_u.F90:205
integer, parameter, public dft_u_acbn0
Definition: lda_u.F90:205
System information (time, memory, sysname)
Definition: loct.F90:117
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
pure real(real64) function, dimension(1:3), public dcross_product(a, b)
Definition: math.F90:1909
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
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 messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1040
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
subroutine, public output_berkeleygw(bgw, namespace, space, dir, st, gr, ks, hm, ions)
subroutine, public output_berkeleygw_init(nst, namespace, bgw, periodic_dim)
this module contains the low-level part of the output system
Definition: output_low.F90:117
character(len=max_path_len) function, public get_filename_with_spin(output, nspin, spin_index)
Returns the filame as output, or output-spX is spin polarized.
Definition: output_low.F90:233
subroutine, public output_me_init(this, namespace, space, st, gr, nst)
Definition: output_me.F90:157
subroutine, public output_me(this, namespace, space, dir, st, gr, ions, hm)
Definition: output_me.F90:288
this module contains the output system
Definition: output.F90:117
subroutine calc_electronic_pressure(st, hm, gr, pressure)
Definition: output.F90:741
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
Definition: output.F90:1003
subroutine, public output_scalar_pot(outp, namespace, space, dir, mesh, ions, ext_partners, grp, time)
Definition: output.F90:1595
logical function, public output_needs_current(outp, states_are_real)
Definition: output.F90:962
subroutine, public output_hamiltonian(outp, namespace, space, dir, hm, st, der, ions, gr, iter, grp)
Definition: output.F90:1311
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:480
logical function, public output_need_exchange(outp)
Definition: output.F90:859
subroutine, public output_init(outp, namespace, space, st, gr, nst, ks)
Definition: output.F90:207
subroutine output_xc_torque(outp, namespace, dir, mesh, hm, st, ions, space)
Definition: output.F90:1633
subroutine, public output_current_flow(outp, namespace, space, dir, gr, st, kpoints)
Definition: output.F90:1201
subroutine, public zoutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
Definition: output.F90:1740
subroutine, public doutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
Definition: output.F90:1978
subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
Definition: output.F90:789
subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
Definition: output.F90:869
subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
Definition: output.F90:625
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:463
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:623
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
pure logical function, public states_are_real(st)
This module defines routines to write information about states.
subroutine, public states_elec_calc_quantities(gr, st, kpoints, nlcc, kinetic_energy_density, paramagnetic_current, density_gradient, density_laplacian, gi_kinetic_energy_density, st_end)
calculated selected quantities
This module implements the calculation of the stress tensor.
Definition: stress.F90:120
subroutine, public output_stress(iunit, space_dim, stress_tensors, all_terms)
Definition: stress.F90:1187
subroutine, public add_last_slash(str)
Adds a '/' in the end of the string, only if it missing. Useful for directories.
Definition: string.F90:162
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_system_t), public units_inp
the units systems for reading and writing
type(unit_t), public unit_one
some special units required for particular quantities
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:120
character pure function, public index2axis(idir)
Definition: utils.F90:211
subroutine, public v_ks_calculate_current(this, calc_cur)
Definition: v_ks.F90:1479
Definition: xc.F90:120
subroutine, public xc_get_vxc(gr, xcs, st, kpoints, psolver, namespace, space, rho, ispin, rcell_volume, vxc, ex, ec, deltaxc, vtau, ex_density, ec_density, stress_xc, force_orbitalfree, force_host)
Definition: xc_vxc.F90:191
subroutine out_basins(ff, filename, output_how)
Definition: output.F90:709
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:171
Class to describe DFT+U parameters.
Definition: lda_u.F90:218
Describes mesh distribution to nodes.
Definition: mesh.F90:187
This is defined even when running serial.
Definition: mpi.F90:144
Output information for BerkeleyGW.
Definition: output_low.F90:147
output handler class
Definition: output_low.F90:166
The states_elec_t class contains all electronic wave functions.
int true(void)