-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathjunction.cpp
More file actions
134 lines (105 loc) · 3.96 KB
/
junction.cpp
File metadata and controls
134 lines (105 loc) · 3.96 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
/* EPANET 3
*
* Copyright (c) 2016 Open Water Analytics
* Distributed under the MIT License (see the LICENSE file for details).
*
*/
#include "junction.h"
#include "emitter.h"
#include "qualsource.h"
#include "Core/network.h"
#include "Core/constants.h"
#include "Models/demandmodel.h"
using namespace std;
//-----------------------------------------------------------------------------
// Junction Constructor
//-----------------------------------------------------------------------------
Junction::Junction(string name_):
Node(name_),
pMin(MISSING),
pFull(MISSING),
emitter(nullptr)
{
}
//-----------------------------------------------------------------------------
// Junction Destructor
//-----------------------------------------------------------------------------
Junction::~Junction()
{
demands.clear();
delete emitter;
}
//-----------------------------------------------------------------------------
// Convert junction properties from user's input units to internal units
// (called after loading network data from an input file)
//-----------------------------------------------------------------------------
void Junction::convertUnits(Network* nw)
{
// ... convert elevation & initial quality units
elev /= nw->ucf(Units::LENGTH);
initQual /= nw->ucf(Units::CONCEN);
// ... if no demand categories exist, add primary demand to list
if (demands.size() == 0) demands.push_back(primaryDemand);
// ... convert flow units for base demand in each demand category
double qcf = nw->ucf(Units::FLOW);
for (Demand& demand : demands)
{
demand.baseDemand /= qcf;
}
// ... convert emitter flow units
if (emitter) emitter->convertUnits(nw);
// ... use global pressure limits if no local limits assigned
if ( pMin == MISSING ) pMin = nw->option(Options::MINIMUM_PRESSURE);
if ( pFull == MISSING ) pFull = nw->option(Options::SERVICE_PRESSURE);
// ... convert units of pressure limits
double pUcf = nw->ucf(Units::PRESSURE);
pMin /= pUcf;
pFull /= pUcf;
}
//-----------------------------------------------------------------------------
// Initialize a junction's properties
//-----------------------------------------------------------------------------
void Junction::initialize(Network* nw)
{
head = elev + (pFull - pMin) / 2.0;;
quality = initQual;
if (qualSource) qualSource->quality = quality;
actualDemand = 0.0;
outflow = 0.0;
fixedGrade = false;
}
//-----------------------------------------------------------------------------
// Find a junction's full demand
//-----------------------------------------------------------------------------
void Junction::findFullDemand(double multiplier, double patternFactor)
{
fullDemand = 0.0;
for (Demand demand : demands)
{
fullDemand += demand.getFullDemand(multiplier, patternFactor);
}
actualDemand = fullDemand;
}
//-----------------------------------------------------------------------------
// Find a junction's actual demand flow and its derivative w.r.t. head
//-----------------------------------------------------------------------------
double Junction::findActualDemand(Network* nw, double h, double &dqdh)
{
return nw->demandModel->findDemand(this, h-elev, dqdh);
}
//-----------------------------------------------------------------------------
// Determine if there is not enough pressure to supply junction's demand
//-----------------------------------------------------------------------------
bool Junction::isPressureDeficient(Network* nw)
{
return nw->demandModel->isPressureDeficient(this);
}
//-----------------------------------------------------------------------------
// Find the outflow from a junction's emitter
//-----------------------------------------------------------------------------
double Junction::findEmitterFlow(double h, double& dqdh)
{
dqdh = 0.0;
if ( emitter) return emitter->findFlowRate(h-elev, dqdh);
return 0;
}