util.F90 Source File


This file depends on

sourcefile~~util.f90~~EfferentGraph sourcefile~util.f90 util.F90 sourcefile~precision.f90 precision.F90 sourcefile~util.f90->sourcefile~precision.f90

Files dependent on this one

sourcefile~~util.f90~~AfferentGraph sourcefile~util.f90 util.F90 sourcefile~get_basis_overlap.f90 get_basis_overlap.F90 sourcefile~get_basis_overlap.f90->sourcefile~util.f90 sourcefile~get_states_overlap.f90 get_states_overlap.F90 sourcefile~get_states_overlap.f90->sourcefile~util.f90 sourcefile~grd2.f90 grd2.F90 sourcefile~grd2.f90->sourcefile~util.f90 sourcefile~guess_hcore.f90 guess_hcore.F90 sourcefile~guess_hcore.f90->sourcefile~util.f90 sourcefile~guess_huckel.f90 guess_huckel.F90 sourcefile~guess_huckel.f90->sourcefile~util.f90 sourcefile~guess_json.f90 guess_json.F90 sourcefile~guess_json.f90->sourcefile~util.f90 sourcefile~hf_gradient.f90 hf_gradient.F90 sourcefile~hf_gradient.f90->sourcefile~util.f90 sourcefile~hf_gradient.f90->sourcefile~grd2.f90 sourcefile~scf.f90 scf.F90 sourcefile~scf.f90->sourcefile~util.f90 sourcefile~tdhf_energy.f90 tdhf_energy.F90 sourcefile~tdhf_energy.f90->sourcefile~util.f90 sourcefile~tdhf_gradient.f90 tdhf_gradient.F90 sourcefile~tdhf_gradient.f90->sourcefile~util.f90 sourcefile~tdhf_gradient.f90->sourcefile~grd2.f90 sourcefile~tdhf_mrsf_energy.f90 tdhf_mrsf_energy.F90 sourcefile~tdhf_mrsf_energy.f90->sourcefile~util.f90 sourcefile~tdhf_sf_energy.f90 tdhf_sf_energy.F90 sourcefile~tdhf_sf_energy.f90->sourcefile~util.f90 sourcefile~tdhf_z_vector.f90 tdhf_z_vector.F90 sourcefile~tdhf_z_vector.f90->sourcefile~util.f90 sourcefile~hf_energy.f90 hf_energy.f90 sourcefile~hf_energy.f90->sourcefile~scf.f90

Source Code

module util
  use precision, only: dp

  implicit none

  character(len=*), parameter :: module_name = "util"

  private
  public :: measure_time
  public :: e_charge_repulsion

contains
  subroutine measure_time(print_total, log_unit)
    use iso_fortran_env, only: int64, real64
    implicit none
    integer, intent(in) :: print_total, log_unit
    integer(int64), save :: start_clock, previous_clock
    integer(int64) :: clock_rate, current_clock
    real(real64), save :: start_cpu_time, previous_cpu_time
    real(real64) :: current_cpu_time, elapsed_cpu_time, elapsed_wall_time
    logical, save :: first_call = .true.

    if (first_call) then
      call system_clock(start_clock, clock_rate)
      call cpu_time(start_cpu_time)
      previous_clock = start_clock
      previous_cpu_time = start_cpu_time
      first_call = .false.
    end if

    call system_clock(current_clock, clock_rate)
    call cpu_time(current_cpu_time)

    elapsed_wall_time = real(current_clock - previous_clock, &
                             real64) / real(clock_rate, real64)
    elapsed_cpu_time = current_cpu_time - previous_cpu_time

    write(log_unit, "(3X, A, F10.3, 3X, A, F10.3)") &
            "Step  CPU time (seconds): ", elapsed_cpu_time, &
            "Wall time (seconds): ", elapsed_wall_time

    previous_clock = current_clock
    previous_cpu_time = current_cpu_time

    if (print_total /= 0) then
      elapsed_wall_time = real(current_clock-start_clock, &
                               real64) / real(clock_rate, real64)
      elapsed_cpu_time = current_cpu_time - start_cpu_time

      write(log_unit, "(3X, A, F10.3, 3X, A, F10.3)") &
              "Total CPU time (seconds): ", elapsed_cpu_time, &
              "Wall time (seconds): ", elapsed_wall_time
    end if
  end subroutine measure_time

  pure function e_charge_repulsion(xyz, q) result(enuc)
    use precision, only: dp
    implicit none
    real(kind=dp) :: enuc
    real(kind=dp), intent(in) :: xyz(:,:), q(:)
    real(kind=dp), parameter :: disttol = 1.0d-10
    integer :: i, j, nat
    real(kind=dp) :: rr

    nat = min(ubound(q,1), ubound(xyz,2))
    enuc = 0.0d0
    do i = 2, nat
      do j = 1, i-1
        rr = sum((xyz(:,i)-xyz(:,j))**2)
        if (rr >= disttol) enuc = enuc + q(i)*q(j)/sqrt(rr)
      end do
    end do
  end function e_charge_repulsion

end module util