Skip to content

Commit

Permalink
Update sirius version and sirius input files parameters (#1627)
Browse files Browse the repository at this point in the history
Update sirius version and sirius input files parameters
  • Loading branch information
mtaillefumier committed Sep 15, 2021
1 parent 212cbeb commit 524554b
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 103 deletions.
84 changes: 60 additions & 24 deletions src/input_cp2k_pwdft.F
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ SUBROUTINE create_pwdft_section(section)
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)

CALL create_sirius_section(subsection, 'settings')
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)

CALL create_sirius_section(subsection, 'mixer')
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)
Expand All @@ -95,6 +99,14 @@ SUBROUTINE create_pwdft_section(section)
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)

!
! uncomment these lines when nlcg is officialy supported in cp2k
!

! CALL create_sirius_section(subsection, 'nlcg')
! CALL section_add_subsection(section, subsection)
! CALL section_release(subsection)

CALL create_print_section(subsection)
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)
Expand Down Expand Up @@ -156,8 +168,7 @@ SUBROUTINE fill_in_section(section, section_name)
name = CHAR(0)
! return a non null terminated string. Stupid fortran does not understand the \0 terminated string when comparing things
CALL sirius_option_get_name_and_type(section_name, i, name, ctype)

! do not invert these two lines
! do not invert these two lines
name1 = TRIM(ADJUSTL(name))

! we need to null char since SIRIUS interface is basically C
Expand All @@ -166,7 +177,7 @@ SUBROUTINE fill_in_section(section, section_name)
! purpose the other one is useless and replaced by a dedicated in cp2k
!
! Moreover xc_functionals would need a special treatment.
IF ((name1 /= 'xc_functionals') .AND. (name1 /= 'memory_usage')) THEN
IF ((name1 /= 'xc_functionals') .AND. (name1 /= 'memory_usage') .AND. (name1 /= 'vk')) THEN
description = CHAR(0)
usage = CHAR(0)
CALL sirius_option_get_description_usage(section_name, name, description, usage)
Expand All @@ -176,50 +187,74 @@ SUBROUTINE fill_in_section(section, section_name)
CALL keyword_create(keyword, __LOCATION__, &
name=TRIM(name1), &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
! usage=TRIM(ADJUSTL(usage)), &
type_of_var=integer_t, &
repeats=.FALSE., &
default_i_val=dummy_i)
CASE (11)
CALL sirius_option_get_int(section_name, name, ivec(1), vec_length)
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
repeats=.FALSE., &
n_var=vec_length, &
default_i_vals=ivec(1:vec_length))
IF (vec_length .EQ. 0) THEN
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
type_of_var=integer_t, &
n_var=-1, &
repeats=.FALSE.)
ELSE
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
type_of_var=integer_t, &
repeats=.FALSE., &
n_var=vec_length, &
default_i_vals=ivec(1:vec_length))
END IF
CASE (2)
CALL sirius_option_get_double(section_name, name, dummy_r, vec_length)
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
! usage=TRIM(ADJUSTL(usage)), &
type_of_var=real_t, &
repeats=.FALSE., &
default_r_val=dummy_r)
CASE (12)
CALL sirius_option_get_double(section_name, name, rvec(1), vec_length)
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
repeats=.FALSE., &
n_var=vec_length, &
default_r_vals=rvec(1:vec_length))
IF (vec_length .EQ. 0) THEN
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
! usage=TRIM(ADJUSTL(usage)), &
type_of_var=real_t, &
repeats=.FALSE., &
n_var=-1)
ELSE
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
! usage=TRIM(ADJUSTL(usage)), &
type_of_var=real_t, &
repeats=.FALSE., &
n_var=vec_length, &
default_r_vals=rvec(1:vec_length))
END IF
CASE (3)
CALL sirius_option_get_logical(section_name, name, dummy_l, vec_length)
IF (dummy_l) THEN
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
! usage=TRIM(ADJUSTL(usage)), &
type_of_var=logical_t, &
repeats=.FALSE., &
default_l_val=.TRUE., &
lone_keyword_l_val=.TRUE.)
ELSE
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
! usage=TRIM(ADJUSTL(usage)), &
type_of_var=logical_t, &
repeats=.FALSE., &
default_l_val=.FALSE., &
lone_keyword_l_val=.TRUE.)
Expand All @@ -232,7 +267,8 @@ SUBROUTINE fill_in_section(section, section_name)
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
!usage=TRIM(ADJUSTL(usage)), &
type_of_var=logical_t, &
repeats=.FALSE., &
n_var=vec_length, &
default_l_vals=lvecl(1:vec_length))
Expand All @@ -251,7 +287,7 @@ SUBROUTINE fill_in_section(section, section_name)
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
! usage=TRIM(ADJUSTL(usage)), &
repeats=.FALSE., &
enum_i_vals=enum_i_val(1:num_possible_values), &
enum_c_vals=possible_values(1:num_possible_values), &
Expand All @@ -260,7 +296,7 @@ SUBROUTINE fill_in_section(section, section_name)
CALL keyword_create(keyword, __LOCATION__, &
name=name1, &
description=TRIM(ADJUSTL(description)), &
usage=TRIM(ADJUSTL(usage)), &
! usage=TRIM(ADJUSTL(usage)), &
type_of_var=char_t, &
default_c_val="", &
repeats=.FALSE.)
Expand Down
15 changes: 2 additions & 13 deletions src/pwdft_environment.F
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,11 @@ SUBROUTINE pwdft_init(pwdft_env, root_section, para_env, force_env_section, subs
! Print symmetry information
CALL write_symmetry(particle_set, my_cell, subsys_section)

IF (iw > 0) THEN
WRITE (iw, '(A,A,A)') " ==================================", " SIRIUS INIT ", &
"================================="
END IF
! Sirius initialization
CALL cp_sirius_create_env(pwdft_env)

IF (iw > 0) THEN
WRITE (iw, '(A,A,A)') " =========================", " SIRIUS INIT FINISHED ", &
"================================="
WRITE (iw, '(A)') "SIRIUS INIT: FINISHED"
END IF
IF (iw > 0) CALL m_flush(iw)

Expand Down Expand Up @@ -237,16 +232,10 @@ SUBROUTINE pwdft_calc_energy_force(pwdft_env, calculate_forces, calculate_stress
iw = cp_logger_get_default_io_unit(logger)

! update context for new positions/cell
IF (iw > 0) THEN
WRITE (iw, '(A,A,A)') " =============================", " SIRIUS UPDATE CONTEXT", &
"============================"
END IF
! Sirius initialization
CALL cp_sirius_update_context(pwdft_env)

IF (iw > 0) THEN
WRITE (iw, '(A,A,A)') " ====================", " SIRIUS UPDATE CONTEXT FINISHED", &
"============================"
WRITE (iw, '(A)') "SIRIUS UPDATE CONTEXT : FINISHED"
END IF
IF (iw > 0) CALL m_flush(iw)

Expand Down
74 changes: 41 additions & 33 deletions src/sirius_interface.F
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ MODULE sirius_interface
qs_subsys_type
USE sirius, ONLY: &
sirius_add_atom, sirius_add_atom_type, sirius_add_atom_type_radial_function, &
sirius_create_context, sirius_create_ground_state, sirius_create_kset_from_grid, &
sirius_finalize, sirius_find_ground_state, sirius_get_band_energies, &
sirius_get_band_occupancies, sirius_get_energy, sirius_get_forces, &
sirius_get_kpoint_properties, sirius_get_num_kpoints, sirius_get_parameters, &
sirius_get_stress_tensor, sirius_import_parameters, sirius_initialize, &
sirius_initialize_context, sirius_option_add_string_to, sirius_option_get_length, &
sirius_option_get_name_and_type, sirius_option_set_double, sirius_option_set_int, &
sirius_option_set_logical, sirius_option_set_string, sirius_set_atom_position, &
sirius_set_atom_type_dion, sirius_set_atom_type_radial_grid, sirius_set_lattice_vectors, &
sirius_update_ground_state
sirius_add_xc_functional, sirius_create_context, sirius_create_ground_state, &
sirius_create_kset_from_grid, sirius_finalize, sirius_find_ground_state, &
sirius_get_band_energies, sirius_get_band_occupancies, sirius_get_energy, &
sirius_get_forces, sirius_get_kpoint_properties, sirius_get_num_kpoints, &
sirius_get_parameters, sirius_get_stress_tensor, sirius_import_parameters, &
sirius_initialize, sirius_initialize_context, sirius_option_add_string_to, &
sirius_option_get_length, sirius_option_get_name_and_type, sirius_option_set_double, &
sirius_option_set_int, sirius_option_set_logical, sirius_option_set_string, &
sirius_set_atom_position, sirius_set_atom_type_dion, sirius_set_atom_type_radial_grid, &
sirius_set_lattice_vectors, sirius_update_ground_state
USE xc_libxc, ONLY: libxc_check_existence_in_libxc
#include "./base/base_uses.f90"

Expand Down Expand Up @@ -130,7 +130,7 @@ SUBROUTINE cp_sirius_create_env(pwdft_env)
INTEGER(KIND=C_INT), DIMENSION(3) :: k_grid, k_shift
INTEGER, DIMENSION(:), POINTER :: kk
LOGICAL :: up, use_ref_cell
LOGICAL(4) :: use_symmetry
LOGICAL(4) :: use_so, use_symmetry
REAL(KIND=C_DOUBLE), ALLOCATABLE, DIMENSION(:) :: fun
REAL(KIND=C_DOUBLE), ALLOCATABLE, DIMENSION(:, :) :: dion
REAL(KIND=C_DOUBLE), DIMENSION(3) :: a1, a2, a3, v1, v2
Expand Down Expand Up @@ -183,15 +183,18 @@ SUBROUTINE cp_sirius_create_env(pwdft_env)
DO i = 1, n
CALL section_vals_val_get(xc_fun, "FUNCTIONAL", i_rep_section=i, c_val=section_name)
IF (section_name(1:3) == "XC_") THEN
CALL sirius_option_add_string_to(sctx, 'parameters', 'xc_functionals', section_name)
CALL sirius_add_xc_functional(sctx, section_name)
! CALL sirius_option_add_string_to(sctx, 'parameters', 'xc_functionals', section_name)
ELSE
CALL sirius_option_add_string_to(sctx, 'parameters', 'xc_functionals', "XC_"//section_name)
CALL sirius_add_xc_functional(sctx, "XC_"//section_name)
! CALL sirius_option_add_string_to(sctx, 'parameters', 'xc_functionals', "XC_"//section_name)
END IF
END DO
ELSE IF (libxc_check_existence_in_libxc(xc_fun)) THEN
! Here, we do not have to check whether the functional name starts with XC_
! because we only allow the shorter form w/o XC_
CALL sirius_option_add_string_to(sctx, 'parameters', 'xc_functionals', "XC_"//TRIM(xc_fun%section%name))
CALL sirius_add_xc_functional(sctx, "XC_"//TRIM(xc_fun%section%name))
! CALL sirius_option_add_string_to(sctx, 'parameters', 'xc_functionals', "XC_"//TRIM(xc_fun%section%name))
ENDIF
END DO
ENDIF
Expand All @@ -217,6 +220,7 @@ SUBROUTINE cp_sirius_create_env(pwdft_env)
k_shift(3) = kk(3)
CALL section_vals_val_get(pwdft_sub_section, "num_mag_dims", i_val=num_mag_dims)
CALL section_vals_val_get(pwdft_sub_section, "use_symmetry", l_val=use_symmetry)
CALL section_vals_val_get(pwdft_sub_section, "so_correction", l_val=use_so)
ENDIF

! import mixer section
Expand All @@ -225,12 +229,28 @@ SUBROUTINE cp_sirius_create_env(pwdft_env)
CALL cp_sirius_fill_in_section(sctx, pwdft_sub_section, "mixer")
ENDIF

! import settings section
pwdft_sub_section => section_vals_get_subs_vals(pwdft_section, "settings")
IF (ASSOCIATED(pwdft_sub_section)) THEN
CALL cp_sirius_fill_in_section(sctx, pwdft_sub_section, "settings")
ENDIF

! import solver section
pwdft_sub_section => section_vals_get_subs_vals(pwdft_section, "iterative_solver")
IF (ASSOCIATED(pwdft_sub_section)) THEN
CALL cp_sirius_fill_in_section(sctx, pwdft_sub_section, "iterative_solver")
ENDIF

!
! uncomment these lines when nlcg is officially supported
!

! import nlcg section
! pwdft_sub_section => section_vals_get_subs_vals(pwdft_section, "nlcg")
! IF (ASSOCIATED(pwdft_sub_section)) THEN
! CALL cp_sirius_fill_in_section(sctx, pwdft_sub_section, "nlcg")
! ENDIF

!CALL sirius_dump_runtime_setup(sctx, "runtime.json")
CALL sirius_import_parameters(sctx)

Expand Down Expand Up @@ -507,12 +527,11 @@ SUBROUTINE cp_sirius_fill_in_section(sctx, section, section_name)
CHARACTER(len=256) :: option_name, option_name1
CHARACTER(len=80) :: str
CHARACTER(len=80), DIMENSION(:), POINTER :: tmp
INTEGER :: ctype, elem, i, ival, j, length, &
lvalsi(16), number_of_options
INTEGER :: ctype, elem, ival, j, length, &
number_of_options
INTEGER, DIMENSION(:), POINTER :: ivals
LOGICAL :: found
LOGICAL(4) :: lval
LOGICAL(4), DIMENSION(:), POINTER :: lvals
LOGICAL :: found, lval
LOGICAL, DIMENSION(:), POINTER :: lvals
REAL(kind=dp) :: rval
REAL(kind=dp), DIMENSION(:), POINTER :: rvals

Expand All @@ -524,7 +543,7 @@ SUBROUTINE cp_sirius_fill_in_section(sctx, section, section_name)
option_name1 = TRIM(ADJUSTL(option_name))
option_name = TRIM(ADJUSTL(option_name))//CHAR(0)

IF ((option_name1 /= 'memory_usage') .AND. (option_name1 /= 'xc_functionals')) THEN
IF ((option_name1 /= 'memory_usage') .AND. (option_name1 /= 'xc_functionals') .AND. (option_name1 /= 'vk')) THEN
CALL section_vals_val_get(section, option_name1, explicit=found)
IF (found) THEN
SELECT CASE (ctype)
Expand All @@ -542,22 +561,11 @@ SUBROUTINE cp_sirius_fill_in_section(sctx, section, section_name)
CALL sirius_option_set_double(sctx, section_name, option_name, rvals(1), SIZE(rvals))
CASE (3)
CALL section_vals_val_get(section, option_name1, l_val=lval)
IF (lval) THEN
CALL sirius_option_set_logical(sctx, section_name, option_name, 1, 0)
ELSE
CALL sirius_option_set_logical(sctx, section_name, option_name, 0, 0)
ENDIF
CALL sirius_option_set_logical(sctx, section_name, option_name, lval, 1)
CASE (13)
CALL section_vals_val_get(section, option_name, l_vals=lvals)
length = SIZE(lvals)
DO i = 1, length
IF (lvals(i)) THEN
lvalsi(i) = 1
ELSE
lvalsi(i) = 0
ENDIF
END DO
CALL sirius_option_set_logical(sctx, section_name, option_name, lvalsi(1), length)
CALL sirius_option_set_logical(sctx, section_name, option_name, lvals(1), length)
CASE (4) ! string nightmare
CALL section_vals_val_get(section, option_name1, c_val=str)
str = TRIM(ADJUSTL(str))//CHAR(0)
Expand Down

0 comments on commit 524554b

Please sign in to comment.