-
Notifications
You must be signed in to change notification settings - Fork 6
/
RB-SFA.m
executable file
·1420 lines (1149 loc) · 87.1 KB
/
RB-SFA.m
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(* ::Package:: *)
(************************************************************************)
(* This file was generated automatically by the Mathematica front end. *)
(* It contains Initialization cells from a Notebook file, which *)
(* typically will have the same name as this file except ending in *)
(* ".nb" instead of ".m". *)
(* *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs. Doing so is equivalent *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end. *)
(* *)
(* DO NOT EDIT THIS FILE. This entire file is regenerated *)
(* automatically each time the parent Notebook file is saved in the *)
(* Mathematica front end. Any changes you make to this file will be *)
(* overwritten. *)
(************************************************************************)
(* ::Input::Initialization:: *)
(*
This is the RB-SFA package for calculating high-order harmonic generation within the Strong Field Approximation. For the notebook that generated this package file and additional documentaion, see https://github.com/episanty/RB-SFA.
*)
(* ::Input::Initialization:: *)
BeginPackage["RBSFA`"];
(* ::Input::Initialization:: *)
$RBSFAversion::usage="$RBSFAversion prints the current version of the RB-SFA package in use and its timestamp.";
$RBSFAtimestamp::usage="$RBSFAtimestamp prints the timestamp of the current version of the RB-SFA package.";
Begin["`Private`"];
$RBSFAversion:="RB-SFA v2.2.2, "<>$RBSFAtimestamp;
End[];
(* ::Input::Initialization:: *)
RBSFAversion::usage="RBSFAversion[] has been deprecated in favour of $RBSFAversion.";
RBSFAversion::dprc="RBSFAversion[] has been deprecated in favour of $RBSFAversion.";
Begin["`Private`"];
RBSFAversion[]:=(Message[RBSFAversion::dprc];$RBSFAversion);
End[];
(* ::Input::Initialization:: *)
Begin["`Private`"];
$RBSFAtimestamp="Tue 6 Oct 2020 18:45:38";
End[];
(* ::Input::Initialization:: *)
$RBSFAdirectory::usage="$RBSFAdirectory is the directory where the current RB-SFA package instance is located.";
(* ::Input::Initialization:: *)
Begin["`Private`"];
With[{softLinkTestString=StringSplit[StringJoin[ReadList["! ls -la "<>StringReplace[$InputFileName,{" "->"\\ "}],String]]," -> "]},
If[Length[softLinkTestString]>1,(*Testing in case $InputFileName is a soft link to the actual directory.*)
$RBSFAdirectory=StringReplace[DirectoryName[softLinkTestString[[2]]],{" "->"\\ "}],
$RBSFAdirectory=StringReplace[DirectoryName[$InputFileName],{" "->"\\ "}];
]];
End[];
(* ::Input::Initialization:: *)
$RBSFAcommit::usage="$RBSFAcommit returns the git commit log at the location of the RB-SFA package if there is one.";
$RBSFAcommit::OS="$RBSFAcommit has only been tested on Linux.";
(* ::Input::Initialization:: *)
Begin["`Private`"];
$RBSFAcommit:=(If[$OperatingSystem!="Unix",Message[$RBSFAcommit::OS]];
StringJoin[Riffle[ReadList["!cd "<>$RBSFAdirectory<>" && git log -1",String],{"\n"}]]);
End[];
(* ::Input::Initialization:: *)
Quiet[Check[
ConstantArray[0,{}];,
Unprotect[ConstantArray];
ConstantArray[Private`x_,{}]:=Private`x;
Protect[ConstantArray];
]];
(* ::Input::Initialization:: *)
Parallelize;
Parallel`Developer`$InitCode=Hold[
Quiet[Check[
ConstantArray[0,{}];,
Unprotect[ConstantArray];
ConstantArray[Private`x_,{}]:=Private`x;
Protect[ConstantArray];
]];
];
(* ::Input::Initialization:: *)
If[
Context[ReIm]=!="System`"&&Attributes[ReIm]=={},
ReIm::usage="\!\(\*RowBox[{\"ReIm\", \"[\", StyleBox[\"z\", \"TI\"], \"]\"}]\) gives the list \!\(\*RowBox[{\"{\", RowBox[{RowBox[{\"Re\", \"[\", StyleBox[\"z\", \"TI\"], \"]\"}], \",\", RowBox[{\"Im\", \"[\", StyleBox[\"z\", \"TI\"], \"]\"}]}], \"}\"}]\) of the number \!\(\*StyleBox[\"z\", \"TI\"]\).";
ReIm[Private`z_]:={Re[Private`z],Im[Private`z]};
SetAttributes[ReIm,Listable];
Protect[ReIm];
]
(* ::Input::Initialization:: *)
AssociationTranspose::usage="AssociationTranspose[association] transposes the given two-level association of associations.";
AssociationTranspose::wrngshp="Input `1` is the wrong shape; it must be an association all of whose Values are valid associations.";
Begin["`Private`"];
AssociationTranspose[association_?(
And@@(AssociationQ/@Join[{#},Values[#]])&
)]:=GroupBy[
Join@@Thread/@Normal//@association,
{First@*Last,First}
][[All,All,1,2,2]];
AssociationTranspose[association__]:="Doesn't display; cf. mm.se/q/29321 for details"/;Message[AssociationTranspose::wrngshp,association]
End[];
(* ::Input::Initialization:: *)
If[
$VersionNumber<10.1,
KeyValueMap::usage="\!\(\*RowBox[{\"KeyValueMap\", \"[\", RowBox[{StyleBox[\"f\",\"TI\"], \",\", RowBox[{\"\[LeftAssociation]\",RowBox[{RowBox[{SubscriptBox[StyleBox[\"key\", \"TI\"], StyleBox[\"1\", \"TR\"]], \"\[Rule]\", SubscriptBox[StyleBox[\"val\", \"TI\"], StyleBox[\"1\", \"TR\"]]}], \",\", RowBox[{SubscriptBox[StyleBox[\"key\", \"TI\"], StyleBox[\"2\", \"TR\"]], \"\[Rule]\", SubscriptBox[StyleBox[\"val\", \"TI\"], StyleBox[\"2\", \"TR\"]]}], \",\", StyleBox[\"\[Ellipsis]\", \"TR\"]}], \"\[RightAssociation]\"}]}], \"]\"}]\) gives the list \!\(\*RowBox[{\"{\", RowBox[{RowBox[{StyleBox[\"f\", \"TI\"], \"[\", RowBox[{SubscriptBox[StyleBox[\"key\", \"TI\"], StyleBox[\"1\", \"TR\"]], \",\", SubscriptBox[StyleBox[\"val\", \"TI\"], StyleBox[\"1\", \"TR\"]]}], \"]\"}], \",\", RowBox[{StyleBox[\"f\", \"TI\"], \"[\", RowBox[{SubscriptBox[StyleBox[\"key\", \"TI\"], StyleBox[\"2\", \"TR\"]], \",\", SubscriptBox[StyleBox[\"val\", \"TI\"], StyleBox[\"2\", \"TR\"]]}], \"]\"}], \",\", StyleBox[\"\[Ellipsis]\", \"TR\"]}], \"}\"}]\). (Note: function backported from v10.1+.)
\!\(\*RowBox[{\"KeyValueMap\", \"[\", StyleBox[\"f\", \"TI\"], \"]\"}]\) represents an operator form of KeyValueMap that can be applied to an expression.";
KeyValueMap::invak="The argument `1` is not a valid association";
]
Begin["`Private`"];
If[
$VersionNumber<10.1,
KeyValueMap[f_,assoc_?AssociationQ]:=Map[Apply[f],Normal[assoc]];
KeyValueMap[f_][assoc_?AssociationQ]:=KeyValueMap[f,assoc];
KeyValueMap[f_,assoc__]:="Doesn't display; cf. mm.se/q/29321 for details"/;Message[KeyValueMap::invak,assoc];
]
End[];
(* ::Input::Initialization:: *)
hydrogenicDTME::usage="hydrogenicDTME[p,\[Kappa]] returns the dipole transition matrix element for a 1s hydrogenic state of ionization potential \!\(\*SubscriptBox[\(I\), \(p\)]\)=\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\).
hydrogenicDTME[p,\[Kappa],{n,l,m}] returns the dipole transition matrix element for an n,l,m hydrogenic state of ground-state ionization potential \!\(\*SubscriptBox[\(I\), \(p\)]\)=\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\).
hydrogenicDTME[p,\[Kappa],n,l,m] returns the dipole transition matrix element for an n,l,m hydrogenic state of ground-state ionization potential \!\(\*SubscriptBox[\(I\), \(p\)]\)=\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\).";
hydrogenicDTMERegularized::usage="hydrogenicDTMERegularized[p,\[Kappa]] returns the dipole transition matrix element for a 1s hydrogenic state of ionization potential \!\(\*SubscriptBox[\(I\), \(p\)]\)=\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\), regularized to remove the denominator of 1/(\!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)\!\(\*SuperscriptBox[\()\), \(3\)]\), where the saddle-point solutions are singular.
hydrogenicDTMERegularized[p,\[Kappa],{n,l,m}] returns the dipole transition matrix element for an n,l,m hydrogenic state of ground-state ionization potential \!\(\*SubscriptBox[\(I\), \(p\)]\)=\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\), regularized to remove factors of (\!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)) from the denominator.
hydrogenicDTMERegularized[p,\[Kappa],n,l,m] returns the dipole transition matrix element for an n,l,m hydrogenic state of ground-state ionization potential \!\(\*SubscriptBox[\(I\), \(p\)]\)=\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\), regularized to remove factors of (\!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)) from the denominator.";
Begin["`Private`"];
hydrogenicDTME[p_List,\[Kappa]_]:=(8I)/\[Pi] (Sqrt[2\[Kappa]^5]p)/(Total[p^2]+\[Kappa]^2)^3
hydrogenicDTME[p_?NumberQ,\[Kappa]_]:=(8I)/\[Pi] (Sqrt[2\[Kappa]^5]p)/(p^2+\[Kappa]^2)^3
hydrogenicDTMERegularized[p_List,\[Kappa]_]:=(8I)/\[Pi] (Sqrt[2\[Kappa]^5]p)/1
hydrogenicDTMERegularized[p_?NumberQ,\[Kappa]_]:=(8I)/\[Pi] (Sqrt[2\[Kappa]^5]p)/1
End[];
(* ::Input::Initialization:: *)
gaussianDTME::usage="gaussianDTME[p,\[Kappa]] returns the dipole transition matrix element for a gaussian state of characteristic size 1/\[Kappa].";
Begin["`Private`"];
gaussianDTME[p_List,\[Kappa]_]:=-I (4\[Pi])^(3/4) \[Kappa]^(-7/2) p Exp[-(Total[p^2]/(2\[Kappa]^2))]
gaussianDTME[p_?NumberQ,\[Kappa]_]:=-I (4\[Pi])^(3/4) \[Kappa]^(-7/2) p Exp[-(p^2/(2\[Kappa]^2))]
End[];
(* ::Input::Initialization:: *)
SolidHarmonicS::usage="SolidHarmonicS[l,m,x,y,z] calculates the solid harmonic \!\(\*SubscriptBox[\(S\), \(lm\)]\)(x,y,z)=\!\(\*SuperscriptBox[\(r\), \(l\)]\)\!\(\*SubscriptBox[\(Y\), \(lm\)]\)(x,y,z).
SolidHarmonicS[l,m,{x,y,z}] does the same.";
Begin["`Private`"];
SolidHarmonicS[\[Lambda]_Integer,\[Mu]_Integer,x_,y_,z_]/;\[Lambda]>=Abs[\[Mu]]:=Sqrt[(2 \[Lambda]+1)/(4 \[Pi])] Sqrt[Gamma[\[Lambda]-Abs[\[Mu]]+1]/Gamma[\[Lambda]+Abs[\[Mu]]+1]] 2^-\[Lambda] (-1)^((\[Mu]-Abs[\[Mu]])/2)*
If[Rationalize[\[Mu]]==0,1,(x+Sign[\[Mu]]I y)^Abs[\[Mu]]]*
Sum[
(-1)^(\[Mu]+k) Binomial[\[Lambda],k] Binomial[2 \[Lambda]-2 k,\[Lambda]] Pochhammer[\[Lambda]-Abs[\[Mu]]-2 k+1,Abs[\[Mu]]] *
If[TrueQ[Pochhammer[\[Lambda]-Abs[\[Mu]]-2 k+1,Abs[\[Mu]]]==0],1,
If[Rationalize[k]==0,1,(x^2+y^2+z^2)^k]If[Rationalize[\[Lambda]-Abs[\[Mu]]-2 k]==0,1,z^(\[Lambda]-Abs[\[Mu]]-2 k)]
]
,{k,0,Quotient[\[Lambda],2]}]
SolidHarmonicS[\[Lambda]_Integer,\[Mu]_Integer,{x_,y_,z_}]/;\[Lambda]>=Abs[\[Mu]]:=SolidHarmonicS[\[Lambda],\[Mu],x,y,z]
End[];
(* ::Input::Initialization:: *)
hydrogenic\[CapitalPsi]::usage="hydrogenic\[CapitalPsi][n,l,m,\[Kappa],px,py,pz] calculates the momentum-space wavefunction \[CapitalPsi](p)=\[LeftAngleBracket]p|nlm\[RightAngleBracket] for a hydrogenic atom with ionization potential \!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)/2.
hydrogenic\[CapitalPsi][n,l,m,\[Kappa],{px,py,pz}] calculates the momentum-space wavefunction \[CapitalPsi](p)=\[LeftAngleBracket]p|nlm\[RightAngleBracket] for a hydrogenic atom with ionization potential \!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)/2.";
Begin["`Private`"];
hydrogenic\[CapitalPsi][n_,l_,m_,\[Kappa]\[Kappa]_,ppx_,ppy_,ppz_]:=Block[{\[Kappa],px,py,pz},
hydrogenic\[CapitalPsi][n,l,m,\[Kappa]_,px_,py_,pz_]=Simplify[
-SolidHarmonicS[l,m,px,py,pz] ((-I)^l \[Pi] 2^(2l+4) l!)/(2\[Pi] \[Kappa])^(3/2) Sqrt[(n (n-l-1)!)/(n+l)!] \[Kappa]^(l+4)/(px^2+py^2+pz^2+\[Kappa]^2)^(l+2) GegenbauerC[n-l-1,l+1,(px^2+py^2+pz^2-\[Kappa]^2)/(px^2+py^2+pz^2+\[Kappa]^2)]
];
hydrogenic\[CapitalPsi][n,l,m,\[Kappa]\[Kappa],ppx,ppy,ppz]
];
hydrogenic\[CapitalPsi][n_,l_,m_,\[Kappa]_,{px_,py_,pz_}]:=hydrogenic\[CapitalPsi][n,l,m,\[Kappa],px,py,pz];
End[];
(* ::Input::Initialization:: *)
hydrogenic\[CapitalPsi]Regularized::usage="hydrogenic\[CapitalUpsilon]Regularized[n,l,m,\[Kappa],px,py,pz] calculates the momentum-space wavefunction \[CapitalPsi](p)=\[LeftAngleBracket]p|nlm\[RightAngleBracket] for a hydrogenic atom with ionization potential \!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)/2, multiplied by (\!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)\!\(\*SuperscriptBox[\()\), \(n + 1\)]\) to remove any factors of \!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\) in the denominator.
hydrogenic\[CapitalUpsilon]Regularized[n,l,m,\[Kappa],{px,py,pz}] calculates the momentum-space wavefunction \[CapitalPsi](p)=\[LeftAngleBracket]p|nlm\[RightAngleBracket] for a hydrogenic atom with ionization potential \!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)/2, multiplied by (\!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)\!\(\*SuperscriptBox[\()\), \(n + 1\)]\) to remove any factors of \!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\) in the denominator.";
Begin["`Private`"];
hydrogenic\[CapitalPsi]Regularized[n_,l_,m_,\[Kappa]\[Kappa]_,ppx_,ppy_,ppz_]:=Block[{\[Kappa],px,py,pz},
hydrogenic\[CapitalPsi]Regularized[n,l,m,\[Kappa]_,px_,py_,pz_]=Simplify[Cancel[
-SolidHarmonicS[l,m,px,py,pz] ((-I)^l \[Pi] 2^(2l+4) l!)/(2\[Pi] \[Kappa])^(3/2) Sqrt[(n (n-l-1)!)/(n+l)!] \[Kappa]^(l+4) (px^2+py^2+pz^2+\[Kappa]^2)^(n-l-1) GegenbauerC[n-l-1,l+1,(px^2+py^2+pz^2-\[Kappa]^2)/(px^2+py^2+pz^2+\[Kappa]^2)]
]];
hydrogenic\[CapitalPsi]Regularized[n,l,m,\[Kappa]\[Kappa],ppx,ppy,ppz]
];
hydrogenic\[CapitalPsi]Regularized[n_,l_,m_,\[Kappa]_,{px_,py_,pz_}]:=hydrogenic\[CapitalPsi]Regularized[n,l,m,\[Kappa],px,py,pz];
End[];
(* ::Input::Initialization:: *)
hydrogenic\[CapitalUpsilon]::usage="hydrogenic\[CapitalUpsilon][n,l,m,\[Kappa],px,py,pz] calculates the Upsilon function \[CapitalUpsilon](p)=(\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SubscriptBox[\(I\), \(p\)]\))\[LeftAngleBracket]p|nlm\[RightAngleBracket] for a hydrogenic atom with ionization potential \!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)/2.
hydrogenic\[CapitalUpsilon][n,l,m,\[Kappa],{px,py,pz}] calculates the Upsilon function \[CapitalUpsilon](p)=(\!\(\*FractionBox[\(1\), \(2\)]\)\!\(\*SuperscriptBox[\(p\), \(2\)]\)+\!\(\*SubscriptBox[\(I\), \(p\)]\))\[LeftAngleBracket]p|nlm\[RightAngleBracket] for a hydrogenic atom with ionization potential \!\(\*SuperscriptBox[\(\[Kappa]\), \(2\)]\)/2.";
Begin["`Private`"];
hydrogenic\[CapitalUpsilon][n_,l_,m_,\[Kappa]_,px_,py_,pz_]:=1/2 (px^2+py^2+pz^2+\[Kappa]^2)hydrogenic\[CapitalPsi][n,l,m,\[Kappa],px,py,pz];
hydrogenic\[CapitalUpsilon][n_,l_,m_,\[Kappa]_,{px_,py_,pz_}]:=hydrogenic\[CapitalUpsilon][n,l,m,\[Kappa],px,py,pz];
End[];
(* ::Input::Initialization:: *)
Begin["`Private`"];
hydrogenicDTME[{ppx_,ppy_,ppz_},\[Kappa]\[Kappa]_,n_,l_,m_]:=Block[{\[Kappa],px,py,pz},
hydrogenicDTME[{px_,py_,pz_},\[Kappa]_,n,l,m]=Simplify[Grad[hydrogenic\[CapitalUpsilon][n,l,m,\[Kappa],px,py,pz],{px,py,pz}]];
hydrogenicDTME[{ppx,ppy,ppz},\[Kappa]\[Kappa],n,l,m]
];
hydrogenicDTME[{px_,py_,pz_},\[Kappa]_,{n_,l_,m_}]:=hydrogenicDTME[{px,py,pz},\[Kappa],n,l,m];
End[];
(* ::Input::Initialization:: *)
Begin["`Private`"];
hydrogenicDTMERegularized[{px_,py_,pz_},\[Kappa]_,n_,l_,m_]:=(px^2+py^2+pz^2+\[Kappa]^2)^(n+1) hydrogenicDTME[{px,py,pz},\[Kappa],n,l,m];
hydrogenicDTMERegularized[{px_,py_,pz_},\[Kappa]_,{n_,l_,m_}]:=hydrogenicDTMERegularized[{px,py,pz},\[Kappa],n,l,m];
End[];
(* ::Input::Initialization:: *)
flatTopEnvelope::usage="flatTopEnvelope[\[Omega],n,nRamp] returns a Function object representing a flat-top envelope at carrier frequency \[Omega], which lasts for a total of n cycles and is zero afterwards, with a sine-squared ramp on either end lasting for nRamp cycles.";
Begin["`Private`"];
flatTopEnvelope[\[Omega]_,num_,nRamp_]:=Function[t,Piecewise[{{0,t<0},{Sin[(\[Omega] t)/(4nRamp)]^2,0<=t<(2 \[Pi])/\[Omega] nRamp},{1,(2 \[Pi])/\[Omega] nRamp<=t<(2 \[Pi])/\[Omega] (num-nRamp)},{Sin[(\[Omega] ((2 \[Pi])/\[Omega] num-t))/(4nRamp)]^2,(2 \[Pi])/\[Omega] (num-nRamp)<=t<(2 \[Pi])/\[Omega] num},{0,(2 \[Pi])/\[Omega] num<=t}}]]
End[];
(* ::Input::Initialization:: *)
cosPowerFlatTop::usage="cosPowerFlatTop[\[Omega],num,power] returns a Function object representing a smooth flat-top envelope of the form 1-Cos(\[Omega] t/2 num\!\(\*SuperscriptBox[\()\), \(power\)]\)";
Begin["`Private`"];
cosPowerFlatTop[\[Omega]_,num_,power_]:=Function[t,1-Cos[(\[Omega] t)/(2num)]^power]
End[];
(* ::Input::Initialization:: *)
PointsPerCycle::usage="PointsPerCycle is a sampling option which specifies the number of sampling points per cycle to be used in integrations.";
TotalCycles::usage="TotalCycles is a sampling option which specifies the total number of periods to be integrated over.";
CarrierFrequency::usage="CarrierFrequency is a sampling option which specifies the carrier frequency to be used.";
CarrierFrequency::default="Warning: no CarrierFrequency was specified, using \[Omega]=`1` a.u. as the default.";
$DefaultCarrierFrequency::usage="Default CarrierFrequency to use when no explicit option is indicated.";
Protect[PointsPerCycle,TotalCycles,CarrierFrequency];
(* ::Input::Initialization:: *)
standardOptions={PointsPerCycle->90,TotalCycles->1,CarrierFrequency->Automatic,IntegrationPointsPerCycle->Automatic};
$DefaultCarrierFrequency=0.057;
(* ::Input::Initialization:: *)
GetCarrierFrequency::usage="GetCarrierFrequency[OptionValue[CarrierFrequency]] returns OptionValue[CarrierFrequency], unless it's set to Automatic, in which case it returns $DefaultCarrierFrequency and issues a warning.
GetCarrierFrequency[\[Omega]] works for any input.";
Begin["`Private`"];
GetCarrierFrequency[optionvalue_]:=If[
optionvalue===Automatic,
Message[CarrierFrequency::default,$DefaultCarrierFrequency];$DefaultCarrierFrequency,
optionvalue
]
End[];
(* ::Input::Initialization:: *)
harmonicOrderAxis::usage="harmonicOrderAxis[opt\[Rule]value] returns a list of frequencies which can be used as a frequency axis for Fourier transforms, scaled in units of harmonic order, for the provided field duration and sampling options.";
TargetLength::usage="TargetLength is an option for harmonicOrderAxis which specifies the total length required of the resulting list.";
LengthCorrection::usage="LengthCorrection is an option for harmonicOrderAxis which allows for manual correction of the length of the resulting list.";
Protect[LengthCorrection,TargetLength];
Begin["`Private`"];
Options[harmonicOrderAxis]=Join[standardOptions,{TargetLength->Automatic,LengthCorrection->1}];
harmonicOrderAxis::target="Invalid TargetLength option `1`. This must be a positive integer or Automatic.";
harmonicOrderAxis[OptionsPattern[]]:=Module[{num=OptionValue[TotalCycles],npp=OptionValue[PointsPerCycle]},
Piecewise[{
{1/num Range[0.,Round[(npp num+1)/2.]-1+OptionValue[LengthCorrection]],OptionValue[TargetLength]===Automatic},
{Round[(npp num+1)/2.]/num Range[0,OptionValue[TargetLength]-1]/OptionValue[TargetLength],IntegerQ[OptionValue[TargetLength]]&&OptionValue[TargetLength]>=0}
},
Message[harmonicOrderAxis::target,OptionValue["TargetLength"]];Abort[]
]
]
End[];
(* ::Input::Initialization:: *)
frequencyAxis::usage="frequencyAxis[opt\[Rule]value] returns a list of frequencies which can be used as a frequency axis for Fourier transforms, in atomic units of frequency, for the provided field duration and sampling options.";
Begin["`Private`"];
Options[frequencyAxis]=Options[harmonicOrderAxis];
frequencyAxis[options:OptionsPattern[]]:=GetCarrierFrequency[OptionValue[CarrierFrequency]]harmonicOrderAxis[options]
End[];
(* ::Input::Initialization:: *)
timeAxis::usage="timeAxis[opt\[Rule]value] returns a list of times which can be used as a time axis ";
TimeScale::usage="TimeScale is an option for timeAxis which specifies the units the list should use: AtomicUnits by default, or LaserPeriods if required.";
AtomicUnits::usage="AtomicUnits is a value for the option TimeScale of timeAxis which specifies that the times should be in atomic units of time.";
LaserPeriods::usage="LaserPeriods is a value for the option TimeScale of timeAxis which specifies that the times should be in multiples of the carrier laser period.";
Protect[TimeScale,AtomicUnits,LaserPeriods];
Begin["`Private`"];
Options[timeAxis]=standardOptions~Join~{TimeScale->AtomicUnits,PointNumberCorrection->0};
timeAxis::scale="Invalid TimeScale option `1`. Available values are AtomicUnits and LaserPeriods";
timeAxis[OptionsPattern[]]:=Block[{T=2\[Pi]/\[Omega],\[Omega]=GetCarrierFrequency[OptionValue[CarrierFrequency]],num=OptionValue[TotalCycles],npp=OptionValue[PointsPerCycle]},
Piecewise[{
{1,OptionValue[TimeScale]===AtomicUnits},
{1/T,OptionValue[TimeScale]===LaserPeriods}
},
Message[timeAxis::scale,OptionValue[TimeScale]];Abort[]
]*Table[t
,{t,0,num (2\[Pi])/\[Omega],num/(num*npp+OptionValue[PointNumberCorrection]) (2\[Pi])/\[Omega]}
]
]
End[];
(* ::Input::Initialization:: *)
VectorFourier::usage="VectorFourier[array,n] performs a Fourier transform on array only on level n of the array.
VectorFourier[array,{n1,n2,\[Ellipsis],nk}] performs a Fourier transform on array only on the specified levels {n1,n2,\[Ellipsis],nk}.";
Begin["`Private`"];
Options[VectorFourier]=Options[Fourier];
VectorFourier::levelspec="The level specification `1` is not correct.";
VectorFourier[array_,level_?NumericQ,opts:OptionsPattern[]]:=VectorFourier[array,{level},opts]
VectorFourier[array_,levelsToTransform_,opts:OptionsPattern[]]:=Block[{totalLevels,untouchedLevels,permutation,inversePermutation},
totalLevels=Range[Depth[array]-1];
untouchedLevels=Complement[totalLevels,levelsToTransform];
If[Not[SubsetQ[totalLevels,levelsToTransform]],Message[VectorFourier::levelspec,levelsToTransform];Abort[]];
permutation=Join[untouchedLevels,levelsToTransform];
inversePermutation=InversePermutation[permutation];
Transpose[
Map[
Function[Fourier[#,opts]],
Transpose[
array,
inversePermutation
],
{Length[untouchedLevels]}
],
permutation
]
]
End[];
(* ::Input::Initialization:: *)
differentiateDipoleList::usage="differentiateDipoleList[dipoleList,\[Delta]t,DifferentiationOrder\[Rule]n] differentiates dipoleList numerically with step \[Delta]t to order n=0,1,2.";
Begin["`Private`"];
Options[differentiateDipoleList]=Join[{DifferentiationOrder->0},standardOptions];
differentiateDipoleList::diffOrd="Invalid differentiation order `1`.";
differentiateDipoleList[dipoleList_,\[Delta]t_,opts:OptionsPattern[]]:=Block[{},
Piecewise[{
{dipoleList,OptionValue[DifferentiationOrder]==0},
{1/(2\[Delta]t) (Most[Most[dipoleList]]-Rest[Rest[dipoleList]]),OptionValue[DifferentiationOrder]==1},
{1/\[Delta]t^2 (Most[Most[dipoleList]]-2Most[Rest[dipoleList]]+Rest[Rest[dipoleList]]),OptionValue[DifferentiationOrder]==2}},
Message[differentiateDipoleList::diffOrd,OptionValue[DifferentiationOrder]];Abort[]
]
]
End[];
(* ::Input::Initialization:: *)
getSpectralAmplitude::usage="getSpectralAmplitude[DipoleList] returns the spectral amplitude of DipoleList.";
Polarization::usage="Polarization is an option for getSpectrum and getSpectralAmplitude which specifies a polarization vector along which to polarize the dipole list. The default, Polarization\[Rule]False, specifies an unpolarized spectrum.";
ComplexPart::usage="ComplexPart is an option for getSpectrum and getSpectralAmplitude which specifies a function (like Re, Im, or by default #&) which should be applied to the dipole list before the spectrum is taken.";
\[Omega]Power::usage="\[Omega]Power is an option for getSpectrum and getSpectralAmplitude which specifies a power of frequency which should multiply the spectrum.";
DifferentiationOrder::usage="DifferentiationOrder is an option for getSpectrum and getSpectralAmplitude which specifies the order to which the dipole list should be differentiated before the spectrum is taken.";
Protect[Polarization,ComplexPart,\[Omega]Power,DifferentiationOrder];
Begin["`Private`"];
Options[getSpectralAmplitude]=Join[{Polarization->False,ComplexPart->Re,\[Omega]Power->0,DifferentiationOrder->0},standardOptions];
getSpectralAmplitude::\[Omega]Pow="Invalid \[Omega] power `1`.";
getSpectralAmplitude[dipoleList_,OptionsPattern[]]:=Block[
{polarizationVector,preprocessedList,depth,dimensions,
num=OptionValue[TotalCycles],npp=OptionValue[PointsPerCycle],\[Omega],\[Delta]t=(2\[Pi]/\[Omega])/npp
},
polarizationVector=OptionValue[Polarization]/Norm[OptionValue[Polarization]];
preprocessedList=OptionValue[ComplexPart][
differentiateDipoleList[dipoleList,\[Delta]t,DifferentiationOrder->OptionValue[DifferentiationOrder]]
];
If[NumberQ[OptionValue[\[Omega]Power]],Null;,Message[getSpectralAmplitude::\[Omega]Pow,OptionValue[\[Omega]Power]];Abort[] ];
If[OptionValue[\[Omega]Power]!=0,\[Omega]=GetCarrierFrequency[OptionValue[CarrierFrequency]],\[Omega]=1];
(*If \[Omega]Power\[Equal]0 the value of \[Omega] doesn't matter and there's no sense in risking printing error messages that would result from a missing CarrierFrequency option.*)
Times[
Sqrt[num] Table[(\[Omega]/num k)^OptionValue[\[Omega]Power],{k,1,Round[Length[preprocessedList]/2]}],
Map[
If[
OptionValue[Polarization]===False,
#&,(*unpolarized spectrum*)
Dot[#,polarizationVector]&
],
VectorFourier[preprocessedList,{1}]
][[1;;Round[Length[preprocessedList]/2]]]
]
]
End[];
(* ::Input::Initialization:: *)
getSpectrum::usage="getSpectrum[DipoleList] returns the power spectrum of DipoleList.";
Begin["`Private`"];
Options[getSpectrum]=Options[getSpectralAmplitude];
getSpectrum[dipoleList_,opts:OptionsPattern[]]:=Map[
Norm[#]^2&,
getSpectralAmplitude[dipoleList,opts]
]
End[];
(* ::Input::Initialization:: *)
spectrumPlotter::usage="spectrumPlotter[spectrum] plots the given spectrum with an appropriate axis in a \!\(\*SubscriptBox[\(log\), \(10\)]\) scale.";
FrequencyAxis::usage="FrequencyAxis is an option for spectrumPlotter which specifies the axis to use.";
Protect[FrequencyAxis];
Begin["`Private`"];
Options[spectrumPlotter]=Join[{FrequencyAxis->"HarmonicOrder"},Options[harmonicOrderAxis],Options[ListLinePlot]];
spectrumPlotter[spectrum_,options:OptionsPattern[]]:=ListPlot[
{Which[
OptionValue[FrequencyAxis]==="HarmonicOrder",
harmonicOrderAxis["TargetLength"->Length[spectrum],Sequence@@FilterRules[{options}~Join~Options[spectrumPlotter],Options[harmonicOrderAxis]]],
OptionValue[FrequencyAxis]==="Frequency",
frequencyAxis["TargetLength"->Length[spectrum],Sequence@@FilterRules[{options}~Join~Options[spectrumPlotter],Options[harmonicOrderAxis]]],
True,Range[Length[spectrum]]
],
Log[10,spectrum]
}\[Transpose]
,Sequence@@FilterRules[{options},Options[ListLinePlot]]
,Joined->True
,PlotRange->Full
,PlotStyle->Thick
,Frame->True
,Axes->False
,ImageSize->800
]
End[];
(* ::Input::Initialization:: *)
biColorSpectrum::usage="biColorSpectrum[DipoleList] produces a two-colour spectrum of DipoleList, separating the two circular polarizations.";
Begin["`Private`"];
Options[biColorSpectrum]=Join[{PlotRange->All},Options[Show],Options[spectrumPlotter],DeleteCases[Options[getSpectrum],Polarization->False]];
biColorSpectrum[dipoleList_,options:OptionsPattern[]]:=Show[{
spectrumPlotter[
getSpectrum[dipoleList,Polarization->{1,+I},Sequence@@FilterRules[{options},Options[getSpectrum]]],
PlotStyle->Red,Sequence@@FilterRules[{options},Options[spectrumPlotter]]],
spectrumPlotter[
getSpectrum[dipoleList,Polarization->{1,-I},Sequence@@FilterRules[{options},Options[getSpectrum]]],
PlotStyle->Blue,Sequence@@FilterRules[{options},Options[spectrumPlotter]]]
}
,PlotRange->OptionValue[PlotRange]
,Sequence@@FilterRules[{options},Options[Show]]
]
End[];
(* ::Input::Initialization:: *)
SineSquaredGate::usage="SineSquaredGate[nGateRamp] specifies an integration gate with a sine-squared ramp, such that SineSquaredGate[nGateRamp][\[Omega]t,nGate] has nGate flat periods and nGateRamp ramp periods.";
LinearRampGate::usage="LinearRampGate[nGateRamp] specifies an integration gate with a linear ramp, such that SineSquaredGate[nGateRamp][\[Omega]t,nGate] has nGate flat periods and nGateRamp ramp periods.";
Begin["`Private`"];
SineSquaredGate[nGateRamp_][\[Omega]\[Tau]_,nGate_]:=Piecewise[{{1,\[Omega]\[Tau]<=2\[Pi] (nGate-nGateRamp)},{Sin[(2\[Pi] nGate-\[Omega]\[Tau])/(4nGateRamp)]^2,2\[Pi] (nGate-nGateRamp)<\[Omega]\[Tau]<=2\[Pi] nGate},{0,nGate<\[Omega]\[Tau]}}]
LinearRampGate[nGateRamp_][\[Omega]\[Tau]_,nGate_]:=Piecewise[{{1,\[Omega]\[Tau]<=2\[Pi] (nGate-nGateRamp)},{-((\[Omega]\[Tau]-2\[Pi] (nGate+nGateRamp))/(2\[Pi] nGateRamp)),2\[Pi] (nGate-nGateRamp)<\[Omega]\[Tau]<=2\[Pi] nGate},{0,nGate<\[Omega]\[Tau]}}]
End[];
(* ::Input::Initialization:: *)
getIonizationPotential::usage="getIonizationPotential[Target] returns the ionization potential of an atomic target, e.g. \"Hydrogen\", in atomic units.\[IndentingNewLine]
getIonizationPotential[Target,q] returns the ionization potential of the q-th ion of the specified Target, in atomic units.\[IndentingNewLine]
getIonizationPotential[{Target,q}] returns the ionization potential of the q-th ion of the specified Target, in atomic units.";
Begin["`Private`"];
getIonizationPotential[Target_,Charge_:0]:=UnitConvert[ElementData[Target,"IonizationEnergies"][[Charge+1]]/(Quantity[1,"AvogadroConstant"]Quantity[1,"Hartrees"])]
getIonizationPotential[{Target_,Charge_:0}]:=getIonizationPotential[Target,Charge]
End[];
(* ::Input::Initialization:: *)
makeDipoleList::usage="makeDipoleList[VectorPotential\[Rule]A] calculates the dipole response to the vector potential A.";
VectorPotential::usage="VectorPotential is an option for makeDipole list which specifies the field's vector potential. Usage should be VectorPotential\[Rule]A, where A[t]//.pars must yield a list of numbers for numeric t and parameters indicated by FieldParameters\[Rule]pars.";
VectorPotentialGradient::usage="VectorPotentialGradient is an option for makeDipole list which specifies the gradient of the field's vector potential. Usage should be VectorPotentialGradient\[Rule]GA, where GA[t]//.pars must yield a square matrix of the same dimension as the vector potential for numeric t and parameters indicated by FieldParameters\[Rule]pars. The indices must be such that GA[t]\[LeftDoubleBracket]i,j\[RightDoubleBracket] returns \!\(\*SubscriptBox[\(\[PartialD]\), \(i\)]\)\!\(\*SubscriptBox[\(A\), \(j\)]\)[t].";
ElectricField::usage="ElectricField is an option for makeDipole list which specifies an electric field to use in the ionization matrix element, in case the time derivative of the vector potential is not desired. Usage should be ElectricField\[Rule]F, where F[t]//.pars must yield a list of numbers for numeric t and parameters indicated by FieldParameters\[Rule]pars.";
FieldParameters::usage="FieldParameters is an option for makeDipole list which provides the parameters, as a list of replacement rules, to use in evaluating the vector potential. If the vector potential is provided as VectorPotential\[Rule]A, and the parameters as FieldParameters\[Rule]pars, then A[t]//.pars must yield a list of numbers if given a numeric argument t.";
Preintegrals::usage="Preintegrals is an option for makeDipole list which specifies whether the preintegrals of the vector potential should be \"Analytic\" or \"Numeric\".";
ReportingFunction::usage="ReportingFunction is an option for makeDipole list which specifies a function used to report the results, either internally (by the default, Identity) or to an external file.";
Gate::usage="Gate is an option for makeDipole list which specifies the integration gate to use. Usage as Gate\[Rule]g, nGate\[Rule]n will gate the integral at time \[Omega]t/\[Omega] by g[\[Omega]t,n]. The default is Gate\[Rule]SineSquaredGate[1/2].";
nGate::usage="nGate is an option for makeDipole list which specifies the total number of cycles in the integration gate.";
IonizationPotential::usage="IonizationPotential is an option for makeDipoleList which specifies the ionization potential \!\(\*SubscriptBox[\(I\), \(p\)]\) of the target.";
Target::usage="Target is an option for makeDipoleList which specifies chemical species producing the HHG emission, pulling the ionization potential from the Wolfram ElementData curated data set.";
DipoleTransitionMatrixElement::usage="DipoleTransitionMatrixElement is an option for makeDipoleList which secifies a function f to use as the dipole transition matrix element, or a pair of functions {\!\(\*SubscriptBox[\(f\), \(ion\)]\),\!\(\*SubscriptBox[\(f\), \(rec\)]\)} to be used separately for the ionization and recombination dipoels, to be used in the form f[p,\[Kappa]]=f[p,\!\(\*SqrtBox[\(2 \*SubscriptBox[\(I\), \(p\)]\)]\)].";
\[Epsilon]Correction::usage="\[Epsilon]Correction is an option for makeDipoleList which specifies the regularization correction \[Epsilon], i.e. as used in the factor \!\(\*FractionBox[\(1\), SuperscriptBox[\((t - tt + \[ImaginaryI]\[Epsilon])\), \(3/2\)]]\).";
PointNumberCorrection::usage="PointNumberCorrection is an option for makeDipoleList and timeAxis which specifies an extra number of points to be integrated over, which is useful to prevent Indeterminate errors when a Piecewise envelope is being differentiated at the boundaries.";
IntegrationPointsPerCycle::usage="IntegrationPointsPerCycle is an option for makeDipoleList which controls the number of points per cycle to use for the integration. Set to Automatic, to follow PointsPerCycle, or to an integer.";
RunInParallel::usage="RunInParallel is an option for makeDipoleList which controls whether each RB-SFA instance is parallelized. It accepts False as the (Automatic) option, True, to parallelize each instance, or a pair of functions {TableCommand, SumCommand} to use for the iteration and summing, which could be e.g. {Inactive[ParallelTable], Inactive[Sum]}.";
Simplifier::usage="Simplifier is an option for makeDipoleList which specifies a function to use to simplify the intermediate and final analytical results.";
CheckNumericFields::usage="CheckNumericFields is an option for makeDipoleList which specifies whether to check for numeric values of A[t] and GA[t] for numeric t.";
QuadraticActionTerms::usage="QuadraticActionTerms is an option for makeDipoleList which specifies whether to use quadratic terms in \[Del]\!\(\*SuperscriptBox[\(A\), \(2\)]\) in the action.";
Protect[VectorPotential,VectorPotentialGradient,ElectricField,FieldParameters,Preintegrals,ReportingFunction,Gate,nGate,IonizationPotential,Target,\[Epsilon]Correction,PointNumberCorrection,DipoleTransitionMatrixElement,IntegrationPointsPerCycle,RunInParallel,Simplifier,CheckNumericFields,QuadraticActionTerms];
Begin["`Private`"];
Options[makeDipoleList]=standardOptions~Join~{
VectorPotential->Automatic,FieldParameters->{},VectorPotentialGradient->None,ElectricField->Automatic,
Preintegrals->"Analytic",ReportingFunction->Identity,
Gate->SineSquaredGate[1/2],nGate->3/2,\[Epsilon]Correction->0.1,
IonizationPotential->0.5,Target->Automatic,DipoleTransitionMatrixElement->hydrogenicDTME,
PointNumberCorrection->0,Verbose->0,CheckNumericFields->True,
RunInParallel->Automatic,
Simplifier->Identity,QuadraticActionTerms->True
};
makeDipoleList::gate="The integration gate g provided as Gate\[Rule]`1` is incorrect. Its usage as g[`2`,`3`] returns `4` and should return a number.";
makeDipoleList::pot="The vector potential A provided as VectorPotential\[Rule]`1` is incorrect or is missing FieldParameters. Its usage as A[`2`] returns `3` and should return a list of numbers.";
makeDipoleList::efield="The electric field f provided as ElectricField\[Rule]`1` is incorrect or is missing FieldParameters. Its usage as F[`2`] returns `3` and should return a list of numbers. Alternatively, use ElectricField\[Rule]Automatic.";
makeDipoleList::gradpot="The vector potential GA provided as VectorPotentialGradient\[Rule]`1` is incorrect or is missing FieldParameters. Its usage as GA[`2`] returns `3` and should return a square matrix of numbers. Alternatively, use VectorPotentialGradient\[Rule]None.";
makeDipoleList::preint="Wrong Preintegrals option `1`. Valid options are \"Analytic\" and \"Numeric\".";
makeDipoleList::runpar="Wrong RunInParallel option `1`.";
makeDipoleList::carrfreq="Non-numeric option CarrierFrequency `1`.";
makeDipoleList[OptionsPattern[]]:=Block[
{
num=OptionValue[TotalCycles],npp=OptionValue[PointsPerCycle],\[Omega],
dipoleRec,dipoleIon,\[Kappa],
A,F,GA,pi,ps,S,
gate,tGate,setPreintegral,
tInit,tFinal,\[Delta]t,\[Delta]tint,\[Epsilon]=OptionValue[\[Epsilon]Correction],
AInt,A2Int,GAInt,GAdotAInt,AdotGAInt,GAIntInt,
PScorrectionInt,constCorrectionInt,GAIntdotGAIntInt,QuadMatrix,q,
simplifier,prefactor,integrand,dipoleList,
TableCommand,SumCommand
},
A[t_]=OptionValue[VectorPotential][t]//.OptionValue[FieldParameters];
If[
OptionValue[ElectricField]===Automatic,F[t_]=-D[A[t],t];,
F[t_]=OptionValue[ElectricField][t]//.OptionValue[FieldParameters];
];
GA[t_]=If[
TrueQ[OptionValue[VectorPotentialGradient]==None], Table[0,{Length[A[tInit]]},{Length[A[tInit]]}],
OptionValue[VectorPotentialGradient][t]//.OptionValue[FieldParameters]
];
\[Omega]=GetCarrierFrequency[OptionValue[CarrierFrequency]];
If[!NumberQ[\[Omega]]&&TrueQ[OptionValue[CheckNumericFields]],Message[makeDipoleList::carrfreq,\[Omega]];Abort[]];
tInit=0;
tFinal=(2\[Pi])/\[Omega] num;
(*looping timestep*)
\[Delta]t=(tFinal-tInit)/(num*npp+OptionValue[PointNumberCorrection]);
(*integration timestep*)
\[Delta]tint=If[OptionValue[IntegrationPointsPerCycle]===Automatic,\[Delta]t,(tFinal-tInit)/(num*OptionValue[IntegrationPointsPerCycle]+OptionValue[PointNumberCorrection])];
tGate=OptionValue[nGate] (2\[Pi])/\[Omega];
(*Check potential and potential gradient for correctness.*)
(*To do: change logic conditions to constructions on VectorQ[#,NumberQ]& and MatrixQ.*)
If[TrueQ[OptionValue[CheckNumericFields]],
With[{\[Omega]tRandom=RandomReal[{\[Omega] tInit,\[Omega] tFinal}]},
If[!And@@(NumberQ/@A[\[Omega]tRandom/\[Omega]]),Message[makeDipoleList::pot,OptionValue[VectorPotential],\[Omega]tRandom,A[\[Omega]tRandom]];Abort[]];
If[!And@@(NumberQ/@Flatten[GA[\[Omega]tRandom/\[Omega]]]),Message[makeDipoleList::gradpot,OptionValue[VectorPotentialGradient],\[Omega]tRandom,GA[\[Omega]tRandom]];Abort[]];
If[!And@@(NumberQ/@F[\[Omega]tRandom/\[Omega]]),Message[makeDipoleList::efield,OptionValue[ElectricField],\[Omega]tRandom,F[\[Omega]tRandom]];Abort[]];
]];
gate[\[Omega]\[Tau]_]:=OptionValue[Gate][\[Omega]\[Tau],OptionValue[nGate]];
With[{\[Omega]tRandom=RandomReal[{\[Omega] tInit,\[Omega] tFinal}]},
If[!TrueQ[NumberQ[gate[\[Omega]tRandom]]],
Message[makeDipoleList::gate,OptionValue[Gate],\[Omega]tRandom,OptionValue[nGate],gate[\[Omega]tRandom]];Abort[]]
];
(*Target setup*)
Which[
OptionValue[Target]===Automatic,\[Kappa]=Sqrt[2OptionValue[IonizationPotential]],
True,\[Kappa]=Sqrt[2getIonizationPotential[OptionValue[Target]]]
];
With[{dim=Length[A[RandomReal[{\[Omega] tInit,\[Omega] tFinal}]]]},
(*Explicit conjugation of the recombination matrix element to keep the integrand analytic.*)
Which[
Head[OptionValue[DipoleTransitionMatrixElement]]===List,
dipoleIon[{p1_,p2_,p3_}[[1;;dim]],\[Kappa]\[Kappa]_]=First[OptionValue[DipoleTransitionMatrixElement]][{p1,p2,p3}[[1;;dim]],\[Kappa]\[Kappa]];
dipoleRec[{p1_,p2_,p3_}[[1;;dim]],\[Kappa]\[Kappa]_]=Assuming[{{p1,p2,p3,\[Kappa]\[Kappa]}\[Element]Reals},Simplify[
Conjugate[Last[OptionValue[DipoleTransitionMatrixElement]][{p1,p2,p3}[[1;;dim]],\[Kappa]\[Kappa]]]
]];
,True,
dipoleIon[{p1_,p2_,p3_}[[1;;dim]],\[Kappa]\[Kappa]_]=OptionValue[DipoleTransitionMatrixElement][{p1,p2,p3}[[1;;dim]],\[Kappa]\[Kappa]];
dipoleRec[{p1_,p2_,p3_}[[1;;dim]],\[Kappa]\[Kappa]_]=Assuming[{{p1,p2,p3,\[Kappa]\[Kappa]}\[Element]Reals},Simplify[
Conjugate[OptionValue[DipoleTransitionMatrixElement][{p1,p2,p3}[[1;;dim]],\[Kappa]\[Kappa]]]
]];
];
];
simplifier=OptionValue[Simplifier];
q=Boole[TrueQ[OptionValue[QuadraticActionTerms]]];
setPreintegral[integralVariable_,preintegrand_,dimensions_,integrateWithoutGradient_,parametric_]:=Which[
OptionValue[VectorPotentialGradient]=!=None||TrueQ[integrateWithoutGradient],(*Vector potential gradient specified, or integral variable does not depend on it, so integrate*)
Which[
OptionValue[Preintegrals]=="Analytic",
integralVariable[t_,tt_]=simplifier[((#/.{\[Tau]->t})-(#/.{\[Tau]->tt}))&[Integrate[preintegrand[\[Tau],tt],\[Tau]]]];
,OptionValue[Preintegrals]=="Numeric",
Which[
TrueQ[Not[parametric]],
Block[{innerVariable},
integralVariable[t_,tt_]=(innerVariable[t]-innerVariable[tt]/.First[
NDSolve[{innerVariable'[\[Tau]]==preintegrand[\[Tau]],innerVariable[tInit]==ConstantArray[0,dimensions]},innerVariable,{\[Tau],tInit,tFinal},MaxStepSize->0.25/\[Omega]]
])
];
,True,
Block[{matrixpreintegrand,innerVariable,\[Tau]pre},
matrixpreintegrand[indices_,t_?NumericQ,tt_?NumericQ]:=preintegrand[t,tt][[##&@@indices]];
integralVariable[t_,tt_]=Array[(
innerVariable[##][t-tt,tt]/.First@NDSolve[{
D[innerVariable[##][\[Tau]pre,tt],\[Tau]pre]==Piecewise[{{matrixpreintegrand[{##},tt+\[Tau]pre,tt],tt+\[Tau]pre<=tFinal}},0],
innerVariable[##][0,tt]==0
},innerVariable[##]
,{\[Tau]pre,0,tFinal-tInit},{tt,tInit,tFinal}
,MaxStepSize->0.25/\[Omega]
]
)&,dimensions];
]
];
];
,OptionValue[VectorPotentialGradient]===None,(*Vector potential gradient has not been specified, and integral variable depends on it, so return appropriate zero matrix*)
integralVariable[t_]=ConstantArray[0,dimensions];
integralVariable[t_,tt_]=ConstantArray[0,dimensions];
];
Apply[setPreintegral,({
{AInt, A[#1]&, {Length[A[tInit]]}, True, False},
{A2Int, A[#1].A[#1]&, {}, True, False},
{GAInt, GA[#1]&, {Length[A[tInit]],Length[A[tInit]]}, False, False},
{GAdotAInt, GA[#1].A[#1]&, {Length[A[tInit]]}, False, False},
{AdotGAInt, A[#1].GA[#1]&, {Length[A[tInit]]}, False, False},
{GAIntInt, GAInt[#1,#2]&, {Length[A[tInit]],Length[A[tInit]]}, False, True},
{PScorrectionInt, GAdotAInt[#1,#2]+A[#1].GAInt[#1,#2]-q GAInt[#1,#2]\[Transpose].GAdotAInt[#1,#2]&, {Length[A[tInit]]}, False, True},
{GAIntdotGAIntInt, q GAInt[#1,#2]\[Transpose].GAInt[#1,#2]&, {Length[A[tInit]],Length[A[tInit]]}, False, True},
{constCorrectionInt, (A[#1]-q/2 GAdotAInt[#1,#2]).GAdotAInt[#1,#2]&, {}, False, True}
}),{1}];
(*{\!\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(t\), \(0\)], \(t\)]\(A\((\[Tau])\)\[DifferentialD]\[Tau]\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(t\), \(0\)], \(t\)]\(A
\*SuperscriptBox[\((\[Tau])\), \(2\)]\[DifferentialD]\[Tau]\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(t\), \(0\)], \(t\)]\(\[Del]A\((\[Tau])\)\[DifferentialD]\[Tau]\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(t\), \(0\)], \(t\)]\(\[Del]A\((\[Tau])\)\[CenterDot]A\((\[Tau])\)\[DifferentialD]\[Tau]\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(t\), \(0\)], \(t\)]\(A\((\[Tau])\)\[CenterDot]\[Del]A\((\[Tau])\)\[DifferentialD]\[Tau]\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(t\)]\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(\[Tau]\)]\[Del]A\((\[Tau]')\)\[DifferentialD]\[Tau]'\[DifferentialD]\[Tau]\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(t\)]\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(\[Tau]\)]
\*SubscriptBox[\(\[PartialD]\), \(j\)]
\*SubscriptBox[\(A\), \(k\)]\((\[Tau]')\)
\*SubscriptBox[\(A\), \(k\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\)\)+Subscript[A, k](\[Tau])\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(\[Tau]\)]\(
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[\(A\), \(j\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\)\)-\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(\[Tau]\)]\(
\*SubscriptBox[\(\[PartialD]\), \(i\)]
\*SubscriptBox[\(A\), \(j\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(\[Tau]\)]
\*SubscriptBox[\(\[PartialD]\), \(i\)]
\*SubscriptBox[\(A\), \(k\)]\((\[Tau]')\)
\*SubscriptBox[\(A\), \(k\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\[DifferentialD]\[Tau]\)\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(t\)]\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(t\), \(0\)], \(t\)]
\*SubscriptBox[\(\[PartialD]\), \(i\)]
\*SubscriptBox[\(A\), \(j\)]\((\[Tau]')\)
\*SubscriptBox[\(A\), \(j\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(t\), \(0\)], \(t\)]
\*SubscriptBox[\(\[PartialD]\), \(i\)]
\*SubscriptBox[\(A\), \(k\)]\((\[Tau]')\)
\*SubscriptBox[\(A\), \(k\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\[DifferentialD]\[Tau]\)\)\),\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(t\)]\(\((
\*SubscriptBox[\(A\), \(k\)]\((\[Tau])\) -
\*FractionBox[\(1\), \(2\)]\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(\[Tau]\)]
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[\(A\), \(i\)]\((\[Tau]')\)
\*SubscriptBox[\(A\), \(i\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\))\)\[CenterDot]\(
\*SubsuperscriptBox[\(\[Integral]\), \(t'\), \(\[Tau]\)]
\*SubscriptBox[\(\[PartialD]\), \(k\)]
\*SubscriptBox[\(A\), \(j\)]\((\[Tau]')\)
\*SubscriptBox[\(A\), \(j\)]\((\[Tau]')\)\[DifferentialD]\[Tau]'\[DifferentialD]\[Tau]\)\)\)};*)
(*Displaced momentum*)
pi[p_,t_,tt_]:=p+A[t]-GAInt[t,tt].p-GAdotAInt[t,tt];
(*Quadratic coefficient in nondipole action*)
QuadMatrix[t_,tt_]:=(GAIntInt[t,tt]+GAIntInt[t,tt]\[Transpose])/2-1/2 GAIntdotGAIntInt[t,tt];
(*Stationary momentum and action*)
ps[t_,tt_]:=ps[t,tt]=-(1/(t-tt-I \[Epsilon]))Inverse[IdentityMatrix[Length[A[tInit]]]-1/(t-tt-I \[Epsilon]) 2QuadMatrix[t,tt]].(AInt[t,tt]-PScorrectionInt[t,tt]);
S[t_,tt_]:=simplifier[
1/2 (Total[ps[t,tt]^2]+\[Kappa]^2)(t-tt)+ps[t,tt].AInt[t,tt]+1/2 A2Int[t,tt]-(
ps[t,tt].QuadMatrix[t,tt].ps[t,tt]+ps[t,tt].PScorrectionInt[t,tt]+constCorrectionInt[t,tt]
)
];
prefactor[t_,\[Tau]_]:=I ((2\[Pi])/(\[Epsilon]+I \[Tau]))^(3/2) dipoleRec[pi[ps[t,t-\[Tau]],t,t-\[Tau]],\[Kappa]]*dipoleIon[pi[ps[t,t-\[Tau]],t-\[Tau],t-\[Tau]],\[Kappa]].F[t-\[Tau]];
integrand[t_,\[Tau]_]:=prefactor[t,\[Tau]]Exp[-I S[t,t-\[Tau]]]gate[\[Omega] \[Tau]];
(*Debugging constructs. Verbose\[Rule]1 prints information about the internal functions. Verbose\[Rule]2 returns all the relevant internal functions and stops. Verbose\[Rule]3 for quantum-orbit constructs.*)
Which[
OptionValue[Verbose]==1,Information/@{A,GA,ps,pi,S,AInt,A2Int,GAInt,GAdotAInt,AdotGAInt,GAIntInt,PScorrectionInt,constCorrectionInt,GAIntdotGAIntInt},
OptionValue[Verbose]==2,Return[With[{t=Symbol["t"],tt=Symbol["tt"],\[Tau]=Symbol["\[Tau]"],p={Symbol["p1"],Symbol["p2"],Symbol["p3"]}[[1;;Length[A[\[Omega] tInit]]]]},
{A[t],GA[t],ps[t,tt],pi[p,t,tt],S[t,tt],AInt[t,tt],A2Int[t,tt],GAInt[t,tt],GAdotAInt[t,tt],AdotGAInt[t,tt],GAIntInt[t,tt],PScorrectionInt[t,tt],constCorrectionInt[t,tt],GAIntdotGAIntInt[t,tt],QuadMatrix[t,tt],integrand[t,\[Tau]]}]],
OptionValue[Verbose]==3,
Return[{
Function[Evaluate[prefactor[#1,#1-#2]]],Function[Evaluate[S[#1,#2]]]
}]
];
(*Single-run parallelization*)
Which[
OptionValue[RunInParallel]===Automatic||OptionValue[RunInParallel]===False, TableCommand=Table;SumCommand=Sum;,
OptionValue[RunInParallel]===True,TableCommand=ParallelTable;SumCommand=Sum;,
True,TableCommand=OptionValue[RunInParallel][[1]];SumCommand=OptionValue[RunInParallel][[2]];
];
(*Numerical integration loop*)
dipoleList=Table[
OptionValue[ReportingFunction][
\[Delta]tint Sum[(
integrand[t,\[Tau]]
),{\[Tau],0,If[OptionValue[Preintegrals]=="Analytic",tGate,Min[t-tInit,tGate]],\[Delta]tint}]
]
,{t,tInit,tFinal,\[Delta]t}
];
dipoleList
]
End[];
(* ::Input::Initialization:: *)
FindComplexRoots::usage="FindComplexRoots[e1==e2, {z, zmin, zmax}] attempts to find complex roots of the equation e1==e2 in the complex rectangle with corners zmin and zmax.
FindComplexRoots[{e1==e2, e3==e4, \[Ellipsis]}, {z1, z1min, z1max}, {z2, z2min, z2max}, \[Ellipsis]] attempts to find complex roots of the given system of equations in the multidimensional complex rectangle with corners z1min, z1max, z2min, z2max, \[Ellipsis].";
Seeds::usage="Seeds is an option for FindComplexRoots which determines how many initial seeds are used to attempt to find roots of the given equation.";
SeedGenerator::usage="SeedGenerator is an option for FindComplexRoots which determines the function used to generate the seeds for the internal FindRoot call. Its value can be RandomComplex, RandomNiederreiterComplexes, RandomSobolComplexes, DeterministicComplexGrid, or any function f such that f[{zmin, zmax}, n] returns n complex numbers in the rectancle with corners zmin and zmax.";
Options[FindComplexRoots] = Join[Options[FindRoot], {Seeds -> 50, SeedGenerator -> RandomComplex, Tolerance -> Automatic, Verbose -> False}];
SyntaxInformation[FindComplexRoots] = {"ArgumentsPattern" -> {_, {_, _, _}, OptionsPattern[]}, "LocalVariables" -> {"Table", {2, \[Infinity]}}};
FindComplexRoots::seeds = "Value of option Seeds -> `1` is not a positive integer.";
FindComplexRoots::tol = "Value of option Tolerance -> `1` is not Automatic or a number in [0,\[Infinity]).";
$MessageGroups=Join[$MessageGroups,{"FindComplexRoots":>{FindRoot::lstol}}];
Protect[Seeds];
Protect[SeedGenerator];
(* ::Input::Initialization:: *)
SetTolerances::usage="SetTolerances[tolerance,length] produces a list of the given length with the specified tolerance, which may be a number or a list of numbers.\n
SetTolerances[tolerance,length,workingPrecision] allows a fallback to a specified workingPrecision in case the given tolerance fails to be numeric.";
Begin["`Private`"];
SetTolerances[tolerance_,length_,workingPrecision_:$MachinePrecision]:=Which[
ListQ[tolerance],tolerance,
True,ConstantArray[
Which[
NumberQ[tolerance],tolerance,
True,10^If[NumberQ[workingPrecision], 2-workingPrecision,2-$MachinePrecision]
]
,length]
]
End[];
(* ::Input::Initialization:: *)
Begin["`Private`"];
FindComplexRoots[equations_List,domainSpecifiers__, ops : OptionsPattern[]] := Block[{seeds,tolerances},
If[! IntegerQ[Rationalize[OptionValue[Seeds]]] || OptionValue[Seeds]<=0,Message[FindComplexRoots::seeds, OptionValue[Seeds]]];If[! (OptionValue[Tolerance] === Automatic || OptionValue[Tolerance]>=0),Message[FindComplexRoots::tol, OptionValue[Seeds]]];
seeds=OptionValue[SeedGenerator][{domainSpecifiers}[[All,{2,3}]],OptionValue[Seeds]];
tolerances=SetTolerances[OptionValue[Tolerance],Length[{domainSpecifiers}],OptionValue[WorkingPrecision]];
If[OptionValue[Verbose],Hold[], Hold[FindRoot::lstol]] /. {
Hold[messageSequence___] :> Quiet[
DeleteDuplicates[
Select[
Check[
FindRoot[
equations
,Evaluate[Sequence@@Table[{{domainSpecifiers}[[j,1]],#[[j]]},{j,Length[{domainSpecifiers}]}]]
,Evaluate[Sequence @@ FilterRules[{ops}, Options[FindRoot]]]
],
##&[]
]&/@seeds,
Function[
repList,
ReplaceAll[
Evaluate[And@@Table[
And[
Re[{domainSpecifiers}[[j,2]]]<=Re[{domainSpecifiers}[[j,1]]]<=Re[{domainSpecifiers}[[j,3]]],
Im[{domainSpecifiers}[[j,2]]]<=Im[{domainSpecifiers}[[j,1]]]<=Im[{domainSpecifiers}[[j,3]]]
]
,{j,Length[{domainSpecifiers}]}]]
,repList]
]
],
Function[{repList1,repList2},
And@@Table[
Abs[({domainSpecifiers}[[j,1]]/.repList1)-({domainSpecifiers}[[j,1]]/.repList2)]<tolerances[[j]]
,{j,Length[{domainSpecifiers}]}]
]
]
, {messageSequence}]}
]
FindComplexRoots[e1_==e2_,{z_,zmin_,zmax_},ops:OptionsPattern[]]:=FindComplexRoots[{e1==e2},{z,zmin,zmax},ops]
End[];
(* ::Input::Initialization:: *)
RandomSobolComplexes::usage="RandomSobolComplexes[{zmin, zmax}, n] generates a low-discrepancy Sobol sequence of n quasirandom complex numbers in the rectangle with corners zmin and zmax.
RandomSobolComplexes[{{z1min,z1max},{z2min,z2max},\[Ellipsis]},n] generates a low-discrepancy Sobol sequence of n quasirandom complex numbers in the multi-dimensional rectangle with corners {z1min,z1max},{z2min,z2max},\[Ellipsis].";
(* ::Input::Initialization:: *)
Begin["`Private`"];
RandomSobolComplexes[pairsList__, number_] :=Map[
Function[randomsList,
pairsList[[All,1]]+Complex@@@Times[
ReIm[pairsList[[All,2]]-pairsList[[All,1]]],
randomsList
]
],
BlockRandom[
SeedRandom[Method->{"MKL",Method->{"Sobol", "Dimension" -> 2Length[pairsList]}}];
SeedRandom[];
RandomReal[{0, 1}, {number,Length[pairsList],2}]
]
]
RandomSobolComplexes[{zmin_?NumericQ,zmax_?NumericQ},number_]:=RandomSobolComplexes[{{zmin,zmax}},number][[All,1]]
End[];
(* ::Input::Initialization:: *)
RandomNiederreiterComplexes::usage="RandomNiederreiterComplexes[{zmin, zmax}, n] generates a low-discrepancy Niederreiter sequence of n quasirandom complex numbers in the rectangle with corners zmin and zmax.
RandomNiederreiterComplexes[{{z1min,z1max},{z2min,z2max},\[Ellipsis]},n] generates a low-discrepancy Niederreiter sequence of n quasirandom complex numbers in the multi-dimensional rectangle with corners {z1min,z1max},{z2min,z2max},\[Ellipsis].";
(* ::Input::Initialization:: *)
Begin["`Private`"];
RandomNiederreiterComplexes[pairsList__, number_] :=Map[
Function[randomsList,
pairsList[[All,1]]+Complex@@@Times[
ReIm[pairsList[[All,2]]-pairsList[[All,1]]],
randomsList
]
],
BlockRandom[
SeedRandom[Method->{"MKL",Method->{"Niederreiter", "Dimension" -> 2Length[pairsList]}}];
SeedRandom[];
RandomReal[{0, 1}, {number,Length[pairsList],2}]
]
]
RandomNiederreiterComplexes[{zmin_?NumericQ,zmax_?NumericQ},number_]:=RandomNiederreiterComplexes[{{zmin,zmax}},number][[All,1]]
End[];
(* ::Input::Initialization:: *)
DeterministicComplexGrid::usage="DeterministicComplexGrid[{zmin, zmax}, n] generates a grid of about n equally spaced complex numbers in the rectangle with corners zmin and zmax.
DeterministicComplexGrid[{{z1min,z1max},{z2min,z2max},\[Ellipsis]},n] generates a regular grid of about n equally spaced complex numbers in the multi-dimensional rectangle with corners {z1min,z1max},{z2min,z2max},\[Ellipsis].";
(* ::Input::Initialization:: *)
Begin["`Private`"];
DeterministicComplexGrid[pairsList_,number_]:=Block[{sep,separationsList,gridPointBasis,k},
sep=NestWhile[0.99#&,Min[Flatten[ReIm[pairsList[[All,2]]-pairsList[[All,1]]]]],Times@@(Floor[Flatten[ReIm[pairsList[[All,2]]-pairsList[[All,1]]]],0.99#]/(0.99#))<=number&];
separationsList=Round[Floor[Flatten[ReIm[pairsList[[All,2]]-pairsList[[All,1]]]],sep]/sep];
gridPointBasis=MapThread[
Function[{l,n},Range[l[[1]],l[[2]],(l[[2]]-l[[1]])/(n+1)][[2;;-2]]],
{Flatten[Transpose[ReIm[pairsList],{1,3,2}],1],separationsList}
];
Flatten[Table[
Table[k[2j-1]+I k[2j],{j,1,Length[pairsList]}],
Evaluate[Sequence@@Table[{k[j],gridPointBasis[[j]]},{j,1,2Length[pairsList]}]]
],Evaluate[Range[1,2Length[pairsList]]]]
]
DeterministicComplexGrid[{zmin_?NumericQ,zmax_?NumericQ},number_]:=DeterministicComplexGrid[{{zmin,zmax}},number][[All,1]]
End[];
(* ::Input::Initialization:: *)
Begin["`Private`"];
Unprotect[RandomComplex];
RandomComplex[{range1_List,moreRanges___},number_]:=Transpose[RandomComplex[#,number]&/@{range1,moreRanges}]
Protect[RandomComplex];
End[];
(* ::Input::Initialization:: *)
Parallelize;
If[Head[Parallel`Developer`$InitCode]=!=Hold,
Parallel`Developer`$InitCode=Hold[]
];
Parallel`Developer`$InitCode=Join[
Parallel`Developer`$InitCode,
Hold[
Unprotect[RandomComplex];
RandomComplex[{Private`range1_List,Private`moreRanges___},Private`number_]:=Transpose[RandomComplex[#,Private`number]&/@{Private`range1,Private`moreRanges}];
Protect[RandomComplex];
]
];
(* ::Input::Initialization:: *)
ConstrainedDerivative::usage="ConstrainedDerivative[n][f][t,tt] calculates the nth derivative of f[t,tt] with respect to t under the constraint that Derivative[0,1][f][t,tt]\[Congruent]0.";
Begin["`Private`"];
ConstrainedDerivative[n_][F_][te_,tte_]:=Block[{f,tts,t,tt},
ConstrainedDerivative[n][f_][t_,tt_]=Nest[
Function[
Simplify[
D[#/.{tt->tts[t]},t]/.{Derivative[0,1][f][t,tts[t]]->0,tts'[t]->-(Derivative[1,1][f][t,tts[t]]/Derivative[0,2][f][t,tts[t]])}
]/.{tts[t]->tt}
]
,f[t,tt],n];
ConstrainedDerivative[n][F][te,tte]
]
End[];
(* ::Input::Initialization:: *)
GetSaddlePoints::usage="GetSaddlePoints[\[CapitalOmega],S,{tmin,tmax},{\[Tau]min,\[Tau]max}] finds a list of solutions {t,\[Tau]} of the HHG temporal saddle-point equations at harmonic energy \[CapitalOmega] for action S, in the range {tmin, tmax} of recombination time and {\[Tau]min, \[Tau]max} of excursion time, where both ranges should be the lower-left and upper-right corners of rectangles in the complex plane.
GetSaddlePoints[\[CapitalOmega]Range,S,{tmin,tmax},{\[Tau]min,\[Tau]max}] finds solutions of the HHG temporal saddle-point equations for a range of harmonic energies \[CapitalOmega]Range, and returns an Association with each harmonic energy \[CapitalOmega] indexing a list of saddle-point solution pairs {t,\[Tau]}.
GetSaddlePoints[\[CapitalOmega]spec,S,{{{\!\(\*SubscriptBox[\(tmin\), \(1\)]\),\!\(\*SubscriptBox[\(tmax\), \(1\)]\)},{\!\(\*SubscriptBox[\(\[Tau]min\), \(1\)]\),\!\(\*SubscriptBox[\(\[Tau]max\), \(1\)]\)}},{{\!\(\*SubscriptBox[\(tmin\), \(2\)]\),\!\(\*SubscriptBox[\(tmax\), \(2\)]\)},{\!\(\*SubscriptBox[\(\[Tau]min\), \(2\)]\),\!\(\*SubscriptBox[\(\[Tau]max\), \(2\)]\)}},\[Ellipsis]}] uses multiple time domains and combines the solutions.
GetSaddlePoints[\[CapitalOmega]spec,S,{{urange,vrange},\[Ellipsis]},IndependentVariables\[Rule]{u,v}] uses the explicit independent variables u and v to solve the equations and over the given ranges, where u and v can be any of \"RecombinationTime\", \"IonizationTime\" and \"ExcursionTime\", or their shorthands \"t\", \"tt\" and \"\[Tau]\" resp.";
SortingFunction::usage="SortingFunction is an option of GetSaddlePoints which sets a function f, to be used as f[t,\[Tau],S,\[CapitalOmega]], to be used to sort the solutions, or a list of such functions.";
SelectionFunction::usage="SelectionFunction is an option of GetSaddlePoints that sets a function f, to be used as f[t,\[Tau],S,\[CapitalOmega]], such that roots are only kept if f returns True.";
IndependentVariables::usage="IndependentVariables is an option for GetSaddlePoints that specifies the two independent variables, out of \"RecombinationTime\", \"IonizationTime\" and \"ExcursionTime\" (or their shorthands \"t\", \"tt\" and \"\[Tau]\", respectively), to be used in solving the saddle-point equations, and which range over the given regions.";
FiniteDifference::usage="FiniteDifference is a value for the option Jacobian of FindRoot, FindComplexRoots, GetSaddlePoints, and related functions, which specifies that the Jacobian at each step should be evaluated using numerical finite difference procedures.";
GetSaddlePoints::error="Errors encountered for harmonic energy \[CapitalOmega]=`1`.";
Begin["`Private`"];
Options[GetSaddlePoints]=Join[{SortingFunction->(#2&),SelectionFunction->(True&),IndependentVariables->{"RecombinationTime","ExcursionTime"}},Options[FindComplexRoots]];
Protect[SortingFunction,SelectionFunction,IndependentVariables,FiniteDifference];
GetSaddlePoints[\[CapitalOmega]spec_,S_,{tmin_,tmax_},{\[Tau]min_,\[Tau]max_},options:OptionsPattern[]]:=GetSaddlePoints[\[CapitalOmega]spec,S,{{{tmin,tmax},{\[Tau]min,\[Tau]max}}},options]
GetSaddlePoints[\[CapitalOmega]_,S_,timeRanges_,options:OptionsPattern[]]:=Block[{equations,roots,t=Symbol["t"],tt=Symbol["tt"],\[Tau]=Symbol["\[Tau]"],indVars,depVar,depVarRule,tolerances},
tolerances=SetTolerances[OptionValue[Tolerance],2,OptionValue[WorkingPrecision]];
indVars=OptionValue[IndependentVariables]/.{"RecombinationTime"->"t","ExcursionTime"->"\[Tau]","IonizationTime"->"tt"};