LCOV - code coverage report
Current view: top level - src/95_drive - m_precpred_1geo.F90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 70.0 % 60 42
Test Date: 2026-09-19 17:42:43 Functions: 100.0 % 1 1

            Line data    Source code
       1              : !!****m* ABINIT/m_precpred_1geo
       2              : !! NAME
       3              : !!  m_precpred_1geo
       4              : !!
       5              : !! FUNCTION
       6              : !! Single geometry: apply force and stress preconditioner followed by geometry predictor.
       7              : !! Choose among the whole set of geometry predictors defined by iommov.
       8              : !!
       9              : !! COPYRIGHT
      10              : !!  Copyright (C) 2018-2026 ABINIT group (DCA, XG, GMR, SE)
      11              : !!  This file is distributed under the terms of the
      12              : !!  GNU General Public License, see ~abinit/COPYING
      13              : !!  or http://www.gnu.org/copyleft/gpl.txt .
      14              : !!
      15              : !! SOURCE
      16              : 
      17              : #if defined HAVE_CONFIG_H
      18              : #include "config.h"
      19              : #endif
      20              : 
      21              : #include "abi_common.h"
      22              : 
      23              : module m_precpred_1geo
      24              : 
      25              :  use defs_basis
      26              :  use m_errors
      27              :  use m_abicore
      28              :  use m_abimover
      29              :  use m_abihist
      30              :  use m_xmpi
      31              :  use m_nctk
      32              :  use m_pimd
      33              :  use netcdf
      34              : #if defined HAVE_LOTF
      35              :  use lotfpath
      36              :  use m_pred_lotf
      37              : #endif
      38              : 
      39              :  use m_fstrings,           only : strcat, sjoin, itoa
      40              :  use m_geometry,           only : chkdilatmx
      41              :  use m_crystal,            only : crystal_t
      42              :  use m_pred_bfgs,          only : pred_bfgs, pred_lbfgs
      43              :  use m_pred_delocint,      only : pred_delocint
      44              :  use m_pred_fire,          only : pred_fire
      45              :  use m_pred_isokinetic,    only : pred_isokinetic
      46              :  use m_pred_diisrelax,     only : pred_diisrelax
      47              :  use m_pred_nose,          only : pred_nose
      48              :  use m_pred_srkhna14,      only : pred_srkna14
      49              :  use m_pred_isothermal,    only : pred_isothermal
      50              :  use m_pred_verlet,        only : pred_verlet
      51              :  use m_pred_velverlet,     only : pred_velverlet
      52              :  use m_pred_moldyn,        only : pred_moldyn
      53              :  use m_pred_langevin,      only : pred_langevin
      54              :  use m_pred_langevin_pimd, only : pred_langevin_pimd
      55              :  use m_pred_steepdesc,     only : pred_steepdesc
      56              :  use m_pred_simple,        only : pred_simple, prec_simple
      57              :  use m_pred_hmc,           only : pred_hmc
      58              :  use m_ipi,                only : ipi_pred
      59              : !use m_generate_training_set, only : generate_training_set
      60              : 
      61              :  implicit none
      62              : 
      63              :  private
      64              : !!***
      65              : 
      66              :  public :: precpred_1geo
      67              : !!***
      68              : 
      69              : contains
      70              : !!***
      71              : 
      72              : !!****f* ABINIT/precpred_1geo
      73              : !! NAME
      74              : !! mover
      75              : !!
      76              : !! FUNCTION
      77              : !! Single geometry: apply force and stress preconditioner followed by geometry predictor.
      78              : !! Choose among the whole set of geometry predictors defined by ionmov.
      79              : !!
      80              : !! INPUTS
      81              : !!  (TO BE DESCRIBED)
      82              : !!
      83              : !! OUTPUT
      84              : !!  (TO BE DESCRIBED)
      85              : !!
      86              : !! SIDE EFFECTS
      87              : !!  hist is the main quantity updated, contains xred, rprimd and acell.
      88              : !!  (TO BE DESCRIBED)
      89              : !!
      90              : !! NOTES
      91              : !!
      92              : !! SOURCE
      93              : 
      94        11526 : subroutine precpred_1geo(ab_mover,ab_xfh,amu_curr,deloc,dt_chkdilatmx,comm_cell,dilatmx,filnam_ds4,hist,hmctt,&
      95              : & icycle,iexit,itime,mttk_vars,nctime,ncycle,nerr_dilatmx,npsp,ntime,pimd_param,rprimd_orig,skipcycle,usewvl)
      96              : 
      97              : !Arguments ------------------------------------
      98              : !scalars
      99              :  integer, intent(in) :: comm_cell,dt_chkdilatmx,hmctt,icycle,itime,nctime,npsp,ntime
     100              :  integer, intent(inout) :: iexit,ncycle,nerr_dilatmx
     101              :  integer, intent(in) :: usewvl
     102              :  real(dp), intent(in) :: dilatmx
     103              :  logical, intent(inout) :: skipcycle
     104              :  character(len=fnlen), intent(in) :: filnam_ds4
     105              :  type(ab_xfh_type),intent(inout) :: ab_xfh
     106              :  type(abihist), intent(inout) :: hist
     107              :  type(abimover), intent(in) :: ab_mover
     108              :  type(delocint), intent(inout) :: deloc
     109              :  type(mttk_type), intent(inout) :: mttk_vars
     110              :  type(pimd_type), intent(in) :: pimd_param
     111              : !arrays
     112              :  real(dp), intent(in) :: amu_curr(ab_mover%ntypat)
     113              :  real(dp), intent(in) :: rprimd_orig(3,3)
     114              : 
     115              : !Local variables-------------------------------
     116              : !scalars
     117              :  integer,parameter :: master=0
     118              :  integer :: ii,me,nloop
     119              : !integer :: iatom
     120              :  logical,parameter :: DEBUG=.FALSE.
     121              : !character(len=500) :: message
     122              :  character(len=500) :: dilatmx_errmsg
     123              :  character(len=fnlen) :: filename
     124        11526 :  type(abiforstr) :: preconforstr ! Preconditioned forces and stress
     125       599352 :  type(crystal_t) :: crystal
     126              : !arrays
     127              :  real(dp) :: acell(3),rprimd(3,3)
     128        11526 :  real(dp), allocatable :: xred(:,:)
     129              : 
     130              : ! ***************************************************************
     131              : 
     132              : !DEBUG
     133              : !write(std_out,'(a,i4)')' m_precpred_1geo, enter : ab_mover%ionmov=',ab_mover%ionmov
     134              : !ABI_MALLOC(xred,(3,ab_mover%natom))
     135              : !call hist2var(acell,hist,ab_mover%natom,rprimd,xred,DEBUG)
     136              : !do iatom=1,ab_mover%natom
     137              : !  write(std_out,'(i4,3es14.6)') iatom,xred(1:3,iatom)
     138              : !enddo
     139              : !ABI_FREE(xred)
     140              : !ENDDEBUG
     141              : 
     142        11526 :  me=xmpi_comm_rank(comm_cell)
     143              : 
     144              : !Precondition forces, stress and energy
     145        11526 :  call abiforstr_ini(preconforstr,ab_mover%natom)
     146              : 
     147        11526 :  if (ab_mover%goprecon>0 .or. iexit==1)then
     148          434 :    call prec_simple(ab_mover,preconforstr,hist,icycle,itime,iexit)
     149              :  end if
     150              : 
     151              : !Call to each predictor
     152              : !MT->GAF: dirty trick to predict vel(t)
     153              : !do a double loop: 1- compute vel, 2- exit
     154        11526 :  nloop=1
     155              : 
     156        11526 :  if (nctime>0.and.iexit==1) then
     157           52 :    iexit=0;nloop=2
     158              :  end if
     159              : 
     160        23104 :  do ii=1,nloop
     161        11578 :    if (ii==2) iexit=1
     162              : 
     163        11526 :    select case (ab_mover%ionmov)
     164              :    case (1)
     165           73 :      call pred_moldyn(ab_mover,hist,icycle,itime,ncycle,ntime,DEBUG,iexit)
     166              :    case (2,3)
     167         1244 :      call pred_bfgs(ab_mover,ab_xfh,preconforstr,hist,ab_mover%ionmov,itime,DEBUG,iexit)
     168              :    case (4,5)
     169           35 :      call pred_simple(ab_mover,hist,iexit)
     170              :    case (6,7)
     171           53 :      call pred_verlet(ab_mover,hist,ab_mover%ionmov,itime,ntime,DEBUG,iexit)
     172              :    case (8)
     173           20 :      call pred_nose(ab_mover,hist,itime,ntime,DEBUG,iexit)
     174              :    case (9)
     175           20 :      call pred_langevin(ab_mover,hist,icycle,itime,ncycle,ntime,DEBUG,iexit,skipcycle)
     176              :    case (10,11)
     177            2 :      call pred_delocint(ab_mover,ab_xfh,deloc,preconforstr,hist,ab_mover%ionmov,itime,DEBUG,iexit)
     178              :    case (12)
     179          978 :      call pred_isokinetic(ab_mover,hist,itime,ntime,DEBUG,iexit)
     180              :    case (13)
     181         1079 :      call pred_isothermal(ab_mover,hist,itime,mttk_vars,ntime,DEBUG,iexit)
     182              :    case (14)
     183           16 :      call pred_srkna14(ab_mover,hist,icycle,DEBUG,iexit,skipcycle)
     184              :    case (15)
     185           12 :      call pred_fire(ab_mover, ab_xfh,preconforstr,hist,ab_mover%ionmov,itime,DEBUG,iexit)
     186              :    case (16)
     187           10 :      call pred_langevin_pimd(ab_mover,hist,itime,DEBUG,pimd_param)
     188              :    case (20)
     189            0 :      call pred_diisrelax(ab_mover,hist,itime,ntime,DEBUG,iexit)
     190              :    case (21)
     191            0 :      call pred_steepdesc(ab_mover,preconforstr,hist,itime,DEBUG,iexit)
     192              :    case (22)
     193           12 :      call pred_lbfgs(ab_mover,ab_xfh,preconforstr,hist,ab_mover%ionmov,itime,DEBUG,iexit)
     194              : #if defined HAVE_LOTF
     195              :    case (23)
     196              :      call pred_lotf(ab_mover,hist,itime,icycle,DEBUG,iexit)
     197              : #endif
     198              :    case (24)
     199           10 :      call pred_velverlet(ab_mover,hist,itime,ntime,DEBUG,iexit)
     200              :    case (25)
     201         8014 :      call pred_hmc(ab_mover,hist,itime,icycle,ntime,hmctt,mttk_vars,DEBUG,iexit)
     202              :    case (27)
     203              :      !In case of ionmov 27, all the atomic configurations have been computed at the
     204              :      !beginning of the routine in generate_training_set, thus we just need to increase the indexes
     205              :      !in the hist
     206            0 :      hist%ihist = abihist_findIndex(hist,+1)
     207              :    case (28)
     208            0 :      call ipi_pred(ab_mover, hist, itime, ntime, DEBUG, iexit, comm_cell)
     209              :    case default
     210        11578 :      ABI_ERROR(sjoin("Wrong value of ionmov:", itoa(ab_mover%ionmov)))
     211              :    end select
     212              : 
     213              :  end do
     214              : 
     215        34578 :  ABI_MALLOC(xred,(3,ab_mover%natom))
     216        11526 :  call hist2var(acell,hist,ab_mover%natom,rprimd,xred,DEBUG)
     217              : 
     218              :  ! check dilatmx here and correct if necessary
     219        11526 :  if (usewvl == 0) then
     220        11526 :    call chkdilatmx(dt_chkdilatmx,dilatmx,rprimd,rprimd_orig,dilatmx_errmsg)
     221        11526 :    if (LEN_TRIM(dilatmx_errmsg) /= 0) then
     222           17 :      ABI_WARNING(dilatmx_errmsg)
     223           17 :      nerr_dilatmx = nerr_dilatmx+1
     224           17 :      if (nerr_dilatmx > 3) then
     225              :        ! Write last structure before aborting, so that we can restart from it.
     226              :        ! zion is not available, but it's not useful here.
     227            0 :        if (me == master) then
     228              :          ! Init crystal
     229            0 :          hist%ihist = abihist_findIndex(hist,-1)
     230            0 :          call hist2var(acell,hist,ab_mover%natom,rprimd,xred,DEBUG)
     231              :          call crystal%init(amu_curr,0,ab_mover%natom,&
     232              :            npsp,ab_mover%ntypat,ab_mover%nsym,rprimd,ab_mover%typat,xred,&
     233              :            [(-one, ii=1,ab_mover%ntypat)],ab_mover%znucl,2,.False.,.False.,"dilatmx_structure",&
     234            0 :            symrel=ab_mover%symrel,tnons=ab_mover%tnons,symafm=ab_mover%symafm)
     235              : 
     236              :          ! Write netcdf file
     237            0 :          filename = strcat(filnam_ds4, "_DILATMX_STRUCT.nc")
     238            0 :          NCF_CHECK(crystal%ncwrite_path(filename))
     239            0 :          call crystal%free()
     240              :        end if
     241            0 :        call xmpi_barrier(comm_cell)
     242              :        write (dilatmx_errmsg, '(a,i0,9a)') &
     243            0 :         'Dilatmx has been exceeded too many times (', nerr_dilatmx, ')',ch10, &
     244            0 :         'See the description of dilatmx and chkdilatmx input variables.',ch10, &
     245            0 :         'Action: either first do a calculation with chkdilatmx=0, or ',ch10,&
     246            0 :         'restart your calculation with a larger dilatmx, or larger lattice vectors.',ch10,&
     247            0 :         'Warning: With chkdilatmx = 0 the final computation of lattice parameters might be inaccurate.'
     248            0 :        ABI_ERROR_CLASS(dilatmx_errmsg, "DilatmxError")
     249              :      end if
     250              :    else
     251        11509 :      nerr_dilatmx=0
     252              :    end if
     253              :  end if
     254              : 
     255              : !DEBUG
     256              : !write(std_out,'(a,i4)')' m_precpred_1geo, exit '
     257              : !do iatom=1,ab_mover%natom
     258              : !  write(std_out,'(i4,3es14.6)') iatom,xred(1:3,iatom)
     259              : !enddo
     260              : !ENDDEBUG
     261              : 
     262        11526 :  call abiforstr_fin(preconforstr)
     263        11526 :  ABI_FREE(xred)
     264              : 
     265        11526 : end subroutine precpred_1geo
     266              : !!***
     267              : 
     268              : end module m_precpred_1geo
     269              : !!***
        

Generated by: LCOV version 2.3-1