Skip to content

Commit 1f2dba7

Browse files
committed
mass exponents and multifractal spectrum
1 parent de774ff commit 1f2dba7

19 files changed

+445
-10
lines changed

FATool.pro

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ QT = core gui
1111
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
1212

1313
SOURCES += main.cpp \
14+
log_window.cpp \
15+
mass_exponents_window.cpp \
1416
plot_window.cpp \
1517
qcustomplot.cpp \
1618
main_window.cpp \
@@ -34,6 +36,7 @@ SOURCES += main.cpp \
3436
refit_window.cpp \
3537
DCCA.cpp \
3638
rhoDCCA.cpp \
39+
spectrum_window.cpp \
3740
starting_window.cpp \
3841
MFDFA.cpp \
3942
MFDFA_single_q.cpp \
@@ -43,6 +46,8 @@ SOURCES += main.cpp \
4346

4447
HEADERS += \
4548
constants.h \
49+
log_window.h \
50+
mass_exponents_window.h \
4651
plot_window.h \
4752
qcustomplot.h \
4853
main_window.h \
@@ -67,6 +72,7 @@ HEADERS += \
6772
refit_window.h \
6873
DCCA.h \
6974
rhoDCCA.h \
75+
spectrum_window.h \
7076
starting_window.h \
7177
MFDFA.h \
7278
MFDFA_single_q.h \

MFDFA.cpp

+98
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ bool MFDFA::computeFlucVec(){
5555
return execStop;
5656
}
5757

58+
void MFDFA::computeMassExponents()
59+
{
60+
tau = new double [Nq];
61+
for(int i = 0; i < Nq; i++)
62+
tau[i] = Hq[i] * qRange[i] - 1.0;
63+
}
64+
65+
void MFDFA::computeSpectrum()
66+
{
67+
computeMassExponents();
68+
alpha = new double [Nq-1];
69+
spectrum = new double [Nq-1];
70+
for(int i = 0; i < Nq-1; i++)
71+
alpha[i] = (tau[i+1] - tau[i]) / (qRange[1] - qRange[0]);
72+
for(int i = 0; i < Nq-1; i++)
73+
spectrum[i] = qRange[i] * alpha[i] - tau[i];
74+
}
75+
5876
std::string MFDFA::outFileStr(){
5977
return "/"+MFDFAfnStart+"_"+std::to_string(minWin)+"_"+std::to_string(maxWin)+"_q"+std::to_string(static_cast<int>(qRange[0]))+"_"+
6078
std::to_string(static_cast<int>(qRange[Nq-1]))+"_"+fileName.substr(fileName.find_last_of("/")+1);
@@ -93,6 +111,36 @@ void MFDFA::qsaveFile(std::string pathTot){
93111
fclose(f);
94112
}
95113

114+
std::string MFDFA::tauOutFileStr(){
115+
return "/tau_q"+std::to_string(static_cast<int>(qRange[0]))+"_"+std::to_string(static_cast<int>(qRange[Nq-1]))+
116+
"_"+fileName.substr(fileName.find_last_of("/")+1);
117+
}
118+
119+
void MFDFA::tauSaveFile(std::string pathTot){
120+
FileOps fo = FileOps();
121+
FILE *f;
122+
f = fo.openFile(pathTot+tauOutFileStr(), "w");
123+
for(int i = 0; i < Nq; i++){
124+
fprintf(f, "%lf %lf\n", qRange[i], tau[i]);
125+
}
126+
fclose(f);
127+
}
128+
129+
std::string MFDFA::spectrumOutFileStr(){
130+
return "/spectrum_q"+std::to_string(static_cast<int>(qRange[0]))+"_"+std::to_string(static_cast<int>(qRange[Nq-1]))+
131+
"_"+fileName.substr(fileName.find_last_of("/")+1);
132+
}
133+
134+
void MFDFA::spectrumSaveFile(std::string pathTot){
135+
FileOps fo = FileOps();
136+
FILE *f;
137+
f = fo.openFile(pathTot+spectrumOutFileStr(), "w");
138+
for(int i = 0; i < Nq-1; i++){
139+
fprintf(f, "%lf %lf\n", alpha[i], spectrum[i]);
140+
}
141+
fclose(f);
142+
}
143+
96144
void MFDFA::plot(BasePlot *plt){
97145
QVector<double> yh(Nq), xq(Nq);
98146
for(int i = 0; i < Nq; i++){
@@ -116,3 +164,53 @@ void MFDFA::plot(BasePlot *plt){
116164
plt->legend->setVisible(true);
117165
plt->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignLeft);
118166
}
167+
168+
void MFDFA::plotMassExponents(BasePlot *plt)
169+
{
170+
QVector<double> yt(Nq), xq(Nq);
171+
for(int i = 0; i < Nq; i++){
172+
xq[i] = qRange[i];
173+
yt[i] = tau[i];
174+
}
175+
plt->addGraph();
176+
plt->xAxis->setLabel("q");
177+
plt->yAxis->setLabel("tau(q)");
178+
plt->graph(0)->setData(xq, yt);
179+
plt->graph(0)->setLineStyle(QCPGraph::lsLine);
180+
plt->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, Qt::red, 10));
181+
QString fn = QString::fromStdString(fileName).split("/").last();
182+
fn.truncate(fn.lastIndexOf("."));
183+
plt->graph(0)->setName(fn);
184+
plt->graph(0)->rescaleAxes();
185+
QPen pen;
186+
pen.setWidth(2);
187+
pen.setColor(Qt::red);
188+
plt->graph(0)->setPen(pen);
189+
plt->legend->setVisible(true);
190+
plt->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignLeft);
191+
}
192+
193+
void MFDFA::plotSpectrum(BasePlot *plt)
194+
{
195+
QVector<double> a(Nq-1), f(Nq-1);
196+
for(int i = 0; i < Nq-1; i++){
197+
a[i] = alpha[i];
198+
f[i] = spectrum[i];
199+
}
200+
plt->addGraph();
201+
plt->xAxis->setLabel("alpha");
202+
plt->yAxis->setLabel("f(alpha)");
203+
plt->graph(0)->setData(a, f);
204+
plt->graph(0)->setLineStyle(QCPGraph::lsLine);
205+
plt->graph(0)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDisc, Qt::red, 10));
206+
QString fn = QString::fromStdString(fileName).split("/").last();
207+
fn.truncate(fn.lastIndexOf("."));
208+
plt->graph(0)->setName(fn);
209+
plt->graph(0)->rescaleAxes();
210+
QPen pen;
211+
pen.setWidth(2);
212+
pen.setColor(Qt::red);
213+
plt->graph(0)->setPen(pen);
214+
plt->legend->setVisible(true);
215+
plt->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignLeft);
216+
}

MFDFA.h

+11
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,29 @@ class MFDFA : public MFDFAsingleQ
1111
void allocateQmemory();
1212
void setQrange(double, int, double);
1313
bool computeFlucVec() override;
14+
void computeMassExponents();
15+
void computeSpectrum();
1416
std::string outFileStr() override;
1517
void saveFile(std::string pathTot) override;
1618
std::string qoutFileStr();
1719
void qsaveFile(std::string pathTot);
20+
std::string tauOutFileStr();
21+
void tauSaveFile(std::string pathTot);
22+
std::string spectrumOutFileStr();
23+
void spectrumSaveFile(std::string pathTot);
1824
void plot(BasePlot *plt) override;
25+
void plotMassExponents(BasePlot *plt);
26+
void plotSpectrum(BasePlot *plt);
1927
private:
2028
int Nq;
2129
double stepq;
2230
double *qRange;
2331
double **flucMtx;
2432
double *Hq;
2533
double *Hinterceptq;
34+
double *tau;
35+
double *alpha;
36+
double *spectrum;
2637
};
2738

2839
#endif

constants.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#define POL_FAILURE -97
1212
#define REV_SEG_FAILURE -96
1313
#define FILE_FAILURE -95
14+
//app version
15+
const QString VERSION = "1.2";
1416
//dcca fluctuation vector
1517
const std::string defaultDCCA = "abs";
1618
const std::string corrDCCA = "sign";

dcca_window.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
DCCAWindow::DCCAWindow(DCCA *dcca_, QWidget *parent) : PlotWindow(parent)
44
{
55
dcca = dcca_;
6+
fileName = QString::fromStdString(dcca->getFileName1()).split("/").last();
7+
fileName2 = QString::fromStdString(dcca->getFileName2()).split("/").last();
68
//set title
7-
QString winTitle = strDCCA+" - "+QString::fromStdString(dcca->getFileName1()).split("/").last();
8-
winTitle.append(" & "+QString::fromStdString(dcca->getFileName2()).split("/").last());
9+
QString winTitle = strDCCA+" - "+fileName;
10+
winTitle.append(" & "+fileName2);
911
setTitle(winTitle);
1012
//refit button
1113
addRefitButton();
14+
//fits log button
15+
addFitLogButton();
1216
//plot
1317
plotData();
1418
//plot fields

dfa_window.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
DFAWindow::DFAWindow(DFA *dfa_, QWidget *parent) : PlotWindow(parent)
44
{
55
dfa = dfa_;
6+
fileName = QString::fromStdString(dfa->getFileName()).split("/").last();
67
//set title
7-
QString winTitle = strDFA+" - "+QString::fromStdString(dfa->getFileName()).split("/").last();
8+
QString winTitle = strDFA+" - "+fileName;
89
setTitle(winTitle);
910
//refit button
1011
addRefitButton();
12+
//fits log button
13+
addFitLogButton();
1114
//plot
1215
plotData();
1316
//plot fields

ht_window.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
HTWindow::HTWindow(HT *ht_, QWidget *parent) : PlotWindow(parent)
44
{
55
ht = ht_;
6+
fileName = QString::fromStdString(ht->getFileName()).split("/").last();
67
//set title
7-
QString winTitle = strHT+" - "+QString::fromStdString(ht->getFileName()).split("/").last();
8+
QString winTitle = strHT+" - "+fileName;
89
setTitle(winTitle);
910
//plot
1011
plotData();

log_window.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include "log_window.h"
2+
3+
LogWindow::LogWindow(QString logs_, QString fileName_, QString fileName2_, QWidget *parent) : QWidget(parent)
4+
{
5+
logs = logs_;
6+
fileName = fileName_;
7+
fileName2 = fileName2_;
8+
//set dimensions
9+
setDimensions();
10+
//set title
11+
setWindowTitle("Fits log - "+fileName);
12+
//win size
13+
setFixedSize(xDim, yDim);
14+
//save button
15+
saveBtn = new QPushButton("Save", this);
16+
saveBtn->setGeometry(xDim-padX/2-xWidth*3, yDim-yHeight-padY, xWidth*3, yHeight);
17+
connect(saveBtn, SIGNAL(clicked()), this, SLOT(onSave()));
18+
//close button
19+
closeBtn = new QPushButton("Close", this);
20+
closeBtn->setGeometry(xDim-padX-xWidth*6, yDim-yHeight-padY, xWidth*3, yHeight);
21+
connect(closeBtn, SIGNAL(clicked()), this, SLOT(close()));
22+
//scrollable text area
23+
txtArea = new QTextEdit(this);
24+
txtArea->setGeometry(padX*2, padY*4, xDim-padX*2, yDim-yHeight-3*padY);
25+
txtArea->setText(logs);
26+
txtArea->setReadOnly(true);
27+
scrollArea = new QScrollArea(this);
28+
scrollArea->setBackgroundRole(QPalette::Dark);
29+
scrollArea->setWidget(txtArea);
30+
}
31+
32+
LogWindow::~LogWindow(){}
33+
34+
void LogWindow::setDimensions()
35+
{
36+
xDim = 300;
37+
yDim = 350;
38+
xWidth = 30;
39+
yHeight = 30;
40+
padX = 10;
41+
padY = 5;
42+
}
43+
44+
void LogWindow::onSave()
45+
{
46+
QString pathToSave = QFileDialog::getExistingDirectory();
47+
if(!pathToSave.isNull() && !pathToSave.isEmpty()){
48+
QString pathTot;
49+
QStringList fnList = fileName.split(".");
50+
QString fn;
51+
for(int i = 0; i < fnList.size()-1; i++)
52+
fn.append(fnList[i]);
53+
pathTot = fn;
54+
if(fileName2 != ""){
55+
QStringList fnList2 = fileName2.split(".");
56+
QString fn2;
57+
for(int i = 0; i < fnList2.size()-1; i++)
58+
fn2.append(fnList2[i]);
59+
pathTot.append("_"+fn2);
60+
}
61+
QFile qFile(pathToSave+"/fitsLog_"+pathTot+".txt");
62+
if (qFile.open(QIODevice::WriteOnly)) {
63+
QTextStream out(&qFile);
64+
out << logs;
65+
qFile.close();
66+
}
67+
}
68+
}

log_window.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef LOG_WINDOW_H
2+
#define LOG_WINDOW_H
3+
4+
#include <QtWidgets>
5+
6+
class LogWindow : public QWidget
7+
{
8+
Q_OBJECT
9+
public:
10+
explicit LogWindow(QString logs_, QString fileName_, QString fileName2_, QWidget *parent=nullptr);
11+
~LogWindow();
12+
private slots:
13+
void onSave();
14+
private:
15+
void setDimensions();
16+
17+
QPushButton *closeBtn;
18+
QPushButton *saveBtn;
19+
QTextEdit *txtArea;
20+
QScrollArea *scrollArea;
21+
22+
QString fileName;
23+
QString fileName2;
24+
QString logs;
25+
int xDim;
26+
int yDim;
27+
int xWidth;
28+
int yHeight;
29+
int padX;
30+
int padY;
31+
};
32+
33+
#endif // LOG_WINDOW_H

main_window.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
55
//set dimensions
66
setDimensions();
77
//set title
8-
setWindowTitle("FATool (v 1.1)");
8+
setWindowTitle("FATool (v "+VERSION+")");
99
//win size
1010
setFixedSize(xDim, yDim);
1111
//plot section

mass_exponents_window.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "mass_exponents_window.h"
2+
3+
MassExponentsWindow::MassExponentsWindow(MFDFA *mfdfa_, QString fileName_, QWidget *parent) : PlotWindow(parent)
4+
{
5+
mfdfa = mfdfa_;
6+
fileName = fileName_;
7+
//set title
8+
QString winTitle = "Mass exponents - "+fileName;
9+
setTitle(winTitle);
10+
//plot
11+
plotData();
12+
//plot fields
13+
addPlotFields();
14+
//legend
15+
addLegend();
16+
}
17+
18+
MassExponentsWindow::~MassExponentsWindow(){}
19+
20+
void MassExponentsWindow::plotData()
21+
{
22+
mfdfa->computeMassExponents();
23+
mfdfa->plotMassExponents(plt);
24+
plt->replot();
25+
}
26+
27+
void MassExponentsWindow::onSaveTxtClick()
28+
{
29+
QString pathToSave = QFileDialog::getExistingDirectory();
30+
if(!pathToSave.isNull() && !pathToSave.isEmpty())
31+
mfdfa->tauSaveFile(pathToSave.toStdString());
32+
}

0 commit comments

Comments
 (0)