Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/tkhstate/BedHeightsFinder.java @ 8915:d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
author | gernotbelger |
---|---|
date | Wed, 28 Feb 2018 17:27:15 +0100 |
parents | |
children | 11bf13cf0463 |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.artifacts.sinfo.tkhstate; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map.Entry; import java.util.NavigableMap; import java.util.TreeMap; import org.apache.commons.lang.math.DoubleRange; import org.dive4elements.river.artifacts.math.Linear; import org.dive4elements.river.artifacts.model.Calculation; import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; import org.dive4elements.river.model.BedHeight; import org.dive4elements.river.model.BedHeightValue; import org.dive4elements.river.model.River; /** * Provides bed heigts for vcarious calculations. * * @author Gernot Belger */ public final class BedHeightsFinder { private final BedHeightInfo info; private final NavigableMap<Double, BedHeightValue> values; /** * Create specific bed heights used in tkh-calculation * * @param problems */ public static Collection<BedHeightsFinder> createTkhBedHeights(final River river, final Calculation problems, final DoubleRange range) { // FIXME: determine relevant bed-heights by river: read from some configuration file // '3' is already the right one for demo-model == '"DGM-2004_Epoche-2-SOBEK"' final int bedheightId = 3; final Collection<BedHeight> bedHeights = Collections.singletonList(BedHeight.getBedHeightById(bedheightId)); // TODO: check for overlapping ranges... and provide a warning message, else we get problems later final List<BedHeightsFinder> result = new ArrayList<>(bedHeights.size()); for (final BedHeight bedHeight : bedHeights) { result.add(createBedHeights(bedHeight, range)); } return result; } /** * Creates a {@link BedHeightsFinder} for a dataset from the database, specified by its id. * * @return <code>null</code> if no bed height with the given id exists. */ public static BedHeightsFinder forId(final int id, final DoubleRange range) { final BedHeight bedHeight = BedHeight.getBedHeightById(id); if (bedHeight == null) return null; return BedHeightsFinder.createBedHeights(bedHeight, range); } /** * Create a finder for a given bed height. * * @param range */ private static BedHeightsFinder createBedHeights(final BedHeight bedHeight, final DoubleRange range) { // FIXME: sort by station, but in what direction? // FIXME: using river.getKmUp()? final NavigableMap<Double, BedHeightValue> values = new TreeMap<>(); for (final BedHeightValue bedHeightValue : bedHeight.getValues()) { final Double station = bedHeightValue.getStation(); if (station != null && range.containsDouble(station)) { if (bedHeightValue.getHeight() != null) values.put(station, bedHeightValue); } } final BedHeightInfo info = BedHeightInfo.from(bedHeight); return new BedHeightsFinder(info, values); } private BedHeightsFinder(final BedHeightInfo info, final NavigableMap<Double, BedHeightValue> values) { this.info = info; this.values = values; } public BedHeightInfo getInfo() { return this.info; } public Collection<Double> getStations() { return this.values.keySet(); } public double getMeanBedHeight(final double km) { if (this.values.containsKey(km)) return this.values.get(km).getHeight(); final Entry<Double, BedHeightValue> floorEntry = this.values.floorEntry(km); final Entry<Double, BedHeightValue> ceilingEntry = this.values.ceilingEntry(km); if (floorEntry == null || ceilingEntry == null) return Double.NaN; final double floorKm = floorEntry.getKey(); final double floorHeight = floorEntry.getValue().getHeight(); final double ceilKm = ceilingEntry.getKey(); final double ceilHeight = ceilingEntry.getValue().getHeight(); // FIXME: check if we always want that... return Linear.linear(km, floorKm, ceilKm, floorHeight, ceilHeight); } }