ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE_old/src/mdtools/libmdCode/simulation_module.F90
(Generate patch)

Comparing trunk/OOPSE_old/src/mdtools/libmdCode/simulation_module.F90 (file contents):
Revision 358 by gezelter, Mon Mar 17 21:07:50 2003 UTC vs.
Revision 360 by gezelter, Tue Mar 18 16:46:47 2003 UTC

# Line 3 | Line 3 | module simulation
3   module simulation
4    use definitions
5    use neighborLists
6 +  use force_globals
7    use vector_class
8    use atype_module
9 +  use lj
10   #ifdef IS_MPI
11    use mpiSimulation
12   #endif
# Line 22 | Line 24 | module simulation
24    integer :: natoms
25    integer, public, save :: nExcludes_Global = 0
26    integer, public, save :: nExcludes_Local = 0
27 +  integer, allocatable, dimension(:,:), public :: excludesLocal
28 +  integer, allocatable, dimension(:), public :: excludesGlobal
29  
30    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    real(kind=dp), public, dimension(3), save :: box
34  
31 #ifdef IS_MPI
32  real( kind = dp ), allocatable, dimension(:,:), public :: q_Row
33  real( kind = dp ), allocatable, dimension(:,:), public :: q_Col
34  real( kind = dp ), allocatable, dimension(:,:), public :: u_l_Row
35  real( kind = dp ), allocatable, dimension(:,:), public :: u_l_Col
36  real( kind = dp ), allocatable, dimension(:,:), public :: A_Row
37  real( kind = dp ), allocatable, dimension(:,:), public :: A_Col
35    
39  real( kind = dp ), allocatable, dimension(:), public :: pot_Row
40  real( kind = dp ), allocatable, dimension(:), public :: pot_Col
41  real( kind = dp ), allocatable, dimension(:), public :: pot_Temp
42  real( kind = dp ), allocatable, dimension(:,:), public :: f_Row
43  real( kind = dp ), allocatable, dimension(:,:), public :: f_Col
44  real( kind = dp ), allocatable, dimension(:,:), public :: f_Temp
45  real( kind = dp ), allocatable, dimension(:,:), public :: t_Row
46  real( kind = dp ), allocatable, dimension(:,:), public :: t_Col
47  real( kind = dp ), allocatable, dimension(:,:), public :: t_Temp
48  real( kind = dp ), allocatable, dimension(:,:), public :: rf_Row
49  real( kind = dp ), allocatable, dimension(:,:), public :: rf_Col
50  real( kind = dp ), allocatable, dimension(:,:), public :: rf_Temp
51
52  integer, allocatable, dimension(:), public :: atid_Row
53  integer, allocatable, dimension(:), public :: atid_Col
54 #else
55  integer, allocatable, dimension(:), public :: atid
56 #endif
57  real( kind = dp ), allocatable, dimension(:,:), public :: rf
58  integer, allocatable, dimension(:,:), public :: excludesLocal
59  integer, allocatable, dimension(:), public :: excludesGlobal
60  real(kind = dp), dimension(9), public :: tau_Temp = 0.0_dp
61  real(kind = dp), public :: virial_Temp = 0.0_dp
62  
36    public :: SimulationSetup
37 +  public :: setBox
38    public :: getBox
39 +  public :: setRcut
40    public :: getRcut
41    public :: getRlist
42    public :: getRrf
43    public :: getRt
44    public :: getDielect
70  public :: getNlocal
45    public :: SimUsesPBC
46    public :: SimUsesLJ
47    public :: SimUsesDipoles
# Line 81 | Line 55 | module simulation
55  
56    interface getBox
57       module procedure getBox_3d
58 <     module procedure getBox_dim
58 >     module procedure getBox_1d
59    end interface
60    
61 +  interface setBox
62 +     module procedure setBox_3d
63 +     module procedure setBox_1d
64 +  end interface
65 +  
66   contains
67    
68    subroutine SimulationSetup(setThisSim, nComponents, c_idents, &
# Line 120 | Line 99 | contains
99      nExcludes_Global = CnGlobalExcludes
100      nExcludes_Local = CnLocalExcludes
101  
102 <    call setupGlobals(thisStat)
102 >    call InitializeForceGlobals(natoms, thisStat)
103      if (thisStat /= 0) then
104         status = -1
105         return
106      endif
107  
108 +    call InitializeSimGlobals(thisStat)
109 +    if (thisStat /= 0) then
110 +       status = -1
111 +       return
112 +    endif
113 +
114   #ifdef IS_MPI
115      ! We can only set up forces if mpiSimulation has been setup.
116      if (.not. isMPISimSet()) then
# Line 199 | Line 184 | contains
184      
185    end subroutine SimulationSetup
186    
187 <  subroutine change_box_size(new_box_size)
187 >  subroutine setBox_3d(new_box_size)
188      real(kind=dp), dimension(3) :: new_box_size
189 +    integer :: smallest, status, i
190 +
191      thisSim%box = new_box_size
192      box = thisSim%box
206  end subroutine change_box_size
193  
194 +    smallest = 1
195 +    do i = 2, 3
196 +       if (new_box_size(i) .lt. new_box_size(smallest)) smallest = i
197 +    end do
198 +    if (thisSim%rcut .gt. 0.5_dp * new_box_size(smallest)) &
199 +         call setRcut(0.5_dp * new_box_size(smallest), status)
200 +    return    
201 +  end subroutine setBox_3d
202 +
203 +  subroutine setBox_1d(dim, new_box_size)
204 +    integer :: dim, status
205 +    real(kind=dp) :: new_box_size
206 +    thisSim%box(dim) = new_box_size
207 +    box(dim) = thisSim%box(dim)
208 +    if (thisSim%rcut .gt. 0.5_dp * new_box_size) &
209 +         call setRcut(0.5_dp * new_box_size, status)
210 +  end subroutine setBox_1d
211 +
212 +  subroutine setRcut(new_rcut, status)
213 +    real(kind = dp) :: new_rcut
214 +    integer :: myStatus, status
215 +    thisSim%rcut = new_rcut
216 +    rcut2 = thisSim%rcut * thisSim%rcut
217 +    rcut6 = rcut2 * rcut2 * rcut2
218 +    myStatus = 0
219 +    call LJ_new_rcut(new_rcut, myStatus)
220 +    if (myStatus .ne. 0) then
221 +       write(default_error, *) 'LJ module refused our rcut!'
222 +       status = -1
223 +       return
224 +    endif
225 +    status = 0
226 +    return
227 +  end subroutine setRcut
228 +
229    function getBox_3d() result(thisBox)
230      real( kind = dp ), dimension(3) :: thisBox
231      thisBox = thisSim%box
232    end function getBox_3d
233 <
234 <  function getBox_dim(dim) result(thisBox)
233 >  
234 >  function getBox_1d(dim) result(thisBox)
235      integer, intent(in) :: dim
236      real( kind = dp ) :: thisBox
237      
238      thisBox = thisSim%box(dim)
239 <  end function getBox_dim
239 >  end function getBox_1d
240      
241    subroutine getRcut(thisrcut,rc2,rc6,status)
242      real( kind = dp ), intent(out) :: thisrcut
# Line 266 | Line 287 | contains
287      real( kind = dp ) :: dielect
288      dielect = thisSim%dielect
289    end function getDielect
290 <  
270 <  pure function getNlocal() result(nlocal)
271 <    integer :: nlocal
272 <    nlocal = natoms
273 <  end function getNlocal
274 <    
290 >      
291    function SimUsesPBC() result(doesit)
292      logical :: doesit
293      doesit = thisSim%SIM_uses_PBC
# Line 323 | Line 339 | contains
339      doesit = thisSim%SIM_uses_RF
340    end function SimRequiresPostpairCalc
341    
342 <  subroutine setupGlobals(thisStat)
342 >  subroutine InitializeSimGlobals(thisStat)
343      integer, intent(out) :: thisStat
328    integer :: nrow
329    integer :: ncol
330    integer :: nlocal
331    integer :: ndim = 3
344      integer :: alloc_stat
345      
346      thisStat = 0
347      
348 < #ifdef IS_MPI
337 <    nrow = getNrow(plan_row)
338 <    ncol = getNcol(plan_col)
339 < #endif
340 <    nlocal = getNlocal()
348 >    call FreeSimGlobals()    
349      
342    call freeGlobals()
343    
344 #ifdef IS_MPI
345
346    allocate(q_Row(ndim,nrow),stat=alloc_stat)
347    if (alloc_stat /= 0 ) then
348       thisStat = -1
349       return
350    endif
351        
352    allocate(q_Col(ndim,ncol),stat=alloc_stat)
353    if (alloc_stat /= 0 ) then
354       thisStat = -1
355       return
356    endif
357      
358    allocate(u_l_Row(ndim,nrow),stat=alloc_stat)
359    if (alloc_stat /= 0 ) then
360       thisStat = -1
361       return
362    endif
363    
364    allocate(u_l_Col(ndim,ncol),stat=alloc_stat)
365    if (alloc_stat /= 0 ) then
366       thisStat = -1
367       return
368    endif
369    
370    allocate(A_row(9,nrow),stat=alloc_stat)
371    if (alloc_stat /= 0 ) then
372       thisStat = -1
373       return
374    endif
375        
376    allocate(A_Col(9,ncol),stat=alloc_stat)
377    if (alloc_stat /= 0 ) then
378       thisStat = -1
379       return
380    endif
381    
382    allocate(pot_row(nrow),stat=alloc_stat)
383    if (alloc_stat /= 0 ) then
384       thisStat = -1
385       return
386    endif
387    
388    allocate(pot_Col(ncol),stat=alloc_stat)
389    if (alloc_stat /= 0 ) then
390       thisStat = -1
391       return
392    endif
393
394    allocate(pot_Temp(nlocal),stat=alloc_stat)
395    if (alloc_stat /= 0 ) then
396       thisStat = -1
397       return
398    endif
399    
400    allocate(f_Row(ndim,nrow),stat=alloc_stat)
401    if (alloc_stat /= 0 ) then
402       thisStat = -1
403       return
404    endif
405    
406    allocate(f_Col(ndim,ncol),stat=alloc_stat)
407    if (alloc_stat /= 0 ) then
408       thisStat = -1
409       return
410    endif
411    
412    allocate(f_Temp(ndim,nlocal),stat=alloc_stat)
413    if (alloc_stat /= 0 ) then
414       thisStat = -1
415       return
416    endif
417    
418    allocate(t_Row(ndim,nrow),stat=alloc_stat)
419    if (alloc_stat /= 0 ) then
420       thisStat = -1
421       return
422    endif
423    
424    allocate(t_Col(ndim,ncol),stat=alloc_stat)
425    if (alloc_stat /= 0 ) then
426       thisStat = -1
427       return
428    endif
429
430    allocate(t_temp(ndim,nlocal),stat=alloc_stat)
431    if (alloc_stat /= 0 ) then
432       thisStat = -1
433       return
434    endif
435
436    allocate(atid_Row(nrow),stat=alloc_stat)
437    if (alloc_stat /= 0 ) then
438       thisStat = -1
439       return
440    endif
441
442    allocate(atid_Col(ncol),stat=alloc_stat)
443    if (alloc_stat /= 0 ) then
444       thisStat = -1
445       return
446    endif
447
448    allocate(rf_Row(ndim,nrow),stat=alloc_stat)
449    if (alloc_stat /= 0 ) then
450       thisStat = -1
451       return
452    endif
453
454    allocate(rf_Col(ndim,ncol),stat=alloc_stat)
455    if (alloc_stat /= 0 ) then
456       thisStat = -1
457       return
458    endif
459
460    allocate(rf_Temp(ndim,nlocal),stat=alloc_stat)
461    if (alloc_stat /= 0 ) then
462       thisStat = -1
463       return
464    endif
465
466
467 #else
468
469    allocate(atid(nlocal),stat=alloc_stat)
470    if (alloc_stat /= 0 ) then
471       thisStat = -1
472       return
473    end if
474
475 #endif
476    
477    allocate(rf(ndim,nlocal),stat=alloc_stat)
478    if (alloc_stat /= 0 ) then
479       thisStat = -1
480       return
481    endif
482
483
350      allocate(excludesLocal(2,nExcludes_Local), stat=alloc_stat)
351      if (alloc_stat /= 0 ) then
352         thisStat = -1
353         return
354      endif
355 <
355 >    
356      allocate(excludesGlobal(nExcludes_Global), stat=alloc_stat)
357      if (alloc_stat /= 0 ) then
358         thisStat = -1
359         return
360      endif
361 <
362 <  end subroutine setupGlobals
361 >    
362 >  end subroutine InitializeSimGlobals
363    
364 <  subroutine freeGlobals()
364 >  subroutine FreeSimGlobals()
365      
366      !We free in the opposite order in which we allocate in.
367      
368      if (allocated(excludesGlobal)) deallocate(excludesGlobal)
369      if (allocated(excludesLocal)) deallocate(excludesLocal)
370 <    if (allocated(rf))         deallocate(rf)
371 < #ifdef IS_MPI
506 <    if (allocated(rf_Temp))    deallocate(rf_Temp)
507 <    if (allocated(rf_Col))     deallocate(rf_Col)
508 <    if (allocated(rf_Row))     deallocate(rf_Row)    
509 <    if (allocated(atid_Col))   deallocate(atid_Col)
510 <    if (allocated(atid_Row))   deallocate(atid_Row)
511 <    if (allocated(t_Temp))     deallocate(t_Temp)
512 <    if (allocated(t_Col))      deallocate(t_Col)
513 <    if (allocated(t_Row))      deallocate(t_Row)
514 <    if (allocated(f_Temp))     deallocate(f_Temp)
515 <    if (allocated(f_Col))      deallocate(f_Col)
516 <    if (allocated(f_Row))      deallocate(f_Row)
517 <    if (allocated(pot_Temp))   deallocate(pot_Temp)
518 <    if (allocated(pot_Col))    deallocate(pot_Col)
519 <    if (allocated(pot_Row))    deallocate(pot_Row)
520 <    if (allocated(A_Col))      deallocate(A_Col)
521 <    if (allocated(A_Row))      deallocate(A_Row)
522 <    if (allocated(u_l_Col))    deallocate(u_l_Col)
523 <    if (allocated(u_l_Row))    deallocate(u_l_Row)
524 <    if (allocated(q_Col))      deallocate(q_Col)
525 <    if (allocated(q_Row))      deallocate(q_Row)    
526 < #else    
527 <    if (allocated(atid))       deallocate(atid)    
528 < #endif
529 <        
530 <  end subroutine freeGlobals
370 >
371 >  end subroutine FreeSimGlobals
372    
373   end module simulation

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines