ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/simulation_module.F90
(Generate patch)

Comparing trunk/OOPSE/libmdtools/simulation_module.F90 (file contents):
Revision 394 by gezelter, Mon Mar 24 21:55:34 2003 UTC vs.
Revision 1138 by gezelter, Wed Apr 28 21:39:22 2004 UTC

# Line 6 | Line 6 | module simulation
6    use force_globals
7    use vector_class
8    use atype_module
9  use lj
9   #ifdef IS_MPI
10    use mpiSimulation
11   #endif
# Line 17 | Line 16 | module simulation
16   #define __FORTRAN90
17   #include "fSimulation.h"
18  
19 <  type (simtype), public :: thisSim
19 >  type (simtype), public, save :: thisSim
20  
21    logical, save :: simulation_setup_complete = .false.
22  
23 <  integer, public, save :: natoms
23 >  integer, public, save :: nLocal, nGlobal
24    integer, public, save :: nExcludes_Global = 0
25    integer, public, save :: nExcludes_Local = 0
26    integer, allocatable, dimension(:,:), public :: excludesLocal
27    integer, allocatable, dimension(:), public :: excludesGlobal
28 +  integer, allocatable, dimension(:), public :: molMembershipList
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 <
30 >  real(kind=dp), public, dimension(3,3), save :: Hmat, HmatInv
31 >  logical, public, save :: boxIsOrthorhombic
32    
33    public :: SimulationSetup
34    public :: getNlocal
35    public :: setBox
39  public :: setBox_3d
40  public :: getBox
41  public :: setRcut
42  public :: getRcut
43  public :: getRlist
44  public :: getRrf
45  public :: getRt
36    public :: getDielect
37    public :: SimUsesPBC
38    public :: SimUsesLJ
39 +  public :: SimUsesCharges
40    public :: SimUsesDipoles
41    public :: SimUsesSticky
42    public :: SimUsesRF
# Line 54 | Line 45 | module simulation
45    public :: SimRequiresPrepairCalc
46    public :: SimRequiresPostpairCalc
47    public :: SimUsesDirectionalAtoms
48 <
58 <  interface getBox
59 <     module procedure getBox_3d
60 <     module procedure getBox_1d
61 <  end interface
48 >  public :: SimUsesMolecularCutoffs
49    
63  interface setBox
64     module procedure setBox_3d
65     module procedure setBox_1d
66  end interface
67  
50   contains
51    
52 <  subroutine SimulationSetup(setThisSim, nComponents, c_idents, &
52 >  subroutine SimulationSetup(setThisSim, CnGlobal, CnLocal, c_idents, &
53         CnLocalExcludes, CexcludesLocal, CnGlobalExcludes, CexcludesGlobal, &
54 +       CmolMembership, &
55         status)    
56  
57      type (simtype) :: setThisSim
58 <    integer, intent(inout) :: nComponents
59 <    integer, dimension(nComponents),intent(inout) :: c_idents
58 >    integer, intent(inout) :: CnGlobal, CnLocal
59 >    integer, dimension(CnLocal),intent(inout) :: c_idents
60  
61      integer :: CnLocalExcludes
62      integer, dimension(2,CnLocalExcludes), intent(in) :: CexcludesLocal
63      integer :: CnGlobalExcludes
64      integer, dimension(CnGlobalExcludes), intent(in) :: CexcludesGlobal
65 +    integer, dimension(CnGlobal),intent(in) :: CmolMembership
66      !!  Result status, success = 0, status = -1
67      integer, intent(out) :: status
68      integer :: i, me, thisStat, alloc_stat, myNode
# Line 93 | Line 77 | contains
77      status = 0
78  
79      ! copy C struct into fortran type
80 +
81 +    nLocal = CnLocal
82 +    nGlobal = CnGlobal
83 +
84      thisSim = setThisSim
97    natoms = nComponents
98    rcut2 = thisSim%rcut * thisSim%rcut
99    rcut6 = rcut2 * rcut2 * rcut2
100    rlist2 = thisSim%rlist * thisSim%rlist
101    box = thisSim%box
85  
86      nExcludes_Global = CnGlobalExcludes
87      nExcludes_Local = CnLocalExcludes
88  
89 <    call InitializeForceGlobals(natoms, thisStat)
89 >    call InitializeForceGlobals(nLocal, thisStat)
90      if (thisStat /= 0) then
91 +       write(default_error,*) "SimSetup: InitializeForceGlobals error"
92         status = -1
93         return
94      endif
95  
96      call InitializeSimGlobals(thisStat)
97      if (thisStat /= 0) then
98 +       write(default_error,*) "SimSetup: InitializeSimGlobals error"
99         status = -1
100         return
101      endif
# Line 159 | Line 144 | contains
144         deallocate(c_idents_Row)
145      endif
146      
147 < #else
148 <    do i = 1, nComponents
147 > #endif
148 >
149 > ! We build the local atid's for both mpi and nonmpi
150 >    do i = 1, nLocal
151        
152         me = getFirstMatchingElement(atypes, "c_ident", c_idents(i))
153         atid(i) = me
154    
155      enddo
169 #endif
156  
171    !! Create neighbor lists
172    call expandNeighborList(nComponents, thisStat)
173    if (thisStat /= 0) then
174       status = -1
175       return
176    endif
157  
158  
159 +
160      do i = 1, nExcludes_Local
161         excludesLocal(1,i) = CexcludesLocal(1,i)
162         excludesLocal(2,i) = CexcludesLocal(2,i)
# Line 184 | Line 165 | contains
165      do i = 1, nExcludes_Global
166         excludesGlobal(i) = CexcludesGlobal(i)
167      enddo
168 <    
168 >
169 >    do i = 1, nGlobal
170 >       molMemberShipList(i) = CmolMembership(i)
171 >     enddo
172 >
173      if (status == 0) simulation_setup_complete = .true.
174      
175    end subroutine SimulationSetup
176    
177 <  subroutine setBox_3d(new_box_size)
178 <    real(kind=dp), dimension(3) :: new_box_size
177 >  subroutine setBox(cHmat, cHmatInv, cBoxIsOrthorhombic)
178 >    real(kind=dp), dimension(3,3) :: cHmat, cHmatInv
179 >    integer :: cBoxIsOrthorhombic
180      integer :: smallest, status, i
181 <
182 <    thisSim%box = new_box_size
183 <    box = thisSim%box
184 <
185 <    smallest = 1
186 <    do i = 2, 3
187 <       if (new_box_size(i) .lt. new_box_size(smallest)) smallest = i
188 <    end do
189 <    if (thisSim%rcut .gt. 0.5_dp * new_box_size(smallest)) &
204 <         call setRcut(0.5_dp * new_box_size(smallest), status)
181 >    
182 >    Hmat = cHmat
183 >    HmatInv = cHmatInv
184 >    if (cBoxIsOrthorhombic .eq. 0 ) then
185 >       boxIsOrthorhombic = .false.
186 >    else
187 >       boxIsOrthorhombic = .true.
188 >    endif
189 >    
190      return    
191 <  end subroutine setBox_3d
207 <
208 <  subroutine setBox_1d(dim, new_box_size)
209 <    integer :: dim, status
210 <    real(kind=dp) :: new_box_size
211 <    thisSim%box(dim) = new_box_size
212 <    box(dim) = thisSim%box(dim)
213 <    if (thisSim%rcut .gt. 0.5_dp * new_box_size) &
214 <         call setRcut(0.5_dp * new_box_size, status)
215 <  end subroutine setBox_1d
191 >  end subroutine setBox
192  
217  subroutine setRcut(new_rcut, status)
218    real(kind = dp) :: new_rcut
219    integer :: myStatus, status
220    thisSim%rcut = new_rcut
221    rcut2 = thisSim%rcut * thisSim%rcut
222    rcut6 = rcut2 * rcut2 * rcut2
223    myStatus = 0
224    call LJ_new_rcut(new_rcut, myStatus)
225    if (myStatus .ne. 0) then
226       write(default_error, *) 'LJ module refused our rcut!'
227       status = -1
228       return
229    endif
230    status = 0
231    return
232  end subroutine setRcut
233
234  function getBox_3d() result(thisBox)
235    real( kind = dp ), dimension(3) :: thisBox
236    thisBox = thisSim%box
237  end function getBox_3d
238  
239  function getBox_1d(dim) result(thisBox)
240    integer, intent(in) :: dim
241    real( kind = dp ) :: thisBox
242    
243    thisBox = thisSim%box(dim)
244  end function getBox_1d
245    
246  subroutine getRcut(thisrcut,rc2,rc6,status)
247    real( kind = dp ), intent(out) :: thisrcut
248    real( kind = dp ), intent(out), optional :: rc2
249    real( kind = dp ), intent(out), optional :: rc6
250    integer, optional :: status
251
252    if (present(status)) status = 0
253    
254    if (.not.simulation_setup_complete ) then
255       if (present(status)) status = -1
256       return
257    end if
258    
259    thisrcut = thisSim%rcut
260    if(present(rc2)) rc2 = rcut2
261    if(present(rc6)) rc6 = rcut6
262  end subroutine getRcut
263  
264  subroutine getRlist(thisrlist,rl2,status)
265    real( kind = dp ), intent(out) :: thisrlist
266    real( kind = dp ), intent(out), optional :: rl2
267
268    integer, optional :: status
269
270    if (present(status)) status = 0
271
272    if (.not.simulation_setup_complete ) then
273       if (present(status)) status = -1
274       return
275    end if
276    
277    thisrlist = thisSim%rlist
278    if(present(rl2)) rl2 = rlist2
279  end subroutine getRlist
280
281  function getRrf() result(rrf)
282    real( kind = dp ) :: rrf
283    rrf = thisSim%rrf
284    write(*,*) 'getRrf = ', rrf, thisSim%rrf
285  end function getRrf
286  
287  function getRt() result(rt)
288    real( kind = dp ) :: rt
289    rt = thisSim%rt
290  end function getRt
291
193    function getDielect() result(dielect)
194      real( kind = dp ) :: dielect
195      dielect = thisSim%dielect
# Line 309 | Line 210 | contains
210      doesit = thisSim%SIM_uses_sticky
211    end function SimUsesSticky
212  
213 +  function SimUsesCharges() result(doesit)
214 +    logical :: doesit
215 +    doesit = thisSim%SIM_uses_charges
216 +  end function SimUsesCharges
217 +
218    function SimUsesDipoles() result(doesit)
219      logical :: doesit
220      doesit = thisSim%SIM_uses_dipoles
# Line 335 | Line 241 | contains
241           thisSim%SIM_uses_GB .or. thisSim%SIM_uses_RF
242    end function SimUsesDirectionalAtoms
243  
244 +  function SimUsesMolecularCutoffs() result(doesit)
245 +    logical :: doesit
246 +    doesit = thisSim%SIM_uses_molecular_cutoffs
247 +  end function SimUsesMolecularCutoffs
248 +
249    function SimRequiresPrepairCalc() result(doesit)
250      logical :: doesit
251      doesit = thisSim%SIM_uses_EAM
# Line 364 | Line 275 | contains
275         thisStat = -1
276         return
277      endif
278 +
279 +    allocate(molMembershipList(nGlobal), stat=alloc_stat)
280 +    if (alloc_stat /= 0 ) then
281 +       thisStat = -1
282 +       return
283 +    endif
284      
285    end subroutine InitializeSimGlobals
286    
287    subroutine FreeSimGlobals()
288      
289      !We free in the opposite order in which we allocate in.
290 <    
290 >
291 >    if (allocated(molMembershipList)) deallocate(molMembershipList)    
292      if (allocated(excludesGlobal)) deallocate(excludesGlobal)
293      if (allocated(excludesLocal)) deallocate(excludesLocal)
294  
295    end subroutine FreeSimGlobals
296  
297 <  pure function getNlocal() result(nlocal)
298 <    integer :: nlocal
299 <    nlocal = natoms
297 >  pure function getNlocal() result(n)
298 >    integer :: n
299 >    n = nLocal
300    end function getNlocal
301  
302    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines