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 270 by mmeineke, Fri Feb 14 17:08:46 2003 UTC vs.
Revision 290 by chuckv, Thu Feb 27 21:25:47 2003 UTC

# Line 1 | Line 1
1 + !! Fortran interface to C entry plug.
2 +
3   module simulation
4    use definitions, ONLY :dp
5   #ifdef IS_MPI
# Line 7 | Line 9 | module simulation
9    implicit none
10    PRIVATE
11  
12 + #define __FORTRAN90
13 + #include "../headers/fsimulation.h"
14  
11
12  type, public :: simtype
13     PRIVATE
14 !     SEQUENCE
15 !! Number of particles on this processor
16     integer :: nLRparticles
17 !! Periodic Box    
18     real ( kind = dp ), dimension(3) :: box
19 !! List Cutoff    
20     real ( kind = dp ) :: rlist = 0.0_dp
21 !! Radial cutoff
22     real ( kind = dp ) :: rcut  = 0.0_dp
23 !! List cutoff squared
24     real ( kind = dp ) :: rlistsq = 0.0_dp
25 !! Radial Cutoff squared
26     real ( kind = dp ) :: rcutsq  = 0.0_dp
27 !! Radial Cutoff^6
28     real ( kind = dp ) :: rcut6  = 0.0_dp
29
30  end type simtype
31
15    type (simtype), public :: thisSim
33 !! Tag for MPI calculations  
34  integer, allocatable, dimension(:) :: tag
16  
36 #ifdef IS_MPI
37  integer, allocatable, dimension(:) :: tag_row
38  integer, allocatable, dimension(:) :: tag_column
39 #endif
40
41 !! WARNING: use_pbc hardcoded, fixme
42  logical :: use_pbc = .true.
17    logical :: setSim = .false.
18  
45 !! array for saving previous positions for neighbor lists.  
46  real( kind = dp ), allocatable,dimension(:,:),save :: q0
19  
48
49  public :: check
50  public :: save_nlist
20    public :: wrap
21    public :: getBox
22    public :: getRcut
23    public :: getRlist
24    public :: getNlocal
25    public :: setSimulation
26 +  public :: isEnsemble
27 +  public :: isPBC
28 +  public :: getStringLen
29 +  public :: returnMixingRules
30 +
31   !  public :: setRcut
32  
33    interface wrap
# Line 69 | Line 43 | module simulation
43  
44  
45  
72
73
74
75
76
77
46   contains
47  
48 <  subroutine setSimulation(nLRParticles,box,rlist,rcut)
49 <    integer, intent(in) :: nLRParticles
50 <    real(kind = dp ), intent(in), dimension(3) :: box
83 <    real(kind = dp ), intent(in) :: rlist
84 <    real(kind = dp ), intent(in) :: rcut
48 >  subroutine setSimulation(setThisSim,error)
49 >    type (simtype) :: setThisSim
50 >    integer :: error
51      integer :: alloc_stat
52 <    if( setsim ) return  ! simulation is already initialized
52 >
53 >    error = 0
54      setSim = .true.
55  
56 <    thisSim%nLRParticles = nLRParticles
57 <    thisSim%box          = box
91 <    thisSim%rlist        = rlist
92 <    thisSIm%rlistsq      = rlist * rlist
93 <    thisSim%rcut         = rcut
94 <    thisSim%rcutsq       = rcut * rcut
95 <    thisSim%rcut6        = thisSim%rcutsq * thisSim%rcutsq * thisSim%rcutsq
96 <    
97 <    if (.not. allocated(q0)) then
98 <       allocate(q0(3,nLRParticles),stat=alloc_stat)
99 <    endif
56 > ! copy C struct into fortran type
57 >    thisSim = setThisSim
58    end subroutine setSimulation
59  
60    function getNparticles() result(nparticles)
# Line 124 | Line 82 | contains
82  
83      thisBox = thisSim%box(dim)
84    end function getBox_dim
127    
128  subroutine check(q,update_nlist)
129    real( kind = dp ), dimension(:,:)  :: q
130    integer :: i
131    real( kind = DP ) :: dispmx
132    logical, intent(out) :: update_nlist
133    real( kind = DP ) :: dispmx_tmp
134    real( kind = dp ) :: skin_thickness
135    integer :: natoms
136
137    natoms = thisSim%nLRparticles
138    skin_thickness = thisSim%rlist - thisSim%rcut
139    dispmx = 0.0E0_DP
140    !! calculate the largest displacement of any atom in any direction
141    
142 #ifdef MPI
143    dispmx_tmp = 0.0E0_DP
144    do i = 1, thisSim%nLRparticles
145       dispmx_tmp = max( abs ( q(1,i) - q0(1,i) ), dispmx )
146       dispmx_tmp = max( abs ( q(2,i) - q0(2,i) ), dispmx )
147       dispmx_tmp = max( abs ( q(3,i) - q0(3,i) ), dispmx )
148    end do
149    call mpi_allreduce(dispmx_tmp,dispmx,1,mpi_double_precision, &
150       mpi_max,mpi_comm_world,mpi_err)
151 #else
152
153    do i = 1, thisSim%nLRparticles
154       dispmx = max( abs ( q(1,i) - q0(1,i) ), dispmx )
155       dispmx = max( abs ( q(2,i) - q0(2,i) ), dispmx )
156       dispmx = max( abs ( q(3,i) - q0(3,i) ), dispmx )
157    end do
158 #endif
85    
160    !! a conservative test of list skin crossings
161    dispmx = 2.0E0_DP * sqrt (3.0E0_DP * dispmx * dispmx)
162    
163    update_nlist = (dispmx.gt.(skin_thickness))
164    
165  end subroutine check
166  
167  subroutine save_nlist(q)
168    real(kind = dp ), dimension(:,:), intent(in)  :: q
169    integer :: list_size
170    
86  
172    list_size = size(q)
173
174    if (.not. allocated(q0)) then
175       allocate(q0(3,list_size))
176    else if( list_size > size(q0)) then
177       deallocate(q0)
178       allocate(q0(3,list_size))
179    endif
180
181    q0 = q
182
183  end subroutine save_nlist
184  
185
87    function wrap_1d(r,dim) result(this_wrap)
88      
89      
# Line 205 | Line 106 | contains
106      real( kind = dp ), dimension(3) :: this_wrap
107  
108      
109 <    if (use_pbc) then
109 >    if (this_sim%use_pbc) then
110         !     this_wrap = r - box(dim)*dsign(1.0E0_DP,r)*int(abs(r/box(dim)) + 0.5E0_DP)
111         this_wrap = r - thisSim%box*nint(r/thisSim%box)
112      else
# Line 264 | Line 165 | contains
165    end function getNlocal
166  
167  
168 +  function isEnsemble(this_ensemble) result(is_this_ensemble)
169 +    character(len = *) :: this_ensemble
170 +    logical :: is_this_enemble
171 +    is_this_ensemble = .false.
172 +    if (this_ensemble == thisSim%ensemble) is_this_ensemble = .true.
173 +  end function isEnsemble
174  
175 +  function returnEnsemble() result(thisEnsemble)
176 +    character (len = len(thisSim%ensemble)) :: thisEnsemble
177 +    thisEnsemble = thisSim%ensemble
178 +  end function returnEnsemble
179 +
180 +  function returnMixingRules() result(thisMixingRule)
181 +    character (len = len(thisSim%ensemble)) :: thisMixingRule
182 +    thisMixingRule = thisSim%MixingRule
183 +  end function returnMixingRules
184 +
185 +  function isPBC() result(PBCset)
186 +    logical :: PBCset
187 +    PBCset = .false.
188 +    if (thisSim%use_pbc) PBCset = .true.
189 +  end function isPBC
190 +
191 +  pure function getStringLen() result (thislen)
192 +    integer :: thislen    
193 +    thislen = string_len
194 +  end function setStringLen
195 +
196   end module simulation

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines