void eterm_show(int m, cmulti **x, func_t *fF, int bmax, int kappa) { int kmax,k,db=64; int *b=NULL,tau; func_t *fJ=NULL; cmulti **y=NULL; rmulti **e=NULL,**eps=NULL,**em=NULL,**r=NULL,*rmax=NULL,**p=NULL; kmax=(bmax-64)/db; if(kmax<0){ kmax=2; } tau=cvec_get_exp_max(m,x); printf("tau=%d\n",tau); fJ=func_grad(func_retain(fF),func_var1_list(m)); CVA(y,m); RVA(e,kmax); RVA(eps,kmax); RVA(em,kmax); RVA(r,kmax); RVA(p,kmax); RA(rmax); b=ivec_allocate(kmax); b[0]=53; for(k=1; k<kmax; k++){ b[k]=(k-1)*db+64; } for(k=0; k<kmax; k++){ printf("b=%4d ",b[k]); set_default_prec(b[k]); rset_d(eps[k],1); rmul_2exp(eps[k],eps[k],-b[k]+tau); mpfr_printf("2^(-b+tau)=%8.1Re ",eps[k]); cvec_round(m,y,b[k]); csolve_newton_map(m,y,x,fF,fJ); csolve_newton_e_norm(e[k],m,y,x,fF,fJ,bmax*4); if(rgt(eps[k],e[k])){ printf("> "); }else{ printf("< "); } mpfr_printf("e=%8.1Re ",e[k]); rset_d(em[k],1); rmul_2exp(em[k],em[k],-b[k]+tau+kappa); if(rgt(e[k],em[k])){ printf("> "); }else{ printf("< "); } mpfr_printf("em=%8.1Re ",em[k]); rlog2(p[k],e[k]); rsub_d1(p[k],tau,p[k]); rsub_d1(p[k],b[k],p[k]); mpfr_printf("b-tau+log2(e)=%+6.2Rf ",p[k]); rlog2(r[k],e[k]); rsub_d1(r[k],tau,r[k]); rdiv_d2(r[k],r[k],b[k]); rsub_d1(r[k],1,r[k]); mpfr_printf("κ=1-(tau-log2(e))/b=%+.10Rf ",r[k]); printf("\n"); } rvec_max(rmax,kmax,p); mpfr_printf("cancel bits=%+.2Rf\n",rmax); rvec_max(rmax,kmax,r); mpfr_printf("κ_max=%+.10Rf\n",rmax); // done fJ=func_del(fJ); b=ivec_free(b); CVF(y,m); RVF(e,kmax); RVF(eps,kmax); RVF(em,kmax); RVF(r,kmax); RVF(p,kmax); RF(rmax); }
gsprof *plumgsp(real mtot, real a, int np, real rmin, real rmax) { gsprof *gsp; real *rtab, *dtab, *mtab, lgrs; int i; assert(mtot > 0.0 && a > 0.0); gsp = (gsprof *) allocate(sizeof(gsprof)); rtab = (real *) allocate(np * sizeof(real)); dtab = (real *) allocate(np * sizeof(real)); mtab = (real *) allocate(np * sizeof(real)); lgrs = rlog2(rmax / rmin) / (np - 1); for (i = 0; i < np; i++) { rtab[i] = rmin * rexp2(lgrs * i); dtab[i] = (3 / FOUR_PI) * mtot * a*a / rpow(rsqr(rtab[i]) + a*a, 2.5); mtab[i] = mtot * rqbe(rtab[i]) / rpow(rsqr(rtab[i]) + a*a, 1.5); } gsp->npoint = np; gsp->radius = rtab; gsp->density = dtab; gsp->mass = mtab; gsp->alpha = 0.0; gsp->beta = -5.0; gsp->mtot = mtot; return (gsp); }
int main(int argc, string argv[]) { stream istr; gsprof *tgsp, *mgsp; real beta_a, *sig2, rrange[2], lgrs, r; int np, i; initparam(argv, defv); istr = stropen(getparam("gsp"), "r"); get_history(istr); tgsp = get_gsprof(istr); strclose(istr); if (! strnull(getparam("grav"))) { istr = stropen(getparam("grav"), "r"); get_history(istr); mgsp = get_gsprof(istr); strclose(istr); } else mgsp = tgsp; beta_a = getdparam("beta_a"); sig2 = calc_sig2_gsp(tgsp, mgsp, beta_a); np = getiparam("npoint"); setrange(rrange, getparam("rrange")); lgrs = rlog2(rrange[1] / rrange[0]) / (np - 1); printf("%12s %12s\n", "radius", "sig_r^2"); for (i = 0; i < np; i++) { r = rrange[0] * rpow(2.0, lgrs * i); printf("%12.5f %12.7f\n", r, sig2_gsp(tgsp, mgsp, beta_a, sig2, r)); } return (0); }