-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodel.h
452 lines (327 loc) · 10.5 KB
/
model.h
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
* This file is part of the ResOpt project.
*
* Copyright (C) 2011-2012 Aleksander O. Juell <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MODEL_H
#define MODEL_H
#include <QString>
#include <QVector>
#include <tr1/memory>
using std::tr1::shared_ptr;
/**
* @brief This namespace is used for all core elements.
*/
namespace ResOpt
{
class Well;
class Reservoir;
class Objective;
class Pipe;
class Capacity;
class IntVariable;
class RealVariable;
class BinaryVariable;
class Constraint;
class Component;
class UserConstraint;
class Cost;
class Logger;
/**
* @brief Abstract base class for Models.
* @details The Model stores all the sub-parts of the problem (wells, pipes, separators, etc).
*
*/
class Model
{
private:
Reservoir *p_reservoir; /**< TODO */
QVector<Well*> m_wells; /**< TODO */
QVector<Pipe*> m_pipes;
QVector<Capacity*> m_capacities;
Objective *p_obj;
QVector<double> m_master_schedule;
QVector<UserConstraint*> m_user_constraints;
bool m_up_to_date; // true if the model has been evaluated
QString m_driver_path;
Logger *p_logger;
/**
* @brief Updates the capacity constraints for all the Capacities in the model.
* @details This function calls in turn Capacity::updateConstraints() on all the capacities.
*
* @return bool
*/
bool updateCapacityConstraints();
/**
* @brief Updates the BHP and connection constraints on the Wells
*
* @return bool
*/
bool updateWellConstaints();
/**
* @brief Updates the pipe connnection constraints
*
* @return bool
*/
bool updatePipeConstraints();
bool updateBoosterConstraints();
/**
* @brief Updates the user defined constraints
*
* @return bool
*/
bool updateUserDefinedConstraints();
QVector<Cost*> sortCosts(QVector<Cost*> c);
public:
Model();
Model(const Model &m);
virtual ~Model();
// virtual functions
virtual QString description() const = 0;
/**
* @brief Calcuates the entire upstream part of the model
* @details This function updates the streams in the pipe network, calculates pressures,
* updates constraint values and objective.
*
*/
virtual void process() = 0;
/**
* @brief Updates the streams in the pipe network.
*
*/
virtual void updateStreams() = 0;
/**
* @brief Returns a clone of this model.
*
* @return Model
*/
virtual Model* clone() const = 0;
/**
* @brief Returns a vector containing all integer variables defined within the model.
* @details These are all the routing variables for the model.
*
* @return QVector<BinaryVariable *>
*/
virtual QVector<shared_ptr<BinaryVariable> >& binaryVariables(bool force_refresh = false) = 0;
/**
* @brief Returns a vector containing all the real variables defined within the model.
* @details These are all the well control variables.
*
* @return QVector<RealVariable *>
*/
virtual QVector<shared_ptr<RealVariable> >& realVariables(bool force_refresh = false) = 0;
/**
* @brief Returns a vector containing all the integer variables.
* @details These are the install time variables for the separators.
*
* @return QVector<shared_ptr<IntVariable> >
*/
virtual QVector<shared_ptr<IntVariable> >& integerVariables(bool force_refresh = false) = 0;
/**
* @brief Returns a vector containing all the constraints defined within the model.
* @details The constraints include well BHP constraints and capasity constraints
*
* @return QVector<Constraint *>
*/
virtual QVector<shared_ptr<Constraint> >& constraints(bool force_refresh = false) = 0;
/**
* @brief Returns a vector of the real variables associated with the Component c.
*
* @param c
* @return QVector<shared_ptr<RealVariable> >
*/
virtual QVector<shared_ptr<RealVariable> > realVariables(Component *c) = 0;
/**
* @brief Initializes the model.
* @detials This function sets up the constraints associated with production wells and separators, and connects the pipe network
* to the wells and separators. The function must be called before the model is used for anything.
*
*/
virtual void initialize() = 0;
/**
* @brief Updates the value of all constraints in the model.
*
* @return bool
*/
virtual bool updateConstraints() = 0;
virtual int numberOfRealVariables() const = 0;
virtual int numberOfBinaryVariables() const = 0;
virtual int numberOfIntegerVariables() const = 0;
virtual int numberOfConstraints() const = 0;
virtual double realVariableValue(int i) const = 0;
virtual double binaryVariableValue(int i) const = 0;
virtual double integerVariableValue(int i) const = 0;
virtual double constraintValue(int i) const = 0;
// misc functions
/**
* @brief Makes sure that the Model is set up propperly.
* @details This function should be called before the Model is used for anything. It checks that all the sub parts of the Model
* are defined, that the master schedule corresponds to the schedule of all the wells, etc.
*
* @return bool
*/
bool validate();
/**
* @brief Checks the current routing of wells and pipes, and connects them correctly.
* @details Wells and Pipes may have an OUTLETPIPE defined. This is either a fixed number, or a routing variable.
* This function tries to resolve the current value of the OUTLETPIPE to a NUMBER assigned to a Pipe.
*
* @return true if successful, false if not resolved
*/
bool resolvePipeRouting();
/**
* @brief Translates the input PIPE numbers given in the driver file to pointers to Pipes.
* @details This functions should only be called once, before the optimization starts. The input pipes to a given Capacity are fixed.
*
* @return bool
*/
bool resolveCapacityConnections();
/**
* @brief Calculates the pressure drops in all the pipes
*
* @return bool
*/
bool calculatePipePressures();
/**
* @brief Reads the pipe pressure drop definition files for all pipes in the model.
* @details These are the files speficied with the FILE keyword in the main driver file.
*
*/
void readPipeFiles();
/**
* @brief Updates the value of the Objective from the current Streams of all the wells in the model.
*
*/
void updateObjectiveValue();
/**
* @brief Updates the value of the constraints that are common for all model types
*
*/
bool updateCommonConstraints();
// set functions
void setMasterSchedule(const QVector<double> &schedule) {m_master_schedule = schedule;}
/**
* @brief Sets the Reservoir
*
* @param r
*/
void setReservoir(Reservoir *r) {p_reservoir = r;}
/**
* @brief Sets the Objective
*
* @param o
*/
void setObjective(Objective *o) {p_obj = o;}
void setUpToDate(bool b) {m_up_to_date = b;}
void setDriverPath(const QString &path) {m_driver_path = path;}
// add functions
/**
* @brief Adds a Well to the model
*
* @param w
*/
void addWell(Well *w) {m_wells.push_back(w);}
/**
* @brief Adds a Pipe to the model
*
* @param p
*/
void addPipe(Pipe *p) {m_pipes.push_back(p);}
/**
* @brief Adds a Capacity to the model
*
* @param s
*/
void addCapacity(Capacity *s) {m_capacities.push_back(s);}
/**
* @brief Adds a user defined constraint to the model
*
* @param uc
*/
void addUserDefinedConstraint(UserConstraint *uc) {m_user_constraints.push_back(uc);}
// get functions
const QString& driverPath() {return m_driver_path;}
int numberOfMasterScheduleTimes() const {return m_master_schedule.size();}
double masterScheduleTime(int i) const {return m_master_schedule.at(i);}
QVector<double>& masterSchedule() {return m_master_schedule;}
/**
* @brief Returns the Reservoir
*
* @return Reservoir
*/
Reservoir* reservoir() const {return p_reservoir;}
/**
* @brief Returns well number i
*
* @param i
* @return Well
*/
Well* well(int i) const {return m_wells.at(i);}
/**
* @brief Returns the total number of wells defined in the model
*
* @return int
*/
int numberOfWells() const {return m_wells.size();}
/**
* @brief Returns the well with the specified id, 0 if not found
*
* @param id
* @return Well
*/
Well* wellById(int comp_id);
Well* wellByName(const QString &name);
/**
* @brief Returns Pipe number i
*
* @param i
* @return Pipe
*/
Pipe* pipe(int i) const {return m_pipes.at(i);}
/**
* @brief Returns the total number of pipes defined in the model
*
* @return int
*/
int numberOfPipes() const {return m_pipes.size();}
/**
* @brief Returns Capacity number i
*
* @param i
* @return Capacity
*/
Capacity* capacity(int i) {return m_capacities.at(i);}
/**
* @brief Returns the total number of capacities defined in the model
*
* @return int
*/
int numberOfCapacities() const {return m_capacities.size();}
UserConstraint* userDefinedConstraint(int i) {return m_user_constraints.at(i);}
int numberOfUserDefinedConstraints() {return m_user_constraints.size();}
Logger* logger() {return p_logger;}
/**
* @brief Returns the Objective
*
* @return Objective
*/
Objective* objective() {return p_obj;}
bool isUpToDate() const {return m_up_to_date;}
Model& operator=(const Model &rhs);
};
} // namespace ResOpt
#endif // MODEL_H