ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/UseTheForce/DarkSide/switcheroo.F90
(Generate patch)

Comparing trunk/OOPSE-4/src/UseTheForce/DarkSide/switcheroo.F90 (file contents):
Revision 2204 by gezelter, Fri Apr 15 22:04:00 2005 UTC vs.
Revision 2715 by chrisfen, Sun Apr 16 02:51:16 2006 UTC

# Line 42 | Line 42 | module switcheroo
42   module switcheroo
43  
44    use definitions
45 +  use interpolation
46  
47    implicit none
48    PRIVATE
49  
50   #define __FORTRAN90
51   #include "UseTheForce/fSwitchingFunction.h"
52 + #include "UseTheForce/DarkSide/fSwitchingFunctionType.h"
53  
54    real ( kind = dp ), dimension(NSWITCHTYPES) :: rin
55    real ( kind = dp ), dimension(NSWITCHTYPES) :: rout
56    real ( kind = dp ), dimension(NSWITCHTYPES) :: rin2
57    real ( kind = dp ), dimension(NSWITCHTYPES) :: rout2
58 +  real ( kind = dp ), save :: c0, c1, c2, c3, c4, c5
59  
60    logical, dimension(NSWITCHTYPES) :: isOK
61 +  logical, save :: haveFunctionType = .false.
62 +  logical, save :: haveSqrtSpline = .false.
63 +  logical, save :: useSpline = .true.
64 +  integer, save :: functionType = CUBIC
65  
66  
67 +  ! spline variables
68 +  type(cubicSpline), save :: scoef
69 +  real ( kind = dp ), dimension(SPLINE_SEGMENTS) :: xValues
70 +  real ( kind = dp ), dimension(SPLINE_SEGMENTS) :: yValues
71 +  real ( kind = dp ), save :: dSqrt1, dSqrtN, range, dX
72 +  real ( kind = dp ), save :: lowerBound
73 +  logical, save :: uniformSpline = .true.
74 +
75    public::set_switch
76 +  public::set_function_type
77    public::get_switch
78  
79   contains
# Line 66 | Line 82 | contains
82  
83      real ( kind = dp ), intent(in):: rinner, router
84      integer, intent(in) :: SwitchType
85 +    integer :: i
86  
87      if (SwitchType .gt. NSWITCHTYPES) then
88         write(default_error, *) &
# Line 93 | Line 110 | contains
110      rout2(SwitchType) = router * router
111      isOK(SwitchType) = .true.
112  
113 +    if (.not.haveSqrtSpline) then
114 +       ! fill arrays for building the spline
115 +       lowerBound = 1.0d0 ! the smallest value expected for r2
116 +       range = rout2(SwitchType) - lowerBound
117 +       dX = range / (SPLINE_SEGMENTS - 1)
118 +      
119 +       ! the spline is bracketed by lowerBound and rout2 endpoints
120 +       xValues(1) = lowerBound
121 +       yValues(1) = dsqrt(lowerBound)
122 +       do i = 1, SPLINE_SEGMENTS-1
123 +          xValues(i+1) = i * dX
124 +          yValues(i+1) = dsqrt( i * dX )
125 +       enddo
126 +      
127 +       ! set the endpoint derivatives
128 +       dSqrt1 = 1 / ( 2.0d0 * dsqrt( xValues(1) ) )
129 +       dSqrtN = 1 / ( 2.0d0 * dsqrt( xValues(SPLINE_SEGMENTS) ) )
130 +
131 +       ! call newSpline to fill the coefficient array
132 +       call newSpline(scoef, xValues, yValues, dSqrt1, dSqrtN, uniformSpline)
133 +      
134 +    endif
135 +    
136    end subroutine set_switch
137  
138 +  subroutine set_function_type(functionForm)
139 +    integer, intent(in) :: functionForm    
140 +    functionType = functionForm
141 +
142 +    if (functionType .eq. FIFTH_ORDER_POLY) then
143 +       c0 = 1.0d0
144 +       c1 = 0.0d0
145 +       c2 = 0.0d0
146 +       c3 = -10.0d0
147 +       c4 = 15.0d0
148 +       c5 = -6.0d0
149 +    endif
150 +  end subroutine set_function_type
151 +
152    subroutine get_switch(r2, sw, dswdr, r, SwitchType, in_switching_region)
153  
154      real( kind = dp ), intent(in) :: r2
155      real( kind = dp ), intent(inout) :: sw, dswdr, r
156      real( kind = dp ) :: ron, roff
157 +    real( kind = dp ) :: rval, rval2, rval3, rval4, rval5
158 +    real( kind = dp ) :: rvaldi, rvaldi2, rvaldi3, rvaldi4, rvaldi5
159      integer, intent(in)    :: SwitchType
160      logical, intent(inout) :: in_switching_region
161  
# Line 121 | Line 177 | contains
177            return
178  
179         else
180 +          if (useSpline) then
181 +             call lookup_uniform_spline(scoef, r2, r)
182 +          else
183 +             r = dsqrt(r2)
184 +          endif
185  
125          r = dsqrt(r2)
126
186            ron = rin(SwitchType)
187            roff = rout(SwitchType)
188  
189 <          sw = (roff + 2.0d0*r - 3.0d0*ron)*(roff-r)**2/ ((roff-ron)**3)
190 <          dswdr = 6.0d0*(r*r - r*ron - r*roff +roff*ron)/((roff-ron)**3)
189 >          if (functionType .eq. FIFTH_ORDER_POLY) then
190 >             rval = ( r - ron )
191 >             rval2 = rval*rval
192 >             rval3 = rval2*rval
193 >             rval4 = rval2*rval2
194 >             rval5 = rval3*rval2
195 >             rvaldi = 1.0d0/( roff - ron )
196 >             rvaldi2 = rvaldi*rvaldi
197 >             rvaldi3 = rvaldi2*rvaldi
198 >             rvaldi4 = rvaldi2*rvaldi2
199 >             rvaldi5 = rvaldi3*rvaldi2
200 >             sw = c0 + c1*rval*rvaldi + c2*rval2*rvaldi2 + c3*rval3*rvaldi3 &
201 >                  + c4*rval4*rvaldi4 + c5*rval5*rvaldi5
202 >             dswdr = c1*rvaldi + 2.0d0*c2*rval*rvaldi2 &
203 >                  + 3.0d0*c3*rval2*rvaldi3 + 4.0d0*c4*rval3*rvaldi4 &
204 >                  + 5.0d0*c5*rval4*rvaldi5
205  
206 +          else
207 +             sw = (roff + 2.0d0*r - 3.0d0*ron)*(roff-r)**2/ ((roff-ron)**3)
208 +             dswdr = 6.0d0*(r*r - r*ron - r*roff +roff*ron)/((roff-ron)**3)
209 +
210 +          endif
211            in_switching_region = .true.
212            return          
213         endif
# Line 138 | Line 216 | end module switcheroo
216      endif
217  
218    end subroutine get_switch
219 +
220   end module switcheroo

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines