| 1 |
chuckv |
4 |
module simulation |
| 2 |
|
|
use definitions, ONLY : DP,ndim |
| 3 |
|
|
implicit none |
| 4 |
|
|
|
| 5 |
|
|
!! simulation parameters |
| 6 |
|
|
|
| 7 |
|
|
|
| 8 |
|
|
|
| 9 |
|
|
!! standard simulation |
| 10 |
|
|
integer :: nmol |
| 11 |
|
|
integer :: natoms |
| 12 |
|
|
integer :: nlocal |
| 13 |
|
|
integer :: nmol_local |
| 14 |
|
|
|
| 15 |
|
|
integer, allocatable, dimension(:) :: na |
| 16 |
|
|
integer, allocatable, dimension(:,:) :: atom_index |
| 17 |
|
|
integer, allocatable, dimension(:) :: ident |
| 18 |
|
|
integer, allocatable, dimension(:) :: present_atypes |
| 19 |
|
|
integer :: n_atypes_present |
| 20 |
chuckv |
9 |
|
| 21 |
|
|
real( kind = DP ) :: nzeta=0.0_DP |
| 22 |
chuckv |
4 |
real( kind = DP ) :: temp |
| 23 |
|
|
real( kind = DP ) :: total_mass |
| 24 |
|
|
real( kind = DP ) :: mass_local |
| 25 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: q |
| 26 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: v |
| 27 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: f |
| 28 |
|
|
real( kind = DP ), allocatable, dimension(:) :: e |
| 29 |
|
|
real( kind = DP ), allocatable, dimension(:) :: rho |
| 30 |
|
|
real( kind = DP ), allocatable, dimension(:) :: frho |
| 31 |
|
|
real( kind = DP ), allocatable, dimension(:) :: mass |
| 32 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: q0 |
| 33 |
|
|
real( kind = DP ) :: rlstsq, rcutsq |
| 34 |
|
|
integer, allocatable, dimension(:) :: point |
| 35 |
|
|
integer, allocatable, dimension(:) :: list |
| 36 |
|
|
character(len=10), allocatable, dimension(:) :: model |
| 37 |
|
|
real( kind = DP ), dimension(3) :: box |
| 38 |
|
|
logical :: use_pbc |
| 39 |
|
|
real( kind = DP ) :: force_time,comm_time |
| 40 |
|
|
|
| 41 |
|
|
|
| 42 |
|
|
#ifdef MPI |
| 43 |
|
|
!! for mpi simulation |
| 44 |
|
|
real( kind = DP ), allocatable, dimension(:) :: e_row |
| 45 |
|
|
real( kind = DP ), allocatable, dimension(:) :: e_col |
| 46 |
|
|
real( kind = DP ), allocatable, dimension(:) :: e_tmp |
| 47 |
|
|
|
| 48 |
|
|
integer, allocatable, dimension(:) :: ident_row |
| 49 |
|
|
integer, allocatable, dimension(:) :: ident_col |
| 50 |
|
|
integer, allocatable, dimension(:) :: tag_local |
| 51 |
|
|
integer, allocatable, dimension(:) :: tag_row |
| 52 |
|
|
integer, allocatable, dimension(:) :: tag_col |
| 53 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: q_tmp |
| 54 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: q_row |
| 55 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: q_col |
| 56 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: q_old |
| 57 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: f_tmp |
| 58 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: f_row |
| 59 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: f_col |
| 60 |
|
|
real( kind = DP ), allocatable, dimension(:,:) :: v_tmp |
| 61 |
|
|
real( kind = DP ), allocatable, dimension(:) :: rho_row |
| 62 |
|
|
real( kind = DP ), allocatable, dimension(:) :: rho_col |
| 63 |
|
|
real( kind = DP ), allocatable, dimension(:) :: rho_tmp |
| 64 |
|
|
real( kind = DP ), allocatable, dimension(:) :: frho_tmp |
| 65 |
|
|
|
| 66 |
|
|
#endif |
| 67 |
|
|
|
| 68 |
|
|
|
| 69 |
|
|
|
| 70 |
|
|
|
| 71 |
|
|
public :: nmol,natoms,na,atom_index,ident,temp,q,v,f |
| 72 |
|
|
public :: mass,q0,rlstsq,rcutsq,point,list,model,box,use_pbc |
| 73 |
|
|
public :: allocate_nmol_arrays, allocate_simulation, deallocate_simulation |
| 74 |
|
|
#ifdef MPI |
| 75 |
|
|
public :: q_tmp,q_row,q_col,q_old,f_tmp,f_row,f_col |
| 76 |
|
|
public :: allocate_mpi_arrays |
| 77 |
|
|
#endif |
| 78 |
|
|
|
| 79 |
|
|
contains |
| 80 |
|
|
subroutine allocate_nmol_arrays(n_size,allocate_error) |
| 81 |
|
|
integer, intent(in) :: n_size |
| 82 |
|
|
integer :: ierror |
| 83 |
|
|
integer, intent(out), optional :: allocate_error |
| 84 |
|
|
|
| 85 |
|
|
allocate(na(n_size),STAT=ierror) |
| 86 |
|
|
if (ierror /= 0 ) then |
| 87 |
|
|
allocate_error = -1 |
| 88 |
|
|
end if |
| 89 |
|
|
|
| 90 |
|
|
allocate(atom_index(n_size,3),STAT=ierror) |
| 91 |
|
|
if (ierror /= 0 ) then |
| 92 |
|
|
allocate_error = -1 |
| 93 |
|
|
end if |
| 94 |
|
|
|
| 95 |
|
|
allocate(model(n_size),STAT=ierror) |
| 96 |
|
|
if (ierror /= 0 ) then |
| 97 |
|
|
allocate_error = -1 |
| 98 |
|
|
end if |
| 99 |
|
|
end subroutine allocate_nmol_arrays |
| 100 |
|
|
|
| 101 |
|
|
subroutine allocate_simulation(n_size,n_col, allocate_error) |
| 102 |
|
|
integer, intent(in) :: n_size |
| 103 |
|
|
integer, optional, intent(in) :: n_col |
| 104 |
|
|
integer :: ierror |
| 105 |
|
|
integer, intent(out), optional :: allocate_error |
| 106 |
|
|
integer :: list_size |
| 107 |
|
|
#ifndef MPI |
| 108 |
|
|
|
| 109 |
|
|
list_size = n_size * 80 |
| 110 |
|
|
|
| 111 |
|
|
allocate(point(n_size),STAT=ierror) |
| 112 |
|
|
if (ierror /= 0 ) then |
| 113 |
|
|
allocate_error = -1 |
| 114 |
|
|
end if |
| 115 |
|
|
|
| 116 |
|
|
|
| 117 |
|
|
allocate(list(list_size),STAT=ierror) |
| 118 |
|
|
if (ierror /= 0 ) then |
| 119 |
|
|
allocate_error = -1 |
| 120 |
|
|
end if |
| 121 |
|
|
|
| 122 |
|
|
|
| 123 |
|
|
#endif |
| 124 |
|
|
|
| 125 |
|
|
allocate(e(n_size),STAT=ierror) |
| 126 |
|
|
if (ierror /= 0 ) then |
| 127 |
|
|
allocate_error = -1 |
| 128 |
|
|
end if |
| 129 |
|
|
|
| 130 |
|
|
allocate(ident(n_size),STAT=ierror) |
| 131 |
|
|
if (ierror /= 0 ) then |
| 132 |
|
|
allocate_error = -1 |
| 133 |
|
|
end if |
| 134 |
|
|
|
| 135 |
|
|
allocate(q(3,n_size),STAT=ierror) |
| 136 |
|
|
if (ierror /= 0 ) then |
| 137 |
|
|
allocate_error = -1 |
| 138 |
|
|
end if |
| 139 |
|
|
|
| 140 |
|
|
allocate(v(3,n_size),STAT=ierror) |
| 141 |
|
|
if (ierror /= 0 ) then |
| 142 |
|
|
allocate_error = -1 |
| 143 |
|
|
end if |
| 144 |
|
|
|
| 145 |
|
|
allocate(f(3,n_size),STAT=ierror) |
| 146 |
|
|
if (ierror /= 0 ) then |
| 147 |
|
|
allocate_error = -1 |
| 148 |
|
|
end if |
| 149 |
|
|
|
| 150 |
|
|
allocate(mass(n_size),STAT=ierror) |
| 151 |
|
|
if (ierror /= 0 ) then |
| 152 |
|
|
allocate_error = -1 |
| 153 |
|
|
end if |
| 154 |
|
|
|
| 155 |
|
|
allocate(q0(3,n_size),STAT=ierror) |
| 156 |
|
|
if (ierror /= 0 ) then |
| 157 |
|
|
allocate_error = -1 |
| 158 |
|
|
end if |
| 159 |
|
|
allocate(rho(n_size),STAT=ierror) |
| 160 |
|
|
if (ierror /= 0 ) then |
| 161 |
|
|
allocate_error = -1 |
| 162 |
|
|
end if |
| 163 |
|
|
allocate(frho(n_size),STAT=ierror) |
| 164 |
|
|
if (ierror /= 0 ) then |
| 165 |
|
|
allocate_error = -1 |
| 166 |
|
|
end if |
| 167 |
|
|
|
| 168 |
|
|
|
| 169 |
|
|
|
| 170 |
|
|
end subroutine allocate_simulation |
| 171 |
|
|
#ifdef MPI |
| 172 |
|
|
subroutine allocate_mpi_arrays(n_size,allocate_error) |
| 173 |
|
|
integer, intent(in) :: n_size |
| 174 |
|
|
integer :: ierror |
| 175 |
|
|
integer, intent(out), optional :: allocate_error |
| 176 |
|
|
|
| 177 |
|
|
allocate(e_tmp(n_size),STAT=ierror) |
| 178 |
|
|
if (ierror /= 0 ) then |
| 179 |
|
|
allocate_error = -1 |
| 180 |
|
|
end if |
| 181 |
|
|
allocate(q_tmp(3,n_size),STAT=ierror) |
| 182 |
|
|
if (ierror /= 0 ) then |
| 183 |
|
|
allocate_error = -1 |
| 184 |
|
|
end if |
| 185 |
|
|
allocate(q_old(3,n_size),STAT=ierror) |
| 186 |
|
|
if (ierror /= 0 ) then |
| 187 |
|
|
allocate_error = -1 |
| 188 |
|
|
end if |
| 189 |
|
|
allocate(f_tmp(3,n_size),STAT=ierror) |
| 190 |
|
|
if (ierror /= 0 ) then |
| 191 |
|
|
allocate_error = -1 |
| 192 |
|
|
end if |
| 193 |
|
|
allocate(v_tmp(3,n_size),STAT=ierror) |
| 194 |
|
|
if (ierror /= 0 ) then |
| 195 |
|
|
allocate_error = -1 |
| 196 |
|
|
end if |
| 197 |
|
|
allocate(rho_tmp(n_size),STAT=ierror) |
| 198 |
|
|
if (ierror /= 0 ) then |
| 199 |
|
|
allocate_error = -1 |
| 200 |
|
|
end if |
| 201 |
|
|
allocate(frho_tmp(n_size),STAT=ierror) |
| 202 |
|
|
if (ierror /= 0 ) then |
| 203 |
|
|
allocate_error = -1 |
| 204 |
|
|
end if |
| 205 |
|
|
allocate(tag_local(n_size),STAT=ierror) |
| 206 |
|
|
if (ierror /= 0 ) then |
| 207 |
|
|
allocate_error = -1 |
| 208 |
|
|
end if |
| 209 |
|
|
end subroutine allocate_mpi_arrays |
| 210 |
|
|
|
| 211 |
|
|
|
| 212 |
|
|
|
| 213 |
|
|
subroutine allocate_mpi_row_arrays(n_size,allocate_error) |
| 214 |
|
|
integer, intent(in) :: n_size |
| 215 |
|
|
integer :: ierror |
| 216 |
|
|
integer, intent(out), optional :: allocate_error |
| 217 |
|
|
|
| 218 |
|
|
|
| 219 |
|
|
allocate(point(n_size+1),STAT=ierror) |
| 220 |
|
|
if (ierror /= 0 ) then |
| 221 |
|
|
allocate_error = -1 |
| 222 |
|
|
end if |
| 223 |
|
|
|
| 224 |
|
|
allocate(list(80*n_size),STAT=ierror) |
| 225 |
|
|
if (ierror /= 0 ) then |
| 226 |
|
|
allocate_error = -1 |
| 227 |
|
|
end if |
| 228 |
|
|
|
| 229 |
|
|
allocate(q_row(3,n_size),STAT=ierror) |
| 230 |
|
|
if (ierror /= 0 ) then |
| 231 |
|
|
allocate_error = -1 |
| 232 |
|
|
end if |
| 233 |
|
|
|
| 234 |
|
|
allocate(e_row(n_size),STAT=ierror) |
| 235 |
|
|
if (ierror /= 0 ) then |
| 236 |
|
|
allocate_error = -1 |
| 237 |
|
|
end if |
| 238 |
|
|
|
| 239 |
|
|
allocate(f_row(3,n_size),STAT=ierror) |
| 240 |
|
|
if (ierror /= 0 ) then |
| 241 |
|
|
allocate_error = -1 |
| 242 |
|
|
end if |
| 243 |
|
|
allocate(rho_row(n_size),STAT=ierror) |
| 244 |
|
|
if (ierror /= 0 ) then |
| 245 |
|
|
allocate_error = -1 |
| 246 |
|
|
end if |
| 247 |
|
|
|
| 248 |
|
|
allocate(ident_row(n_size),STAT=ierror) |
| 249 |
|
|
if (ierror /= 0 ) then |
| 250 |
|
|
allocate_error = -1 |
| 251 |
|
|
end if |
| 252 |
|
|
allocate(tag_row(n_size),STAT=ierror) |
| 253 |
|
|
if (ierror /= 0 ) then |
| 254 |
|
|
allocate_error = -1 |
| 255 |
|
|
end if |
| 256 |
|
|
|
| 257 |
|
|
|
| 258 |
|
|
end subroutine allocate_mpi_row_arrays |
| 259 |
|
|
|
| 260 |
|
|
subroutine allocate_mpi_col_arrays(n_size,allocate_error) |
| 261 |
|
|
integer, intent(in) :: n_size |
| 262 |
|
|
integer :: ierror |
| 263 |
|
|
integer, intent(out), optional :: allocate_error |
| 264 |
|
|
|
| 265 |
|
|
allocate(q_col(3,n_size),STAT=ierror) |
| 266 |
|
|
if (ierror /= 0 ) then |
| 267 |
|
|
allocate_error = -1 |
| 268 |
|
|
end if |
| 269 |
|
|
allocate(rho_col(n_size),STAT=ierror) |
| 270 |
|
|
if (ierror /= 0 ) then |
| 271 |
|
|
allocate_error = -1 |
| 272 |
|
|
end if |
| 273 |
|
|
|
| 274 |
|
|
allocate(e_col(n_size),STAT=ierror) |
| 275 |
|
|
if (ierror /= 0 ) then |
| 276 |
|
|
allocate_error = -1 |
| 277 |
|
|
end if |
| 278 |
|
|
allocate(ident_col(n_size),STAT=ierror) |
| 279 |
|
|
if (ierror /= 0 ) then |
| 280 |
|
|
allocate_error = -1 |
| 281 |
|
|
end if |
| 282 |
|
|
allocate(tag_col(n_size),STAT=ierror) |
| 283 |
|
|
if (ierror /= 0 ) then |
| 284 |
|
|
allocate_error = -1 |
| 285 |
|
|
end if |
| 286 |
|
|
|
| 287 |
|
|
allocate(f_col(3,n_size),STAT=ierror) |
| 288 |
|
|
if (ierror /= 0 ) then |
| 289 |
|
|
allocate_error = -1 |
| 290 |
|
|
end if |
| 291 |
|
|
|
| 292 |
|
|
|
| 293 |
|
|
|
| 294 |
|
|
end subroutine allocate_mpi_col_arrays |
| 295 |
|
|
|
| 296 |
|
|
subroutine deallocate_mpi_arrays() |
| 297 |
|
|
deallocate(q_tmp) |
| 298 |
|
|
deallocate(q_row) |
| 299 |
|
|
deallocate(q_col) |
| 300 |
|
|
deallocate(q_old) |
| 301 |
|
|
deallocate(f_tmp) |
| 302 |
|
|
deallocate(f_row) |
| 303 |
|
|
deallocate(f_col) |
| 304 |
|
|
deallocate(ident_col) |
| 305 |
|
|
deallocate(e_col) |
| 306 |
|
|
deallocate(ident_row) |
| 307 |
|
|
deallocate(e_row) |
| 308 |
|
|
deallocate(e_tmp) |
| 309 |
|
|
deallocate(e) |
| 310 |
|
|
end subroutine deallocate_mpi_arrays |
| 311 |
|
|
#endif |
| 312 |
|
|
subroutine deallocate_simulation() |
| 313 |
|
|
|
| 314 |
|
|
deallocate(point) |
| 315 |
|
|
deallocate(list) |
| 316 |
|
|
deallocate(na) |
| 317 |
|
|
deallocate(atom_index) |
| 318 |
|
|
deallocate(ident) |
| 319 |
|
|
deallocate(v) |
| 320 |
|
|
deallocate(f) |
| 321 |
|
|
deallocate(mass) |
| 322 |
|
|
deallocate(q0) |
| 323 |
|
|
deallocate(model) |
| 324 |
|
|
deallocate(q) |
| 325 |
|
|
|
| 326 |
|
|
end subroutine deallocate_simulation |
| 327 |
|
|
end module simulation |