-
Notifications
You must be signed in to change notification settings - Fork 1
/
tank.cpp
112 lines (94 loc) · 1.97 KB
/
tank.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "tank.h"
#include "math.h"
//#define PI (3.141592653589793)
#define PI 1
Tank::Tank(QObject *parent) :
QObject(parent)
{
}
qreal Tank::height(void) {
return m_height;
}
void Tank::setHeight(qreal h){
if(h!=m_height){
m_height=h;
emit heightChanged();
}
}
qreal Tank::radius(void) {
return m_radius;
}
void Tank::setRadius(qreal r){
if( r != m_radius){
m_radius=r;
emit radiusChanged();
}
}
qreal Tank::capacity(void) {
m_capacity = PI*m_radius*m_radius*m_height/1000;
return m_capacity;
}
qreal Tank::volume(void){
m_volume=PI*m_radius*m_radius*m_level/1000;
return m_volume;
}
qreal Tank::level(void){
return m_level;
}
void Tank::setLevel(qreal l){
if (l>=m_height){
m_level=m_height;
}else{
m_level=l;
}
emit levelChanged();
}
qreal Tank::temperature(void){
return m_temperature;
}
void Tank::setTemperature(qreal t){
if(t!=m_temperature){
m_temperature=t;
emit temperatureChanged();
}
}
qreal Tank::density(void){
return m_density;
}
void Tank::setDensity(qreal d){
if(d!=m_density){
m_density=d;
emit densityChanged();
}
}
qreal Tank::heatCapacity(void){
return m_heatCapacity;
}
void Tank::setHeatCapacity(qreal hc){
m_heatCapacity=hc;
}
void Tank::inEnergy(qreal energy){
m_temperature+=(energy/(m_density*m_volume*m_heatCapacity*1000));
if(m_temperature>100){
m_temperature=100;
}
emit temperatureChanged();
}
// Insert volumes of liquid in the tank
void Tank::inFlow(qreal flow){
m_level+=(flow/(PI*m_radius*m_radius/100));
if (m_level>m_height){
m_level=m_height;
}
emit levelChanged();
}
// Throw out volumes of liquid of the tank
void Tank::outFlow(qreal flow){
if(m_temperature>0){
m_level-=(flow/(PI*m_radius*m_radius/100));
if (m_level<0){
m_level=0;
}
}
emit levelChanged();
}