ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/forceGlobals.F90
Revision: 318
Committed: Wed Mar 12 13:51:04 2003 UTC (21 years, 6 months ago) by chuckv
File size: 10663 byte(s)
Log Message:
Added allocation of module arrays.

File Contents

# User Rev Content
1 chuckv 306 module forceGlobals
2 gezelter 317
3 gezelter 309 use definitions
4     use simulation
5     use atype_typedefs
6 gezelter 317 use vector_class
7 gezelter 309 #ifdef IS_MPI
8     use mpiSimulation
9     #endif
10 gezelter 317
11     logical, save :: atype_vector_initialized = .false.
12     logical, save :: ff_initialized = .false.
13 chuckv 318
14 gezelter 317
15 chuckv 306 #ifdef IS_MPI
16 gezelter 317 real( kind = dp ), allocatable, dimension(:,:) :: q_Row
17     real( kind = dp ), allocatable, dimension(:,:) :: q_Col
18     real( kind = dp ), allocatable, dimension(:,:) :: u_l_Row
19     real( kind = dp ), allocatable, dimension(:,:) :: u_l_Col
20     real( kind = dp ), allocatable, dimension(:,:) :: A_Row
21     real( kind = dp ), allocatable, dimension(:,:) :: A_Col
22    
23     real( kind = dp ), allocatable, dimension(:) :: pot_Row
24     real( kind = dp ), allocatable, dimension(:) :: pot_Col
25     real( kind = dp ), allocatable, dimension(:) :: pot_Temp
26     real( kind = dp ), allocatable, dimension(:,:) :: f_Row
27     real( kind = dp ), allocatable, dimension(:,:) :: f_Col
28     real( kind = dp ), allocatable, dimension(:,:) :: f_Temp
29     real( kind = dp ), allocatable, dimension(:,:) :: t_Row
30     real( kind = dp ), allocatable, dimension(:,:) :: t_Col
31     real( kind = dp ), allocatable, dimension(:,:) :: t_Temp
32     integer, allocatable, dimension(:) :: atid_Row
33     integer, allocatable, dimension(:) :: atid_Col
34 chuckv 306 #else
35 gezelter 317 integer, allocatable, dimension(:) :: atid
36 chuckv 306 #endif
37 gezelter 317
38 gezelter 309 real(kind = dp) :: pot = 0.0_dp
39     real(kind = dp), dimension(9) :: tau_Temp = 0.0_dp
40     real(kind = dp) :: virial_Temp = 0.0_dp
41 gezelter 317
42 chuckv 306 public :: new_atype
43     public :: init_FF
44    
45 gezelter 317 contains
46 chuckv 306
47 gezelter 317 subroutine new_atype(c_ident, is_LJ, is_Sticky, is_DP, is_GB, &
48     lj_epsilon, lj_sigma, &
49     dipole_moment, &
50     sticky_w0, sticky_v0, &
51     GB_sigma, GB_l2b_ratio, GB_eps, GB_eps_ratio, GB_mu, GB_nu, &
52     status)
53    
54     real( kind = dp ), intent(in) :: lj_epsilon
55     real( kind = dp ), intent(in) :: lj_sigma
56     real( kind = dp ), intent(in) :: sticky_w0
57     real( kind = dp ), intent(in) :: sticky_v0
58     real( kind = dp ), intent(in) :: dipole_moment
59     real( kind = dp ), intent(in) :: GB_sigma, GB_l2b_ratio, GB_eps
60     real( kind = dp ), intent(in) :: GB_eps_ratio, GB_mu, GB_nu
61 chuckv 306
62 gezelter 317 integer, intent(in) :: c_ident
63 chuckv 306 integer, intent(out) :: status
64 gezelter 317 integer, intent(in) :: is_Sticky
65     integer, intent(in) :: is_DP
66     integer, intent(in) :: is_GB
67     integer, intent(in) :: is_LJ
68     integer :: me
69     logical :: l_is_LJ, l_is_DP, l_is_Sticky, l_is_GB
70 chuckv 306
71     status = 0
72    
73 gezelter 317 if (.not.atype_vector_initialized) then
74     !! There are 16 properties to worry about for now.
75     !! Fix this if needed for more atomic properties
76     atypes = initialize(16)
77     if (.not.associated(atypes)) then
78     status = -1
79     return
80     endif
81     endif
82 chuckv 306
83 gezelter 317 me = addElement(atypes)
84 chuckv 306
85 gezelter 317 call setElementProperty(atypes, me, "c_ident", c_ident)
86 chuckv 306
87 gezelter 317 l_is_LJ = (is_LJ .ne. 0)
88     l_is_DP = (is_DP .ne. 0)
89     l_is_Sticky = (is_Sticky .ne. 0)
90     l_is_GB = (is_GB .ne. 0)
91 gezelter 309
92 gezelter 317 call setElementProperty(atypes, me, "is_LJ", l_is_LJ)
93     call setElementProperty(atypes, me, "is_DP", l_is_DP)
94     call setElementProperty(atypes, me, "is_Sticky", l_is_Sticky)
95     call setElementProperty(atypes, me, "is_GB", l_is_GB)
96 chuckv 306
97 gezelter 317 if (l_is_LJ) then
98     call setElementProperty(atypes, me, "lj_sigma", lj_sigma)
99     call setElementProperty(atypes, me, "lj_epsilon", lj_epsilon)
100 chuckv 306 endif
101 gezelter 317 if (l_is_DP) then
102     call setElementProperty(atypes, me, "dipole_moment", dipole_moment)
103     endif
104     if (l_is_Sticky) then
105     call setElementProperty(atypes, me, "sticky_w0", sticky_w0)
106     call setElementProperty(atypes, me, "sticky_v0", sticky_v0)
107     endif
108     if (l_is_GB) then
109     call setElementProperty(atypes, me, "GB_sigma", GB_sigma)
110     call setElementProperty(atypes, me, "GB_l2b_ratio", GB_l2b_ratio)
111     call setElementProperty(atypes, me, "GB_eps", GB_eps)
112     call setElementProperty(atypes, me, "GB_eps_ratio", GB_eps_ratio)
113     call setElementProperty(atypes, me, "GB_mu", GB_mu)
114     call setElementProperty(atypes, me, "GB_nu", GB_nu)
115     endif
116    
117 chuckv 306 end subroutine new_atype
118    
119 gezelter 317
120     subroutine init_FF(nComponents, c_idents, nExcludes, excludesLocal, status)
121     !! Number of components in c_idents array
122 chuckv 306 integer, intent(inout) :: nComponents
123 gezelter 317 !! Array of identities nComponents long corresponding to
124     !! ljatype ident.
125     integer, dimension(nComponents),intent(inout) :: c_idents
126 chuckv 306 integer :: nExcludes
127 gezelter 309 integer, dimension(nExcludes),intent(inout) :: excludesLocal
128 gezelter 317 !! Result status, success = 0, error = -1
129     integer, intent(out) :: status
130     integer :: i, me, thisStat
131     integer :: myNode
132 chuckv 306
133     #ifdef IS_MPI
134 gezelter 317 integer, allocatable, dimension(:) :: c_idents_Row
135     integer, allocatable, dimension(:) :: c_idents_Col
136 chuckv 306 integer :: nrow
137     integer :: ncol
138     #endif
139 gezelter 317
140 chuckv 306 status = 0
141    
142    
143 gezelter 317 #ifdef IS_MPI
144     ! We can only set up forces if mpiSimulation has been setup.
145 chuckv 306 if (.not. isMPISimSet()) then
146     write(default_error,*) "MPI is not set"
147     status = -1
148     return
149     endif
150     nrow = getNrow(plan_row)
151     ncol = getNcol(plan_col)
152     mynode = getMyNode()
153 gezelter 317
154     allocate(c_idents_Row(nrow),stat=alloc_stat)
155 chuckv 306 if (alloc_stat /= 0 ) then
156     status = -1
157     return
158     endif
159    
160 gezelter 317 allocate(c_idents_Col(ncol),stat=alloc_stat)
161 chuckv 306 if (alloc_stat /= 0 ) then
162     status = -1
163     return
164     endif
165    
166 gezelter 317 call gather(c_idents, c_idents_Row, plan_row)
167     call gather(c_idents, c_idents_Col, plan_col)
168    
169     allocate(atid_Row(nrow),stat=alloc_stat)
170     if (alloc_stat /= 0 ) then
171 chuckv 306 status = -1
172     return
173     endif
174 gezelter 317
175     allocate(atid_Col(ncol),stat=alloc_stat)
176     if (alloc_stat /= 0 ) then
177 chuckv 306 status = -1
178     return
179     endif
180    
181 gezelter 317 do i = 1, nrow
182     me = getFirstMatchingElement(atypes, "c_ident", c_idents_Row(i))
183     atid_Row(i) = me
184     enddo
185    
186     do i = 1, ncol
187     me = getFirstMatchingElement(atypes, "c_ident", c_idents_Col(i))
188     atid_Col(i) = me
189     enddo
190    
191     !! free temporary ident arrays
192 chuckv 306 if (allocated(identCol)) then
193     deallocate(identCol)
194     end if
195     if (allocated(identCol)) then
196     deallocate(identRow)
197     endif
198 gezelter 317
199     #else
200     do i = 1, nComponents
201 chuckv 306
202 gezelter 317 me = getFirstMatchingElement(atypes, "c_ident", c_idents(i))
203     atid(i) = me
204    
205     enddo
206 chuckv 306 #endif
207 gezelter 317
208 chuckv 306 call initForce_Modules(thisStat)
209     if (thisStat /= 0) then
210     status = -1
211     return
212     endif
213 gezelter 317
214     !! Create neighbor lists
215 chuckv 306 call expandList(thisStat)
216     if (thisStat /= 0) then
217     status = -1
218     return
219     endif
220 gezelter 317
221 chuckv 315 call setupGlobals(thisStat)
222     if (thisStat /= 0) then
223     status = -1
224     return
225     endif
226 gezelter 309
227 gezelter 317 ff_initialized = .true.
228 gezelter 309
229 gezelter 317
230 chuckv 306 end subroutine init_FF
231 gezelter 317
232 chuckv 315 subroutine setupGlobals(thisStat)
233     integer, intent(out) :: thisStat
234 chuckv 318 integer :: nrow
235     integer :: ncol
236     integer :: nlocal
237     integer :: ndim = 3
238     integer :: alloc_stat
239    
240     thisStat = 0
241    
242     #ifdef IS_MPI
243     nrow = getNrow(plan_row)
244     ncol = getNcol(plan_col)
245     #endif
246     nlocal = getNlocal()
247    
248     call freeGlobals()
249    
250     allocate(q_Row(ndim,nrow),stat=alloc_stat)
251     if (alloc_stat /= 0 ) then
252     thisStat = 0
253     return
254     endif
255 gezelter 317
256 chuckv 318
257     allocate(q_Col(ndim,ncol),stat=alloc_stat)
258     if (alloc_stat /= 0 ) then
259     thisStat = 0
260     return
261     endif
262    
263    
264     allocate(u_l_Row(ndim,nrow),stat=alloc_stat)
265     if (alloc_stat /= 0 ) then
266     thisStat = 0
267     return
268     endif
269    
270    
271     allocate(u_l_Col(ndim,ncol),stat=alloc_stat)
272     if (alloc_stat /= 0 ) then
273     thisStat = 0
274     return
275     endif
276    
277    
278     allocate(A_row(9,nrow),stat=alloc_stat)
279     if (alloc_stat /= 0 ) then
280     thisStat = 0
281     return
282     endif
283    
284    
285     allocate(A_Col(9,ncol),stat=alloc_stat)
286     if (alloc_stat /= 0 ) then
287     thisStat = 0
288     return
289     endif
290    
291    
292     allocate(pot_row(nrow),stat=alloc_stat)
293     if (alloc_stat /= 0 ) then
294     thisStat = 0
295     return
296     endif
297    
298     allocate(pot_Col(ncol),stat=alloc_stat)
299     if (alloc_stat /= 0 ) then
300     thisStat = 0
301     return
302     endif
303    
304     allocate(pot_Temp(nlocal),stat=alloc_stat)
305     if (alloc_stat /= 0 ) then
306     thisStat = 0
307     return
308     endif
309    
310     allocate(f_Row(ndim,nrow),stat=alloc_stat)
311     if (alloc_stat /= 0 ) then
312     thisStat = 0
313     return
314     endif
315    
316     allocate(f_Col(ndim,ncol),stat=alloc_stat)
317     if (alloc_stat /= 0 ) then
318     thisStat = 0
319     return
320     endif
321    
322     allocate(f_Temp(ndim,nlocal),stat=alloc_stat)
323     if (alloc_stat /= 0 ) then
324     thisStat = 0
325     return
326     endif
327    
328     allocate(t_Row(ndim,nrow),stat=alloc_stat)
329     if (alloc_stat /= 0 ) then
330     thisStat = 0
331     return
332     endif
333    
334     allocate(t_Col(ndim,ncol),stat=alloc_stat)
335     if (alloc_stat /= 0 ) then
336     thisStat = 0
337     return
338     endif
339    
340     allocate(t_temp(ndim,nlocal),stat=alloc_stat)
341     if (alloc_stat /= 0 ) then
342     thisStat = 0
343     return
344     endif
345    
346     allocate(atid_Row(nrow),stat=alloc_stat)
347     if (alloc_stat /= 0 ) then
348     thisStat = 0
349     return
350     endif
351    
352     allocate(atid_Col(ncol),stat=alloc_stat)
353     if (alloc_stat /= 0 ) then
354     thisStat = 0
355     return
356     endif
357    
358     #else
359    
360     allocate(atid(nlocal),stat=alloc_stat)
361     if (alloc_stat /= 0 ) then
362     thisStat = 0
363     return
364     end if
365     #endif
366    
367 chuckv 315 end subroutine setupGlobals
368 gezelter 317
369 chuckv 318 subroutine freeGlobals()
370    
371     !We free in the opposite order in which we allocate in.
372     #ifdef IS_MPI
373    
374     if (allocated(atid_Col)) deallocate(atid_Col)
375     if (allocated(atid_Row)) deallocate(atid_Row)
376     if (allocated(t_Temp)) deallocate(t_Temp)
377     if (allocated(t_Col)) deallocate(t_Col)
378     if (allocated(t_Row)) deallocate(t_Row)
379     if (allocated(f_Temp)) deallocate(f_Temp)
380     if (allocated(f_Col)) deallocate(f_Col)
381     if (allocated(f_Row)) deallocate(f_Row)
382     if (allocated(pot_Temp)) deallocate(pot_Temp)
383     if (allocated(pot_Col)) deallocate(pot_Col)
384     if (allocated(pot_Row)) deallocate(pot_Row)
385     if (allocated(A_Col)) deallocate(A_Col)
386     if (allocated(A_Row)) deallocate(A_Row)
387     if (allocated(u_l_Col)) deallocate(u_l_Col)
388     if (allocated(u_l_Row)) deallocate(u_l_Row)
389     if (allocated(q_Col)) deallocate(q_Col)
390     if (allocated(q_Row)) deallocate(q_Row)
391    
392     #else
393    
394     if (allocated(atid)) deallocate(atid)
395    
396     #endif
397    
398    
399     end subroutine freeGlobals
400    
401    
402    
403    
404 gezelter 317
405 chuckv 306 subroutine initForce_Modules(thisStat)
406     integer, intent(out) :: thisStat
407     integer :: my_status
408    
409     thisStat = 0
410 gezelter 317 call init_lj_FF(my_status)
411 chuckv 306 if (my_status /= 0) then
412     thisStat = -1
413     return
414     end if
415 gezelter 317
416 chuckv 306 end subroutine initForce_Modules
417 gezelter 317
418 chuckv 306 end module forceGlobals