ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/md_code/lj_FF.F90
(Generate patch)

Comparing trunk/mdtools/md_code/lj_FF.F90 (file contents):
Revision 246 by chuckv, Fri Jan 24 21:36:52 2003 UTC vs.
Revision 281 by chuckv, Mon Feb 24 21:25:15 2003 UTC

# Line 2 | Line 2
2   !! Corresponds to the force field defined in lj_FF.cpp
3   !! @author Charles F. Vardeman II
4   !! @author Matthew Meineke
5 < !! @version $Id: lj_FF.F90,v 1.10 2003-01-24 21:36:52 chuckv Exp $, $Date: 2003-01-24 21:36:52 $, $Name: not supported by cvs2svn $, $Revision: 1.10 $
5 > !! @version $Id: lj_FF.F90,v 1.19 2003-02-24 21:25:15 chuckv Exp $, $Date: 2003-02-24 21:25:15 $, $Name: not supported by cvs2svn $, $Revision: 1.19 $
6  
7  
8  
9   module lj_ff
10    use simulation
11    use definitions
12 +  use generic_atypes
13   #ifdef IS_MPI
14    use mpiSimulation
15   #endif
# Line 18 | Line 19 | module lj_ff
19   !! Number of lj_atypes in lj_atype_list
20    integer, save :: n_lj_atypes = 0
21  
22 < !! Starting Size for ljMixed Array
23 <  integer, parameter :: ljMixed_blocksize = 10
22 > !! Global list of lj atypes in simulation
23 >  type (lj_atype), pointer :: ljListHead => null()
24 >  type (lj_atype), pointer :: ljListTail => null()
25  
24 !! Basic atom type for a Lennard-Jones Atom.
25  type, public :: lj_atype
26     private
27     sequence
28 !! Unique number for place in linked list
29     integer :: atype_number = 0
30 !! Unique indentifier number (ie atomic no, etc)
31     integer :: atype_ident = 0
32 !! Mass of Particle
33     real ( kind = dp )  :: mass = 0.0_dp
34 !! Lennard-Jones epslon
35     real ( kind = dp )  :: epsilon = 0.0_dp
36 !! Lennard-Jones Sigma
37     real ( kind = dp )  :: sigma = 0.0_dp
38 !! Lennard-Jones Sigma Squared
39     real ( kind = dp )  :: sigma2 = 0.0_dp
40 !! Lennard-Jones Sigma to sixth
41     real ( kind = dp )  :: sigma6 = 0.0_dp
42 !! Pointer for linked list creation
43     type (lj_atype), pointer :: next => null()
44  end type lj_atype
26  
46 !! Pointer type for atype ident array
47  type, public :: lj_atypePtr
48     type (lj_atype), pointer :: this => null()
49  end type lj_atypePtr
50
51 !! Global list of lj atypes in simulation
52  type (lj_atype), pointer :: lj_atype_list => null()
27   !! LJ mixing array  
28    type (lj_atype), dimension(:,:), pointer :: ljMixed => null()
55 !! identity pointer list for force loop.
56  type (lj_atypePtr), dimension(:), pointer :: identPtrList => null()
29  
30  
31   !! Neighbor list and commom arrays
# Line 64 | Line 36 | module lj_ff
36    integer :: nListAllocs = 0
37    integer, parameter :: maxListAllocs = 5
38  
39 < #ifdef IS_MPI
68 < ! Universal routines: All types of force calculations will need these arrays
69 < ! Arrays specific to a type of force calculation should be declared in that module.
70 < !! Row position array.
71 <  real( kind = dp ), allocatable, dimension(:,:) :: qRow
72 < !! Column position array.
73 <  real( kind = dp ), allocatable, dimension(:,:) :: qColumn
39 >  logical, save :: firstTime = .True.
40  
41 < !! Row Force array.
42 <  real( kind = dp ), allocatable, dimension(:,:) :: fRow
77 < !! Column Force Array.
78 <  real( kind = dp ), allocatable, dimension(:,:) :: fColumn
79 <
80 < !! Row potential energy array
81 <  real( kind = dp ), allocatable, dimension(:) :: eRow
82 < !! Column potential energy array
83 <  real( kind = dp ), allocatable, dimension(:) :: eColumn
84 <
85 <
41 > !! Atype identity pointer lists
42 > #ifdef IS_MPI
43   !! Row lj_atype pointer list
44 <  type (lj_atypePtr), dimension(:), pointer :: identPtrListRow => null()
44 >  type (lj_identPtrList), dimension(:), pointer :: identPtrListRow => null()
45   !! Column lj_atype pointer list
46 <  type (lj_atypePtr), dimension(:), pointer :: identPtrListColumn => null()
46 >  type (lj_identPtrList), dimension(:), pointer :: identPtrListColumn => null()
47 > #else
48 >  type( lj_identPtrList ), dimension(:), pointer :: identPtrList => null()
49   #endif
50  
51  
# Line 105 | Line 64 | contains
64  
65   contains
66  
67 + !! Adds a new lj_atype to the list.
68    subroutine new_lj_atype(ident,mass,epsilon,sigma,status)
69      real( kind = dp ), intent(in) :: mass
70      real( kind = dp ), intent(in) :: epsilon
# Line 112 | Line 72 | contains
72      integer, intent(in) :: ident
73      integer, intent(out) :: status
74  
75 <    type (lj_atype), pointer :: this_lj_atype
116 <    type (lj_atype), pointer :: lj_atype_ptr
117 <
118 <    type (lj_atype), dimension(:,:), pointer :: thisMix
119 <    type (lj_atype), dimension(:,:), pointer :: oldMix
75 >    type (lj_atype), pointer :: newLJ_atype
76      integer :: alloc_error
77      integer :: atype_counter = 0
78      integer :: alloc_size
79 <
79 >    integer :: err_stat
80      status = 0
81  
82  
83  
84   ! allocate a new atype    
85 <    allocate(this_lj_atype,stat=alloc_error)
85 >    allocate(newLJ_atype,stat=alloc_error)
86      if (alloc_error /= 0 ) then
87         status = -1
88         return
89      end if
90  
91   ! assign our new lj_atype information
92 <    this_lj_atype%mass        = mass
93 <    this_lj_atype%epsilon     = epsilon
94 <    this_lj_atype%sigma       = sigma
95 <    this_lj_atype%sigma2      = sigma * sigma
96 <    this_lj_atype%sigma6      = this_lj_atype%sigma2 * this_lj_atype%sigma2 &
97 <         * this_lj_atype%sigma2
92 >    newLJ_atype%mass        = mass
93 >    newLJ_atype%epsilon     = epsilon
94 >    newLJ_atype%sigma       = sigma
95 >    newLJ_atype%sigma2      = sigma * sigma
96 >    newLJ_atype%sigma6      = newLJ_atype%sigma2 * newLJ_atype%sigma2 &
97 >         * newLJ_atype%sigma2
98   ! assume that this atype will be successfully added
99 <    this_lj_atype%atype_ident = ident
100 <    this_lj_atype%atype_number = n_lj_atypes + 1
99 >    newLJ_atype%atype_ident = ident
100 >    newLJ_atype%atype_number = n_lj_atypes + 1
101  
102 <
103 < ! First time through allocate a array of size ljMixed_blocksize
104 <    if(.not. associated(ljMixed)) then
105 <       allocate(thisMix(ljMixed_blocksize,ljMixed_blocksize))
150 <       if (alloc_error /= 0 ) then
151 <          status = -1
152 <          return
153 <       end if
154 <       ljMixed => thisMix
155 < ! If we have outgrown ljMixed_blocksize, allocate a new matrix twice the size and
156 < ! point ljMix at the new matrix.
157 <    else if( (n_lj_atypes + 1) > size(ljMixed)) then
158 <       alloc_size = 2*size(ljMixed)
159 <       allocate(thisMix(alloc_size,alloc_size))
160 <       if (alloc_error /= 0 ) then
161 <          status = -1
162 <          return
163 <       end if
164 < ! point oldMix at old ljMixed array
165 <       oldMix => ljMixed
166 < ! Copy oldMix into new Mixed array      
167 <       thisMix = oldMix
168 < ! Point ljMixed at new array
169 <       ljMixed => thisMix
170 < ! Free old array so we don't have a memory leak
171 <       deallocate(oldMix)
102 >    call add_atype(newLJ_atype,ljListHead,ljListTail,err_stat)
103 >    if (err_stat /= 0 ) then
104 >       status = -1
105 >       return
106      endif
107  
174
175
176
177
178 ! Find bottom of atype master list
179 ! if lj_atype_list is null then we are at the top of the list.
180    if (.not. associated(lj_atype_list)) then
181
182       write(*,*) "Associating lists for first time"
183      
184
185       this_lj_atype%atype_number = 1
186      
187       ljMixed(n_lj_atypes,n_lj_atypes)%sigma  = this_lj_atype%sigma
188      
189       ljMixed(n_lj_atypes,n_lj_atypes)%sigma2  = ljMixed(n_lj_atypes,n_lj_atypes)%sigma &
190            * ljMixed(n_lj_atypes,n_lj_atypes)%sigma
191      
192       ljMixed(n_lj_atypes,n_lj_atypes)%sigma6 = ljMixed(n_lj_atypes,n_lj_atypes)%sigma2 &
193            * ljMixed(n_lj_atypes,n_lj_atypes)%sigma2 &
194            * ljMixed(n_lj_atypes,n_lj_atypes)%sigma2
195      
196       ljMixed(n_lj_atypes,n_lj_atypes)%epsilon = this_lj_atype%epsilon
197      
198       lj_atype_list => this_lj_atype
199      
200       write(*,*) "lj_atype_list first time through -- ident", lj_atype_list%atype_ident
201    else ! we need to find the bottom of the list to insert new atype
202       write(*,*) "Second time through"
203       lj_atype_ptr => lj_atype_list
204       write(*,*) "lj_atype_ptr to next"
205       atype_counter = 1
206       find_end: do
207          if (.not. associated(lj_atype_ptr)) exit find_end
208
209          write(*,*) "Inside find_end-this ident", lj_atype_ptr%atype_ident
210 ! Set up mixing for new atype and current atype in list
211       ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma  =  &
212            calcLJMix("sigma",this_lj_atype%sigma, &
213            lj_atype_ptr%sigma)
214
215       ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma2  = &
216            ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma &
217            * ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma
218
219       ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma6 = &
220            ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma2 &
221            * ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma2 &
222            * ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%sigma2
223
224       ljMixed(this_lj_atype%atype_number,lj_atype_ptr%atype_number)%epsilon = &
225            calcLJMix("epsilon",this_lj_atype%epsilon, &
226            lj_atype_ptr%epsilon)
227
228 ! Advance to next pointer
229       lj_atype_ptr => lj_atype_ptr%next          
230       atype_counter = atype_counter + 1          
231       end do find_end
232
233       lj_atype_ptr => this_lj_atype
234       write(*,*) "just added: ", lj_atype_ptr%atype_ident
235    end if
236
237    write(*,*) "lj_atype_list now contains.."
238    
239    lj_atype_ptr => lj_atype_list
240    do while (associated(lj_atype_ptr))
241       write(*,*) "lj_atype_list contains ident", lj_atype_ptr%atype_ident
242       lj_atype_ptr => lj_atype_ptr%next
243    end do
244    
245 ! Insert new atype at end of list
246
247 ! Increment number of atypes
248
108      n_lj_atypes = n_lj_atypes + 1
109  
251 ! Set up self mixing
110  
111    end subroutine new_lj_atype
112  
# Line 266 | Line 124 | contains
124  
125      integer :: thisStat
126      integer :: i
127 +
128 +    integer :: myNode
129   #ifdef IS_MPI
130      integer, allocatable, dimension(:) :: identRow
131      integer, allocatable, dimension(:) :: identCol
132      integer :: nrow
133      integer :: ncol
274    integer :: alloc_stat
134   #endif
135      status = 0
136 +  
137  
138 <    write(*,*) "Initializing ljFF"
138 >    
139 >
140   !! if were're not in MPI, we just update ljatypePtrList
141   #ifndef IS_MPI
142 <    call new_ljatypePtrList(nComponents,ident,identPtrList,thisStat)
142 >    call create_IdentPtrlst(ident,ljListHead,identPtrList,thisStat)
143      if ( thisStat /= 0 ) then
144         status = -1
145         return
146      endif
147 <    write(*,*) "component pointer list initialized"
147 >
148   !! Allocate pointer lists
149      allocate(point(nComponents),stat=alloc_stat)
150      if (alloc_stat /=0) then
# Line 299 | Line 160 | contains
160      
161   ! if were're in MPI, we also have to worry about row and col lists    
162   #else
163 +  
164   ! We can only set up forces if mpiSimulation has been setup.
165      if (.not. isMPISimSet()) then
166 +       write(default_error,*) "MPI is not set"
167         status = -1
168         return
169      endif
170 <    nrow = getNrow()
171 <    ncol = getNcol()
170 >    nrow = getNrow(plan_row)
171 >    ncol = getNcol(plan_col)
172 >    mynode = getMyNode()
173   !! Allocate temperary arrays to hold gather information
174      allocate(identRow(nrow),stat=alloc_stat)
175      if (alloc_stat /= 0 ) then
# Line 318 | Line 182 | contains
182         status = -1
183         return
184      endif
185 +
186   !! Gather idents into row and column idents
187 +
188      call gather(ident,identRow,plan_row)
189      call gather(ident,identCol,plan_col)
190 <
190 >    
191 >  
192   !! Create row and col pointer lists
193 <    call new_ljatypePtrList(nrow,identRow,identPtrListRow,thisStat)
193 >  
194 >    call create_IdentPtrlst(identRow,ljListHead,identPtrListRow,thisStat)
195      if (thisStat /= 0 ) then
196         status = -1
197         return
198      endif
199 <
200 <    call new_ljatypePtrList(ncol,identCol,identPtrListCol,thisStat)
199 >  
200 >    call create_IdentPtrlst(identCol,ljListHead,identPtrListColumn,thisStat)
201      if (thisStat /= 0 ) then
202         status = -1
203         return
204      endif
205  
206   !! free temporary ident arrays
207 <    deallocate(identCol)
208 <    deallocate(identRow)
209 <
210 < !! Allocate Simulation arrays
211 < !! NOTE: This bit of code should be fixed, it can cause large
344 < !! memory fragmentation if call repeatedly
345 <
346 <    if (.not.allocated(qRow)) then
347 <       allocate(qRow(3,nrow),stat=alloc_stat)
348 <       if (alloc_stat /= 0 ) then
349 <          status = -1
350 <          return
351 <       endif
352 <    else
353 <       deallocate(qrow)
354 <       allocate(qRow(3,nrow),stat=alloc_stat)
355 <       if (alloc_stat /= 0 ) then
356 <          status = -1
357 <          return
358 <       endif
207 >    if (allocated(identCol)) then
208 >       deallocate(identCol)
209 >    end if
210 >    if (allocated(identCol)) then
211 >       deallocate(identRow)
212      endif
213  
361    if (.not.allocated(3,qCol)) then
362       allocate(qCol(ncol),stat=alloc_stat)
363       if (alloc_stat /= 0 ) then
364          status = -1
365          return
366       endif
367    else
368       deallocate(qCol)
369       allocate(qCol(3,ncol),stat=alloc_stat)
370       if (alloc_stat /= 0 ) then
371          status = -1
372          return
373       endif
374    endif
375
376    if (.not.allocated(fRow)) then
377       allocate(fRow(3,nrow),stat=alloc_stat)
378       if (alloc_stat /= 0 ) then
379          status = -1
380          return
381       endif
382    else
383       deallocate(fRow)
384       allocate(fRow(3,nrow),stat=alloc_stat)
385       if (alloc_stat /= 0 ) then
386          status = -1
387          return
388       endif
389    endif
390
391    if (.not.allocated(fCol)) then
392       allocate(fCol(3,ncol),stat=alloc_stat)
393       if (alloc_stat /= 0 ) then
394          status = -1
395          return
396       endif
397    else
398       deallocate(fCol)
399       allocate(fCol(3,ncol),stat=alloc_stat)
400       if (alloc_stat /= 0 ) then
401          status = -1
402          return
403       endif
404    endif
405
406    if (.not.allocated(eRow)) then
407       allocate(eRow(nrow),stat=alloc_stat)
408       if (alloc_stat /= 0 ) then
409          status = -1
410          return
411       endif
412    else
413       deallocate(eRow)
414       allocate(eRow(nrow),stat=alloc_stat)
415       if (alloc_stat /= 0 ) then
416          status = -1
417          return
418       endif
419    endif
420
421    if (.not.allocated(eCol)) then
422       allocate(eCol(ncol),stat=alloc_stat)
423       if (alloc_stat /= 0 ) then
424          status = -1
425          return
426       endif
427    else
428       deallocate(eCol)
429       allocate(eCol(ncol),stat=alloc_stat)
430       if (alloc_stat /= 0 ) then
431          status = -1
432          return
433       endif
434    endif
435
436    if (.not.allocated(eTemp)) then
437       allocate(eTemp(nComponents),stat=alloc_stat)
438       if (alloc_stat /= 0 ) then
439          status = -1
440          return
441       endif
442    else
443       deallocate(eTemp)
444       allocate(eTemp(nComponets),stat=alloc_stat)
445       if (alloc_stat /= 0 ) then
446          status = -1
447          return
448       endif
449    endif
450
451
214   !! Allocate neighbor lists for mpi simulations.
215      if (.not. allocated(point)) then
216         allocate(point(nrow),stat=alloc_stat)
# Line 480 | Line 242 | contains
242  
243   #endif
244      
245 <    
246 <    do i = 1, nComponents
247 <       write(*,*) "Ident pointer list ident: ", identPtrList(i)%this%atype_ident
248 <    end do
249 <
245 >    call createMixingList(thisStat)
246 >    if (thisStat /= 0) then
247 >       status = -1
248 >       return
249 >    endif
250      isljFFinit = .true.
251  
252 +
253    end subroutine init_ljFF
254  
255  
256  
257  
258  
496 !! Takes an ident array and creates an atype pointer list
497 !! based on those identities
498  subroutine new_ljatypePtrList(mysize,ident,PtrList,status)
499    integer, intent(in) :: mysize
500    integer,dimension(:), intent(in) :: ident
501    integer, optional :: status
502    type(lj_atypePtr), dimension(:), pointer :: PtrList
259  
260 <    integer :: thisIdent
260 >  subroutine createMixingList(status)
261 >    integer :: listSize
262 >    integer :: status
263      integer :: i
264 <    integer :: alloc_error
507 <    type (lj_atype), pointer :: tmpPtr
264 >    integer :: j
265  
266 <    if (present(status)) status = 0
266 >    integer :: outerCounter = 0
267 >    integer :: innerCounter = 0
268 >    type (lj_atype), pointer :: tmpPtrOuter => null()
269 >    type (lj_atype), pointer :: tmpPtrInner => null()
270 >    status = 0
271  
272 <    write(*,*) "Creating new ljatypePtrList...."
273 < ! First time through, allocate list
274 <    if (.not.associated(PtrList)) then
275 <       write(*,*) "allocating pointer list...."
276 <       allocate(PtrList(mysize))
277 <    else
517 < ! We want to creat a new ident list so free old list
518 <       deallocate(PtrList)
519 <       allocate(PtrList(mysize))
520 <    endif
272 >    listSize = getListLen(ljListHead)
273 >    if (listSize == 0) then
274 >       status = -1
275 >       return
276 >    end if
277 >  
278  
279 < ! Match pointer list
280 <    write(*,*) "Doing ident search"
281 <    do i = 1, mysize
282 <       thisIdent = ident(i)
283 <       write(*,*) "Calling getLJatype for ident ", thisIdent
284 <       call getLJatype(thisIdent,tmpPtr)
528 <
529 <      if (.not. associated(tmpPtr)) then
530 <         write(*,*) "tmpptr was not associated"
531 <          status = -1
532 <          return
533 <       endif
534 <      
535 <       PtrList(i)%this => tmpPtr
536 <    end do
279 >    if (.not. associated(ljMixed)) then
280 >       allocate(ljMixed(listSize,listSize))
281 >    else
282 >       status = -1
283 >       return
284 >    end if
285  
286 <  end subroutine new_ljatypePtrList
286 >    
287  
288 < !! Finds a lj_atype based upon numerical ident
289 < !! returns a null pointer if error
290 <  subroutine getLJatype(ident,ljAtypePtr)
291 <    integer, intent(in) :: ident
292 <    type (lj_atype), pointer :: ljAtypePtr    
293 <    type (lj_atype), pointer :: tmplj_atype_ptr => null()
288 >    tmpPtrOuter => ljListHead
289 >    tmpPtrInner => tmpPtrOuter%next
290 >    do while (associated(tmpPtrOuter))
291 >       outerCounter = outerCounter + 1
292 > ! do self mixing rule
293 >       ljMixed(outerCounter,outerCounter)%sigma  = tmpPtrOuter%sigma
294 >                                                                                                  
295 >       ljMixed(outerCounter,outerCounter)%sigma2  = ljMixed(outerCounter,outerCounter)%sigma &
296 >            * ljMixed(outerCounter,outerCounter)%sigma
297 >                                                                                                  
298 >       ljMixed(outerCounter,outerCounter)%sigma6 = ljMixed(outerCounter,outerCounter)%sigma2 &
299 >            * ljMixed(outerCounter,outerCounter)%sigma2 &
300 >            * ljMixed(outerCounter,outerCounter)%sigma2
301 >                                                                                                  
302 >       ljMixed(outerCounter,outerCounter)%epsilon = tmpPtrOuter%epsilon
303  
304 <    write(*,*) "Finding ljAtype for ident ", ident
305 <    ljAtypePtr => null()
304 >       innerCounter = outerCounter + 1
305 >       do while (associated(tmpPtrInner))
306 >          
307 >          ljMixed(outerCounter,innerCounter)%sigma  =  &
308 >               calcLJMix("sigma",tmpPtrOuter%sigma, &
309 >               tmpPtrInner%sigma)
310 >          
311 >          ljMixed(outerCounter,innerCounter)%sigma2  = &
312 >               ljMixed(outerCounter,innerCounter)%sigma &
313 >               * ljMixed(outerCounter,innerCounter)%sigma
314 >          
315 >          ljMixed(outerCounter,innerCounter)%sigma6 = &
316 >               ljMixed(outerCounter,innerCounter)%sigma2 &
317 >               * ljMixed(outerCounter,innerCounter)%sigma2 &
318 >               * ljMixed(outerCounter,innerCounter)%sigma2
319 >          
320 >          ljMixed(outerCounter,innerCounter)%epsilon = &
321 >               calcLJMix("epsilon",tmpPtrOuter%epsilon, &
322 >               tmpPtrInner%epsilon)
323 >          ljMixed(innerCounter,outerCounter)%sigma = ljMixed(outerCounter,innerCounter)%sigma
324 >          ljMixed(innerCounter,outerCounter)%sigma2 = ljMixed(outerCounter,innerCounter)%sigma2
325 >          ljMixed(innerCounter,outerCounter)%sigma6 = ljMixed(outerCounter,innerCounter)%sigma6
326 >          ljMixed(innerCounter,outerCounter)%epsilon = ljMixed(outerCounter,innerCounter)%epsilon
327  
550    if(.not. associated(lj_atype_list)) return
328  
329 < ! Point at head of list.
330 <    write(*,*) "Searching at head of list"
331 <    tmplj_atype_ptr => lj_atype_list
332 <    find_ident: do
333 <       if (.not.associated(tmplj_atype_ptr)) then
334 <          write(*,*) "Find_ident, pointer not associated"
335 <          exit find_ident
559 <       else if( tmplj_atype_ptr%atype_ident == ident) then
560 <          ljAtypePtr => tmplj_atype_ptr
561 <          exit find_ident
329 >          tmpPtrInner => tmpPtrInner%next
330 >          innerCounter = innerCounter + 1
331 >       end do
332 > ! advance pointers
333 >       tmpPtrOuter => tmpPtrOuter%next
334 >       if (associated(tmpPtrOuter)) then
335 >          tmpPtrInner => tmpPtrOuter%next
336         endif
337 <       tmplj_atype_ptr => tmplj_atype_ptr%next
338 <    end do find_ident
337 >      
338 >    end do
339  
340 +  end subroutine createMixingList
341  
342  
343  
569  end subroutine getLJatype
344  
345  
346 +
347 +
348 +
349   !! FORCE routine Calculates Lennard Jones forces.
350   !------------------------------------------------------------->
351 <  subroutine do_lj_ff(q,f,potE,do_pot)
351 >  subroutine do_lj_ff(q,f,potE,tau,do_pot)
352   !! Position array provided by C, dimensioned by getNlocal
353      real ( kind = dp ), dimension(3,getNlocal()) :: q
354   !! Force array provided by C, dimensioned by getNlocal
355      real ( kind = dp ), dimension(3,getNlocal()) :: f
356 + !! Stress Tensor
357 +    real( kind = dp), dimension(9) :: tau
358 +    real( kind = dp), dimension(9) :: tauTemp
359      real ( kind = dp ) :: potE
360      logical ( kind = 2) :: do_pot
361      
362      type(lj_atype), pointer :: ljAtype_i
363      type(lj_atype), pointer :: ljAtype_j
364  
365 < #ifdef MPI
366 <  real( kind = DP ), dimension(3,getNcol()) :: efr
367 <  real( kind = DP ) :: pot_local
588 < #else
589 <  real( kind = DP ), dimension(3,getNlocal()) :: efr
590 < #endif
365 >
366 >
367 >
368    
369 +
370 + #ifdef IS_MPI
371 +  real( kind = DP ) :: pot_local
372 +
373 + !! Local arrays needed for MPI
374 +  real(kind = dp), dimension(3,getNrow(plan_row)) :: qRow = 0.0_dp
375 +  real(kind = dp), dimension(3,getNcol(plan_col)) :: qCol = 0.0_dp
376 +
377 +  real(kind = dp), dimension(3,getNrow(plan_row)) :: fRow = 0.0_dp
378 +  real(kind = dp), dimension(3,getNcol(plan_col)) :: fCol = 0.0_dp
379 +  real(kind = dp), dimension(3,getNlocal()) :: fMPITemp = 0.0_dp
380 +
381 +  real(kind = dp), dimension(getNrow(plan_row)) :: eRow = 0.0_dp
382 +  real(kind = dp), dimension(getNcol(plan_col)) :: eCol = 0.0_dp
383 +
384 +  real(kind = dp), dimension(getNlocal()) :: eTemp = 0.0_dp
385 +
386 + #endif
387 +
388 +
389 +
390    real( kind = DP )   :: pe
391    logical             :: update_nlist
392  
# Line 598 | Line 396 | contains
396    integer :: j_start
397    integer :: tag_i,tag_j
398    real( kind = DP ) ::  r, pot, ftmp, dudr, d2, drdx1, kt1, kt2, kt3, ktmp
399 +  real( kind = dp ) :: fx,fy,fz
400 +  real( kind = DP ) ::  drdx, drdy, drdz
401    real( kind = DP ) ::  rxi, ryi, rzi, rxij, ryij, rzij, rijsq
402    real( kind = DP ) ::  rlistsq, rcutsq,rlist,rcut
403  
# Line 610 | Line 410 | contains
410    integer :: nrow
411    integer :: ncol
412    integer :: natoms
413 + !! should we calculate the stress tensor
414 +  logical  :: do_stress = .false.
415  
416 +
417 +
418   ! Make sure we are properly initialized.
419    if (.not. isljFFInit) then
420       write(default_error,*) "ERROR: lj_FF has not been properly initialized"
# Line 627 | Line 431 | contains
431    natoms = getNlocal()
432    call getRcut(rcut,rcut2=rcutsq)
433    call getRlist(rlist,rlistsq)
434 + !! Find ensemble
435 +  if (isEnsemble("NPT")) do_stress = .true.
436 +
437   #ifndef IS_MPI
438    nrow = natoms - 1
439    ncol = natoms
# Line 640 | Line 447 | contains
447    
448   !! See if we need to update neighbor lists
449    call check(q,update_nlist)
450 +  if (firstTime) then
451 +     update_nlist = .true.
452 +     firstTime = .false.
453 +  endif
454  
455   !--------------WARNING...........................
456   ! Zero variables, NOTE:::: Forces are zeroed in C
# Line 651 | Line 462 | contains
462    pe = 0.0E0_DP
463  
464   #else
465 <    f_row = 0.0E0_DP
466 <    f_col = 0.0E0_DP
465 >    fRow = 0.0E0_DP
466 >    fCol = 0.0E0_DP
467  
468      pe_local = 0.0E0_DP
469  
# Line 660 | Line 471 | contains
471      eCol = 0.0E0_DP
472      eTemp = 0.0E0_DP
473   #endif
663    efr = 0.0E0_DP
474  
475   ! communicate MPI positions
476 < #ifdef MPI    
477 <    call gather(q,qRow,plan_row3)
478 <    call gather(q,qCol,plan_col3)
476 > #ifdef IS_MPI    
477 >    call gather(q,qRow,plan_row3d)
478 >    call gather(q,qCol,plan_col3d)
479   #endif
480  
481  
# Line 677 | Line 487 | contains
487      
488       nlist = 0
489      
490 <    
490 >    
491  
492       do i = 1, nrow
493          point(i) = nlist + 1
494 < #ifdef MPI
494 > #ifdef IS_MPI
495          ljAtype_i => identPtrListRow(i)%this
496          tag_i = tagRow(i)
497          rxi = qRow(1,i)
# Line 696 | Line 506 | contains
506   #endif
507  
508          inner: do j = j_start, ncol
509 < #ifdef MPI
509 > #ifdef IS_MPI
510   ! Assign identity pointers and tags
511             ljAtype_j => identPtrListColumn(j)%this
512 <           tag_j = tagCol(j)
512 >           tag_j = tagColumn(j)
513             if (newtons_thrd) then
514                if (tag_i <= tag_j) then
515                   if (mod(tag_i + tag_j,2) == 0) cycle inner
# Line 720 | Line 530 | contains
530   #endif          
531             rijsq = rxij*rxij + ryij*ryij + rzij*rzij
532  
533 < #ifdef MPI
533 > #ifdef IS_MPI
534               if (rijsq <=  rlistsq .AND. &
535                    tag_j /= tag_i) then
536   #else
537 +          
538               if (rijsq <  rlistsq) then
539   #endif
540              
# Line 734 | Line 545 | contains
545                endif
546                list(nlist) = j
547  
548 <              
548 >    
549                if (rijsq <  rcutsq) then
550                  
551                   r = dsqrt(rijsq)
552        
553                   call getLJPot(r,pot,dudr,ljAtype_i,ljAtype_j)
554        
555 < #ifdef MPI
555 > #ifdef IS_MPI
556                  eRow(i) = eRow(i) + pot*0.5
557                  eCol(i) = eCol(i) + pot*0.5
558   #else
559 <                pe = pe + pot
559 >                    pe = pe + pot
560   #endif                
561              
562 <                 efr(1,j) = -rxij
563 <                 efr(2,j) = -ryij
564 <                 efr(3,j) = -rzij
565 <
566 <                 do dim = 1, 3  
567 <
568 <            
569 <                    drdx1 = efr(dim,j) / r
570 <                    ftmp = dudr * drdx1
571 <
572 <
573 < #ifdef MPI
574 <                    fCol(dim,j) = fCol(dim,j) - ftmp
575 <                    fRow(dim,i) = fRow(dim,i) + ftmp
576 < #else                    
577 <            
578 <                    f(dim,j) = f(dim,j) - ftmp
579 <                    f(dim,i) = f(dim,i) + ftmp
580 <
581 < #endif                    
582 <                 enddo
583 <              endif
584 <           endif
585 <        enddo inner
562 >                drdx = -rxij / r
563 >                drdy = -ryij / r
564 >                drdz = -rzij / r
565 >                
566 >                fx = dudr * drdx
567 >                fy = dudr * drdy
568 >                fz = dudr * drdz
569 >                
570 > #ifdef IS_MPI
571 >                fCol(1,j) = fCol(1,j) - fx
572 >                fCol(2,j) = fCol(2,j) - fy
573 >                fCol(3,j) = fCol(3,j) - fz
574 >                
575 >                fRow(1,j) = fRow(1,j) + fx
576 >                fRow(2,j) = fRow(2,j) + fy
577 >                fRow(3,j) = fRow(3,j) + fz
578 > #else
579 >                f(1,j) = f(1,j) - fx
580 >                f(2,j) = f(2,j) - fy
581 >                f(3,j) = f(3,j) - fz
582 >                f(1,i) = f(1,i) + fx
583 >                f(2,i) = f(2,i) + fy
584 >                f(3,i) = f(3,i) + fz
585 > #endif
586 >                
587 >                if (do_stress) then
588 >                   tauTemp(1) = tauTemp(1) + fx * rxij
589 >                   tauTemp(2) = tauTemp(2) + fx * ryij
590 >                   tauTemp(3) = tauTemp(3) + fx * rzij
591 >                   tauTemp(4) = tauTemp(4) + fy * rxij
592 >                   tauTemp(5) = tauTemp(5) + fy * ryij
593 >                   tauTemp(6) = tauTemp(6) + fy * rzij
594 >                   tauTemp(7) = tauTemp(7) + fz * rxij
595 >                   tauTemp(8) = tauTemp(8) + fz * ryij
596 >                   tauTemp(9) = tauTemp(9) + fz * rzij
597 >                endif
598 >             endif
599 >          enddo inner
600       enddo
601  
602 < #ifdef MPI
602 > #ifdef IS_MPI
603       point(nrow + 1) = nlist + 1
604   #else
605       point(natoms) = nlist + 1
# Line 788 | Line 613 | contains
613          JEND = POINT(i+1) - 1
614          ! check thiat molecule i has neighbors
615          if (jbeg .le. jend) then
616 < #ifdef MPI
616 > #ifdef IS_MPI
617             ljAtype_i => identPtrListRow(i)%this
618             rxi = qRow(1,i)
619             ryi = qRow(2,i)
# Line 801 | Line 626 | contains
626   #endif
627             do jnab = jbeg, jend
628                j = list(jnab)
629 < #ifdef MPI
629 > #ifdef IS_MPI
630                ljAtype_j = identPtrListColumn(j)%this
631 <              rxij = wrap(rxi - q_col(1,j), 1)
632 <              ryij = wrap(ryi - q_col(2,j), 2)
633 <              rzij = wrap(rzi - q_col(3,j), 3)
631 >              rxij = wrap(rxi - qCol(1,j), 1)
632 >              ryij = wrap(ryi - qCol(2,j), 2)
633 >              rzij = wrap(rzi - qCol(3,j), 3)
634   #else
635                ljAtype_j = identPtrList(j)%this
636                rxij = wrap(rxi - q(1,j), 1)
# Line 819 | Line 644 | contains
644                   r = dsqrt(rijsq)
645                  
646                   call getLJPot(r,pot,dudr,ljAtype_i,ljAtype_j)
647 < #ifdef MPI
647 > #ifdef IS_MPI
648                  eRow(i) = eRow(i) + pot*0.5
649                  eCol(i) = eCol(i) + pot*0.5
650   #else
651                  pe = pe + pot
652   #endif                
653 <
654 <                
655 <                 efr(1,j) = -rxij
656 <                 efr(2,j) = -ryij
657 <                 efr(3,j) = -rzij
658 <
659 <                 do dim = 1, 3                        
660 <                    
661 <                    drdx1 = efr(dim,j) / r
662 <                    ftmp = dudr * drdx1
663 < #ifdef MPI
664 <                    fCol(dim,j) = fCol(dim,j) - ftmp
665 <                    fRow(dim,i) = fRow(dim,i) + ftmp
666 < #else                    
667 <                    f(dim,j) = f(dim,j) - ftmp
668 <                    f(dim,i) = f(dim,i) + ftmp
669 < #endif                    
670 <                 enddo
671 <              endif
672 <           enddo
673 <        endif
674 <     enddo
675 <  endif
653 >  
654 >                drdx = -rxij / r
655 >                drdy = -ryij / r
656 >                drdz = -rzij / r
657 >                
658 >                fx = dudr * drdx
659 >                fy = dudr * drdy
660 >                fz = dudr * drdz
661 >                
662 > #ifdef IS_MPI
663 >                fCol(1,j) = fCol(1,j) - fx
664 >                fCol(2,j) = fCol(2,j) - fy
665 >                fCol(3,j) = fCol(3,j) - fz
666 >                
667 >                fRow(1,j) = fRow(1,j) + fx
668 >                fRow(2,j) = fRow(2,j) + fy
669 >                fRow(3,j) = fRow(3,j) + fz
670 > #else
671 >                f(1,j) = f(1,j) - fx
672 >                f(2,j) = f(2,j) - fy
673 >                f(3,j) = f(3,j) - fz
674 >                f(1,i) = f(1,i) + fx
675 >                f(2,i) = f(2,i) + fy
676 >                f(3,i) = f(3,i) + fz
677 > #endif
678 >                
679 >                if (do_stress) then
680 >                   tauTemp(1) = tauTemp(1) + fx * rxij
681 >                   tauTemp(2) = tauTemp(2) + fx * ryij
682 >                   tauTemp(3) = tauTemp(3) + fx * rzij
683 >                   tauTemp(4) = tauTemp(4) + fy * rxij
684 >                   tauTemp(5) = tauTemp(5) + fy * ryij
685 >                   tauTemp(6) = tauTemp(6) + fy * rzij
686 >                   tauTemp(7) = tauTemp(7) + fz * rxij
687 >                   tauTemp(8) = tauTemp(8) + fz * ryij
688 >                   tauTemp(9) = tauTemp(9) + fz * rzij
689 >                endif
690 >                
691 >                
692 >             endif
693 >          enddo
694 >       endif
695 >    enddo
696 > endif
697 >
698  
699  
700 <
854 < #ifdef MPI
700 > #ifdef IS_MPI
701      !!distribute forces
856    call scatter(fRow,f,plan_row3)
702  
703 <    call scatter(fCol,f_tmp,plan_col3)
703 >    call scatter(fRow,f,plan_row3d)
704  
705 +    call scatter(fCol,fMPITemp,plan_col3d)
706 +
707      do i = 1,nlocal
708 <       f(1:3,i) = f(1:3,i) + f_tmp(1:3,i)
708 >       f(1:3,i) = f(1:3,i) + fMPITemp(1:3,i)
709      end do
710  
711  
712      
713      if (do_pot) then
714 < ! scatter/gather pot_row into the members of my column
715 <       call scatter(e_row,e_tmp,plan_row)
714 >       ! scatter/gather pot_row into the members of my column
715 >       call scatter(eRow,eTemp,plan_row)
716        
717         ! scatter/gather pot_local into all other procs
718         ! add resultant to get total pot
719         do i = 1, nlocal
720 <          pe_local = pe_local + e_tmp(i)
720 >          pe_local = pe_local + eTemp(i)
721         enddo
722         if (newtons_thrd) then
723 <          e_tmp = 0.0E0_DP
724 <          call scatter(e_col,e_tmp,plan_col)
723 >          eTemp = 0.0E0_DP
724 >          call scatter(eCol,eTemp,plan_col)
725            do i = 1, nlocal
726 <             pe_local = pe_local + e_tmp(i)
726 >             pe_local = pe_local + eTemp(i)
727            enddo
728         endif
729 +       pe = pe_local
730      endif
731 <    potE = pe_local
731 >
732   #endif
733  
734      potE = pe
735  
736  
737 +    if (do_stress) then
738 + #ifdef IS_MPI
739 +       mpi_allreduce = (tau,tauTemp,9,mpi_double_precision,mpi_sum, &
740 +            mpi_comm_world,mpi_err)
741 + #else
742 +       tau = tauTemp
743 + #endif      
744 +    endif
745 +
746 +
747    end subroutine do_lj_ff
748  
749   !! Calculates the potential between two lj particles based on two lj_atype pointers, optionally returns second
# Line 941 | Line 799 | contains
799      epsilon  = ljMixed(atype1%atype_ident,atype2%atype_ident)%epsilon
800  
801  
802 <
802 >    
803 >
804      call getRcut(rcut,rcut2=rcut2,rcut6=rcut6,status=errorStat)
805      
806      r2 = r * r
# Line 980 | Line 839 | contains
839      real(kind = dp)  :: param1
840      real(kind = dp)  :: param2
841      real(kind = dp ) :: myMixParam
842 +    character(len = getStringLen()) :: thisMixingRule
843      integer, optional :: status
844  
845 <
845 > !! get the mixing rules from the simulation
846 >    thisMixingRule = returnMixingRules()
847      myMixParam = 0.0_dp
848  
849      if (present(status)) status = 0
850 <
851 <    select case (thisParam)
852 <
853 <    case ("sigma")
854 <       myMixParam = 0.5_dp * (param1 + param2)
855 <    case ("epsilon")
856 <       myMixParam = sqrt(param1 * param2)
850 >    select case (thisMixingRule)
851 >       case ("standard")
852 >          select case (thisParam)
853 >          case ("sigma")
854 >             myMixParam = 0.5_dp * (param1 + param2)
855 >          case ("epsilon")
856 >             myMixParam = sqrt(param1 * param2)
857 >          case default
858 >             status = -1
859 >          end select
860 >    case("LJglass")
861      case default
862         status = -1
863      end select
999
864    end function calcLJMix
865  
866  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines