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