Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit caf3237

Browse filesBrowse files
committed
Pulse & logs
- Better handling of pulse discretisation - Fixed graphical log updates - Better pulse visualisation
1 parent 532d08c commit caf3237
Copy full SHA for caf3237
Expand file treeCollapse file tree

25 files changed

+294
-174
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>kotik-coder</groupId>
55
<artifactId>PULsE</artifactId>
6-
<version>1.97</version>
6+
<version>1.97b</version>
77
<name>PULsE</name>
88
<description>Processing Unit for Laser flash Experiments</description>
99
<developers>
@@ -18,20 +18,19 @@
1818
<name>The Apache License, Version 2.0</name>
1919
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
2020
</license>
21-
</licenses>
22-
21+
</licenses>
2322
<dependencies>
2423
<dependency>
2524
<groupId>org.jfree</groupId>
2625
<artifactId>jfreechart</artifactId>
2726
<version>1.5.0</version>
2827
</dependency>
2928
<dependency>
30-
<groupId>com.weblookandfeel</groupId>
31-
<artifactId>weblaf-ui</artifactId>
32-
<version>1.2.13</version>
29+
<groupId>com.formdev</groupId>
30+
<artifactId>flatlaf</artifactId>
31+
<version>3.0</version>
3332
</dependency>
34-
<dependency>
33+
<dependency>
3534
<groupId>org.apache.commons</groupId>
3635
<artifactId>commons-math3</artifactId>
3736
<version>3.6.1</version>

‎src/main/java/pulse/problem/laser/DiscretePulse.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/problem/laser/DiscretePulse.java
+105-67Lines changed: 105 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import pulse.problem.schemes.Grid;
88
import pulse.problem.statements.Problem;
99
import pulse.problem.statements.Pulse;
10+
import static pulse.properties.NumericProperties.derive;
11+
import static pulse.properties.NumericPropertyKeyword.TAU_FACTOR;
1012
import pulse.tasks.SearchTask;
13+
import pulse.util.PropertyHolderListener;
1114

1215
/**
1316
* A {@code DiscretePulse} is an object that acts as a medium between the
@@ -20,9 +23,10 @@ public class DiscretePulse {
2023

2124
private final Grid grid;
2225
private final Pulse pulse;
23-
26+
private final ExperimentalData data;
27+
2428
private double widthOnGrid;
25-
private double timeConversionFactor;
29+
private double characteristicTime;
2630
private double invTotalEnergy; //normalisation factor
2731

2832
/**
@@ -49,29 +53,28 @@ public class DiscretePulse {
4953
*/
5054
public DiscretePulse(Problem problem, Grid grid) {
5155
this.grid = grid;
52-
timeConversionFactor = problem.getProperties().timeFactor();
56+
characteristicTime = problem.getProperties().characteristicTime();
5357
this.pulse = problem.getPulse();
5458

5559
Object ancestor
5660
= Objects.requireNonNull(problem.specificAncestor(SearchTask.class),
5761
"Problem has not been assigned to a SearchTask");
5862

59-
ExperimentalData data =
60-
(ExperimentalData) ( ((SearchTask) ancestor).getInput() );
61-
init(data);
62-
63+
data = (ExperimentalData) (((SearchTask) ancestor).getInput());
64+
init();
65+
66+
PropertyHolderListener phl = e -> {
67+
characteristicTime = problem.getProperties().characteristicTime();
68+
widthOnGrid = 0;
69+
init();
70+
};
71+
6372
pulse.addListener(e -> {
64-
timeConversionFactor = problem.getProperties().timeFactor();
65-
init(data);
73+
widthOnGrid = 0;
74+
init();
6675
});
67-
68-
}
69-
70-
private void init(ExperimentalData data) {
71-
widthOnGrid = 0;
72-
recalculate();
73-
pulse.getPulseShape().init(data, this);
74-
invTotalEnergy = 1.0/totalEnergy();
76+
problem.addListener(phl);
77+
7578
}
7679

7780
/**
@@ -91,39 +94,77 @@ public double laserPowerAt(double time) {
9194
*
9295
* @see pulse.problem.schemes.Grid.gridTime(double,double)
9396
*/
94-
public final void recalculate() {
95-
final double nominalWidth = ((Number) pulse.getPulseWidth().getValue()).doubleValue();
96-
final double resolvedWidth = timeConversionFactor / getWidthToleranceFactor();
97+
public final void init() {
98+
final double nominalWidth = ((Number) pulse.getPulseWidth().getValue()).doubleValue();
99+
final double resolvedWidth = resolvedPulseWidthSeconds();
97100

98101
final double EPS = 1E-10;
99-
102+
103+
double oldValue = widthOnGrid;
104+
this.widthOnGrid = pulseWidthGrid();
105+
100106
/**
101107
* The pulse is too short, which makes calculations too expensive. Can
102108
* we replace it with a rectangular pulse shape instead?
103109
*/
104-
105-
if (nominalWidth < resolvedWidth - EPS && widthOnGrid < EPS) {
110+
if (nominalWidth < resolvedWidth - EPS && oldValue < EPS) {
106111
//change shape to rectangular
107112
var shape = new RectangularPulse();
108-
pulse.setPulseShape(shape);
109-
//change pulse width
110-
setDiscreteWidth(resolvedWidth);
113+
pulse.setPulseShape(shape);
111114
shape.init(null, this);
112-
//adjust the pulse object to update the visualised pulse
113-
} else if(nominalWidth > resolvedWidth + EPS) {
114-
setDiscreteWidth(nominalWidth);
115-
}
116-
117-
invTotalEnergy = 1.0/totalEnergy();
118-
115+
} else {
116+
pulse.getPulseShape().init(data, this);
117+
}
118+
119+
invTotalEnergy = 1.0 / totalEnergy();
119120
}
120-
121+
121122
/**
122-
* Calculates the total pulse energy using a numerical integrator.The
123-
* normalisation factor is then equal to the inverse total energy.
124-
* @return the total pulse energy, assuming sample area fully covered by the beam
123+
* Optimises the {@code Grid} parameters so that the timestep is
124+
* sufficiently small to enable accurate pulse correction.
125+
* <p>
126+
* This can change the {@code tauFactor} and {@code tau} variables in the
127+
* {@code Grid} object if {@code discretePulseWidth/(M - 1) < grid.tau},
128+
* where M is the required number of pulse calculations.
129+
* </p>
130+
*
131+
* @see PulseTemporalShape.getRequiredDiscretisation()
125132
*/
133+
public double pulseWidthGrid() {
134+
//minimum number of points for pulse calculation
135+
int reqPoints = pulse.getPulseShape().getRequiredDiscretisation();
136+
//physical pulse width in time units
137+
double experimentalWidth = (double) pulse.getPulseWidth().getValue();
138+
139+
//minimum resolved pulse width in time units for that specific problem
140+
double resolvedWidth = resolvedPulseWidthSeconds();
141+
142+
double pWidth = Math.max(experimentalWidth, resolvedWidth);
143+
144+
final double EPS = 1E-10;
126145

146+
double newTau = pWidth / characteristicTime / reqPoints;
147+
148+
double result = 0;
149+
150+
if (newTau < grid.getTimeStep() - EPS) {
151+
double newTauFactor = (double) grid.getTimeFactor().getValue() / 2.0;
152+
grid.setTimeFactor(derive(TAU_FACTOR, newTauFactor));
153+
result = pulseWidthGrid();
154+
} else {
155+
result = grid.gridTime(pWidth, characteristicTime);
156+
}
157+
158+
return result;
159+
}
160+
161+
/**
162+
* Calculates the total pulse energy using a numerical integrator.The
163+
* normalisation factor is then equal to the inverse total energy.
164+
*
165+
* @return the total pulse energy, assuming sample area fully covered by the
166+
* beam
167+
*/
127168
public final double totalEnergy() {
128169
var pulseShape = pulse.getPulseShape();
129170

@@ -140,27 +181,22 @@ public double integrand(double... vars) {
140181
}
141182

142183
/**
143-
* Gets the discrete dimensionless pulse width, which is a multiplier of the current
144-
* grid timestep. The pulse width is converted to the dimensionless pulse width by
145-
* dividing the real value by <i>l</i><sup>2</sup>/a.
184+
* Gets the discrete dimensionless pulse width, which is a multiplier of the
185+
* current grid timestep. The pulse width is converted to the dimensionless
186+
* pulse width by dividing the real value by <i>l</i><sup>2</sup>/a.
146187
*
147188
* @return the dimensionless pulse width mapped to the grid.
148189
*/
149190
public double getDiscreteWidth() {
150191
return widthOnGrid;
151192
}
152-
153-
private void setDiscreteWidth(double width) {
154-
widthOnGrid = grid.gridTime(width, timeConversionFactor);
155-
grid.adjustTimeStep(this);
156-
}
157193

158194
/**
159195
* Gets the physical {@code Pulse}
160196
*
161197
* @return the {@code Pulse} object
162198
*/
163-
public Pulse getPulse() {
199+
public Pulse getPhysicalPulse() {
164200
return pulse;
165201
}
166202

@@ -172,36 +208,38 @@ public Pulse getPulse() {
172208
public Grid getGrid() {
173209
return grid;
174210
}
175-
211+
176212
/**
177-
* Gets the dimensional factor required to convert real time variable into
178-
* a dimensional variable, defined in the {@code Problem} class
213+
* Gets the dimensional factor required to convert real time variable into a
214+
* dimensional variable, defined in the {@code Problem} class
215+
*
179216
* @return the conversion factor
180217
*/
181-
182-
public double getConversionFactor() {
183-
return timeConversionFactor;
218+
public double getCharacteristicTime() {
219+
return characteristicTime;
184220
}
185-
221+
186222
/**
187-
* Gets the minimal resolved pulse width defined by the {@code WIDTH_TOLERANCE_FACTOR}
188-
* and the characteristic time given by the {@code getConversionFactor}.
189-
* @return
223+
* Gets the minimal resolved pulse width defined by the
224+
* {@code WIDTH_TOLERANCE_FACTOR} and the characteristic time given by the
225+
* {@code getConversionFactor}.
226+
*
227+
* @return
190228
*/
191-
192-
public double resolvedPulseWidth() {
193-
return timeConversionFactor / getWidthToleranceFactor();
229+
public double resolvedPulseWidthSeconds() {
230+
return characteristicTime / getWidthToleranceFactor();
194231
}
195-
196-
/**
197-
* Assuming a characteristic time is divided by the return value of this method
198-
* and is set to the minimal resolved pulse width, shows how small a pulse width
199-
* can be to enable finite pulse correction.
200-
* @return the smallest fraction of a characteristic time resolved as a finite pulse.
232+
233+
/**
234+
* Assuming a characteristic time is divided by the return value of this
235+
* method and is set to the minimal resolved pulse width, shows how small a
236+
* pulse width can be to enable finite pulse correction.
237+
*
238+
* @return the smallest fraction of a characteristic time resolved as a
239+
* finite pulse.
201240
*/
202-
203241
public int getWidthToleranceFactor() {
204242
return WIDTH_TOLERANCE_FACTOR;
205243
}
206244

207-
}
245+
}

‎src/main/java/pulse/problem/laser/DiscretePulse2D.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/problem/laser/DiscretePulse2D.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class DiscretePulse2D extends DiscretePulse {
2626
* This had to be decreased for the 2d pulses.
2727
*/
2828

29-
private final static int WIDTH_TOLERANCE_FACTOR = 2000;
29+
private final static int WIDTH_TOLERANCE_FACTOR = 1000;
3030

3131
/**
3232
* The constructor for {@code DiscretePulse2D}.
@@ -90,7 +90,7 @@ private void calcPulseSpot(ExtendedThermalProperties properties) {
9090
* @see pulse.problem.schemes.Grid2D.gridRadialDistance(double,double)
9191
*/
9292
public final void evalPulseSpot() {
93-
var pulse = (Pulse2D) getPulse();
93+
var pulse = (Pulse2D) getPhysicalPulse();
9494
var grid2d = (Grid2D) getGrid();
9595
final double spotRadius = (double) pulse.getSpotDiameter().getValue() / 2.0;
9696
discretePulseSpot = grid2d.gridRadialDistance(spotRadius, sampleRadius);

‎src/main/java/pulse/problem/laser/NumericPulse.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/problem/laser/NumericPulse.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void init(ExperimentalData data, DiscretePulse pulse) {
6464
setPulseWidthOf(problem);
6565

6666
//convert to dimensionless time and interpolate
67-
double timeFactor = problem.getProperties().timeFactor();
67+
double timeFactor = problem.getProperties().characteristicTime();
6868
doInterpolation(timeFactor);
6969
}
7070

‎src/main/java/pulse/problem/laser/RectangularPulse.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/problem/laser/RectangularPulse.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
public class RectangularPulse extends PulseTemporalShape {
1616

17-
private final static int MIN_POINTS = 4;
17+
private final static int MIN_POINTS = 2;
1818

1919
/**
2020
* @param time the time measured from the start of the laser pulse.
@@ -41,4 +41,4 @@ public int getRequiredDiscretisation() {
4141
return MIN_POINTS;
4242
}
4343

44-
}
44+
}

‎src/main/java/pulse/problem/laser/TrapezoidalPulse.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/problem/laser/TrapezoidalPulse.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class TrapezoidalPulse extends PulseTemporalShape {
2222
private double fall;
2323
private double h;
2424

25-
private final static int MIN_POINTS = 6;
25+
private final static int MIN_POINTS = 8;
2626

2727
/**
2828
* Constructs a trapezoidal pulse using a default segmentation principle.

‎src/main/java/pulse/problem/schemes/DifferenceScheme.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/problem/schemes/DifferenceScheme.java
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package pulse.problem.schemes;
22

3+
import java.util.Objects;
34
import static pulse.properties.NumericProperties.def;
45
import static pulse.properties.NumericProperties.derive;
56
import static pulse.properties.NumericProperty.requireType;
@@ -92,7 +93,7 @@ protected void prepare(Problem problem) throws SolverException {
9293
if (discretePulse == null) {
9394
discretePulse = problem.discretePulseOn(grid);
9495
}
95-
discretePulse.recalculate();
96+
discretePulse.init();
9697
clearArrays();
9798
}
9899

@@ -114,13 +115,13 @@ public void runTimeSequence(Problem problem, final double offset, final double e
114115
int numPoints = (int) curve.getNumPoints().getValue();
115116

116117
final double startTime = (double) curve.getTimeShift().getValue();
117-
final double timeSegment = (endTime - startTime - offset) / problem.getProperties().timeFactor();
118+
final double timeSegment = (endTime - startTime - offset) / problem.getProperties().characteristicTime();
118119

119120
double tau = grid.getTimeStep();
120121
final double dt = timeSegment / (numPoints - 1);
121122
timeInterval = Math.max( (int) (dt / tau), 1);
122123

123-
double wFactor = timeInterval * tau * problem.getProperties().timeFactor();
124+
double wFactor = timeInterval * tau * problem.getProperties().characteristicTime();
124125

125126
// First point (index = 0) is always (0.0, 0.0)
126127
curve.addPoint(0.0, 0.0);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.