Skip to content

Commit

Permalink
1.91FM_01
Browse files Browse the repository at this point in the history
Better error handling in SearchTask: now instead of freezing on
nonsensical values, an exception is thrown by the assign() method in
ThermalProperties if the numeric properties in the ParameterVector do
not pass the validate() check, and is handled by setting the status of
the task to failed and breaking the main loop of the search.

Better handling of very small pulses where calculations could previously
start with a pulse width = 0 (less than the grid time step)

Better calculation of the maximum temperature rise for the heating
curves (baseline correction)
  • Loading branch information
Artem Lunev committed Jun 11, 2021
1 parent 8fb90b3 commit 0f2f95b
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>kotik-coder</groupId>
<artifactId>PULsE</artifactId>
<version>1.91FM</version>
<version>1.91FM_01</version>
<name>PULsE</name>
<description>Processing Unit for Laser flash Experiments</description>
<developers>
Expand Down
22 changes: 9 additions & 13 deletions src/main/java/pulse/input/ExperimentalData.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public List<Point2D> runningAverage(int reductionFactor) {

List<Point2D> crudeAverage = new ArrayList<>(count / reductionFactor);

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

int step = (end - start) / (count / reductionFactor);
double av = 0;
Expand Down Expand Up @@ -193,9 +193,9 @@ public List<Point2D> runningAverage(int reductionFactor) {
* @see pulse.problem.statements.Problem.estimateSignalRange(ExperimentalData)
*/

public double maxAdjustedSignal() {
public Point2D maxAdjustedSignal() {
var degraded = runningAverage(REDUCTION_FACTOR);
return (max(degraded, pointComparator)).getY();
return max(degraded, pointComparator);
}

/**
Expand All @@ -217,18 +217,14 @@ public double maxAdjustedSignal() {
*/

public double halfRiseTime() {
var degraded = runningAverage(REDUCTION_FACTOR);
double max = (max(degraded, pointComparator)).getY();
var baseline = new FlatBaseline();
var degraded = runningAverage(REDUCTION_FACTOR);
var max = (max(degraded, pointComparator));
var baseline = new FlatBaseline();
baseline.fitTo(this);

double halfMax = (max + baseline.valueAt(0)) / 2.0;

int cutoffIndex = degraded.size() - 1;

for(int i = cutoffIndex; i > 0 && degraded.get(i).getY() < halfMax; i--)
cutoffIndex--;
double halfMax = (max.getY() + baseline.valueAt(0)) / 2.0;

int cutoffIndex = degraded.indexOf(max);
degraded = degraded.subList(0, cutoffIndex);

int index = IndexRange.closestLeft(halfMax,
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/pulse/math/ParameterVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pulse.math.linear.Vector;
import pulse.math.transforms.Transformable;
import pulse.properties.NumericProperties;
import pulse.properties.NumericPropertyKeyword;

/**
Expand Down Expand Up @@ -214,6 +215,15 @@ public String toString() {
sb.append(" Values: " + super.toString());
return sb.toString();
}

public boolean validate() {
for(int i = 0; i < this.dimension(); i++) {
if( !NumericProperties.derive(this.getIndex(i), inverseTransform(i)).validate() ) {
return false;
}
}
return true;
}

public Segment[] getBounds() {
return bounds;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pulse/problem/laser/DiscretePulse.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public double laserPowerAt(double time) {

public void recalculate() {
final double width = ((Number) pulse.getPulseWidth().getValue()).doubleValue();
discretePulseWidth = grid.gridTime(width, timeFactor);
discretePulseWidth = Math.max( grid.gridTime(width, timeFactor), grid.getTimeStep() );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public double evalRightBoundary(final int m, final double alphaN, final double b
return (HH * getPreviousSolution()[N] + 2. * tau * betaN) / (2 * Bi1HTAU + HH - 2. * tau * (alphaN - 1));
}


@Override
public DifferenceScheme copy() {
var grid = getGrid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pulse.problem.schemes.DifferenceScheme;
import pulse.problem.schemes.Grid;
import pulse.problem.schemes.Grid2D;
import pulse.problem.schemes.solvers.SolverException;
import pulse.problem.statements.model.ExtendedThermalProperties;
import pulse.problem.statements.model.ThermalProperties;
import pulse.properties.Flag;
Expand Down Expand Up @@ -102,7 +103,7 @@ public void optimisationVector(ParameterVector output, List<Flag> flags) {
}

@Override
public void assign(ParameterVector params) {
public void assign(ParameterVector params) throws SolverException {
super.assign(params);
var properties = (ExtendedThermalProperties) getProperties();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/pulse/problem/statements/CoreShellProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pulse.math.transforms.InvDiamTransform;
import pulse.math.transforms.InvLenSqTransform;
import pulse.math.transforms.InvLenTransform;
import pulse.problem.schemes.solvers.SolverException;
import pulse.problem.statements.model.ExtendedThermalProperties;
import pulse.properties.Flag;
import pulse.properties.NumericProperty;
Expand Down Expand Up @@ -139,7 +140,7 @@ public void optimisationVector(ParameterVector output, List<Flag> flags) {
}

@Override
public void assign(ParameterVector params) {
public void assign(ParameterVector params) throws SolverException {
super.assign(params);

for (int i = 0, size = params.dimension(); i < size; i++) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/pulse/problem/statements/DiathermicMedium.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pulse.math.transforms.AtanhTransform;
import pulse.problem.schemes.DifferenceScheme;
import pulse.problem.schemes.solvers.ImplicitDiathermicSolver;
import pulse.problem.schemes.solvers.SolverException;
import pulse.problem.statements.model.DiathermicProperties;
import pulse.problem.statements.model.ThermalProperties;
import pulse.properties.Flag;
Expand Down Expand Up @@ -80,7 +81,7 @@ public void optimisationVector(ParameterVector output, List<Flag> flags) {
}

@Override
public void assign(ParameterVector params) {
public void assign(ParameterVector params) throws SolverException {
super.assign(params);
var properties = (DiathermicProperties) this.getProperties();

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pulse/problem/statements/NonlinearProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pulse.math.transforms.AtanhTransform;
import pulse.problem.schemes.DifferenceScheme;
import pulse.problem.schemes.ImplicitScheme;
import pulse.problem.schemes.solvers.SolverException;
import pulse.properties.Flag;
import pulse.properties.NumericProperty;
import pulse.properties.Property;
Expand Down Expand Up @@ -96,11 +97,12 @@ public void optimisationVector(ParameterVector output, List<Flag> flags) {
*
* @param params the optimisation vector, containing a similar set of parameters
* to this {@code Problem}
* @throws SolverException
* @see listedTypes()
*/

@Override
public void assign(ParameterVector params) {
public void assign(ParameterVector params) throws SolverException {
super.assign(params);
var p = getProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pulse.math.transforms.Transformable;
import pulse.problem.schemes.DifferenceScheme;
import pulse.problem.schemes.solvers.MixedCoupledSolver;
import pulse.problem.schemes.solvers.SolverException;
import pulse.problem.statements.model.ThermalProperties;
import pulse.problem.statements.model.ThermoOpticalProperties;
import pulse.properties.Flag;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void optimisationVector(ParameterVector output, List<Flag> flags) {
}

@Override
public void assign(ParameterVector params) {
public void assign(ParameterVector params) throws SolverException {
super.assign(params);
var properties = (ThermoOpticalProperties)getProperties();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pulse.math.Segment;
import pulse.problem.schemes.DifferenceScheme;
import pulse.problem.schemes.solvers.ImplicitTranslucentSolver;
import pulse.problem.schemes.solvers.SolverException;
import pulse.problem.statements.model.AbsorptionModel;
import pulse.problem.statements.model.BeerLambertAbsorption;
import pulse.properties.Flag;
Expand Down Expand Up @@ -94,7 +95,7 @@ public void optimisationVector(ParameterVector output, List<Flag> flags) {
}

@Override
public void assign(ParameterVector params) {
public void assign(ParameterVector params) throws SolverException {
super.assign(params);

double value;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/pulse/problem/statements/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import pulse.problem.schemes.DifferenceScheme;
import pulse.problem.schemes.Grid;
import pulse.problem.schemes.solvers.Solver;
import pulse.problem.schemes.solvers.SolverException;
import pulse.problem.statements.model.ThermalProperties;
import pulse.properties.Flag;
import pulse.properties.NumericProperty;
Expand Down Expand Up @@ -199,7 +200,8 @@ public void retrieveData(ExperimentalData c) {
*/

public void estimateSignalRange(ExperimentalData c) {
final double signalHeight = c.maxAdjustedSignal() - baseline.valueAt(0);
var maxPoint = c.maxAdjustedSignal();
final double signalHeight = maxPoint.getY() - baseline.valueAt(maxPoint.getX());
properties.setMaximumTemperature(derive(MAXTEMP, signalHeight));
}

Expand Down Expand Up @@ -279,7 +281,12 @@ protected void setHeatLossParameter(ParameterVector output, int i, double Bi) {
*/

@Override
public void assign(ParameterVector params) {
public void assign(ParameterVector params) throws SolverException {

if(!params.validate()) {
throw new SolverException("Parameter values not sensible");
}

baseline.assign(params);
for (int i = 0, size = params.dimension(); i < size; i++) {

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pulse/search/Optimisable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import pulse.math.ParameterVector;
import pulse.problem.schemes.solvers.SolverException;
import pulse.properties.Flag;

/**
Expand All @@ -20,10 +21,11 @@ public interface Optimisable {
*
* @param params the optimisation vector, containing a similar set of parameters
* to this {@code Problem}
* @throws SolverException if {@code params} contains invalid parameter values
* @see pulse.util.PropertyHolder.listedTypes()
*/

public void assign(ParameterVector params);
public void assign(ParameterVector params) throws SolverException;

/**
* Calculates the vector argument defined on <math><b>R</b><sup>n</sup></math>
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/pulse/tasks/SearchTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import pulse.tasks.listeners.TaskRepositoryEvent;
import pulse.tasks.logs.CorrelationLogEntry;
import pulse.tasks.logs.DataLogEntry;
import pulse.tasks.logs.Details;
import pulse.tasks.logs.Log;
import pulse.tasks.logs.LogEntry;
import pulse.tasks.logs.StateEntry;
Expand Down Expand Up @@ -217,7 +218,14 @@ public ParameterVector searchVector() {
*/

public void assign(ParameterVector searchParameters) {
current.getProblem().assign(searchParameters);
try {
current.getProblem().assign(searchParameters);
} catch (SolverException e) {
var status = FAILED;
status.setDetails(Details.PARAMETER_VALUES_NOT_SENSIBLE);
setStatus(status);
e.printStackTrace();
}
curve.getRange().assign(searchParameters);
}

Expand Down Expand Up @@ -282,7 +290,7 @@ public void run() {
outer: do {

bufferFutures.clear();

for (var i = 0; i < bufferSize; i++) {

if (current.getStatus() != IN_PROGRESS)
Expand All @@ -291,12 +299,14 @@ public void run() {
int iter = 0;

try {
for (boolean finished = false; !finished && iter < maxIterations; iter++)
finished = optimiser.iteration(this);
for (boolean finished = false; !finished && iter < maxIterations; iter++) {
finished = optimiser.iteration(this);
}
} catch (SolverException e) {
setStatus(FAILED);
System.err.println(this + " failed during execution. Details: ");
e.printStackTrace();
break outer;
}

if(iter >= maxIterations) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/pulse/ui/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class Launcher {
private final static boolean DEBUG = false;

private Launcher() {
arrangeErrorOutput();
if(!DEBUG)
arrangeErrorOutput();
arrangeMessages();
}

Expand Down Expand Up @@ -82,9 +83,6 @@ private static void splashScreen() {
}

private void arrangeErrorOutput() {
if (DEBUG)
return;

String path = Launcher.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = "";
//
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/pulse/ui/components/panels/ProblemToolbar.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ private void addListeners() {
// simulate btn listener

btnSimulate.addActionListener((ActionEvent e) -> {
if (instance.getSelectedTask() == null)
instance.selectFirstTask();

var t = instance.getSelectedTask();

if (t == null)
return;


var calc = t.getCurrentCalculation();

t.checkProblems(true);
var status = t.getCurrentCalculation().getStatus();

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/NumericProperty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@
abbreviation="&lt;i&gt;t&lt;/i&gt;&lt;sub&gt;lim&lt;/sub&gt;"
auto-adjustable="true"
descriptor="End time, &lt;i&gt;t&lt;/i&gt;&lt;sub&gt;lim&lt;/sub&gt; (s)"
dimensionfactor="1.0" keyword="TIME_LIMIT" maximum="20.0"
dimensionfactor="1.0" keyword="TIME_LIMIT" maximum="100.0"
minimum="1.0E-6" value="1.0" primitive-type="double" discreet="true"
default-search-variable="false" />
<NumericProperty
Expand Down Expand Up @@ -438,11 +438,11 @@
auto-adjustable="true"
descriptor="Heat loss (side surface), Bi&lt;sub&gt;s&lt;/sub&gt;"
dimensionfactor="1.0" keyword="HEAT_LOSS_SIDE" maximum="10.0"
minimum="0.0" value="1E-3" primitive-type="double" discreet="false"
minimum="0.0" value="0.2" primitive-type="double" discreet="false"
default-search-variable="true" />
<NumericProperty keyword="HEAT_LOSS" abbreviation="Bi"
auto-adjustable="true" descriptor="Heat loss, Bi" dimensionfactor="1"
maximum="10" minimum="0.0" primitive-type="double" value="1E-3"
maximum="10" minimum="0.0" primitive-type="double" value="0.2"
discreet="false" default-search-variable="true">
</NumericProperty>
<NumericProperty abbreviation="Gain" auto-adjustable="false"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.91FM
1.91FM_01

0 comments on commit 0f2f95b

Please sign in to comment.