-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
2710 lines (2281 loc) · 104 KB
/
Copy pathmainwindow.cpp
File metadata and controls
2710 lines (2281 loc) · 104 KB
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 "mainwindow.h"
#include "ui_mainwindow.h"
#include "myglobalvars.h"
#include <QMessageBox>
#include <QProcess>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QKeyEvent>
#include "calcvals.h"
#include "simulateall.h"
//#ifdef __APPLE__
//#include <carbon/Carbon.h>
//#endif
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//Setting the color schem for the program
QPalette pal = this->palette();
QLinearGradient gradient(0, 0, 400, 400);
gradient.setColorAt(0, QColor(50, 230, 255));
gradient.setColorAt(0.7, QColor(150, 255, 255));
gradient.setColorAt(1, QColor(230, 255, 255));
pal.setBrush(QPalette::Window, QBrush(gradient));
this->setPalette(pal);
runProcess=true;
//Finished setting background
#ifdef __APPLE__
QDir dir = QCoreApplication::applicationDirPath();
dir.cdUp();
rootPath = dir.absolutePath();
PlotPath = documentFolderPath+"/Graphs";
DataPath = documentFolderPath+"/Data";
WSIMPath = rootPath+"/Add-ons";
simEngine = rootPath+"/Simulators";
TempFileName = documentFolderPath+"/Data/ModiNL.cir";
TempOutFile = documentFolderPath+"/Data/TempOut.tmp";
propertiesFile=documentFolderPath+"/properties.stat";
#endif
//Initialization of folders
firstRun_Init();
//setting the timer for interruptions
// myTimer = new QTimer(this);
// myTimer->setInterval(500);
// myTimer->setSingleShot(false);
// connect(myTimer, SIGNAL(timeout()), this, SLOT(timerslot()));
// Create authorization reference
// AuthorizationRef authorizationRef;
// OSStatus status;
// status = AuthorizationCreate(nullptr, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef);
// char* tool = QApplication::instance()->applicationFilePath().toLocal8Bit().data();
// char* args[] = { "STARTUPDATE", nullptr };
// FILE* pipe = nullptr;
// status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
// QApplication::instance()->quit();
// Initialize the values for the input and output files
ui->SaveLineEdit->setText(DataPath+"/Out.dat");
ui->NetlistLineEdit->setText(DataPath+"/JOINUS-test.cir");
ui->frame->close();
ui->TempLineEdit->setEnabled(false);
ui->PlotCheckBox->setEnabled(true);
QString NetlistFile = ui->NetlistLineEdit->text();
ui->PlotCheckBox->setChecked(true);
temperature=4.2;
// Set text editor font
QFont font;
font.setFamily("Courier");
font.setFixedPitch(true);
font.setPointSize(12);
ui->NetlistPlainTextEdit->setFont(font);
font.setFamily("Arial");
font.setPointSize(10);
ui->TerminalPlainTextEdit->setFont(font);
ui->ASWcheckBox->setChecked(true);
ui->ASWcheckBox->setVisible(false);
//ui->StopPushButton->setEnabled(false);
ui->InfoLabel->setText("Initial temperature value : "+QString::number(temperature)+" [K]");
//Connecting stop to start
//connect(ui->StopPushButton, SIGNAL(clicked()), ui->StartPushButton, SLOT(exit()));
//Tests For MacOS
//Displaying data paths
// ui->TerminalPlainTextEdit->appendPlainText("Netlist Path: "+DataPath+"/si.inp");
// ui->TerminalPlainTextEdit->appendPlainText("Output file name: "+dir.currentPath()+OutputFileName);
// ui->TerminalPlainTextEdit->appendPlainText("JSIM Path: "+dir.absolutePath()+"/JSIM");
// Initialize the highlighter for the netlist editor
m_jsimsyntax = new Jsimsyntax(ui->NetlistPlainTextEdit->document());
LoadNetlist(NetlistFile);
}
// Initialization of the folders for all OS
void MainWindow::firstRun_Init()
{
//Creating folders and putting files in them
if (!QDir(documentFolderPath).exists())
{
QDir().mkdir(documentFolderPath);
}
if (!QDir(DataPath).exists())
{
QDir().mkdir(DataPath);
//QFile::copy(":/Data/Data/JoSIM_n",DataPath+"/JoSIM_n");
//QFile::copy(":/Data/Data/jsim_n",DataPath+"/jsim_n");
}
if (!QDir(PlotPath).exists())
{
QDir().mkdir(PlotPath);
}
if (!QDir(WSIMPath).exists())
{
QDir().mkdir(WSIMPath);
}
if (!QDir(simEngine).exists())
{
QDir().mkdir(simEngine);
}
if (!QDir(documentFolderPath+"/Help").exists())
{
QDir().mkdir(documentFolderPath+"/Help");
}
//Checking if it is the first run
if (QDir(rootPath+"/MyResources").exists())
{
QMessageBox::information(this,"Initialization","JOINUS folders and files have been initialized during "
"installation, the JOINUS folder is located in your <i>Documents</i> "
"folder. It should stay there.");
QFile::copy(rootPath+"/MyResources/JOINUS-manual-in-a-nutshell-v2.0.pdf",documentFolderPath+"/Help/JOINUS-manual-in-a-nutshell-v2.0.pdf");
QFile::copy(rootPath+"/MyResources/JoSIM-ReadMe.pdf",documentFolderPath+"/Help/JoSIM-ReadMe.pdf");
QFile::copy(rootPath+"/MyResources/JSIM-manual-v12.0.pdf",documentFolderPath+"/Help/JSIM-manual-v12.0.pdf");
#ifdef __APPLE__
//Moving engines here
QFile::copy(rootPath+"/MyResources/jsim_n",simEngine+"/jsim_n");
QFile(simEngine+"/jsim_n").setPermissions(QFile(rootPath+"/MyResources/jsim_n").permissions());
QFile::copy(rootPath+"/MyResources/JoSIM_n",simEngine+"/JoSIM_n");
QFile(simEngine+"/JoSIM_n").setPermissions(QFile(rootPath+"/MyResources/JoSIM_n").permissions());
//Moving Add-ons here
if (QFile(rootPath+"/MyResources/WSIM").exists()){
QFile::copy(rootPath+"/MyResources/WSIM",WSIMPath+"/WSIM");
QFile(simEngine+"/WSIM").setPermissions(QFile(rootPath+"/MyResources/WSIM").permissions());
}
if (QFile(rootPath+"/MyResources/SMP").exists()){
QFile::copy(rootPath+"/MyResources/SMP",WSIMPath+"/SMP");
QFile(simEngine+"/SMP").setPermissions(QFile(rootPath+"/MyResources/SMP").permissions());
}
#elif __linux__
//Moving engines here
QFile::copy(rootPath+"/MyResources/jsim_n",simEngine+"/jsim_n");
QFile(simEngine+"/jsim_n").setPermissions(QFile(rootPath+"/MyResources/jsim_n").permissions());
QFile::copy(rootPath+"/MyResources/JoSIM_n",simEngine+"/JoSIM_n");
QFile(simEngine+"/JoSIM_n").setPermissions(QFile(rootPath+"/MyResources/JoSIM_n").permissions());
//Moving Add-ons here
if (QFile(rootPath+"/MyResources/Add-ons/WSIM").exists()){
QFile::copy(rootPath+"/MyResources/Add-ons/WSIM",WSIMPath+"/WSIM");
QFile(simEngine+"/WSIM").setPermissions(QFile(rootPath+"/MyResources/Add-ons/WSIM").permissions());
}
if (QFile(rootPath+"/MyResources/Add-ons/SMP").exists()){
QFile::copy(rootPath+"/MyResources/Add-ons/SMP",WSIMPath+"/SMP");
QFile(simEngine+"/SMP").setPermissions(QFile(rootPath+"/MyResources/Add-ons/SMP").permissions());
}
#elif __WIN32__
//Moving engines here
QFile::copy(rootPath+"/MyResources/jsim_n.exe",simEngine+"/jsim_n.exe");
QFile::copy(rootPath+"/MyResources/JoSIM_n.exe",simEngine+"/JoSIM_n.exe");
//Moving Add-ons here
QDir dir;
if( !dir.rename( rootPath+"/MyResources/Add-ons", rootPath+"/Add-ons" ) ){
QMessageBox::information(this,"Error","Moving Failed. Please move Add-ons manualy.");
}
#endif
if (!QDir(DataPath+"/Demos").exists())
QDir().rename(rootPath+"/MyResources/Demos", DataPath+"/Demos");
}
if (!QFile(DataPath+"/JOINUS-test.cir").exists())
{
QFile::copy(":/Data/Data/si.cir",DataPath+"/JOINUS-test.cir");
QFile(DataPath+"/JOINUS-test.cir").setPermissions(QFileDevice::ReadOwner | QFileDevice::WriteOwner);
}
if (!QFile(DataPath+"/JOINUS-test.png").exists())
QFile::copy(":/image/Data/si.png",DataPath+"/JOINUS-test.png");
//Removing the resourses folder from app pack
QDir dir(rootPath+"/MyResources");
dir.removeRecursively();
ui->TerminalPlainTextEdit->appendPlainText(">> Program directory : "+rootPath);
ui->TerminalPlainTextEdit->appendPlainText(">> Graphs storage directory : "+PlotPath);
ui->TerminalPlainTextEdit->appendPlainText(">> File storage directory : "+DataPath);
ui->TerminalPlainTextEdit->appendPlainText(">> Add-ons directory : "+WSIMPath);
ui->TerminalPlainTextEdit->appendPlainText(">> Simulators native directory : "+simEngine);
//ui->TerminalPlainTextEdit->appendPlainText(TempFileName);
//ui->TerminalPlainTextEdit->appendPlainText(TempOutFile);
//ui->TerminalPlainTextEdit->appendPlainText(propertiesFile);
//ui->TerminalPlainTextEdit->appendPlainText(documentFolderPath+OutputFileName);
}
// *** Main Simulation Function***
// By pushing this button, the netlist would be compiled and based on the user selections,
// the simulation would start.
// You can add new simulation types here!
// Be careful of the global parameters!
void MainWindow::on_StartPushButton_clicked()
{
simulateall *simclass=new simulateall;
runProcess=true;
if (Simindex==4)
TempFileName = documentFolderPath+"/Data/TempNetlistBER.cir";
else if (Simindex==5)
TempFileName = documentFolderPath+"/Data/TempNetlistFreq.cir";
else
TempFileName = documentFolderPath+"/Data/ModiNL.cir";
// ConsoleOutputs gives the outputs and errors of the terminal. In windows it is Command Prompt.
struct ConsoleOutputs simout={"",""};
// SimParams are parameters that are set for the simulation. Full defenition in the header file.
struct SimParams simParams=readSimParams();
CalcVals *calcVal=new CalcVals;
//Statistical analyze of the I-V curve activation
bool IVstatistical = ui->ASWcheckBox->isChecked();
ui->InfoLabel->setText("Initial temperature value : "+QString::number(temperature)+" [K]");
// Testing to see if the entered parameters are legit
bool validData1=true;
bool validData2=true;
validData2=simParams.pointNum.toInt(&validData1)>0;
if (!validData1 || !validData2)
{
QMessageBox::warning(this,"Error!","Number of the points should be positive integer!");
return;
}
// validData2=simParams.tempVal.toDouble(&validData1)>=0;
// if ((!validData1 || !validData2) && Simindex!=3)
// {
// QMessageBox::warning(this,"Error!","Temperature should be real number bigger or equal to zero!");
// return;
// }
if (Simindex==3)
temperature=4.2;
// else
// temperature = simParams.tempVal.toDouble();
int SimulatorIndex=ui->SimComboBox->currentIndex();
bool noise= ui->NoiseCheckBox->isChecked();
QString NetlistFile=ui->NetlistLineEdit->text();
QString BERtempfile=documentFolderPath+"/Data/TempOutputBER.DAT";
QString Freqtempfile=documentFolderPath+"/Data/TempOutputFreq.DAT";
ui->ProgressBar->setValue(0);
// *** new netlist ***
// Make a netlist without comments with changes for temperature and noise made to it
QString mnnerr=simclass->make_new_netlist(noise,NetlistFile,simParams,SimulatorIndex,IVstatistical);
if (mnnerr!="Success"){
QMessageBox::warning(this,"Error!",mnnerr);
return;
}
// set the values for the simulation and give information about it
ui->SimComboBox->setEnabled(false);
ui->TypeComboBox->setEnabled(false);
ui->StartPushButton->setEnabled(false);
//ui->StopPushButton->setEnabled(true);
ui->TerminalPlainTextEdit->appendPlainText("Output file name: "+documentFolderPath+OutputFileName);
ui->TerminalPlainTextEdit->appendPlainText("Column Number: "+QString::number(columNum));
QString noisecond=ui->NoiseCheckBox->isChecked()?"On":"off";
ui->TerminalPlainTextEdit->appendPlainText("Noise Simulation: "+noisecond);
ui->TerminalPlainTextEdit->appendPlainText("Temperature value:"+ QString::number(temperature));
ui->TerminalPlainTextEdit->appendPlainText("Delimator: '"+ delimator+"'");
QString initSubParam=simParams.subParam;
double stepSize=0;
titleVals.clear();
QVector <long> DataIn(simParams.pointNum.toInt());
QVector <long> DataOut(simParams.pointNum.toInt());
switch (Simindex)
{
// Normal time domain simulation
case 0:
ui->ProgressBar->setValue(50);
simout = simclass->simulatenetlist(TempFileName,SimulatorIndex);
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
ui->ProgressBar->setValue(100);
//testing jsim command for MacOS
//ui->TerminalPlainTextEdit->appendPlainText(DataPath+"/jsim_n "+TempFileName);
break;
// I-V simulation results
case 1:
if (IVstatistical)
{
ui->ProgressBar->setValue(20);
//testing the netlist
simout = simclass->simulateivtest(TempFileName,SimulatorIndex,simParams.pointNum.toInt(),simParams.subParam.toInt());
ui->ProgressBar->setValue(40);
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
TempFileName=documentFolderPath+"/Data/TempOut1.tmp";
//make new netlist after statistical analysis
mnnerr=simclass->make_new_netlist(noise,NetlistFile,simParams,SimulatorIndex,2);
if (mnnerr!="Success"){
QMessageBox::warning(this,"Error!",mnnerr);
ui->StartPushButton->setEnabled(true);
//ui->StopPushButton->setEnabled(false);
return;
}
ui->ProgressBar->setValue(50);
//simulate the newly generated netlist from statistical data
simout = simclass->simulateivcurve(TempFileName,SimulatorIndex,simParams.pointNum.toInt(),simParams.subParam.toInt(),IVstatistical);
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
}else{
ui->ProgressBar->setValue(50);
simout = simclass->simulateivcurve(TempFileName,SimulatorIndex,simParams.pointNum.toInt(),simParams.subParam.toInt(),IVstatistical);
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
}
ui->ProgressBar->setValue(100);
columNum=2;
break;
// Parametric shift
case 2:
if (simParams.pointNum.toInt()>1)
stepSize=(calcVal->convertToValues(simParams.maxVal)-
calcVal->convertToValues(simParams.minVal))/(simParams.pointNum.toInt()-1);
for (int simstep=0 ; simstep<simParams.pointNum.toInt() ; simstep++)
{
if (!runProcess)
break;
simParams.subParam=initSubParam+"<*>"+calcVal->convertToUnits(calcVal->convertToValues(simParams.minVal)+simstep*stepSize);
// Change the netlist with the new parameter
TempFileName=documentFolderPath+"/Data/TempOut"+QString::number(simstep)+".tmp";
QString mnnerr=simclass->make_new_netlist(noise,NetlistFile,simParams,SimulatorIndex,IVstatistical);
if (mnnerr!="Success")
QMessageBox::warning(this,"Error!",mnnerr);
else{
simout = simclass->simulatenetlist(TempFileName,SimulatorIndex);
ui->ProgressBar->setValue(100*(simstep+1)/simParams.pointNum.toInt());
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
QString Outtemp=documentFolderPath+"/Data/Tmp"+titleVals.at(simstep*2)+".dat";
QFile::remove(Outtemp);
bool whileLoopLogic=QFile::copy(documentFolderPath+OutputFileName, Outtemp);
while (!whileLoopLogic){}
}
}
break;
//Temperature sweep simulation
case 3:
simParams.subParam="4.2";
if (simParams.pointNum.toInt()>1)
stepSize=(calcVal->convertToValues(simParams.maxVal)-
calcVal->convertToValues(simParams.minVal))/(simParams.pointNum.toInt()-1);
for (int simstep=0 ; simstep<simParams.pointNum.toInt() ; simstep++)
{
if (!runProcess)
break;
temperature=calcVal->convertToValues(simParams.minVal)+simstep*stepSize;
ui->TempLineEdit->setText(QString::number(temperature));
simParams.tempVal=QString::number(temperature);
//Change the netlist with the new parameter
TempFileName=documentFolderPath+"/Data/TempOut"+QString::number(simstep)+".tmp";
QString mnnerr=simclass->make_new_netlist(noise,NetlistFile,simParams,SimulatorIndex,IVstatistical);
if (mnnerr!="Success")
QMessageBox::warning(this,"Error!",mnnerr);
else{
simout = simclass->simulatenetlist(TempFileName,SimulatorIndex);
ui->ProgressBar->setValue(100*(simstep+1)/simParams.pointNum.toInt());
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
QString Outtemp=documentFolderPath+"/Data/Tmp"+QString::number(simstep)+"K.dat";
QFile::remove(Outtemp);
bool whileLoopLogic=QFile::copy(documentFolderPath+OutputFileName, Outtemp);
while (!whileLoopLogic){}
}
}
break;
//Bit error rate calculations
case 4:
if (simParams.pointNum.toInt()>1)
stepSize=(calcVal->convertToValues(simParams.maxVal)-
calcVal->convertToValues(simParams.minVal))/(simParams.pointNum.toInt()-1);
if (QFile::exists(BERtempfile))
QFile::remove(BERtempfile);
for (int simstep=0 ; simstep<simParams.pointNum.toInt() ; simstep++)
{
if (!runProcess)
break;
simParams.subParam=initSubParam+"<*>"+calcVal->convertToUnits(calcVal->convertToValues(simParams.minVal)+simstep*stepSize);
// Change the netlist with the new parameter
QString mnnerr=simclass->make_new_netlist(noise,NetlistFile,simParams,SimulatorIndex,IVstatistical);
if (mnnerr!="Success")
QMessageBox::warning(this,"Error!",mnnerr);
else{
simout=simclass->simulateBER(SimulatorIndex,simParams.tempVal.toFloat(),calcVal->convertToValues(simParams.minVal)+simstep*stepSize);
ui->ProgressBar->setValue(100*(simstep+1)/simParams.pointNum.toInt());
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
}
}
if (QFile::exists(documentFolderPath+OutputFileName))
QFile::remove(documentFolderPath+OutputFileName);
if(QFile::copy(BERtempfile, documentFolderPath+OutputFileName))
QFile::remove(BERtempfile);
else
break;
columNum=2;
break;
//Shift and find maximum frequency
case 5:
if (QFile::exists(Freqtempfile))
QFile::remove(Freqtempfile);
if (simParams.pointNum.toInt()>1){
double minV=Phi0*calcVal->convertToValues(simParams.minVal);
double maxV=Phi0*calcVal->convertToValues(simParams.maxVal);
stepSize=(maxV-minV)/(simParams.pointNum.toInt()-1);
QVector<double> Multiplyers;
QStringList Mulfields;
Mulfields.append(simParams.tempVal.split(","));
for (int mulcntr=0;mulcntr<Mulfields.length();mulcntr++)
Multiplyers.append(Mulfields.at(mulcntr).toDouble());
for (int simstep=0 ; simstep<simParams.pointNum.toInt() ; simstep++)
{
if (!runProcess)
break;
simParams.subParam=initSubParam+"<*>"+calcVal->convertToUnits(minV+simstep*stepSize);
// Change the netlist with the new parameter
QString mnnerr=simclass->make_new_netlist(noise,NetlistFile,simParams,SimulatorIndex,IVstatistical);
if (mnnerr!="Success")
QMessageBox::warning(this,"Error!",mnnerr);
else{
double freqvalforfunc=calcVal->convertToValues(simParams.minVal)+simstep*stepSize/Phi0;
simout=simclass->simulateFreq(SimulatorIndex,Multiplyers,freqvalforfunc);
ui->ProgressBar->setValue(100*(simstep+1)/simParams.pointNum.toInt());
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
}
}
}else{
simParams.subParam=initSubParam+"<*>"+calcVal->convertToUnits(Phi0*calcVal->convertToValues(simParams.minVal));
QVector<double> Multiplyers;
QStringList Mulfields;
Mulfields.append(simParams.tempVal.split(","));
for (int mulcntr=0;mulcntr<Mulfields.length();mulcntr++)
Multiplyers[mulcntr]=Mulfields.at(mulcntr).toDouble();
// Change the netlist with the new parameter
QString mnnerr=simclass->make_new_netlist(noise,NetlistFile,simParams,SimulatorIndex,IVstatistical);
if (mnnerr!="Success")
QMessageBox::warning(this,"Error!",mnnerr);
else{
simout=simclass->simulateFreq(SimulatorIndex,Multiplyers,calcVal->convertToValues(simParams.minVal));
ui->ProgressBar->setValue(100);
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
}
}
if (QFile::exists(documentFolderPath+OutputFileName))
QFile::remove(documentFolderPath+OutputFileName);
if(QFile::copy(Freqtempfile, documentFolderPath+OutputFileName))
QFile::remove(Freqtempfile);
else
break;
break;
//New I-V calculation method
case 6:
ui->ProgressBar->setValue(50);
simout = simclass->simulateivnew(TempFileName,SimulatorIndex,simParams.pointNum.toInt());
ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolErr);
//ui->TerminalPlainTextEdit->appendPlainText(simout.ConsolOut);
ui->ProgressBar->setValue(100);
columNum=2;
break;
default:
ui->statusBar->showMessage("The simulation type is not valid!");
break;
}
ui->SimComboBox->setEnabled(true);
ui->TypeComboBox->setEnabled(true);
if (ui->SaveCheckBox->isChecked()==true)
{
if (Simindex==2)
{
//copying all the files in series to the output for parameter shift
for (int simstep=0 ; simstep<simParams.pointNum.toInt() ; simstep++)
{
QString Outtemp=documentFolderPath+"/Data/Tmp"+titleVals.at(simstep*2)+".dat";
QFileInfo fi(ui->SaveLineEdit->text());
fi.completeSuffix();
QString seriesOutFile=fi.absolutePath()+"/"+fi.fileName().remove(fi.completeSuffix(),Qt::CaseInsensitive)
+QString::number(simstep)+fi.completeSuffix();
Copy_File(seriesOutFile,Outtemp);
}
}else if (Simindex==3)
{
//copying all the files in series to the output for temperature shift
for (int simstep=0 ; simstep<simParams.pointNum.toInt() ; simstep++)
{
QString Outtemp=documentFolderPath+"/Data/Tmp"+QString::number(simstep)+"K.dat";
QFileInfo fi(ui->SaveLineEdit->text());
fi.completeSuffix();
QString seriesOutFile=fi.absolutePath()+"/"+fi.fileName().remove(fi.completeSuffix(),Qt::CaseInsensitive)
+QString::number(simstep)+fi.completeSuffix();
Copy_File(seriesOutFile,Outtemp);
}
}
else
Copy_File(ui->SaveLineEdit->text(),documentFolderPath+OutputFileName);
}
// Testing the Legends value,
for (int legendcntr=0;legendcntr<Legends.length();legendcntr++)
{
ui->TerminalPlainTextEdit->appendPlainText("Data "+QString::number(legendcntr)+" : "+Legends.at(legendcntr));
}
if (ui->PlotCheckBox->isChecked()==true)
plotNetlist();
ui->StartPushButton->setEnabled(true);
//ui->StopPushButton->setEnabled(false);
}
void MainWindow::on_actionAbout_triggered()
{
QMessageBox::about(this,"About JOINUS","JOINUS is developed by S. R. in France as part of the ColdFlux/Supertools project.");
}
// Load the netlist file and copies it to the Plain text editor
void MainWindow::on_NetlistToolButton_clicked()
{
QString NetlistFile = QFileDialog::getOpenFileName(this, tr("Open Netlist File..."),documentFolderPath, tr("Netlist files (*.cir);;Other netlist files (*.js *.inp);;All files (*)"));
if (!NetlistFile.isEmpty())
{
ui->NetlistLineEdit->setText(NetlistFile);
LoadNetlist(NetlistFile);
}
}
//Calls Folder Dialog for determination of the output path
void MainWindow::on_SaveToolButton_clicked()
{
QString dirFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"$(pwd)",QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
if (!dirFolder.isEmpty())
{
ui->SaveLineEdit->setText(dirFolder+OutputFileName);
}
}
// Ploting the output file
//Based on the user choice, one fo the programs will be called to the output
void MainWindow::plotNetlist()
{
int comboIndexVal= ui->PlotComboBox->currentIndex();
ui->PlotComboBox->setEnabled(false);
switch(comboIndexVal){
case 0:
dialogPlot = new DialogPlot(this);
dialogPlot->show();
break;
case 1:
GNUplot();
break;
case 2:
XMGracePlot();
break;
default:
ui->statusBar->showMessage("The Plot selection out of reach!");
}
ui->PlotComboBox->setEnabled(true);
}
//Calls the GNUPLot program for graph generation from the output
void MainWindow::GNUplot()
{
QProcess *process=new QProcess(this);
ui->statusBar->showMessage("GNUplot running");
QString OutFile=documentFolderPath+OutputFileName;
QString Commandlines="\"set terminal png;"
"set title 'JSIM Plot';"
"set xlabel 'Time(s)';"
"set ylabel 'Output';"
"set style data lines;"
"plot "+OutFile+";\" >"+PlotPath+"/out.png";
#ifdef __linux__
QString plotcommand="gnuplot -e "+Commandlines;
process->start("/bin/sh", QStringList() << "-c" << plotcommand);
process->waitForFinished(-1); // will wait forever until finished
#elif _WIN32
process->setProgram("gnuplot.exe");
process->setArguments({"-e", Commandlines});
process->setCreateProcessArgumentsModifier([] (
QProcess::CreateProcessArguments *args) {
args->flags &= CREATE_NO_WINDOW;});
process->startDetached();
#else
QString plotcommand="gnuplot -e "+Commandlines;
process->start("/bin/sh", QStringList() << "-c" << plotcommand);
process->waitForFinished(-1); // will wait forever until finished
#endif
//QString OSname=QSysInfo::productType();
// if (OSname=="windows"){
// process.setProgram("gnuplot.exe");
// process.setArguments({"-e", Commandlines});
// process.setCreateProcessArgumentsModifier([] (
// QProcess::CreateProcessArguments *args) {
// args->flags &= CREATE_NO_WINDOW;});
// process.startDetached();
// }
// else{
// QString plotcommand="gnuplot -e "+Commandlines;
// process.start("/bin/sh", QStringList() << "-c" << plotcommand);
// process.waitForFinished(-1); // will wait forever until finished
// }
QString plotstderr = process->readAllStandardError();
ui->statusBar->showMessage(plotstderr);
QString plotstdout = process->readAllStandardOutput();
ui->TerminalPlainTextEdit->appendPlainText(plotstdout);
}
//Calls the XMGrace program for graph generation from the output
void MainWindow::XMGracePlot()
{
QProcess *process=new QProcess(this);
ui->statusBar->showMessage("XMGrace running");
QString OutFile=documentFolderPath+OutputFileName;
QString Commandlines="-nxy "+OutFile+" -legend load";
//QString OSname=QSysInfo::productType();
#ifdef __linux__
QString plotcommand="xmgrace "+Commandlines;
process->start("/bin/sh", QStringList() << "-c" << plotcommand);
process->waitForFinished(-1); // will wait forever until finished
#elif _WIN32
process->setProgram("qtgrace.exe");
process->setArguments({Commandlines});
process->setCreateProcessArgumentsModifier([] (
QProcess::CreateProcessArguments *args) {
args->flags &= CREATE_NO_WINDOW;});
process->startDetached();
#else
QString plotcommand="xmgrace "+Commandlines;
process->start("/bin/sh", QStringList() << "-c" << plotcommand);
process->waitForFinished(-1); // will wait forever until finished
#endif
// if (OSname=="windows"){
// process.setProgram("qtgrace.exe");
// process.setArguments({Commandlines});
// process.setCreateProcessArgumentsModifier([] (
// QProcess::CreateProcessArguments *args) {
// args->flags &= CREATE_NO_WINDOW;});
// process.startDetached();
// }
// else{
// QString plotcommand="xmgrace "+Commandlines;
// process.start("/bin/sh", QStringList() << "-c" << plotcommand);
// process.waitForFinished(-1); // will wait forever until finished
// }
QString plotstderr = process->readAllStandardError();
ui->statusBar->showMessage(plotstderr);
QString plotstdout = process->readAllStandardOutput();
ui->TerminalPlainTextEdit->appendPlainText(plotstdout);
}
// Load the netlist file and copies it to the Plain text editor
void MainWindow::LoadNetlist(QString NetlistFile)
{
QFile file(NetlistFile);
if (!file.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning(this,"Error!",file.errorString());
}
QByteArray dataNetlist = file.readAll();
ui->NetlistPlainTextEdit->setPlainText(dataNetlist);
file.close();
//Set the image for start
QFileInfo fi(NetlistFile);
QString PicFileName=fi.absolutePath()+"/"+fi.fileName().remove(fi.completeSuffix(),Qt::CaseInsensitive)
+"png";
//ui->TerminalPlainTextEdit->appendPlainText(PicFileName);
QPixmap pix;
//QScrollArea *scrollArea=new QScrollArea(this);
//ui->lblNetlistPic->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
//ui->scrollArea->setBackgroundRole(QPalette::Dark);
//ui->scrollArea->setWidget(ui->lblNetlistPic);
//scrollArea->setVisible(false);
ui->lblNetlistPic->setScaledContents(true);
ui->lblNetlistPic->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred);
ui->lblNetlistPic->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
if (pix.load(PicFileName)){
//pix = pix.scaled(ui->lblNetlistPic->size());
ui->lblNetlistPic->setPixmap(pix);
}
else
{
pix.load(":/image/Image/actions/cancel.png");
//pix = pix.scaled(ui->lblNetlistPic->size());
ui->lblNetlistPic->setPixmap(pix);
}
}
//Opens and closes the frame for the parameter editor on changing the type of simulation
//Sets Global variable for the simulation type
void MainWindow::on_TypeComboBox_currentIndexChanged(int index)
{
//Make a table to set the Simindex to the write value:
switch (index)
{
case 0:
//Time domain calculation
Simindex=0;
break;
case 1:
//Parametric Analysis
Simindex=2;
break;
case 2:
//Temperatures Analysis
Simindex=3;
break;
case 3:
//BER
Simindex=4;
break;
case 4:
//Frequency Analysis
Simindex=5;
break;
case 5:
//I-V slow
Simindex=1;
break;
case 6:
//I-V fast
Simindex=6;
break;
default:
Simindex=0;
break;
}
switch (Simindex)
{
case 0:
ui->frame->hide();
ui->ASWcheckBox->setVisible(false);
QMessageBox::information(this,"Time domain simulation","This is the standard default mode of simulation. "
"JOINUS calls the chosen Josephson digital simulator to simulate the netlist chosen in the Netlist file"
" field and displays results in the console and on a plotter window if the Plot results checkbox is ticked. "
"Noise is added to resistances if they Include noise checkbox is ticked. ");
break;
case 1:
ui->frame->show();
ui->label_7->setText("Number of steps");
ui->label_8->setText("Temperature [K]");
ui->label_9->setText("Minimum current [A]");
ui->label_10->setText("Maximum current [A]");
ui->label_11->setText("Current source");
ui->ParamLineEdit->setEnabled(true);
ui->ASWcheckBox->setVisible(true);
ui->TempLineEdit->setEnabled(false);
ui->label_12->setText("Number of cycles");
ui->ParamLineEdit->setText("I0");
ui->SubParamLineEdit->setText("1");
ui->MinValLineEdit->setText("-1m");
ui->MaxValLineEdit->setText("1m");
ui->StepLineEdit->setText("100");
ui->TempLineEdit->setText(QString::number(temperature));
ui->SubParamLineEdit->setEnabled(true);
ui->label_12->show();
QMessageBox::information(this,"I-V characteristics (accurate)","This is the accuarate method for I-V curve calculation.\n"
"JOINUS uses the first output of the netlist as Current (Y-axis) and the second output as Voltage (X-axis) and plot them versus each other.\n"
"The parameters that you must enter are :\n"
"- Current source : the current source name. (Ex. I0)\n"
"- Maximum and Minimum current : the boundary values for the current.\n"
"- Number of steps : the number of points per cycle for the accurate algorithm.\n"
"- Number of cycles : the number of cycles (number of times the current is swept between its boundary values).\n"
"If the Adaptive step width option is active, the program will use adaptive time step sizes. This option is slower but it is "
"useful when there is noise present.");//(or the averaging window size for the fast algorithm)
break;
case 2:
ui->frame->show();
ui->ParamLineEdit->setEnabled(true);
ui->label_7->setText("Number of steps");
ui->label_8->setText("Temperature [K]");
ui->label_9->setText("Minimum");
ui->label_10->setText("Maximum");
ui->label_11->setText("Parameter name");
ui->label_12->setText("Sub-parameter name");
ui->SubParamLineEdit->setEnabled(true);
ui->ASWcheckBox->setVisible(false);
ui->TempLineEdit->setEnabled(false);
ui->ParamLineEdit->setText("VBias");
ui->SubParamLineEdit->setText("2.5mv");
ui->MinValLineEdit->setText("1m");
ui->MaxValLineEdit->setText("5m");
ui->StepLineEdit->setText("5");
ui->TempLineEdit->setText(QString::number(temperature));
QMessageBox::information(this,"Parameter analysis","The parametric analysis allows to choose a netlist parameter to sweep it across a specified range.\n "
"The parameter name, nominal parameter value in the netlist, boundary values and number of steps within the range must be entered on the front panel.\n"
"For Example if the parameter is the frequency of current source I1, \"Parameter name\" would be \"I1\", \"Sub-parameter name\" would be \"200GHz\""
", the boundries would be from \"100G\"Hz to \"500G\"Hz and the number of simulation steps are \"5\".\n"
"If the JOINUS built-in plotter is used it is possible to visualize the evolution of results when "
"the parameter under study is modified by sliding the cursor at the bottom of the graph.");
break;
case 3:
ui->frame->show();
ui->label_7->setText("Number of steps");
ui->label_8->setText("Temperature [K]");
ui->label_9->setText("Minimum temperature");
ui->label_10->setText("Maximum temperature");
ui->label_11->setText(" ");
ui->ParamLineEdit->setEnabled(false);
ui->ASWcheckBox->setVisible(false);
ui->TempLineEdit->setEnabled(false);
ui->label_12->setText(" ");
ui->ParamLineEdit->setText(" ");
ui->SubParamLineEdit->setText(" ");
ui->MinValLineEdit->setText("2");
ui->MaxValLineEdit->setText("7");
ui->StepLineEdit->setText("6");
ui->TempLineEdit->setText(" ");
ui->SubParamLineEdit->setEnabled(false);
QMessageBox::information(this,"Temperature analysis","The temperature analysis mode is a specific type of parametric analysis that involves changes in all elements of the netlist that depend on temperature.\n "
"For this mdoe boundary values and number of steps within the range must be entered on the front panel.\n"
"For example for sweeping temperature between 2K and 7K, with 1K increamenting, there should be 6 steps.\n"
"If the JOINUS built-in plotter is used it is possible to visualize the evolution of results when "
"the temperature under study is modified by sliding the cursor at the bottom of the graph.");
break;
//Continue from here
case 4:
ui->frame->show();
ui->ParamLineEdit->setEnabled(true);
ui->label_7->setText("Number of steps");
ui->label_8->setText("Multiplier");
ui->label_9->setText("Minimum value");
ui->label_10->setText("Maximum value");
ui->label_11->setText("Name of element");
ui->label_12->setText("Nominal value of element");
ui->SubParamLineEdit->setEnabled(true);
ui->ASWcheckBox->setVisible(false);
ui->TempLineEdit->setEnabled(true);
ui->ParamLineEdit->setText("VBias");
ui->SubParamLineEdit->setText("2.5mV");
ui->MinValLineEdit->setText("1m");
ui->MaxValLineEdit->setText("5m");
ui->StepLineEdit->setText("40");
ui->TempLineEdit->setText("2");
QMessageBox::information(this,"Bit Error Rate (BER)","For BER analysis, JOINUS needs:\n"
"- Name of element : the name of the element that is varied, such as \"VBias\".\n"
"- Nominal value of element : the value of the element from the netlist, such as \"2.5mV\".\n"
"- Boundary values : \"Maximum value\" and \"Minimum value\" of the element determines the range that parameter changes.\n"
"- Number of steps : number of simulation points within the chosen boundaries.\n"
"- Multiplier : The multiplier field is the ratio of the number of input pulses divided by the expected number of output pulses. "
"For instance, if one expects only one output pulse for two input pulses the multiplier value is 2.\n"
"By clicking on the Start button JOINUS simulates the netlist for each of the steps and generate temporary outputs for each step. "
"JOINUS will store the data points for BER after processing the outputs if the Save simulation results checkbox is ticked.");
break;