Skip to content

Commit

Permalink
Improved truncation & time limit adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Lunev committed May 25, 2021
1 parent 25c0642 commit aaf7e8e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
18 changes: 15 additions & 3 deletions src/main/java/pulse/input/ExperimentalData.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<Point2D> runningAverage(int reductionFactor) {

int start = indexRange.getLowerBound();
int end = indexRange.getUpperBound();

int step = (end - start) / (count / reductionFactor);
double av = 0;

Expand All @@ -177,9 +177,9 @@ public List<Point2D> runningAverage(int reductionFactor) {
av /= step;

crudeAverage.add(new Point2D.Double(timeAt((i1 + i2) / 2), av));

}

return crudeAverage;

}
Expand Down Expand Up @@ -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());
}

}
13 changes: 8 additions & 5 deletions src/main/java/pulse/problem/schemes/DifferenceScheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,18 @@ public void copyFrom(DifferenceScheme df) {
/**
* <p>
* 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.
* </p>
* <p>
* All subclasses of
* {@code DifferenceScheme} should override and explicitly call this superclass
* method where appropriate.
* </p>
*
* @param problem the heat problem to be solved
* @see pulse.problem.schemes.Grid.adjustTo()
*/

protected void prepare(Problem problem) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ThermalProperties extends PropertyHolder {
* Chem. Eng. Sci. <b>199</b> (2019) 546-551</a>
*/

public final double PARKERS_COEFFICIENT = 0.1370; // in mm
public final double PARKERS_COEFFICIENT = 0.1388; // in mm

public ThermalProperties() {
super();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/pulse/tasks/SearchTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/pulse/tasks/TaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -373,8 +375,12 @@ public void generateTasks(List<File> 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();

}

Expand Down Expand Up @@ -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);
});
}

Expand Down
19 changes: 3 additions & 16 deletions src/main/java/pulse/ui/components/DataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<File> userInput(String descriptor, List<String> extensions) {
JFileChooser fileChooser = new JFileChooser();

Expand Down

0 comments on commit aaf7e8e

Please sign in to comment.