From aaf7e8eeb445a5c1dbd0f87e21351a6082744247 Mon Sep 17 00:00:00 2001 From: Artem Lunev Date: Tue, 25 May 2021 10:17:29 +0200 Subject: [PATCH] Improved truncation & time limit adjustment --- .../java/pulse/input/ExperimentalData.java | 18 +++++++++++++++--- .../problem/schemes/DifferenceScheme.java | 13 ++++++++----- .../statements/model/ThermalProperties.java | 2 +- src/main/java/pulse/tasks/SearchTask.java | 5 +++++ src/main/java/pulse/tasks/TaskManager.java | 13 ++++++++++--- .../java/pulse/ui/components/DataLoader.java | 19 +++---------------- 6 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/main/java/pulse/input/ExperimentalData.java b/src/main/java/pulse/input/ExperimentalData.java index 5291ec6..05010f3 100644 --- a/src/main/java/pulse/input/ExperimentalData.java +++ b/src/main/java/pulse/input/ExperimentalData.java @@ -159,7 +159,7 @@ public List runningAverage(int reductionFactor) { int start = indexRange.getLowerBound(); int end = indexRange.getUpperBound(); - + int step = (end - start) / (count / reductionFactor); double av = 0; @@ -177,9 +177,9 @@ public List runningAverage(int reductionFactor) { av /= step; crudeAverage.add(new Point2D.Double(timeAt((i1 + i2) / 2), av)); - + } - + return crudeAverage; } @@ -411,5 +411,17 @@ private void doSetRange() { if (metadata != null) range.updateMinimum(metadata.numericProperty(PULSE_WIDTH)); } + + /** + * Retrieves the + * + * @see pulse.problem.schemes.DifferenceScheme + * @return a double, equal to the last element of the {@code time List}. + */ + + @Override + public double timeLimit() { + return timeAt(indexRange.getUpperBound()); + } } \ No newline at end of file diff --git a/src/main/java/pulse/problem/schemes/DifferenceScheme.java b/src/main/java/pulse/problem/schemes/DifferenceScheme.java index 28aa526..0e3544d 100644 --- a/src/main/java/pulse/problem/schemes/DifferenceScheme.java +++ b/src/main/java/pulse/problem/schemes/DifferenceScheme.java @@ -97,16 +97,18 @@ public void copyFrom(DifferenceScheme df) { /** *

* Contains preparatory steps to ensure smooth running of the solver. This - * includes creating a {@code DiscretePulse} object and calculating the - * {@code timeInterval}. The latter determines the real-time calculation of a - * {@code HeatingCurve} based on the numerical solution of {@code problem}; it - * thus takes into account the difference between the scheme timestep and the - * {@code HeatingCurve} point spacing. All subclasses of + * includes creating a {@code DiscretePulse} object and adjusting the grid of this + * scheme to match the {@code DiscretePulse} created for this {@code problem}. + * Finally, a heating curve is cleared from the previously calculated values. + *

+ *

+ * All subclasses of * {@code DifferenceScheme} should override and explicitly call this superclass * method where appropriate. *

* * @param problem the heat problem to be solved + * @see pulse.problem.schemes.Grid.adjustTo() */ protected void prepare(Problem problem) { @@ -305,6 +307,7 @@ public NumericProperty getTimeLimit() { public void setTimeLimit(NumericProperty timeLimit) { requireType(timeLimit, TIME_LIMIT); this.timeLimit = (double) timeLimit.getValue(); + firePropertyChanged(this, timeLimit); } @Override diff --git a/src/main/java/pulse/problem/statements/model/ThermalProperties.java b/src/main/java/pulse/problem/statements/model/ThermalProperties.java index ed48e9b..77d27aa 100644 --- a/src/main/java/pulse/problem/statements/model/ThermalProperties.java +++ b/src/main/java/pulse/problem/statements/model/ThermalProperties.java @@ -52,7 +52,7 @@ public class ThermalProperties extends PropertyHolder { * Chem. Eng. Sci. 199 (2019) 546-551 */ - public final double PARKERS_COEFFICIENT = 0.1370; // in mm + public final double PARKERS_COEFFICIENT = 0.1388; // in mm public ThermalProperties() { super(); diff --git a/src/main/java/pulse/tasks/SearchTask.java b/src/main/java/pulse/tasks/SearchTask.java index 15122ee..eb1aa8c 100644 --- a/src/main/java/pulse/tasks/SearchTask.java +++ b/src/main/java/pulse/tasks/SearchTask.java @@ -119,6 +119,11 @@ private void addListeners() { if (p.areThermalPropertiesLoaded()) p.useTheoreticalEstimates(curve); }); + + /** + * Sets the difference scheme's time limit to the upper bound of the range of {@code ExperimentalData} + * multiplied by a safety margin {@value Calculation.RELATIVE_TIME_MARGIN}. + */ curve.addDataListener(dataEvent -> { var scheme = current.getScheme(); diff --git a/src/main/java/pulse/tasks/TaskManager.java b/src/main/java/pulse/tasks/TaskManager.java index f3941d5..c449e9b 100644 --- a/src/main/java/pulse/tasks/TaskManager.java +++ b/src/main/java/pulse/tasks/TaskManager.java @@ -239,7 +239,9 @@ public boolean dataNeedsTruncation() { */ public void truncateData() { - tasks.stream().forEach(t -> t.getExperimentalCurve().truncate()); + tasks.stream().forEach(t -> + t.getExperimentalCurve().truncate() + ); } private void fireTaskSelected(Object source) { @@ -373,8 +375,12 @@ public void generateTasks(List files) { System.err.println("Failed to load all tasks within 2 minutes. Details:"); e.printStackTrace(); } - + selectFirstTask(); + + // check if the data loaded needs truncation + if (instance.dataNeedsTruncation()) + this.truncateData(); } @@ -512,7 +518,8 @@ public String describe() { public void evaluate() { tasks.stream().forEach(t -> { var properties = t.getCurrentCalculation().getProblem().getProperties(); - properties.useTheoreticalEstimates(t.getExperimentalCurve()); + var c = t.getExperimentalCurve(); + properties.useTheoreticalEstimates(c); }); } diff --git a/src/main/java/pulse/ui/components/DataLoader.java b/src/main/java/pulse/ui/components/DataLoader.java index cc1c367..0261cf4 100644 --- a/src/main/java/pulse/ui/components/DataLoader.java +++ b/src/main/java/pulse/ui/components/DataLoader.java @@ -4,7 +4,6 @@ import static pulse.io.readers.ReaderManager.pulseReaders; import static pulse.io.readers.ReaderManager.read; -import java.awt.Window; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; @@ -64,9 +63,11 @@ public static void loadDataDialog() { var files = userInput(Messages.getString("TaskControlFrame.ExtensionDescriptor"), ReaderManager.getCurveExtensions()); + var instance = TaskManager.getManagerInstance(); + if (files != null) { progressFrame.trackProgress(files.size()); - TaskManager.getManagerInstance().generateTasks(files); + instance.generateTasks(files); } } @@ -116,10 +117,6 @@ public static void loadMetadataDialog() { } - // check if the data loaded needs truncation - if (instance.dataNeedsTruncation()) - truncateDataDialog(progressFrame); - progressFrame.incrementProgress(); // select first of the generated task @@ -179,16 +176,6 @@ public static void load(StandartType type, File f) throws IOException { TaskManager.getManagerInstance().evaluate(); } - private static void truncateDataDialog(Window frame) { - Object[] options = { "Truncate", "Do not change" }; - int answer = JOptionPane.showOptionDialog(frame, - ("The acquisition time for some experiments appears to be too long.\nIf time resolution is low, the model estimates will be biased.\n\nIt is recommended to allow PULSE to truncate this data.\n\nWould you like to proceed? "), //$NON-NLS-1$ - "Potential Problem with Data", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, - options[0]); - if (answer == 0) - TaskManager.getManagerInstance().truncateData(); - } - private static List userInput(String descriptor, List extensions) { JFileChooser fileChooser = new JFileChooser();