-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathqualsource.cpp
More file actions
124 lines (106 loc) · 3.48 KB
/
qualsource.cpp
File metadata and controls
124 lines (106 loc) · 3.48 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
/* EPANET 3
*
* Copyright (c) 2016 Open Water Analytics
* Licensed under the terms of the MIT License (see the LICENSE file for details).
*
*/
#include "qualsource.h"
#include "node.h"
#include "pattern.h"
#include "Core/constants.h"
#include <cmath>
#include <algorithm>
using namespace std;
const char* QualSource::SourceTypeWords[] =
{"CONCEN", "MASS", "FLOWPACED", "SETPOINT", 0};
//-----------------------------------------------------------------------------
QualSource::QualSource() :
type(CONCEN),
base(0.0),
pattern(nullptr),
strength(0.0),
outflow(0.0),
quality(0.0)
{}
QualSource::~QualSource()
{}
//-----------------------------------------------------------------------------
bool QualSource::addSource(Node* node, int t, double b, Pattern* p)
{
if ( node->qualSource == nullptr )
{
node->qualSource = new QualSource();
if ( node->qualSource == nullptr ) return false;
}
node->qualSource->type = t;
node->qualSource->base = b;
node->qualSource->pattern = p;
node->qualSource->quality = 0.0;
node->qualSource->outflow = 0.0;
return true;
}
//-----------------------------------------------------------------------------
void QualSource::setStrength(Node* node)
{
strength = base;
if ( pattern ) strength *= pattern->currentFactor();
if ( type == MASS ) strength /= 60.0; // mass/min -> mass/sec
else strength /= FT3perL; // mass/L -> mass/ft3
}
//-----------------------------------------------------------------------------
double QualSource::getQuality(Node* node)
{
// ... no source contribution if no flow out of node
quality = node->quality;
if (abs(outflow) <= ZERO_FLOW)
{
if (node->type() == Node::JUNCTION && node->outflow < 0.0)
{
if (type == MASS) quality = strength * 60.0; // mass/sec -> mass/min
else quality = strength;
}
return quality;
}
switch (type)
{
case CONCEN:
switch (node->type())
{
// ... for junctions, outflow quality is the node's quality plus the
// source's quality times the fraction of outflow to the network
// contributed by external inflow (i.e., negative demand)
// NOTE: qualSource.outflow is flow in links leaving the node,
// node->outflow is node's external outflow (demands, etc.)
case Node::JUNCTION:
if ( node->outflow < 0.0 )
{
quality += strength * (-node->outflow / outflow);
}
break;
// ... for tanks, the outflow quality is the larger of the
// tank's value and the source's value
case Node::TANK:
quality = max(quality, strength);
break;
// ... for reservoirs, outflow quality equals the source strength
case Node::RESERVOIR:
quality = strength;
break;
}
break;
case MASS:
// ... outflow quality is node's quality plus the source's
// mass flow rate divided by the node's outflow to the network
quality += strength / outflow;
break;
case SETPOINT:
// ... outflow quality is larger of node quality and setpoint strength
quality = max(quality, strength);
break;
case FLOWPACED:
// ... outflow quality is node's quality + source's strength
quality += strength;
break;
}
return quality;
}