[PATCH 2 of 2] Fitting new Option UI

Wald Commits scm-commit at wald.intevation.org
Mon Dec 2 15:08:19 CET 2019


# HG changeset patch
# User dnt_bjoernsen <d.tironi at bjoernsen.de>
# Date 1575292446 -3600
#      Mon Dec 02 14:14:06 2019 +0100
# Node ID 58f3fe98fd6b21c9c6b8dd3f710471925caaae7e
# Parent  3987fef69143107618123cebf7d6efdc8e548a35
Fitting new Option UI

diff -r 3987fef69143 -r 58f3fe98fd6b artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/AbstractLogLinear.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/AbstractLogLinear.java	Mon Dec 02 14:14:06 2019 +0100
@@ -0,0 +1,72 @@
+/** 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.math.fitting;
+
+/**
+ * @author Domenico Nardi Tironi
+ *
+ */
+/*
+ * Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
+ * Software engineering by Intevation GmbH
+ * 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.
+ */
+
+public abstract class AbstractLogLinear extends Function {
+    public static final Derivative DERIVATIVE = new Derivative("W'(Q) = a*m/(m*Q + b)") {
+
+        @Override
+        public org.dive4elements.river.artifacts.math.Function instantiate(final double[] parameters) {
+            final double a = parameters[0];
+            final double m = parameters[1];
+            final double b = parameters[2];
+
+            return new org.dive4elements.river.artifacts.math.Function() {
+                @Override
+                public double value(final double Q) {
+                    return a * m / (m * Q + b);
+                }
+            };
+        }
+    };
+
+    public AbstractLogLinear(final String name, final String description) {
+        super(name, description, new String[] { "a", "m", "b" });
+    }
+
+    @Override
+    public final double value(final double x, final double[] parameters) {
+        return parameters[0] * Math.log(parameters[1] * x + parameters[2]);
+    }
+
+    @Override
+    public double[] gradient(final double x, final double[] parameters) {
+        final double a = parameters[0];
+        final double m = parameters[1];
+        final double b = parameters[2];
+
+        final double lin = m * x + b;
+
+        return new double[] { Math.log(lin), a * x / lin, a / lin };
+    }
+
+    @Override
+    public final Derivative getDerivative() {
+        return DERIVATIVE;
+    }
+
+    @Override
+    public Function getInverse() {
+        return InvLogLinear.INSTANCE;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 3987fef69143 -r 58f3fe98fd6b artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/FunctionFactory.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/FunctionFactory.java	Mon Dec 02 14:07:25 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/FunctionFactory.java	Mon Dec 02 14:14:06 2019 +0100
@@ -12,18 +12,18 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-public final class FunctionFactory
-{
+public final class FunctionFactory {
     private static FunctionFactory instance;
 
-    private Map<String, Function> functions;
+    private final Map<String, Function> functions;
 
     private FunctionFactory() {
-        functions = new LinkedHashMap<String, Function>();
+        this.functions = new LinkedHashMap<>();
 
         registerFunction(Log.INSTANCE);
         registerFunction(Linear.INSTANCE);
         registerFunction(LogLinear.INSTANCE);
+        registerFunction(LogLinearAlternative.INSTANCE);
         registerFunction(Exp.INSTANCE);
         registerFunction(Quad.INSTANCE);
         registerFunction(Pow.INSTANCE);
@@ -37,16 +37,16 @@
         return instance;
     }
 
-    public Function getFunction(String name) {
-        return functions.get(name);
+    public Function getFunction(final String name) {
+        return this.functions.get(name);
     }
 
-    public void registerFunction(Function function) {
-        functions.put(function.getName(), function);
+    public void registerFunction(final Function function) {
+        this.functions.put(function.getName(), function);
     }
 
     public Collection<Function> getFunctions() {
-        return functions.values();
+        return this.functions.values();
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 3987fef69143 -r 58f3fe98fd6b artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/InvSQPow.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/InvSQPow.java	Mon Dec 02 14:07:25 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/InvSQPow.java	Mon Dec 02 14:14:06 2019 +0100
@@ -8,24 +8,19 @@
 
 package org.dive4elements.river.artifacts.math.fitting;
 
-public class InvSQPow
-extends      Function
-{
-    public static final Derivative DERIVATIVE =
-        new Derivative("Q'(S) = (S/a)^(1/b)/(b*S)") {
+public class InvSQPow extends Function {
+    public static final Derivative DERIVATIVE = new Derivative("Q'(S) = (S/a)^(1/b)/(b*S)") {
 
         @Override
-        public org.dive4elements.river.artifacts.math.Function
-            instantiate(double [] parameters)
-        {
-            final double _1a = 1d/parameters[0];
-            final double   b = parameters[1];
-            final double _1b = 1d/b;
+        public org.dive4elements.river.artifacts.math.Function instantiate(final double[] parameters) {
+            final double _1a = 1d / parameters[0];
+            final double b = parameters[1];
+            final double _1b = 1d / b;
 
             return new org.dive4elements.river.artifacts.math.Function() {
                 @Override
-                public double value(double S) {
-                    return Math.pow(S*_1a, _1b)/(b*S);
+                public double value(final double S) {
+                    return Math.pow(S * _1a, _1b) / (b * S);
                 }
             };
         }
@@ -33,30 +28,24 @@
     public static final Function INSTANCE = new InvSQPow();
 
     public InvSQPow() {
-        super(
-            "inv-sq-pow",
-            "Q(S) = Q=(S/a)^(1/b)",
-            new String [] { "a", "b" });
+        super("inv-special", "Q(S) = Q=(S/a)^(1/b)", new String[] { "a", "b" });
     }
 
     @Override
-    public double value(double S, double [] parameters) {
-        double a = parameters[0];
-        double b = parameters[1];
-        return Math.pow(S/a, 1d/b);
+    public double value(final double S, final double[] parameters) {
+        final double a = parameters[0];
+        final double b = parameters[1];
+        return Math.pow(S / a, 1d / b);
     }
 
     @Override
-    public double [] gradient(double S, double [] parameters) {
-        double a     = parameters[0];
-        double b     = parameters[1];
-        double Sa    = S/a;
-        double _1b   = 1d/b;
-        double eSa1b = Math.pow(Sa, _1b);
-        return new double [] {
-            -eSa1b/(a*b),
-            -(eSa1b*Math.log(Sa))/(b*b)
-        };
+    public double[] gradient(final double S, final double[] parameters) {
+        final double a = parameters[0];
+        final double b = parameters[1];
+        final double Sa = S / a;
+        final double _1b = 1d / b;
+        final double eSa1b = Math.pow(Sa, _1b);
+        return new double[] { -eSa1b / (a * b), -(eSa1b * Math.log(Sa)) / (b * b) };
     }
 
     @Override
diff -r 3987fef69143 -r 58f3fe98fd6b artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/LogLinear.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/LogLinear.java	Mon Dec 02 14:07:25 2019 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/LogLinear.java	Mon Dec 02 14:14:06 2019 +0100
@@ -8,66 +8,12 @@
 
 package org.dive4elements.river.artifacts.math.fitting;
 
-public class LogLinear
-extends      Function
-{
-    public static final Derivative DERIVATIVE =
-        new Derivative("W'(Q) = a*m/(m*Q + b)") {
+public class LogLinear extends AbstractLogLinear {
 
-        @Override
-        public org.dive4elements.river.artifacts.math.Function
-            instantiate(double [] parameters)
-        {
-            final double a = parameters[0];
-            final double m = parameters[1];
-            final double b = parameters[2];
-
-            return new org.dive4elements.river.artifacts.math.Function() {
-                @Override
-                public double value(double Q) {
-                    return a*m/(m*Q + b);
-                }
-            };
-        }
-    };
 
     public static final Function INSTANCE = new LogLinear();
 
     public LogLinear() {
-        super(
-            "log-linear",
-            "W(Q) = a*ln(m*Q + b)",
-            new String [] { "a", "m", "b" });
-    }
-
-    @Override
-    public double value(double x, double [] parameters) {
-        return parameters[0]*Math.log(parameters[1]*x + parameters[2]);
+        super("log-linear", "W(Q) = a*ln(m*Q + b)");
     }
-
-    @Override
-    public double [] gradient(double x, double [] parameters) {
-        double a = parameters[0];
-        double m = parameters[1];
-        double b = parameters[2];
-
-        double lin = m*x + b;
-
-        return new double [] {
-            Math.log(lin),
-            a*x / lin,
-            a / lin
-        };
-    }
-
-    @Override
-    public Derivative getDerivative() {
-        return DERIVATIVE;
-    }
-
-    @Override
-    public Function getInverse() {
-        return InvLogLinear.INSTANCE;
-    }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+}
\ No newline at end of file
diff -r 3987fef69143 -r 58f3fe98fd6b artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/LogLinearAlternative.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/math/fitting/LogLinearAlternative.java	Mon Dec 02 14:14:06 2019 +0100
@@ -0,0 +1,24 @@
+/** 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.math.fitting;
+
+/**
+ * @author Domenico Nardi Tironi
+ *
+ */
+public class LogLinearAlternative extends AbstractLogLinear {
+
+    public static final String NAME = "log-linear-alternative";
+    public static final Function INSTANCE = new LogLinearAlternative();
+
+    public LogLinearAlternative() {
+        super(NAME, "W(Q) = a*ln(m*Q + b) (linearisiert)");
+    }
+}
diff -r 3987fef69143 -r 58f3fe98fd6b gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixFunctionSelect.java
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixFunctionSelect.java	Mon Dec 02 14:07:25 2019 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/fixation/FixFunctionSelect.java	Mon Dec 02 14:14:06 2019 +0100
@@ -33,6 +33,7 @@
         funcDesc.put("log", "W(Q) = m*ln(Q + b)");
         funcDesc.put("linear", "W(Q) = m * Q + b");
         funcDesc.put("log-linear", "W(Q) = a*ln(m*Q+b)");
+        funcDesc.put("log-linear-alternative", "W(Q) = a*ln(m*Q+b) (linearisiert)");
         funcDesc.put("exp", "W(Q) = m * a^Q + b");
         funcDesc.put("quad", "W(Q) = n*Q^2+m*Q+b");
         funcDesc.put("pow", "W(Q) = a * Q^c + d");


More information about the Dive4Elements-commits mailing list