// Calculate the roots of the approximation int AlgRemez::root() { long i,j; bigfloat x,dx=0.05; bigfloat upper=1, lower=-100000; bigfloat tol = 1e-20; bigfloat *poly = new bigfloat[neq+1]; // First find the numerator roots for (i=0; i<=n; i++) poly[i] = param[i]; //for (i=0; i<=n; i++) printf("%d %e\n", i, (double)poly[i]); for (i=n-1; i>=0; i--) { roots[i] = rtnewt(poly,i+1,lower,upper,tol); //printf("root[%d] = %e\n", i, (double)roots[i]); if (roots[i] == 0.0) { printf("Failure to converge on root %d/%d\n", i+1, n); return 0; } poly[0] = -poly[0]/roots[i]; for (j=1; j<=i; j++) poly[j] = (poly[j-1] - poly[j])/roots[i]; } // Now find the denominator roots poly[d] = 1l; for (i=0; i<d; i++) poly[i] = param[n+1+i]; //for (i=0; i<=d; i++) printf("%d %e\n", i, (double)poly[i]); for (i=d-1; i>=0; i--) { poles[i]=rtnewt(poly,i+1,lower,upper,tol); //printf("pole[%d] = %e\n", i, (double)poles[i]); if (poles[i] == 0.0) { printf("Failure to converge on pole %d/%d\n", i+1, d); return 0; } poly[0] = -poly[0]/poles[i]; for (j=1; j<=i; j++) poly[j] = (poly[j-1] - poly[j])/poles[i]; } norm = param[n]; //printf("Normalisation constant is %e\n",(double)norm); //for (i=0; i<n; i++) printf("%ld root = %e\n",i,(double)roots[i]); //for (i=0; i<d; i++) printf("%ld pole = %e\n",i,(double)poles[i]); delete [] poly; return 1; }
// Calculate the roots of the approximation int AlgRemez::root() { char *fname = "root()"; // VRB.Func(cname,fname); long i,j; bigfloat x,dx=0.05; bigfloat upper=1, lower=-100000; bigfloat tol = 1e-20; bigfloat *poly = new bigfloat[neq+1]; if(poly == 0) ERR.Pointer(cname,fname,"poly"); VRB.Smalloc(cname,fname,"poly",poly,(n+d+2) * sizeof(bigfloat)); // First find the numerator roots for (i=0; i<=n; i++) poly[i] = param[i]; for (i=n-1; i>=0; i--) { roots[i] = rtnewt(poly,i+1,lower,upper,tol); if (roots[i] == 0.0) { VRB.Warn(cname,fname,"Failure to converge on root\n"); return 0; } poly[0] = -poly[0]/roots[i]; for (j=1; j<=i; j++) poly[j] = (poly[j-1] - poly[j])/roots[i]; } // Now find the denominator roots poly[d] = 1l; for (i=0; i<d; i++) poly[i] = param[n+1+i]; for (i=d-1; i>=0; i--) { poles[i]=rtnewt(poly,i+1,lower,upper,tol); if (poles[i] == 0.0) { VRB.Warn(cname,fname,"Failure to converge on root"); return 0; } poly[0] = -poly[0]/poles[i]; for (j=1; j<=i; j++) poly[j] = (poly[j-1] - poly[j])/poles[i]; } norm = param[n]; VRB.Result(cname,fname,"Normalisation constant is %0.14e\n",(double)norm); for (i=0; i<n; i++) VRB.Result(cname,fname,"%ld root = %0.14e\n",i,(Float)roots[i]); for (i=0; i<d; i++) VRB.Result(cname,fname,"%ld pole = %0.14e\n",i,(Float)poles[i]); VRB.Sfree(cname,fname, "poly",poly); delete [] poly; return 1; }
/****************************************************************************** * @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); } }
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); } }