Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java @ 3992:a9c93b7c9da1
Simpify the S(Q) fraction sieving stuff.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 30 Sep 2012 21:15:23 +0200 |
parents | |
children | ab3a4ad82ae1 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/sq/SieveArray.java Sun Sep 30 21:15:23 2012 +0200 @@ -0,0 +1,91 @@ +package de.intevation.flys.artifacts.model.sq; + +public class SieveArray +{ + public static final double EPSILON = 1e-8; + + public static final double [] SIEVE_DIAMETERS = { + 100d, 63d, 31.5d, 16d, + 8d, 4d, 2d, 1d, + 0.5d, 0.25d, 0.125d, 0.063d + }; + + protected double [] loads; + protected double [] normLoads; + + public SieveArray() { + loads = new double[SIEVE_DIAMETERS.length+1]; + normLoads = new double[SIEVE_DIAMETERS.length+1]; + } + + public void doSieving(Sieve s) { + + double diameter = s.getDiameter(); + + for (int i = 0; i < SIEVE_DIAMETERS.length; ++i) { + if (diameter >= SIEVE_DIAMETERS[i]) { + loads[i] += s.getLoad(); + return; + } + } + loads[loads.length-1] += s.getLoad(); + } + + public double totalLoad() { + double sum = 0d; + for (double load: loads) { + sum += load; + } + return sum; + } + + public void calculateNormLoads() { + double total = totalLoad(); + if (Math.abs(total) < EPSILON) { + return; + } + total = 1d/total; + for (int i = 0; i < normLoads.length; ++i) { + normLoads[i] = total*loads[i]; + } + } + + /** + * Gets the loads for this instance. + * + * @return The loads. + */ + public double[] getLoads() { + return this.loads; + } + + /** + * Gets the loads for this instance. + * + * @param index The index to get. + * @return The loads. + */ + public double getLoads(int index) { + return this.loads[index]; + } + + /** + * Gets the normLoads for this instance. + * + * @return The normLoads. + */ + public double[] getNormLoads() { + return this.normLoads; + } + + /** + * Gets the normLoads for this instance. + * + * @param index The index to get. + * @return The normLoads. + */ + public double getNormLoads(int index) { + return this.normLoads[index]; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :