diff --git a/src/Elements/curve.cpp b/src/Elements/curve.cpp index 59ddcca..9ad6fd1 100644 --- a/src/Elements/curve.cpp +++ b/src/Elements/curve.cpp @@ -71,7 +71,7 @@ double Curve::getYofX(double x) { double dx = xData[i] - xData[i-1]; if ( dx == 0.0 ) return yData[i-1]; - return yData[i-1] + (x - yData[i-1]) / dx * (yData[i] - yData[i-1]); + return yData[i-1] + (x - xData[i-1]) / dx * (yData[i] - yData[i-1]); } } return yData[xData.size()-1]; diff --git a/src/Input/linkparser.cpp b/src/Input/linkparser.cpp index 8e94104..4841578 100644 --- a/src/Input/linkparser.cpp +++ b/src/Input/linkparser.cpp @@ -201,10 +201,10 @@ void LinkParser::parseReaction(Link* link, int type, vector& tokenList) throw InputError(InputError::INVALID_NUMBER, tokens[1]); } - // ... save reaction coeff. converted to 1/sec + // ... save reaction coeff. - if (type == Link::BULK) pipe->bulkCoeff = x / SECperDAY; - else if (type == Link::WALL) pipe->wallCoeff = x / SECperDAY; + if (type == Link::BULK) pipe->bulkCoeff = x; + else if (type == Link::WALL) pipe->wallCoeff = x; } //----------------------------------------------------------------------------- diff --git a/src/Input/nodeparser.cpp b/src/Input/nodeparser.cpp index 5a40b2b..51158dc 100644 --- a/src/Input/nodeparser.cpp +++ b/src/Input/nodeparser.cpp @@ -224,14 +224,10 @@ void NodeParser::parseTankReact(Node* node, vector& tokenList) // ... read reaction coefficient in 1/days - if ( !Utilities::parseNumber(tokens[1], tank->bulkCoeff) ) + if ( !Utilities::parseNumber(tokens[2], tank->bulkCoeff) ) { - throw InputError(InputError::INVALID_NUMBER, tokens[1]); + throw InputError(InputError::INVALID_NUMBER, tokens[2]); } - - // ... convert coefficient to 1/sec - - tank->bulkCoeff /= 86400; } //----------------------------------------------------------------------------- diff --git a/src/Input/optionparser.cpp b/src/Input/optionparser.cpp index 822be2a..e34d510 100644 --- a/src/Input/optionparser.cpp +++ b/src/Input/optionparser.cpp @@ -471,25 +471,24 @@ void OptionParser::parseQualOption(const string& s2, const string& s3, network->options.setOption(Options::QUAL_UNITS, Options::MGL); } - if ( !s3.empty() ) + if (network->option(Options::QUAL_TYPE) == Options::TRACE) { - if ( network->option(Options::QUAL_TYPE) == Options::TRACE ) - { - int nodeIndex = network->indexOf(Element::NODE, s3); - if (i < 0) throw InputError(InputError::UNDEFINED_OBJECT, s3); - network->options.setOption(Options::TRACE_NODE, nodeIndex); - network->options.setOption(Options::TRACE_NODE_NAME, s3); - } - if ( network->option(Options::QUAL_TYPE) == Options::CHEM ) - { - string s3U = Utilities::upperCase(s3); - if ( s3U.compare("MG/L") == 0 ) - network->options.setOption(Options::QUAL_UNITS, Options::MGL); - else if ( s3U.compare("UG/L") == 0 ) - network->options.setOption(Options::QUAL_UNITS, Options::UGL); - else throw InputError(InputError::INVALID_KEYWORD, s3); - } - } + if (s3.empty()) throw InputError(InputError::UNDEFINED_OBJECT, s3); + int nodeIndex = network->indexOf(Element::NODE, s3); + if (nodeIndex < 0) throw InputError(InputError::UNDEFINED_OBJECT, s3); + network->options.setOption(Options::TRACE_NODE, nodeIndex); + network->options.setOption(Options::TRACE_NODE_NAME, s3); + } + + if (network->option(Options::QUAL_TYPE) == Options::CHEM && !s3.empty()) + { + string s3U = Utilities::upperCase(s3); + if (s3U.compare("MG/L") == 0) + network->options.setOption(Options::QUAL_UNITS, Options::MGL); + else if (s3U.compare("UG/L") == 0) + network->options.setOption(Options::QUAL_UNITS, Options::UGL); + else throw InputError(InputError::INVALID_KEYWORD, s3); + } } //----------------------------------------------------------------------------- diff --git a/src/Models/qualmodel.cpp b/src/Models/qualmodel.cpp index a9a3816..f1309b9 100644 --- a/src/Models/qualmodel.cpp +++ b/src/Models/qualmodel.cpp @@ -60,6 +60,7 @@ ChemModel::ChemModel() : QualModel(CHEM) wallOrder = 1.0; // pipe wall reaction order pipeUcf = 1.0; // volume conversion factor for pipes tankUcf = 1.0; // volume conversion factor for tanks + wallUcf = 1.0; // wall reaction coefficient conversion factor for pipes cLimit = 0.001; // min/max concentration limit (mass/ft3) } @@ -80,6 +81,13 @@ void ChemModel::init(Network* nw) pipeUcf = pow(LperFT3, (1.0 - pipeOrder)); tankUcf = pow(LperFT3, (1.0 - tankOrder)); + // wall reaction coefficient conversion + double ucf = nw->ucf(Units::LENGTH); + if (wallOrder == 0) + wallUcf = ucf * ucf; + else + wallUcf = 1.0 / ucf; + // save diffusuivity, viscosity & Schmidt number diffus = nw->option(Options::MOLEC_DIFFUSIVITY); viscos = nw->option(Options::KIN_VISCOSITY); @@ -163,7 +171,7 @@ double ChemModel::pipeReact(Pipe* pipe, double c, double tstep) double kb = pipe->bulkCoeff / SECperDAY; if ( kb != 0.0 ) dCdT = findBulkRate(kb, pipeOrder, c) * pipeUcf; - double kw = pipe->wallCoeff / SECperDAY; + double kw = pipe->wallCoeff / SECperDAY * wallUcf; if ( kw != 0.0 ) dCdT += findWallRate(kw, pipe->diameter, wallOrder, c); c = c + dCdT * tstep; diff --git a/src/Models/qualmodel.h b/src/Models/qualmodel.h index f1ad0fe..9c8e512 100644 --- a/src/Models/qualmodel.h +++ b/src/Models/qualmodel.h @@ -88,6 +88,7 @@ class ChemModel : public QualModel double massTransCoeff; // a pipe's mass transfer coeff. (ft/sec) double pipeUcf; // volume conversion factor for pipes double tankUcf; // volume conversion factor for tanks + double wallUcf; // wall reaction coefficient conversion factor for pipes double cLimit; // min/max concentration limit (mass/ft3) bool setReactive(Network* nw); diff --git a/src/Models/tankmixmodel.cpp b/src/Models/tankmixmodel.cpp index dfd28c1..f873dd6 100644 --- a/src/Models/tankmixmodel.cpp +++ b/src/Models/tankmixmodel.cpp @@ -46,10 +46,10 @@ void TankMixModel::init(Tank* tank, SegPool* segPool, double _cTol) vMixed = fracMixed * tank->maxVolume; // ... create a volume segment for the entire tank - lastSeg = nullptr; firstSeg = segPool->getSegment(tank->volume, cTank); if ( firstSeg == nullptr ) throw SystemError(SystemError::OUT_OF_MEMORY); + lastSeg = firstSeg; // ... create a second segment for the 2-compartment model if ( type == MIX2 ) diff --git a/src/Utilities/utilities.cpp b/src/Utilities/utilities.cpp index 7a53c96..0687d66 100644 --- a/src/Utilities/utilities.cpp +++ b/src/Utilities/utilities.cpp @@ -233,10 +233,10 @@ int Utilities::getSeconds(const string& strTime, const string& strUnits) // determine time units and convert time accordingly - if (match(strUnits, s_Day) == 0) return (int) (3600. * 24. * t); - if (match(strUnits, s_Hour) == 0) return (int) (3600. * t); - if (match(strUnits, s_Minute) == 0) return (int) (60. * t); - if (match(strUnits, s_Second) == 0) return (int) t; + if (match(strUnits, s_Day)) return (int) (3600. * 24. * t); + if (match(strUnits, s_Hour)) return (int) (3600. * t); + if (match(strUnits, s_Minute)) return (int) (60. * t); + if (match(strUnits, s_Second)) return (int) t; // if AM/PM supplied, time is in hours and adjust it accordingly