@@ -9,7 +9,7 @@ using GLMakie
99using LaTeXStrings
1010
1111const inch = 96
12- const pt = 4 / 3
12+ const pt = 4 / 3
1313const cm = inch / 2.54
1414
1515# set_theme!(
@@ -22,21 +22,21 @@ const cm = inch / 2.54
2222# Code is using Atomic Units !!!
2323# natural constants
2424c = 137.03599908330932 # speed of light
25- qme = - 1. # specific charge
25+ qme = - 1.0 # specific charge
2626
2727h = 2 π
28- α = 1 / c
29- ε₀= qme^ 2 / (2 α* h * c)
30- μ₀= 1 / (ε₀* c^ 2 )
28+ α = 1 / c
29+ ε₀ = qme^ 2 / (2 α * h * c)
30+ μ₀ = 1 / (ε₀ * c^ 2 )
3131
3232# derived
3333ω = 0.057
34- τ = 150 / ω
35- λ = 2 π* c / ω
34+ τ = 150 / ω
35+ λ = 2 π * c / ω
3636w₀ = 75 λ
3737Rmax = 3.25 w₀
3838
39- ξx, ξy = (1 / √2 , im/ √2 ) .| > complex
39+ ξx, ξy = (1 / √ 2 , im / √ 2 ) .| > complex
4040
4141# Laser parameters in atomic units
4242λ_au = λ
@@ -54,20 +54,20 @@ z₀ = 0.0
5454# @named ref_frame = LabFrame(:atomic)
5555
5656@named laser = LaguerreGaussLaser (
57- wavelength= λ_au,
58- a0= a₀,
59- beam_waist= w₀_au,
60- radial_index= p_index,
61- azimuthal_index= m_index,
62- ref_frame= ref_frame ,
63- temporal_profile= :gaussian , # Using Gaussian profile
64- temporal_width= τ_fwhm,
65- focus_position= z₀,
66- polarization= :circular
57+ wavelength = λ_au,
58+ a0 = a₀,
59+ beam_waist = w₀_au,
60+ radial_index = p_index,
61+ azimuthal_index = m_index,
62+ ref_frame,
63+ temporal_profile = :gaussian , # Using Gaussian profile
64+ temporal_width = τ_fwhm,
65+ focus_position = z₀,
66+ polarization = :circular
6767)
6868
6969# Create electron system
70- @named lg_elec = ClassicalElectron (; laser, ref_frame )
70+ @named lg_elec = ClassicalElectron (; laser)
7171
7272
7373# Compile the system
@@ -79,21 +79,21 @@ sys = mtkcompile(lg_elec)
7979tspan = (τi, τf)
8080
8181# Create base problem with placeholder initial position
82- x⁰ = [τi* c, 0.0 , 0.0 , 0.0 ]
82+ x⁰ = [τi * c, 0.0 , 0.0 , 0.0 ]
8383u⁰ = [c, 0.0 , 0.0 , 0.0 ]
8484
8585u0 = [
8686 (sys. x) => x⁰,
87- (sys. u) => u⁰
87+ (sys. u) => u⁰,
8888]
8989
90- prob = ODEProblem {false, SciMLBase.FullSpecialize} (sys, u0, tspan, u0_constructor= SVector{8 }, fully_determined= true )
91- sol0 = solve (prob, Vern9 (), reltol = 1e -15 , abstol = 1e -12 )
90+ prob = ODEProblem {false, SciMLBase.FullSpecialize} (sys, u0, tspan, u0_constructor = SVector{8 }, fully_determined = true )
91+ sol0 = solve (prob, Vern9 (), reltol = 1.0e -15 , abstol = 1.0e -12 )
9292
9393# Sunflower pattern for initial positions
9494N = 900
9595
96- const ϕ = (1 + √ 5 )/ 2
96+ const ϕ = (1 + √ 5 ) / 2
9797
9898function radius (k, n, b)
9999 if k > n - b
@@ -105,21 +105,21 @@ end
105105
106106function sunflower (n, α)
107107 points = []
108- angle_stride = 2 π/ ϕ^ 2 # geodesic ? 360 * ϕ :
108+ angle_stride = 2 π / ϕ^ 2 # geodesic ? 360 * ϕ :
109109 b = round (Int, α * sqrt (n)) # number of boundary points
110110
111111 for k in 1 : n
112112 r = radius (k, n, b)
113113 θ = k * angle_stride
114- append! (points, ([r * cos (θ), r * sin (θ)], ))
114+ append! (points, ([r * cos (θ), r * sin (θ)],))
115115 end
116116
117117 return points
118118end
119119
120120# Generate initial positions in sunflower pattern
121- R₀ = Rmax* sunflower (N, 2 )
122- xμ = [[τi* c, r... , 0. ] for r in R₀]
121+ R₀ = Rmax * sunflower (N, 2 )
122+ xμ = [[τi * c, r... , 0.0 ] for r in R₀]
123123
124124# Use SymbolicIndexingInterface to set positions
125125set_x = setsym_oop (prob, [Initial (sys. x); Initial (sys. u)]);
@@ -136,59 +136,63 @@ function prob_func(prob, i, repeat)
136136 # Set new initial conditions
137137 u0, p = set_x (prob, SVector {8} (x_new... , u_new... ))
138138
139- remake (prob; u0, p)
139+ return remake (prob; u0, p)
140140end
141141
142142# Absolute error tolerance function
143143function abserr (a₀)
144144 amp = log10 (a₀)
145- expo = - amp^ 2 / 27 + 32 amp/ 27 - 220 / 27
146- 10 ^ expo
145+ expo = - amp^ 2 / 27 + 32 amp / 27 - 220 / 27
146+ return 10 ^ expo
147147end
148148
149149# Create ensemble problem
150- ensemble = EnsembleProblem (prob; prob_func, safetycopy= false )
150+ ensemble = EnsembleProblem (prob; prob_func, safetycopy = false )
151151
152152# Solve ensemble
153- solution = solve (ensemble, Vern9 (), EnsembleThreads ();
154- reltol= 1e-12 , abstol= abserr (a₀),
155- trajectories= N)
153+ solution = solve (
154+ ensemble, Vern9 (), EnsembleThreads ();
155+ reltol = 1.0e-12 , abstol = abserr (a₀),
156+ trajectories = N
157+ )
156158
157159# ru = solution.u[1](range(τi, τf, 1001), idxs = [sys.x; sys.u])
158160
159161# Solve single trajectory for visualization (electron #1)
160162x_single = SVector {8} (xμ[1 ]. .. , u⁰... )
161163u0_single, p_single = set_x (prob, x_single)
162- prob_single = remake (prob; u0= u0_single, p= p_single)
164+ prob_single = remake (prob; u0 = u0_single, p = p_single)
163165
164- sol = solve (prob_single, Vern9 (),
165- reltol= 1e-12 ,
166- abstol= 1e-20 )
166+ sol = solve (
167+ prob_single, Vern9 (),
168+ reltol = 1.0e-12 ,
169+ abstol = 1.0e-20
170+ )
167171
168172# ### eval field
169173
170174_t = 0
171175_x = sol[sys. x, 500 ]
172176
173- x_sub = map (x-> EvalAt (_t)(x[1 ])=> x[2 ], collect (sys. x .=> _x))
174- eval_point = [laser. τ=> 0 ; x_sub; sys. t => EvalAt (_t)(sys. x[1 ]) / c]
177+ x_sub = map (x -> EvalAt (_t)(x[1 ]) => x[2 ], collect (sys. x .=> _x))
178+ eval_point = [laser. τ => 0 ; x_sub; sys. t => EvalAt (_t)(sys. x[1 ]) / c]
175179
176180all_eqs = Symbolics. fixpoint_sub (equations (laser), merge (initial_conditions (laser), initial_conditions (eval_point)))
177- eq_dict = Dict (map (eq-> eq. lhs=> eq. rhs, all_eqs[setdiff (1 : 19 , 10 : 15 )]))
181+ eq_dict = Dict (map (eq -> eq. lhs => eq. rhs, all_eqs[setdiff (1 : 19 , 10 : 15 )]))
178182Symbolics. fixpoint_sub (all_eqs, eq_dict)
179183
180184# using CairoMakie
181185# Visualization
182- fig = Figure (fontsize= 14 pt)
186+ fig = Figure (fontsize = 14 pt)
183187# ax = Axis3(fig[1, 1], aspect=:data)
184- ax = Axis3 (fig[1 , 1 ], aspect= (1 , 1 , 1 ))
188+ ax = Axis3 (fig[1 , 1 ], aspect = (1 , 1 , 1 ))
185189
186190
187191# Extract trajectory
188- t_range = range (τi, τf, length= 10001 )
189- x_traj = [sol (t, idxs= sys. x[2 ]) for t in t_range]
190- y_traj = [sol (t, idxs= sys. x[3 ]) for t in t_range]
191- z_traj = [sol (t, idxs= sys. x[4 ]) for t in t_range]
192+ t_range = range (τi, τf, length = 10001 )
193+ x_traj = [sol (t, idxs = sys. x[2 ]) for t in t_range]
194+ y_traj = [sol (t, idxs = sys. x[3 ]) for t in t_range]
195+ z_traj = [sol (t, idxs = sys. x[4 ]) for t in t_range]
192196
193197lines! (ax, x_traj, y_traj, z_traj)
194198
0 commit comments