-
Notifications
You must be signed in to change notification settings - Fork 5
/
decoupledmodel.h
137 lines (101 loc) · 4.71 KB
/
decoupledmodel.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
/*
* 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 DECOUPLEDMODEL_H
#define DECOUPLEDMODEL_H
#include "model.h"
#include "realvariable.h"
#include "binaryvariable.h"
#include "intvariable.h"
#include "constraint.h"
namespace ResOpt
{
class InputRateVariable;
class MaterialBalanceConstraint;
class ProductionWell;
class MidPipe;
class Separator;
class Stream;
/**
* @brief Model where input rates to all parts of the system are treated as variables.
* @details In this type of Model there is no automatic link between the output of a upstream part and the input to a downstream part. The input rates to every pipe segment in the Model
* is included as a variable. Constraints are included to honour the mass balance in the system (c = q_in - q_out = 0).
*
*/
class DecoupledModel : public Model
{
private:
QVector<shared_ptr<BinaryVariable> > m_vars_binary; // vector containing all binary variables
QVector<shared_ptr<RealVariable> > m_vars_real; // vector containing all real variables
QVector<shared_ptr<IntVariable> > m_vars_integer; // vector containing all integer variables
QVector<shared_ptr<Constraint> > m_cons; // vector containing all the constraints
QVector<InputRateVariable*> m_rate_vars; // all the varaibles for rate input to the different parts of the model
QVector<MaterialBalanceConstraint*> m_mb_cons; // constraints associated with the input rate variables for mass balance feasibility
void initializeVarsAndCons();
/**
* @brief Adds the streams flowing from this well to the streams in the asociated material balance constraints
*
* @param w
*/
void addToMaterialBalanceStreamsUpstream(ProductionWell *w);
/**
* @brief Adds the streams flowing from this pipe to the streams in the asociated material balance constraints
*
* @param p
*/
void addToMaterialBalanceStreamsUpstream(MidPipe *p, Well *from_well, double flow_frac);
/**
* @brief Adds the streams flowing from this separator to the streams in the asociated material balance constraints
*
* @param s
*/
void addToMaterialBalanceStreamsUpstream(Separator *s, Well *from_well, double flow_frac);
/**
* @brief Updates all the streams in the material balance constraints
*
*/
void updateMaterialBalanceStreams();
MaterialBalanceConstraint* find(Stream *s);
public:
DecoupledModel();
DecoupledModel(const DecoupledModel &m);
virtual ~DecoupledModel();
// virtual functions
virtual Model* clone() const {return new DecoupledModel(*this);}
virtual QString description() const {return QString("DECOUPLED MODEL\n\n");}
virtual void initialize();
virtual void process();
virtual void updateStreams();
virtual bool updateConstraints();
virtual QVector<shared_ptr<BinaryVariable> >& binaryVariables(bool force_refresh = false);
virtual QVector<shared_ptr<RealVariable> >& realVariables(bool force_refresh = false);
virtual QVector<shared_ptr<IntVariable> >& integerVariables(bool force_refresh = false);
virtual QVector<shared_ptr<Constraint> >& constraints(bool force_refresh = false);
virtual QVector<shared_ptr<RealVariable> > realVariables(Component *c);
virtual int numberOfRealVariables() const {return m_vars_real.size();}
virtual int numberOfBinaryVariables() const {return m_vars_binary.size();}
virtual int numberOfIntegerVariables() const {return m_vars_integer.size();}
virtual int numberOfConstraints() const {return m_cons.size();}
virtual double realVariableValue(int i) const {return m_vars_real.at(i)->value();}
virtual double binaryVariableValue(int i) const {return m_vars_binary.at(i)->value();}
virtual double integerVariableValue(int i) const {return m_vars_integer.at(i)->value();}
virtual double constraintValue(int i) const {return m_cons.at(i)->value();}
};
} // namespace ResOpt
#endif // DECOUPLEDMODEL_H