-
Notifications
You must be signed in to change notification settings - Fork 95
/
SteadyLogSpiralPotential.py
223 lines (195 loc) · 6.83 KB
/
SteadyLogSpiralPotential.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
###############################################################################
# SteadyLogSpiralPotential: a steady-state spiral potential
###############################################################################
import numpy
from ..util import conversion
from .planarPotential import planarPotential
_degtorad = numpy.pi / 180.0
class SteadyLogSpiralPotential(planarPotential):
"""Class that implements a steady-state spiral potential
.. math::
\\Phi(R,\\phi) = \\frac{\\mathrm{amp}\\times A}{\\alpha}\\,\\cos\\left(\\alpha\\,\\ln R - m\\,(\\phi-\\Omega_s\\,t-\\gamma)\\right)
Can be grown in a similar way as the DehnenBarPotential, but using :math:`T_s = 2\\pi/\\Omega_s` to normalize :math:`t_{\\mathrm{form}}` and :math:`t_{\\mathrm{steady}}`. If the pattern speed is zero, :math:`t_\\mathrm{form}` and :math:`t_\\mathrm{steady}` are straight times, not times divided by the spiral period.
"""
def __init__(
self,
amp=1.0,
omegas=0.65,
A=-0.035,
alpha=-7.0,
m=2,
gamma=numpy.pi / 4.0,
p=None,
tform=None,
tsteady=None,
ro=None,
vo=None,
):
"""
Initialize a steady-state logarithmic spiral potential.
Parameters
----------
amp : float, optional
Amplitude to be applied to the potential (default: 1., A below).
omegas : float or Quantity, optional
Pattern speed (default: 0.65).
A : float or Quantity, optional
Amplitude (alpha*potential-amplitude; default=0.035).
alpha : float, optional
Parameter that sets the strength of the spiral potential.
m : int, optional
Number of spiral arms.
gamma : float or Quantity, optional
Angle between sun-GC line and the line connecting the peak of the spiral pattern at the Solar radius (in rad; default=45 degree).
p : float or Quantity, optional
Pitch angle.
tform : float, optional
Start of spiral growth / spiral period (default: -Infinity).
tsteady : float, optional
Time from tform at which the spiral is fully grown / spiral period (default: 2 periods).
ro : float or Quantity, optional
Distance scale for translation into internal units (default from configuration file).
vo : float or Quantity, optional
Velocity scale for translation into internal units (default from configuration file).
Notes
-----
- 2011-03-27 - Started - Bovy (NYU)
"""
planarPotential.__init__(self, amp=amp, ro=ro, vo=vo)
gamma = conversion.parse_angle(gamma)
p = conversion.parse_angle(p)
A = conversion.parse_energy(A, vo=self._vo)
omegas = conversion.parse_frequency(omegas, ro=self._ro, vo=self._vo)
self._omegas = omegas
self._A = A
self._m = m
self._gamma = gamma
if not p is None:
self._alpha = self._m / numpy.tan(p)
else:
self._alpha = alpha
self._ts = 2.0 * numpy.pi / self._omegas if self._omegas != 0.0 else 1.0
if not tform is None:
self._tform = tform * self._ts
else:
self._tform = None
if not tsteady is None:
self._tsteady = self._tform + tsteady * self._ts
else:
if self._tform is None:
self._tsteady = None
else:
self._tsteady = self._tform + 2.0 * self._ts
self.hasC = True
def _evaluate(self, R, phi=0.0, t=0.0):
if not self._tform is None:
if t < self._tform:
smooth = 0.0
elif t < self._tsteady:
deltat = t - self._tform
xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0
smooth = (
3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5
)
else: # spiral is fully on
smooth = 1.0
else:
smooth = 1.0
return (
smooth
* self._A
/ self._alpha
* numpy.cos(
self._alpha * numpy.log(R)
- self._m * (phi - self._omegas * t - self._gamma)
)
)
def _Rforce(self, R, phi=0.0, t=0.0):
if not self._tform is None:
if t < self._tform:
smooth = 0.0
elif t < self._tsteady:
deltat = t - self._tform
xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0
smooth = (
3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5
)
else: # spiral is fully on
smooth = 1.0
else:
smooth = 1.0
return (
smooth
* self._A
/ R
* numpy.sin(
self._alpha * numpy.log(R)
- self._m * (phi - self._omegas * t - self._gamma)
)
)
def _phitorque(self, R, phi=0.0, t=0.0):
if not self._tform is None:
if t < self._tform:
smooth = 0.0
elif t < self._tsteady:
deltat = t - self._tform
xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0
smooth = (
3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5
)
else: # spiral is fully on
smooth = 1.0
else:
smooth = 1.0
return (
-smooth
* self._A
/ self._alpha
* self._m
* numpy.sin(
self._alpha * numpy.log(R)
- self._m * (phi - self._omegas * t - self._gamma)
)
)
def wavenumber(self, R):
"""
Return the wavenumber at radius R (d f(R)/ d R in Phi_a(R) = F(R) e^[i f(R)]; see Binney & Tremaine 2008)
Parameters
----------
R : float
Cylindrical radius
Returns
-------
float
wavenumber at R
Notes
-----
- 2014-08-23 - Written - Bovy (IAS)
"""
return self._alpha / R
def OmegaP(self):
return self._omegas
def m(self):
"""
Return the number of arms.
Returns
-------
int
Number of arms.
Notes
-----
- 2014-08-23 - Written - Bovy (IAS)
"""
return self._m
def tform(self): # pragma: no cover
"""
Return formation time of the bar.
Returns
-------
tform : float
Formation time of the bar in normalized units.
Notes
-----
- 2011-03-08 - Written - Bovy (NYU)
"""
return self._tform