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 : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
10 : ! **************************************************************************************************
11 : MODULE al_system_mapping
12 :
13 : USE al_system_types, ONLY: al_system_type,&
14 : al_thermo_create
15 : USE distribution_1d_types, ONLY: distribution_1d_type
16 : USE extended_system_types, ONLY: map_info_type
17 : USE input_constants, ONLY: &
18 : do_thermo_communication, do_thermo_no_communication, isokin_ensemble, langevin_ensemble, &
19 : npe_f_ensemble, npe_i_ensemble, nph_uniaxial_damped_ensemble, nph_uniaxial_ensemble, &
20 : npt_f_ensemble, npt_i_ensemble, npt_ia_ensemble, nve_ensemble, nvt_ensemble, &
21 : reftraj_ensemble
22 : USE kinds, ONLY: dp
23 : USE message_passing, ONLY: mp_para_env_type
24 : USE molecule_kind_types, ONLY: molecule_kind_type
25 : USE molecule_types, ONLY: global_constraint_type,&
26 : molecule_type
27 : USE simpar_types, ONLY: simpar_type
28 : USE thermostat_mapping, ONLY: thermostat_mapping_region
29 : USE thermostat_types, ONLY: thermostat_info_type
30 : #include "../../base/base_uses.f90"
31 :
32 : IMPLICIT NONE
33 :
34 : PRIVATE
35 :
36 : ! *** Global parameters ***
37 :
38 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'al_system_mapping'
39 :
40 : PUBLIC :: al_to_particle_mapping
41 :
42 : CONTAINS
43 :
44 : ! **************************************************************************************************
45 : !> \brief Creates the thermostatting maps
46 : !> \param thermostat_info ...
47 : !> \param simpar ...
48 : !> \param local_molecules ...
49 : !> \param molecule_set ...
50 : !> \param molecule_kind_set ...
51 : !> \param al ...
52 : !> \param para_env ...
53 : !> \param gci ...
54 : !> \author Teodoro Laino [tlaino] 10.2007- University of Zurich
55 : ! **************************************************************************************************
56 4 : SUBROUTINE al_to_particle_mapping(thermostat_info, simpar, local_molecules, &
57 : molecule_set, molecule_kind_set, al, para_env, gci)
58 :
59 : TYPE(thermostat_info_type), POINTER :: thermostat_info
60 : TYPE(simpar_type), POINTER :: simpar
61 : TYPE(distribution_1d_type), POINTER :: local_molecules
62 : TYPE(molecule_type), POINTER :: molecule_set(:)
63 : TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
64 : TYPE(al_system_type), POINTER :: al
65 : TYPE(mp_para_env_type), POINTER :: para_env
66 : TYPE(global_constraint_type), POINTER :: gci
67 :
68 : INTEGER :: i, imap, j, natoms_local, &
69 : sum_of_thermostats
70 4 : INTEGER, DIMENSION(:), POINTER :: deg_of_freedom, massive_atom_list
71 : REAL(KIND=dp) :: fac
72 : TYPE(map_info_type), POINTER :: map_info
73 :
74 4 : NULLIFY (massive_atom_list, deg_of_freedom)
75 4 : SELECT CASE (simpar%ensemble)
76 : CASE DEFAULT
77 0 : CPABORT('Unknown ensemble!')
78 : CASE (nve_ensemble, isokin_ensemble, npe_f_ensemble, npe_i_ensemble, nph_uniaxial_ensemble, &
79 : nph_uniaxial_damped_ensemble, reftraj_ensemble, langevin_ensemble)
80 0 : CPABORT('Never reach this point!')
81 : CASE (nvt_ensemble, npt_i_ensemble, npt_f_ensemble, npt_ia_ensemble)
82 :
83 : CALL setup_al_thermostat(al, thermostat_info, deg_of_freedom, &
84 : massive_atom_list, molecule_kind_set, local_molecules, molecule_set, &
85 4 : para_env, natoms_local, simpar, sum_of_thermostats, gci)
86 :
87 : ! Sum up the number of degrees of freedom on each thermostat.
88 : ! first: initialize the target
89 4 : map_info => al%map_info
90 49597 : map_info%s_kin = 0.0_dp
91 16 : DO i = 1, 3
92 49609 : DO j = 1, natoms_local
93 49605 : map_info%p_kin(i, j)%point = map_info%p_kin(i, j)%point + 1
94 : END DO
95 : END DO
96 :
97 : ! If thermostats are replicated but molecules distributed, we have to
98 : ! sum s_kin over all processors
99 4 : IF (map_info%dis_type == do_thermo_communication) CALL para_env%sum(map_info%s_kin)
100 :
101 : ! We know the total number of system thermostats.
102 4 : IF ((sum_of_thermostats == 1) .AND. (map_info%dis_type /= do_thermo_no_communication)) THEN
103 0 : fac = map_info%s_kin(1) - deg_of_freedom(1) - simpar%nfree_rot_transl
104 0 : IF (fac == 0.0_dp) THEN
105 0 : CPABORT('Zero degrees of freedom. Nothing to thermalize!')
106 : END IF
107 0 : al%nvt(1)%nkt = simpar%temp_ext*fac
108 0 : al%nvt(1)%degrees_of_freedom = FLOOR(fac)
109 : ELSE
110 49597 : DO i = 1, al%loc_num_al
111 49593 : imap = map_info%map_index(i)
112 49593 : fac = (map_info%s_kin(imap) - deg_of_freedom(i))
113 49593 : al%nvt(i)%nkt = simpar%temp_ext*fac
114 49597 : al%nvt(i)%degrees_of_freedom = FLOOR(fac)
115 : END DO
116 : END IF
117 :
118 4 : DEALLOCATE (deg_of_freedom)
119 8 : DEALLOCATE (massive_atom_list)
120 : END SELECT
121 :
122 4 : END SUBROUTINE al_to_particle_mapping
123 :
124 : ! **************************************************************************************************
125 : !> \brief Main general setup for AD_LANGEVIN thermostats
126 : !> \param al ...
127 : !> \param thermostat_info ...
128 : !> \param deg_of_freedom ...
129 : !> \param massive_atom_list ...
130 : !> \param molecule_kind_set ...
131 : !> \param local_molecules ...
132 : !> \param molecule_set ...
133 : !> \param para_env ...
134 : !> \param natoms_local ...
135 : !> \param simpar ...
136 : !> \param sum_of_thermostats ...
137 : !> \param gci ...
138 : !> \param shell ...
139 : !> \author Teodoro Laino [tlaino] - University of Zurich - 10.2007
140 : ! **************************************************************************************************
141 8 : SUBROUTINE setup_al_thermostat(al, thermostat_info, deg_of_freedom, &
142 : massive_atom_list, molecule_kind_set, local_molecules, molecule_set, &
143 : para_env, natoms_local, simpar, sum_of_thermostats, gci, shell)
144 :
145 : TYPE(al_system_type), POINTER :: al
146 : TYPE(thermostat_info_type), POINTER :: thermostat_info
147 : INTEGER, DIMENSION(:), POINTER :: deg_of_freedom, massive_atom_list
148 : TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
149 : TYPE(distribution_1d_type), POINTER :: local_molecules
150 : TYPE(molecule_type), POINTER :: molecule_set(:)
151 : TYPE(mp_para_env_type), POINTER :: para_env
152 : INTEGER, INTENT(OUT) :: natoms_local
153 : TYPE(simpar_type), POINTER :: simpar
154 : INTEGER, INTENT(OUT) :: sum_of_thermostats
155 : TYPE(global_constraint_type), POINTER :: gci
156 : LOGICAL, INTENT(IN), OPTIONAL :: shell
157 :
158 : INTEGER :: nkind, number, region
159 : LOGICAL :: do_shell
160 : TYPE(map_info_type), POINTER :: map_info
161 :
162 4 : do_shell = .FALSE.
163 4 : IF (PRESENT(shell)) do_shell = shell
164 4 : map_info => al%map_info
165 :
166 4 : nkind = SIZE(molecule_kind_set)
167 4 : sum_of_thermostats = thermostat_info%sum_of_thermostats
168 4 : map_info%dis_type = thermostat_info%dis_type
169 4 : number = thermostat_info%number_of_thermostats
170 4 : region = al%region
171 :
172 : CALL thermostat_mapping_region(map_info, deg_of_freedom, massive_atom_list, &
173 : molecule_kind_set, local_molecules, molecule_set, para_env, natoms_local, &
174 : simpar, number, region, gci, do_shell, thermostat_info%map_loc_thermo_gen, &
175 4 : sum_of_thermostats)
176 :
177 : ! This is the local number of available thermostats
178 4 : al%loc_num_al = number
179 4 : al%glob_num_al = sum_of_thermostats
180 4 : CALL al_thermo_create(al)
181 :
182 4 : END SUBROUTINE setup_al_thermostat
183 :
184 : END MODULE al_system_mapping
|