Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief types used in the flexible partitioning scheme
10 : !> \par History
11 : !> 04.2006 [Joost VandeVondele]
12 : !> \author Joost VandeVondele
13 : ! **************************************************************************************************
14 : MODULE fp_types
15 : USE cp_log_handling, ONLY: cp_get_default_logger,&
16 : cp_logger_type
17 : USE cp_output_handling, ONLY: cp_print_key_finished_output,&
18 : cp_print_key_unit_nr
19 : USE input_section_types, ONLY: section_vals_get,&
20 : section_vals_get_subs_vals,&
21 : section_vals_release,&
22 : section_vals_retain,&
23 : section_vals_type,&
24 : section_vals_val_get
25 : USE kinds, ONLY: dp
26 : #include "./base/base_uses.f90"
27 :
28 : IMPLICIT NONE
29 : PRIVATE
30 :
31 : PUBLIC :: fp_type
32 : PUBLIC :: fp_env_create, fp_env_release, fp_env_read, fp_env_write
33 :
34 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'fp_types'
35 :
36 : ! **************************************************************************************************
37 : TYPE fp_type
38 :
39 : ! input related objects
40 : LOGICAL :: use_fp = .FALSE.
41 :
42 : INTEGER :: central_atom = -1
43 : INTEGER, DIMENSION(:), POINTER :: inner_atoms => NULL(), outer_atoms => NULL()
44 : REAL(KIND=dp) :: inner_radius = 0.0_dp, outer_radius = 0.0_dp
45 : REAL(KIND=dp) :: strength = 0.0_dp, smooth_width = 0.0_dp
46 : LOGICAL :: bias = .FALSE.
47 : REAL(KIND=dp) :: temperature = 0.0_dp
48 : TYPE(section_vals_type), POINTER :: print_section => NULL()
49 :
50 : ! computed during runs
51 : INTEGER :: i1 = -1, i2 = -1, o1 = -1, o2 = -1
52 : REAL(KIND=dp) :: ri1 = 0.0_dp, ri2 = 0.0_dp, ro1 = 0.0_dp, ro2 = 0.0_dp
53 : REAL(KIND=dp) :: weight = 0.0_dp, comb_weight = 0.0_dp, bias_weight = 0.0_dp
54 : REAL(KIND=dp) :: energy = 0.0_dp, bias_energy = 0.0_dp, restraint_energy = 0.0_dp
55 : END TYPE fp_type
56 :
57 : CONTAINS
58 :
59 : ! **************************************************************************************************
60 : !> \brief create retain release the flexible partitioning environment
61 : !> \param fp_env ...
62 : !> \par History
63 : !> 04.2006 created [Joost VandeVondele]
64 : ! **************************************************************************************************
65 8505 : PURE SUBROUTINE fp_env_create(fp_env)
66 : TYPE(fp_type), INTENT(OUT) :: fp_env
67 :
68 : fp_env%use_fp = .FALSE.
69 : NULLIFY (fp_env%inner_atoms)
70 : NULLIFY (fp_env%outer_atoms)
71 : NULLIFY (fp_env%print_section)
72 :
73 8505 : END SUBROUTINE fp_env_create
74 :
75 : ! **************************************************************************************************
76 : !> \brief ...
77 : !> \param fp_env ...
78 : ! **************************************************************************************************
79 8505 : SUBROUTINE fp_env_release(fp_env)
80 : TYPE(fp_type), INTENT(INOUT) :: fp_env
81 :
82 8505 : IF (ASSOCIATED(fp_env%inner_atoms)) DEALLOCATE (fp_env%inner_atoms)
83 8505 : IF (ASSOCIATED(fp_env%outer_atoms)) DEALLOCATE (fp_env%outer_atoms)
84 8505 : IF (ASSOCIATED(fp_env%print_section)) CALL section_vals_release(fp_env%print_section)
85 8505 : fp_env%use_fp = .FALSE.
86 :
87 8505 : END SUBROUTINE fp_env_release
88 :
89 : ! **************************************************************************************************
90 : !> \brief reads the corresponding input section and stores it in the fp_env
91 : !> \param fp_env ...
92 : !> \param fp_section ...
93 : !> \par History
94 : !> 04.2006 created [Joost VandeVondele]
95 : ! **************************************************************************************************
96 8505 : SUBROUTINE fp_env_read(fp_env, fp_section)
97 : TYPE(fp_type), INTENT(INOUT) :: fp_env
98 : TYPE(section_vals_type), POINTER :: fp_section
99 :
100 : CHARACTER(len=*), PARAMETER :: routineN = 'fp_env_read'
101 :
102 : INTEGER :: handle
103 8505 : INTEGER, DIMENSION(:), POINTER :: tmplist
104 :
105 8505 : CALL timeset(routineN, handle)
106 8505 : CALL section_vals_get(fp_section, explicit=fp_env%use_fp)
107 8505 : IF (fp_env%use_fp) THEN
108 2 : CALL section_vals_val_get(fp_section, "CENTRAL_ATOM", i_val=fp_env%central_atom)
109 :
110 2 : CALL section_vals_val_get(fp_section, "INNER_ATOMS", i_vals=tmplist)
111 6 : ALLOCATE (fp_env%inner_atoms(SIZE(tmplist, 1)))
112 18 : fp_env%inner_atoms = tmplist
113 :
114 2 : CALL section_vals_val_get(fp_section, "OUTER_ATOMS", i_vals=tmplist)
115 6 : ALLOCATE (fp_env%outer_atoms(SIZE(tmplist, 1)))
116 48 : fp_env%outer_atoms = tmplist
117 :
118 2 : CALL section_vals_val_get(fp_section, "INNER_RADIUS", r_val=fp_env%inner_radius)
119 2 : CALL section_vals_val_get(fp_section, "OUTER_RADIUS", r_val=fp_env%outer_radius)
120 2 : CALL section_vals_val_get(fp_section, "STRENGTH", r_val=fp_env%strength)
121 2 : CALL section_vals_val_get(fp_section, "SMOOTH_WIDTH", r_val=fp_env%smooth_width)
122 2 : CALL section_vals_val_get(fp_section, "BIAS", l_val=fp_env%bias)
123 2 : CALL section_vals_val_get(fp_section, "TEMPERATURE", r_val=fp_env%temperature)
124 :
125 2 : fp_env%print_section => section_vals_get_subs_vals(fp_section, "WEIGHTS")
126 2 : CALL section_vals_retain(fp_env%print_section)
127 : END IF
128 8505 : CALL timestop(handle)
129 :
130 8505 : END SUBROUTINE fp_env_read
131 :
132 : ! **************************************************************************************************
133 : !> \brief writes information concerning the fp_env to the output
134 : !> \param fp_env ...
135 : !> \param fp_section ...
136 : !> \par History
137 : !> 04.2006 created [Joost VandeVondele]
138 : ! **************************************************************************************************
139 8505 : SUBROUTINE fp_env_write(fp_env, fp_section)
140 : TYPE(fp_type), INTENT(IN) :: fp_env
141 : TYPE(section_vals_type), POINTER :: fp_section
142 :
143 : CHARACTER(len=*), PARAMETER :: routineN = 'fp_env_write'
144 :
145 : INTEGER :: handle, output_unit
146 : TYPE(cp_logger_type), POINTER :: logger
147 : TYPE(section_vals_type), POINTER :: PRINT
148 :
149 8505 : CALL timeset(routineN, handle)
150 8505 : logger => cp_get_default_logger()
151 :
152 8505 : IF (fp_env%use_fp) THEN
153 2 : PRINT => section_vals_get_subs_vals(fp_section, "CONTROL")
154 2 : output_unit = cp_print_key_unit_nr(logger, PRINT, "", extension=".Log")
155 2 : IF (output_unit > 0) THEN
156 : WRITE (UNIT=output_unit, FMT="(T2,A,T79,A)") &
157 1 : "FP| Flexible partitioning is ", "ON"
158 : WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
159 1 : "FP| Central atom ", fp_env%central_atom
160 : WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
161 1 : "FP| number of inner atoms", SIZE(fp_env%inner_atoms, 1)
162 9 : WRITE (UNIT=output_unit, FMT="(1(T2,8I8))") fp_env%inner_atoms
163 : WRITE (UNIT=output_unit, FMT="(T2,A,T71,I10)") &
164 1 : "FP| number of outer atoms", SIZE(fp_env%outer_atoms, 1)
165 24 : WRITE (UNIT=output_unit, FMT="(1(T2,8I8))") fp_env%outer_atoms
166 : WRITE (UNIT=output_unit, FMT="(T2,A,T61,F20.10)") &
167 1 : "FP| inner radius [a.u.] ", fp_env%inner_radius
168 : WRITE (UNIT=output_unit, FMT="(T2,A,T61,F20.10)") &
169 1 : "FP| outer radius [a.u.] ", fp_env%outer_radius
170 : WRITE (UNIT=output_unit, FMT="(T2,A,T61,F20.10)") &
171 1 : "FP| reflecting restraint strength ", fp_env%strength
172 1 : IF (fp_env%bias) THEN
173 : WRITE (UNIT=output_unit, FMT="(T2,A,T79,A)") &
174 1 : "FP| Flexible partitioning bias is ", "ON"
175 : WRITE (UNIT=output_unit, FMT="(T2,A,T61,F20.10)") &
176 1 : "FP| bias temperature [kT a.u.]", fp_env%temperature
177 : WRITE (UNIT=output_unit, FMT="(T2,A,T61,F20.10)") &
178 1 : "FP| smooth width [a.u.] ", fp_env%smooth_width
179 : ELSE
180 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A)") &
181 0 : "FP| Flexible partitioning bias is", "OFF"
182 : END IF
183 : END IF
184 2 : CALL cp_print_key_finished_output(output_unit, logger, PRINT, "")
185 : END IF
186 8505 : CALL timestop(handle)
187 :
188 8505 : END SUBROUTINE fp_env_write
189 :
190 0 : END MODULE fp_types
|