#include #include #include // AWS20080711 r194: for compatibility with gcc4.3 using namespace std; void B_field_3D_model (char* name, double *parameters, double x, double y, double z, int options, double &Breg, double &Bregx, double &Bregy, double &Bregz, double &Bran, double &Branx, double &Brany, double &Branz, int debug=0 ) { // General purpose interface for Galactic magnetic field models // including regular and random components // input arguments // name: name of model // parameters: array of model parameters for model with this name // options: for addional control // x,y,z Galactic coordinates of point, kpc (Sun at x=Rsun, y=z=0) // output arguments // magnetic field strengths in Gauss // Breg regular field total // Bregx regular field x-component // Bregy regular field y-component // Bregz regular field z-component // Bran random field total // Branx random field x-component (for a random direction) // Brany random field y-component (for a random direction) // Branz random field z-component (for a random direction) // local variables double theta,phi; // spherical angles double dtr=acos(-1.)/180.; // degrees to radians double pi =acos(-1.); if(debug==1)cout<<"B_field_3D_model"< 1000) { Bo= (model/1000000) * 0.1 *1.0e-10; rscale=(model-(model/1000000)*1000000 )/1000 * 0.1 ; zscale=(model%1000) * 0.1 ; b_field=Bo *exp(-(r-ro)/rscale) * exp(-fabs(z)/zscale); if(debug==1) cout<<"galprop original model="< rbreak) B0 =parameters[0]*(ro/r); Bregx=B0 *cos(theta-psi*log( r /r0))*sin(p-theta)*fz; //AWS20080311 20081107 Bregy=B0 *cos(theta-psi*log( r /r0))*cos(p-theta)*fz; //correction AWS20080320 AWS20080311 20081107 Bregz=0.; Bregz=parameters[5]; //AWS20080711 Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); //AWS20080331 // random component can be added for testing Bran=parameters[4]; Branx=Bran; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; } if(debug==1) cout<<"B model= "< rbreak) B0 =parameters[0]*(ro/r); Bregx=B0 *cos(theta-psi*log( r /r0))*sin(p-theta)*fz; //AWS20080311 20081107 Bregy=B0 *cos(theta-psi*log( r /r0))*cos(p-theta)*fz; //correction AWS20080320 AWS20080311 20081107 Bregz=0.; Bregz=parameters[5]; //AWS20080711 Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); //AWS20080331 Bran=parameters[4]*Breg; //AWS20080331 Branx=Bran; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; } ////////////////////////////////////////////////////////////////////////////////////// // Tinyakov & Tkachev 2002,Astroparticle Physics 18, 165 BSS-A model, // radial dependence of Bo // from Elena Orlando if(strcmp(name,"tinyakov_exp_ran")==0) //EO20081118 { double B0; double ro=8.5; theta=atan2(y,x); double p=parameters[2]*dtr; //=-8 pitch angle double r0=(ro-0.5)*exp((-pi/2)*tan(p)); double z0=parameters[6]; double fz=exp(-fabs(z/z0)); if(z<0.) fz=-fz; // to avoid problem at z=0 double psi=1./(tan(p));//radial dependence of opening angle double r=pow(x*x+y*y,0.5); double rbreak = parameters[8]; //EO20081119 if(r<=rbreak) B0 =parameters[0]*(ro/rbreak);//parameters[0]=1.4 if(r> rbreak) B0 =parameters[0]*(ro/r); Bregx=B0 *cos(theta-psi*log(r/r0))*sin(p-theta)*fz; Bregy=B0 *cos(theta-psi*log(r/r0))*cos(p-theta)*fz; Bregz=parameters[5]; Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); // random component can be added for testing Bran=parameters[4]; Branx=Bran*fz; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; } //////////////////////////////////////////////////////////////////////////////////////////// // halo dipole component from prouza 2003 formulae, same parameters if(strcmp(name,"halo_dipole")==0) { theta=atan2(y,x); // NB theta defined differently from above double r=pow(x*x+y*y,0.5); double beta=90.*dtr-atan(z/r); if(fabs(z)<=0.3 && r<=0.1) //Btot=const =2mG from prouza {double k=pow(10.,-3.); Bregx=-(3./2.)*k*sin(2.*beta)*sin(theta); Bregy=-(3./2.)*k*sin(2.*beta)*cos(theta); Bregz=-k*(3.*cos(beta)*cos(beta)-1.); } if(fabs(z)>0.3 && r<=0.1) //Btot=const =2mG from prouza {double k=2.*pow(10.,-7.); Bregx=-(3./2.)*k*sin(2.*beta)*sin(theta)/pow(r,3.); Bregy=-(3./2.)*k*sin(2.*beta)*cos(theta)/pow(r,3.); Bregz=-k*(3.*cos(beta)*cos(beta)-1.)/pow(r,3.); } if( r>0.1 && r<=2.) // from prouza {double k=2.*pow(10.,-7.); Bregx=-(3./2.)*k*sin(2.*beta)*sin(theta)/pow(r,3.); Bregy=-(3./2.)*k*sin(2.*beta)*cos(theta)/pow(r,3.); Bregz=-k*(3.*cos(beta)*cos(beta)-1.)/pow(r,3.); } if( r>2. && r<=5.) // from prouza {double k=5.*pow(10.,-7.); Bregx=-(3./2.)*k*sin(2.*beta)*sin(theta); Bregy=-(3./2.)*k*sin(2.*beta)*cos(theta); Bregz=-k*(3.*cos(beta)*cos(beta)-1.); } if( r>5.) // from prouza {double k=pow(10.,-4.); Bregx=-(3./2.)*k*sin(2.*beta)*sin(theta)/pow(r,3.); Bregy=-(3./2.)*k*sin(2.*beta)*cos(theta)/pow(r,3.); Bregz=-k*(3.*cos(beta)*cos(beta)-1.)/pow(r,3.); } Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); // random component set to zero Bran =0.0; Branx=0.0; Brany=0.0; Branz=0.0; } /////////////////////////////////////////////////////// EO20090701 //Sun model for B in the plane. ASS-RING model if(strcmp(name,"sun")==0) //EO20090207 { double B0; double ro=8.5; theta=atan2(y,x); double p=parameters[2]*dtr; //=-12 pitch angle //double r0=(ro-0.5)*exp((-pi/2)*tan(p)); double r0=10.; double z0=parameters[6]; //=1 kpc double fz=exp(-fabs(z/z0)); if(z<0.) fz=-fz; // to avoid problem at z=0 // double psi=1./(tan(p));//radial dependence of opening angle double r=pow(x*x+y*y,0.5); double rbreak = parameters[8];//rc=5 kpc //EO20081119 double D1; double D2; B0=parameters[0];//2 microGauss if(r<=rbreak && fabs(z)<=1) D1 = B0; if(r<=rbreak && fabs(z)>1) D1 = 0.;//artificial cut not present in Sun formulation if(r> rbreak) D1 =B0*exp(-(r-ro)/r0)*fz; if(r>7.5) D2=1; if(r<=7.5 & r>6.) D2=-1; if(r>5.&& r<=6) D2=1; if(r<=5) D2=-1; Bregx=D1*D2*sin(p-theta); Bregy=D1*D2*cos(p-theta); Bregz=parameters[5];//=0 in Sun Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); // random component can be added for testing Bran=parameters[4];//3 microgauss Branx=Bran; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // from Elena Orlando EO20090716 if(strcmp(name,"random")==0) { double Bo,rscale,zscale; double ro=8.5; double b_field; double r=sqrt(x*x+y*y); //just to test the random compoennt since the contrubution of the models for the regular is negligible EO20090716 Bo = parameters[0]; // Gauss rscale=parameters[3]; // kpc zscale=parameters[2]; // kpc double chi0=parameters[1]*dtr;// not defined in Han; parameter[1]=8 in WMAP Miville double chi=chi0*tanh(z/parameters[9]); // z dependence, not defined in Han; //EO20081120 b_field=Bo *exp(-(r-ro)/rscale)*cos(chi);// * exp(-fabs(z)/zscale); // the regular field is zero Breg =0.0; Bregx=0.0; Bregy=0.0; Bregz=0.0; Bran=b_field; Branx=Bran; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; theta=0.0; phi =0.0; } //only random component /////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // from Elena Orlando EO20090716 if(strcmp(name,"random1")==0) { double Bo,rscale,zscale; double ro=8.5; double b_field; double r=sqrt(x*x+y*y); //just to test the random compoennt since the contrubution of the models for the regular is negligible EO20090716 Bo = parameters[0]; // Gauss rscale=parameters[3]; // kpc zscale=parameters[2]; // kpc double chi0=parameters[1]*dtr;// not defined in Han; parameter[1]=8 in WMAP Miville double chi=chi0*tanh(z/parameters[9]); // z dependence, not defined in Han; //EO20081120 double rc=parameters[4]; if(r<=rc) b_field=Bo *exp(-(r-ro)/rscale)*cos(chi);// * exp(-fabs(z)/zscale); if(r>rc) b_field=Bo *exp(-(rc-ro)/rscale)*cos(chi);// * exp(-fabs(z)/zscale); // the regular field is zero Breg =0.0; Bregx=0.0; Bregy=0.0; Bregz=0.0; Bran=b_field; Branx=Bran; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; theta=0.0; phi =0.0; } //only random component /////////////////////////////////////////////////////// EO20090701 //Sun model for B in the plane. ASS-RING model if(strcmp(name,"jansson_disk")==0) //EO20090207 { double B0; double ro=8.5; theta=atan2(y,x); double p=-5*dtr; //=-12 pitch angle //double r0=(ro-0.5)*exp((-pi/2)*tan(p)); double r0=5.1; double z0=parameters[6]; //=1 kpc double fz=exp(-fabs(z/z0)); if(z<0.) fz=-fz; // to avoid problem at z=0 // double psi=1./(tan(p));//radial dependence of opening angle double r=pow(x*x+y*y,0.5); double rbreak = 5.7;//rc=5 kpc //EO20081119 double D1; double D2; double Bc=0.16e-6; B0=1.1e-6;//2 microGauss if(r<=rbreak) D1 = Bc*fz; // if(r<=rbreak) D1 = 0.;//artificial cut not present in Sun formulation if(r> rbreak) D1 =B0*exp(-(r-ro)/r0)*fz; if(r>7.5) D2=1; if(r<=7.5 & r>6.) D2=-1; if(r>5.&& r<=6) D2=1; if(r<=5) D2=-1; Bregx=D1*D2*sin(p-theta); Bregy=D1*D2*cos(p-theta); Bregz=0.0;//=0 in Sun Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); // random component can be added for testing Bran=0.0;//3 microgauss Branx=Bran; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; } /////////////////////////////////////////////////////// EO20090701 //Sun model for B in the plane. ASS-RING model //to be finished!!!! if(strcmp(name,"jansson_halo")==0) //EO20090207 { double B0; double ro=8.5; theta=atan2(y,x); double p; //=-12 pitch angle //double r0=(ro-0.5)*exp((-pi/2)*tan(p)); double r0=28.; double z0=parameters[6]; //=1 kpc double fz=exp(-fabs(z/z0)); if(z<0.) fz=-fz; // to avoid problem at z=0 // double psi=1./(tan(p));//radial dependence of opening angle double r=pow(x*x+y*y,0.5); double rbreak = 8.72;//rc=5 kpc //EO20081119 // double D1; // double D2; // double Bc=0.16; B0=2.3e-6;//2 microGauss if(r<=rbreak) p=-30.*dtr;// D1 = Bc*fz; // if(r<=rbreak) D1 = 0.;//artificial cut not present in Sun formulation if(r> rbreak) p=-2.*dtr; // D1 =B0*exp(-r/r0)*fz; // if(r>7.5) D2=1; // if(r<=7.5 & r>6.) D2=-1; // if(r>5.&& r<=6) D2=1; // if(r<=5) D2=-1; Bregx=B0*exp(-r/r0)*fz*sin(p-theta); Bregy=B0*exp(-r/r0)*fz*cos(p-theta); Bregz=0.0;//=0 in Sun Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); // random component can be added for testing Bran=0.0;//3 microgauss Branx=Bran; // put all field in x-direction (has no significance) Brany=0.0; Branz=0.0; } /////////////////////////////////////////////////////// (from M.Regis and M.Taoso) //Farrar and Jansson model for regular and random B (see 1204.3662 and 1210.7820) if(strcmp(name,"farrar")==0) { double bregdisk[3],bregtor[3],bregXhalo[3],brandisk,branhalo; double i=11.5*pi/180.; double bring=0.1,hdisk=0.4,wdisk=0.27; double b1=0.1,b2=3.0,b3=-0.9,b4=-0.8,b5=-2.0,b6=-4.2,b7=0.0,b8=2.7; double Rx1=-5.1,Rx2=-6.3,Rx3=-7.1,Rx4=-8.3,Rx5=-9.8,Rx6=-11.4,Rx7=-12.7,Rx8=-15.5; double r,rsph,phi2,B0,bt,rt,phil; double Lf=1.0/(1.0+exp(-2*(fabs(z)-hdisk)/wdisk)); if(x!=0.) {phi2=atan(fabs(y/x));} r=sqrt(x*x+y*y); rsph=sqrt(x*x+y*y+z*z); if(x==0. && y>=0.0) {phi=pi/2.;} if(x==0. && y<0.0) {phi=3.*pi/2.;} if(x>0. && y>=0.0) {phi=phi2;} if(x<0. && y>=0.0) {phi=pi-phi2;} if(x<0. && y<0.0) {phi=pi+phi2;} if(x>0. && y<0.0) {phi=2*pi-phi2;} // Regular B: disk component: if(r>=20.0) {B0=0;} if(r<3.0) {B0=0;} if(r>=3.0 && r<=5.0) {B0=bring;} if(r>5. && r<20.){ if(phi<=pi) {phil=pi+phi;} else {phil=phi-pi;} rt=r*exp(-phil/(tan(pi/2-i))); if(rtfabs(Rx8)) {rt=r*exp(-(phil+2*pi)/tan(pi/2.-i));} if(rtfabs(Rx1))&&(rtfabs(Rx2))&&(rtfabs(Rx3))&&(rtfabs(Rx4))&&(rtfabs(Rx5))&&(rtfabs(Rx6))&&(rtfabs(Rx7))&&(rt5.){ br=sin(i); bphi=cos(i);} bregdisk[0]=(br*cos(phi)-cos(pi/2.-phi)*bphi)*B0; bregdisk[1]=(br*sin(phi)+sin(pi/2.-phi)*bphi)*B0; bregdisk[2]=0.0; // Regular B: toroidal component: double bn=1.4,bs=-1.1,rn=9.22,rs=16.7,wh=0.2,z0=5.3; double Lfn=1.0/(1.+exp(-2*(fabs(r)-rn)/wh)); double Lfs=1.0/(1.+exp(-2*(fabs(r)-rs)/wh)); B0=(z<0) ? exp(-fabs(z/z0))*Lf*bs*(1-Lfs) : exp(-fabs(z/z0))*Lf*bn*(1-Lfn); if(rsph<1.0 || rsph>20.) {B0=0;} br=0.0; bphi=1.0; bregtor[0]=(br*cos(phi)-cos(pi/2.-phi)*bphi)*B0; bregtor[1]=(br*sin(phi)+sin(pi/2.-phi)*bphi)*B0; bregtor[2]=0; // Regular B: X-halo component: double thetaxu,theta0x=49.*pi/180.,rcx=4.8; double bx=4.6,rx=2.9; double rp=r-fabs(z)/tan(theta0x); double BXp=bx*exp(-rp/rx); if(r==0) {B0=0;thetaxu=0.0;} else {B0=BXp*rp/r;thetaxu=theta0x;} if(rp20.) B0=0; br=1.0; bphi=0.0; bregXhalo[0]=(br*cos(phi)-cos(pi/2.-phi)*bphi)*B0*cos(thetaxu); if(z<0) bregXhalo[0]*=-1; bregXhalo[1]=(br*sin(phi)+sin(pi/2.-phi)*bphi)*B0*cos(thetaxu); if(z<0) bregXhalo[1]*=-1; bregXhalo[2]=B0*sin(thetaxu); // Regular B: Total Bregx=bregdisk[0]+bregtor[0]+bregXhalo[0]; Bregy=bregdisk[1]+bregtor[1]+bregXhalo[1]; Bregz=bregdisk[2]+bregtor[2]+bregXhalo[2]; Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); // random striated component added as a multiplicative factor acting on Breg: double fstri=sqrt(2.36); // the value is taken from the most recent paper 1210.7820 Bregx*=fstri*1.e-6; Bregy*=fstri*1.e-6; Bregz*=fstri*1.e-6; Breg*=fstri*1.e-6; // Gauss // Random B: disk component: double bint=7.63,z0disk=0.61; if(r<5.0) {bt=bint;} if(r>5.){ b1=10.81;b2=6.96;b3=9.59;b4=6.96;b5=1.96;b6=16.34;b7=37.29;b8=10.35; if(phi<=pi) {phil=pi+phi;} else {phil=phi-pi;} rt=r*exp(-phil/(tan(pi/2-i))); if(rtfabs(Rx8)) rt=r*exp(-(phil+2*pi)/tan(pi/2.-i)); if(rtfabs(Rx1))&&(rtfabs(Rx2))&&(rtfabs(Rx3))&&(rtfabs(Rx4))&&(rtfabs(Rx5))&&(rtfabs(Rx6))&&(rtfabs(Rx7))&&(rt=1.5) z1=0.4; double B1=1/(1+pow((fabs(z)-1.5)/z1, 2)); double B2=exp(-(r-4)/4); double Bt=B0t*B1*B2*r/4; theta=atan2(y,x); double Bhalox = Bt*cos(theta); double Bhaloy =-Bt*sin(theta); double Bhaloz=0.; if (z<0.){Bhalox=-Bhalox; Bhaloy=-Bhaloy;} Bregx += Bhalox; Bregy += Bhaloy; Bregz += Bhaloz; Breg=sqrt(Bregx*Bregx + Bregy*Bregy + Bregz*Bregz); //////////////////////////////////////////////////////////////// //============================================================================ if(debug==1) cout<<"B model= "<