Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Input definition and setup for EEQ model
10 : !> \author JGH [2024]
11 : ! **************************************************************************************************
12 : MODULE eeq_input
13 : USE input_keyword_types, ONLY: keyword_create,&
14 : keyword_release,&
15 : keyword_type
16 : USE input_section_types, ONLY: section_add_keyword,&
17 : section_create,&
18 : section_type,&
19 : section_vals_type,&
20 : section_vals_val_get
21 : USE kinds, ONLY: dp
22 : #include "./base/base_uses.f90"
23 :
24 : IMPLICIT NONE
25 : PRIVATE
26 :
27 : TYPE eeq_solver_type
28 : LOGICAL :: direct = .FALSE.
29 : LOGICAL :: sparse = .FALSE.
30 : REAL(KIND=dp) :: eps_diis = 1.0E-09_dp
31 : REAL(KIND=dp) :: alpha = 0.75_dp
32 : INTEGER :: mdiis = 12
33 : INTEGER :: sdiis = 3
34 : INTEGER :: max_diis = 500
35 : INTEGER :: sparse_threshold = 256
36 : END TYPE eeq_solver_type
37 :
38 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'eeq_input'
39 :
40 : PUBLIC :: eeq_solver_type
41 : PUBLIC :: read_eeq_param
42 : PUBLIC :: create_eeq_control_section
43 :
44 : CONTAINS
45 :
46 : ! **************************************************************************************************
47 : !> \brief ...
48 : !> \param section ...
49 : ! **************************************************************************************************
50 97745 : SUBROUTINE create_eeq_control_section(section)
51 : TYPE(section_type), POINTER :: section
52 :
53 : TYPE(keyword_type), POINTER :: keyword
54 :
55 97745 : CPASSERT(.NOT. ASSOCIATED(section))
56 : CALL section_create(section, __LOCATION__, name="EEQ", &
57 : description="Parameters needed for EEQ method and solver", &
58 97745 : n_keywords=1, n_subsections=1, repeats=.FALSE.)
59 :
60 97745 : NULLIFY (keyword)
61 : CALL keyword_create(keyword, __LOCATION__, name="DIRECT", &
62 : description="Use a direct method to solve the EEQ equations in PBC (matrix solver)", &
63 97745 : usage="DIRECT", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
64 97745 : CALL section_add_keyword(section, keyword)
65 97745 : CALL keyword_release(keyword)
66 :
67 : CALL keyword_create(keyword, __LOCATION__, name="SPARSE", &
68 : description="Use the matrix-free projected-CG solver for periodic EEQ. "// &
69 : "The short-range response is stored sparsely and the translationally invariant "// &
70 : "long-range Coulomb response is applied by the FFT-based SPME operator. "// &
71 : "This path is shared by methods using CP2K EEQ charges, including GFN0-xTB "// &
72 : "and the internal DFT-D4 implementation.", &
73 97745 : usage="SPARSE", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
74 97745 : CALL section_add_keyword(section, keyword)
75 97745 : CALL keyword_release(keyword)
76 :
77 : CALL keyword_create(keyword, __LOCATION__, name="SPARSE_THRESHOLD", &
78 : description="Automatically use the sparse periodic EEQ solver at or above "// &
79 : "this number of atoms for every method using CP2K EEQ charges. A non-positive "// &
80 : "value disables automatic selection.", &
81 97745 : usage="SPARSE_THRESHOLD 256", default_i_val=256)
82 97745 : CALL section_add_keyword(section, keyword)
83 97745 : CALL keyword_release(keyword)
84 :
85 : CALL keyword_create(keyword, __LOCATION__, name="EPS_DIIS", &
86 : description="Accuracy for the iterative solver.", &
87 97745 : usage="EPS_DIIS 1.0E-10", default_r_val=1.0e-10_dp)
88 97745 : CALL section_add_keyword(section, keyword)
89 97745 : CALL keyword_release(keyword)
90 :
91 : CALL keyword_create(keyword, __LOCATION__, name="ALPHA", &
92 : description="Step length of initial steepest descent steps.", &
93 97745 : usage="ALPHA 1.0", default_r_val=0.75_dp)
94 97745 : CALL section_add_keyword(section, keyword)
95 97745 : CALL keyword_release(keyword)
96 :
97 : CALL keyword_create(keyword, __LOCATION__, name="MAX_DIIS", &
98 : description="Max. number of iterations for EEQ solver.", &
99 97745 : usage="MAX_DIIS 100", default_i_val=500)
100 97745 : CALL section_add_keyword(section, keyword)
101 97745 : CALL keyword_release(keyword)
102 :
103 : CALL keyword_create(keyword, __LOCATION__, name="MDIIS", &
104 : description="Max. number of DIIS vectors used.", &
105 97745 : usage="MDIIS 10", default_i_val=12)
106 97745 : CALL section_add_keyword(section, keyword)
107 97745 : CALL keyword_release(keyword)
108 :
109 : CALL keyword_create(keyword, __LOCATION__, name="SDIIS", &
110 : description="Number of vectors accumulated before starting DIIS.", &
111 97745 : usage="SDIIS 4", default_i_val=3)
112 97745 : CALL section_add_keyword(section, keyword)
113 97745 : CALL keyword_release(keyword)
114 :
115 97745 : END SUBROUTINE create_eeq_control_section
116 :
117 : ! **************************************************************************************************
118 : !> \brief ...
119 : !> \param eeq_section ...
120 : !> \param eeq_sparam ...
121 : ! **************************************************************************************************
122 1272 : SUBROUTINE read_eeq_param(eeq_section, eeq_sparam)
123 :
124 : TYPE(section_vals_type), POINTER :: eeq_section
125 : TYPE(eeq_solver_type), INTENT(INOUT) :: eeq_sparam
126 :
127 1272 : CALL section_vals_val_get(eeq_section, "DIRECT", l_val=eeq_sparam%direct)
128 1272 : CALL section_vals_val_get(eeq_section, "SPARSE", l_val=eeq_sparam%sparse)
129 1272 : CALL section_vals_val_get(eeq_section, "SPARSE_THRESHOLD", i_val=eeq_sparam%sparse_threshold)
130 1272 : CALL section_vals_val_get(eeq_section, "EPS_DIIS", r_val=eeq_sparam%eps_diis)
131 1272 : CALL section_vals_val_get(eeq_section, "ALPHA", r_val=eeq_sparam%alpha)
132 1272 : CALL section_vals_val_get(eeq_section, "MAX_DIIS", i_val=eeq_sparam%max_diis)
133 1272 : CALL section_vals_val_get(eeq_section, "MDIIS", i_val=eeq_sparam%mdiis)
134 1272 : CALL section_vals_val_get(eeq_section, "SDIIS", i_val=eeq_sparam%sdiis)
135 :
136 1272 : END SUBROUTINE read_eeq_param
137 :
138 0 : END MODULE eeq_input
|