13 static void mc_table(
bool lgHeader,
double tau,
double a,
double pesc1,
14 double nbar,
double lbar,
double taul,
double pdest)
20 "# tau1/2 pesc1 <N> <L>"
22 " pdest esca0k2 esctot\n");
27 "%12.5e %12.5e %12.5e %12.5e %12.5e %12.5e %12.5e %12.5e\n",
28 tau, pesc1, nbar, lbar, taul, pdest,
esca0k2(tau/SQRTPI),
34 static double phigauss(
double nu)
36 return exp(-nu*nu)/SQRTPI;
84 return beta*phi/(beta+phi);
92 void mc_escape(
double tau_in,
double a,
double beta)
101 const long NSAMP = 1e7;
102 double totnu1 = 0.0, totnu2 = 0.0, totphi = 0.0;
103 for (
long i=0; i<NSAMP; ++i)
107 double nu2 = (10.*(i+0.5))/NSAMP;
108 double phi = phigauss(nu2);
110 totnu2 += nu2*nu2*phi;
114 fprintf(
ioQQQ,
"Check %g %g %g\n",totnu1/NSAMP,totphi/(0.1*NSAMP),
120 vector<realnum> v(npt), y(npt), cv(npt+1);
126 for (
long i = 0; i<npt; ++i)
128 v[i] = width*(i+0.5)/npt;
130 VoigtU(a,&v[0],&y[0],npt);
132 for (
long i = 0; i<npt; ++i)
134 cv[i+1] = cv[i] + (width/npt)*y[i];
136 for (
long i = 0; i<npt; ++i)
142 const long NPART = 10000;
143 mc_table(
true,0.,a,0.,0.,0.,0.,0.);
144 for (
double tau0=0.01; tau0<tau_in; tau0 *= 1.1)
146 double nfirst = 0.0, ntot = 0.0, ltot=0.0, taulast=0.0,
148 for (
long i=0; i<NPART; ++i)
155 double tauprev = tau;
173 ASSERT (ii > 0 && ii < npt);
175 nu = sign*((1.0-
frac)*v[ii]+frac*v[ii+1]);
176 phix = (1.0-
frac)*y[ii]+frac*y[ii+1];
185 double dlength = dtaunu /
SDIV(beta+phix);
188 double dtauperp = dlength * costheta;
190 if (tau-dtauperp < 0.0)
191 ltot += tau/costheta;
192 else if (tau-dtauperp > 2.0*tau0)
193 ltot += (2.0*tau0-tau)/costheta;
223 mc_table(
false,tau0,a,nfirst/NPART,ntot/NPART,ltot/NPART,
224 taulast/(NPART-ndest),ndest/NPART);
231 double taustep = 2., taumin=1e-8,taumax=1e14;
232 for (
double tau = taumin; tau < taumax; tau *= taustep)
234 double esccom_v =
esca0k2(tau);
236 k2DampArg k2fun(a,SQRTPI*tau);
237 double rmax1 = 1.0,rmax;
238 for(
int idiv=0;idiv<200;++idiv)
242 if (k2fun(rmax1) != 0.0)
248 double intgral = IntDamp.
sum(0.0,rmax);
250 k2r(integrate::Midpoint<k2DampArg>(k2fun,0.0,rmax));
252 fprintf(ioQQQ,"%15.8g %15.8g %15.8g %15.8g %15.8g %15.8g\n",
253 tau,a,esccom_v,esctot,2.0*intgral,2.0*k2r.sum());
256 fprintf(ioQQQ,"\n\n#betaFbeta at a \n");
257 double betastep = 2., betamin=1e-6,betamax=1e3;
258 for (double beta = betamin; beta < betamax; beta *= betastep)
261 class integrate::Romberg<integrate::Midpoint<overlap> >
262 ovr(integrate::Midpoint<overlap>(ov,-100.0,100.0));
264 fprintf(ioQQQ,"%15.8g %15.8g %15.8g %15.8g\n",
265 beta,a,beta/(1.0+beta),ovr.sum());
double expn(int n, double x)
long hunt_bisect(const T x[], long n, T xval)
void mc_escape(double tau_in, double a, double beta)
double sum(double min, double max) const
double RandGauss(double xMean, double s)
void VoigtU(realnum a, const realnum v[], realnum y[], int n)
int fprintf(const Output &stream, const char *format,...)
sys_float SDIV(sys_float x)
double esca0k2(double taume)
double esc_CRDwing_1side(double tau, double a)