LCOV - code coverage report
Current view: top level - src/95_drive - m_rttddft_driver.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 50 50
Test Date: 2026-11-08 02:25:56 Functions: 100.0 % 1 1
Branches: 29.4 % 486 143

             Branch data     Line data    Source code
       1                 :             : !!****m* ABINIT/m_rttddft_driver
       2                 :             : !! NAME
       3                 :             : !!  m_rttddft_driver
       4                 :             : !!
       5                 :             : !! FUNCTION
       6                 :             : !!  Real-Time Time Dependent DFT (RT-TDDFT)
       7                 :             : !!
       8                 :             : !! COPYRIGHT
       9                 :             : !!  Copyright (C) 2021-2026 ABINIT group (FB)
      10                 :             : !!  This file is distributed under the terms of the
      11                 :             : !!  GNU General Public License, see ~abinit/COPYING
      12                 :             : !!  or http://www.gnu.org/copyleft/gpl.txt .
      13                 :             : !!
      14                 :             : !! SOURCE
      15                 :             : 
      16                 :             : #if defined HAVE_CONFIG_H
      17                 :             : #include "config.h"
      18                 :             : #endif
      19                 :             : 
      20                 :             : #include "abi_common.h"
      21                 :             : 
      22                 :             : module m_rttddft_driver
      23                 :             : 
      24                 :             :  use defs_basis
      25                 :             :  use defs_abitypes,        only: MPI_type
      26                 :             :  use defs_datatypes,       only: pseudopotential_type
      27                 :             :  use m_dtfil,              only: datafiles_type
      28                 :             :  use m_dtset,              only: dataset_type
      29                 :             :  use m_errors,             only: msg_hndl
      30                 :             :  use m_pawang,             only: pawang_type
      31                 :             :  use m_pawrad,             only: pawrad_type
      32                 :             :  use m_pawtab,             only: pawtab_type
      33                 :             :  use m_rttddft_output,     only: rttddft_output
      34                 :             :  use m_rttddft_tdks,       only: tdks_type
      35                 :             :  use m_rttddft_propagate,  only: rttddft_propagate_ele
      36                 :             :  use m_rttddft_properties, only: rttddft_calc_density, &
      37                 :             :                                & rttddft_calc_etot,    &
      38                 :             :                                & rttddft_calc_current
      39                 :             :  use m_specialmsg,         only: wrtout
      40                 :             :  use m_time,               only: cwtime
      41                 :             : 
      42                 :             :  implicit none
      43                 :             : 
      44                 :             :  private
      45                 :             : !!***
      46                 :             : 
      47                 :             :  public :: rttddft
      48                 :             : !!***
      49                 :             : 
      50                 :             : contains
      51                 :             : !!***
      52                 :             : 
      53                 :             : !!****f* m_rttddft_driver/rttddft
      54                 :             : !! NAME
      55                 :             : !!  rttddft
      56                 :             : !!
      57                 :             : !! FUNCTION
      58                 :             : !!  Primary routine for real-time TDDFT calculations.
      59                 :             : !!  1) Initialization: create main tdks (Time-Dependent Kohn-Sham) object
      60                 :             : !!    - intialize various important parameters
      61                 :             : !!    - read intial KS orbitals in WFK file
      62                 :             : !!    - compute initial density from KS orbitals
      63                 :             : !!  2) Propagation loop (rttddft_propagate):
      64                 :             : !!    for i = 1, ntime
      65                 :             : !!       - propagate KS orbitals
      66                 :             : !!       - propagate nuclei if requested (Erhenfest dynamics)
      67                 :             : !!       - compute new density
      68                 :             : !!       - Compute and print requested properties
      69                 :             : !!  3) Final printout and finalize
      70                 :             : !!
      71                 :             : !! INPUTS
      72                 :             : !!  codvsn = code version
      73                 :             : !!  dtfil <type datafiles_type> = infos about file names
      74                 :             : !!  dtset <type(dataset_type)> = all input variables for this dataset
      75                 :             : !!  mpi_enreg <MPI_type> = MPI-parallelisation information
      76                 :             : !!  pawang <type(pawang_type)> = paw angular mesh and related data
      77                 :             : !!  pawrad(ntypat*usepaw) <type(pawrad_type)> = paw radial mesh and related data
      78                 :             : !!  pawtab(ntypat*usepaw) <type(pawtab_type)> = paw tabulated starting data
      79                 :             : !!  psps <type(pseudopotential_type)> = variables related to pseudopotentials
      80                 :             : !!
      81                 :             : !! OUTPUT
      82                 :             : !!
      83                 :             : !! SOURCE
      84                 :          50 : subroutine rttddft(codvsn,dtfil,dtset,mpi_enreg,pawang,pawrad,pawtab,psps)
      85                 :             : 
      86                 :             :  !Arguments ------------------------------------
      87                 :             :  !scalars
      88                 :             :  character(len=8),           intent(in)    :: codvsn
      89                 :             :  type(dataset_type),         intent(inout) :: dtset
      90                 :             :  type(datafiles_type),       intent(inout) :: dtfil
      91                 :             :  type(MPI_type),             intent(inout) :: mpi_enreg
      92                 :             :  type(pawang_type),          intent(inout) :: pawang
      93                 :             :  type(pseudopotential_type), intent(inout) :: psps
      94                 :             :  !arrays
      95                 :             :  type(pawrad_type), target,  intent(inout) :: pawrad(psps%ntypat*psps%usepaw)
      96                 :             :  type(pawtab_type), target,  intent(inout) :: pawtab(psps%ntypat*psps%usepaw)
      97                 :             : 
      98                 :             :  !Local variables-------------------------------
      99                 :             :  !scalars
     100                 :             :  character(len=500)   :: msg
     101                 :             :  integer              :: istep
     102                 :             :  real(dp)             :: integrated_density, stability
     103                 :          50 :  type(tdks_type)      :: tdks
     104                 :             :  !arrays
     105                 :             :  real(dp)             :: cpu, wall, gflops
     106                 :             : 
     107                 :             : ! ***********************************************************************
     108                 :             : 
     109                 :          50 :  write(msg,'(7a)') ch10,'---------------------------------------------------------------------------',&
     110                 :          50 :                  & ch10,'----------------   Starting real-time time dependent DFT   ----------------',&
     111                 :         100 :                  & ch10,'---------------------------------------------------------------------------',ch10
     112                 :          50 :  call wrtout(ab_out,msg)
     113         [ +  + ]:          50 :  if (do_write_log) call wrtout(std_out,msg)
     114                 :          50 :  write(msg,'(7a)') ch10,' RT-TDDFT is under active development and should thus be used with caution ',&
     115                 :         100 :                  & ch10,'---------------------------------------------------------------------------',ch10
     116         [ +  + ]:          50 :  if (do_write_log) call wrtout(std_out,msg)
     117                 :             : 
     118                 :             :  !** 1) Initialization: create main tdks (Time-Dependent Kohn-Sham) object
     119                 :          50 :  write(msg,'(3a)') ch10,'---------------------------   Initialization   ----------------------------',ch10
     120                 :          50 :  call wrtout(ab_out,msg)
     121         [ +  + ]:          50 :  if (do_write_log) call wrtout(std_out,msg)
     122                 :             : 
     123                 :          50 :  call tdks%init(codvsn,dtfil,dtset,mpi_enreg,pawang,pawrad,pawtab,psps)
     124                 :             : 
     125                 :             :  !Compute initial electronic density
     126                 :          50 :  call rttddft_calc_density(dtset,mpi_enreg,psps,tdks)
     127                 :             : 
     128                 :             :  !Compute current at t=0 (or t-dt) and update vector potential accordingly
     129   [ +  +  -  + ]:          50 :  if (dtset%prtcurrent/=0 .or. tdks%tdef%induced_vecpot) then
     130                 :          21 :    call rttddft_calc_current(tdks,dtset,dtfil,psps,mpi_enreg)
     131                 :             :  end if
     132                 :             : 
     133                 :             :  !** 2) Propagation loop
     134                 :          50 :  write(msg,'(3a)') ch10,'-------------------------   Starting propagation   ------------------------',ch10
     135                 :          50 :  call wrtout(ab_out,msg)
     136         [ +  + ]:          50 :  if (do_write_log) call wrtout(std_out,msg)
     137                 :             : 
     138         [ +  + ]:        1774 :  do istep = tdks%first_step, tdks%first_step+tdks%ntime-1
     139                 :             : 
     140                 :        1725 :    call cwtime(cpu,wall,gflops,"start")
     141                 :             : 
     142                 :             :    !*** Perform electronic step ***
     143                 :             :    !Compute new WF at time t and energy contribution at time t-dt
     144                 :        1725 :    call rttddft_propagate_ele(dtset,istep,mpi_enreg,psps,tdks)
     145                 :             : 
     146                 :             :    !Compute total energy at time t-dt
     147                 :        1725 :    call rttddft_calc_etot(dtset,tdks%energies,tdks%etot,tdks%occ)
     148                 :             : 
     149                 :             :    !Update electric field and vector potential value
     150                 :             :    call tdks%tdef%update(dtset,mpi_enreg,istep*tdks%dt,tdks%rprimd,tdks%gprimd,tdks%kg, &
     151                 :        1725 :                        & psps%mpsang,tdks%npwarr,tdks%ylm,tdks%ylmgr,tdks%current)
     152                 :             : 
     153                 :             :    !Compute new electronic density at t
     154                 :        1725 :    call rttddft_calc_density(dtset,mpi_enreg,psps,tdks)
     155                 :             : 
     156                 :             :    !Compute current at t
     157   [ +  +  -  + ]:        1725 :    if (dtset%prtcurrent/=0 .or. tdks%tdef%induced_vecpot) then
     158                 :        1100 :       call rttddft_calc_current(tdks,dtset,dtfil,psps,mpi_enreg)
     159                 :             :    end if
     160                 :             : 
     161                 :             :    !Compute and output useful electronic values
     162                 :        1725 :    call rttddft_output(dtfil,dtset,istep,mpi_enreg,psps,tdks)
     163                 :             : 
     164                 :             :    !Test of stability
     165         [ +  + ]:    29324940 :    integrated_density = sum(tdks%rhor(:,1))*tdks%ucvol/tdks%nfftf
     166                 :        1725 :    stability = abs(integrated_density-dtset%nelect)/dtset%nelect
     167         [ +  + ]:        1725 :    if (stability > 0.1_dp) then
     168                 :           1 :       write(msg,"(3a)") "The integrated density has changed by more than 10%!", ch10, &
     169                 :           2 :                      &  "The integration is unstable, you should probably decrease the timestep dtele."
     170                 :           1 :       ABI_ERROR(msg)
     171         [ +  + ]:        1724 :    else if (stability > 0.05_dp) then
     172                 :           1 :       write(msg,"(3a)") "The integrated density has changed by more than 5%!", ch10, &
     173                 :           2 :                      &  "You should be careful, the integration might be unstable"
     174                 :           1 :       ABI_WARNING(msg)
     175                 :             :    end if
     176                 :             : 
     177                 :             :    !TODO: *** Perform nuclear step ***
     178                 :             :    ! For Ehrenfest dynamics
     179                 :             :    !call rttddft_propagate_nuc(dtset,istep,mpi_enreg,psps,tdks)
     180                 :             : 
     181                 :        1724 :    call cwtime(cpu,wall,gflops,"stop")
     182                 :        1724 :    write(msg,'(a,2f8.2,a)') '- Time - cpu, wall (sec):', cpu, wall, ch10
     183                 :        1724 :    call wrtout(ab_out,msg)
     184         [ +  + ]:        5222 :    if (do_write_log) call wrtout(std_out,msg)
     185                 :             : 
     186                 :             :  end do
     187                 :             : 
     188                 :             :  !** 3) Final Output and free memory
     189                 :          49 :  write(msg,'(7a)') ch10,'---------------------------------------------------------------------------',&
     190                 :          49 :                  & ch10,'----------------   Finished real-time time dependent DFT   ----------------',&
     191                 :          98 :                  & ch10,'---------------------------------------------------------------------------',ch10
     192                 :          49 :  call wrtout(ab_out,msg)
     193         [ +  + ]:          49 :  if (do_write_log) call wrtout(std_out,msg)
     194                 :             : 
     195                 :          49 :  call tdks%free(dtset,mpi_enreg,psps)
     196                 :             : 
     197   [ -  +  -  +  :          49 : end subroutine rttddft
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  +  
          -  +  -  +  -  
          +  -  +  -  -  
          -  -  -  -  -  
          -  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  -  -  
          -  -  -  -  +  
          -  -  -  -  -  
          -  -  +  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  +  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  +  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
             -  -  -  - ]
     198                 :             : !!***
     199                 :             : 
     200                 :             : end module m_rttddft_driver
     201                 :             : !!***
        

Generated by: LCOV version 2.3-1