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 xc_oct_m
91 use xc_oep_oct_m
93 use xc_f03_lib_m
94 use xc_vxc_oct_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:3) = dcross_product(outp%plane%u(1:3), outp%plane%v(1:3))
284
285 case (2)
286
287 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
288 call parse_block_float(blk, 0, 1, outp%line%origin(2), units_inp%length)
289 call parse_block_float(blk, 1, 0, outp%line%u(1))
290 call parse_block_float(blk, 1, 1, outp%line%u(2))
291 call parse_block_float(blk, 2, 0, outp%line%spacing, units_inp%length)
292 call parse_block_integer(blk, 3, 0, outp%line%nu)
293 call parse_block_integer(blk, 3, 1, outp%line%mu)
294
295 norm = norm2(outp%line%u(1:2))
296 if (norm < m_epsilon) then
297 write(message(1), '(a)') 'u-vector for CurrentThroughPlane cannot have norm zero.'
298 call messages_fatal(1, namespace=namespace)
299 end if
300 outp%line%u(1:2) = outp%line%u(1:2) / norm
301
302 outp%line%n(1) = -outp%line%u(2)
303 outp%line%n(2) = outp%line%u(1)
304
305 case (1)
306
307 call parse_block_float(blk, 0, 0, outp%line%origin(1), units_inp%length)
308
309 case default
310
311 call messages_not_implemented("CurrentThroughPlane for 4D or higher", namespace=namespace)
312
313 end select
314 call parse_block_end(blk)
315 end if
316
317 if (outp%what(option__output__matrix_elements)) then
318 call output_me_init(outp%me, namespace, space, st, gr, nst)
319 else
320 outp%me%what = .false.
321 end if
322
323 if (outp%what(option__output__berkeleygw)) then
324 if (accel_is_enabled()) then
325 message(1) = "BerkeleyGW is not compatible with GPUs."
326 call messages_fatal(1, namespace=namespace)
327 end if
328 call output_berkeleygw_init(nst, namespace, outp%bgw, space%periodic_dim)
329 end if
330
331 ! required for output_hamiltonian()
332 if (outp%what(option__output__potential_gradient) .and. .not. outp%what(option__output__potential)) then
333 outp%what(option__output__potential) = .true.
334 outp%output_interval(option__output__potential) = outp%output_interval(option__output__potential_gradient)
335 end if
336
337
338 !%Variable OutputDuringSCF
339 !%Type logical
340 !%Default no
341 !%Section Output
342 !%Description
343 !% During <tt>gs</tt> and <tt>unocc</tt> runs, if this variable is set to yes,
344 !% output will be written after every <tt>OutputInterval</tt> iterations.
345 !%End
346 call parse_variable(namespace, 'OutputDuringSCF', .false., outp%duringscf)
347
348 if (parse_is_defined(namespace, 'RestartWriteInterval')) then
349 write(message(1), '(a)') 'Input variable RestartWriteInterval is obsolete.'
350 write(message(2), '(a)') 'Restart files are now written in periods of the wallclock time'
351 write(message(3), '(a)') 'given by RestartWallTimePeriod, so you can simply delete this variable.'
352 call messages_fatal(3, only_root_writes=.true., namespace=namespace)
353 end if
354
355 !%Variable OutputIterDir
356 !%Default "output_iter"
357 !%Type string
358 !%Section Output
359 !%Description
360 !% The name of the directory where <tt>Octopus</tt> stores information
361 !% such as the density, forces, etc. requested by variable <tt>Output</tt>
362 !% in the format specified by <tt>OutputFormat</tt>.
363 !% This information is written while iterating <tt>CalculationMode = gs</tt>, <tt>unocc</tt>, or <tt>td</tt>,
364 !% according to <tt>OutputInterval</tt>, and has nothing to do with the restart information.
365 !%End
366 call parse_variable(namespace, 'OutputIterDir', "output_iter", outp%iter_dir)
367 if (any(outp%what) .and. any(outp%output_interval > 0)) then
368 call io_mkdir(outp%iter_dir, namespace)
369 end if
370 call add_last_slash(outp%iter_dir)
371
372 ! At this point, we don`t know whether the states will be real or complex.
373 ! We therefore pass .false. to states_are_real, and need to check for real states later.
374
375 if (output_needs_current(outp, .false.)) then
376 call v_ks_calculate_current(ks, .true.)
377 else
378 call v_ks_calculate_current(ks, .false.)
379 end if
380
381 if (outp%what(option__output__current_dia)) then
382 message(1) = "The diamagnetic current will be calculated only if CalculateDiamagneticCurrent = yes."
383 call messages_warning(1, namespace=namespace)
384 end if
385
386#ifndef HAVE_ETSF_IO
387 do iout = lbound(outp%how, 1), ubound(outp%how, 1)
388 if (bitand(outp%how(iout), option__outputformat__etsf) /= 0) then
389 message(1) = "ETSF output can only be used if Octopus is compiled with ETSF-IO"
390 call messages_fatal(1, namespace=namespace)
391 end if
392 end do
393#endif
394
395 pop_sub(output_init)
396 end subroutine output_init
397
398 ! ---------------------------------------------------------
399 subroutine output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
400 type(output_t), intent(in) :: outp
401 type(namespace_t), intent(in) :: namespace
402 class(space_t), intent(in) :: space
403 character(len=*), intent(in) :: dir
404 type(grid_t), intent(in) :: gr
405 type(ions_t), intent(in) :: ions
406 integer, intent(in) :: iter
407 type(states_elec_t), intent(inout) :: st
408 type(hamiltonian_elec_t), intent(inout) :: hm
409 type(v_ks_t), intent(inout) :: ks
410
411 integer :: idir, ierr, iout, iunit
412 character(len=MAX_PATH_LEN) :: fname
413
414 push_sub(output_all)
415 call profiling_in("OUTPUT_ALL")
416
417 if (any(outp%what)) then
418 message(1) = "Info: Writing output to " // trim(dir)
419 call messages_info(1, namespace=namespace)
420 call io_mkdir(dir, namespace)
421 end if
422
423 if (outp%what_now(option__output__mesh_r, iter)) then
424 do idir = 1, space%dim
425 write(fname, '(a,a)') 'mesh_r-', index2axis(idir)
426 call dio_function_output(outp%how(option__output__mesh_r), dir, fname, namespace, space, &
427 gr, gr%x_t(:,idir), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
428 end do
429 end if
430
431 call output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
432 call output_hamiltonian(outp, namespace, space, dir, hm, st, gr%der, ions, gr, iter, st%st_kpt_mpi_grp)
433
434 ! We can only test against the theory level here, as it is not set in the call of output_init().
435 if (outp%what_now(option__output__el_pressure, iter)) then
436 if(ks%theory_level /= kohn_sham_dft) then
437 call messages_not_implemented("el_pressure for TheoryLevel different from kohn_sham", namespace=namespace)
438 end if
439 if (st%d%spin_channels > 1) then
440 call messages_not_implemented("el_pressure for spin-polarized or spinors", namespace=namespace)
441 end if
442 end if
443
444 !hm not initialized yet when calling output_init()
445 if (outp%what(option__output__kanamoriu) .and. hm%lda_u_level /= dft_u_acbn0) then
446 message(1) = "kanamoriU output can only be computed for DFTULevel = dft_u_acbn0"
447 call messages_fatal(1, namespace=namespace)
448 end if
449
450
451 call output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
452
453 if (outp%what_now(option__output__j_flow, iter)) then
454 call output_current_flow(outp, namespace, space, dir, gr, st, hm%kpoints)
455 end if
456
457 if (outp%what_now(option__output__geometry, iter)) then
458 if (bitand(outp%how(option__output__geometry), option__outputformat__xcrysden) /= 0) then
459 call write_xsf_geometry_file(dir, "geometry", space, ions%latt, ions%pos, ions%atom, gr, namespace)
460 end if
461 if (bitand(outp%how(option__output__geometry), option__outputformat__xyz) /= 0) then
462 call ions%write_xyz(trim(dir)//'/geometry')
463 if (ions%space%is_periodic()) then
464 call ions%write_crystal(dir)
465 end if
466 end if
467 if (bitand(outp%how(option__output__geometry), option__outputformat__vtk) /= 0) then
468 call ions%write_vtk_geometry(trim(dir)//'/geometry')
469 end if
470 if (bitand(outp%how(option__output__geometry), option__outputformat__poscar) /= 0) then
471 call ions%write_poscar(trim(dir)//'/POSCAR')
472 end if
473 end if
474
475 if (outp%what_now(option__output__forces, iter)) then
476 if (bitand(outp%how(option__output__forces), option__outputformat__bild) /= 0) then
477 call ions%write_bild_forces_file(dir, "forces")
478 else
479 call write_xsf_geometry_file(dir, "forces", space, ions%latt, ions%pos, ions%atom, &
480 gr, namespace, total_forces = ions%tot_force)
481 end if
482 end if
483
484 if (outp%what_now(option__output__matrix_elements, iter)) then
485 call output_me(outp%me, namespace, space, dir, st, gr, ions, hm)
486 end if
487
488 do iout = lbound(outp%how, 1), ubound(outp%how, 1)
489 if (bitand(outp%how(iout), option__outputformat__etsf) /= 0) then
490 call output_etsf(outp, namespace, space, dir, st, gr, hm%kpoints, ions, iter)
491 exit
492 end if
493 end do
495 if (outp%what_now(option__output__berkeleygw, iter)) then
496 call output_berkeleygw(outp%bgw, namespace, space, dir, st, gr, ks, hm, ions)
497 end if
498
499 if (outp%what_now(option__output__energy_density, iter)) then
500 call output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
501 end if
502
503 if (outp%what_now(option__output__stress, iter)) then
504 call io_mkdir(dir, namespace)
505 iunit = io_open(trim(dir)//'/stress', namespace, action='write')
506 call output_stress(iunit, space%periodic_dim, st%stress_tensors)
507 call io_close(iunit)
508 end if
509
510 if (hm%lda_u_level /= dft_u_none) then
511 if (outp%what_now(option__output__occ_matrices, iter))&
512 call lda_u_write_occupation_matrices(dir, hm%lda_u, st, namespace)
513
514 if (outp%what_now(option__output__effectiveu, iter))&
515 call lda_u_write_effectiveu(dir, hm%lda_u, st, namespace)
516
517 if (outp%what_now(option__output__magnetization, iter))&
518 call lda_u_write_magnetization(dir, hm%lda_u, ions, gr, st, namespace)
519
520 if (outp%what_now(option__output__local_orbitals, iter))&
521 call output_dftu_orbitals(outp, dir, namespace, space, hm%lda_u, st, gr, ions, hm%phase%is_allocated())
522
523 if (outp%what_now(option__output__kanamoriu, iter))&
524 call lda_u_write_kanamoriu(dir, st, hm%lda_u, namespace)
525
526 if (ks%oep_photon%level == oep_level_full) then
527 if (outp%what_now(option__output__photon_correlator, iter)) then
528 write(fname, '(a)') 'photon_correlator'
529 call dio_function_output(outp%how(option__output__photon_correlator), dir, trim(fname), namespace, space, &
530 gr, ks%oep_photon%pt%correlator(:,1), units_out%length, ierr, pos=ions%pos, atoms=ions%atom)
531 end if
532 end if
533 end if
534
535 ! We can only test against the theory level here, as it is not set in the call of output_init().
536 if (outp%what_now(option__output__xc_torque, iter)) then
537 if (ks%theory_level /= kohn_sham_dft .and. ks%theory_level /= generalized_kohn_sham_dft) then
538 write(message(1), '(a)') 'The output xc_torque can only be computed when there is a xc potential.'
539 call messages_fatal(1, namespace=namespace)
540 end if
541 end if
542
543 call output_xc_torque(outp, namespace, dir, gr, hm, st, ions, ions%space)
544
545 call profiling_out("OUTPUT_ALL")
546 pop_sub(output_all)
547 end subroutine output_all
548
549
550 ! ---------------------------------------------------------
551 subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
552 type(output_t), intent(in) :: outp
553 type(namespace_t), intent(in) :: namespace
554 class(space_t), intent(in) :: space
555 character(len=*), intent(in) :: dir
556 type(states_elec_t), intent(inout) :: st
557 type(hamiltonian_elec_t), intent(in) :: hm
558 type(grid_t), intent(in) :: gr
559 type(ions_t), intent(in) :: ions
560 integer, intent(in) :: iter
561
562 real(real64), allocatable :: f_loc(:,:)
563 character(len=MAX_PATH_LEN) :: fname
564 integer :: is, ierr, imax
565 type(mpi_grp_t) :: mpi_grp
566
568
569 mpi_grp = st%dom_st_kpt_mpi_grp
570
571 ! if SPIN_POLARIZED, the ELF contains one extra channel: the total ELF
572 imax = st%d%nspin
573 if (st%d%ispin == spin_polarized) imax = 3
574
575 safe_allocate(f_loc(1:gr%np, 1:imax))
576
577 ! First the ELF in real space
578 if (outp%what_now(option__output__elf, iter) .or. outp%what_now(option__output__elf_basins, iter)) then
579 assert(space%dim /= 1)
580
581 call elf_calc(space, st, gr, hm%kpoints, f_loc)
582
583 ! output ELF in real space
584 if (outp%what_now(option__output__elf, iter)) then
585 write(fname, '(a)') 'elf_rs'
586 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
587 f_loc(:,imax), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
588 ! this quantity is dimensionless
589
590 if (st%d%ispin /= unpolarized) then
591 do is = 1, 2
592 write(fname, '(a,i1)') 'elf_rs-sp', is
593 call dio_function_output(outp%how(option__output__elf), dir, trim(fname), namespace, space, gr, &
594 f_loc(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
595 ! this quantity is dimensionless
596 end do
597 end if
598 end if
599
600 if (outp%what_now(option__output__elf_basins, iter)) then
601 call out_basins(f_loc(:,1), "elf_rs_basins", outp%how(option__output__elf_basins))
602 end if
603 end if
604
605 ! Now Bader analysis
606 if (outp%what_now(option__output__bader, iter)) then
607 do is = 1, st%d%nspin
608 call dderivatives_lapl(gr%der, st%rho(:,is), f_loc(:,is))
609
610 fname = get_filename_with_spin('bader', st%d%nspin, is)
611
612 call dio_function_output(outp%how(option__output__bader), dir, trim(fname), namespace, space, gr, &
613 f_loc(:,is), units_out%length**(-2 - space%dim), ierr, &
614 pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
615
616 fname = get_filename_with_spin('bader_basins', st%d%nspin, is)
617 call out_basins(f_loc(:, is), fname, outp%how(option__output__bader))
618 end do
619 end if
620
621 ! Now the pressure
622 if (outp%what_now(option__output__el_pressure, iter)) then
623 call calc_electronic_pressure(st, hm, gr, f_loc(:,1))
624 call dio_function_output(outp%how(option__output__el_pressure), dir, "el_pressure", namespace, space, gr, &
625 f_loc(:,1), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
626 ! this quantity is dimensionless
627 end if
628
629 safe_deallocate_a(f_loc)
630
632
633 contains
634 ! ---------------------------------------------------------
635 subroutine out_basins(ff, filename, output_how)
636 real(real64), intent(in) :: ff(:)
637 character(len=*), intent(in) :: filename
638 integer(int64), intent(in) :: output_how
639
640 character(len=MAX_PATH_LEN) :: fname
641 type(basins_t) :: basins
642 integer :: iunit
643
645
646 call basins_init(basins, namespace, gr)
647 call basins_analyze(basins, namespace, gr, ff(:), st%rho, 0.01_real64)
648
649 call dio_function_output(output_how, dir, trim(filename), namespace, space, gr, &
650 real(basins%map, real64) , unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = mpi_grp)
651 ! this quantity is dimensionless
652
653 write(fname,'(4a)') trim(dir), '/', trim(filename), '.info'
654 iunit = io_open(trim(fname), namespace, action = 'write')
655 call basins_write(basins, gr, iunit)
656 call io_close(iunit)
657
658 call basins_end(basins)
659
661 end subroutine out_basins
662
663 end subroutine output_localization_funct
664
665
666 ! ---------------------------------------------------------
667 subroutine calc_electronic_pressure(st, hm, gr, pressure)
668 type(states_elec_t), intent(inout) :: st
669 type(hamiltonian_elec_t), intent(in) :: hm
670 type(grid_t), intent(in) :: gr
671 real(real64), intent(out) :: pressure(:)
672
673 real(real64), allocatable :: rho(:,:), lrho(:), tau(:,:)
674 real(real64) :: p_tf, dens
675 integer :: is, ii
676
678
679 safe_allocate( rho(1:gr%np_part, 1:st%d%nspin))
680 safe_allocate(lrho(1:gr%np))
681 safe_allocate( tau(1:gr%np, 1:st%d%nspin))
682
683 rho = m_zero
684 call density_calc(st, gr, rho)
685 call states_elec_calc_quantities(gr, st, hm%kpoints, .false., kinetic_energy_density = tau)
686
687 pressure = m_zero
688 do is = 1, st%d%spin_channels
689 lrho = m_zero
690 call dderivatives_lapl(gr%der, rho(:, is), lrho)
691
692 pressure(:) = pressure(:) + &
693 tau(:, is)/m_three - lrho(:)/m_four
694 end do
695
696 do ii = 1, gr%np
697 dens = sum(rho(ii,1:st%d%spin_channels))
698
699 p_tf = m_two/m_five*(m_three*m_pi**2)**(m_two/m_three)* &
700 dens**(m_five/m_three)
701
702 ! add XC pressure
703 ! FIXME: Not correct for spinors and spin-polarized here
704 pressure(ii) = pressure(ii) + (dens*hm%ks_pot%vxc(ii,1) - hm%energy%exchange - hm%energy%correlation)
705
706 pressure(ii) = pressure(ii)/p_tf
707 pressure(ii) = m_half*(m_one + pressure(ii)/sqrt(m_one + pressure(ii)**2))
708 end do
709
711 end subroutine calc_electronic_pressure
712
713
714 ! ---------------------------------------------------------
715 subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
716 type(output_t), intent(in) :: outp
717 type(namespace_t), intent(in) :: namespace
718 class(space_t), intent(in) :: space
719 character(len=*), intent(in) :: dir
720 type(hamiltonian_elec_t), intent(in) :: hm
721 type(v_ks_t), intent(inout) :: ks
722 type(states_elec_t), intent(in) :: st
723 type(ions_t), intent(in) :: ions
724 type(grid_t), intent(in) :: gr
725
726 integer :: is, ierr, ip
727 character(len=MAX_PATH_LEN) :: fname
728 type(unit_t) :: fn_unit
729 real(real64), allocatable :: energy_density(:, :)
730 real(real64), allocatable :: ex_density(:)
731 real(real64), allocatable :: ec_density(:)
732
733 push_sub(output_energy_density)
734
735 fn_unit = units_out%energy*units_out%length**(-space%dim)
736 safe_allocate(energy_density(1:gr%np, 1:st%d%nspin))
737
738 ! the kinetic energy density
739 call states_elec_calc_quantities(gr, st, hm%kpoints, .true., kinetic_energy_density = energy_density)
740
741 ! the external potential energy density
742 do is = 1, st%d%nspin
743 do ip = 1, gr%np
744 energy_density(ip, is) = energy_density(ip, is) + st%rho(ip, is)*hm%ep%vpsl(ip)
745 end do
746 end do
747
748 ! the hartree energy density
749 do is = 1, st%d%nspin
750 do ip = 1, gr%np
751 energy_density(ip, is) = energy_density(ip, is) + m_half*st%rho(ip, is)*hm%ks_pot%vhartree(ip)
752 end do
753 end do
754
755 ! the XC energy density
756 safe_allocate(ex_density(1:gr%np))
757 safe_allocate(ec_density(1:gr%np))
758
759 call xc_get_vxc(gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, st%rho, st%d%ispin, &
760 hm%ions%latt%rcell_volume, ex_density = ex_density, ec_density = ec_density)
761 do is = 1, st%d%nspin
762 do ip = 1, gr%np
763 energy_density(ip, is) = energy_density(ip, is) + ex_density(ip) + ec_density(ip)
764 end do
765 end do
766
767 safe_deallocate_a(ex_density)
768 safe_deallocate_a(ec_density)
769
770 do is = 1, st%d%spin_channels
771 fname = get_filename_with_spin('energy_density', st%d%nspin, is)
772 call dio_function_output(outp%how(option__output__energy_density), dir, trim(fname), namespace, space, gr, &
773 energy_density(:, is), unit_one, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
774 end do
775 safe_deallocate_a(energy_density)
776
777 pop_sub(output_energy_density)
778 end subroutine output_energy_density
779
780 !--------------------------------------------------------------
781
782 logical function output_need_exchange(outp) result(need_exx)
783 type(output_t), intent(in) :: outp
784
785 need_exx =(outp%what(option__output__berkeleygw) &
786 .or. outp%me%what(option__outputmatrixelements__two_body) &
787 .or. outp%me%what(option__outputmatrixelements__two_body_exc_k))
788 end function output_need_exchange
789
790
791 ! ---------------------------------------------------------
792 subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
793 type(output_t), intent(in) :: outp
794 character(len=*), intent(in) :: dir
795 type(namespace_t), intent(in) :: namespace
796 class(space_t), intent(in) :: space
797 type(lda_u_t), intent(in) :: this
798 type(states_elec_t), intent(in) :: st
799 class(mesh_t), intent(in) :: mesh
800 type(ions_t), intent(in) :: ions
801 logical, intent(in) :: has_phase
802
803 integer :: ios, im, ik, idim, ierr
804 complex(real64), allocatable :: tmp(:)
805 real(real64), allocatable :: dtmp(:)
806 type(orbitalset_t), pointer :: os
807 type(unit_t) :: fn_unit
808 character(len=MAX_PATH_LEN) :: fname
809
811
812 fn_unit = sqrt(units_out%length**(-space%dim))
813
814 if (this%basis%use_submesh) then
815 if (states_are_real(st)) then
816 safe_allocate(dtmp(1:mesh%np))
817 else
818 safe_allocate(tmp(1:mesh%np))
819 end if
820 end if
821
822 do ios = 1, this%norbsets
823 os => this%orbsets(ios)
824 do ik = st%d%kpt%start, st%d%kpt%end
825 do im = 1, this%orbsets(ios)%norbs
826 do idim = 1, min(os%ndim, st%d%dim)
827 if (st%nik > 1) then
828 if (min(os%ndim, st%d%dim) > 1) then
829 write(fname, '(a,i1,a,i3.3,a,i8.8,a,i1)') 'orb', im, '-os', ios, '-k', ik, '-sp', idim
830 else
831 write(fname, '(a,i1,a,i3.3,a,i8.8)') 'orb', im, '-os', ios, '-k', ik
832 end if
833 else
834 if (min(os%ndim, st%d%dim) > 1) then
835 write(fname, '(a,i1,a,i3.3,a,i1)') 'orb', im, '-os', ios, '-sp', idim
836 else
837 write(fname, '(a,i1,a,i3.3)') 'orb', im, '-os', ios
838 end if
839 end if
840 if (has_phase) then
841 if (.not. this%basis%use_submesh) then
842 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
843 mesh, os%eorb_mesh(1:mesh%np,im,idim,ik), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
844 else
845 tmp = m_z0
846 call submesh_add_to_mesh(os%sphere, os%eorb_submesh(1:os%sphere%np,idim,im,ik), tmp)
847 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
848 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
849 end if
850 else
851 if (.not. this%basis%use_submesh) then
852 if (states_are_real(st)) then
853 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
854 os%dorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
855 else
856 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, mesh, &
857 os%zorb(1:mesh%np,idim,im), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
858 end if
859 else
860 if (states_are_real(st)) then
861 dtmp = m_zero
862 call submesh_add_to_mesh(os%sphere, os%dorb(1:os%sphere%np,idim,im), dtmp)
863 call dio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
864 mesh, dtmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
865 else
866 tmp = m_z0
867 call submesh_add_to_mesh(os%sphere, os%zorb(1:os%sphere%np,idim,im), tmp)
868 call zio_function_output(outp%how(option__output__local_orbitals), dir, fname, namespace, space, &
869 mesh, tmp, fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
870 end if
871 end if
872 end if
873 end do
874 end do
875 end do
876 end do
878 safe_deallocate_a(tmp)
879 safe_deallocate_a(dtmp)
880
881 pop_sub(output_dftu_orbitals)
882 end subroutine output_dftu_orbitals
883
884 ! ---------------------------------------------------------
885 logical function output_needs_current(outp, states_are_real)
886 type(output_t), intent(in) :: outp
887 logical, intent(in) :: states_are_real
888
889 output_needs_current = .false.
890
891 if (outp%what(option__output__current) &
892 .or. outp%what(option__output__current_dia) &
893 .or. outp%what(option__output__heat_current) &
894 .or. outp%what(option__output__current_kpt)) then
895 if (.not. states_are_real) then
897 else
898 message(1) = 'No current density output for real states since it is identically zero.'
899 call messages_warning(1)
900 end if
901 end if
902
903
904 end function
905
906#include "output_etsf_inc.F90"
907
908#include "output_states_inc.F90"
909
910#include "output_h_inc.F90"
911
912#include "undef.F90"
913#include "complex.F90"
914#include "output_linear_response_inc.F90"
915
916#include "undef.F90"
917#include "real.F90"
918#include "output_linear_response_inc.F90"
919
920end module output_oct_m
921
922!! Local Variables:
923!! mode: f90
924!! coding: utf-8
925!! End:
pure logical function, public accel_is_enabled()
Definition: accel.F90:403
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
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: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:1901
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:763
subroutine, public output_states(outp, namespace, space, dir, st, gr, ions, hm, iter)
Definition: output.F90:1091
logical function, public output_needs_current(outp, states_are_real)
Definition: output.F90:981
subroutine, public output_hamiltonian(outp, namespace, space, dir, hm, st, der, ions, gr, iter, grp)
Definition: output.F90:1391
subroutine, public output_all(outp, namespace, space, dir, gr, ions, iter, st, hm, ks)
Definition: output.F90:495
logical function, public output_need_exchange(outp)
Definition: output.F90:878
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:1710
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:1817
subroutine, public doutput_lr(outp, namespace, space, dir, st, mesh, lr, idir, isigma, ions, pert_unit)
Definition: output.F90:2046
subroutine, public output_scalar_pot(outp, namespace, space, dir, mesh, ions, ext_partners, time)
Definition: output.F90:1673
subroutine output_energy_density(outp, namespace, space, dir, hm, ks, st, ions, gr)
Definition: output.F90:811
subroutine output_dftu_orbitals(outp, dir, namespace, space, this, st, mesh, ions, has_phase)
Definition: output.F90:888
subroutine output_localization_funct(outp, namespace, space, dir, st, hm, gr, ions, iter)
Definition: output.F90:647
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:1032
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:1080
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:205
subroutine, public v_ks_calculate_current(this, calc_cur)
Definition: v_ks.F90:1526
Definition: xc.F90:120
integer, parameter, public oep_level_full
Definition: xc_oep.F90:174
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:731
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)