comparison 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
comparison
equal deleted inserted replaced
3991:3a1cac4bfe70 3992:a9c93b7c9da1
1 package de.intevation.flys.artifacts.model.sq;
2
3 public class SieveArray
4 {
5 public static final double EPSILON = 1e-8;
6
7 public static final double [] SIEVE_DIAMETERS = {
8 100d, 63d, 31.5d, 16d,
9 8d, 4d, 2d, 1d,
10 0.5d, 0.25d, 0.125d, 0.063d
11 };
12
13 protected double [] loads;
14 protected double [] normLoads;
15
16 public SieveArray() {
17 loads = new double[SIEVE_DIAMETERS.length+1];
18 normLoads = new double[SIEVE_DIAMETERS.length+1];
19 }
20
21 public void doSieving(Sieve s) {
22
23 double diameter = s.getDiameter();
24
25 for (int i = 0; i < SIEVE_DIAMETERS.length; ++i) {
26 if (diameter >= SIEVE_DIAMETERS[i]) {
27 loads[i] += s.getLoad();
28 return;
29 }
30 }
31 loads[loads.length-1] += s.getLoad();
32 }
33
34 public double totalLoad() {
35 double sum = 0d;
36 for (double load: loads) {
37 sum += load;
38 }
39 return sum;
40 }
41
42 public void calculateNormLoads() {
43 double total = totalLoad();
44 if (Math.abs(total) < EPSILON) {
45 return;
46 }
47 total = 1d/total;
48 for (int i = 0; i < normLoads.length; ++i) {
49 normLoads[i] = total*loads[i];
50 }
51 }
52
53 /**
54 * Gets the loads for this instance.
55 *
56 * @return The loads.
57 */
58 public double[] getLoads() {
59 return this.loads;
60 }
61
62 /**
63 * Gets the loads for this instance.
64 *
65 * @param index The index to get.
66 * @return The loads.
67 */
68 public double getLoads(int index) {
69 return this.loads[index];
70 }
71
72 /**
73 * Gets the normLoads for this instance.
74 *
75 * @return The normLoads.
76 */
77 public double[] getNormLoads() {
78 return this.normLoads;
79 }
80
81 /**
82 * Gets the normLoads for this instance.
83 *
84 * @param index The index to get.
85 * @return The normLoads.
86 */
87 public double getNormLoads(int index) {
88 return this.normLoads[index];
89 }
90 }
91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org