-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
110 lines (91 loc) · 3.93 KB
/
main.cpp
File metadata and controls
110 lines (91 loc) · 3.93 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
#include <QApplication>
#include <QMainWindow>
#include <QWidget>
#include <QVBoxLayout>
#include <QLabel>
#include <QSlider>
#include <QDoubleSpinBox>
#include <QTimer>
#include <QPushButton>
#include "reactor.h" // Assuming reactorcore.h contains the ReactorCore class definition
class ReactorWindow : public QMainWindow {
Q_OBJECT
public:
ReactorWindow() : reactor(1.0, 300.0, 0.5, 290.0) {
setWindowTitle("Basic Reactor Simulator");
centralWidget = new QWidget;
setCentralWidget(centralWidget);
layout = new QVBoxLayout(centralWidget);
fluxLabel = new QLabel("Neutron Flux: 0.0");
tempLabel = new QLabel("Reactor Temperature: 0.0 K");
powerLabel = new QLabel("Power Level: 0.0 MW");
coolantInLabel = new QLabel("Coolant Inlet Temp: 0.0 K");
coolantOutLabel = new QLabel("Coolant Outlet Temp: 0.0 K");
QPushButton *startupButton = new QPushButton("Startup Ignition")
controlRodSlider = new QSlider(Qt::Horizontal);
controlRodSlider->setRange(0, 100); // Representing 0% to 100% insertion
controlRodLabel = new QLabel("Control Rod Insertion: 50%");
coolantInSpinBox = new QDoubleSpinBox();
coolantInSpinBox->setRange(273.15, 400.0); // Example temperature range
coolantInSpinBox->setSuffix(" K");
coolantInLabelEdit = new QLabel("Coolant Inlet Temperature:");
layout->addWidget(fluxLabel);
layout->addWidget(tempLabel);
layout->addWidget(powerLabel);
layout->addWidget(coolantInLabel);
layout->addWidget(coolantOutLabel);
layout->addWidget(controlRodLabel);
layout->addWidget(controlRodSlider);
layout->addWidget(coolantInLabelEdit);
layout->addWidget(coolantInSpinBox);
layout->addWidget(startupButton);
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &ReactorWindow::updateSimulation);
timer->start(100); // Update every 100 milliseconds
connect(controlRodSlider, &QSlider::valueChanged, this, &ReactorWindow::onControlRodChanged);
connect(coolantInSpinBox, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &ReactorWindow::onCoolantInletChanged);
connect(startupButton, &QPushButton::clicked, this, &ReactorCore::setReactorStartupStatus);
updateLabels();
}
private slots:
void updateSimulation() {
reactor.update(0.1); // Simulate for 0.1 seconds per update
updateLabels();
}
void onControlRodChanged(int value) {
double insertion = static_cast<double>(value) / 100.0;
reactor.setControlRodInsertion(insertion);
controlRodLabel->setText(QString("Control Rod Insertion: %1%").arg(value));
}
void onCoolantInletChanged(double temp) {
reactor.setCoolantInletTemperature(temp);
}
private:
ReactorCore reactor;
QWidget* centralWidget;
QVBoxLayout* layout;
QLabel* fluxLabel;
QLabel* tempLabel;
QLabel* powerLabel;
QLabel* coolantInLabel;
QLabel* coolantOutLabel;
QLabel* controlRodLabel;
QSlider* controlRodSlider;
QLabel* coolantInLabelEdit;
QDoubleSpinBox* coolantInSpinBox;
QTimer* timer;
void updateLabels() {
fluxLabel->setText(QString("Neutron Flux: %1").arg(reactor.neutronFlux, 0, 'g', 3));
tempLabel->setText(QString("Reactor Temperature: %1 K").arg(reactor.reactorTemperature, 0, 'f', 2));
powerLabel->setText(QString("Power Level: %1 MW").arg(reactor.powerLevel, 0, 'f', 2));
coolantInLabel->setText(QString("Coolant Inlet Temp: %1 K").arg(reactor.coolantInletTemperature, 0, 'f', 2));
coolantOutLabel->setText(QString("Coolant Outlet Temp: %1 K").arg(reactor.coolantOutletTemperature, 0, 'f', 2));
}
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
ReactorWindow window;
window.show();
return app.exec();
}
#include "main.moc" // Necessary for Qt's signal/slot mechanism