@@ -19,6 +19,12 @@ |
import org.jfree.data.xy.XYSeries; |
import org.jfree.data.xy.XYSeriesCollection; |
|
+/** |
+* Last Updated: 7-August-2015 |
+* @author Chris Dumler |
+* @since 22-June-2015 |
+*/ |
+ |
public class StandardStepMethod { |
|
boolean irregularGeometry =true; |
@@ -135,17 +141,59 @@ |
} |
} |
|
+ /** |
+ * Created new Standard Step Model object and starts 'run' method. |
+ * |
+ * @param args |
+ * |
+ * @throws IOException |
+ */ |
+ |
public static void main(String[] args) throws IOException { |
StandardStepMethod model = new StandardStepMethod(); |
model.run(); |
- } |
+ }//end main |
+ |
+ /** |
+ * Starts calcStandardStepMethod(). |
+ * |
+ * @throws IOException |
+ */ |
|
public void run() throws IOException { |
|
calcStandardStepMethod(); |
- |
- } //end of run |
+ }//end run |
|
+ /** |
+ * Calculates the water depth at each subsequent cross section using the |
+ * Standard Step Equation. |
+ * For irregular channel geometries, uses xy-point cross sections and channel |
+ * reach characteristics provided by text files in destination folder. |
+ * Cross-sections must be formatted as below: |
+ * (0|100)(20|100)(30|95)(40|90)(50|90)(60|95)(70|100)(90|100) |
+ * (0|100)(20|99.96)(35|94.96)(50|89.96)(65|89.96)(80|94.96)(95|99.96)(115|100) |
+ * Note: Each pair of numbers within a set of parentheses represents an xy-point |
+ * along the cross section. The y-point can be used to determine elevation and |
+ * bed slope. |
+ * Reach data must be formatted as below: |
+ * 100|.035|.05|0 |
+ * Note: The first number is the reach length, the second is manning's n, the |
+ * third is the seepage, and the forth is the reach slope. This is optional as it |
+ * can also be determined using the thalweg elevation from the given cross-sections. |
+ * For uniform-trapezoidal channels, the channel variables can be set using the |
+ * appropriate 'set' methods and the graphs and summary file will be created in |
+ * the designated folder. |
+ * |
+ * Returns a graph of the longitudinal depth and elevation profiles as well as a text |
+ * file containing all the important information for each cross-section and reach. For irregular channels, the graphs |
+ * and summary file are created in the same folder that contains the 'reaches' and 'crossSections' |
+ * text files. For uniform channels, the graphs and summary file are created in the designated folder. |
+ * |
+ * @throws IOException |
+ * |
+ */ |
+ |
public void calcStandardStepMethod() throws IOException { |
|
if (irregularGeometry) { |
@@ -252,7 +300,7 @@ |
guessDepth_US = (lower + upper) / 2; |
USValues = setUSValues(currentCrossSectionGeometry_US, |
currentReachProperties, |
- guessDepth_US);; |
+ guessDepth_US); |
velocity_US = calcVelocity(USValues); |
frictionSlope_US = calcFrictionSlope(USValues); |
|
@@ -411,7 +459,20 @@ |
"Channel Bed (x-axis)", |
"Depth (m)"); |
|
- } //end calcStandardStepMethod |
+ }//end calcStandardStepMethod |
+ |
+ /** |
+ * Calculates the max and min water elevations to plug into the Standard Step |
+ * Equation based on the water surface profile. |
+ * |
+ * @param depth_DS The depth at the downstream cross-section. |
+ * @param criticalDepth The critical depth at the upstream cross-section. |
+ * @param normalDepth The normal depth at the upstream cross-section. |
+ * |
+ * @return An array containing the minimum(a) and maximum(b) water depths. |
+ * |
+ * @throws IOException |
+ */ |
|
public double[] calcBoundaryConditions(double depth_DS, |
double criticalDepth, |
@@ -477,7 +538,22 @@ |
boundaries[0] = a; |
boundaries[1] = b; |
return boundaries; |
- } //end calcBoundaryConditions |
+ }//end calcBoundaryConditions |
+ |
+ /** |
+ * Creates a 2-dimensional array containing the calculated elevation values for the current |
+ * cross-section. This array is then imported into a 3-dimensional array containing the |
+ * depth values for every cross-section in a given channel. |
+ * |
+ * @param waterDepth The calculated depth at the current cross-section. |
+ * @param critDepth The calculated critical depth at the given cross-section. |
+ * @param normDepth The calculated normal depth at the given cross-section. |
+ * @param distance_DS The distance of the given cross-section from the origin. |
+ * @param bedElevation The elevation of the channel bed above or below the origin. |
+ * |
+ * @return A 2-dimensional array containing the calculated elevation values for |
+ * the current cross-section. |
+ */ |
|
public double[][] writeElevationArray(double waterDepth, |
double critDepth, |
@@ -493,7 +569,22 @@ |
results[1][3] = bedElevation; |
|
return results; |
- } |
+ }//end writeElevationArray |
+ |
+ /** |
+ * Creates a 2-dimensional array containing the calculated depth values for the current |
+ * cross-section. This array is then imported into a 3-dimensional array containing the |
+ * depth values for every cross-section in a given channel. |
+ * |
+ * @param waterDepth The calculated depth at the current cross-section. |
+ * @param critDepth The calculated critical depth at the given cross-section. |
+ * @param normDepth The calculated normal depth at the given cross-section. |
+ * @param distance_DS The distance of the given cross-section from the origin. |
+ * @param bedElevation The elevation of the channel bed above or below the origin. |
+ * |
+ * @return A 2-dimensional array containing the calculated depth values for |
+ * the current cross-section. |
+ */ |
|
public double[][] writeDepthArray(double waterDepth, |
double critDepth, |
@@ -508,39 +599,81 @@ |
results[1][2] = normDepth; |
|
return results; |
- } |
+ }//end writeDepthArray |
+ |
+ /** |
+ * Determines the number of lines in a given text file (including blank lines). |
+ * |
+ * @param file_path The location of the 'crossSections' or 'reaches' text file. |
+ * |
+ * @return The number of lines in the text file. |
+ * |
+ * @throws IOException |
+ */ |
|
- public int readLines(String file_path) throws IOException { //determine number of lines in text file to find how many cross sections there are. |
+ public int readLines(String file_path) throws IOException { |
|
- FileReader fr = new FileReader(file_path); |
- BufferedReader bf = new BufferedReader(fr); |
- String aLine; |
int numberOfLines = 0; |
- while ((aLine = bf.readLine()) != null) { |
- numberOfLines++; |
+ |
+ try{ |
+ String aLine; |
+ FileReader fr = new FileReader(file_path); |
+ BufferedReader bf = new BufferedReader(fr); |
+ while ((aLine = bf.readLine()) != null) { |
+ numberOfLines++; |
+ } |
+ bf.close(); |
} |
- bf.close(); |
+ catch(IOException e){ |
+ System.out.println(e.getMessage()); |
+ } |
+ |
return numberOfLines; |
- } |
+ }//end readLines |
+ |
+ /** |
+ * Transfers a text file to a one 1-dimensional array. Each line of the text file |
+ * is written to its corresponding array location. |
+ * |
+ * @param file_path The location of the 'crossSections' or 'reaches' text file. |
+ * |
+ * @return A 1-dimensional array containing every line in a given text file. |
+ * |
+ * @throws IOException |
+ */ |
|
- public String[] transferTXTFile(String file_path) throws IOException { //read text file and add entries to single dimension array. |
+ public String[] transferTXTFile(String file_path) throws IOException { |
|
- FileReader fr = new FileReader(file_path); |
- BufferedReader textReader = new BufferedReader(fr); |
+ String[] crossSections = new String[0]; |
+ |
+ try{ |
+ FileReader fr = new FileReader(file_path); |
+ BufferedReader textReader = new BufferedReader(fr); |
+ int numberOfLines = readLines(file_path); |
+ crossSections = new String[numberOfLines]; |
+ int i; |
+ for (i = 0; i < numberOfLines; i++) { |
+ crossSections[i] = textReader.readLine(); |
+ } |
+ textReader.close(); |
+ } |
+ catch(IOException e){ |
+ System.out.println(e.getMessage()); |
+ } |
+ |
+ return crossSections; |
+ }//end transferTXTFile |
+ |
+ /** |
+ * Determines the largest number of xy-points in any one of the provided cross-sections. |
+ * This value is used to create the cross-sections array. |
+ * |
+ * @return The largest number of points in any of the given cross-sections. |
+ * |
+ * @throws IOException |
+ */ |
|
- int numberOfLines = readLines(file_path); |
- String[] crossSections = new String[numberOfLines]; |
- |
- int i; |
- for (i = 0; i < numberOfLines; i++) { |
- crossSections[i] = textReader.readLine(); |
- } |
- textReader.close(); |
- return crossSections; |
- |
- } |
- |
- public int calcLargestCrossSection() throws IOException { //determine the longest cross section to determine the length of the new array. |
+ public int calcLargestCrossSection() throws IOException { |
|
String[] sections = transferTXTFile(mainFolder + File.separator + "crossSections.txt"); |
int numberOfLines = readLines(mainFolder + File.separator + "crossSections.txt"); |
@@ -554,11 +687,20 @@ |
if (n > m) { |
m = n; |
} |
- |
} |
m = m - 1; |
return m; |
- } |
+ }//end calcLargestCrossSection |
+ |
+ /** |
+ * Splits the xy-point strings to creates a 3-dimensional array containing |
+ * all the x and y points for each cross-section in a given channel. |
+ * |
+ * @return A 3-dimensional array containing all x and y points for every given cross-section |
+ * along the channel length. |
+ * |
+ * @throws IOException |
+ */ |
|
public double[][][] setCrossSectionGeometries() throws IOException { |
|
@@ -582,7 +724,17 @@ |
dimensionalArray[i] = xyPoints_new; |
} |
return dimensionalArray; |
- } |
+ }//end setCrossSectionGeometries |
+ |
+ /** |
+ * Splits the reach property strings to creates a 2-dimensional array containing |
+ * all the reach properties for every reach along the channel length. |
+ * |
+ * @return A 2-dimensional array containing all the reach properties for every |
+ * reach along the channel length. |
+ * |
+ * @throws IOException |
+ */ |
|
public double[][] setReachProperties() throws IOException { |
|
@@ -598,19 +750,18 @@ |
} |
} |
return properties; |
- } |
- |
- /*public void testEGLChange(int currentReach) throws IOException { |
- setDSValues(currentReach); |
- double EGL1 = calcFrictionSlope(); |
- |
- this.setUSValues(currentReach); |
- double EGL2 = calcFrictionSlope(); |
- |
- System.out.println(EGL1 + ":" + EGL2); |
- } //end testEGLChange |
- */ |
- |
+ }//end setReachProperties |
+ |
+ /** |
+ * Calculates the velocity at the current cross-section using the calculated area |
+ * and discharge. |
+ * |
+ * @param values The ChannelGeometry object containing the correct values for current |
+ * cross-section. Created by the 'setUSValues' and 'setDSValues' methods. |
+ * |
+ * @return The water velocity at the current cross-section. |
+ */ |
+ |
public double calcVelocity(ChannelGeometry values) { //Need to move to ChannelGeomety Class? |
|
if (irregularGeometry) { |
@@ -623,9 +774,19 @@ |
return velocity; |
} |
|
- } //end of calcVelocity |
+ }//end calcVelocity |
+ |
+ /** |
+ * Calculates the friction slope at the current cross-section using the calculated area, |
+ * hydraulic radius, manning's n, and discharge. |
+ * |
+ * @param values The ChannelGeometry object containing the correct values for current |
+ * cross-section. Created by the 'setUSValues' and 'setDSValues' methods. |
+ * |
+ * @return The water friction slope at the current cross-section. |
+ */ |
|
- public double calcFrictionSlope(ChannelGeometry values) { //Need to move to ChannelGeometry Class? |
+ public double calcFrictionSlope(ChannelGeometry values) { |
|
if (irregularGeometry) { |
double area = values.calcIrregularArea(); |
@@ -640,7 +801,22 @@ |
/ (area * Math.pow(hydrRadius, 2. / 3.))), 2.); |
return frictionSlope; |
} |
- } //end of calcFrictionSlope |
+ }//end calcFrictionSlope |
+ |
+ /** |
+ * Calculates the Thalweg Elevation of the current cross-section using the |
+ * elevation data from the xy-point cross-section geometries. Then uses the |
+ * thalweg elevation from the up and downstream cross-sections to determine the |
+ * average slope between the two cross-sections. |
+ * |
+ * @param currentReach The reach being calculated by the current iteration of the |
+ * Standard Step Method. |
+ * |
+ * @return The reach slope based on the thalweg elevations of the up and downstream |
+ * cross-sections. |
+ * |
+ * @throws IOException |
+ */ |
|
public double calcThalwegElevationSlope(int currentReach)throws IOException { |
GeneralFunctions general = new GeneralFunctions(); |
@@ -657,8 +833,21 @@ |
|
double slope = (thalwegElevation1 - thalwegElevation2)/currentReachLength; |
return slope; |
- } |
- |
+ }//end calcThalwegElevation |
+ |
+ /** |
+ * Creates a new ChannelGeometry object and sets the ChannelGeometry variables |
+ * to the values of the cross-section downstream of the current reach. |
+ * |
+ * @param currentCrossSectionGeometry_DS An array containing the xy-points for the |
+ * downstream cross-section. |
+ * @param currentReachProperties An array containing the properties of the current reach. |
+ * @param depth The calculated depth of the downstream cross-section. |
+ * |
+ * @return A new ChannelGeometry object with the values set for the downstream cross-section. |
+ * |
+ * @throws IOException |
+ */ |
|
public ChannelGeometry setDSValues(double[][] currentCrossSectionGeometry_DS, |
double[] currentReachProperties, |
@@ -683,6 +872,20 @@ |
} |
return DSValues; |
}//end setDSValues |
+ |
+ /** |
+ * Creates a new ChannelGeometry object and sets the ChannelGeometry variables |
+ * to the values of the cross-section upstream of the current reach. |
+ * |
+ * @param currentCrossSectionGeometry_US An array containing the xy-points for the |
+ * upstream cross-section. |
+ * @param currentReachProperties An array containing the properties of the current reach. |
+ * @param depth The calculated depth of the upstream cross-section. |
+ * |
+ * @return A new ChannelGeometry object with the values set for the upstream cross-section. |
+ * |
+ * @throws IOException |
+ */ |
|
public ChannelGeometry setUSValues(double[][] currentCrossSectionGeometry_US, |
double[] currentReachProperties, |
@@ -707,7 +910,26 @@ |
USValues.setBedSlope(bedSlope); |
} |
return USValues; |
- }//end of setUSValues |
+ }//end setUSValues |
+ |
+ /** |
+ * Calculates the standard step equation using the predetermined values for the downstream |
+ * cross-section and guess values for the upstream cross-section based on the set boundaries. |
+ * |
+ * @param velocity_DS The calculated velocity at the downstream cross-section. |
+ * @param velocity_US The calculated velocity at the upstream cross-section. |
+ * @param frictionSlope_DS The calculated friction slope at the downstream cross-section. |
+ * @param frictionSlope_US The calculated friction slope at the upstream cross-section. |
+ * @param measuredDownstreamDepth The calculated depth at the downstream cross-section. |
+ * @param depth_US The calculated depth at the upstream cross-section. |
+ * @param bedSlope The bed slope between the up and downstream cross-sections. |
+ * @param length The distance between the up and downstream cross sections. |
+ * |
+ * @return An error value based on the guessed upstream depth value. The closer the error is to zero, |
+ * the closer the guess depth is to the actual depth. |
+ * |
+ * @throws IOException |
+ */ |
|
private double standardStepEquation(double velocity_DS, |
double velocity_US, |
@@ -725,7 +947,26 @@ |
+ length; |
|
return error; |
- } //end standardStepEquation |
+ }//end standardStepEquation |
+ |
+ /** |
+ * Creates a graph of the longitudinal depth and elevation profiles of the given |
+ * channel reach and saves them to the designated folder as jpeg's. |
+ * |
+ * @param resultsArray A 3-dimensional array containing the results of the |
+ * Standard Step Method calculations. |
+ * @param numberOfReaches The total number of reaches calculated. |
+ * @param graphTitle The title of the graph. |
+ * @param graphOutputName The file name under which the graph jpeg will be saved. |
+ * @param mainFolder The folder into which the graphs will be saved. |
+ * @param series1_name The name of the depth or elevation series. |
+ * @param series2_name The name of the critical depth series. |
+ * @param series3_name The name of the normal depth series. |
+ * @param series4_name The name of the bed elevation series. |
+ * @param yAxis_name The name of the y-axis. |
+ * |
+ * @throws IOException |
+ */ |
|
public void graphLongitudinalProfile(double[][][] resultsArray, |
int numberOfReaches, |
@@ -743,26 +984,21 @@ |
//Graph data |
XYSeries series1 = new XYSeries(series1_name); |
for (int i = 0; i < numberOfReaches + 1; i++) { |
- //Graph the rating curve |
series1.add(resultsArray[i][0][0], resultsArray[i][1][0]); |
} |
XYSeries series2 = new XYSeries(series2_name); |
for (int i = 0; i < numberOfReaches + 1; i++) { |
- //Graph the rating curve |
series2.add(resultsArray[i][0][0], resultsArray[i][1][1]); |
} |
XYSeries series3 = new XYSeries(series3_name); |
for (int i = 0; i < numberOfReaches + 1; i++) { |
- //Graph the rating curve |
series3.add(resultsArray[i][0][0], resultsArray[i][1][2]); |
} |
XYSeries series4 = new XYSeries(series4_name); |
for (int i = 0; i < numberOfReaches + 1; i++) { |
- //Graph the rating curve |
series4.add(resultsArray[i][0][0], resultsArray[i][1][3]); |
} |
|
- //Graph the effective discharge curve |
XYPlot plot = new XYPlot(); |
XYDataset dataset1 = new XYSeriesCollection(series1); |
XYItemRenderer currentRenderer = new XYLineAndShapeRenderer(true, false); |
@@ -813,14 +1049,25 @@ |
} catch (IOException e) { |
System.err.println("A problem occurred while trying to create the chart."); |
} |
- }// end graphRatingCurve |
+ }//end graphRatingCurve |
+ |
+ /** |
+ * Writes a given line to a text file. |
+ * |
+ * @param textLine The line to be written. |
+ * @param append_to_file If false, erases the current content of the text file before writing new line. |
+ * If true, adds the new line to the end of the existing content of the text file. |
+ * @param summaryOutputName The file name under which the text file will be saved. |
+ * |
+ * @throws IOException |
+ */ |
|
public void writeToFile(String textLine, boolean append_to_file, String summaryOutputName) throws IOException { |
FileWriter write = new FileWriter(mainFolder + File.separator + summaryOutputName,append_to_file); |
- PrintWriter print_line = new PrintWriter(write); |
+ PrintWriter print_line; |
+ print_line = new PrintWriter(write); |
print_line.printf("%s" + "%n", textLine); |
print_line.close(); |
- } |
+ }//end writeToFile |
|
-} //end of StandardStepMethd |
- |
+}//end StandardStepMeth |
\ No newline at end of file |