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 containing essential information for running implicit (iterative)
10 : !> Poisson solver
11 : !> \par History
12 : !> 08.2014 created [Hossein Bani-Hashemian]
13 : !> \author Hossein Bani-Hashemian
14 : ! **************************************************************************************************
15 : MODULE ps_implicit_types
16 :
17 : USE dct, ONLY: dct_type,&
18 : dct_type_release
19 : USE dielectric_types, ONLY: dielectric_release,&
20 : dielectric_type
21 : USE dirichlet_bc_types, ONLY: dbc_release,&
22 : dirichlet_bc_p_type
23 : USE kinds, ONLY: dp
24 : USE pw_pool_types, ONLY: pw_pool_type
25 : USE pw_types, ONLY: pw_r3d_rs_type
26 : #include "../base/base_uses.f90"
27 :
28 : IMPLICIT NONE
29 : PRIVATE
30 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ps_implicit_types'
31 :
32 : INTEGER, PARAMETER, PUBLIC :: PERIODIC_BC = 0, &
33 : MIXED_BC = 1, &
34 : MIXED_PERIODIC_BC = 2, &
35 : NEUMANN_BC = 3
36 :
37 : TYPE :: ps_implicit_parameters
38 : INTEGER :: boundary_condition = PERIODIC_BC
39 : LOGICAL :: zero_initial_guess = .FALSE.
40 : INTEGER :: max_iter = 0
41 : REAL(KIND=dp) :: tol = 0.0_dp
42 : REAL(KIND=dp) :: omega = 0.0_dp
43 : INTEGER :: neumann_directions = 0
44 : END TYPE ps_implicit_parameters
45 :
46 : TYPE :: ps_implicit_type
47 : LOGICAL :: do_dbc_cube = .FALSE.
48 : TYPE(dielectric_type), POINTER :: dielectric => NULL()
49 : TYPE(dct_type) :: dct_env = dct_type()
50 : TYPE(pw_r3d_rs_type), POINTER :: initial_guess => NULL()
51 : TYPE(pw_r3d_rs_type), POINTER :: v_eps => NULL()
52 : TYPE(pw_r3d_rs_type), POINTER :: cstr_charge => NULL()
53 : REAL(dp), DIMENSION(:), ALLOCATABLE :: initial_lambda
54 : REAL(dp) :: ehartree = 0.0_dp
55 : REAL(dp) :: electric_enthalpy = 0.0_dp
56 : INTEGER :: times_called = 0
57 : TYPE(dirichlet_bc_p_type), &
58 : DIMENSION(:), ALLOCATABLE :: contacts
59 : REAL(dp), DIMENSION(:, :), ALLOCATABLE :: QS
60 : REAL(dp), DIMENSION(:, :), ALLOCATABLE :: Rinv
61 : REAL(dp), DIMENSION(:, :), ALLOCATABLE :: B
62 : REAL(dp), DIMENSION(:, :), ALLOCATABLE :: Bt
63 : REAL(dp), DIMENSION(:), ALLOCATABLE :: v_D
64 : REAL(dp), DIMENSION(:), ALLOCATABLE :: osc_frac
65 : REAL(dp), DIMENSION(:), ALLOCATABLE :: frequency
66 : REAL(dp), DIMENSION(:), ALLOCATABLE :: phase
67 : INTEGER, DIMENSION(:), ALLOCATABLE :: idx_1dto3d
68 : END TYPE ps_implicit_type
69 :
70 : PUBLIC ps_implicit_type, ps_implicit_parameters
71 : PUBLIC ps_implicit_release
72 :
73 : CONTAINS
74 :
75 : ! **************************************************************************************************
76 : !> \brief Deallocates ps_implicit
77 : !> \param ps_implicit_env the implicit_env to be deallocated
78 : !> \param ps_implicit_params implicit env parameters
79 : !> \param pw_pool pool of plane-wave grid
80 : !> \par History
81 : !> 08.2014 created [Hossein Bani-Hashemian]
82 : !> \author Mohammad Hossein Bani-Hashemian
83 : ! **************************************************************************************************
84 20320 : SUBROUTINE ps_implicit_release(ps_implicit_env, ps_implicit_params, pw_pool)
85 : TYPE(ps_implicit_type), POINTER :: ps_implicit_env
86 : TYPE(ps_implicit_parameters), INTENT(INOUT) :: ps_implicit_params
87 : TYPE(pw_pool_type), INTENT(IN), OPTIONAL, POINTER :: pw_pool
88 :
89 : CHARACTER(len=*), PARAMETER :: routineN = 'ps_implicit_release'
90 :
91 : INTEGER :: boundary_condition, handle
92 : LOGICAL :: can_give_back, do_dbc_cube
93 :
94 20320 : CALL timeset(routineN, handle)
95 :
96 20320 : IF (ASSOCIATED(ps_implicit_env)) THEN
97 54 : can_give_back = PRESENT(pw_pool)
98 54 : IF (can_give_back) can_give_back = ASSOCIATED(pw_pool)
99 54 : do_dbc_cube = ps_implicit_env%do_dbc_cube
100 :
101 54 : IF (can_give_back) THEN
102 0 : CALL pw_pool%give_back_pw(ps_implicit_env%initial_guess)
103 0 : CALL pw_pool%give_back_pw(ps_implicit_env%v_eps)
104 0 : CALL pw_pool%give_back_pw(ps_implicit_env%cstr_charge)
105 0 : DEALLOCATE (ps_implicit_env%initial_guess, ps_implicit_env%v_eps, ps_implicit_env%cstr_charge)
106 0 : CALL dbc_release(ps_implicit_env%contacts, do_dbc_cube, pw_pool=pw_pool)
107 : ELSE
108 54 : CALL ps_implicit_env%initial_guess%release()
109 54 : CALL ps_implicit_env%v_eps%release()
110 54 : IF (ASSOCIATED(ps_implicit_env%cstr_charge)) THEN
111 38 : CALL ps_implicit_env%cstr_charge%release()
112 38 : DEALLOCATE (ps_implicit_env%cstr_charge)
113 : END IF
114 54 : DEALLOCATE (ps_implicit_env%initial_guess, ps_implicit_env%v_eps)
115 54 : CALL dbc_release(ps_implicit_env%contacts, do_dbc_cube)
116 : END IF
117 :
118 54 : DEALLOCATE (ps_implicit_env%initial_lambda)
119 54 : DEALLOCATE (ps_implicit_env%B)
120 54 : DEALLOCATE (ps_implicit_env%Bt)
121 54 : DEALLOCATE (ps_implicit_env%QS)
122 54 : DEALLOCATE (ps_implicit_env%Rinv)
123 54 : DEALLOCATE (ps_implicit_env%v_D)
124 54 : DEALLOCATE (ps_implicit_env%osc_frac)
125 54 : DEALLOCATE (ps_implicit_env%frequency)
126 54 : DEALLOCATE (ps_implicit_env%phase)
127 54 : DEALLOCATE (ps_implicit_env%idx_1dto3d)
128 :
129 54 : CALL dielectric_release(ps_implicit_env%dielectric, pw_pool)
130 54 : boundary_condition = ps_implicit_params%boundary_condition
131 54 : IF (boundary_condition .EQ. MIXED_BC .OR. boundary_condition .EQ. NEUMANN_BC) THEN
132 22 : CALL dct_type_release(ps_implicit_env%dct_env)
133 : END IF
134 :
135 54 : DEALLOCATE (ps_implicit_env)
136 : END IF
137 :
138 20320 : CALL timestop(handle)
139 :
140 20320 : END SUBROUTINE ps_implicit_release
141 :
142 0 : END MODULE ps_implicit_types
|