1 |
chuckv |
290 |
!! Fortran interface to C entry plug. |
2 |
|
|
|
3 |
mmeineke |
270 |
module simulation |
4 |
gezelter |
325 |
use definitions |
5 |
|
|
use neighborLists |
6 |
gezelter |
360 |
use force_globals |
7 |
gezelter |
358 |
use vector_class |
8 |
gezelter |
328 |
use atype_module |
9 |
gezelter |
360 |
use lj |
10 |
mmeineke |
270 |
#ifdef IS_MPI |
11 |
|
|
use mpiSimulation |
12 |
|
|
#endif |
13 |
|
|
|
14 |
|
|
implicit none |
15 |
|
|
PRIVATE |
16 |
|
|
|
17 |
mmeineke |
285 |
#define __FORTRAN90 |
18 |
gezelter |
309 |
#include "fSimulation.h" |
19 |
mmeineke |
270 |
|
20 |
|
|
type (simtype), public :: thisSim |
21 |
|
|
|
22 |
gezelter |
325 |
logical, save :: simulation_setup_complete = .false. |
23 |
mmeineke |
270 |
|
24 |
gezelter |
361 |
integer, public, save :: natoms |
25 |
gezelter |
330 |
integer, public, save :: nExcludes_Global = 0 |
26 |
|
|
integer, public, save :: nExcludes_Local = 0 |
27 |
gezelter |
360 |
integer, allocatable, dimension(:,:), public :: excludesLocal |
28 |
|
|
integer, allocatable, dimension(:), public :: excludesGlobal |
29 |
gezelter |
332 |
|
30 |
gezelter |
325 |
real(kind=dp), save :: rcut2 = 0.0_DP |
31 |
|
|
real(kind=dp), save :: rcut6 = 0.0_DP |
32 |
|
|
real(kind=dp), save :: rlist2 = 0.0_DP |
33 |
gezelter |
330 |
real(kind=dp), public, dimension(3), save :: box |
34 |
mmeineke |
270 |
|
35 |
gezelter |
325 |
|
36 |
|
|
public :: SimulationSetup |
37 |
gezelter |
361 |
public :: getNlocal |
38 |
gezelter |
360 |
public :: setBox |
39 |
mmeineke |
367 |
public :: setBox_3d |
40 |
mmeineke |
270 |
public :: getBox |
41 |
gezelter |
360 |
public :: setRcut |
42 |
mmeineke |
270 |
public :: getRcut |
43 |
|
|
public :: getRlist |
44 |
gezelter |
312 |
public :: getRrf |
45 |
|
|
public :: getRt |
46 |
gezelter |
329 |
public :: getDielect |
47 |
gezelter |
325 |
public :: SimUsesPBC |
48 |
|
|
public :: SimUsesLJ |
49 |
|
|
public :: SimUsesDipoles |
50 |
|
|
public :: SimUsesSticky |
51 |
|
|
public :: SimUsesRF |
52 |
|
|
public :: SimUsesGB |
53 |
|
|
public :: SimUsesEAM |
54 |
|
|
public :: SimRequiresPrepairCalc |
55 |
|
|
public :: SimRequiresPostpairCalc |
56 |
gezelter |
332 |
public :: SimUsesDirectionalAtoms |
57 |
mmeineke |
285 |
|
58 |
mmeineke |
270 |
interface getBox |
59 |
|
|
module procedure getBox_3d |
60 |
gezelter |
360 |
module procedure getBox_1d |
61 |
mmeineke |
270 |
end interface |
62 |
gezelter |
325 |
|
63 |
gezelter |
360 |
interface setBox |
64 |
|
|
module procedure setBox_3d |
65 |
|
|
module procedure setBox_1d |
66 |
|
|
end interface |
67 |
|
|
|
68 |
mmeineke |
270 |
contains |
69 |
gezelter |
325 |
|
70 |
|
|
subroutine SimulationSetup(setThisSim, nComponents, c_idents, & |
71 |
gezelter |
332 |
CnLocalExcludes, CexcludesLocal, CnGlobalExcludes, CexcludesGlobal, & |
72 |
|
|
status) |
73 |
chuckv |
368 |
|
74 |
chuckv |
290 |
type (simtype) :: setThisSim |
75 |
gezelter |
325 |
integer, intent(inout) :: nComponents |
76 |
|
|
integer, dimension(nComponents),intent(inout) :: c_idents |
77 |
gezelter |
332 |
|
78 |
|
|
integer :: CnLocalExcludes |
79 |
|
|
integer, dimension(2,CnLocalExcludes), intent(in) :: CexcludesLocal |
80 |
|
|
integer :: CnGlobalExcludes |
81 |
|
|
integer, dimension(CnGlobalExcludes), intent(in) :: CexcludesGlobal |
82 |
gezelter |
325 |
!! Result status, success = 0, status = -1 |
83 |
|
|
integer, intent(out) :: status |
84 |
|
|
integer :: i, me, thisStat, alloc_stat, myNode |
85 |
|
|
#ifdef IS_MPI |
86 |
|
|
integer, allocatable, dimension(:) :: c_idents_Row |
87 |
|
|
integer, allocatable, dimension(:) :: c_idents_Col |
88 |
|
|
integer :: nrow |
89 |
|
|
integer :: ncol |
90 |
gezelter |
332 |
#endif |
91 |
gezelter |
325 |
|
92 |
|
|
simulation_setup_complete = .false. |
93 |
|
|
status = 0 |
94 |
|
|
|
95 |
gezelter |
312 |
! copy C struct into fortran type |
96 |
chuckv |
290 |
thisSim = setThisSim |
97 |
gezelter |
325 |
natoms = nComponents |
98 |
|
|
rcut2 = thisSim%rcut * thisSim%rcut |
99 |
|
|
rcut6 = rcut2 * rcut2 * rcut2 |
100 |
|
|
rlist2 = thisSim%rlist * thisSim%rlist |
101 |
gezelter |
330 |
box = thisSim%box |
102 |
gezelter |
332 |
nExcludes_Global = CnGlobalExcludes |
103 |
|
|
nExcludes_Local = CnLocalExcludes |
104 |
mmeineke |
270 |
|
105 |
gezelter |
360 |
call InitializeForceGlobals(natoms, thisStat) |
106 |
gezelter |
332 |
if (thisStat /= 0) then |
107 |
|
|
status = -1 |
108 |
|
|
return |
109 |
|
|
endif |
110 |
|
|
|
111 |
gezelter |
360 |
call InitializeSimGlobals(thisStat) |
112 |
|
|
if (thisStat /= 0) then |
113 |
|
|
status = -1 |
114 |
|
|
return |
115 |
|
|
endif |
116 |
|
|
|
117 |
gezelter |
325 |
#ifdef IS_MPI |
118 |
|
|
! We can only set up forces if mpiSimulation has been setup. |
119 |
|
|
if (.not. isMPISimSet()) then |
120 |
|
|
write(default_error,*) "MPI is not set" |
121 |
|
|
status = -1 |
122 |
|
|
return |
123 |
|
|
endif |
124 |
|
|
nrow = getNrow(plan_row) |
125 |
|
|
ncol = getNcol(plan_col) |
126 |
|
|
mynode = getMyNode() |
127 |
|
|
|
128 |
|
|
allocate(c_idents_Row(nrow),stat=alloc_stat) |
129 |
|
|
if (alloc_stat /= 0 ) then |
130 |
|
|
status = -1 |
131 |
|
|
return |
132 |
|
|
endif |
133 |
mmeineke |
270 |
|
134 |
gezelter |
325 |
allocate(c_idents_Col(ncol),stat=alloc_stat) |
135 |
|
|
if (alloc_stat /= 0 ) then |
136 |
|
|
status = -1 |
137 |
|
|
return |
138 |
|
|
endif |
139 |
|
|
|
140 |
|
|
call gather(c_idents, c_idents_Row, plan_row) |
141 |
|
|
call gather(c_idents, c_idents_Col, plan_col) |
142 |
|
|
|
143 |
|
|
do i = 1, nrow |
144 |
|
|
me = getFirstMatchingElement(atypes, "c_ident", c_idents_Row(i)) |
145 |
|
|
atid_Row(i) = me |
146 |
|
|
enddo |
147 |
|
|
|
148 |
|
|
do i = 1, ncol |
149 |
|
|
me = getFirstMatchingElement(atypes, "c_ident", c_idents_Col(i)) |
150 |
|
|
atid_Col(i) = me |
151 |
|
|
enddo |
152 |
|
|
|
153 |
|
|
!! free temporary ident arrays |
154 |
|
|
if (allocated(c_idents_Col)) then |
155 |
|
|
deallocate(c_idents_Col) |
156 |
|
|
end if |
157 |
|
|
if (allocated(c_idents_Row)) then |
158 |
|
|
deallocate(c_idents_Row) |
159 |
|
|
endif |
160 |
|
|
|
161 |
|
|
#else |
162 |
|
|
do i = 1, nComponents |
163 |
|
|
|
164 |
|
|
me = getFirstMatchingElement(atypes, "c_ident", c_idents(i)) |
165 |
|
|
atid(i) = me |
166 |
|
|
|
167 |
|
|
enddo |
168 |
|
|
#endif |
169 |
|
|
|
170 |
|
|
!! Create neighbor lists |
171 |
|
|
call expandNeighborList(nComponents, thisStat) |
172 |
|
|
if (thisStat /= 0) then |
173 |
|
|
status = -1 |
174 |
|
|
return |
175 |
|
|
endif |
176 |
gezelter |
332 |
|
177 |
|
|
do i = 1, nExcludes_Local |
178 |
|
|
excludesLocal(1,i) = CexcludesLocal(1,i) |
179 |
|
|
excludesLocal(2,i) = CexcludesLocal(2,i) |
180 |
|
|
enddo |
181 |
gezelter |
325 |
|
182 |
gezelter |
332 |
do i = 1, nExcludes_Global |
183 |
|
|
excludesGlobal(i) = CexcludesGlobal(i) |
184 |
|
|
enddo |
185 |
|
|
|
186 |
gezelter |
325 |
if (status == 0) simulation_setup_complete = .true. |
187 |
gezelter |
332 |
|
188 |
gezelter |
325 |
end subroutine SimulationSetup |
189 |
|
|
|
190 |
gezelter |
360 |
subroutine setBox_3d(new_box_size) |
191 |
mmeineke |
270 |
real(kind=dp), dimension(3) :: new_box_size |
192 |
gezelter |
360 |
integer :: smallest, status, i |
193 |
|
|
|
194 |
mmeineke |
270 |
thisSim%box = new_box_size |
195 |
gezelter |
330 |
box = thisSim%box |
196 |
mmeineke |
270 |
|
197 |
gezelter |
360 |
smallest = 1 |
198 |
|
|
do i = 2, 3 |
199 |
|
|
if (new_box_size(i) .lt. new_box_size(smallest)) smallest = i |
200 |
|
|
end do |
201 |
|
|
if (thisSim%rcut .gt. 0.5_dp * new_box_size(smallest)) & |
202 |
|
|
call setRcut(0.5_dp * new_box_size(smallest), status) |
203 |
|
|
return |
204 |
|
|
end subroutine setBox_3d |
205 |
|
|
|
206 |
|
|
subroutine setBox_1d(dim, new_box_size) |
207 |
|
|
integer :: dim, status |
208 |
|
|
real(kind=dp) :: new_box_size |
209 |
|
|
thisSim%box(dim) = new_box_size |
210 |
|
|
box(dim) = thisSim%box(dim) |
211 |
|
|
if (thisSim%rcut .gt. 0.5_dp * new_box_size) & |
212 |
|
|
call setRcut(0.5_dp * new_box_size, status) |
213 |
|
|
end subroutine setBox_1d |
214 |
|
|
|
215 |
|
|
subroutine setRcut(new_rcut, status) |
216 |
|
|
real(kind = dp) :: new_rcut |
217 |
|
|
integer :: myStatus, status |
218 |
|
|
thisSim%rcut = new_rcut |
219 |
|
|
rcut2 = thisSim%rcut * thisSim%rcut |
220 |
|
|
rcut6 = rcut2 * rcut2 * rcut2 |
221 |
|
|
myStatus = 0 |
222 |
|
|
call LJ_new_rcut(new_rcut, myStatus) |
223 |
|
|
if (myStatus .ne. 0) then |
224 |
|
|
write(default_error, *) 'LJ module refused our rcut!' |
225 |
|
|
status = -1 |
226 |
|
|
return |
227 |
|
|
endif |
228 |
|
|
status = 0 |
229 |
|
|
return |
230 |
|
|
end subroutine setRcut |
231 |
|
|
|
232 |
mmeineke |
270 |
function getBox_3d() result(thisBox) |
233 |
|
|
real( kind = dp ), dimension(3) :: thisBox |
234 |
|
|
thisBox = thisSim%box |
235 |
|
|
end function getBox_3d |
236 |
gezelter |
360 |
|
237 |
|
|
function getBox_1d(dim) result(thisBox) |
238 |
mmeineke |
270 |
integer, intent(in) :: dim |
239 |
|
|
real( kind = dp ) :: thisBox |
240 |
gezelter |
312 |
|
241 |
mmeineke |
270 |
thisBox = thisSim%box(dim) |
242 |
gezelter |
360 |
end function getBox_1d |
243 |
gezelter |
312 |
|
244 |
gezelter |
325 |
subroutine getRcut(thisrcut,rc2,rc6,status) |
245 |
mmeineke |
270 |
real( kind = dp ), intent(out) :: thisrcut |
246 |
gezelter |
325 |
real( kind = dp ), intent(out), optional :: rc2 |
247 |
|
|
real( kind = dp ), intent(out), optional :: rc6 |
248 |
mmeineke |
270 |
integer, optional :: status |
249 |
|
|
|
250 |
|
|
if (present(status)) status = 0 |
251 |
gezelter |
325 |
|
252 |
|
|
if (.not.simulation_setup_complete ) then |
253 |
mmeineke |
270 |
if (present(status)) status = -1 |
254 |
|
|
return |
255 |
|
|
end if |
256 |
|
|
|
257 |
|
|
thisrcut = thisSim%rcut |
258 |
gezelter |
325 |
if(present(rc2)) rc2 = rcut2 |
259 |
|
|
if(present(rc6)) rc6 = rcut6 |
260 |
mmeineke |
270 |
end subroutine getRcut |
261 |
|
|
|
262 |
gezelter |
325 |
subroutine getRlist(thisrlist,rl2,status) |
263 |
mmeineke |
270 |
real( kind = dp ), intent(out) :: thisrlist |
264 |
gezelter |
325 |
real( kind = dp ), intent(out), optional :: rl2 |
265 |
mmeineke |
270 |
|
266 |
|
|
integer, optional :: status |
267 |
|
|
|
268 |
|
|
if (present(status)) status = 0 |
269 |
|
|
|
270 |
gezelter |
325 |
if (.not.simulation_setup_complete ) then |
271 |
mmeineke |
270 |
if (present(status)) status = -1 |
272 |
|
|
return |
273 |
|
|
end if |
274 |
|
|
|
275 |
|
|
thisrlist = thisSim%rlist |
276 |
gezelter |
325 |
if(present(rl2)) rl2 = rlist2 |
277 |
gezelter |
312 |
end subroutine getRlist |
278 |
mmeineke |
270 |
|
279 |
gezelter |
312 |
function getRrf() result(rrf) |
280 |
|
|
real( kind = dp ) :: rrf |
281 |
|
|
rrf = thisSim%rrf |
282 |
|
|
end function getRrf |
283 |
mmeineke |
270 |
|
284 |
gezelter |
312 |
function getRt() result(rt) |
285 |
|
|
real( kind = dp ) :: rt |
286 |
|
|
rt = thisSim%rt |
287 |
|
|
end function getRt |
288 |
gezelter |
329 |
|
289 |
|
|
function getDielect() result(dielect) |
290 |
|
|
real( kind = dp ) :: dielect |
291 |
|
|
dielect = thisSim%dielect |
292 |
|
|
end function getDielect |
293 |
gezelter |
360 |
|
294 |
gezelter |
325 |
function SimUsesPBC() result(doesit) |
295 |
|
|
logical :: doesit |
296 |
|
|
doesit = thisSim%SIM_uses_PBC |
297 |
|
|
end function SimUsesPBC |
298 |
|
|
|
299 |
|
|
function SimUsesLJ() result(doesit) |
300 |
|
|
logical :: doesit |
301 |
|
|
doesit = thisSim%SIM_uses_LJ |
302 |
|
|
end function SimUsesLJ |
303 |
|
|
|
304 |
|
|
function SimUsesSticky() result(doesit) |
305 |
|
|
logical :: doesit |
306 |
|
|
doesit = thisSim%SIM_uses_sticky |
307 |
|
|
end function SimUsesSticky |
308 |
|
|
|
309 |
|
|
function SimUsesDipoles() result(doesit) |
310 |
|
|
logical :: doesit |
311 |
|
|
doesit = thisSim%SIM_uses_dipoles |
312 |
|
|
end function SimUsesDipoles |
313 |
|
|
|
314 |
|
|
function SimUsesRF() result(doesit) |
315 |
|
|
logical :: doesit |
316 |
|
|
doesit = thisSim%SIM_uses_RF |
317 |
|
|
end function SimUsesRF |
318 |
|
|
|
319 |
|
|
function SimUsesGB() result(doesit) |
320 |
|
|
logical :: doesit |
321 |
|
|
doesit = thisSim%SIM_uses_GB |
322 |
|
|
end function SimUsesGB |
323 |
|
|
|
324 |
|
|
function SimUsesEAM() result(doesit) |
325 |
|
|
logical :: doesit |
326 |
|
|
doesit = thisSim%SIM_uses_EAM |
327 |
|
|
end function SimUsesEAM |
328 |
|
|
|
329 |
gezelter |
329 |
function SimUsesDirectionalAtoms() result(doesit) |
330 |
|
|
logical :: doesit |
331 |
|
|
doesit = thisSim%SIM_uses_dipoles .or. thisSim%SIM_uses_sticky .or. & |
332 |
|
|
thisSim%SIM_uses_GB .or. thisSim%SIM_uses_RF |
333 |
gezelter |
330 |
end function SimUsesDirectionalAtoms |
334 |
gezelter |
329 |
|
335 |
gezelter |
325 |
function SimRequiresPrepairCalc() result(doesit) |
336 |
|
|
logical :: doesit |
337 |
|
|
doesit = thisSim%SIM_uses_EAM |
338 |
|
|
end function SimRequiresPrepairCalc |
339 |
|
|
|
340 |
|
|
function SimRequiresPostpairCalc() result(doesit) |
341 |
|
|
logical :: doesit |
342 |
|
|
doesit = thisSim%SIM_uses_RF |
343 |
|
|
end function SimRequiresPostpairCalc |
344 |
gezelter |
312 |
|
345 |
gezelter |
360 |
subroutine InitializeSimGlobals(thisStat) |
346 |
gezelter |
325 |
integer, intent(out) :: thisStat |
347 |
|
|
integer :: alloc_stat |
348 |
|
|
|
349 |
|
|
thisStat = 0 |
350 |
|
|
|
351 |
gezelter |
360 |
call FreeSimGlobals() |
352 |
gezelter |
325 |
|
353 |
gezelter |
360 |
allocate(excludesLocal(2,nExcludes_Local), stat=alloc_stat) |
354 |
gezelter |
325 |
if (alloc_stat /= 0 ) then |
355 |
gezelter |
332 |
thisStat = -1 |
356 |
gezelter |
325 |
return |
357 |
|
|
endif |
358 |
|
|
|
359 |
gezelter |
360 |
allocate(excludesGlobal(nExcludes_Global), stat=alloc_stat) |
360 |
gezelter |
325 |
if (alloc_stat /= 0 ) then |
361 |
gezelter |
332 |
thisStat = -1 |
362 |
gezelter |
325 |
return |
363 |
|
|
endif |
364 |
|
|
|
365 |
gezelter |
360 |
end subroutine InitializeSimGlobals |
366 |
gezelter |
312 |
|
367 |
gezelter |
360 |
subroutine FreeSimGlobals() |
368 |
gezelter |
325 |
|
369 |
|
|
!We free in the opposite order in which we allocate in. |
370 |
gezelter |
332 |
|
371 |
|
|
if (allocated(excludesGlobal)) deallocate(excludesGlobal) |
372 |
|
|
if (allocated(excludesLocal)) deallocate(excludesLocal) |
373 |
gezelter |
360 |
|
374 |
|
|
end subroutine FreeSimGlobals |
375 |
gezelter |
361 |
|
376 |
|
|
pure function getNlocal() result(nlocal) |
377 |
|
|
integer :: nlocal |
378 |
|
|
nlocal = natoms |
379 |
|
|
end function getNlocal |
380 |
|
|
|
381 |
gezelter |
309 |
|
382 |
mmeineke |
270 |
end module simulation |