@@ -424,77 +424,82 @@ function recombination(system::System, diagram::Diagram, 𝐩, 𝐀, i)
424
424
end
425
425
end
426
426
427
- function integrate_diagram (:: Type{Amp} , system:: System , diagram:: Diagram , iref, 𝐤= nothing ; memory= typemax (Int), imin= 1 ) where Amp
428
- ions, unique_momenta, momenta, indeterminate_momenta, order = analyze_diagram (system, diagram)
427
+ function integrate_diagram (:: Type{Amp} , system:: System , diagram:: Diagram , iref, 𝐤= nothing ; memory= typemax (Int), imin= 1 ,
428
+ to= TimerOutput (), verbosity= 1 ) where Amp
429
+ ions, unique_momenta, momenta, indeterminate_momenta, order = @timeit to " Analyze diagram" analyze_diagram (system, diagram)
429
430
430
- weight = (- im* system. dt)^ order
431
+ @timeit to " Allocations" begin
432
+ weight = (- im* system. dt)^ order
431
433
432
- # println()
433
- # @info "Integrating diagram up to" iref system diagram ions unique_momenta momenta indeterminate_momenta order weight 𝐤
434
+ verbosity > 1 && @info " Integrating diagram up to" iref system diagram ions unique_momenta momenta indeterminate_momenta order weight 𝐤
434
435
435
- # @show
436
- Eᵢₒₙₛ = [system. ionization_channels[ion]. E for ion in ions]
437
- 𝐩s = complex (zeros (momentum_type (system, 𝐤), length (unique_momenta)))
438
- prefactors = ones (complex (eltype (system. t)), length (unique_momenta))
439
- if ! isnothing (𝐤)
440
- 𝐩s[1 ] = 𝐤
436
+ Eᵢₒₙₛ = [system. ionization_channels[ion]. E for ion in ions]
437
+ 𝐩s = complex (zeros (momentum_type (system, 𝐤), length (unique_momenta)))
438
+ prefactors = ones (complex (eltype (system. t)), length (unique_momenta))
439
+ if ! isnothing (𝐤)
440
+ 𝐩s[1 ] = 𝐤
441
+ end
442
+
443
+ 𝐀 = system. 𝐀
444
+ amplitude = complex (zero (Amp))
445
+ ctT = complex (eltype (system. t))
446
+
447
+ is = vcat (iref, zeros (Int, order))
441
448
end
442
- # @show 𝐩s
443
449
444
- 𝐀 = system. 𝐀
445
- amplitude = complex (zero (Amp))
446
- ctT = complex (eltype (system. t))
447
-
448
- is = vcat (iref, zeros (Int, order))
449
-
450
- for i in TelescopeIterator (max (1 ,imin): iref- 1 , order, memory)
451
- is[2 : end ] .= i
452
- # is = vcat(iref, i)
453
- # is = (iref,i...)
454
- # for i in 1:iref-1, j in 1:i-1
455
- # is = (iref,i,j)
456
- # println(is)
457
-
458
- evaluate_momenta! (𝐩s, prefactors, system, unique_momenta, indeterminate_momenta, is)
459
- # @show 𝐩s prefactors
460
-
461
- Sᵢₒₙ = zero (ctT)
462
- Sₑₗ = zero (ctT)
463
- for j = 1 : order
464
- a,b = is[j], is[j+ 1 ]
465
- τ = system. t[a] - system. t[b]
466
- Sᵢₒₙ += Eᵢₒₙₛ[j]* τ
467
- Sₑₗ += volkov_phase (𝐩s[j], system. volkov, a, b)
468
- end
469
- S = Sᵢₒₙ + Sₑₗ
470
- aₚᵣₒₚ = prod (prefactors)* exp (- im* S)
450
+ @timeit to " Time loop" begin
451
+ for i in TelescopeIterator (max (1 ,imin): iref- 1 , order, memory)
452
+ is[2 : end ] .= i
453
+ # is = vcat(iref, i)
454
+ # is = (iref,i...)
455
+ # for i in 1:iref-1, j in 1:i-1
456
+ # is = (iref,i,j)
457
+ # println(is)
458
+
459
+ @timeit to " Evaluate momenta" evaluate_momenta! (𝐩s, prefactors, system, unique_momenta, indeterminate_momenta, is)
460
+ verbosity > 10 && @show 𝐩s prefactors
461
+
462
+ @timeit to " Evaluate propagators" begin
463
+ Sᵢₒₙ = zero (ctT)
464
+ Sₑₗ = zero (ctT)
465
+ for j = 1 : order
466
+ a,b = is[j], is[j+ 1 ]
467
+ τ = system. t[a] - system. t[b]
468
+ Sᵢₒₙ += Eᵢₒₙₛ[j]* τ
469
+ Sₑₗ += volkov_phase (𝐩s[j], system. volkov, a, b)
470
+ end
471
+ S = Sᵢₒₙ + Sₑₗ
472
+ aₚᵣₒₚ = prod (prefactors)* exp (- im* S)
473
+ end
471
474
472
- # @show is prefactors
475
+ verbosity > 10 && @show is prefactors
473
476
474
- ∂a = (ionization (system, diagram, 𝐩s[end ], 𝐀, is[end ]) *
475
- aₚᵣₒₚ *
476
- recombination (system, diagram, 𝐩s[1 ], 𝐀, iref))
477
+ ∂a = @timeit to " Prefactor " (ionization (system, diagram, 𝐩s[end ], 𝐀, is[end ]) *
478
+ aₚᵣₒₚ *
479
+ recombination (system, diagram, 𝐩s[1 ], 𝐀, iref))
477
480
478
- # Loop over "interior" interactions
479
- for j = (order> 1 && first (diagram)[2 ]== 0 ? 3 : 2 ): order
480
- ion,which = diagram. path[j- 1 ]
481
- α = ions[j- 1 ]
482
- β = ions[j]
483
- # @show j, ion, which α,β
484
- interaction = system. couplings[which][α,β]
481
+ @timeit to " Interior interactions" begin
482
+ # Loop over "interior" interactions
483
+ for j = (order> 1 && first (diagram)[2 ]== 0 ? 3 : 2 ): order
484
+ ion,which = diagram. path[j- 1 ]
485
+ α = ions[j- 1 ]
486
+ β = ions[j]
487
+ verbosity > 20 && @show j, ion, which α,β
488
+ interaction = system. couplings[which][α,β]
485
489
486
- 𝐤ᵢ = 𝐩s[momenta[j- 1 ]]
487
- 𝐩ᵢ = 𝐩s[momenta[j]]
488
- 𝐀ᵢ = 𝐀[is[j]]
490
+ 𝐤ᵢ = 𝐩s[momenta[j- 1 ]]
491
+ 𝐩ᵢ = 𝐩s[momenta[j]]
492
+ 𝐀ᵢ = 𝐀[is[j]]
489
493
490
- ∂a *= interaction (kinematic_momentum (𝐤ᵢ, 𝐀ᵢ), kinematic_momentum (𝐩ᵢ, 𝐀ᵢ), is[j+ 1 ])
491
- end
494
+ ∂a *= @timeit to " Interaction" interaction (kinematic_momentum (𝐤ᵢ, 𝐀ᵢ), kinematic_momentum (𝐩ᵢ, 𝐀ᵢ), is[j+ 1 ])
495
+ end
496
+ end
492
497
493
- # ∂a = prod(prefactors)
494
- amplitude += ∂a
498
+ amplitude += ∂a
499
+ end
495
500
end
496
501
497
- weight* amplitude
502
+ @timeit to " Weighting " weight* amplitude
498
503
end
499
504
500
505
# * High-level interface
@@ -507,11 +512,18 @@ function photoelectron_spectrum(k::AbstractArray{T},
507
512
508
513
cT = complex (eltype (T))
509
514
c = similar (k, cT)
515
+ to = TimerOutput ()
510
516
p = Progress (length (k))
511
- threaded_range_loop (eachindex (k)) do i
512
- c[i] = integrate_diagram (cT, system, diagram, iref, k[i]; kwargs... )
513
- ProgressMeter. next! (p)
517
+ @timeit to " k loop" begin
518
+ threaded_range_loop (eachindex (k)) do i
519
+ tok = TimerOutput ()
520
+ c[i] = integrate_diagram (cT, system, diagram, iref, k[i]; to= tok, verbosity= verbosity- 1 , kwargs... )
521
+ ProgressMeter. next! (p)
522
+ merge! (to, tok, tree_point= [" k loop" ])
523
+ end
514
524
end
525
+ TimerOutputs. complement! (to)
526
+ verbosity > 0 && print_timer (to)
515
527
c
516
528
end
517
529
@@ -537,7 +549,7 @@ function induced_dipole(system::System, diagram::Diagram; verbosity = 1, kwargs.
537
549
memory = get (kwargs, :memory , typemax (Int))
538
550
539
551
@showprogress for (i,t) in enumerate (t)
540
- 𝐝̃ = integrate_diagram (DT, system, diagram, i; imin= i- memory, kwargs... )
552
+ 𝐝̃ = integrate_diagram (DT, system, diagram, i; imin= i- memory, verbosity = verbosity - 1 , kwargs... )
541
553
𝐝[i] = 2 real (𝐝̃)
542
554
end
543
555
0 commit comments