Search in sources :

Example 1 with PfafstetterNumber

use of org.hortonmachine.hmachine.modules.network.PfafstetterNumber in project hortonmachine by TheHortonMachine.

the class OmsAdige method process.

@SuppressWarnings("nls")
@Execute
public void process() throws Exception {
    checkNull(inHillslope, inNetwork);
    if (startTimestamp == null) {
        outDischarge = new HashMap<Integer, double[]>();
        outSubdischarge = new HashMap<Integer, double[]>();
        startTimestamp = adigeFormatter.parseDateTime(tStart);
        if (tEnd != null)
            endTimestamp = adigeFormatter.parseDateTime(tEnd);
        currentTimstamp = startTimestamp;
        if (pRainintensity != -1) {
            if (pRainduration != -1) {
                rainEndTimestamp = startTimestamp.plusMinutes(pRainduration);
            } else {
                throw new ModelsIllegalargumentException("In the case of usage of a constant rainintensity it is necessary to define also its duration.\nCheck your arguments, probably the --rainduration flag is missing.", this, pm);
            }
        }
        if (pfaffsList == null) {
            // first time link basins with network
            linkBasinWithNetwork();
        }
        prepareMonitoringPoints();
        hillsSlopeNum = inHillslope.size();
        // at the first round create the hillslopes and network hierarchy
        orderedHillslopes = AdigeUtilities.generateHillSlopes(inNetwork, inHillslope, pm);
        if (inDuffyInput != null) {
            List<IHillSlope> duffyHillslopes = new ArrayList<IHillSlope>();
            for (IHillSlope hillSlope : orderedHillslopes) {
                IHillSlope newHS = new HillSlopeDuffy(hillSlope, inDuffyInput);
                duffyHillslopes.add(newHS);
            }
            orderedHillslopes = duffyHillslopes;
        }
        IHillSlope outletHillSlope = orderedHillslopes.get(0);
        outletHillslopeId = outletHillSlope.getHillslopeId();
        netPfaffsList = new ArrayList<PfafstetterNumber>();
        pfaff2Index = new HashMap<String, Integer>();
        basinid2Index = new HashMap<Integer, Integer>();
        index2Basinid = new HashMap<Integer, Integer>();
        pm.beginTask("Analaysing hillslopes and calculating distribution curves...", orderedHillslopes.size());
        for (int i = 0; i < orderedHillslopes.size(); i++) {
            IHillSlope hillSlope = orderedHillslopes.get(i);
            PfafstetterNumber pfafstetterNumber = hillSlope.getPfafstetterNumber();
            netPfaffsList.add(pfafstetterNumber);
            int hillslopeId = hillSlope.getHillslopeId();
            basinid2Index.put(hillslopeId, i);
            index2Basinid.put(i, hillslopeId);
            pfaff2Index.put(pfafstetterNumber.toString(), i);
            // the distributor
            pm.worked(1);
        }
        pm.done();
        if (pPfafids == null) {
            pPfafids = outletHillSlope.getPfafstetterNumber().toString();
        }
        if (pfaffsList == null) {
            String[] split = pPfafids.split(",");
            for (int i = 0; i < split.length; i++) {
                split[i] = split[i].trim();
            }
            pfaffsList = Arrays.asList(split);
        }
        if (inDuffyInput != null) {
            initialConditions = new double[hillsSlopeNum * 4];
            adigeEngine = new DuffyAdigeEngine(orderedHillslopes, inDuffyInput, pm, doLog, initialConditions, basinid2Index, index2Basinid, pfaffsList, pfaff2Index, outDischarge, outSubdischarge, startTimestamp, endTimestamp, tTimestep);
        } else if (inHymodInput != null) {
            initialConditions = null;
            adigeEngine = new HymodAdigeEngine(inHymodInput, orderedHillslopes, index2Basinid, outDischarge, outSubdischarge, pfaffsList, doLog, doLog, pm);
        } else {
            throw new ModelsIllegalargumentException("No parameters for any model were defined. Check your syntax.", this, pm);
        }
        if (hydrometersHandler != null) {
            adigeEngine.addDischargeContributor(hydrometersHandler);
        }
        if (damsHandler != null) {
            adigeEngine.addDischargeContributor(damsHandler);
        }
        if (tributaryHandler != null) {
            adigeEngine.addDischargeContributor(tributaryHandler);
        }
        if (offtakesHandler != null) {
            adigeEngine.addDischargeContributor(offtakesHandler);
        }
    } else {
        currentTimstamp = currentTimstamp.plusMinutes(tTimestep);
    }
    if (inHydrometerdata != null) {
        hydrometersHandler.setCurrentData(inHydrometerdata);
    }
    if (inDamsdata != null) {
        damsHandler.setCurrentData(inDamsdata);
    }
    if (inOfftakesdata != null) {
        offtakesHandler.setCurrentData(inOfftakesdata);
    }
    if (inTributarydata != null) {
        tributaryHandler.setCurrentData(inTributarydata);
    }
    // deal with rain
    if (pRainintensity != -1) {
        /*
             * in the case of constant rain the array is build once and then used every time.
             * The only thing that changes, is that after the rainEndDate, the rain intensity is
             * set to 0.
             */
        rainArray = new double[netPfaffsList.size()];
        if (currentTimstamp.isBefore(rainEndTimestamp)) {
            Arrays.fill(rainArray, pRainintensity);
        } else {
            Arrays.fill(rainArray, 0);
        }
    } else {
        // read rainfall from input link scalar set and transform into a rainfall intensity
        // [mm/h]
        rainArray = new double[hillsSlopeNum];
        etpArray = new double[hillsSlopeNum];
        setDataArray(inRain, rainArray);
        if (inEtp != null) {
            setDataArray(inEtp, etpArray);
        }
    }
    // long runningDateInMinutes = currentTimstamp.getMillis() / 1000L / 60L;
    // double intervalStartTimeInMinutes = runningDateInMinutes;
    // double intervalEndTimeInMinutes = runningDateInMinutes + tTimestep;
    initialConditions = adigeEngine.solve(currentTimstamp, tTimestep, 1, initialConditions, rainArray, etpArray);
}
Also used : ArrayList(java.util.ArrayList) HymodAdigeEngine(org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.hymod.HymodAdigeEngine) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) ModelsIllegalargumentException(org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException) PfafstetterNumber(org.hortonmachine.hmachine.modules.network.PfafstetterNumber) DuffyAdigeEngine(org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.duffy.DuffyAdigeEngine) HillSlopeDuffy(org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.HillSlopeDuffy) IHillSlope(org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.IHillSlope) Execute(oms3.annotations.Execute)

Example 2 with PfafstetterNumber

use of org.hortonmachine.hmachine.modules.network.PfafstetterNumber in project hortonmachine by TheHortonMachine.

the class HillSlope method compare.

/* (non-Javadoc)
     * @see org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.IHillSlope#compare(org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.HillSlope, org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.HillSlope)
     */
public int compare(IHillSlope ue1, IHillSlope ue2) {
    PfafstetterNumber p1 = ue1.getPfafstetterNumber();
    PfafstetterNumber p2 = ue2.getPfafstetterNumber();
    return p1.compareTo(p2);
}
Also used : PfafstetterNumber(org.hortonmachine.hmachine.modules.network.PfafstetterNumber)

Example 3 with PfafstetterNumber

use of org.hortonmachine.hmachine.modules.network.PfafstetterNumber in project hortonmachine by TheHortonMachine.

the class HillSlope method getAllUpstreamElementsGeometries.

/* (non-Javadoc)
     * @see org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.IHillSlope#getAllUpstreamElementsGeometries(java.util.List, java.util.List, org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.IHillSlope)
     */
public void getAllUpstreamElementsGeometries(List<Geometry> elems, List<PfafstetterNumber> limit, IHillSlope firstOfMaiorBasin) {
    // if the limit is the number of the actual element, return
    if (limit != null && limit.size() > 0) {
        for (PfafstetterNumber pfafs : limit) {
            if (pfafs.compareTo(pfafstetterNumber) == 0) {
                return;
            }
        }
    }
    this.firstOfMaiorBasin = firstOfMaiorBasin;
    elems.add((Geometry) hillslopeFeature.getDefaultGeometry());
    for (IHillSlope upstreamElement : upstreamElements) {
        upstreamElement.getAllUpstreamElementsGeometries(elems, limit, firstOfMaiorBasin);
    }
}
Also used : PfafstetterNumber(org.hortonmachine.hmachine.modules.network.PfafstetterNumber)

Example 4 with PfafstetterNumber

use of org.hortonmachine.hmachine.modules.network.PfafstetterNumber in project hortonmachine by TheHortonMachine.

the class HillSlopeDuffy method compare.

public int compare(IHillSlope ue1, IHillSlope ue2) {
    PfafstetterNumber p1 = ue1.getPfafstetterNumber();
    PfafstetterNumber p2 = ue2.getPfafstetterNumber();
    return p1.compareTo(p2);
}
Also used : PfafstetterNumber(org.hortonmachine.hmachine.modules.network.PfafstetterNumber)

Example 5 with PfafstetterNumber

use of org.hortonmachine.hmachine.modules.network.PfafstetterNumber in project hortonmachine by TheHortonMachine.

the class HymodAdigeEngine method solve.

public double[] solve(DateTime currentTimstamp, int tTimestep, double internalTimestepInMinutes, double[] initialConditions, double[] rainArray, double[] etpArray) throws IOException {
    if (initialConditions != null) {
        for (int i = orderedHillslopes.size() - 1; i >= 0; i--) {
            xLoss[i] = initialConditions[i];
            xSlow[i] = initialConditions[i + orderedHillslopes.size()];
            xQuick[0][i] = initialConditions[i + 2 * orderedHillslopes.size()];
            xQuick[1][i] = initialConditions[i + 3 * orderedHillslopes.size()];
            xQuick[2][i] = initialConditions[i + 4 * orderedHillslopes.size()];
        }
    }
    if (initialConditions == null) {
        xSlow = new double[orderedHillslopes.size()];
        coeffs = new double[orderedHillslopes.size()];
        xQuick = new double[3][orderedHillslopes.size()];
        xLoss = new double[orderedHillslopes.size()];
        initialConditions = new double[orderedHillslopes.size() * 5];
        for (int i = orderedHillslopes.size() - 1; i >= 0; i--) {
            IHillSlope hillSlope = orderedHillslopes.get(i);
            double areaKm2 = hillSlope.getHillslopeArea() / 1E6;
            // System.out.println(areaKm2);
            coeffs[i] = (Math.pow(10, 9)) * tTimestep * 60 / (areaKm2 * (Math.pow(10, 12)));
            xSlow[i] = 0 * hymodInputs.pQ0 * coeffs[i] / hymodInputs.pRs;
        }
    }
    for (int i = orderedHillslopes.size() - 1; i >= 0; i--) {
        IHillSlope hillSlope = orderedHillslopes.get(i);
        // /////////////FISSATO PER CHECK///////////////
        // hymodInputs.pAlpha=0.323;
        // hymodInputs.pCmax=999.0;
        // hymodInputs.pB=0.515;
        // hymodInputs.pRq=0.135;
        // hymodInputs.pRs=0.0091;
        // /////////////FISSATO PER CHECK///////////////
        double rain = rainArray[i];
        double etp = etpArray[i];
        // funziona
        // if (rain == -999 || etp ==-999) {
        // rain=0;etp=0;
        // }
        // modificato
        // System.out.println("rain= "+rain+" etp= "+etp);
        // if (isNovalue(rain) || isNovalue(etp)) {
        // rain=0;
        // etp=0;
        // }
        // 
        // 
        // /*
        // * sum together the discharge contributed by the current
        // * hillslope plus the contributions coming from upstream
        // */
        // 
        // PfafstetterNumber pfaf = hillSlope.getPfafstetterNumber();
        // if (pfaffsList.contains(pfaf.toString())) {
        // outDischarge.put(basinId, new double[] { -999 });
        // outSubDischarge.put(basinId, new double[] { -999 });
        // }
        // 
        // outDischargeInternal.put(basinId,
        // new double[] { -999 });
        // System.out.println(basinId+" rain= "+rain+" etp="+etp+ "outDischargeInternal="+
        // outDischargeInternal.get(basinId));
        // // if (i == 2) {
        // // //
        // // System.out.println(conta+" basinDischarge"+(-999)
        // // +" xloss="+xLoss[i]);
        // // conta++;
        // // }
        // } else {
        double[] out_excess = excess(xLoss[i], rain, etp);
        double UT1 = out_excess[0];
        double UT2 = out_excess[1];
        xLoss[i] = out_excess[2];
        double UQ = hymodInputs.pAlpha * UT2 + UT1;
        double US = (1.0 - hymodInputs.pAlpha) * UT2;
        double inflow = US;
        double[] out_linres1 = linres(xSlow[i], inflow, hymodInputs.pRs, 1);
        xSlow[i] = out_linres1[0];
        double outflow1 = out_linres1[1];
        double QS = outflow1;
        inflow = UQ;
        double outflow2 = 0;
        for (int k = 0; k < 3; k++) {
            double[] out_linres2 = linres(xQuick[k][i], inflow, hymodInputs.pRq, 1);
            xQuick[k][i] = out_linres2[0];
            outflow2 = out_linres2[1];
            inflow = outflow2;
        }
        Integer basinId = index2Basinid.get(i);
        double basinDischarge = (QS + outflow2) / coeffs[i];
        double basinSubDischarge = QS / coeffs[i];
        double allContributionsDischarge = handleContributors(hillSlope, basinDischarge);
        /*
             * sum together the discharge contributed by the current
             * hillslope plus the contributions coming from upstream
             */
        basinDischarge = basinDischarge + allContributionsDischarge;
        PfafstetterNumber pfaf = hillSlope.getPfafstetterNumber();
        if (pfaffsList.contains(pfaf.toString())) {
            outDischarge.put(basinId, new double[] { basinDischarge });
            outSubDischarge.put(basinId, new double[] { basinSubDischarge });
        }
        initialConditions[i] = xLoss[i];
        initialConditions[i + orderedHillslopes.size()] = xSlow[i];
        initialConditions[i + 2 * orderedHillslopes.size()] = xQuick[0][i];
        initialConditions[i + 3 * orderedHillslopes.size()] = xQuick[1][i];
        initialConditions[i + 4 * orderedHillslopes.size()] = xQuick[2][i];
        outDischargeInternal.put(basinId, new double[] { basinDischarge });
    // System.out.println(basinId+" rain= "+rain+" etp="+etp+ "outDischargeInternal="+
    // outDischargeInternal.get(basinId));
    // if (i == 61) {
    // System.out.println("rain= "+rain+" etp= "+etp+" basinId= "+basinId+
    // " basinDischarge"+basinDischarge+" allcontributions= "+allContributionsDischarge+" xloss= "+xLoss[i]);
    // }
    // if (i == 61) {
    // //
    // System.out.println(conta+"rain= "+rain+" etp= "+etp+" basinDischarge"+(basinDischarge-allContributionsDischarge)
    // +" xloss="+xLoss[i]);
    // conta++;
    // }
    // }
    }
    // + etpArray[0]);
    return initialConditions;
}
Also used : PfafstetterNumber(org.hortonmachine.hmachine.modules.network.PfafstetterNumber) IHillSlope(org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.IHillSlope)

Aggregations

PfafstetterNumber (org.hortonmachine.hmachine.modules.network.PfafstetterNumber)14 ArrayList (java.util.ArrayList)5 IHillSlope (org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.IHillSlope)5 Execute (oms3.annotations.Execute)3 ModelsIllegalargumentException (org.hortonmachine.gears.libs.exceptions.ModelsIllegalargumentException)3 Point (org.locationtech.jts.geom.Point)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 HashMap (java.util.HashMap)2 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)2 IDischargeContributor (org.hortonmachine.hmachine.modules.hydrogeomorphology.adige.core.IDischargeContributor)2 LineString (org.locationtech.jts.geom.LineString)2 WritableRaster (java.awt.image.WritableRaster)1 File (java.io.File)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1