Skip to content

Commit

Permalink
Add more initializers (#2663)
Browse files Browse the repository at this point in the history
This PR adds initializers to all types of the modules in the directories common, eri_mme, pw_env, subsys and introduces suitable simplifications the respective modules.
  • Loading branch information
fstein93 committed Mar 9, 2023
1 parent 3f6365a commit 07ce178
Show file tree
Hide file tree
Showing 29 changed files with 900 additions and 1,404 deletions.
12 changes: 6 additions & 6 deletions src/common/structure_factor_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ MODULE structure_factor_types

! **************************************************************************************************
TYPE structure_factor_type
COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: ex, ey, ez
COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: shell_ex, shell_ey, shell_ez
COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: core_ex, core_ey, core_ez
INTEGER, DIMENSION(:, :), POINTER :: centre, core_centre, shell_centre
REAL(KIND=dp), DIMENSION(:, :), POINTER :: delta, core_delta, shell_delta
INTEGER :: lb(3)
COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: ex => NULL(), ey => NULL(), ez => NULL()
COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: shell_ex => NULL(), shell_ey => NULL(), shell_ez => NULL()
COMPLEX(KIND=dp), DIMENSION(:, :), POINTER :: core_ex => NULL(), core_ey => NULL(), core_ez => NULL()
INTEGER, DIMENSION(:, :), POINTER :: centre => NULL(), core_centre => NULL(), shell_centre => NULL()
REAL(KIND=dp), DIMENSION(:, :), POINTER :: delta => NULL(), core_delta => NULL(), shell_delta => NULL()
INTEGER :: lb(3) = -1
END TYPE structure_factor_type

END MODULE structure_factor_types
Expand Down
34 changes: 17 additions & 17 deletions src/common/timings_base_type.F
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ MODULE timings_base_type
PRIVATE

TYPE routine_stat_type
INTEGER :: routine_id
CHARACTER(len=default_string_length) :: routineN
REAL(kind=dp) :: excl_walltime_accu
REAL(kind=dp) :: incl_walltime_accu
REAL(kind=dp) :: excl_energy_accu
REAL(kind=dp) :: incl_energy_accu
INTEGER :: active_calls
INTEGER :: total_calls
INTEGER :: stackdepth_accu
LOGICAL :: trace
INTEGER :: routine_id = -1
CHARACTER(len=default_string_length) :: routineN = ""
REAL(kind=dp) :: excl_walltime_accu = 0.0_dp
REAL(kind=dp) :: incl_walltime_accu = 0.0_dp
REAL(kind=dp) :: excl_energy_accu = 0.0_dp
REAL(kind=dp) :: incl_energy_accu = 0.0_dp
INTEGER :: active_calls = 0
INTEGER :: total_calls = 0
INTEGER :: stackdepth_accu = 0
LOGICAL :: trace = .FALSE.
END TYPE routine_stat_type

TYPE call_stat_type
INTEGER :: total_calls
REAL(kind=dp) :: incl_walltime_accu
REAL(kind=dp) :: incl_energy_accu
INTEGER :: total_calls = 0
REAL(kind=dp) :: incl_walltime_accu = 0.0_dp
REAL(kind=dp) :: incl_energy_accu = 0.0_dp
END TYPE call_stat_type

TYPE callstack_entry_type
INTEGER :: routine_id
REAL(kind=dp) :: walltime_start
REAL(kind=dp) :: energy_start
INTEGER :: routine_id = -1
REAL(kind=dp) :: walltime_start = 0.0_dp
REAL(kind=dp) :: energy_start = 0.0_dp
END TYPE callstack_entry_type

TYPE routine_report_type
CHARACTER(LEN=default_string_length) :: routineN
CHARACTER(LEN=default_string_length) :: routineN = ""
REAL(KIND=dp) :: max_icost = 0.0_dp
REAL(KIND=dp) :: sum_icost = 0.0_dp
REAL(KIND=dp) :: max_ecost = 0.0_dp
Expand Down
18 changes: 9 additions & 9 deletions src/common/timings_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ MODULE timings_types
PRIVATE

TYPE timer_env_type
INTEGER :: ref_count
TYPE(routine_map_type) :: routine_names
TYPE(list_routinestat_type) :: routine_stats
TYPE(list_callstackentry_type) :: callstack
TYPE(callgraph_type) :: callgraph
INTEGER :: trace_max
INTEGER :: trace_unit
CHARACTER(len=13) :: trace_str
LOGICAL :: trace_all
INTEGER :: ref_count = -1
TYPE(routine_map_type) :: routine_names = routine_map_type()
TYPE(list_routinestat_type) :: routine_stats = list_routinestat_type()
TYPE(list_callstackentry_type) :: callstack = list_callstackentry_type()
TYPE(callgraph_type) :: callgraph = callgraph_type()
INTEGER :: trace_max = -1
INTEGER :: trace_unit = -1
CHARACTER(len=13) :: trace_str = ""
LOGICAL :: trace_all = .FALSE.
END TYPE timer_env_type

PUBLIC :: timer_env_type
Expand Down
12 changes: 4 additions & 8 deletions src/cp2k_debug.F
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ MODULE cp2k_debug
USE qs_environment_types, ONLY: get_qs_env
USE qs_kind_types, ONLY: qs_kind_type
USE string_utilities, ONLY: uppercase
USE virial_types, ONLY: cp_virial,&
virial_set,&
virial_type,&
zero_virial
USE virial_types, ONLY: virial_set,&
virial_type
#include "./base/base_uses.f90"

IMPLICIT NONE
Expand Down Expand Up @@ -204,17 +202,15 @@ SUBROUTINE cp2k_debug_energy_and_forces(force_env)
calc_stress_tensor=.TRUE.)

! Retrieve the analytical virial
CALL zero_virial(virial_analytical)
CALL cp_virial(virial, virial_analytical)
virial_analytical = virial

! Debug stress tensor (numerical vs analytical)
CALL virial_set(virial, pv_numer=.TRUE.)
CALL force_env_calc_num_pressure(force_env, dx=dx)

! Retrieve the numerical virial
CALL cp_subsys_get(subsys, virial=virial)
CALL zero_virial(virial_numerical)
CALL cp_virial(virial, virial_numerical)
virial_numerical = virial

! Print results
IF (iw > 0) THEN
Expand Down
5 changes: 1 addition & 4 deletions src/cp_subsys_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ MODULE cp_subsys_methods
init_topology,&
topology_parameters_type
USE topology_util, ONLY: check_subsys_element
USE virial_types, ONLY: virial_set,&
zero_virial
USE virial_types, ONLY: virial_set
#include "./base/base_uses.f90"

IMPLICIT NONE
Expand Down Expand Up @@ -200,7 +199,6 @@ SUBROUTINE cp_subsys_create(subsys, para_env, &
END SELECT

ALLOCATE (subsys%virial)
CALL zero_virial(subsys%virial)
CALL virial_set(virial=subsys%virial, &
pv_availability=pv_availability, &
pv_numer=pv_numerical, &
Expand Down Expand Up @@ -393,7 +391,6 @@ SUBROUTINE create_small_subsys(small_subsys, big_subsys, small_cell, &
CALL molecule_kind_list_release(mol_kinds)

ALLOCATE (small_subsys%virial)
CALL zero_virial(small_subsys%virial)
CALL atprop_create(small_subsys%atprop)
CALL cp_result_create(small_subsys%results)
END SUBROUTINE create_small_subsys
Expand Down
12 changes: 4 additions & 8 deletions src/energy_corrections.F
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,8 @@ MODULE energy_corrections
USE virial_methods, ONLY: one_third_sum_diag,&
write_stress_tensor,&
write_stress_tensor_components
USE virial_types, ONLY: cp_virial,&
symmetrize_virial,&
virial_type,&
zero_virial
USE virial_types, ONLY: symmetrize_virial,&
virial_type
USE voronoi_interface, ONLY: entry_voronoi_or_bqb
#include "./base/base_uses.f90"

Expand Down Expand Up @@ -1059,8 +1057,7 @@ SUBROUTINE ec_dc_build_ks_matrix_force(qs_env, ec_env)
! apply volume terms immediately
BLOCK
TYPE(virial_type) :: virdeb
CALL zero_virial(virdeb)
CALL cp_virial(virial, virdeb)
virdeb = virial

CALL para_env%sum(virdeb%pv_overlap)
CALL para_env%sum(virdeb%pv_ekinetic)
Expand Down Expand Up @@ -2164,8 +2161,7 @@ SUBROUTINE ec_build_ks_matrix_force(qs_env, ec_env)
! apply volume terms immediately
BLOCK
TYPE(virial_type) :: virdeb
CALL zero_virial(virdeb)
CALL cp_virial(virial, virdeb)
virdeb = virial

CALL para_env%sum(virdeb%pv_overlap)
CALL para_env%sum(virdeb%pv_ekinetic)
Expand Down
56 changes: 28 additions & 28 deletions src/eri_mme/eri_mme_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -53,41 +53,41 @@ MODULE eri_mme_types
eri_mme_set_potential

TYPE minimax_grid
REAL(KIND=dp) :: cutoff
INTEGER :: n_minimax
REAL(KIND=dp) :: cutoff = 0.0_dp
INTEGER :: n_minimax = 0
REAL(KIND=dp), POINTER, &
DIMENSION(:) :: minimax_aw => NULL()
REAL(KIND=dp) :: error
REAL(KIND=dp) :: error = 0.0_dp
END TYPE

TYPE eri_mme_param
INTEGER :: n_minimax
REAL(KIND=dp), DIMENSION(3, 3) :: hmat, h_inv
REAL(KIND=dp) :: vol
LOGICAL :: is_ortho
REAL(KIND=dp) :: cutoff
LOGICAL :: do_calib_cutoff
LOGICAL :: do_error_est
LOGICAL :: print_calib
REAL(KIND=dp) :: cutoff_min, cutoff_max, cutoff_delta, &
cutoff_eps
REAL(KIND=dp) :: err_mm, err_c
REAL(KIND=dp) :: mm_delta
REAL(KIND=dp) :: G_min, R_min
LOGICAL :: is_valid
LOGICAL :: debug
REAL(KIND=dp) :: debug_delta
INTEGER :: debug_nsum
REAL(KIND=dp) :: C_mm
INTEGER :: unit_nr
REAL(KIND=dp) :: sum_precision
INTEGER :: n_grids
INTEGER :: n_minimax = 0
REAL(KIND=dp), DIMENSION(3, 3) :: hmat = 0.0_dp, h_inv = 0.0_dp
REAL(KIND=dp) :: vol = 0.0_dp
LOGICAL :: is_ortho = .FALSE.
REAL(KIND=dp) :: cutoff = 0.0_dp
LOGICAL :: do_calib_cutoff = .FALSE.
LOGICAL :: do_error_est = .FALSE.
LOGICAL :: print_calib = .FALSE.
REAL(KIND=dp) :: cutoff_min = 0.0_dp, cutoff_max = 0.0_dp, cutoff_delta = 0.0_dp, &
cutoff_eps = 0.0_dp
REAL(KIND=dp) :: err_mm = 0.0_dp, err_c = 0.0_dp
REAL(KIND=dp) :: mm_delta = 0.0_dp
REAL(KIND=dp) :: G_min = 0.0_dp, R_min = 0.0_dp
LOGICAL :: is_valid = .FALSE.
LOGICAL :: debug = .FALSE.
REAL(KIND=dp) :: debug_delta = 0.0_dp
INTEGER :: debug_nsum = 0
REAL(KIND=dp) :: C_mm = 0.0_dp
INTEGER :: unit_nr = -1
REAL(KIND=dp) :: sum_precision = 0.0_dp
INTEGER :: n_grids = 0
TYPE(minimax_grid), DIMENSION(:), &
ALLOCATABLE :: minimax_grid
REAL(KIND=dp) :: zet_max, zet_min
INTEGER :: l_mm, l_max_zet
INTEGER :: potential
REAL(KIND=dp) :: pot_par
REAL(KIND=dp) :: zet_max = 0.0_dp, zet_min = 0.0_dp
INTEGER :: l_mm = -1, l_max_zet = -1
INTEGER :: potential = 0
REAL(KIND=dp) :: pot_par = 0.0_dp
END TYPE eri_mme_param

CONTAINS
Expand Down
9 changes: 3 additions & 6 deletions src/force_env_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ MODULE force_env_methods
USE string_utilities, ONLY: compress
USE virial_methods, ONLY: write_stress_tensor,&
write_stress_tensor_components
USE virial_types, ONLY: cp_virial,&
symmetrize_virial,&
USE virial_types, ONLY: symmetrize_virial,&
virial_p_type,&
virial_type,&
zero_virial
Expand Down Expand Up @@ -939,7 +938,6 @@ SUBROUTINE mixed_energy_forces(force_env, calculate_forces)
NULLIFY (subsystems(iforce_eval)%subsys, particles(iforce_eval)%list)
NULLIFY (results(iforce_eval)%results, virials(iforce_eval)%virial)
ALLOCATE (virials(iforce_eval)%virial)
CALL zero_virial(virials(iforce_eval)%virial)
CALL cp_result_create(results(iforce_eval)%results)
IF (.NOT. ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env)) CYCLE
! From this point on the error is the sub_error
Expand Down Expand Up @@ -985,7 +983,7 @@ SUBROUTINE mixed_energy_forces(force_env, calculate_forces)
virial=loc_virial, results=loc_results)
energies(iforce_eval) = energy
glob_natoms(iforce_eval) = natom
CALL cp_virial(loc_virial, virials(iforce_eval)%virial)
virials(iforce_eval)%virial = loc_virial
CALL cp_result_copy(loc_results, results(iforce_eval)%results)
END IF
! Deallocate map_index array
Expand Down Expand Up @@ -1246,7 +1244,6 @@ SUBROUTINE mixed_cdft_energy_forces(force_env, calculate_forces, particles, ener
NULLIFY (subsystems(iforce_eval)%subsys, particles(iforce_eval)%list)
NULLIFY (results(iforce_eval)%results, virials(iforce_eval)%virial)
ALLOCATE (virials(iforce_eval)%virial)
CALL zero_virial(virials(iforce_eval)%virial)
CALL cp_result_create(results(iforce_eval)%results)
IF (.NOT. ASSOCIATED(force_env%sub_force_env(iforce_eval)%force_env)) CYCLE
! Get all available subsys
Expand Down Expand Up @@ -1307,7 +1304,7 @@ SUBROUTINE mixed_cdft_energy_forces(force_env, calculate_forces, particles, ener
virial=loc_virial, results=loc_results)
energies(iforce_eval) = energy
glob_natoms(iforce_eval) = natom
CALL cp_virial(loc_virial, virials(iforce_eval)%virial)
virials(iforce_eval)%virial = loc_virial
CALL cp_result_copy(loc_results, results(iforce_eval)%results)
END IF
! Deallocate map_index array
Expand Down
4 changes: 1 addition & 3 deletions src/motion/averages_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ MODULE averages_types
USE kinds, ONLY: default_string_length,&
dp
USE md_ener_types, ONLY: md_ener_type
USE virial_types, ONLY: virial_type,&
zero_virial
USE virial_types, ONLY: virial_type
#include "../base/base_uses.f90"

IMPLICIT NONE
Expand Down Expand Up @@ -120,7 +119,6 @@ SUBROUTINE create_averages(averages, averages_section, virial_avg, force_env)
IF (PRESENT(virial_avg)) THEN
IF (virial_avg) THEN
ALLOCATE (averages%virial)
CALL zero_virial(averages%virial)
END IF
END IF
CALL section_vals_val_get(averages_section, "AVERAGE_COLVAR", l_val=do_colvars)
Expand Down
11 changes: 4 additions & 7 deletions src/motion/gopt_f77_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ SUBROUTINE cp_eval_at(gopt_env, x, f, gradient, master, &
USE particle_list_types, ONLY: particle_list_type
USE particle_methods, ONLY: write_structure_data
USE virial_methods, ONLY: virial_update
USE virial_types, ONLY: cp_virial, &
virial_type, zero_virial
USE virial_types, ONLY: virial_type
USE cp_log_handling, ONLY: cp_add_default_logger, &
cp_rm_default_logger
USE space_groups_types, ONLY: spgr_type
Expand Down Expand Up @@ -193,13 +192,12 @@ SUBROUTINE cp_eval_at(gopt_env, x, f, gradient, master, &
! Compute the pressure tensor
BLOCK
TYPE(virial_type) :: virial_avg
CALL zero_virial(virial_avg)
CALL force_env_calc_energy_force(gopt_env%force_env, &
calc_force=PRESENT(gradient), &
require_consistent_energy_force=gopt_env%require_consistent_energy_force)
! Possibly take the potential energy
CALL force_env_get(gopt_env%force_env, potential_energy=potential_energy)
CALL cp_virial(virial, virial_avg)
virial_avg = virial
CALL virial_update(virial_avg, subsys, para_env)
IF (PRESENT(f)) THEN
CALL force_env_get(gopt_env%force_env, potential_energy=f)
Expand Down Expand Up @@ -244,7 +242,6 @@ SUBROUTINE cp_eval_at(gopt_env, x, f, gradient, master, &
! Compute the pressure tensor
BLOCK
TYPE(virial_type) :: virial_avg
CALL zero_virial(virial_avg)
IF (my_final_evaluation) THEN
CALL force_env_calc_energy_force(gopt_env%force_env, &
calc_force=PRESENT(gradient), &
Expand All @@ -266,7 +263,7 @@ SUBROUTINE cp_eval_at(gopt_env, x, f, gradient, master, &
CALL cp_add_default_logger(new_logger)
CALL cp_geo_opt(gopt_env%force_env, gopt_env%globenv, eval_opt_geo=.FALSE.)
CALL force_env_get(gopt_env%force_env, potential_energy=potential_energy)
CALL cp_virial(virial, virial_avg)
virial_avg = virial
CASE (default_cell_md_id)
work => section_vals_get_subs_vals(gopt_env%motion_section, "MD")
avgs_section => section_vals_get_subs_vals(work, "AVERAGES")
Expand All @@ -288,7 +285,7 @@ SUBROUTINE cp_eval_at(gopt_env, x, f, gradient, master, &
CALL qs_mol_dyn(gopt_env%force_env, gopt_env%globenv, averages, rm_restart_info=.FALSE.)
! Retrieve the average of the stress tensor and the average of the potential energy
potential_energy = averages%avepot
CALL cp_virial(averages%virial, virial_avg)
virial_avg = averages%virial
CALL release_averages(averages)
CASE DEFAULT
CPABORT("")
Expand Down

0 comments on commit 07ce178

Please sign in to comment.