-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
4531 lines (4275 loc) · 130 KB
/
mainwindow.cpp
File metadata and controls
4531 lines (4275 loc) · 130 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
#define _CRT_SECURE_NO_WARNINGS 1
#include "mainwindow.h"
#include "mkl.h"
#include <math.h>
#include "myparam.h"
#include <QCursor>
#include <QVBoxLayout>
#include <QMessageBox>
const double Cond_min = 1e-12;
const int NCUT = 1e4;
const int nJ=5000;
//const double Delta_r=35;//15; //nm
const double E0=560.;//meV
const double Vg0=240;//350;//240//350;//400;//50;
//const double Vg0=50;//240//350;//400;//50;
//const double Cg0=-0.15;//-0.12;//-0.1;//-0.06;//-0.05;//-0.04;
// const double EF0=20;
double elementCr = 1e+22;
double sigma_m=0.1;
//double a_barrier=200;//150;//100;
class ColorScale
{
protected:
double v0,v1;
QColor c0,c1;
friend class ColorScale2;
public:
ColorScale() : v0(0), v1(1), c0(Qt::red), c1(Qt::blue) {}
void setRange(double vmin,double vmax)
{
v0 = vmin; v1 = vmax;
}
void setColors(QColor cmin,QColor cmax)
{
c0 = cmin; c1 = cmax;
}
QColor color(double v) const
{
if (v <= v0) return c0;
if (v >= v1) return c1;
int r = c0.red() + (v - v0)/(v1 - v0) * (c1.red() - c0.red());
int g = c0.green() + (v - v0)/(v1 - v0) * (c1.green() - c0.green());
int b = c0.blue() + (v - v0)/(v1 - v0) * (c1.blue() - c0.blue());
return QColor(r,g,b);
}
};
class ColorScale2
{
ColorScale a,b;
public:
ColorScale2() {}
void setRange(double vmin,double vmax)
{
double vmid = 0.5 *( vmax + vmin );
a.setRange(vmin, vmid);
b.setRange(vmid, vmax);
}
void setColors(QColor cmin,QColor cmax)
{
int r0,g0,b0,r1,g1,b1;
cmin.getRgb(&r0,&g0,&b0);
cmax.getRgb(&r1,&g1,&b1);
a.setColors(cmin,QColor(0.5*(r0+r1),0.5*(g0+g1),0.5*(b0+b1)));
b.setColors(QColor(0.5*(r0+r1),0.5*(g0+g1),0.5*(b0+b1)),cmax);
}
QColor color(double v) const
{
if (v < a.v0) return a.c0;
if (v < b.v0) return a.color(v);
if (v < b.v1) return b.color(v);
return b.c1;
}
void setExtraColor(double v, QColor c)
{
a.v1 = b.v0 = v;
a.c1 = b.c0 = c;
}
};
ColorScale csV; // Voltage scale and node coloring
ColorScale2 csJ; // Joule heat scale and node coloring
ColorScale2 csI; // Current scale and edge coloring
ColorScale2 csS; // Sigma scale and edge coloring
class DoubleValidator : public QRegExpValidator
{
public:
DoubleValidator(QWidget *parent) : QRegExpValidator(parent)
{
const QRegExp x(QString("[+-]?\\d+\\.?\\d*([dDe][+-]?\\d+)?"));
setRegExp(x);
}
~DoubleValidator(){}
} theDoubleValidator(0);
class PosIntValidator : public QRegExpValidator
{
public:
PosIntValidator(QWidget *parent) : QRegExpValidator(parent)
{
const QRegExp x(QString("\\d+"));
setRegExp(x);
}
~PosIntValidator(){}
} thePosIntValidator(0);
void MainWindow::initMenuBar()
{
exitAction = new QAction("Exit", this);
saveAction = new QAction("Save As", this);
openAction = new QAction("Open file", this);
chooseFontAction = new QAction("Choose Font", this);
saveAction->setStatusTip(tr("Сохранить в файле напряжения, токи и параметры расчета"));
openAction->setStatusTip(tr("Загрузить параметры из файла"));
saveAction->setShortcut(tr("Ctrl+S"));
openAction->setShortcut(tr("Ctrl+O"));
exitAction->setShortcut(tr("Ctrl+Q"));
chooseFontAction->setShortcut(tr("Ctrl+F"));
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
connect(chooseFontAction, SIGNAL(triggered()), this, SLOT(chooseFont()));
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveAs()));
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
QMenu* file = menuBar()->addMenu("Menu");
file->addAction(saveAction);
file->addAction(openAction);
file->addAction(chooseFontAction);
file->addSeparator();
file->addAction(exitAction);
// menu->insertSeparator();
/* Q3PopupMenu* help = new Q3PopupMenu( menu );
help->insertItem("&About", this, SLOT(help()), Qt::Key_F1);
menu->insertItem(tr("Помощь"),help);
*/
}
void MainWindow::initToolBar()
{
QPixmap pix(15,15);
pix.fill(Qt::red);
QAction *criticalElement = new QAction("Critical Element", this);
QToolBar *toolBar = new QToolBar(this);
// QHBoxLayout *H = new QHBoxLayout;
// this->Ex.setDisplay(("E_x[meV]"), H);
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
QToolButton *button1=new QToolButton();
button1->setIcon(pix);
toolBar->addAction(criticalElement);
addToolBar(toolBar);
}
void MainWindow::chooseFont()
{
bool ok;
QFont oldfont = myfont;
myfont = QFontDialog::getFont(&ok, oldfont, this);
if (ok)
setFont(myfont);
else
myfont = oldfont;
}
void MainWindow::initStatusBar()
{
createStatusBar();
this->dispCond = new QLabel("RCond: --------------",
this->statusBar());
this->statusBar()->addWidget(this->dispCond);
this->dispDeltaI = new QLabel("dI: -----------",
this->statusBar());
this->statusBar()->addWidget(this->dispDeltaI);
this->dispFerr = new QLabel("Ferr: -----------",
this->statusBar());
this->statusBar()->addWidget(this->dispFerr);
this->dispBerr = new QLabel("Berr: -----------",
this->statusBar());
this->statusBar()->addWidget(this->dispBerr);
this->dispConduct = new QLabel("G: ------------",
this->statusBar());
this->statusBar()->addWidget(this->dispConduct);
this->dispCapac = new QLabel("C: ------------",
this->statusBar());
this->statusBar()->addWidget(this->dispCapac);
}
void MainWindow::initControlDockWindow()
{
QDockWidget *myDockWidget = new QDockWidget(tr("Control Panel"),this);
myDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, myDockWidget);
QWidget *control = new QWidget();
QVBoxLayout *vl0 = new QVBoxLayout(control);
{
QGroupBox *gb1 = new QGroupBox(tr("One Resistor"),control);
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(gb1->sizePolicy().hasHeightForWidth());
gb1->setSizePolicy(sizePolicy);
QGroupBox *gb2 = new QGroupBox(tr("Resistor Network"), control);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(gb2->sizePolicy().hasHeightForWidth());
gb2->setSizePolicy(sizePolicy);
/* now fill gb1/OneResistor */
QVBoxLayout *vl2 = new QVBoxLayout(gb1);
vl0->addWidget(gb1);
{
QHBoxLayout *hlLR = new QHBoxLayout(gb1);
QGroupBox *gb = new QGroupBox(tr("Compute Conductance G"));
vl2->addLayout(hlLR);
vl2->addWidget(gb);
/* now fill LR */
QVBoxLayout *L = new QVBoxLayout(gb1);
hlLR->addLayout(L);
{
this->T.setDisplay(("T[meV]"), this, L);
// this->Ex.setDisplay(("a[nm]"), L);
this->deltaEx.setDisplay(("deltaE_x[meV]"), this, L);
this->Ex.setDisplay(("E_x[meV]"), this, L);
this->Ey.setDisplay(("E_y[meV]"), this, L);
this->Tmin.setDisplay(("T_min"), this, L);
this->Tmax.setDisplay(("T_max"), this, L);
this->dT.setDisplay(("dT"), this, L);
this->a_barrier.setDisplay(("a_bar"), this, L);
this->Delta_r.setDisplay(("Delta_r"), this, L);
// this->EFT.setDisplay(("EF(T,U)"), L);
QPushButton *bL = new QPushButton(tr("E_F for given T,U"));
connect(bL,SIGNAL(clicked()), this, SLOT(computeEF_TU()));
L->addWidget(bL);
QPushButton *computeDensityButton = new QPushButton(tr("density(U)"));
connect(computeDensityButton,SIGNAL(clicked()), this, SLOT(compute_nU()));
L->addWidget(computeDensityButton);
L->addStretch(1);
}
QVBoxLayout *R = new QVBoxLayout(gb1);
// QVBoxLayout *R = new QVBoxLayout(this);
hlLR->addLayout(R);
{
this->U.setDisplay(("U[meV]"), this, R);
this->rand.setDisplay(("r[0--1]"), this, R);
this->EF0.setDisplay(("EF0"), this, R);
this->EFT.setDisplay(("EFT"), this, R);
this->Umin.setDisplay(("U_min"), this, R);
this->Umax.setDisplay(("U_max"), this, R);
this->dU.setDisplay(("dU"), this, R);
this->Cg0.setDisplay(("Cg"), this, R);
this->G_ser.setDisplay(("G_ser"), this, R);
this->y_cr.setDisplay(("y_cr"), this, R);
// QPushButton *computeDensityButton = new QPushButton(tr("density(U)"));
// connect(computeDensityButton,SIGNAL(clicked()), this, SLOT(compute_nU()));
// R->addWidget(computeDensityButton);
typeCond = new QComboBox;
typeCond->addItem(tr("Total conductance"));
typeCond->addItem(tr("Tunnel conductance"));
typeCond->addItem(tr("Over-barrier G"));
typeCond->addItem(tr("Tunnel+Over-barrier G"));
typeCond->addItem(tr("G(E_F0)"));
typeCond->setCurrentIndex(3);
R->addWidget(typeCond);
R->addStretch(1);
}
/* now fill gb/Compute Conductance G */
QHBoxLayout *hl = new QHBoxLayout(gb);
{
QPushButton *b1 = new QPushButton(tr("G(T)"));
connect(b1,SIGNAL(clicked()), this, SLOT(computeRT1()));
QPushButton *b2 = new QPushButton(tr("G(U)"));
connect(b2,SIGNAL(clicked()), this, SLOT(computeRU1()));
QPushButton *b3 = new QPushButton(tr("U(x) for given T,U"));
connect(b3,SIGNAL(clicked()), this, SLOT(potential()));
QPushButton *b4 = new QPushButton(tr("E_F(U)"));
//// QPushButton *b4 = new QPushButton(tr("Area(E)"));
// connect(b4,SIGNAL(clicked()), this, SLOT(computeEFU()));
connect(b4,SIGNAL(clicked()), this, SLOT(computeAreaE()));
/* typeCond = new QComboBox;
typeCond->addItem(tr("Total conductance"));
typeCond->addItem(tr("Tunnel conductance"));
typeCond->addItem(tr("Over-barrier G"));
typeCond->addItem(tr("Tunnel+Over-barrier G"));
typeCond->addItem(tr("G(E_F0)"));
typeCond->setCurrentIndex(0);
*/
hl->addWidget(b1);
hl->addWidget(b2);
hl->addWidget(b3);
hl->addWidget(b4);
}
}
/* now fill gb2/ResistorNetwork */
QVBoxLayout *vl3 = new QVBoxLayout(gb2);
vl0->addWidget(gb2);
{
QHBoxLayout *hlLR = new QHBoxLayout;
QHBoxLayout *hl3 = new QHBoxLayout;
QGroupBox *gb3 = new QGroupBox(tr("Canvas Images"), gb2);
QGroupBox *gb4 = new QGroupBox(tr("G-curves"), gb2);
QGroupBox *gb5 = new QGroupBox(tr("C-curves"), gb2);
vl3->addLayout(hlLR);
hl3->addWidget(gb3);
hl3->addWidget(gb4);
hl3->addWidget(gb5);
vl3->addLayout(hl3);
/* now fill LR */
QVBoxLayout *L = new QVBoxLayout(this);
hlLR->addLayout(L);
{
QGroupBox *gbRType = new QGroupBox(tr("Resistor Network Type"));
L->addWidget(gbRType);
QRadioButton *type1 = new QRadioButton(tr("RNW Exp(-kappa*x)"));
// QRadioButton *type1 = new QRadioButton(tr("Одинаковые сопротивления"));
QRadioButton *type2 = new QRadioButton(tr("RNW 0 or 1"));
QRadioButton *type3 = new QRadioButton(tr("model RNW"));
QVBoxLayout *vbox = new QVBoxLayout(gbRType);
vbox->addWidget(type1);
vbox->addWidget(type2);
vbox->addWidget(type3);
// vbox->addStretch(1);
this->typeResistor = new QButtonGroup;
this->typeResistor->setExclusive(true);
this->typeResistor->addButton(type1,0);
this->typeResistor->addButton(type2,1);
this->typeResistor->addButton(type3,2);
this->typeResistor->button(2)->setChecked(true);
//connect(typeResistor,SIGNAL(clicked(int)),this,SLOT(selectSigma(int)));
this->CUTOFF_SIGMA.setDisplay(("Sigma_cut_off"), this, L);
this->kappa.setDisplay(("kappa"), this, L);
// this->Vijmax.setDisplay(("deltaVijmax"), L);
// this->portion.setDisplay(("portion"), L);
}
QVBoxLayout *R = new QVBoxLayout(this);
hlLR->addLayout(R);
{
this->rows.setDisplay(("rows"), this, R);
this->cols.setDisplay(("cols"), this, R);
this->seed.setDisplay(("seed"), this, R);
this->deviation.setDisplay(("deviation"), this, R);
this->sigmaU.setDisplay(("sigmaU"), this, R);
// this->fraction.setDisplay(("fraction x"), R);
this->r_c.setDisplay(("r_c"), this, R);
this->sigmaMin.setDisplay(("sigmaMin"), this, R);
this->i_Rcr.setDisplay(("i_cr"), this, R);
// this->Vijmax.setDisplay(("deltaVijmax"), R);
// QGroupBox *critElem = new QGroupBox(tr("Red Bond"));
// QVBoxLayout *Hcr = new QVBoxLayout(R);
// this->r_c.setDisplay(("r_c"), Hcr);
// this->sigmaMin.setDisplay(("sigmaMin"), Hcr);
// Hcr->addWidget(critElem);
}
/* now fill gb0/Canvas Image */
// QVBoxLayout *vl = new QVBoxLayout(hl3);
QVBoxLayout *vl = new QVBoxLayout(gb3);
{
QPushButton *computeButton = new QPushButton(tr("Compute"));
computeButton->setDefault(true);
connect(computeButton, SIGNAL(clicked()), this, SLOT(computeModel()));
QPushButton *drawResButton = new QPushButton(tr("Conductivity network"));
connect(drawResButton,SIGNAL(clicked()), this, SLOT(drawModelR()));
QPushButton *drawCurButton = new QPushButton(tr("Draw Current I"));
connect(drawCurButton,SIGNAL(clicked()), this, SLOT(drawModelI()));
QPushButton *drawVButton = new QPushButton(tr("Draw Voltage V"));
connect(drawVButton,SIGNAL(clicked()), this, SLOT(drawModelV()));
QPushButton *drawJButton = new QPushButton(tr("Draw Heat I*V"));
connect(drawJButton,SIGNAL(clicked()), this, SLOT(drawModelJ()));
QPushButton *drawdVButton = new QPushButton(tr("Draw dV"));
connect(drawdVButton,SIGNAL(clicked()), this, SLOT(drawModeldV()));
QPushButton *clearButton = new QPushButton(tr("Clear"));
connect(clearButton,SIGNAL(clicked()), this, SLOT(clearScene()));
vl->addWidget(computeButton);
vl->addWidget(drawResButton);
vl->addWidget(drawCurButton);
vl->addWidget(drawdVButton);
vl->addWidget(drawVButton);
vl->addWidget(drawJButton);
vl->addWidget(clearButton);
vl->addStretch(1);
}
QVBoxLayout *vl1 = new QVBoxLayout(gb4);
{
QPushButton *stopB = new QPushButton(tr("STOP"));
connect(stopB, SIGNAL(clicked()), this, SLOT(stopCalc()));
QPushButton *xB = new QPushButton(tr("Conductivity(x)"));
connect(xB,SIGNAL(clicked()), this, SLOT(computeRX()));
QPushButton *uB = new QPushButton(tr("Conductivity(U)"));
connect(uB,SIGNAL(clicked()), this, SLOT(computeRU()));
QPushButton *ueffB = new QPushButton(tr("Effective Gm(U)"));
connect(ueffB,SIGNAL(clicked()), this, SLOT(computeReffU()));
QPushButton *VmaxB = new QPushButton(tr("Vmax(U)"));
connect(VmaxB,SIGNAL(clicked()), this, SLOT(computeVimax()));
QPushButton *rcB = new QPushButton(tr("Conductivity(rc)"));
connect(rcB,SIGNAL(clicked()), this, SLOT(computeRrc()));
QPushButton *dB = new QPushButton(tr("Deviation"));
connect(dB,SIGNAL(clicked()), this, SLOT(compute_deviation()));
vl1->addWidget(stopB);
vl1->addWidget(xB);
vl1->addWidget(uB);
vl1->addWidget(ueffB);
vl1->addWidget(VmaxB);
vl1->addWidget(rcB);
vl1->addWidget(dB);
vl1->addStretch(1);
}
// QVBoxLayout *vl2 = new QVBoxLayout(hl3);
QVBoxLayout *vl2 = new QVBoxLayout(gb5);
{
QPushButton *cuB = new QPushButton(tr("Capacity(U)"));
connect(cuB,SIGNAL(clicked()), this, SLOT(computeCapacityU()));
QPushButton *ctB = new QPushButton(tr("Capacity(T)"));
connect(ctB,SIGNAL(clicked()), this, SLOT(computeCapacityT()));
QPushButton *gtB = new QPushButton(tr("Conductivity(T)"));
connect(gtB,SIGNAL(clicked()), this, SLOT(computeRT()));
QPushButton *gteffB = new QPushButton(tr("Effective Gm(T)"));
connect(gteffB,SIGNAL(clicked()), this, SLOT(computeReffT()));
// QPushButton *pVb = new QPushButton(tr("pVoltage"));
// connect(pVb,SIGNAL(clicked()), this, SLOT(compute_pV()));
QPushButton *pVb = new QPushButton(tr("Voltage(x) at y=y_cr"));
connect(pVb,SIGNAL(clicked()), this, SLOT(compute_Vx()));
// connect(pVb,SIGNAL(clicked()), this, SLOT(compute_deltaVx()));
// QPushButton *pSVb = new QPushButton(tr("pSmallVoltage"));
// connect(pSVb,SIGNAL(clicked()), this, SLOT(compute_p_small_V()));
QPushButton *pdVb = new QPushButton(tr("pdeltaV"));
connect(pdVb,SIGNAL(clicked()), this, SLOT( compute_pdV()));
QPushButton *pSdVb = new QPushButton(tr("pSmalldeltaV"));
connect(pSdVb,SIGNAL(clicked()), this, SLOT(compute_p_small_dV()));
// QPushButton *pC = new QPushButton(tr("pCurrent"));
// connect(pC,SIGNAL(clicked()), this, SLOT(compute_pCurrent()));
QPushButton *cpSB = new QPushButton(tr("pSigma"));
connect(cpSB,SIGNAL(clicked()), this, SLOT(compute_pSigma()));
// QPushButton *cSpSB = new QPushButton(tr("Sum_pSigma"));
// connect(cSpSB,SIGNAL(clicked()), this, SLOT(compute_SumpSigma()));
vl2->addWidget(cuB);
vl2->addWidget(ctB);
vl2->addWidget(gtB);
vl2->addWidget(gteffB);
vl2->addWidget(pVb);
// vl2->addWidget(pSVb);
vl2->addWidget(pdVb);
// vl2->addWidget(pSdVb);
// vl2->addWidget(pC);
vl2->addWidget(cpSB);
// vl2->addWidget(cSpSB);
vl2->addStretch(1);
}
}
}
vl0->addStretch(1);
myDockWidget->setWidget(control);
}
void MainWindow::initGraphicsView()
{
QGraphicsScene *scene = new QGraphicsScene(0,0,600,600);
this->gv = new QGraphicsView(scene,this);
setCentralWidget(this->gv);
this->gv->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
}
void MainWindow::initPlotCurrent()
{
winPlotI = new QDialog(this);
winPlotI->setWindowTitle(tr("Distribution of current:"));
QVBoxLayout *layout=new QVBoxLayout(winPlotI);
this->plotterI= new Plotter(winPlotI);
this->plotterI->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterI);
}
void MainWindow::initPlotVoltage()
{
winPlotV = new QDialog(this);
winPlotV->setWindowTitle(tr("Distribution of voltage:"));
QVBoxLayout *layout=new QVBoxLayout(winPlotV);
this->plotterV= new Plotter(winPlotV);
this->plotterV->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterV);
}
void MainWindow::initPlotJouleHeat()
{
winPlotJ = new QDialog(this);
winPlotJ->setWindowTitle(tr("Distribution of Joule Heat:"));
QVBoxLayout *layout=new QVBoxLayout(winPlotJ);
this->plotterJ= new Plotter(winPlotJ);
this->plotterJ->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterJ);
}
void MainWindow::initPlotConductance()
{
winPlotG = new QDialog(this);
winPlotG->setWindowTitle(tr("Distribution of conductance:"));
QVBoxLayout *layout=new QVBoxLayout(winPlotG);
this->plotterG= new Plotter(winPlotG);
this->plotterG->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterG);
}
void MainWindow::initPlotterU()
{
winPlotU = new QDialog(this);
winPlotU->setWindowTitle(tr("Dependences G(U):"));
QVBoxLayout *layout=new QVBoxLayout(winPlotU);
this->plotterU= new Plotter(winPlotU);
// this->plotterU = new Plotter(winPlotU);
this->plotterU->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterU);
}
void MainWindow::initPlotterT()
{
winPlotT = new QDialog(this);
winPlotT->setFocus();
winPlotT->setWindowTitle(tr("Dependences G(T):"));
QVBoxLayout *layout=new QVBoxLayout(winPlotT);
this->plotterT= new Plotter(winPlotT);
this->plotterT->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterT);
}
void MainWindow::initPlotterE()
{
winPlotE = new QDialog(this);
winPlotE->setFocus();
winPlotE->setWindowTitle(tr("Area(E):"));
QVBoxLayout *layout=new QVBoxLayout(winPlotE);
this->plotterE= new Plotter(winPlotE);
this->plotterE->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterE);
}
void MainWindow::initPlotterCT()
{
winPlotCT = new QDialog(this);
winPlotCT->setWindowTitle(tr("Capacity(T):"));
QVBoxLayout *layout=new QVBoxLayout(winPlotCT);
this->plotterCT= new Plotter(winPlotCT);
this->plotterCT->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterCT);
}
void MainWindow::initPlotterCU()
{
winPlotCU = new QDialog(this);
winPlotCU->setWindowTitle(tr("Capacity(U):"));
QVBoxLayout *layout=new QVBoxLayout(winPlotCU);
this->plotterCU= new Plotter(winPlotCU);
this->plotterCU->setCurveData(1, this->plotdata);
layout->addWidget(this->plotterCU);
}
void MainWindow::setModel()
{
if (model) delete model;
model = new PercolRect(this->rows,this->cols);
}
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags f)
: randc(0.5),
//Exc(5.), Eyc(5.),
density(1000.),sigmaU(1.e2), flgStop(false),portion(0.01),
// T(0.13), Tmin(0.1),Tmax(5.331), dT(0.1), //Gold(0.0),
T(0.13), Tmin(0.),Tmax(0.3), dT(0.01), //Gold(0.0),
U(465.), Umin(460.), Umax(600.), dU(10.),
//U(155.), Umin(155.), Umax(240.), dU(5.),
i_Rcr(0),CUTOFF_SIGMA(1.e-15),
//U(950), Umin(200.), Umax(1500), dU(5.),
r_c(0.0), Ex(22.), deltaEx(0.), Vijmax(2.), Ey(6.), rand(0.5), EF(20.),EFT(22.),kappa(10.),y_cr(15),
a_barrier(180.), Cg0(-0.09),Delta_r(22.),G_ser(1.0),EF0(42.),
//a_barrier(150.), Cg0(-0.12),Delta_r(30.),G_ser(3.0),EF0(20.),
QMainWindow(parent,f),
rows(30), cols(53), numOfCurve(1), seed(1), model(0)
{
this->initMenuBar();
this->initToolBar();
this->initStatusBar();
this->initPlotCurrent();
this->initPlotVoltage();
this->initPlotJouleHeat();
this->initPlotConductance();
this->initPlotterT();
this->initPlotterE();
this->initPlotterU();
this->initPlotterCT();
this->initPlotterCU();
this->initControlDockWindow();
this->setModel();
this->initGraphicsView();
init();
}
bool MainWindow::open()
{
QString fn = QFileDialog::getOpenFileName( this,
tr("Choose a file name"), ".",
tr("*.dat*"));
if ( !fn.isEmpty() ) {
// read from file
curFile = fn;
return this->read();
}
return false;
}
bool MainWindow::read()
{
if (this->curFile.isEmpty())
{
return this->open();
}
QFile f(this->curFile);
if (!f.open(QIODevice::ReadOnly)) {
QMessageBox::information(this, tr("Unable to open file"),
f.errorString());
return false;
}
return true;
}
bool MainWindow::saveAs()
{
QString fn = QFileDialog::getSaveFileName( this,
tr("Choose a file name"), ".",
tr("*.dat*"));
if ( !fn.isEmpty() ) {
curFile = fn;
return this->save();
}
return false;
}
bool MainWindow::save()
{
if (this->curFile.isEmpty())
{
return this->saveAs();
}
QString nV=this->curFile+"V";
QFile fV(nV);
if(fV.exists()){
int n=QMessageBox::warning(0,
tr("Warning"),
"File with this name has already existed,"
"\n Do you want to rewrite it?",
"Yes",
"No",
QString::null,
0,
1
);
if(n){
return this->saveAs(); //выбираем новое имя
}
}
//Saving the file!
fV.open(QIODevice::WriteOnly|QIODevice::Truncate);
QTextStream o(&fV);
o << "Percolation model:\n";
o << "Rows Cols Seed Conduct Temp Vg sigmaU Ex\n";
QString s1;
s1.sprintf("%i %i %i %lg %lg %lg %lg% lg\n",int(this->rows),int(this->cols),int(this->seed),
double(model->conductivity), double(this->T), double(this->U),
double(this->sigmaU),double(this->Ex));
o << s1;
o << "x_cr y_cr sigma_cr\n";
// this->i_Rcr = model->index_of_Rcr();
double sigma_cr=model->Sigma[this->i_Rcr ];
QPair<int,int> endsRcr = model->ends(i_Rcr);
QPair<double,double> xy0Rcr = model->xy(endsRcr.first);
QPair<double,double> xy1Rcr = model->xy(endsRcr.second);
double x=0.5*(xy0Rcr.first+xy1Rcr.first);
double y=0.5*(xy0Rcr.second+xy1Rcr.second);
QString s2;
s2.sprintf("%lg %lg %lg\n",x,y,sigma_cr);
o << s2;
o << "x y Voltage:\n";
QString s;
QPair<double,double> xy = model->xy(0);
s.sprintf("%lg %lg %lg\n",xy.first,xy.second,model->V[0]);
o << s;
// o << "Calculated v-nodes\n";
for (int w = 0; w < model->nW(); ++w)
{
QString s;
QPair<double,double> xy = model->xy(w + model->nV());
s.sprintf("%lg %lg %lg\n",xy.first,xy.second,model->W[w]);
// s.sprintf("%i %lg %lg %lg\n",w + model->nV(),xy.first,xy.second,model->W[w]);
o << s;
}
QString ss;
QPair<double,double> xy1 = model->xy(1);
ss.sprintf("%lg %lg %lg\n",xy1.first,xy1.second,model->V[1]);
o << ss;
fV.close();
// statusBar()->showMessage(tr("Saved '%1'").arg(fV), 2009);
QString nC=this->curFile+"C";
QFile fC(nC);
// QFile f(this->curFile);
if(fC.exists()){
int n=QMessageBox::warning(0,
tr("Warning"),
"File with this name has already existed,"
"\n Do you want to rewrite it?",
"Yes",
"No",
QString::null,
0,
1
);
if(n){
return this->saveAs(); //выбираем новое имя
}
}
//Saving the file!
fC.open(QIODevice::WriteOnly|QIODevice::Truncate);
QTextStream oC(&fC);
oC << "Current at centers of edges\n";
for (int e = 0; e < model->nI(); ++e)
{
QPair<int,int> ends = model->ends(e);
QPair<double,double> xy0 = model->xy(ends.first);
QPair<double,double> xy1 = model->xy(ends.second);
x=0.5*(xy0.first+xy1.first);
y=0.5*(xy0.second+xy1.second);
QString s;
// QPair<int,int> from_to = model->ends(e);
s.sprintf("%lg %lg %lg\n",x,y, fabs(model->I[e]));
oC << s;
}
fC.close();
QString nJ=this->curFile+"J";
QFile fJ(nJ);
if(fJ.exists()){
int n=QMessageBox::warning(0,
tr("Warning"),
"File with this name has already existed,"
"\n Do you want to rewrite it?",
"Yes",
"No",
QString::null,
0,
1
);
if(n){
return this->saveAs(); //выбираем новое имя
}
}
//Saving the file!
fJ.open(QIODevice::WriteOnly|QIODevice::Truncate);
QTextStream oJ(&fJ);
oJ << "Joule Heat at centers of edges\n";
for (int e = 0; e < model->nI(); ++e)
{
QPair<int,int> ends = model->ends(e);
QPair<double,double> xy0 = model->xy(ends.first);
QPair<double,double> xy1 = model->xy(ends.second);
x=0.5*(xy0.first+xy1.first);
y=0.5*(xy0.second+xy1.second);
QString s;
s.sprintf("%lg %lg %lg\n",x,y, model->IdifV[e]);
oJ << s;
}
fJ.close();
QString ndV=this->curFile+"dV";
QFile fdV(ndV);
if(fdV.exists()){
int n=QMessageBox::warning(0,
tr("Warning"),
"File with this name has already existed,"
"\n Do you want to rewrite it?",
"Yes",
"No",
QString::null,
0,
1
);
if(n){
return this->saveAs(); //выбираем новое имя
}
}
//Saving the file!
fdV.open(QIODevice::WriteOnly|QIODevice::Truncate);
QTextStream odV(&fdV);
odV << "Voltage difference at centers of edges\n";
for (int e = 0; e < model->nI(); ++e)
{
QPair<int,int> ends = model->ends(e);
QPair<double,double> xy0 = model->xy(ends.first);
QPair<double,double> xy1 = model->xy(ends.second);
x=0.5*(xy0.first+xy1.first);
y=0.5*(xy0.second+xy1.second);
QString s;
s.sprintf("%lg %lg %lg\n",x,y, fabs(model->difV[e]));
odV << s;
}
fdV.close();
// statusBar()->showMessage(tr("Saved '%1'").arg(fC), 2009);
return TRUE;
}
void MainWindow::createStatusBar()
{
}
void MainWindow::help()
{
static QMessageBox *about;
if (!about)
{
char buf[200];
MKL_Get_Version_String(buf,sizeof(buf)-1);
buf[sizeof(buf)-1] = 0;
about = new QMessageBox("Percolation",buf,
QMessageBox::Information, 1, 0, 0, this);
}
about->setButtonText(1, "Dismiss" );
about->show();
}
void MainWindow::init()
{
int r_type = this->typeResistor->checkedId();
this->selectSigma(r_type);
}
void MainWindow::clear()
{
setMouseTracking( FALSE );
this->gv->scene()->clear();
}
class NodeItemFactory
{
QGraphicsScene *canvas;
ColorScale *cs;
double scale;
QPair<double,double> offset;
int blob_size;
public:
NodeItemFactory( QGraphicsScene *_canvas, ColorScale *_cs,
double _scale, QPair<double,double> _offset, int _blob_size = 2 )
: canvas(_canvas), cs(_cs), scale(_scale), offset(_offset), blob_size(_blob_size) {}
// Q3CanvasEllipse *newVnode(double v, QPair<double,double> xy)
QGraphicsEllipseItem *newVnode(double v, QPair<double,double> xy)
{
int v_blob_size = 2;
double canvasx = (xy.first - offset.first) * scale - 0.5 * v_blob_size;
double canvasy = (xy.second - offset.second) * scale - 0.5 * v_blob_size;
QGraphicsEllipseItem *n = canvas->addEllipse(canvasx,canvasy,
v_blob_size,v_blob_size,QPen(Qt::black,0),QBrush(cs->color(v)));
return n;
}
QGraphicsEllipseItem *newWnode(double v, QPair<double,double> xy)
//new: QGraphicsEllipseItem *newWnode(double v, QPair<double,double> xy)???(10,10)->(-5, -5, 10, 10);
{
double canvasx = (xy.first - offset.first) * scale - 0.5*blob_size;
double canvasy = (xy.second - offset.second) * scale - 0.5*blob_size;
QColor c = cs->color(v);
QGraphicsEllipseItem *n = canvas->addEllipse(canvasx,canvasy,blob_size,blob_size,QPen(c),QBrush(c));
// n->setBrush(QBrush(cs->color(v)));
// n->setZ( 128 );
// n->move( canvasx, canvasy );
return n;
}
void setBlobSize(int s) { blob_size = s; }
};
class EdgeItemFactory
{
QGraphicsScene *canvas;
ColorScale2 *cs;
double scale;
QPair<double,double> offset;
public:
EdgeItemFactory( QGraphicsScene *_canvas, ColorScale2 *_cs,
double _scale, QPair<double,double> _offset )
: canvas(_canvas), cs(_cs), scale(_scale), offset(_offset) {}
QGraphicsLineItem *newEdge(double c, QPair<double,double> xy0, QPair<double,double> xy1)
{ int canvasx0 = (xy0.first - offset.first) * scale;//- 0.5*blob_size;
int canvasy0 = (xy0.second - offset.second) * scale;//- 0.5*blob_size;
int canvasx1 = (xy1.first - offset.first) * scale;//- 0.5*blob_size;
int canvasy1 = (xy1.second - offset.second) * scale;//- 0.5*blob_size;
QPen pen;
if (c == 0)
pen = QPen(Qt::white);
else if (c == 1.e-15)
pen = QPen(Qt::white);
// pen = QPen(Qt::blue);
else
pen = QPen(cs->color(c),2);
if(c==1000) pen=QPen(Qt::black);
if(c==elementCr) pen=QPen(Qt::red);
QGraphicsLineItem *n = canvas->addLine(canvasx0,canvasy0,canvasx1,canvasy1,pen);
return n;
}
};
void MainWindow::clearScene()
{
QGraphicsScene *scene = gv->scene();
gv->fitInView(scene->sceneRect(),Qt::KeepAspectRatioByExpanding);
scene->clear();
}
void MainWindow::drawModelV()
{
QGraphicsScene *scene = gv->scene();
gv->fitInView(scene->sceneRect(),Qt::KeepAspectRatioByExpanding);
scene->clear();
// Set view port
const double factor = 0.95;
double xscale = factor * scene->width() / (model->xmax() - model->xmin());
double yscale = factor * scene->height() / (model->ymax() - model->ymin());