-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix several quality source issues #65
base: develop
Are you sure you want to change the base?
fix several quality source issues #65
Conversation
1. the junction and tank's source quality has not been initialized 2. for MASS Booster quality source type, converting mass flow rate from min. to sec. uses strength *= 60.0, which should be strength /= 60.0 3. in QualSource::getQuality method, to determine if there is no flow out of node, now it uses "==0.0", which should use ZERO_FLOW as instead 4. no source contribution if no flow out of node, but for inflow junction, the source contribution should be the source quality 5. the inflow junction's constituent concentration has not been updated if the junction has Quality Source in LTDSolver::updateNodeQuality method
@@ -82,6 +83,7 @@ void Junction::initialize(Network* nw) | |||
{ | |||
head = elev + (pFull - pMin) / 2.0;; | |||
quality = initQual; | |||
if (qualSource) qualSource->quality = quality; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialize the source quality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to initialize qualSource->quality
. This variable is assigned locally in QualSource::getQuality
.
@@ -107,6 +108,7 @@ void Tank::initialize(Network* nw) | |||
outflow = 0.0; | |||
pastOutflow = 0.0; | |||
quality = initQual; | |||
if (qualSource) qualSource->quality = quality; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
initialize the source quality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, there is no need to initialize qualSource->quality
here.
@@ -54,7 +54,7 @@ void QualSource::setStrength(Node* node) | |||
{ | |||
strength = base; | |||
if ( pattern ) strength *= pattern->currentFactor(); | |||
if ( type == MASS ) strength *= 60.0; // mass/min -> mass/sec | |||
if ( type == MASS ) strength /= 60.0; // mass/min -> mass/sec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
converting mass flow rate from min. to sec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is correct - thank you.
@@ -64,7 +64,15 @@ double QualSource::getQuality(Node* node) | |||
{ | |||
// ... no source contribution if no flow out of node | |||
quality = node->quality; | |||
if ( outflow == 0.0 ) return quality; | |||
if (abs(outflow) <= ZERO_FLOW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ZERO_FLOW to determine the stagnant flow but not 0.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a major problem with the original code here -- the value of QualSource::outflow
is never assigned anywhere. To fix this one has to:
- Add the following line to ltdsolver.h:
std::vector<double> qOut; // flow in links leaving each node
- Add the following to the top of LTDSolver::solve:
memset(&qOut, 0, nodeCount*sizeof(double));
for (int i = 0; i < linkCount; i++)
{
Link* link = network->link(i);
double q = link->flow;
int j = link->fromNode->index;
if ( q < 0.0 ) j = link->toNode->index;
qOut[j] += abs(q);
}
- Add the following to LTDSolver::release:
// ... modify node quality c to include any source input
if ( node->qualSource && network->qualModel->type == QualModel::CHEM )
{
node->qualSource->outflow = qOut[node->index]; //new line here
c = node->qualSource->getQuality(node);
. . .
if ( outflow == 0.0 ) return quality; | ||
if (abs(outflow) <= ZERO_FLOW) | ||
{ | ||
if (node->type() == Node::JUNCTION && node->outflow < 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for inflow junction, the source contribution should be the source quality
@@ -308,7 +308,7 @@ void LTDSolver::updateNodeQuality() | |||
if ( node->type() == Node::JUNCTION ) | |||
{ | |||
// ... account for dilution from any external negative demand | |||
if (node->outflow < 0.0 && node->qualSource == nullptr ) | |||
if (node->outflow < 0.0 && node->qualSource != nullptr ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update the concentration if the inflow junction has Quality Source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not correct. The dilution occurs only for external inflows at nodes with no WQ source. For nodes with WQ sources the mixing of the external inflow with the node's current quality is handled in QualSource::getQuality
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my individual comments to your changes.
@@ -82,6 +83,7 @@ void Junction::initialize(Network* nw) | |||
{ | |||
head = elev + (pFull - pMin) / 2.0;; | |||
quality = initQual; | |||
if (qualSource) qualSource->quality = quality; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to initialize qualSource->quality
. This variable is assigned locally in QualSource::getQuality
.
@@ -54,7 +54,7 @@ void QualSource::setStrength(Node* node) | |||
{ | |||
strength = base; | |||
if ( pattern ) strength *= pattern->currentFactor(); | |||
if ( type == MASS ) strength *= 60.0; // mass/min -> mass/sec | |||
if ( type == MASS ) strength /= 60.0; // mass/min -> mass/sec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is correct - thank you.
@@ -64,7 +64,15 @@ double QualSource::getQuality(Node* node) | |||
{ | |||
// ... no source contribution if no flow out of node | |||
quality = node->quality; | |||
if ( outflow == 0.0 ) return quality; | |||
if (abs(outflow) <= ZERO_FLOW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There appears to be a major problem with the original code here -- the value of QualSource::outflow
is never assigned anywhere. To fix this one has to:
- Add the following line to ltdsolver.h:
std::vector<double> qOut; // flow in links leaving each node
- Add the following to the top of LTDSolver::solve:
memset(&qOut, 0, nodeCount*sizeof(double));
for (int i = 0; i < linkCount; i++)
{
Link* link = network->link(i);
double q = link->flow;
int j = link->fromNode->index;
if ( q < 0.0 ) j = link->toNode->index;
qOut[j] += abs(q);
}
- Add the following to LTDSolver::release:
// ... modify node quality c to include any source input
if ( node->qualSource && network->qualModel->type == QualModel::CHEM )
{
node->qualSource->outflow = qOut[node->index]; //new line here
c = node->qualSource->getQuality(node);
. . .
@@ -107,6 +108,7 @@ void Tank::initialize(Network* nw) | |||
outflow = 0.0; | |||
pastOutflow = 0.0; | |||
quality = initQual; | |||
if (qualSource) qualSource->quality = quality; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, there is no need to initialize qualSource->quality
here.
@@ -308,7 +308,7 @@ void LTDSolver::updateNodeQuality() | |||
if ( node->type() == Node::JUNCTION ) | |||
{ | |||
// ... account for dilution from any external negative demand | |||
if (node->outflow < 0.0 && node->qualSource == nullptr ) | |||
if (node->outflow < 0.0 && node->qualSource != nullptr ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not correct. The dilution occurs only for external inflows at nodes with no WQ source. For nodes with WQ sources the mixing of the external inflow with the node's current quality is handled in QualSource::getQuality
.
fix several quality source issues: