From 4724b9fcf4f549bea4fa3df6d3b4e1050c96b029 Mon Sep 17 00:00:00 2001 From: Alvaro Huarte Date: Wed, 24 Jun 2015 23:40:35 +0200 Subject: [PATCH] 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: https://github.com/Baseform/Baseform-Epanet-Java-Library/issues/4 --- .../hydraulic/HydraulicAndQualitySim.java | 76 +++++++++++++++++++ .../epanet/hydraulic/HydraulicSim.java | 13 +++- 2 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 src/org/addition/epanet/hydraulic/HydraulicAndQualitySim.java diff --git a/src/org/addition/epanet/hydraulic/HydraulicAndQualitySim.java b/src/org/addition/epanet/hydraulic/HydraulicAndQualitySim.java new file mode 100644 index 0000000..5b24ac6 --- /dev/null +++ b/src/org/addition/epanet/hydraulic/HydraulicAndQualitySim.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2012 Addition, Lda. (addition at addition dot pt) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package org.addition.epanet.hydraulic; + +import java.io.IOException; +import java.util.logging.Logger; + +import org.addition.epanet.hydraulic.io.AwareStep; +import org.addition.epanet.network.Network; +import org.addition.epanet.network.PropertiesMap; +import org.addition.epanet.quality.QualitySim; +import org.addition.epanet.util.ENException; + +/** + * Hybrid Hydraulic and Water Quality simulation class. + */ +public class HydraulicAndQualitySim extends HydraulicSim { + + /** + * Optional related QualitySim when Water Quality analysis is needed. + */ + private QualitySim qualitySim; + + /** + * Init hydraulic simulation, preparing the linear solver and the hydraulic structures wrappers. + * + * @param net Hydraulic network reference. + * @param log Logger reference. + * @throws ENException + */ + public HydraulicAndQualitySim(Network net, Logger log) throws ENException { + super(net, log); + if (!net.getPropertiesMap().getQualflag().equals(PropertiesMap.QualType.NONE)) qualitySim = new QualitySim(net, log); + } + + /** + * Write the simulation results to current output. + */ + @Override + protected void writeSimulationOutput() throws ENException, IOException { + if (simulationOutput != null && qualitySim != null) { + AwareStep.writeHydAndQual(simulationOutput, this, qualitySim, Rtime-Htime, Htime); + return; + } + super.writeSimulationOutput(); + } + + /** + * Finds length of next time step & updates tank levels and rule-based control actions. + */ + @Override + protected long nextHyd() throws ENException, IOException { + long hydstep = super.nextHyd(); + + if (qualitySim != null) { + for (long i = 0, qstep = pMap.getQstep(), numQsteps = hydstep/qstep; i < numQsteps; i++) { + qualitySim.simulateSingleStep(nNodes, nLinks, qstep); + } + } + return hydstep; + } +} diff --git a/src/org/addition/epanet/hydraulic/HydraulicSim.java b/src/org/addition/epanet/hydraulic/HydraulicSim.java index 88dd8a2..dd6f0d7 100644 --- a/src/org/addition/epanet/hydraulic/HydraulicSim.java +++ b/src/org/addition/epanet/hydraulic/HydraulicSim.java @@ -686,13 +686,20 @@ private void computeDemands() throws ENException { } /** - * Finds length of next time step & updates tank levels and rule-based contol actions. + * Write the simulation results to current output. + */ + protected void writeSimulationOutput() throws ENException, IOException { + if (simulationOutput != null) + AwareStep.write(simulationOutput, this, Htime); + } + + /** + * Finds length of next time step & updates tank levels and rule-based control actions. */ protected long nextHyd() throws ENException, IOException { long hydstep = 0; - if (simulationOutput != null) - AwareStep.write(simulationOutput, this, Htime); + writeSimulationOutput(); if (Htime < pMap.getDuration()) hydstep = timeStep();