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