| 1 | mmeineke | 491 | ! Fortran interface to C entry plug. | 
| 2 | mmeineke | 377 |  | 
| 3 |  |  | module force_globals | 
| 4 |  |  | use definitions | 
| 5 |  |  | #ifdef IS_MPI | 
| 6 |  |  | use mpiSimulation | 
| 7 |  |  | #endif | 
| 8 |  |  |  | 
| 9 |  |  | implicit none | 
| 10 |  |  | PRIVATE | 
| 11 |  |  |  | 
| 12 |  |  | logical, save :: force_globals_initialized = .false. | 
| 13 |  |  |  | 
| 14 |  |  | #ifdef IS_MPI | 
| 15 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: q_Row | 
| 16 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: q_Col | 
| 17 | gezelter | 1150 | real( kind = dp ), allocatable, dimension(:,:), public :: q_group_Row | 
| 18 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: q_group_Col | 
| 19 | mmeineke | 377 | real( kind = dp ), allocatable, dimension(:,:), public :: u_l_Row | 
| 20 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: u_l_Col | 
| 21 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: A_Row | 
| 22 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: A_Col | 
| 23 |  |  |  | 
| 24 |  |  | real( kind = dp ), allocatable, dimension(:), public :: pot_Row | 
| 25 |  |  | real( kind = dp ), allocatable, dimension(:), public :: pot_Col | 
| 26 |  |  | real( kind = dp ), allocatable, dimension(:), public :: pot_Temp | 
| 27 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: f_Row | 
| 28 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: f_Col | 
| 29 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: f_Temp | 
| 30 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: t_Row | 
| 31 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: t_Col | 
| 32 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: t_Temp | 
| 33 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: rf_Row | 
| 34 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: rf_Col | 
| 35 |  |  | real( kind = dp ), allocatable, dimension(:,:), public :: rf_Temp | 
| 36 |  |  |  | 
| 37 |  |  | integer, allocatable, dimension(:), public :: atid_Row | 
| 38 |  |  | integer, allocatable, dimension(:), public :: atid_Col | 
| 39 | chuckv | 648 | #endif | 
| 40 |  |  |  | 
| 41 | mmeineke | 377 | integer, allocatable, dimension(:), public :: atid | 
| 42 | chuckv | 648 |  | 
| 43 | mmeineke | 377 | real( kind = dp ), allocatable, dimension(:,:), public :: rf | 
| 44 |  |  | real(kind = dp), dimension(9), public :: tau_Temp = 0.0_dp | 
| 45 |  |  | real(kind = dp), public :: virial_Temp = 0.0_dp | 
| 46 |  |  |  | 
| 47 |  |  | public :: InitializeForceGlobals | 
| 48 |  |  |  | 
| 49 |  |  | contains | 
| 50 |  |  |  | 
| 51 |  |  | subroutine InitializeForceGlobals(nlocal, thisStat) | 
| 52 |  |  | integer, intent(out) :: thisStat | 
| 53 | tim | 1198 | integer :: nAtomsInRow, nAtomsInCol | 
| 54 |  |  | integer :: nGroupsInRow, nGroupsInCol | 
| 55 | mmeineke | 377 | integer :: nlocal | 
| 56 |  |  | integer :: ndim = 3 | 
| 57 |  |  | integer :: alloc_stat | 
| 58 |  |  |  | 
| 59 |  |  | thisStat = 0 | 
| 60 |  |  |  | 
| 61 |  |  | #ifdef IS_MPI | 
| 62 | tim | 1198 | nAtomsInRow = getNatomsInRow(plan_atom_row) | 
| 63 |  |  | nAtomsInCol = getNatomsInCol(plan_atom_col) | 
| 64 |  |  | nGroupsInRow = getNgroupsInRow(plan_group_row) | 
| 65 |  |  | nGroupsInCol = getNgroupsInCol(plan_group_col) | 
| 66 | gezelter | 1150 |  | 
| 67 | mmeineke | 377 | #endif | 
| 68 |  |  |  | 
| 69 |  |  | call FreeForceGlobals() | 
| 70 |  |  |  | 
| 71 |  |  | #ifdef IS_MPI | 
| 72 |  |  |  | 
| 73 | tim | 1198 | allocate(q_Row(ndim,nAtomsInRow),stat=alloc_stat) | 
| 74 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 75 |  |  | thisStat = -1 | 
| 76 |  |  | return | 
| 77 |  |  | endif | 
| 78 |  |  |  | 
| 79 | tim | 1198 | allocate(q_Col(ndim,nAtomsInCol),stat=alloc_stat) | 
| 80 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 81 |  |  | thisStat = -1 | 
| 82 |  |  | return | 
| 83 |  |  | endif | 
| 84 | gezelter | 1138 |  | 
| 85 | tim | 1198 | allocate(q_group_Row(ndim,nGroupsInRow),stat=alloc_stat) | 
| 86 | gezelter | 1138 | if (alloc_stat /= 0 ) then | 
| 87 |  |  | thisStat = -1 | 
| 88 |  |  | return | 
| 89 |  |  | endif | 
| 90 |  |  |  | 
| 91 | tim | 1198 | allocate(q_group_Col(ndim,nGroupsInCol),stat=alloc_stat) | 
| 92 | gezelter | 1138 | if (alloc_stat /= 0 ) then | 
| 93 |  |  | thisStat = -1 | 
| 94 |  |  | return | 
| 95 |  |  | endif | 
| 96 | mmeineke | 377 |  | 
| 97 | tim | 1198 | allocate(u_l_Row(ndim,nAtomsInRow),stat=alloc_stat) | 
| 98 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 99 |  |  | thisStat = -1 | 
| 100 |  |  | return | 
| 101 |  |  | endif | 
| 102 |  |  |  | 
| 103 | tim | 1198 | allocate(u_l_Col(ndim,nAtomsInCol),stat=alloc_stat) | 
| 104 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 105 |  |  | thisStat = -1 | 
| 106 |  |  | return | 
| 107 |  |  | endif | 
| 108 |  |  |  | 
| 109 | tim | 1198 | allocate(A_row(9,nAtomsInRow),stat=alloc_stat) | 
| 110 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 111 |  |  | thisStat = -1 | 
| 112 |  |  | return | 
| 113 |  |  | endif | 
| 114 |  |  |  | 
| 115 | tim | 1198 | allocate(A_Col(9,nAtomsInCol),stat=alloc_stat) | 
| 116 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 117 |  |  | thisStat = -1 | 
| 118 |  |  | return | 
| 119 |  |  | endif | 
| 120 |  |  |  | 
| 121 | tim | 1198 | allocate(pot_row(nAtomsInRow),stat=alloc_stat) | 
| 122 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 123 |  |  | thisStat = -1 | 
| 124 |  |  | return | 
| 125 |  |  | endif | 
| 126 |  |  |  | 
| 127 | tim | 1198 | allocate(pot_Col(nAtomsInCol),stat=alloc_stat) | 
| 128 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 129 |  |  | thisStat = -1 | 
| 130 |  |  | return | 
| 131 |  |  | endif | 
| 132 |  |  |  | 
| 133 |  |  | allocate(pot_Temp(nlocal),stat=alloc_stat) | 
| 134 |  |  | if (alloc_stat /= 0 ) then | 
| 135 |  |  | thisStat = -1 | 
| 136 |  |  | return | 
| 137 |  |  | endif | 
| 138 |  |  |  | 
| 139 | tim | 1198 | allocate(f_Row(ndim,nAtomsInRow),stat=alloc_stat) | 
| 140 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 141 |  |  | thisStat = -1 | 
| 142 |  |  | return | 
| 143 |  |  | endif | 
| 144 |  |  |  | 
| 145 | tim | 1198 | allocate(f_Col(ndim,nAtomsInCol),stat=alloc_stat) | 
| 146 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 147 |  |  | thisStat = -1 | 
| 148 |  |  | return | 
| 149 |  |  | endif | 
| 150 |  |  |  | 
| 151 |  |  | allocate(f_Temp(ndim,nlocal),stat=alloc_stat) | 
| 152 |  |  | if (alloc_stat /= 0 ) then | 
| 153 |  |  | thisStat = -1 | 
| 154 |  |  | return | 
| 155 |  |  | endif | 
| 156 |  |  |  | 
| 157 | tim | 1198 | allocate(t_Row(ndim,nAtomsInRow),stat=alloc_stat) | 
| 158 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 159 |  |  | thisStat = -1 | 
| 160 |  |  | return | 
| 161 |  |  | endif | 
| 162 |  |  |  | 
| 163 | tim | 1198 | allocate(t_Col(ndim,nAtomsInCol),stat=alloc_stat) | 
| 164 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 165 |  |  | thisStat = -1 | 
| 166 |  |  | return | 
| 167 |  |  | endif | 
| 168 |  |  |  | 
| 169 |  |  | allocate(t_temp(ndim,nlocal),stat=alloc_stat) | 
| 170 |  |  | if (alloc_stat /= 0 ) then | 
| 171 |  |  | thisStat = -1 | 
| 172 |  |  | return | 
| 173 |  |  | endif | 
| 174 |  |  |  | 
| 175 | chuckv | 648 | allocate(atid(nlocal),stat=alloc_stat) | 
| 176 |  |  | if (alloc_stat /= 0 ) then | 
| 177 |  |  | thisStat = -1 | 
| 178 |  |  | return | 
| 179 |  |  | endif | 
| 180 |  |  |  | 
| 181 |  |  |  | 
| 182 | tim | 1198 | allocate(atid_Row(nAtomsInRow),stat=alloc_stat) | 
| 183 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 184 |  |  | thisStat = -1 | 
| 185 |  |  | return | 
| 186 |  |  | endif | 
| 187 |  |  |  | 
| 188 | tim | 1198 | allocate(atid_Col(nAtomsInCol),stat=alloc_stat) | 
| 189 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 190 |  |  | thisStat = -1 | 
| 191 |  |  | return | 
| 192 |  |  | endif | 
| 193 |  |  |  | 
| 194 | tim | 1198 | allocate(rf_Row(ndim,nAtomsInRow),stat=alloc_stat) | 
| 195 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 196 |  |  | thisStat = -1 | 
| 197 |  |  | return | 
| 198 |  |  | endif | 
| 199 |  |  |  | 
| 200 | tim | 1198 | allocate(rf_Col(ndim,nAtomsInCol),stat=alloc_stat) | 
| 201 | mmeineke | 377 | if (alloc_stat /= 0 ) then | 
| 202 |  |  | thisStat = -1 | 
| 203 |  |  | return | 
| 204 |  |  | endif | 
| 205 |  |  |  | 
| 206 |  |  | allocate(rf_Temp(ndim,nlocal),stat=alloc_stat) | 
| 207 |  |  | if (alloc_stat /= 0 ) then | 
| 208 |  |  | thisStat = -1 | 
| 209 |  |  | return | 
| 210 |  |  | endif | 
| 211 |  |  |  | 
| 212 |  |  | #else | 
| 213 |  |  |  | 
| 214 |  |  | allocate(atid(nlocal),stat=alloc_stat) | 
| 215 |  |  | if (alloc_stat /= 0 ) then | 
| 216 |  |  | thisStat = -1 | 
| 217 |  |  | return | 
| 218 |  |  | end if | 
| 219 |  |  |  | 
| 220 |  |  | #endif | 
| 221 |  |  |  | 
| 222 |  |  | allocate(rf(ndim,nlocal),stat=alloc_stat) | 
| 223 |  |  | if (alloc_stat /= 0 ) then | 
| 224 |  |  | thisStat = -1 | 
| 225 |  |  | return | 
| 226 |  |  | endif | 
| 227 |  |  |  | 
| 228 |  |  | force_globals_initialized = .true. | 
| 229 |  |  |  | 
| 230 |  |  | end subroutine InitializeForceGlobals | 
| 231 |  |  |  | 
| 232 |  |  | subroutine FreeForceGlobals() | 
| 233 |  |  |  | 
| 234 |  |  | !We free in the opposite order in which we allocate in. | 
| 235 |  |  |  | 
| 236 |  |  | if (allocated(rf))         deallocate(rf) | 
| 237 |  |  | #ifdef IS_MPI | 
| 238 |  |  | if (allocated(rf_Temp))    deallocate(rf_Temp) | 
| 239 |  |  | if (allocated(rf_Col))     deallocate(rf_Col) | 
| 240 |  |  | if (allocated(rf_Row))     deallocate(rf_Row) | 
| 241 |  |  | if (allocated(atid_Col))   deallocate(atid_Col) | 
| 242 |  |  | if (allocated(atid_Row))   deallocate(atid_Row) | 
| 243 | chuckv | 648 | if (allocated(atid))       deallocate(atid) | 
| 244 | mmeineke | 377 | if (allocated(t_Temp))     deallocate(t_Temp) | 
| 245 |  |  | if (allocated(t_Col))      deallocate(t_Col) | 
| 246 |  |  | if (allocated(t_Row))      deallocate(t_Row) | 
| 247 |  |  | if (allocated(f_Temp))     deallocate(f_Temp) | 
| 248 |  |  | if (allocated(f_Col))      deallocate(f_Col) | 
| 249 |  |  | if (allocated(f_Row))      deallocate(f_Row) | 
| 250 |  |  | if (allocated(pot_Temp))   deallocate(pot_Temp) | 
| 251 |  |  | if (allocated(pot_Col))    deallocate(pot_Col) | 
| 252 |  |  | if (allocated(pot_Row))    deallocate(pot_Row) | 
| 253 |  |  | if (allocated(A_Col))      deallocate(A_Col) | 
| 254 |  |  | if (allocated(A_Row))      deallocate(A_Row) | 
| 255 |  |  | if (allocated(u_l_Col))    deallocate(u_l_Col) | 
| 256 |  |  | if (allocated(u_l_Row))    deallocate(u_l_Row) | 
| 257 | gezelter | 1150 | if (allocated(q_group_Col)) deallocate(q_group_Col) | 
| 258 |  |  | if (allocated(q_group_Row)) deallocate(q_group_Row) | 
| 259 | mmeineke | 377 | if (allocated(q_Col))      deallocate(q_Col) | 
| 260 |  |  | if (allocated(q_Row))      deallocate(q_Row) | 
| 261 |  |  | #else | 
| 262 |  |  | if (allocated(atid))       deallocate(atid) | 
| 263 |  |  | #endif | 
| 264 |  |  |  | 
| 265 |  |  | end subroutine FreeForceGlobals | 
| 266 |  |  |  | 
| 267 |  |  | end module force_globals |