Refactor tank mixing zone volume

Addresses issue #597.
This commit is contained in:
Lew Rossman
2020-07-11 17:12:49 -04:00
parent 71a733ed85
commit 951c7ce727
7 changed files with 14 additions and 22 deletions

View File

@@ -1847,7 +1847,7 @@ int DLLEXPORT EN_addnode(EN_Project p, char *id, int nodeType, int *index)
tank->Pat = 0; tank->Pat = 0;
tank->Vcurve = 0; tank->Vcurve = 0;
tank->MixModel = 0; tank->MixModel = 0;
tank->V1max = 10000; tank->V1frac = 1;
tank->CanOverflow = FALSE; tank->CanOverflow = FALSE;
} }
net->Nnodes++; net->Nnodes++;
@@ -2164,7 +2164,9 @@ int DLLEXPORT EN_getnodevalue(EN_Project p, int index, int property, double *val
case EN_MIXZONEVOL: case EN_MIXZONEVOL:
v = 0.0; v = 0.0;
if (index > nJuncs) v = Tank[index - nJuncs].V1max * Ucf[VOLUME]; if (index > nJuncs)
v = Tank[index - nJuncs].V1frac * Tank[index - nJuncs].Vmax *
Ucf[VOLUME];
break; break;
case EN_DEMAND: case EN_DEMAND:
@@ -2224,9 +2226,9 @@ int DLLEXPORT EN_getnodevalue(EN_Project p, int index, int property, double *val
case EN_MIXFRACTION: case EN_MIXFRACTION:
v = 1.0; v = 1.0;
if (index > nJuncs && Tank[index - nJuncs].Vmax > 0.0) if (index > nJuncs)
{ {
v = Tank[index - nJuncs].V1max / Tank[index - nJuncs].Vmax; v = Tank[index - nJuncs].V1frac;
} }
break; break;
@@ -2293,7 +2295,6 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu
int i, j, n; int i, j, n;
Psource source; Psource source;
double hTmp; double hTmp;
double vTmp;
if (!p->Openflag) return 102; if (!p->Openflag) return 102;
if (index <= 0 || index > nNodes) return 203; if (index <= 0 || index > nNodes) return 203;
@@ -2418,9 +2419,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu
// shape below Hmin. Vmin can always be changed by setting // shape below Hmin. Vmin can always be changed by setting
// EN_MINVOLUME in a subsequent function call. // EN_MINVOLUME in a subsequent function call.
Tank[j].V0 = tankvolume(p, j, Tank[j].H0); // new init. volume Tank[j].V0 = tankvolume(p, j, Tank[j].H0); // new init. volume
vTmp = Tank[j].Vmax; // old max. volume
Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax); // new max. volume Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax); // new max. volume
Tank[j].V1max *= Tank[j].Vmax / vTmp; // new mix zone volume
break; break;
case EN_MINVOLUME: case EN_MINVOLUME:
@@ -2450,9 +2449,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu
// Since Vmin changes the other volumes need updating // Since Vmin changes the other volumes need updating
Tank[j].V0 = tankvolume(p, j, Tank[j].H0); // new init. volume Tank[j].V0 = tankvolume(p, j, Tank[j].H0); // new init. volume
vTmp = Tank[j].Vmax; // old max. volume
Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax); // new max. volume Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax); // new max. volume
Tank[j].V1max *= Tank[j].Vmax / vTmp; // new mix zone volume
} }
break; break;
@@ -2477,9 +2474,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu
Tank[j].Vcurve = i; // assign curve to tank Tank[j].Vcurve = i; // assign curve to tank
Tank[j].Vmin = tankvolume(p, j, Tank[j].Hmin); // new min. volume Tank[j].Vmin = tankvolume(p, j, Tank[j].Hmin); // new min. volume
Tank[j].V0 = tankvolume(p, j, Tank[j].H0); // new init. volume Tank[j].V0 = tankvolume(p, j, Tank[j].H0); // new init. volume
vTmp = Tank[j].Vmax; // old max. volume
Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax); // new max. volume Tank[j].Vmax = tankvolume(p, j, Tank[j].Hmax); // new max. volume
Tank[j].V1max *= Tank[j].Vmax / vTmp; // new mix zone volume
Tank[j].A = (curve->Y[n] - curve->Y[0]) / // nominal area Tank[j].A = (curve->Y[n] - curve->Y[0]) / // nominal area
(curve->X[n] - curve->X[0]); (curve->X[n] - curve->X[0]);
break; break;
@@ -2521,9 +2516,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu
if (value > curve->X[n]) return 225; // new level is off curve if (value > curve->X[n]) return 225; // new level is off curve
} }
Tank[j].Hmax = hTmp; // new max. head Tank[j].Hmax = hTmp; // new max. head
vTmp = Tank[j].Vmax; // old max. volume
Tank[j].Vmax = tankvolume(p, j, hTmp); // new max. volume Tank[j].Vmax = tankvolume(p, j, hTmp); // new max. volume
Tank[j].V1max *= Tank[j].Vmax / vTmp; // new mix zone volume
break; break;
case EN_MIXMODEL: case EN_MIXMODEL:
@@ -2542,7 +2535,7 @@ int DLLEXPORT EN_setnodevalue(EN_Project p, int index, int property, double valu
j = index - nJuncs; j = index - nJuncs;
if (Tank[j].A > 0.0) if (Tank[j].A > 0.0)
{ {
Tank[j].V1max = value * Tank[j].Vmax; Tank[j].V1frac = value;
} }
break; break;

View File

@@ -523,7 +523,7 @@ int saveinpfile(Project *pr, const char *fname)
tank = &net->Tank[i]; tank = &net->Tank[i];
if (tank->A == 0.0) continue; if (tank->A == 0.0) continue;
fprintf(f, "\n %-31s %-8s %12.4f", net->Node[tank->Node].ID, fprintf(f, "\n %-31s %-8s %12.4f", net->Node[tank->Node].ID,
MixTxt[tank->MixModel], (tank->V1max / tank->Vmax)); MixTxt[tank->MixModel], tank->V1frac);
} }
// Write [REACTIONS] section // Write [REACTIONS] section

View File

@@ -588,7 +588,6 @@ void convertunits(Project *pr)
tank->Kb /= SECperDAY; tank->Kb /= SECperDAY;
tank->V = tank->V0; tank->V = tank->V0;
tank->C = node->C0; tank->C = node->C0;
tank->V1max *= tank->Vmax;
} }
// Convert hydraulic convergence criteria // Convert hydraulic convergence criteria

View File

@@ -252,7 +252,7 @@ int tankdata(Project *pr)
tank->Vcurve = curve; tank->Vcurve = curve;
tank->MixModel = MIX1; // Completely mixed tank->MixModel = MIX1; // Completely mixed
tank->V1max = 1.0; // Mixing compartment size fraction tank->V1frac = 1.0; // Mixing compartment size fraction
return 0; return 0;
} }
@@ -1288,7 +1288,7 @@ int mixingdata(Project *pr)
i = j - net->Njuncs; i = j - net->Njuncs;
if (net->Tank[i].A == 0.0) return 0; if (net->Tank[i].A == 0.0) return 0;
net->Tank[i].MixModel = (char)m; net->Tank[i].MixModel = (char)m;
net->Tank[i].V1max = v; net->Tank[i].V1frac = v;
return 0; return 0;
} }

View File

@@ -525,7 +525,7 @@ void tankmix2(Project *pr, int i, double vin, double win, double vnet)
if (mixzone == NULL || stagzone == NULL) return; if (mixzone == NULL || stagzone == NULL) return;
// Full mixing zone volume // Full mixing zone volume
vmz = tank->V1max; vmz = tank->V1frac * tank->Vmax;
// Tank is filling // Tank is filling
vt = 0.0; vt = 0.0;

View File

@@ -612,7 +612,7 @@ void initsegs(Project *pr)
if (net->Tank[j].MixModel == MIX2) if (net->Tank[j].MixModel == MIX2)
{ {
// ... mixing zone segment // ... mixing zone segment
v1 = MAX(0, v - net->Tank[j].V1max); v1 = MAX(0, v - net->Tank[j].V1frac * net->Tank[j].Vmax);
qual->FirstSeg[k]->v = v1; qual->FirstSeg[k]->v = v1;
// ... stagnant zone segment // ... stagnant zone segment

View File

@@ -7,7 +7,7 @@
Authors: see AUTHORS Authors: see AUTHORS
Copyright: see AUTHORS Copyright: see AUTHORS
License: see LICENSE License: see LICENSE
Last Updated: 10/29/2019 Last Updated: 07/11/2020
****************************************************************************** ******************************************************************************
*/ */
@@ -428,7 +428,7 @@ typedef struct // Tank Object
int Pat; // fixed grade time pattern int Pat; // fixed grade time pattern
int Vcurve; // volume v. elev. curve index int Vcurve; // volume v. elev. curve index
MixType MixModel; // type of mixing model MixType MixModel; // type of mixing model
double V1max; // mixing compartment size double V1frac; // mixing compartment fraction
int CanOverflow; // tank can overflow or not int CanOverflow; // tank can overflow or not
} Stank; } Stank;