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 Methods and functions on the EIP environment
10 : !> \par History
11 : !> 03.2006 initial create [tdk]
12 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
13 : ! **************************************************************************************************
14 : MODULE eip_environment
15 : USE atomic_kind_types, ONLY: atomic_kind_type,&
16 : get_atomic_kind
17 : USE cell_types, ONLY: cell_type
18 : USE cp_subsys_methods, ONLY: cp_subsys_create
19 : USE cp_subsys_types, ONLY: cp_subsys_type
20 : USE distribution_1d_types, ONLY: distribution_1d_release,&
21 : distribution_1d_type
22 : USE distribution_methods, ONLY: distribute_molecules_1d
23 : USE eip_environment_types, ONLY: eip_env_set,&
24 : eip_environment_type
25 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
26 : section_vals_type,&
27 : section_vals_val_get
28 : USE kinds, ONLY: default_string_length,&
29 : dp
30 : USE message_passing, ONLY: mp_para_env_type
31 : USE molecule_kind_types, ONLY: molecule_kind_type,&
32 : write_molecule_kind_set
33 : USE molecule_types, ONLY: molecule_type
34 : USE particle_methods, ONLY: write_fist_particle_coordinates,&
35 : write_particle_distances,&
36 : write_structure_data
37 : USE particle_types, ONLY: particle_type
38 : #include "./base/base_uses.f90"
39 :
40 : IMPLICIT NONE
41 :
42 : PRIVATE
43 :
44 : ! *** Global parameters ***
45 :
46 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'eip_environment'
47 :
48 : ! *** Public subroutines ***
49 :
50 : PUBLIC :: eip_init
51 :
52 : CONTAINS
53 :
54 : ! **************************************************************************************************
55 : !> \brief Initialize the eip environment
56 : !> \param eip_env The eip environment to retain
57 : !> \param root_section ...
58 : !> \param para_env ...
59 : !> \param force_env_section ...
60 : !> \param subsys_section ...
61 : !> \par History
62 : !> 03.2006 initial create [tdk]
63 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
64 : ! **************************************************************************************************
65 2 : SUBROUTINE eip_init(eip_env, root_section, para_env, force_env_section, &
66 : subsys_section)
67 : TYPE(eip_environment_type), POINTER :: eip_env
68 : TYPE(section_vals_type), POINTER :: root_section
69 : TYPE(mp_para_env_type), POINTER :: para_env
70 : TYPE(section_vals_type), POINTER :: force_env_section, subsys_section
71 :
72 : CHARACTER(len=*), PARAMETER :: routineN = 'eip_init'
73 :
74 : INTEGER :: handle
75 : TYPE(cp_subsys_type), POINTER :: subsys
76 : TYPE(section_vals_type), POINTER :: colvar_section, eip_section
77 :
78 2 : CALL timeset(routineN, handle)
79 :
80 2 : CPASSERT(ASSOCIATED(eip_env))
81 :
82 : ! nullifying pointers
83 2 : NULLIFY (colvar_section, eip_section, subsys)
84 :
85 2 : IF (.NOT. ASSOCIATED(subsys_section)) THEN
86 0 : subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
87 : END IF
88 2 : colvar_section => section_vals_get_subs_vals(subsys_section, "COLVAR")
89 2 : eip_section => section_vals_get_subs_vals(force_env_section, "EIP")
90 :
91 : CALL eip_env_set(eip_env=eip_env, eip_input=eip_section, &
92 2 : force_env_input=force_env_section)
93 :
94 2 : CALL cp_subsys_create(subsys, para_env, root_section)
95 :
96 : CALL eip_init_subsys(eip_env=eip_env, subsys=subsys, &
97 2 : subsys_section=subsys_section)
98 :
99 2 : CALL timestop(handle)
100 :
101 2 : END SUBROUTINE eip_init
102 :
103 : ! **************************************************************************************************
104 : !> \brief Initialize the eip environment
105 : !> \param eip_env The eip environment of matter
106 : !> \param subsys the subsys
107 : !> \param subsys_section ...
108 : !> \par History
109 : !> 03.2006 initial create [tdk]
110 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
111 : ! **************************************************************************************************
112 2 : SUBROUTINE eip_init_subsys(eip_env, subsys, subsys_section)
113 : TYPE(eip_environment_type), POINTER :: eip_env
114 : TYPE(cp_subsys_type), POINTER :: subsys
115 : TYPE(section_vals_type), POINTER :: subsys_section
116 :
117 : CHARACTER(len=*), PARAMETER :: routineN = 'eip_init_subsys'
118 :
119 : INTEGER :: handle, natom
120 2 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
121 : TYPE(cell_type), POINTER :: my_cell, my_cell_ref
122 : TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
123 2 : TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
124 2 : TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
125 2 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
126 :
127 : ! ------------------------------------------------------------------------
128 :
129 2 : CALL timeset(routineN, handle)
130 :
131 : NULLIFY (atomic_kind_set, molecule_kind_set, particle_set, molecule_set, &
132 2 : my_cell, my_cell_ref, local_molecules, local_particles)
133 :
134 2 : particle_set => subsys%particles%els
135 2 : atomic_kind_set => subsys%atomic_kinds%els
136 2 : molecule_kind_set => subsys%molecule_kinds%els
137 2 : molecule_set => subsys%molecules%els
138 2 : my_cell => subsys%cell
139 2 : my_cell_ref => subsys%cell_ref
140 :
141 : ! *** Set up cell ***
142 : CALL eip_env_set(eip_env=eip_env, subsys=subsys, &
143 : cell_ref=my_cell_ref, &
144 2 : use_ref_cell=subsys%use_ref_cell)
145 :
146 : ! *** Print the molecule kind set ***
147 2 : CALL write_molecule_kind_set(molecule_kind_set, subsys_section)
148 :
149 : ! *** Print the atomic coordinates
150 2 : CALL write_fist_particle_coordinates(particle_set, subsys_section)
151 : CALL write_particle_distances(particle_set, cell=my_cell, &
152 2 : subsys_section=subsys_section)
153 : CALL write_structure_data(particle_set, cell=my_cell, &
154 2 : input_section=subsys_section)
155 :
156 : ! *** Distribute molecules and atoms using the new data structures ***
157 : CALL distribute_molecules_1d(atomic_kind_set=atomic_kind_set, &
158 : particle_set=particle_set, &
159 : local_particles=local_particles, &
160 : molecule_kind_set=molecule_kind_set, &
161 : molecule_set=molecule_set, &
162 : local_molecules=local_molecules, &
163 2 : force_env_section=eip_env%force_env_input)
164 :
165 2 : natom = SIZE(particle_set)
166 :
167 6 : ALLOCATE (eip_env%eip_forces(3, natom))
168 :
169 8002 : eip_env%eip_forces(:, :) = 0.0_dp
170 :
171 : CALL eip_env_set(eip_env=eip_env, &
172 : local_molecules=local_molecules, &
173 2 : local_particles=local_particles)
174 :
175 2 : CALL distribution_1d_release(local_particles)
176 2 : CALL distribution_1d_release(local_molecules)
177 :
178 2 : CALL eip_init_model(eip_env=eip_env)
179 :
180 2 : CALL timestop(handle)
181 :
182 2 : END SUBROUTINE eip_init_subsys
183 :
184 : ! **************************************************************************************************
185 : !> \brief Initialize the empirical interatomic potnetial (force field) model
186 : !> \param eip_env The eip environment to retain
187 : !> \par History
188 : !> 03.2006 initial create [tdk]
189 : !> \author Thomas D. Kuehne (tkuehne@phys.chem.ethz.ch)
190 : ! **************************************************************************************************
191 2 : SUBROUTINE eip_init_model(eip_env)
192 : TYPE(eip_environment_type), POINTER :: eip_env
193 :
194 : CHARACTER(len=*), PARAMETER :: routineN = 'eip_init_model'
195 :
196 : CHARACTER(LEN=default_string_length) :: eip_atomic_kind_name
197 : INTEGER :: handle, i
198 2 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
199 : TYPE(atomic_kind_type), POINTER :: atomic_kind_ptr
200 : TYPE(section_vals_type), POINTER :: eip_section
201 :
202 : ! ------------------------------------------------------------------------
203 :
204 2 : CALL timeset(routineN, handle)
205 :
206 2 : NULLIFY (atomic_kind_set, atomic_kind_ptr, eip_section)
207 :
208 : eip_section => section_vals_get_subs_vals(eip_env%force_env_input, &
209 2 : "EIP")
210 :
211 2 : atomic_kind_set => eip_env%subsys%atomic_kinds%els
212 :
213 : ! loop over all kinds
214 4 : DO i = 1, SIZE(atomic_kind_set)
215 2 : atomic_kind_ptr => eip_env%subsys%atomic_kinds%els(i)
216 : CALL get_atomic_kind(atomic_kind=atomic_kind_ptr, &
217 2 : name=eip_atomic_kind_name)
218 2 : SELECT CASE (eip_atomic_kind_name)
219 : CASE ("SI", "Si")
220 : CALL section_vals_val_get(section_vals=eip_section, &
221 : keyword_name="EIP-Model", &
222 2 : i_val=eip_env%eip_model)
223 : CASE DEFAULT
224 2 : CPABORT("EIP models for other elements than Si isn't implemented yet.")
225 : END SELECT
226 : END DO
227 :
228 2 : CALL timestop(handle)
229 :
230 2 : END SUBROUTINE eip_init_model
231 :
232 : END MODULE eip_environment
|