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 : !> \note 10 : !> If parallel mode is distributed certain combination of 11 : !> "in_use" and "in_space" can not be used. 12 : !> For performance reasons it would be better to have the loops 13 : !> over g-vectros in the gather/scatter routines in new subprograms 14 : !> with the actual arrays (also the addressing) in the parameter list 15 : !> \par History 16 : !> JGH (29-Dec-2000) : Changes for parallel use 17 : !> JGH (13-Mar-2001) : added timing calls 18 : !> JGH (26-Feb-2003) : OpenMP enabled 19 : !> JGH (17-Nov-2007) : Removed mass arrays 20 : !> JGH (01-Dec-2007) : Removed and renamed routines 21 : !> 03.2008 [tlaino] : Splitting pw_types into pw_types and pw_methods 22 : !> \author apsi 23 : ! ************************************************************************************************** 24 : MODULE pw_types 25 : 26 : USE cp_log_handling, ONLY: cp_to_string 27 : USE kinds, ONLY: dp 28 : USE pw_grid_types, ONLY: pw_grid_type 29 : USE pw_grids, ONLY: pw_grid_release, & 30 : pw_grid_retain 31 : #include "../base/base_uses.f90" 32 : 33 : IMPLICIT NONE 34 : 35 : #:include 'pw_types.fypp' 36 : 37 : PRIVATE 38 : #:for space in pw_spaces 39 : #:for kind in pw_kinds 40 : PUBLIC :: pw_${kind}$_${space}$_type, pw_${kind}$_${space}$_p_type 41 : #:endfor 42 : #:endfor 43 : 44 : #:for space in pw_spaces 45 : #:for kind, type in zip(pw_kinds, pw_types) 46 : ! ************************************************************************************************** 47 : TYPE pw_${kind}$_${space}$_type 48 : ${type}$, CONTIGUOUS, POINTER :: array => NULL() 49 : TYPE(pw_grid_type), POINTER :: pw_grid => NULL() 50 : CONTAINS 51 : PROCEDURE, PUBLIC, NON_OVERRIDABLE :: create => pw_create_${kind}$_${space}$ 52 : PROCEDURE, PUBLIC, NON_OVERRIDABLE :: release => pw_release_${kind}$_${space}$ 53 : END TYPE pw_${kind}$_${space}$_type 54 : 55 : ! ************************************************************************************************** 56 : TYPE pw_${kind}$_${space}$_p_type 57 : TYPE(pw_${kind}$_${space}$_type), POINTER :: pw => NULL() 58 : END TYPE pw_${kind}$_${space}$_p_type 59 : #:endfor 60 : #:endfor 61 : 62 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pw_types' 63 : LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .FALSE. 64 : 65 : CONTAINS 66 : #:for space in pw_spaces 67 : #:for kind, type in zip(pw_kinds, pw_types) 68 : ! ************************************************************************************************** 69 : !> \brief releases the given pw 70 : !> \param pw the pw to release 71 : !> \par History 72 : !> 04.2003 created [fawzi] 73 : !> \author fawzi 74 : !> \note 75 : !> see doc/ReferenceCounting.html 76 : ! ************************************************************************************************** 77 14572552 : SUBROUTINE pw_release_${kind}$_${space}$ (pw) 78 : CLASS(pw_${kind}$_${space}$_type), INTENT(INOUT) :: pw 79 : 80 14572552 : IF (ASSOCIATED(pw%array)) DEALLOCATE (pw%array) 81 14572552 : CALL pw_grid_release(pw%pw_grid) 82 14572552 : END SUBROUTINE pw_release_${kind}$_${space}$ 83 : 84 : ! ************************************************************************************************** 85 : !> \brief allocates and initializes pw_r3d_rs_type 86 : !> \param pw the type that will bw allocated and initialized 87 : !> \param pw_grid ... 88 : !> \param array_ptr pointer with to data 89 : !> \par History 90 : !> 11.2003 created [fawzi] 91 : !> \author fawzi 92 : ! ************************************************************************************************** 93 7096777 : SUBROUTINE pw_create_${kind}$_${space}$ (pw, pw_grid, array_ptr) 94 : CLASS(pw_${kind}$_${space}$_type), INTENT(INOUT) :: pw 95 : TYPE(pw_grid_type), INTENT(IN), POINTER :: pw_grid 96 : ${type}$, CONTIGUOUS, INTENT(IN), OPTIONAL, POINTER :: array_ptr 97 : 98 : CHARACTER(len=*), PARAMETER :: routineN = 'pw_create_${kind}$' 99 : 100 : INTEGER :: handle 101 : 102 7096777 : CALL timeset(routineN, handle) 103 : 104 : ! Ensure a clean grid to prevent memory leaks 105 7096777 : CALL pw%release() 106 : 107 7096777 : pw%pw_grid => pw_grid 108 7096777 : CALL pw_grid_retain(pw%pw_grid) 109 : 110 : #:if kind[1]=="1" 111 3699573 : IF (PRESENT(array_ptr)) THEN 112 3699453 : IF (ASSOCIATED(array_ptr)) THEN 113 3552401 : CPASSERT(SIZE(array_ptr) == pw%pw_grid%ngpts_cut_local) 114 3552401 : pw%array(1:pw%pw_grid%ngpts_cut_local) => array_ptr 115 : END IF 116 : END IF 117 3993917 : IF (.NOT. ASSOCIATED(pw%array)) ALLOCATE (pw%array(pw%pw_grid%ngpts_cut_local)) 118 : #:elif kind[1]=="3" 119 : ASSOCIATE (bounds => pw%pw_grid%bounds_local) 120 3397204 : IF (PRESENT(array_ptr)) THEN 121 3364800 : IF (ASSOCIATED(array_ptr)) THEN 122 12518656 : IF (ALL(bounds(1, :) <= bounds(2, :))) THEN 123 21907648 : CPASSERT(ALL(LBOUND(array_ptr) == bounds(1, :))) 124 21907648 : CPASSERT(ALL(UBOUND(array_ptr) == bounds(2, :))) 125 : END IF 126 3129664 : pw%array => array_ptr 127 : END IF 128 : END IF 129 6762004 : IF (.NOT. ASSOCIATED(pw%array)) THEN 130 : ALLOCATE (pw%array( & 131 : bounds(1, 1):bounds(2, 1), & 132 : bounds(1, 2):bounds(2, 2), & 133 1337700 : bounds(1, 3):bounds(2, 3))) 134 : END IF 135 : END ASSOCIATE 136 : #:endif 137 7096777 : CALL timestop(handle) 138 7096777 : END SUBROUTINE pw_create_${kind}$_${space}$ 139 : #:endfor 140 : #:endfor 141 : 142 0 : END MODULE pw_types