-
Notifications
You must be signed in to change notification settings - Fork 0
/
workthread.cpp
94 lines (76 loc) · 2.13 KB
/
workthread.cpp
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
#include "workthread.h"
#include <QFile>
#include <QTextStream>
#include <QtCore>
#include <iostream>
WorkThread::WorkThread(QObject *parent) :
QThread(parent)
{
}
void WorkThread::run()
{
/*********************************************************/
/* Read input file, and initialize params and vars. This */
/* function calls SPECIES and LOAD or Restore */
start_(argc, argv);
// init output file
QString filename = "Qdust(t).txt";
QFile file(filename);
// InitWindows(argc, argv);
history();
fields();
int step=0;
float *pot = phi;
if (file.open(QIODevice::WriteOnly)) {
QTextStream stream(&file);
stream.setRealNumberPrecision(20);
while(True)
{
if(!stop){
// mutex.lock();
t += dt;
move();
adjust();
mcc();
fields();
history();
if(((int)(t/dt))%2==0) stream << t<<"\t"<< qdust << "\t"<< energy_flux[0] <<"\t"<< energy_flux[1] << endl;
updatePlasmaModel();
if(step%200==0 && step>0) {
// stop=true;
std::cout<< "Step "<<step<<": a signal sent to save data\n"<<endl;
emit DataChanged();
}
} else{
this->msleep(50);
}
step++;
}
}
}
void WorkThread::setPlasmaModel(PlasmaModel *pm)
{
plasma = pm;
}
PlasmaModel *WorkThread::updatePlasmaModel()
{
int size = nc*3/4;
//Copy values from array to QVector. Required by QCustomPlot
QVector<double> r(size),phi_(size),ne(size),ni(size),npe(size),npi(size);
for(int i=0; i<size;i++){
r[i] = r_array[i];
phi_[i] = phi[i];
ne[i] = srho[0][i];
ni[i] = srho[1][i];
npe[i] = np_hist[0][i];
npi[i] = np_hist[1][i];
}
//Set the vectors into model
plasma->setR(r);
plasma->setPhiDistribution(phi_);
plasma->setElectronConcDistribution(ne);
plasma->setIonConcDistribution(ni);
plasma->setElectronsNumber(npe);
plasma->setIonsNumber(npi);
return plasma;
}