@@ -55,14 +55,11 @@ to define a method for [`DynamicalBilliards.specular!`](@ref). You can however d
55
55
custom methods for [ ` DynamicalBilliards.specular! ` ] ( @ref ) , which is what we have done e.g.
56
56
for [ ` RandomDisk ` ] ( @ref ) .
57
57
58
- !!! note "Use ` import ` !"
59
- Notice that you have to properly ` import ` the methods to extend them. For example,
60
- do ` import DynamicalBilliards: normalvec, distance, collision ` time.
61
58
62
- The first method is very simple, just do:
59
+
60
+ The first method is very simple. * (Remember that in Julia to extend a function with a new method you must preface it with the parent module)*
63
61
``` julia
64
- import DynamicalBilliards: normalvec, distance, collision
65
- normalvec (d:: Semicircle , pos) = normalize (d. c - pos)
62
+ DynamicalBilliards. normalvec (d:: Semicircle , pos) = normalize (d. c - pos)
66
63
```
67
64
Since the function is only used during ` distance ` and
68
65
[ ` DynamicalBilliards.resolvecollision! ` ] ( @ref ) and since we will be writing explicit methods for the first,
@@ -79,7 +76,7 @@ expanded. That is because when the particle is on the "open" half of the
79
76
disk, the distance is not correct. We write:
80
77
``` julia
81
78
SV = SVector{2 } # convenience
82
- function distance (pos:: AbstractVector{T} , s:: Semicircle{T} ) where {T}
79
+ function DynamicalBilliards . distance (pos:: AbstractVector{T} , s:: Semicircle{T} ) where {T}
83
80
# Check on which half of circle is the particle
84
81
v1 = pos .- s. c
85
82
nn = dot (v1, s. facedir)
@@ -98,14 +95,14 @@ the "other side".
98
95
Finally, the method for [ ` collision ` ] ( @ref ) is by far the most * trickiest* . But,
99
96
with pen, paper and a significant amount of patience, one can find a way:
100
97
``` julia
101
- function collision (p:: Particle{T} , d:: Semicircle{T} ):: T where {T}
98
+ function DynamicalBilliards . collision (p:: Particle{T} , d:: Semicircle{T} ):: T where {T}
102
99
103
100
dc = p. pos - d. c
104
101
B = dot (p. vel, dc) # velocity towards circle center: B > 0
105
102
C = dot (dc, dc) - d. r* d. r # being outside of circle: C > 0
106
103
Δ = B^ 2 - C
107
104
108
- Δ ≤ 0 && return nocollision (T)
105
+ Δ ≤ 0 && return DynamicalBilliards . nocollision (T)
109
106
sqrtD = sqrt (Δ)
110
107
111
108
nn = dot (dc, d. facedir)
@@ -122,10 +119,10 @@ function collision(p::Particle{T}, d::Semicircle{T})::T where {T}
122
119
# This check is necessary to not collide with the non-existing side
123
120
newpos = p. pos + p. vel * t
124
121
if dot (newpos - d. c, d. facedir) ≥ 0 # collision point on BAD HALF;
125
- return nocollision (T)
122
+ return DynamicalBilliards . nocollision (T)
126
123
end
127
124
# If collision time is negative, return Inf:
128
- t ≤ 0.0 ? nocollision (T) : (t, p. pos + t* p. vel)
125
+ t ≤ 0.0 ? DynamicalBilliards . nocollision (T) : (t, p. pos + t* p. vel)
129
126
end
130
127
```
131
128
@@ -138,16 +135,14 @@ And that is all. The obstacle now works perfectly fine for straight propagation.
138
135
139
136
1 . [ ` DynamicalBilliards.cellsize ` ] ( @ref ) : Enables [ ` randominside ` ] ( @ref ) with this obstacle.
140
137
1 . [ ` collision ` ] ( @ref ) with [ ` MagneticParticle ` ] ( @ref ) : enables magnetic propagation
141
- 2 . [ ` plot ` ] ( @ref ) with ` obstacle ` : enables plotting
138
+ 2 . [ ` plot ` ] ( @ref ) with ` obstacle ` : enables plotting and animating
142
139
3 . [ ` DynamicalBilliards.specular! ` ] ( @ref ) with ` offset ` : Allows [ ` lyapunovspectrum ` ] ( @ref ) to be computed.
143
140
4 . [ ` to_bcoords ` ] ( @ref ) : Allows the [ ` boundarymap ` ] ( @ref ) and [ ` boundarymap_portion ` ] ( @ref ) to be computed.
144
141
5 . [ ` from_bcoords ` ] ( @ref ) : Allows [ ` phasespace_portion ` ] ( @ref ) to be computed.
145
142
146
143
The [ ` DynamicalBilliards.cellsize ` ] ( @ref ) method is kinda trivial:
147
144
``` julia
148
- import DynamicalBilliards: cellsize, plot, to_bcoords, from_bcoords
149
-
150
- function cellsize (a:: Semicircle{T} ) where {T}
145
+ function DynamicalBilliards. cellsize (a:: Semicircle{T} ) where {T}
151
146
xmin, ymin = a. c - a. r
152
147
xmax, ymax = a. c + a. r
153
148
return xmin, ymin, xmax, ymax
157
152
158
153
The [ ` collision ` ] ( @ref ) method for [ ` MagneticParticle ` ] ( @ref ) is also tricky, however it is almost identical with the method for the general ` Circular ` obstacle:
159
154
``` julia
160
- function collision (p:: MagneticParticle{T} , o:: Semicircle{T} ):: T where {T}
155
+ function DynamicalBilliards . collision (p:: MagneticParticle{T} , o:: Semicircle{T} ):: T where {T}
161
156
ω = p. omega
162
157
pc, rc = cyclotron (p)
163
158
p1 = o. c
200
195
Then, we add swag by writing a method for [ ` plot ` ] ( @ref ) :
201
196
202
197
``` julia
203
- using PyPlot
198
+ using PyPlot # brings plot(::Obstacle; kwargs...) into scope
204
199
205
- function plot (d:: Semicircle ; kwargs... )
200
+ function DynamicalBilliards . plot (d:: Semicircle ; kwargs... )
206
201
theta1 = atan (d. facedir[2 ], d. facedir[1 ])* 180 / π + 90
207
202
theta2 = theta1 + 180
208
203
edgecolor = DynamicalBilliards. obcolor (d)
@@ -226,7 +221,7 @@ were already determined by Dellago, Posch and Hoover [1] – we just have to
226
221
implement them.
227
222
228
223
``` julia
229
- function specular! (p:: Particle{T} , o:: Circular{T} ,
224
+ function DynamicalBilliards . specular! (p:: Particle{T} , o:: Circular{T} ,
230
225
offset:: Vector{SVector{4, T}} ) where {T<: AbstractFloat }
231
226
232
227
n = normalvec (o, p. pos)
@@ -258,9 +253,9 @@ Note that calculating Lyapunov exponents for magnetic particles requires a
258
253
separate method, as the formulas are different for magnetic propagation.
259
254
260
255
Finally, we also add a methods for [ ` to_bcoords ` ] ( @ref ) and [ ` from_bcoords ` ] ( @ref ) .
261
- For them, see the relevant source file (use ` @which ` ).
256
+ For them, see the relevant source file (use ` @edit ` ).
262
257
263
258
264
259
** References**
265
260
266
- [ 1] : Ch. Dellago et al., Phys. Rev. E 53, 1485 (1996).
261
+ [ 1] : Dellago et al., Phys. Rev. E 53, 1485 (1996).
0 commit comments