Quantum Phenomena Explorer 7.9.8
Interactive quantum-phenomena Explorer Tutor — source documentation
Loading...
Searching...
No Matches
quantumquenchplotwidget.cpp
Go to the documentation of this file.
1/**
2 * @file quantumquenchplotwidget.cpp
3 * @brief Implements the quantumquenchplotwidget visualization component used by QPE.
4 * @ingroup qpe_graphics
5 *
6 * Source: @c graphics/renderer/quantumquenchplotwidget.cpp. This file is part of Quantum Phenomena Explorer (QPE),
7 * maintained by Officina Turini. See LICENSE_IT.txt / LICENSE.txt for the
8 * QPE freeware source-available terms and THIRD_PARTY_NOTICES.txt for
9 * third-party components.
10 */
11
13
14#include <QPaintEvent>
15#include <QPainter>
16#include <QPainterPath>
17
18#include <algorithm>
19#include <cmath>
20#include <limits>
21
23 : QWidget(parent)
24{
25 setMinimumHeight(180);
26 setAutoFillBackground(false);
27}
28
30 const std::vector<qpe::ObservablesTimeSeries2DSample> &samples)
31{
32 samples_ = samples;
33 update();
34}
35
37{
38 quenchTime_ = time;
39 update();
40}
41
43{
44 samples_.clear();
45 quenchTime_ = -1.0;
46 update();
47}
48
50{
51 return QSize(480, 180);
52}
53
55{
56 Q_UNUSED(event);
57 QPainter painter(this);
58 painter.setRenderHint(QPainter::Antialiasing, true);
59 painter.setRenderHint(QPainter::TextAntialiasing, true);
60 painter.fillRect(rect(), QColor(15, 18, 23));
61
62 const QRectF plotRect(58.0, 26.0,
63 std::max(10.0, width() - 78.0),
64 std::max(10.0, height() - 64.0));
65 painter.setPen(QPen(QColor(78, 86, 96), 1.0));
66 for (int i = 0; i <= 4; ++i) {
67 const double u = static_cast<double>(i) / 4.0;
68 painter.drawLine(QPointF(plotRect.left() + u * plotRect.width(), plotRect.top()),
69 QPointF(plotRect.left() + u * plotRect.width(), plotRect.bottom()));
70 painter.drawLine(QPointF(plotRect.left(), plotRect.top() + u * plotRect.height()),
71 QPointF(plotRect.right(), plotRect.top() + u * plotRect.height()));
72 }
73 painter.setPen(QPen(QColor(170, 180, 190), 1.0));
74 painter.drawRect(plotRect);
75
76 double tMin = 0.0;
77 double tMax = quenchTime_ > 0.0 ? quenchTime_ + 4.0 : 1.0;
78 double sigmaMin = std::numeric_limits<double>::infinity();
79 double sigmaMax = -std::numeric_limits<double>::infinity();
80 double energyMin = std::numeric_limits<double>::infinity();
81 double energyMax = -std::numeric_limits<double>::infinity();
82 for (const qpe::ObservablesTimeSeries2DSample &sample : samples_) {
83 tMax = std::max(tMax, sample.time);
84 if (std::isfinite(sample.sigmaX)) {
85 sigmaMin = std::min(sigmaMin, sample.sigmaX);
86 sigmaMax = std::max(sigmaMax, sample.sigmaX);
87 }
88 if (std::isfinite(sample.totalEnergy)) {
89 energyMin = std::min(energyMin, sample.totalEnergy);
90 energyMax = std::max(energyMax, sample.totalEnergy);
91 }
92 }
93 if (!(tMax > tMin)) tMax = tMin + 1.0;
94 if (!(sigmaMax > sigmaMin)) { sigmaMin = 0.0; sigmaMax = std::max(1.0, sigmaMax); }
95 if (!(energyMax > energyMin)) { energyMin -= 0.5; energyMax += 0.5; }
96 const double sigmaPad = 0.10 * std::max(1.0e-6, sigmaMax - sigmaMin);
97 sigmaMin = std::max(0.0, sigmaMin - sigmaPad);
98 sigmaMax += sigmaPad;
99 const double energyPad = 0.10 * std::max(1.0e-6, energyMax - energyMin);
100 energyMin -= energyPad;
101 energyMax += energyPad;
102
103 const auto mapX = [plotRect, tMin, tMax](double t) {
104 return plotRect.left() + (t - tMin) / (tMax - tMin) * plotRect.width();
105 };
106 const auto mapSigma = [plotRect, sigmaMin, sigmaMax](double v) {
107 return plotRect.bottom() - (v - sigmaMin) / (sigmaMax - sigmaMin) * plotRect.height();
108 };
109 const auto mapEnergy = [plotRect, energyMin, energyMax](double v) {
110 return plotRect.bottom() - (v - energyMin) / (energyMax - energyMin) * plotRect.height();
111 };
112
113 if (quenchTime_ >= tMin && quenchTime_ <= tMax) {
114 painter.setPen(QPen(QColor(255, 220, 100), 1.5, Qt::DashLine));
115 painter.drawLine(QPointF(mapX(quenchTime_), plotRect.top()),
116 QPointF(mapX(quenchTime_), plotRect.bottom()));
117 painter.drawText(QRectF(mapX(quenchTime_) + 4.0, plotRect.top() + 2.0, 80.0, 18.0),
118 Qt::AlignLeft, QStringLiteral("quench"));
119 }
120
121 QPainterPath sigmaPath;
122 QPainterPath energyPath;
123 bool first = true;
124 for (const qpe::ObservablesTimeSeries2DSample &sample : samples_) {
125 const QPointF ps(mapX(sample.time), mapSigma(sample.sigmaX));
126 const QPointF pe(mapX(sample.time), mapEnergy(sample.totalEnergy));
127 if (first) {
128 sigmaPath.moveTo(ps);
129 energyPath.moveTo(pe);
130 first = false;
131 } else {
132 sigmaPath.lineTo(ps);
133 energyPath.lineTo(pe);
134 }
135 }
136
137 if (!first) {
138 painter.setPen(QPen(QColor(100, 220, 255), 2.2));
139 painter.drawPath(sigmaPath);
140 painter.setPen(QPen(QColor(255, 170, 105), 1.8));
141 painter.drawPath(energyPath);
142 } else {
143 painter.setPen(QColor(190, 195, 205));
144 painter.drawText(plotRect, Qt::AlignCenter,
145 QStringLiteral("Load Quantum Quench and press Play"));
146 }
147
148 painter.setPen(QColor(210, 215, 222));
149 painter.drawText(QRectF(plotRect.left(), 2.0, plotRect.width(), 20.0),
150 Qt::AlignCenter,
151 QStringLiteral("Quantum quench: width and total energy"));
152 painter.setPen(QColor(100, 220, 255));
153 painter.drawText(QRectF(plotRect.left() + 8.0, plotRect.top() + 5.0, 110.0, 18.0),
154 Qt::AlignLeft, QStringLiteral("sigmaX"));
155 painter.setPen(QColor(255, 170, 105));
156 painter.drawText(QRectF(plotRect.left() + 80.0, plotRect.top() + 5.0, 110.0, 18.0),
157 Qt::AlignLeft, QStringLiteral("<H>"));
158 painter.setPen(QColor(160, 168, 178));
159 painter.drawText(QRectF(plotRect.left(), plotRect.bottom() + 5.0,
160 plotRect.width(), 22.0),
161 Qt::AlignCenter, QStringLiteral("simulation time"));
162}
void setQuenchTime(double time)
Sets quench time.
QSize minimumSizeHint() const override
Performs minimum size hint.
std::vector< qpe::ObservablesTimeSeries2DSample > samples_
void setSamples(const std::vector< qpe::ObservablesTimeSeries2DSample > &samples)
Sets samples.
QuantumQuenchPlotWidget(QWidget *parent=nullptr)
Performs quantum quench plot widget.
void paintEvent(QPaintEvent *event) override
Paints event.
Declares the quantumquenchplotwidget visualization component used by QPE.
Data record containing Observables Time Series2D Sample.