From 7e81b155febe5f237eb48ce7b0c2893ba297a872 Mon Sep 17 00:00:00 2001 From: mark Date: Mon, 10 Jul 2017 12:46:44 -0400 Subject: [PATCH] #20 Refactor to use ScaledResults and interpolated time --- src/net/relinc/viewer/GUI/ChartsGUI.java | 32 +++------- src/net/relinc/viewer/GUI/ExportGUI.java | 10 +--- .../viewer/application/ScaledResults.java | 59 +++++++++++-------- 3 files changed, 43 insertions(+), 58 deletions(-) diff --git a/src/net/relinc/viewer/GUI/ChartsGUI.java b/src/net/relinc/viewer/GUI/ChartsGUI.java index 924ae4e..a0e6a65 100644 --- a/src/net/relinc/viewer/GUI/ChartsGUI.java +++ b/src/net/relinc/viewer/GUI/ChartsGUI.java @@ -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; @@ -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; @@ -536,18 +531,12 @@ public LineChartWithMarkers 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 series1 = new XYChart.Series(); series1.setName(s.getName() + " Front Face Force"); @@ -556,16 +545,13 @@ public LineChartWithMarkers getFaceForceTimeChart() { ArrayList> frontFaceForceDatapoints = new ArrayList>(); ArrayList> backFaceForceDatapoints = new ArrayList>(); - - 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(frontTime[i] * timeUnits.getMultiplier(), frontFaceForce[i])); + frontFaceForceDatapoints.add(new Data(time[i], frontFaceForce[i])); else - frontFaceForceDatapoints.add(new Data(frontTime[i] * timeUnits.getMultiplier(), Converter.LbfFromN(frontFaceForce[i]))); + frontFaceForceDatapoints.add(new Data(time[i], frontFaceForce[i])); i += totalDataPoints / DataPointsToShow; } series1.getData().addAll(frontFaceForceDatapoints); @@ -573,9 +559,9 @@ public LineChartWithMarkers getFaceForceTimeChart() { totalDataPoints = backFaceForce.length; for(int i = 0; i < backFaceForce.length; i++){ if(!isEnglish.get()) - backFaceForceDatapoints.add(new Data(transmissionPulse.getTrimmedTime()[i] * timeUnits.getMultiplier(), backFaceForce[i])); + backFaceForceDatapoints.add(new Data(time[i], backFaceForce[i])); else - backFaceForceDatapoints.add(new Data(transmissionPulse.getTrimmedTime()[i] * timeUnits.getMultiplier(), Converter.LbfFromN(backFaceForce[i]))); + backFaceForceDatapoints.add(new Data(time[i], backFaceForce[i])); i += totalDataPoints / DataPointsToShow; } series2.getData().addAll(backFaceForceDatapoints); diff --git a/src/net/relinc/viewer/GUI/ExportGUI.java b/src/net/relinc/viewer/GUI/ExportGUI.java index b6079bb..88b51a6 100644 --- a/src/net/relinc/viewer/GUI/ExportGUI.java +++ b/src/net/relinc/viewer/GUI/ExportGUI.java @@ -432,13 +432,6 @@ private void writeCSVFile(File file){ double[] strainRateData = results.getStrainRate(); double[] frontFaceForceData = results.getFrontFaceForce(); double[] backFaceForceData = results.getBackFaceForce(); - - //List 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); @@ -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); } @@ -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] + "," + diff --git a/src/net/relinc/viewer/application/ScaledResults.java b/src/net/relinc/viewer/application/ScaledResults.java index b773120..3e3b0ee 100644 --- a/src/net/relinc/viewer/application/ScaledResults.java +++ b/src/net/relinc/viewer/application/ScaledResults.java @@ -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; @@ -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(); @@ -85,6 +80,33 @@ public ScaledResults(Sample s) { } } + private void renderFrontFaceForce(HopkinsonBarSample hoppy) + { + Map 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 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() { @@ -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 getScaledDataArraysFromSample(Sample s, boolean isStress, boolean english, boolean engineering, MetricMultiplier timeUnits){//, double[] stress, double[] strain, double[] strainRate){ - - - ArrayList 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; - } + }