ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/UseTheForce/DarkSide/switcheroo.F90
Revision: 725
Committed: Fri Nov 11 15:21:55 2005 UTC (19 years, 8 months ago) by chrisfen
Original Path: trunk/src/UseTheForce/DarkSide/switcheroo.F90
File size: 5895 byte(s)
Log Message:
added in a 5th order polynomial switching function

File Contents

# User Rev Content
1 gezelter 246 !!
2     !! Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3     !!
4     !! The University of Notre Dame grants you ("Licensee") a
5     !! non-exclusive, royalty free, license to use, modify and
6     !! redistribute this software in source and binary code form, provided
7     !! that the following conditions are met:
8     !!
9     !! 1. Acknowledgement of the program authors must be made in any
10     !! publication of scientific results based in part on use of the
11     !! program. An acceptable form of acknowledgement is citation of
12     !! the article in which the program was described (Matthew
13     !! A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14     !! J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15     !! Parallel Simulation Engine for Molecular Dynamics,"
16     !! J. Comput. Chem. 26, pp. 252-271 (2005))
17     !!
18     !! 2. Redistributions of source code must retain the above copyright
19     !! notice, this list of conditions and the following disclaimer.
20     !!
21     !! 3. Redistributions in binary form must reproduce the above copyright
22     !! notice, this list of conditions and the following disclaimer in the
23     !! documentation and/or other materials provided with the
24     !! distribution.
25     !!
26     !! This software is provided "AS IS," without a warranty of any
27     !! kind. All express or implied conditions, representations and
28     !! warranties, including any implied warranty of merchantability,
29     !! fitness for a particular purpose or non-infringement, are hereby
30     !! excluded. The University of Notre Dame and its licensors shall not
31     !! be liable for any damages suffered by licensee as a result of
32     !! using, modifying or distributing the software or its
33     !! derivatives. In no event will the University of Notre Dame or its
34     !! licensors be liable for any lost revenue, profit or data, or for
35     !! direct, indirect, special, consequential, incidental or punitive
36     !! damages, however caused and regardless of the theory of liability,
37     !! arising out of the use of or inability to use software, even if the
38     !! University of Notre Dame has been advised of the possibility of
39     !! such damages.
40     !!
41    
42 gezelter 115 module switcheroo
43    
44     use definitions
45    
46     implicit none
47     PRIVATE
48    
49     #define __FORTRAN90
50     #include "UseTheForce/fSwitchingFunction.h"
51 chrisfen 725 #include "UseTheForce/DarkSide/fSwitchingFunctionType.h"
52 gezelter 115
53     real ( kind = dp ), dimension(NSWITCHTYPES) :: rin
54     real ( kind = dp ), dimension(NSWITCHTYPES) :: rout
55     real ( kind = dp ), dimension(NSWITCHTYPES) :: rin2
56     real ( kind = dp ), dimension(NSWITCHTYPES) :: rout2
57 chrisfen 725 real ( kind = dp ), save :: c0, c1, c2, c3, c4, c5
58 gezelter 115
59     logical, dimension(NSWITCHTYPES) :: isOK
60 chrisfen 725 logical, save :: haveFunctionType = .false.
61     integer, save :: functionType = CUBIC
62 gezelter 115
63    
64     public::set_switch
65 chrisfen 725 public::set_function_type
66 gezelter 115 public::get_switch
67    
68     contains
69    
70     subroutine set_switch(SwitchType, rinner, router)
71    
72     real ( kind = dp ), intent(in):: rinner, router
73     integer, intent(in) :: SwitchType
74    
75     if (SwitchType .gt. NSWITCHTYPES) then
76     write(default_error, *) &
77     'set_switch: not that many switch types! '
78     return
79     endif
80    
81     isOK(SwitchType) = .false.
82    
83     if (router .lt. rinner) then
84     write(default_error, *) &
85     'set_switch: router is less than rinner '
86     return
87     endif
88    
89     if ((router .lt. 0.0d0) .or. (rinner .lt. 0.0d0)) then
90     write(default_error, *) &
91     'set_switch: one of the switches is negative!'
92     return
93     endif
94 gezelter 507
95 gezelter 115 rin(SwitchType) = rinner
96     rout(SwitchType) = router
97     rin2(SwitchType) = rinner * rinner
98     rout2(SwitchType) = router * router
99     isOK(SwitchType) = .true.
100    
101     end subroutine set_switch
102    
103 chrisfen 725 subroutine set_function_type(functionForm)
104     integer, intent(in) :: functionForm
105     functionType = functionForm
106    
107     if (functionType .eq. FIFTH_ORDER_POLY) then
108     c0 = 1.0d0
109     c1 = 0.0d0
110     c2 = 0.0d0
111     c3 = -10.0d0
112     c4 = 15.0d0
113     c5 = -6.0d0
114     endif
115     end subroutine set_function_type
116    
117 gezelter 115 subroutine get_switch(r2, sw, dswdr, r, SwitchType, in_switching_region)
118    
119     real( kind = dp ), intent(in) :: r2
120     real( kind = dp ), intent(inout) :: sw, dswdr, r
121     real( kind = dp ) :: ron, roff
122 chrisfen 725 real( kind = dp ) :: rval, rval2, rval3, rval4, rval5
123     real( kind = dp ) :: rvaldi, rvaldi2, rvaldi3, rvaldi4, rvaldi5
124 gezelter 115 integer, intent(in) :: SwitchType
125     logical, intent(inout) :: in_switching_region
126    
127     sw = 0.0d0
128     dswdr = 0.0d0
129     in_switching_region = .false.
130    
131     if (.not.isOK(SwitchType)) then
132     write(default_error, *) &
133     'get_switch: this switching function has not been set up!'
134     return
135     endif
136    
137     if (r2.lt.rout2(SwitchType)) then
138     if (r2.lt.rin2(SwitchType)) then
139 gezelter 507
140 gezelter 115 sw = 1.0d0
141     dswdr = 0.0d0
142     return
143 gezelter 507
144 gezelter 115 else
145 gezelter 507
146 gezelter 115 r = dsqrt(r2)
147 gezelter 507
148 gezelter 115 ron = rin(SwitchType)
149     roff = rout(SwitchType)
150 gezelter 507
151 chrisfen 725 if (functionType .eq. FIFTH_ORDER_POLY) then
152     rval = ( r - ron )
153     rval2 = rval*rval
154     rval3 = rval2*rval
155     rval4 = rval2*rval2
156     rval5 = rval3*rval2
157     rvaldi = 1.0d0/( roff - ron )
158     rvaldi2 = rvaldi*rvaldi
159     rvaldi3 = rvaldi2*rvaldi
160     rvaldi4 = rvaldi2*rvaldi2
161     rvaldi5 = rvaldi3*rvaldi2
162     sw = c0 + c1*rval*rvaldi + c2*rval2*rvaldi2 + c3*rval3*rvaldi3 &
163     + c4*rval4*rvaldi4 + c5*rval5*rvaldi5
164     dswdr = c1*rvaldi + 2.0d0*c2*rval*rvaldi2 &
165     + 3.0d0*c3*rval2*rvaldi3 + 4.0d0*c4*rval3*rvaldi4 &
166     + 5.0d0*c5*rval4*rvaldi5
167 gezelter 507
168 chrisfen 725 else
169     sw = (roff + 2.0d0*r - 3.0d0*ron)*(roff-r)**2/ ((roff-ron)**3)
170     dswdr = 6.0d0*(r*r - r*ron - r*roff +roff*ron)/((roff-ron)**3)
171    
172     endif
173 gezelter 115 in_switching_region = .true.
174     return
175     endif
176     else
177     return
178 gezelter 507 endif
179    
180 gezelter 115 end subroutine get_switch
181 chrisfen 725
182 gezelter 115 end module switcheroo