Skip to content
This repository has been archived by the owner on Jul 15, 2018. It is now read-only.

Commit

Permalink
#20 Refactor to use ScaledResults and interpolated time
Browse files Browse the repository at this point in the history
  • Loading branch information
markhalonen committed Jul 10, 2017
1 parent 1c77199 commit 7e81b15
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 58 deletions.
32 changes: 9 additions & 23 deletions src/net/relinc/viewer/GUI/ChartsGUI.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package net.relinc.viewer.GUI;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


import com.sun.javafx.charts.Legend;
import com.sun.javafx.charts.Legend.LegendItem;

Expand All @@ -15,11 +13,8 @@
import javafx.scene.paint.Color;
import net.relinc.libraries.application.LineChartWithMarkers;
import net.relinc.libraries.application.LineChartWithMarkers.chartDataType;
import net.relinc.libraries.data.ReflectedPulse;
import net.relinc.libraries.data.TransmissionPulse;
import net.relinc.libraries.sample.HopkinsonBarSample;
import net.relinc.libraries.sample.Sample;
import net.relinc.libraries.staticClasses.Converter;
import net.relinc.libraries.staticClasses.SPOperations;
import net.relinc.viewer.application.ScaledResults;

Expand Down Expand Up @@ -536,18 +531,12 @@ public LineChartWithMarkers<Number, Number> getFaceForceTimeChart() {

for(Sample s : getCheckedSamples()){
HopkinsonBarSample hopkinsonBarSample = (HopkinsonBarSample)s; // Only hbar samples are checked if face force is graphable.
double[] frontFaceForce = null;
double[] backFaceForce = null;

double sign = hopkinsonBarSample.getTransmissionPulseSign();

frontFaceForce = hopkinsonBarSample.getFrontFaceForce();

TransmissionPulse transmissionPulse = (TransmissionPulse)s.getCurrentLoadDatasubset();

ReflectedPulse reflectedPulse = (ReflectedPulse)s.getCurrentDisplacementDatasubset();

backFaceForce = transmissionPulse.getBackFaceForcePulse(s.barSetup.TransmissionBar, sign);
ScaledResults results = new ScaledResults(hopkinsonBarSample);

double[] frontFaceForce = results.getFrontFaceForce();
double[] backFaceForce = results.getBackFaceForce();
double[] time = results.getTime();

XYChart.Series<Number, Number> series1 = new XYChart.Series<Number, Number>();
series1.setName(s.getName() + " Front Face Force");
Expand All @@ -556,26 +545,23 @@ public LineChartWithMarkers<Number, Number> getFaceForceTimeChart() {

ArrayList<Data<Number, Number>> frontFaceForceDatapoints = new ArrayList<Data<Number, Number>>();
ArrayList<Data<Number, Number>> backFaceForceDatapoints = new ArrayList<Data<Number, Number>>();

double[] frontTime = reflectedPulse.getTrimmedTime();
frontTime = Arrays.copyOfRange(frontTime, 0, frontFaceForce.length);

int totalDataPoints = frontFaceForce.length;
for(int i = 0; i < frontFaceForce.length; i++){
if(!isEnglish.get())
frontFaceForceDatapoints.add(new Data<Number, Number>(frontTime[i] * timeUnits.getMultiplier(), frontFaceForce[i]));
frontFaceForceDatapoints.add(new Data<Number, Number>(time[i], frontFaceForce[i]));
else
frontFaceForceDatapoints.add(new Data<Number, Number>(frontTime[i] * timeUnits.getMultiplier(), Converter.LbfFromN(frontFaceForce[i])));
frontFaceForceDatapoints.add(new Data<Number, Number>(time[i], frontFaceForce[i]));
i += totalDataPoints / DataPointsToShow;
}
series1.getData().addAll(frontFaceForceDatapoints);

totalDataPoints = backFaceForce.length;
for(int i = 0; i < backFaceForce.length; i++){
if(!isEnglish.get())
backFaceForceDatapoints.add(new Data<Number, Number>(transmissionPulse.getTrimmedTime()[i] * timeUnits.getMultiplier(), backFaceForce[i]));
backFaceForceDatapoints.add(new Data<Number, Number>(time[i], backFaceForce[i]));
else
backFaceForceDatapoints.add(new Data<Number, Number>(transmissionPulse.getTrimmedTime()[i] * timeUnits.getMultiplier(), Converter.LbfFromN(backFaceForce[i])));
backFaceForceDatapoints.add(new Data<Number, Number>(time[i], backFaceForce[i]));
i += totalDataPoints / DataPointsToShow;
}
series2.getData().addAll(backFaceForceDatapoints);
Expand Down
10 changes: 1 addition & 9 deletions src/net/relinc/viewer/GUI/ExportGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,6 @@ private void writeCSVFile(File file){
double[] strainRateData = results.getStrainRate();
double[] frontFaceForceData = results.getFrontFaceForce();
double[] backFaceForceData = results.getBackFaceForce();

//List<double[]> data = homeController.getScaledDataArraysFromSample(sample);//, stressData, strainData, strainRateData);

// timeData = data.get(0);
// stressData = data.get(1);
// strainData = data.get(2);
// strainRateData = data.get(3);

timeDataList.add(timeData);
stressDataList.add(stressData);
Expand All @@ -447,8 +440,6 @@ private void writeCSVFile(File file){

if(faceForcePresent)
{
// frontFaceForceData = data.get(4);
// backFaceForceData = data.get(5);
frontFaceForceDataList.add(frontFaceForceData);
backFaceForceDataList.add(backFaceForceData);
}
Expand All @@ -460,6 +451,7 @@ private void writeCSVFile(File file){
String dataLine = "";
for(int j = 0; j < timeDataList.size(); j++){
if(timeDataList.get(j).length > i){

if(faceForcePresent){
dataLine += timeDataList.get(j)[i] + "," + stressDataList.get(j)[i] + "," +
strainDataList.get(j)[i] + "," + strainRateDataList.get(j)[i] + "," +
Expand Down
59 changes: 33 additions & 26 deletions src/net/relinc/viewer/application/ScaledResults.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package net.relinc.viewer.application;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import net.relinc.libraries.data.TransmissionPulse;
import net.relinc.libraries.sample.HopkinsonBarSample;
import net.relinc.libraries.sample.LoadDisplacementSampleResults;
import net.relinc.libraries.sample.Sample;
import net.relinc.libraries.staticClasses.Converter;
import net.relinc.libraries.staticClasses.SPOperations;
Expand Down Expand Up @@ -70,13 +69,9 @@ public ScaledResults(Sample s) {

if (s.isFaceForceGraphable()) {
HopkinsonBarSample hoppy = (HopkinsonBarSample) s;
frontFaceForce = hoppy.getFrontFaceForce();

double sign = hoppy.getTransmissionPulseSign();

TransmissionPulse transmissionPulse = (TransmissionPulse) s.getCurrentLoadDatasubset();

backFaceForce = transmissionPulse.getBackFaceForcePulse(s.barSetup.TransmissionBar, sign);

renderFrontFaceForce(hoppy);
renderBackFaceForce(hoppy);

if (english) {
frontFaceForce = Arrays.stream(frontFaceForce).map(d -> Converter.LbfFromN(d)).toArray();
Expand All @@ -85,6 +80,33 @@ public ScaledResults(Sample s) {
}
}

private void renderFrontFaceForce(HopkinsonBarSample hoppy)
{
Map<String, double[]> forceData = hoppy.getFrontFaceForceInterpolated();
double[] data = forceData.get("force");
double[] timeData = forceData.get("time");
//frontFaceForce = hoppy.getFrontFaceForce();
try {
frontFaceForce =
LoadDisplacementSampleResults.interpolateValues(data, timeData, hoppy.results.time);
} catch (Exception e) {
e.printStackTrace();
}
}

private void renderBackFaceForce(HopkinsonBarSample hoppy)
{
Map<String, double[]> data = hoppy.getBackFaceForceInterpolated();
double[] force = data.get("force");
double[] time = data.get("time");
try {
backFaceForce =
LoadDisplacementSampleResults.interpolateValues(force, time, hoppy.results.time);
} catch (Exception e) {
e.printStackTrace();
}
}

// Returns load or stress, depending on isLoadDisplacement
public double[] getLoad()
{
Expand Down Expand Up @@ -116,20 +138,5 @@ public double[] getTime()
{
return time;
}
// All the data collection should go through this. Maybe use dictionary instead of indexes.
public List<double[]> getScaledDataArraysFromSample(Sample s, boolean isStress, boolean english, boolean engineering, MetricMultiplier timeUnits){//, double[] stress, double[] strain, double[] strainRate){


ArrayList<double[]> a = new ArrayList<>();
return a;
// a.add(time);
// a.add(stress);
// a.add(strain);
// a.add(strainRate);
// if(s.isFaceForceGraphable()){
// a.add(frontFaceForce);
// a.add(backFaceForce);
// }
// return a;
}

}

0 comments on commit 7e81b15

Please sign in to comment.