Displaying differences for changeset
 
display as  

src/java/hydraulics/StandardStepMethod.java

@@ -21,27 +21,26 @@
 
 public class StandardStepMethod {
     
-    boolean irregularGeometry =false;
-
+    boolean irregularGeometry =true;
+    boolean downstreamCrossSections = true;
+    boolean useThalwegElevation = false;
+    
+    String subFolder = "Test";
+    String mainFolder = "C:/Users/Chris/Documents/Java Projects/StandardStepMethod" + File.separator + subFolder ;
+    double measuredDownstreamDepth = 7;
+    
     //Downstream x-section characteristics
     double bottomWidth = 10;
     double sideSlope = 2;
-    double measuredDownstreamDepth = 7;
     double discharge_DS = 200;
 
     //Reach Characteristics
     double manning_n = .035;
     double bedSlope = 0.0004;
     double seepage = 0;
-    boolean downstream = true; //Designates whether the water surface profile
-    //is being calculated up or downstream from the original sample location
-    //(designated x-section 0). True if downstream/False if upstream.
+    
     double channelLength = 20000; //Distance between sample x-sections
-    double reachLength = 100; //Length between calculated x-section
-    
-    String subFolder = "Test2";
-    //String subFolder = "ChinExample4_11";
-    String mainFolder = "C:/Users/Chris/My Documents/StandardStepMethod" + File.separator + subFolder ;
+    int numberOfReaches = 100; //Length between calculated x-section
     
     //Sets
     public void setBottomWidth(double bottomWidth){
@@ -76,8 +75,8 @@
         this.channelLength = channelLength;
     }
     
-    public void setReachLength(double reachLength){
-        this.reachLength = reachLength;
+    public void setReachLength(int numberOfReaches){
+        this.numberOfReaches = numberOfReaches;
     }
     
     public void setMainFolder(String mainFolder){
@@ -88,8 +87,8 @@
         this.subFolder = subFolder;
     }
     
-    public void setStreamDirection(boolean downstream){
-        this.downstream = downstream;
+    public void setStreamDirection(boolean downstreamCrossSections){
+        this.downstreamCrossSections = downstreamCrossSections;
     }
     
     //gets
@@ -102,7 +101,7 @@
     }
     
     public String getElevationGraphOutputName(){
-        if (downstream){
+        if (downstreamCrossSections){
             return subFolder + " Downstream Longitudinal Elevation Profile.png";
         }
         else{
@@ -111,7 +110,7 @@
     }
     
     public String getDepthGraphOutputName(){
-        if (downstream){
+        if (downstreamCrossSections){
             return subFolder + " Downstream Longitudinal Depth Profile.png";
         }
         else{
@@ -120,15 +119,15 @@
     }
     
     public String getSummaryTitle(){
-        if (downstream){
-            return subFolder + " Downstream Summary Data.txt";
+        if (downstreamCrossSections){
+            return subFolder + " Downstream Summary Data";
         }
         else{
-            return subFolder + " Upstream Summary Data.txt";
+            return subFolder + " Upstream Summary Data";
         }
     }
     public String getSummaryOuputName(){
-        if (downstream){
+        if (downstreamCrossSections){
             return subFolder + " Downstream Summary Data.txt";
         }
         else{
@@ -148,57 +147,67 @@
     } //end of run
 
     public void calcStandardStepMethod() throws IOException {
-        
-        int numberOfReaches;
 
         if (irregularGeometry) {
             numberOfReaches = readLines(mainFolder + File.separator + "reaches.txt");
-        } else {
-            double numReach = channelLength / reachLength;
-            if (numReach == Math.floor(numReach) && !Double.isInfinite(numReach)) {
-                numberOfReaches = (int) numReach;
-            } else {
-                System.out.println("Variable reachLength must be factor of channelLength");
-                numberOfReaches = 1;
-            }
         }
 
         double[][][] elevationArray = new double[numberOfReaches + 1][2][4];
         double[][][] depthArray = new double[numberOfReaches + 1][2][4];
         
+        double [][][] crossSectionGeometries;
+        double [][] reachProperties;
+        if (irregularGeometry) {
+            crossSectionGeometries = setCrossSectionGeometries();
+            reachProperties = setReachProperties();
+        }
+        else{
+            crossSectionGeometries = new double[1][1][1];
+            reachProperties = new double[1][1];
+        }
+        
         double downstreamDistance = 0;
         double bedElevation = 0;
         double depth_DS = measuredDownstreamDepth;
+        
         for (int currentReach = 0; currentReach < numberOfReaches; currentReach++) {
             
+            double[][] currentCrossSectionGeometry_DS = crossSectionGeometries[currentReach];
+            double[][] currentCrossSectionGeometry_US = crossSectionGeometries[currentReach+1];
+            double[] currentReachProperties = reachProperties[currentReach];
+            
             double length;
+            double reachSlope;
+            
             if (irregularGeometry) {
-                double[][] reachProperties = setReachProperties();
-                length = reachProperties[currentReach][0];
+                length = currentReachProperties[0];
+                if(useThalwegElevation){
+                    reachSlope = calcThalwegElevationSlope(currentReach);
+                }
+                else{
+                    reachSlope = currentReachProperties[3];
+                }
             } else {
-                length = reachLength;
-            }
-            
-
-            double reachSlope;
-            if (irregularGeometry) {
-                double[][] reachProperties = setReachProperties();
-                reachSlope = reachProperties[currentReach][1];
-            } else {
+                length = channelLength/numberOfReaches;
                 reachSlope = bedSlope;
             }
             
-            if (downstream == false){
+            
+            if (downstreamCrossSections == false){
                 length = -length;
             }
             
-            ChannelGeometry DSValues = setDSValues(currentReach,depth_DS);
+            ChannelGeometry DSValues = setDSValues(currentCrossSectionGeometry_DS,
+                                                    currentReachProperties,
+                                                    depth_DS);
             double velocity_DS = calcVelocity(DSValues);
             double frictionSlope_DS = calcFrictionSlope(DSValues);
             double critDepth_DS = DSValues.calcCriticalDepth();
             double normDepth_DS = DSValues.calcNormalDepth();
             
-            ChannelGeometry USValues = setUSValues(currentReach,depth_DS);
+            ChannelGeometry USValues = setUSValues(currentCrossSectionGeometry_US,
+                                                    currentReachProperties,
+                                                    depth_DS);
             double critDepth_US = USValues.calcCriticalDepth();
             double normDepth_US = USValues.calcNormalDepth();
             
@@ -206,7 +215,9 @@
             double lower = bounds[0];
             double upper = bounds[1];
             
-            USValues = setUSValues(currentReach,lower);
+            USValues = setUSValues(currentCrossSectionGeometry_US,
+                                    currentReachProperties,
+                                    lower);
             double velocity_US = calcVelocity(USValues);
             double frictionSlope_US = calcFrictionSlope(USValues);
             double err_lower = standardStepEquation(velocity_DS, 
@@ -218,7 +229,9 @@
                                                         reachSlope,
                                                         length);
             
-            USValues = setUSValues(currentReach,upper);
+            USValues = setUSValues(currentCrossSectionGeometry_US,
+                                    currentReachProperties,
+                                    upper);
             velocity_US = calcVelocity(USValues);
             frictionSlope_US = calcFrictionSlope(USValues);
             double err_upper = standardStepEquation(velocity_DS, 
@@ -237,7 +250,9 @@
                 while (Math.abs(error) > .0001 && ctr < 100) {
                     
                     guessDepth_US = (lower + upper) / 2;
-                    USValues = setUSValues(currentReach,guessDepth_US);
+                    USValues = setUSValues(currentCrossSectionGeometry_US,
+                                    currentReachProperties,
+                                    guessDepth_US);;
                     velocity_US = calcVelocity(USValues);
                     frictionSlope_US = calcFrictionSlope(USValues);
                     
@@ -253,11 +268,14 @@
                     }
                     ctr = ctr + 1;
                 }
-            } else if (err_lower < 0 && err_upper > 0) {
+            }
+            else if (err_lower < 0 && err_upper > 0) {
                 while (Math.abs(error) > .0001 && ctr < 100) {
                     
                     guessDepth_US = (lower + upper) / 2;
-                    USValues = setUSValues(currentReach,guessDepth_US);
+                    USValues = setUSValues(currentCrossSectionGeometry_US,
+                                    currentReachProperties,
+                                    guessDepth_US);
                     velocity_US = calcVelocity(USValues);
                     frictionSlope_US = calcFrictionSlope(USValues);
                     
@@ -273,7 +291,8 @@
                     }
                     ctr = ctr + 1;
                 }
-            } else {
+            } 
+            else {
                 guessDepth_US = (lower + upper) / 2;
                 System.out.println("****Could not solve standard step equation****");
             }
@@ -299,14 +318,17 @@
                 writeToFile(summaryTitle,append_to_file,summaryOutputName);
                 append_to_file = true;
                 writeToFile("",append_to_file,summaryOutputName);
-                writeToFile("Cross Section " + currentReach + ": " + downstreamDistance + " m downstream",append_to_file,summaryOutputName);
+                writeToFile("Cross Section " + currentReach + " (Origin): " + downstreamDistance + " m downstream",append_to_file,summaryOutputName);
                 writeToFile("   Depth: " + depth_DS,append_to_file,summaryOutputName);
                 writeToFile("   Critical Depth: " + critDepth_DS,append_to_file,summaryOutputName);
                 writeToFile("   Normal Depth: " + normDepth_DS,append_to_file,summaryOutputName);
                 writeToFile("   Bed Elevation: " + bedElevation,append_to_file,summaryOutputName);
                 writeToFile("   Water Surface Elevation: " + (depth_DS + bedElevation),append_to_file,summaryOutputName);
                 writeToFile("",append_to_file,summaryOutputName);
-                
+                writeToFile("Reach " + (currentReach + 1), append_to_file, summaryOutputName);
+                writeToFile("   Length: " + length, append_to_file, summaryOutputName);
+                writeToFile("   Slope: " + reachSlope, append_to_file, summaryOutputName);
+                writeToFile("",append_to_file,summaryOutputName);
                 
                 downstreamDistance = downstreamDistance + length;
                 bedElevation = bedElevation - (reachSlope * length);
@@ -331,7 +353,8 @@
                 writeToFile("   Water Surface Elevation: " + (guessDepth_US + bedElevation),append_to_file,summaryOutputName);
                 writeToFile("",append_to_file,summaryOutputName);
                 
-            } else {
+            } 
+            else {
                 downstreamDistance = downstreamDistance + length;
                 
                 
@@ -350,6 +373,10 @@
                                                                         bedElevation);
                 append_to_file = true;
                 String summaryOutputName = getSummaryOuputName();
+                writeToFile("Reach " + (currentReach + 1), append_to_file, summaryOutputName);
+                writeToFile("   Length: " + length, append_to_file, summaryOutputName);
+                writeToFile("   Slope: " + reachSlope, append_to_file, summaryOutputName);
+                writeToFile("",append_to_file,summaryOutputName);
                 writeToFile("Cross Section " + (currentReach + 1) + ": " + downstreamDistance + " m downstream",append_to_file,summaryOutputName);
                 writeToFile("   Depth: " + guessDepth_US,append_to_file,summaryOutputName);
                 writeToFile("   Critical Depth: " + critDepth_US,append_to_file,summaryOutputName);
@@ -533,7 +560,7 @@
         return m;
     }
 
-    public double[][][] setCrossSectionArray() throws IOException {
+    public double[][][] setCrossSectionGeometries() throws IOException {
         
         int numberOfSections = readLines(mainFolder + File.separator + "crossSections.txt");
         String[] sections = transferTXTFile(mainFolder + File.separator + "crossSections.txt");
@@ -614,21 +641,38 @@
             return frictionSlope;
         }
     } //end of calcFrictionSlope
+    
+    public double calcThalwegElevationSlope(int currentReach)throws IOException {
+        GeneralFunctions general = new GeneralFunctions();
+        double[][][] geometries = setCrossSectionGeometries();
+        double[][] properties = setReachProperties();
+        
+        double[][] crossSection1 = geometries[currentReach];
+        double thalwegElevation1 = general.min(general.getColumn(crossSection1, 1));
+        
+        double[][] crossSection2 = geometries[currentReach + 1];
+        double thalwegElevation2 = general.min(general.getColumn(crossSection2, 1));
+        
+        double currentReachLength = properties[currentReach][0];
+        
+        double slope = (thalwegElevation1 - thalwegElevation2)/currentReachLength;
+        return slope;
+    }
+        
 
-    public ChannelGeometry setDSValues(int currentReach,
+    public ChannelGeometry setDSValues(double[][] currentCrossSectionGeometry_DS,
+                                            double[] currentReachProperties,
                                             double depth) throws IOException {
         
         ChannelGeometry DSValues = new ChannelGeometry();
         DSValues.setGeometryType(irregularGeometry);
 
         if (irregularGeometry) {
-            double[][][] geometries = setCrossSectionArray();
-            double[][] properties = setReachProperties();
-            DSValues.setXYPoints(geometries[currentReach]);
+            DSValues.setXYPoints(currentCrossSectionGeometry_DS);
             DSValues.setDepth(depth);
             DSValues.setDischarge(discharge_DS);
-            DSValues.setManningRoughness(properties[currentReach][2]);
-            DSValues.setBedSlope(properties[currentReach][1]);
+            DSValues.setManningRoughness(currentReachProperties[1]);
+            DSValues.setBedSlope(currentReachProperties[3]);
         } else {
             DSValues.setBottomWidth(bottomWidth);
             DSValues.setSideSlope(sideSlope);
@@ -640,25 +684,25 @@
         return DSValues;
     }//end setDSValues
 
-    public ChannelGeometry setUSValues(int currentReach,
+    public ChannelGeometry setUSValues(double[][] currentCrossSectionGeometry_US,
+                                            double[] currentReachProperties,
                                             double depth) throws IOException {
         
         ChannelGeometry USValues = new ChannelGeometry();
         USValues.setGeometryType(irregularGeometry);
 
         if (irregularGeometry) {
-            double[][][] geometries = setCrossSectionArray();
-            double[][] properties = setReachProperties();
-            USValues.setXYPoints(geometries[currentReach + 1]);
+            USValues.setXYPoints(currentCrossSectionGeometry_US);
             USValues.setDepth(depth);
-            USValues.setDischarge(discharge_DS);
-            USValues.setManningRoughness(properties[currentReach][2]);
-            USValues.setBedSlope(properties[currentReach][1]);
+            double currentReachSeepage = currentReachProperties[2];
+            USValues.setDischarge(discharge_DS + currentReachSeepage);
+            USValues.setManningRoughness(currentReachProperties[1]);
+            USValues.setBedSlope(currentReachProperties[3]);
         } else {
             USValues.setBottomWidth(bottomWidth);
             USValues.setSideSlope(sideSlope);
             USValues.setDepth(depth);
-            USValues.setDischarge(discharge_DS);
+            USValues.setDischarge(discharge_DS + seepage);
             USValues.setManningRoughness(manning_n);
             USValues.setBedSlope(bedSlope);
         }
@@ -677,7 +721,7 @@
         
         double error = (((depth_US + (Math.pow(velocity_US, 2.) / (2 * 9.81)))
                 - (measuredDownstreamDepth + (Math.pow(velocity_DS, 2.) / (2. * 9.81))))
-                / (((frictionSlope_US + frictionSlope_DS) / 2) - (Math.abs(bedSlope))))
+                / (((frictionSlope_US + frictionSlope_DS) / 2) - (bedSlope)))
                 + length;
 
         return error;