Skip to content

Commit 4724b9f

Browse files
committed
Bug fix issue 'No quality data generated'
New HydraulicAndQualitySim class to simulate hydraulic and Water quality analysis in order to fill the water quality data in output. It fixes the issue: #4
1 parent e3b8873 commit 4724b9f

2 files changed

Lines changed: 86 additions & 3 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2012 Addition, Lda. (addition at addition dot pt)
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see http://www.gnu.org/licenses/.
16+
*/
17+
package org.addition.epanet.hydraulic;
18+
19+
import java.io.IOException;
20+
import java.util.logging.Logger;
21+
22+
import org.addition.epanet.hydraulic.io.AwareStep;
23+
import org.addition.epanet.network.Network;
24+
import org.addition.epanet.network.PropertiesMap;
25+
import org.addition.epanet.quality.QualitySim;
26+
import org.addition.epanet.util.ENException;
27+
28+
/**
29+
* Hybrid Hydraulic and Water Quality simulation class.
30+
*/
31+
public class HydraulicAndQualitySim extends HydraulicSim {
32+
33+
/**
34+
* Optional related QualitySim when Water Quality analysis is needed.
35+
*/
36+
private QualitySim qualitySim;
37+
38+
/**
39+
* Init hydraulic simulation, preparing the linear solver and the hydraulic structures wrappers.
40+
*
41+
* @param net Hydraulic network reference.
42+
* @param log Logger reference.
43+
* @throws ENException
44+
*/
45+
public HydraulicAndQualitySim(Network net, Logger log) throws ENException {
46+
super(net, log);
47+
if (!net.getPropertiesMap().getQualflag().equals(PropertiesMap.QualType.NONE)) qualitySim = new QualitySim(net, log);
48+
}
49+
50+
/**
51+
* Write the simulation results to current output.
52+
*/
53+
@Override
54+
protected void writeSimulationOutput() throws ENException, IOException {
55+
if (simulationOutput != null && qualitySim != null) {
56+
AwareStep.writeHydAndQual(simulationOutput, this, qualitySim, Rtime-Htime, Htime);
57+
return;
58+
}
59+
super.writeSimulationOutput();
60+
}
61+
62+
/**
63+
* Finds length of next time step & updates tank levels and rule-based control actions.
64+
*/
65+
@Override
66+
protected long nextHyd() throws ENException, IOException {
67+
long hydstep = super.nextHyd();
68+
69+
if (qualitySim != null) {
70+
for (long i = 0, qstep = pMap.getQstep(), numQsteps = hydstep/qstep; i < numQsteps; i++) {
71+
qualitySim.simulateSingleStep(nNodes, nLinks, qstep);
72+
}
73+
}
74+
return hydstep;
75+
}
76+
}

src/org/addition/epanet/hydraulic/HydraulicSim.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,20 @@ private void computeDemands() throws ENException {
686686
}
687687

688688
/**
689-
* Finds length of next time step & updates tank levels and rule-based contol actions.
689+
* Write the simulation results to current output.
690+
*/
691+
protected void writeSimulationOutput() throws ENException, IOException {
692+
if (simulationOutput != null)
693+
AwareStep.write(simulationOutput, this, Htime);
694+
}
695+
696+
/**
697+
* Finds length of next time step & updates tank levels and rule-based control actions.
690698
*/
691699
protected long nextHyd() throws ENException, IOException {
692700
long hydstep = 0;
693701

694-
if (simulationOutput != null)
695-
AwareStep.write(simulationOutput, this, Htime);
702+
writeSimulationOutput();
696703

697704
if (Htime < pMap.getDuration())
698705
hydstep = timeStep();

0 commit comments

Comments
 (0)