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 initialize mixed environment
10 : !> \author fschiff
11 : ! **************************************************************************************************
12 : MODULE mixed_environment
13 : USE atomic_kind_types, ONLY: atomic_kind_type
14 : USE cell_types, ONLY: cell_type
15 : USE cp_subsys_methods, ONLY: cp_subsys_create
16 : USE cp_subsys_types, ONLY: cp_subsys_type
17 : USE distribution_1d_types, ONLY: distribution_1d_release,&
18 : distribution_1d_type
19 : USE distribution_methods, ONLY: distribute_molecules_1d
20 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
21 : section_vals_type
22 : USE message_passing, ONLY: mp_para_env_type
23 : USE mixed_energy_types, ONLY: allocate_mixed_energy,&
24 : mixed_energy_type
25 : USE mixed_environment_types, ONLY: mixed_environment_type,&
26 : set_mixed_env
27 : USE molecule_kind_types, ONLY: molecule_kind_type,&
28 : write_molecule_kind_set
29 : USE molecule_types, ONLY: molecule_type
30 : USE particle_types, ONLY: particle_type
31 : #include "./base/base_uses.f90"
32 :
33 : IMPLICIT NONE
34 :
35 : PRIVATE
36 :
37 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'mixed_environment'
38 : PUBLIC :: mixed_init
39 :
40 : CONTAINS
41 :
42 : ! **************************************************************************************************
43 : !> \brief reads the input and database file for mixed
44 : !> \param mixed_env ...
45 : !> \param root_section ...
46 : !> \param para_env ...
47 : !> \param force_env_section ...
48 : !> \param use_motion_section ...
49 : !> \par Used By
50 : !> mixed_main
51 : !> \author fschiff
52 : ! **************************************************************************************************
53 130 : SUBROUTINE mixed_init(mixed_env, root_section, para_env, force_env_section, &
54 : use_motion_section)
55 :
56 : TYPE(mixed_environment_type), INTENT(INOUT) :: mixed_env
57 : TYPE(section_vals_type), POINTER :: root_section
58 : TYPE(mp_para_env_type), POINTER :: para_env
59 : TYPE(section_vals_type), POINTER :: force_env_section
60 : LOGICAL, INTENT(IN) :: use_motion_section
61 :
62 : CHARACTER(len=*), PARAMETER :: routineN = 'mixed_init'
63 :
64 : INTEGER :: handle
65 : TYPE(cp_subsys_type), POINTER :: subsys
66 : TYPE(section_vals_type), POINTER :: subsys_section
67 :
68 130 : CALL timeset(routineN, handle)
69 :
70 130 : NULLIFY (subsys)
71 :
72 130 : subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
73 :
74 130 : CALL set_mixed_env(mixed_env, input=force_env_section)
75 : CALL cp_subsys_create(subsys, para_env, root_section, &
76 : force_env_section=force_env_section, &
77 130 : use_motion_section=use_motion_section)
78 :
79 : CALL mixed_init_subsys(mixed_env, subsys, &
80 130 : force_env_section, subsys_section)
81 :
82 130 : CALL timestop(handle)
83 :
84 130 : END SUBROUTINE mixed_init
85 :
86 : ! **************************************************************************************************
87 : !> \brief Read the input and the database files for the setup of the
88 : !> mixed environment.
89 : !> \param mixed_env ...
90 : !> \param subsys ...
91 : !> \param force_env_section ...
92 : !> \param subsys_section ...
93 : !> \date 11.06
94 : !> \author fschiff
95 : !> \version 1.0
96 : ! **************************************************************************************************
97 130 : SUBROUTINE mixed_init_subsys(mixed_env, subsys, force_env_section, &
98 : subsys_section)
99 :
100 : TYPE(mixed_environment_type), INTENT(INOUT) :: mixed_env
101 : TYPE(cp_subsys_type), POINTER :: subsys
102 : TYPE(section_vals_type), POINTER :: force_env_section, subsys_section
103 :
104 : CHARACTER(len=*), PARAMETER :: routineN = 'mixed_init_subsys'
105 :
106 : INTEGER :: handle
107 130 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
108 : TYPE(cell_type), POINTER :: my_cell_ref
109 : TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
110 : TYPE(mixed_energy_type), POINTER :: mixed_energy
111 130 : TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
112 130 : TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
113 130 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
114 :
115 130 : CALL timeset(routineN, handle)
116 130 : NULLIFY (mixed_energy, local_molecules, local_particles, my_cell_ref)
117 130 : particle_set => subsys%particles%els
118 130 : atomic_kind_set => subsys%atomic_kinds%els
119 130 : molecule_set => subsys%molecules%els
120 130 : molecule_kind_set => subsys%molecule_kinds%els
121 130 : my_cell_ref => subsys%cell_ref
122 :
123 : ! Create the mixed_energy_type
124 130 : CALL allocate_mixed_energy(mixed_energy)
125 :
126 : ! Print the molecule kind set
127 130 : CALL write_molecule_kind_set(molecule_kind_set, subsys_section)
128 :
129 : ! Distribute molecules and atoms using the new data structures ***
130 : CALL distribute_molecules_1d(atomic_kind_set=atomic_kind_set, &
131 : particle_set=particle_set, &
132 : local_particles=local_particles, &
133 : molecule_kind_set=molecule_kind_set, &
134 : molecule_set=molecule_set, &
135 : local_molecules=local_molecules, &
136 130 : force_env_section=force_env_section)
137 :
138 : ! set the mixed_env
139 130 : CALL set_mixed_env(mixed_env=mixed_env, subsys=subsys)
140 : CALL set_mixed_env(mixed_env=mixed_env, &
141 : cell_ref=my_cell_ref, &
142 : local_molecules=local_molecules, &
143 : local_particles=local_particles, &
144 130 : mixed_energy=mixed_energy)
145 :
146 130 : CALL distribution_1d_release(local_particles)
147 130 : CALL distribution_1d_release(local_molecules)
148 :
149 130 : CALL timestop(handle)
150 :
151 130 : END SUBROUTINE mixed_init_subsys
152 :
153 : END MODULE mixed_environment
|