Exemplo n.º 1
0
/******************************************************************************
 * @brief    Iterate to find actual shear stress during saltation.
 *****************************************************************************/
void
shear_stress(double  U10,
             double  ZO,
             double *ushear,
             double *Zo_salt,
             double  utshear)
{
    double umin, umax, xacc;
    double fl, fh, df;

    /* Find min & max shear stress to bracket value. */
    umin = utshear;
    umax = CONST_KARMAN * U10;
    xacc = 0.10 * umin;

    /* Check to see if value is bracketed. */
    get_shear(umin, &fl, &df, U10, 10.);
    get_shear(umax, &fh, &df, U10, 10.);

    if (fl < 0.0 && fh < 0.0) {
        log_err("Solution surpasses upper boundary."
                "fl(%f)=%f, fh(%f)=%f", umin, fl, umax, fh);
    }

    if (fl > 0.0 && fh > 0.0) {
        *Zo_salt = ZO;
        *ushear = CONST_KARMAN * U10 / log(10. / ZO);
    }
    else {
        /* Iterate to find actual shear stress. */
        *ushear = rtnewt(umin, umax, xacc, U10, 10.);
        *Zo_salt = 0.12 * (*ushear) * (*ushear) / (2. * CONST_G);
    }
}
Exemplo n.º 2
0
void shear_stress(double U10, double ZO,double *ushear, double *Zo_salt, double utshear)
{
  double umin, umax, xacc;
  double fl, fh, df;

  /* Find min & max shear stress to bracket value. */
  umin = utshear;
  umax = von_K*U10;
  xacc = 0.10*umin;

  /* Check to see if value is bracketed. */
   get_shear(umin,&fl,&df, U10, 10.);
   get_shear(umax,&fh,&df, U10, 10.);

    if(fl < 0.0 && fh < 0.0) { 
      fprintf(stderr, "Solution in rtnewt surpasses upper boundary.\n");
      fprintf(stderr, "fl(%f)=%f, fh(%f)=%f\n",umin, fl, umax, fh);
      exit(0);
    }
    
    if(fl > 0.0 && fh > 0.0) {
      //      fprintf(stderr, "No solution possible that exceeds utshear.\n");
      //   fprintf(stderr, "utshear=%f, u10=%f\n",utshear, U10);
     
      *Zo_salt = ZO;
      *ushear = von_K * U10 / log(10./ZO);  
    }
    else {
      /* Iterate to find actual shear stress. */
      *ushear = rtnewt (umin, umax, xacc, U10, 10.);
      *Zo_salt = 0.12 *(*ushear) * (*ushear) / (2.* G_STD);
    }
    
}
Exemplo n.º 3
0
double rtnewt(double x1, double x2, double acc, double Ur, double Zr)
{
  int j;
  double df, dx, dxold, f, fh, fl;
  double temp, xh, xl, rts;

    get_shear(x1,&fl,&df, Ur, Zr);
    get_shear(x2,&fh,&df, Ur, Zr);

    if ((fl > 0.0 && fh > 0.0) || (fl < 0.0 && fh < 0.0)) {
      fprintf(stderr, "Root must be bracketed in rtnewt.\n");
      exit(0);
    }

    if (fl == 0.0) return x1;
    if (fh == 0.0) return x2;
    if (fl < 0.0) {
      xl=x1;
      xh=x2; }
    else {
      xh=x1;
      xl=x2;
    }
    rts=0.5*(x1+x2);
    dxold=fabs(x2-x1);
    dx=dxold;
    get_shear(rts,&f,&df, Ur, Zr);
    for(j=1; j<=MAX_ITER; j++) {
      if((((rts-xh)*df-f)*((rts-x1)*df-f) > 0.0)
	 || (fabs(2.0*f) > fabs(dxold*df))) {
	dxold=dx;
	dx=0.5*(xh-xl);
	rts=xl+dx;
	if (xl == rts) return rts; }
      else {
	dxold=dx;
	dx=f/df;
	temp=rts;
	rts -= dx;
	if (temp == rts) return rts;
      }
      if(fabs(dx) < acc) return rts;
      // if(rts < .025) rts=.025;
      get_shear(rts,&f,&df, Ur, Zr);
       if(f<0.0)
	 xl=rts;
       else 
	 xh = rts;
    }
    fprintf(stderr, "Maximum number of iterations exceeded in rtnewt.\n");
    return 0.0;
}
Exemplo n.º 4
0
/******************************************************************************
 * @brief    Newton-Raphson method.
 *****************************************************************************/
double
rtnewt(double x1,
       double x2,
       double acc,
       double Ur,
       double Zr)
{
    extern parameters_struct param;

    int                      j;
    double                   df, dx, dxold, f, fh, fl;
    double                   temp, xh, xl, rts;

    get_shear(x1, &fl, &df, Ur, Zr);
    get_shear(x2, &fh, &df, Ur, Zr);

    if ((fl > 0.0 && fh > 0.0) || (fl < 0.0 && fh < 0.0)) {
        log_err("Root must be bracketed");
    }

    if (fl == 0.0) {
        return x1;
    }
    if (fh == 0.0) {
        return x2;
    }
    if (fl < 0.0) {
        xl = x1;
        xh = x2;
    }
    else {
        xh = x1;
        xl = x2;
    }
    rts = 0.5 * (x1 + x2);
    dxold = fabs(x2 - x1);
    dx = dxold;
    get_shear(rts, &f, &df, Ur, Zr);
    for (j = 1; j <= param.BLOWING_MAX_ITER; j++) {
        if ((((rts - xh) * df - f) * ((rts - x1) * df - f) > 0.0) ||
            (fabs(2.0 * f) > fabs(dxold * df))) {
            dxold = dx;
            dx = 0.5 * (xh - xl);
            rts = xl + dx;
            if (xl == rts) {
                return rts;
            }
        }
        else {
            dxold = dx;
            dx = f / df;
            temp = rts;
            rts -= dx;
            if (temp == rts) {
                return rts;
            }
        }
        if (fabs(dx) < acc) {
            return rts;
        }
        // if(rts < .025) rts=.025;
        get_shear(rts, &f, &df, Ur, Zr);
        if (f < 0.0) {
            xl = rts;
        }
        else {
            xh = rts;
        }
    }
    log_err("Maximum number of iterations exceeded");
}