Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Elements/junction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "junction.h"
#include "emitter.h"
#include "qualsource.h"
#include "Core/network.h"
#include "Core/constants.h"
#include "Models/demandmodel.h"
Expand Down Expand Up @@ -82,6 +83,7 @@ void Junction::initialize(Network* nw)
{
head = elev + (pFull - pMin) / 2.0;;
quality = initQual;
if (qualSource) qualSource->quality = quality;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize the source quality

Copy link
Collaborator

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.

actualDemand = 0.0;
outflow = 0.0;
fixedGrade = false;
Expand Down
12 changes: 10 additions & 2 deletions src/Elements/qualsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

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.

Copy link
Collaborator

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.

else strength /= FT3perL; // mass/L -> mass/ft3
}

Expand All @@ -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)
Copy link
Contributor Author

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.

Copy link
Collaborator

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:

  1. Add the following line to ltdsolver.h:
std::vector<double>    qOut;            // flow in links leaving each node
  1. 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);
    }
  1. 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 (node->type() == Node::JUNCTION && node->outflow < 0.0)
Copy link
Contributor Author

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

{
if (type == MASS) quality = strength * 60.0; // mass/sec -> mass/min
else quality = strength;
}
return quality;
}

switch (type)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Elements/tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "tank.h"
#include "curve.h"
#include "qualsource.h"
#include "Core/network.h"
#include "Core/constants.h"
#include "Core/error.h"
Expand Down Expand Up @@ -107,6 +108,7 @@ void Tank::initialize(Network* nw)
outflow = 0.0;
pastOutflow = 0.0;
quality = initQual;
if (qualSource) qualSource->quality = quality;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize the source quality

Copy link
Collaborator

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.

updateArea();
if ( volCurve ) minVolume = findVolume(minHead);
else if ( minVolume == 0.0 ) minVolume = (minHead - elev) * area;
Expand Down
2 changes: 1 addition & 1 deletion src/Solvers/ltdsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Copy link
Contributor Author

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

Copy link
Collaborator

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.

{
volIn[i] -= node->outflow * tstep;
}
Expand Down