-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathseparator.cpp
More file actions
151 lines (113 loc) · 5.02 KB
/
separator.cpp
File metadata and controls
151 lines (113 loc) · 5.02 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "separator.h"
#include <iostream>
#include "cost.h"
#include "pipeconnection.h"
#include "intvariable.h"
#include "realvariable.h"
#include "stream.h"
using std::cout;
using std::endl;
namespace ResOpt
{
Separator::Separator()
: m_type(WATER),
p_cost(0),
p_outlet_connection(0)
{
}
Separator::Separator(const Separator &s)
: Pipe(s)
{
// copying base types
m_type = s.m_type;
m_remaining_capacity = s.m_remaining_capacity;
// copying pointed objects
p_cost = new Cost(*s.p_cost);
p_outlet_connection = new PipeConnection(*s.p_outlet_connection);
// copying variables
p_install_time = shared_ptr<IntVariable>(new IntVariable(*s.p_install_time));
p_remove_fraction = shared_ptr<RealVariable>(new RealVariable(*s.p_remove_fraction));
p_remove_capacity = shared_ptr<RealVariable>(new RealVariable(*s.p_remove_capacity));
}
Separator::~Separator()
{
if(p_cost != 0) delete p_cost;
if(p_outlet_connection != 0) delete p_outlet_connection;
}
//-----------------------------------------------------------------------------------------------
// initializes the separator
//-----------------------------------------------------------------------------------------------
void Separator::initialize(const QVector<double> &schedule)
{
Pipe::initialize(schedule);
m_remaining_capacity.fill(p_remove_capacity->value(), schedule.size());
}
//-----------------------------------------------------------------------------------------------
// empties the streams, and resets the remaining capacities
//-----------------------------------------------------------------------------------------------
void Separator::emptyStreams()
{
Pipe::emptyStreams();
m_remaining_capacity.fill(p_remove_capacity->value());
}
//-----------------------------------------------------------------------------------------------
// reduces the remaining capacity for time step i
//-----------------------------------------------------------------------------------------------
void Separator::reduceRemainingCapacity(int i, double q)
{
double remaining = m_remaining_capacity.at(i);
remaining = (q > remaining) ? 0 : (remaining - q);
m_remaining_capacity.replace(i, remaining);
}
//-----------------------------------------------------------------------------------------------
// calculates the inlet pressure of the separator
//-----------------------------------------------------------------------------------------------
void Separator::calculateInletPressure()
{
// checking if the outlet connection is defined
if(p_outlet_connection == 0)
{
cout << endl << "### Runtime Error ###" << endl
<< "NO Outlet pipe set for SEPARATOR: " << number() << endl << endl;
exit(1);
}
// checking if outlet pipe have the same number of streams
if(numberOfStreams() != outletConnection()->pipe()->numberOfStreams())
{
cout << endl << "### Runtime Error ###" << endl
<< "Separator and upstream pipe do not have the same number of time steps..." << endl
<< "SEPARATOR : " << number() << ", n = " << numberOfStreams() << endl
<< "Upstream PIPE: " << outletConnection()->pipe()->number() << ", n = " << outletConnection()->pipe()->numberOfStreams() << endl << endl;
exit(1);
}
// looping through the time steps
for(int i = 0; i < numberOfStreams(); i++)
{
// getting the outlet pressure
double p_out = outletConnection()->pipe()->stream(i)->pressure(stream(i)->inputUnits());
// setting inlet pressure = outlet pressure
stream(i)->setPressure(p_out);
}
}
//-----------------------------------------------------------------------------------------------
// generates a description for driver file
//-----------------------------------------------------------------------------------------------
QString Separator::description() const
{
QString str("START SEPARATOR\n");
str.append(" NUMBER " + QString::number(number()) + "\n");
str.append(" TYPE ");
if(type() == WATER) str.append("WATER\n");
else if(type() == GAS) str.append("GAS\n");
if(p_install_time != 0)
{
str.append(" INSTALLTIME " + QString::number(p_install_time->value()) + " " + QString::number(p_install_time->max()) + " " + QString::number(p_install_time->min()) + "\n");
}
str.append(" COST " + QString::number(p_cost->constantCost()) + " " + QString::number(p_cost->fractionCost()) + " " + QString::number(p_cost->capacityCost()) + "\n");
str.append(" OUTLETPIPE " + QString::number(p_outlet_connection->pipeNumber()) + "\n");
str.append(" REMOVE " + QString::number(p_remove_fraction->value()) + " " + QString::number(p_remove_fraction->max()) + " " + QString::number(p_remove_fraction->min()) + "\n");
str.append(" CAPACITY " + QString::number(p_remove_capacity->value()) + " " + QString::number(p_remove_capacity->max()) + " " + QString::number(p_remove_capacity->min()) + "\n");
str.append("END SEPARATOR\n\n");
return str;
}
} // namespace ResOpt