Skip to content

Commit

Permalink
fixed a bug in critical_depth and updated to address CRAN comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoohafkan committed Feb 18, 2015
1 parent 4adaf85 commit 96ec899
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
7 changes: 5 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Package: rivr
Type: Package
Title: Steady and unsteady open channel flow computation
Title: Steady and Unsteady Open-Channel Flow Computation
Version: 0.9.1
Date: 2015-01-10
Author: Michael C Koohafkan [aut, cre]
Maintainer: Michael C Koohafkan <michael.koohafkan@gmail.com>
Description: A tool for undergraduate courses in open channel hydraulics. Provides functions for computing normal and critical depths, steady-state water surface profiles (e.g. backwater curves) and unsteady flow computations (e.g. flood wave routing).
Description: A tool for undergraduate courses in open-channel hydraulics.
Provides functions for computing normal and critical depths, steady-state
water surface profiles (e.g. backwater curves) and unsteady flow
computations (e.g. flood wave routing).
URL: https://github.com/mkoohafkan/rivr
BugReports: https://github.com/mkoohafkan/rivr/issues
License: GPL (>= 3) + file LICENSE
Expand Down
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ normal_depth <- function(So, n, Q, yopt, Cm, B, SS) {
#' @param SS Channel sideslope [\eqn{L L^{-1}}].
#' @return The critical depth \eqn{y_c} [\eqn{L}].
#' @examples
#' critical_depth(250, 32.2, 2, 100, 0) # rectangular channel
#' critical_depth(126, 9.81, 1, 6.1, 1.5) # trapezoidal channel with sideslope 3H:2V
#' critical_depth(250, 2, 32.2, 100, 0) # rectangular channel
#' critical_depth(126, 1, 9.81, 6.1, 1.5) # trapezoidal channel with sideslope 3H:2V
#' @export
critical_depth <- function(Q, yopt, g, B, SS) {
.Call('rivr_critical_depth', PACKAGE = 'rivr', Q, yopt, g, B, SS)
Expand Down
8 changes: 4 additions & 4 deletions R/graduallyvariedflow_v2.r
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ NULL
#' \item{Sf}{Friction slope.}
#' \item{E}{Total energy.}
#' \item{Fr}{Froude Number.}
#' @details Computes the longitudinal water surface profile of a
#' prismatic channel using the standard step method by solving the non-linear
#' ODE \eqn{\frac{dy}{dx} = \frac{S_0 - S_f}{1 - Fr^2}}. The standard-step
#' @details Computes the longitudinal water surface profile of a prismatic
#' channel using the standard step method by solving the non-linear ODE
#' \eqn{\frac{dy}{dx} = \frac{S_0 - S_f}{1 - Fr^2}}. The standard-step
#' method operates by stepping along the channel by a constant distance
#' interval, starting from a cross-section where the flow depth is known
#' (the control section). The flow depth is computed at the adjacent
#' cross-section (target section). The computed value at the target is then
#' used as the basis for computing flow depth at the next cross-section, i.e.
#' the previous target section becomes the new control section for each step.
#' A Newton-Raphson scheme is used each step to compute the flow depth and
#' friction slope. Technically, the average friction slope of the control and
#' friction slope. Technically, the average friction slope of the control and
#' target section is used to compute the flow depth at the target section.
#' @examples
#' \donttest{
Expand Down
6 changes: 3 additions & 3 deletions man/compute_profile.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ data.frame with columns:
Compute the gradually-varied flow profile of a prismatic channel.
}
\details{
Computes the longitudinal water surface profile of a
prismatic channel using the standard step method by solving the non-linear
ODE \eqn{\frac{dy}{dx} = \frac{S_0 - S_f}{1 - Fr^2}}. The standard-step
Computes the longitudinal water surface profile of a prismatic
channel using the standard step method by solving the non-linear ODE
\eqn{\frac{dy}{dx} = \frac{S_0 - S_f}{1 - Fr^2}}. The standard-step
method operates by stepping along the channel by a constant distance
interval, starting from a cross-section where the flow depth is known
(the control section). The flow depth is computed at the adjacent
Expand Down
4 changes: 2 additions & 2 deletions man/critical_depth.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The critical depth is the water depth at which a channel
\eqn{y = y_c} when \deqn{\frac{dE}{dy} = 1 - \frac{Q^2}{gA^3}\frac{dA}{dy} = 0}.
}
\examples{
critical_depth(250, 32.2, 2, 100, 0) # rectangular channel
critical_depth(126, 9.81, 1, 6.1, 1.5) # trapezoidal channel with sideslope 3H:2V
critical_depth(250, 2, 32.2, 100, 0) # rectangular channel
critical_depth(126, 1, 9.81, 6.1, 1.5) # trapezoidal channel with sideslope 3H:2V
}

13 changes: 7 additions & 6 deletions src/rivmech_characteristic_v7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ double normal_depth(double So, double n, double Q, double yopt, double Cm,
dy = ( pow(gp["A"], 5.0/3.0)/pow(gp["P"], 2.0/3.0) - n*Q/(Cm*sqrt(So)) ) /
( gp["dAdy"]*(5.0/3.0)*pow(gp["A"]/gp["P"], 2.0/3.0) -
(2.0/3.0)*gp["dPdy"]*pow(gp["A"]/gp["P"], 5.0/3.0) );
yopt = yopt - dy;
yopt -= dy;
i++;
}
return(yopt);
Expand All @@ -150,8 +150,8 @@ double normal_depth(double So, double n, double Q, double yopt, double Cm,
//' @param SS Channel sideslope [\eqn{L L^{-1}}].
//' @return The critical depth \eqn{y_c} [\eqn{L}].
//' @examples
//' critical_depth(250, 32.2, 2, 100, 0) # rectangular channel
//' critical_depth(126, 9.81, 1, 6.1, 1.5) # trapezoidal channel with sideslope 3H:2V
//' critical_depth(250, 2, 32.2, 100, 0) # rectangular channel
//' critical_depth(126, 1, 9.81, 6.1, 1.5) # trapezoidal channel with sideslope 3H:2V
//' @export
// [[Rcpp::export]]
double critical_depth(double Q, double yopt, double g, double B, double SS){
Expand All @@ -162,9 +162,10 @@ double critical_depth(double Q, double yopt, double g, double B, double SS){
int i = 0;
while((fabs(dy) > tol) & (i < maxit)){
NumericVector gp = channel_geom(yopt, B, SS);
dy = (pow(gp["A"], 3.0)/gp["dAdy"] - Q*Q/g) /
(3*pow(gp["A"], 2.0) - pow(gp["A"], 3.0)*gp["dTdy"]/gp["dAdy"]);
yopt = yopt - dy;
dy = (pow(gp["A"], 3.0)/gp["dAdy"] - pow(Q, 2.0)/g) /
(3.0*pow(gp["A"], 2.0) - pow(gp["A"], 3.0)*gp["dTdy"] /
pow(gp["dAdy"], 2.0));
yopt -= dy;
i++;
}
return(yopt);
Expand Down
Binary file modified src/rivr.dll
Binary file not shown.

0 comments on commit 96ec899

Please sign in to comment.