|
| 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 | +} |
0 commit comments