-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim.hpp
3494 lines (2893 loc) · 91.3 KB
/
sim.hpp
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
//#include "stdafx.h"
#include <math.h>
#include <time.h>
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
#include "mutex.h"
#include <iostream>
#include "boost/random.hpp"
#include "boost/generator_iterator.hpp"
#include "boost/random/uniform_real_distribution.hpp"
#include <stdio.h>
#include <string>
#include "exports.h"
#include "mcp.h"
#include "Data1DPlotArray.h"
#include "levmarq.h"
#include "sim.h"
#include <boost/thread/mutex.hpp>
boost::mutex io_mutex; // The iostreams are not guaranteed to be thread-safe!
///gsl includes
#include <stdlib.h>
#include <stdio.h>
#include <FullGLWidgetCode.h>
#include "ScriptDll.h"
extern EXPORT FullGLWidgetCode &IonTrapDisplay;
using namespace std;
glob(int,numIons,maxionanz);
double Time=4000./1e6; //30000./1e6; Gesamtdauer der Simulation in sekunden //49993./1e6; //1000./1e6;//
//ACHTUNG!!! Time muss ausreichend klein gewählt werden, ab einem bestimmten größe des Time/steps verhältnisses steigen sonst die fallenfrequenzen an
// wenn das verhältnis klein genug ist, gehen die fallenfrequenzen "in sättigung", sprich kleinere Time werte verringern die fallenfrequenz nicht weiter.
int const steps=2000000; //Anzahl der Simulationssteps
glob(double, hglob,5e-9); //zeitschritt in sekunden
double xStart[maxionanz][3]={};
double vStart[maxionanz][3]={};
// Electron charge
#undef electronCharge
#undef MCa
#undef qDivM
const double electronCharge=1.602176565e-19;
//Mass of Calcium
const double MCa=(40.078*1.660538921e-27);
const double qDivM=electronCharge/MCa;
#define pi 3.141592653589793
#define epsilon0 8.854187818E-12 /* epsilon0 +- .000000071E-12 F/m */
const static double forceconstant=(electronCharge*electronCharge/(4.*pi*epsilon0))/MCa;
#define C 299792458.
#define mm 1./1000.
#define MHz 1000000.
#define hbar 1.054571726e-34 //in [Js]
const double k_B=1.3806488e-23; // Boltzmann Konstante [J/K]
//ACHTUNG!!! Time muss ausreichend klein gewählt werden, ab einem bestimmten größe des Time/steps verhältnisses steigen sonst die fallenfrequenzen an
// wenn das verhältnis klein genug ist, gehen die fallenfrequenzen "in sättigung", sprich kleinere Time werte verringern die fallenfrequenz nicht weiter.
const double T=0.001;//0.1; //in Kelvin
glob(bool,initialdamp,false);
glob(double,OmegaRF,22.75e6);
///gsl includes
//#include <unistd.h>
//#include "linearPaulTrap_edit.h"
glob(bool,runningcalc,true);
bool refine=true;
class D3world;
class D3electrode;
//sollte ungerade anzahl sein da <---- zu faul war für gerade
#define Anzahl 11
#define LOOPS 100
bool maincalled=false;
//include editable scripts here
#ifndef __CINT__
//#include "linearPaulTrap_edit.cxx"
#else
void load(){int retval;gROOT->ProcessLine(".L Traptest.cpp", &retval );}
void unload(){int retval;gROOT->ProcessLine(".U Traptest.cpp", &retval );}
void u() {unload();}
void l() {load();}
#endif
#define Anzahl 11
#define PI 3.141592653589793
struct Xv{
int i;
double *xpos;
double *ypos;
double *zpos;
double *vxpos;
double *vypos;
double *vzpos;
double *tpos;
double *rpos;
};
const int anz=100;
//double arrx[anz];
//double arrxpot[anz];
//double arrxpotfit[anz];
//EXPORT Data1DPlotArray potplotx(anz,arrx,arrxpot);
//EXPORT Data1DPlotArray potplotfitx(anz,arrx,arrxpotfit);
//double arry[anz];
//double arrypot[anz];
//double arrypotfit[anz];
//EXPORT Data1DPlotArray potploty(anz,arry,arrypot);
//EXPORT Data1DPlotArray potplotfity(anz,arry,arrypotfit);
//double arrz[anz];
//double arrzpot[anz];
//double arrzpotfit[anz];
//EXPORT Data1DPlotArray potplotz(anz,arrz,arrzpot);
//EXPORT Data1DPlotArray potplotfitz(anz,arrz,arrzpotfit);
glob(double,dissipationfactor,1000);
glob(double,initialdamptime,0.0001);
glob(double,temperature,0);
glob(bool,displayRad,false);
glob(int,hello_Sam,1);
///////////////////////////////////
struct data3 {
size_t n;
double *x;
double * y;
double * sigma;
};
//import capacitor ramps to fit a voltage model used then in sim
//double fit_val[cnt_eltype][cnt_axis][cnt_fit];
//double xslope[1000000];
//double yslope[1000000];
//EXPORT Data1DPlotArray slope(1000000,xslope,yslope);
//double yslopefit[1000000];
//EXPORT Data1DPlotArray slopefit(1000000,xslope,yslopefit);
//glob(double,fittedoffset,0);
//glob(double,fittedamp,0);
//glob(double,fittedtau,0);
//glob(double,fittedt0,0);
glob(string,runname,"");
glob(string,name,"");
int cntGlobal=0;
//const double tau=7.1e-9; //Lebensdauer
glob(double, tau,7.1e-9);
double gamma=1/(2*PI*tau);
EXPORT void setTau(){
gamma=1/(2*PI*tau);
}
EXPORT void getTau(){
double tautemp=7.2*0.000000001;
cout<<"tau "<<tautemp<<endl;
tauSet(tautemp);
setTau();
}
glob(double,detune,-1.e7); //Verstimmung kühllaser
glob(double,sat,5);//=I/I0
EXPORT double setGammaHalf(){
//detuneSet(-2e8);
detuneSet(-gamma/2);
satSet(5);
return gamma/2;
}
glob(double,rfamp,0);
glob(bool,laseron,true);
glob(bool,laserTrap,false);
glob(bool,dosim,true);
glob(double,startiondist,4.8e-5);
glob(double,startionasym,0.00247);
glob(double,startionshift,7e-7);
glob(int,simsteps,10);
glob(bool,displayiontrap,false);
glob(double,endzeit,0.003);
glob(int,loopanz,100);
int filenum=0;
glob(bool,scatterEvent,true);
glob(bool,useSimSingle,false);
glob(double, reduceAmp, 1.);
glob(int,cyclePts,50);
double cycleArray[50];
double *cycleRadPlot=cycleArray;
double *OmegaRadPlot=cycleArray;
glob(double,freezing,0.99999);
glob(bool, stochKickGlob, true);
glob(bool, doThermalKick, true);
glob(bool, gib_a_aus,false);
glob(bool, verlet, false);
glob(bool,doRMS, false);
glob(double, angle, 11.);
glob(double,Uz,0.16);
glob(double,zOffset,0); //Center of trap along z axis
glob(double,kicktime,0.);
glob(bool,HeatEngine,false);
double static x0=1.0*0.001; //Distance rods to trap center
double static z0=4.0*0.001; //Distance endcaps to trap center
#define CPUCNT 8
int ionplotcntmax;
int ionplotcnt[CPUCNT]={};
#define ionplotanz 100000 //100000 geht, bei 1000000 stürzt er ab beim allokieren des pseichers fürs zweite positionsarray
//double tttt[CPUCNT][ionplotanz];
//double yyyy[3][CPUCNT][maxionanz][ionplotanz];
template<class T,int dim> T*makearrayPos(){
try{
return new T[dim];
}
catch (exception& e)
{
cout << "Standard exception in file: "<<__FILE__<<" at line "<< __LINE__<<" function: "<<__FUNCTION__<<" problem: "<< e.what() << endl;
}
}
template<class T,int dim> T*makearrayVel(){
try{
return new T[dim];
}
catch (exception& e)
{
cout << "Standard exception in file: "<<__FILE__<<" at line "<< __LINE__<<" function: "<<__FUNCTION__<<" problem: "<< e.what() << endl;
}
}
template<class T,int dim> T*makearrayTime(){
try{
return new T[dim];
}
catch (exception& e)
{
cout << "Standard exception in file: "<<__FILE__<<" at line "<< __LINE__<<" function: "<<__FUNCTION__<<" problem: "<< e.what() << endl;
}
}
typedef double testtyp[CPUCNT][maxionanz][ionplotanz];
typedef double Tpos[CPUCNT][maxionanz][ionplotanz];
typedef double Tvel[CPUCNT][maxionanz][ionplotanz];
typedef double Ttime[ionplotanz];
Tpos *yyyy=0;//=makearrayPos<Tpos,3>();//--> in function
Tvel *vvvv=0;//=makearrayPos<Tpos,3>();
Ttime *tttt=0;//=makearrayTime<Ttime,CPUCNT>();//--> in function
//delete[] test;
//EXPORT void printptr(){
// try{
// test=new double[3][CPUCNT][maxionanz][ionplotanz];
// }
// catch (exception& e)
// {
// cout << "Standard exception in file: "<<__FILE__<<" at line "<< __LINE__<<" function: "<<__FUNCTION__<<" problem: "<< e.what() << endl;
// }
//}
int dummyLength=10;
double dummyX[10];
double dummyY[10];
//double vvvv[3][CPUCNT][maxionanz][ionplotanz];
double ERad[CPUCNT][maxionanz][ionplotanz];
double ETotal[CPUCNT][maxionanz][ionplotanz];
double ERadMean[maxionanz][ionplotanz];
double ETotMean[maxionanz][ionplotanz];
double yyyyMean[3][maxionanz][ionplotanz];
double HCAmpPlot[ionplotanz];
EXPORT Data1DPlotArray plot1(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot2(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot3(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot4(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot5(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot6(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot7(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot8(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot9(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot10(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot11(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot12(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot13(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot14(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot15(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot16(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot17(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plot18(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotVoltage(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotHC(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotMeanX(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotMeanY(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotMeanZ(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotERad(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotETotal(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray cyclePlot(cyclePts,OmegaRadPlot,cycleRadPlot);
EXPORT Data1DPlotArray plotX1(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotX2(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotX3(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotX4(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotX5(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotX6(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotX7(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotY1(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotY2(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotY3(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotY4(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotY5(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotY6(dummyLength,dummyX, dummyY);
EXPORT Data1DPlotArray plotY7(dummyLength,dummyX, dummyY);
double scatterprob[ionplotanz]={};
boost::mutex incmutex;
int incfilenum(){
boost::mutex::scoped_lock scoped_lock(incmutex);
int n;
filenum++;
n=filenum;
return n;
}
class semaphore
{
//The current semaphore count.
unsigned int count_;
//mutex_ protects count_.
//Any code that reads or writes the count_ data must hold a lock on
//the mutex.
//Code that increments count_ must notify the condition variable.
boost::condition_variable condition_;
public:
boost::mutex mutex_;
explicit semaphore(unsigned int initial_count)
: count_(initial_count),
mutex_(),
condition_()
{
}
void init(int i){count_=i;}
unsigned int get_count() //for debugging/testing only
{
//The "lock" object locks the mutex when it's constructed,
//and unlocks it when it's destroyed.
boost::unique_lock<boost::mutex> lock(mutex_);
return count_;
}
void enter() //called "release" in Java
{
boost::unique_lock<boost::mutex> lock(mutex_);
++count_;
//Wake up any waiting threads.
//Always do this, even if count_ wasn't 0 on entry.
//Otherwise, we might not wake up enough waiting threads if we
//get a number of signal() calls in a row.
condition_.notify_all();
}
void signal() //called "release" in Java
{
boost::unique_lock<boost::mutex> lock(mutex_);
--count_;
//Wake up any waiting threads.
//Always do this, even if count_ wasn't 0 on entry.
//Otherwise, we might not wake up enough waiting threads if we
//get a number of signal() calls in a row.
condition_.notify_all();
}
void wait() //called "acquire" in Java
{
boost::unique_lock<boost::mutex> lock(mutex_);
while (count_ != 0)
{
condition_.wait(lock);
}
}
};
// This is a typedef for a random number generator.
// Try boost::mt19937 or boost::ecuyer1988 instead of boost::minstd_rand
typedef boost::minstd_rand base_generator_type;
base_generator_type generator(std::time(0));
int displaysim=0;
EXPORT void displaysimset(int i){
if(i<=0) return;
if(i>CPUCNT) return;
displaysim=i;
i--;
switch(numIons){
/*case 18:
plot18.setData(tttt[i],yyyy[2][i][17]);
plot18.setNum(ionplotcnt[i]);
plot18.update();
case 17:
plot17.setData(tttt[i],yyyy[2][i][16]);
plot17.setNum(ionplotcnt[i]);
plot17.update();
case 16:
plot16.setData(tttt[i],yyyy[2][i][15]);
plot16.setNum(ionplotcnt[i]);
plot16.update();
case 15:
plot15.setData(tttt[i],yyyy[2][i][14]);
plot15.setNum(ionplotcnt[i]);
plot15.update();
case 14:
plot14.setData(tttt[i],yyyy[2][i][13]);
plot14.setNum(ionplotcnt[i]);
plot14.update();
case 13:
plot13.setData(tttt[i],yyyy[2][i][12]);
plot13.setNum(ionplotcnt[i]);
plot13.update();
case 12:
plot12.setData(tttt[i],yyyy[2][i][11]);
plot12.setNum(ionplotcnt[i]);
plot12.update();
case 11:
plot11.setData(tttt[i],yyyy[2][i][10]);
plot11.setNum(ionplotcnt[i]);
plot11.update();
case 10:
plot10.setData(tttt[i],yyyy[2][i][9]);
plot10.setNum(ionplotcnt[i]);
plot10.update();
case 9:
plot9.setData(tttt[i],yyyy[2][i][8]);
plot9.setNum(ionplotcnt[i]);
plot9.update();
case 8:
plot8.setData(tttt[i],yyyy[2][i][7]);
plot8.setNum(ionplotcnt[i]);
plot8.update();
case 7:
plot7.setData(tttt[i],yyyy[2][i][6]);
plot7.setNum(ionplotcnt[i]);
plot7.update();
case 6:
plot6.setData(tttt[i],yyyy[2][i][5]);
plot6.setNum(ionplotcnt[i]);
plot6.update();
case 5:
plot5.setData(tttt[i],yyyy[2][i][4]);
plot5.setNum(ionplotcnt[i]);
plot5.update();
case 4:
plot4.setData(tttt[i],yyyy[2][i][3]);
plot4.setNum(ionplotcnt[i]);
plot4.update();*/
case 3:
plot3.setData(tttt[i],yyyy[2][i][2]);
plot3.setNum(ionplotcnt[i]);
plot3.update();
case 2:
plot2.setData(tttt[i],yyyy[2][i][1]);
plot2.setNum(ionplotcnt[i]);
plot2.update();
case 1:
plot1.setData(tttt[i],yyyy[2][i][0]);
plot1.setNum(ionplotcnt[i]);
plot1.update();
default: break;
}
switch(numIons){
/*case 7:
plotX7.setData(tttt[i],yyyy[0][i][6]);
plotX7.setNum(ionplotcnt[0]);
plotX7.update();
case 6:
plotX6.setData(tttt[i],yyyy[0][i][5]);
plotX6.setNum(ionplotcnt[0]);
plotX6.update();
case 5:
plotX5.setData(tttt[i],yyyy[0][i][4]);
plotX5.setNum(ionplotcnt[0]);
plotX5.update();
case 4:
plotX4.setData(tttt[i],yyyy[0][i][3]);
plotX4.setNum(ionplotcnt[0]);
plotX4.update();*/
case 3:
plotX3.setData(tttt[i],yyyy[0][i][2]);
plotX3.setNum(ionplotcnt[0]);
plotX3.update();
case 2:
plotX2.setData(tttt[i],yyyy[0][i][1]);
plotX2.setNum(ionplotcnt[0]);
plotX2.update();
case 1:
plotX1.setData(tttt[i],yyyy[0][i][0]);
plotX1.setNum(ionplotcnt[0]);
plotX1.update();
default: break;
}
switch(numIons){
/*case 7:
plotY7.setData(tttt[i],yyyy[1][i][6]);
plotY7.setNum(ionplotcnt[0]);
plotY7.update();
case 6:
plotY6.setData(tttt[i],yyyy[1][i][5]);
plotY6.setNum(ionplotcnt[0]);
plotY6.update();
case 5:
plotY5.setData(tttt[i],yyyy[1][i][4]);
plotY5.setNum(ionplotcnt[0]);
plotY5.update();
case 4:
plotY4.setData(tttt[i],yyyy[1][i][3]);
plotY4.setNum(ionplotcnt[0]);
plotY4.update();*/
case 3:
plotY3.setData(tttt[i],yyyy[1][i][2]);
plotY3.setNum(ionplotcnt[0]);
plotY3.update();
case 2:
plotY2.setData(tttt[i],yyyy[1][i][1]);
plotY2.setNum(ionplotcnt[0]);
plotY2.update();
case 1:
plotY1.setData(tttt[i],yyyy[1][i][0]);
plotY1.setNum(ionplotcnt[0]);
plotY1.update();
default: break;
}
plotHC.setData(tttt[i],HCAmpPlot);
plotHC.setNum(ionplotcnt[0]);
plotHC.update();
//if(displayiontrap) IonTrapDisplay.update();
}
glob(bool,dotrapfreq,false);
glob(double,t0glob,0.002);
EXPORT void clearPlot(){
if(yyyy==0){
yyyy=makearrayPos<Tpos,3>();cout<<"yyyy"<<endl;
vvvv=makearrayVel<Tvel,3>();cout<<"vvvv"<<endl;
tttt=makearrayTime<Ttime,CPUCNT>();cout<<"tttt"<<endl;
}
for(int i=0;i<maxionanz;i++){
for(int n=0;n<CPUCNT;n++){
ionplotcnt[n]=0;
for(int j=0;j<ionplotanz;j++){
for (int dim=0;dim<3;dim++){
yyyy[dim][n][i][j]=0;
vvvv[dim][n][i][j]=0;
yyyyMean[dim][i][j]=0;
tttt[n][j]=0;
HCAmpPlot[j]=0;
}
}
}
}
switch(maxionanz){
case 18:
plot18.setData(tttt[0],yyyy[2][0][17]);
plot18.setNum(ionplotcnt[0]);
plot18.update();
case 17:
plot17.setData(tttt[0],yyyy[2][0][16]);
plot17.setNum(ionplotcnt[0]);
plot17.update();
case 16:
plot16.setData(tttt[0],yyyy[2][0][15]);
plot16.setNum(ionplotcnt[0]);
plot16.update();
case 15:
plot15.setData(tttt[0],yyyy[2][0][14]);
plot15.setNum(ionplotcnt[0]);
plot15.update();
case 14:
plot14.setData(tttt[0],yyyy[2][0][13]);
plot14.setNum(ionplotcnt[0]);
plot14.update();
case 13:
plot13.setData(tttt[0],yyyy[2][0][12]);
plot13.setNum(ionplotcnt[0]);
plot13.update();
case 12:
plot12.setData(tttt[0],yyyy[2][0][11]);
plot12.setNum(ionplotcnt[0]);
plot12.update();
case 11:
plot11.setData(tttt[0],yyyy[2][0][10]);
plot11.setNum(ionplotcnt[0]);
plot11.update();
case 10:
plot10.setData(tttt[0],yyyy[2][0][9]);
plot10.setNum(ionplotcnt[0]);
plot10.update();
case 9:
plot9.setData(tttt[0],yyyy[2][0][8]);
plot9.setNum(ionplotcnt[0]);
plot9.update();
case 8:
plot8.setData(tttt[0],yyyy[2][0][7]);
plot8.setNum(ionplotcnt[0]);
plot8.update();
case 7:
plot7.setData(tttt[0],yyyy[2][0][6]);
plot7.setNum(ionplotcnt[0]);
plot7.update();
case 6:
plot6.setData(tttt[0],yyyy[2][0][5]);
plot6.setNum(ionplotcnt[0]);
plot6.update();
case 5:
plot5.setData(tttt[0],yyyy[2][0][4]);
plot5.setNum(ionplotcnt[0]);
plot5.update();
case 4:
plot4.setData(tttt[0],yyyy[2][0][3]);
plot4.setNum(ionplotcnt[0]);
plot4.update();
case 3:
plot3.setData(tttt[0],yyyy[2][0][2]);
plot3.setNum(ionplotcnt[0]);
plot3.update();
case 2:
plot2.setData(tttt[0],yyyy[2][0][1]);
plot2.setNum(ionplotcnt[0]);
plot2.update();
case 1:
plot1.setData(tttt[0],yyyy[2][0][0]);
plot1.setNum(ionplotcnt[0]);
plot1.update();
default: break;
}
switch(7){
case 7:
plotX7.setData(tttt[0],yyyy[0][0][6]);
plotX7.setNum(ionplotcnt[0]);
plotX7.update();
case 6:
plotX6.setData(tttt[0],yyyy[0][0][5]);
plotX6.setNum(ionplotcnt[0]);
plotX6.update();
case 5:
plotX5.setData(tttt[0],yyyy[0][0][4]);
plotX5.setNum(ionplotcnt[0]);
plotX5.update();
case 4:
plotX4.setData(tttt[0],yyyy[0][0][3]);
plotX4.setNum(ionplotcnt[0]);
plotX4.update();
case 3:
plotX3.setData(tttt[0],yyyy[0][0][2]);
plotX3.setNum(ionplotcnt[0]);
plotX3.update();
case 2:
plotX2.setData(tttt[0],yyyy[0][0][1]);
plotX2.setNum(ionplotcnt[0]);
plotX2.update();
case 1:
plotX1.setData(tttt[0],yyyy[0][0][0]);
plotX1.setNum(ionplotcnt[0]);
plotX1.update();
default: break;
}
switch(7){
case 7:
plotY7.setData(tttt[0],yyyy[1][0][6]);
plotY7.setNum(ionplotcnt[0]);
plotY7.update();
case 6:
plotY6.setData(tttt[0],yyyy[1][0][5]);
plotY6.setNum(ionplotcnt[0]);
plotY6.update();
case 5:
plotY5.setData(tttt[0],yyyy[1][0][4]);
plotY5.setNum(ionplotcnt[0]);
plotY5.update();
case 4:
plotY4.setData(tttt[0],yyyy[1][0][3]);
plotY4.setNum(ionplotcnt[0]);
plotY4.update();
case 3:
plotY3.setData(tttt[0],yyyy[1][0][2]);
plotY3.setNum(ionplotcnt[0]);
plotY3.update();
case 2:
plotY2.setData(tttt[0],yyyy[1][0][1]);
plotY2.setNum(ionplotcnt[0]);
plotY2.update();
case 1:
plotY1.setData(tttt[0],yyyy[1][0][0]);
plotY1.setNum(ionplotcnt[0]);
plotY1.update();
default: break;
}
plotHC.setData(tttt[0],HCAmpPlot);
plotHC.setNum(ionplotcnt[0]);
plotHC.update();
//if(displayiontrap) IonTrapDisplay.update();
}
bool doTestSqueeze=false;
bool TestSqueezeDone[CPUCNT];
bool phaseScrambleDone[CPUCNT];
glob(double, squeezing, 0.);
glob(bool, doSqueeze, false);
double trand[CPUCNT];
bool restarted[CPUCNT];
bool HotLaserOn[CPUCNT];
bool ColdLaserOn[CPUCNT];
int noiseFunction;
double noiseParam[3];
double noiseRF[CPUCNT];
Kibblesim::Kibblesim():simnum(simnum){
static int simcnt=0;
simcnt++;
simnum=simcnt;
//initSim(); //Das darf hier nicht stehen, sonst schmiewrt alles ab. Konstruktor wird vor der GUI ausgeführt.
//Daher werden alle Globs mit ihren startwerten und nicht mit den Werten der Gui gesetzt.
//Dies kann zu Problemen führen!!!
}
Kibblesim::~Kibblesim(){}
glob(double, OmegaRes, 2914262.4);
glob(double, epsilon, 1.);
glob(bool,doStepSqueeze,false);
double rfMod[CPUCNT];
int Kibblesim::Signum(double zahl){
if(zahl>0.)return 1;
if(zahl<0.)return -1;
if(zahl==0.)return 0;
}
int Signum2(double zahl){
if(zahl>0.)return 1;
if(zahl<0.)return -1;
if(zahl==0.)return 0;
}
double Kibblesim::RandomReal(double min, double max){
// Define a uniform random number distribution which produces "double"
// values between 0 and 1 (0 inclusive, 1 exclusive).
boost::uniform_real<> uni_dist(min,max);
boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni(generator, uni_dist);
std::cout.setf(std::ios::fixed);
// calling the generator as a zero-argument function.
return uni();
}
double Kibblesim::RandomGauss(double mean, double sigma){
// Define a uniform random number distribution which produces "double"
// values between 0 and 1 (0 inclusive, 1 exclusive).
boost::normal_distribution<> norm_dist(mean,sigma);
boost::variate_generator<base_generator_type&, boost::normal_distribution<> > norma(generator, norm_dist);
return norma();
}
double Kibblesim::RandomExp(double tau){
// Define a uniform random number distribution which produces "double"
// values between 0 and 1 (0 inclusive, 1 exclusive).
boost::exponential_distribution<> exp_dist(tau);
boost::variate_generator<base_generator_type&, boost::exponential_distribution<> > expo(generator, exp_dist);
return expo();
}
glob(bool,phaseScramble,false);
void Kibblesim::PhaseScramble(double v[maxionanz][3], double x[maxionanz][3], double a[maxionanz][3]){
if(phaseScrambleDone[simnum-1]==false && ColdLaserOn[simnum-1]==false){
phaseScrambleDone[simnum-1]=true;
double EScr[maxionanz][3]={};
for(int i=0;i<numIons;i++){
EScr[i][0]=(x[i][0]*x[i][0])*( 2*pi*(x[i][2]*(-2241983470.)+2969444.))*( 2*pi*(x[i][2]*(-2241983470.)+2969444.)) + (v[i][0]*v[i][0]);
EScr[i][1]=(x[i][1]*x[i][1])*( 2*pi*(x[i][2]*(-2241983470.)+2969444.))*( 2*pi*(x[i][2]*(-2241983470.)+2969444.)) + (v[i][1]*v[i][1]);
cout<<EScr[i][0]<<"\t"<<x[i][0]*( 2*pi*(x[i][2]*(-2241983470.)+2969444.))<<"\t"<<v[i][0]<<"\t/\t";
v[i][0]=RandomReal(-sqrt(EScr[i][0]),sqrt(EScr[i][0]));
x[i][0]=Signum(RandomReal(-1,1))*sqrt(EScr[i][0]-(v[i][0]*v[i][0]))/(2*pi*(x[i][2]*(-2241983470.)+2969444.));
v[i][1]=RandomReal(-sqrt(EScr[i][1]),sqrt(EScr[i][1]));
x[i][1]=Signum(RandomReal(-1,1))*sqrt(EScr[i][1]-(v[i][1]*v[i][1]))/(2*pi*(x[i][2]*(-2241983470.)+2969444.));
//randX=RandomReal(0,pi/2);
//randY=RandomReal(0,pi/2);
//v[i][0]=Signum(RandomReal(-1,1))*sqrt(EScr[i][0]*sin(randX));
//v[i][1]=Signum(RandomReal(-1,1))*sqrt(EScr[i][1]*sin(randY));
//x[i][0]=Signum(RandomReal(-1,1))*sqrt(EScr[i][0]/((2*pi*(x[i][2]*(-2241983470.)+2969444.))*( 2*pi*(x[i][2]*(-2241983470.)+2969444.)))*cos(randX));
//x[i][1]=Signum(RandomReal(-1,1))*sqrt(EScr[i][1]/((2*pi*(x[i][2]*(-2241983470.)+2969444.))*( 2*pi*(x[i][2]*(-2241983470.)+2969444.)))*cos(randY));
a[i][0]=0;
a[i][1]=0;
a[i][2]=0;
//cout<<x[i][0]*( 2*pi*(x[i][2]*(-2241983470.)+2969444.))<<"\t"<<v[i][0]<<endl;
cout<<(x[i][0]*x[i][0])*( 2*pi*(x[i][2]*(-2241983470.)+2969444.))*( 2*pi*(x[i][2]*(-2241983470.)+2969444.)) + (v[i][0]*v[i][0])<<endl;
}
}
}
//double Voltage[ionplotanz];
void Kibblesim::StepSqueeze(double v[maxionanz][3],double v12[maxionanz][3],double x[maxionanz][3],double t,double h){
if((t>endzeit/2.) && (t<endzeit*2./3.)){
if( Signum(sin(2.*2.*pi*OmegaRes*t)) < Signum(sin(2.*2.*pi*OmegaRes*(t-h))) ){
rfMod[simnum-1]=epsilon;
//cout<<"bum"<<endl;
/*if(simnum-1==0)Voltage[*/
}
if( Signum(sin(2.*2.*pi*OmegaRes*t)) > Signum(sin(2.*2.*pi*OmegaRes*(t-h))) ){
rfMod[simnum-1]=1;
}
//if( Signum(sin(OmegaRes*t)) != Signum(sin(OmegaRes*(t-h))) ){ //macht 2 Omega!!!!
// for(int ion=0;ion<numIons;ion++){
// for(int dim=0;dim<3;dim++){
// v[ion][dim]=epsilon*v[ion][dim];
// v12[ion][dim]=epsilon*v12[ion][dim];
// x[ion][dim]=x[ion][dim]/epsilon;
// }
// }
//}
}
}
void Kibblesim::TestSqueezeKick(double v[maxionanz][3],double v12[maxionanz][3],double x[maxionanz][3],double &t,double h){
if(TestSqueezeDone[simnum-1]==false && t>endzeit/3.){
//cout<<"squeeze"<<endl;
for(int ion=0;ion<numIons;ion++){
for(int dim=0;dim<3;dim++){
v[ion][dim]=v[ion][dim]*squeezing;
v12[ion][dim]=v12[ion][dim]*squeezing;
x[ion][dim]=x[ion][dim]/squeezing;
}
}
TestSqueezeDone[simnum-1]=true;
}
if(t>endzeit/2. && t<endzeit*4./5.){
Laser(v12,h,0);
Laser(v12,h,1);
Laser(v12,h,3);
Laser(v12,h,4);
}
/*if(t<endzeit/4){
Laser(v12,h,0);
Laser(v12,h,1);
Laser(v12,h,3);
Laser(v12,h,4);
}*/
}
//glob(double,meanScatteringRate,0);
glob(bool, LaserX1, false);
glob(bool, LaserX2, false);
glob(bool, LaserY1, false);
glob(bool, LaserY2, false);
glob(bool, LaserZ1, false);
glob(bool, LaserZ2, false);
glob(int, PhotonCount,0);
EXPORT void FlipLaser(){
bool steuerBool=false;
steuerBool=LaserX1;
if(LaserX2!=steuerBool || LaserY1!=steuerBool || LaserY2!=steuerBool || LaserZ1!=steuerBool || LaserZ2!=steuerBool){
LaserX1Set(false);
LaserX2Set(false);
LaserY1Set(false);
LaserY2Set(false);
LaserZ1Set(false);
LaserZ2Set(false);
}
else{
LaserX1Set(!LaserX1);
LaserX2Set(!LaserX2);
LaserY1Set(!LaserY1);
LaserY2Set(!LaserY2);
LaserZ1Set(!LaserZ1);
LaserZ2Set(!LaserZ2);
}
}
double satMT[CPUCNT];
double detuneMT[CPUCNT];
double HCAmp[CPUCNT];