python初心者です。
未だにpythonで何が出来るか、理解できていないことが多いです。
もし知っていることがありましたら、ご教授して頂きたく存じます。
何卒宜しくお願いいたします。
前提・実現したいこと
現在持っている計算コード(C++)をpython上で使用したいです。
ちなみに、使用したいC++のコードは以下になります。
環境
Mac
pyhton3.7
//////////////////////////////////////////////*/ #include <iostream> #include <fstream> #include <math.h> using namespace std; //グローバル変数[mksA] double Pi=3.141592653589793;// double Rho=1.e3; // double R_dom =0.32e-6;// double R_nucl=3.9e-6;// // double Beta=0.0615;// double Alpha0=0.172; // double PrimEne=2000.;// double z=6.;// double n=12.;// double A=n;// double Zt=7.4;// double MI=75;// double mc2=511028.3556;// double re=2.817e-15;// double Sn=Pi*Rho*R_nucl*R_nucl; double Z0=sqrt(Sn/Beta/(1/(Pi*Rho*R_dom*R_dom)+1/Sn))/(Pi*R_dom*R_dom*Rho); //Track-D(r) ****************************************** int LEMhenkan=0; double R_core,D_core,R_penu,K_penu; double track(double r){ double dose; if(r<=R_core){dose=D_core;}// else if(r>R_penu){dose=0.;}// else{dose=K_penu/(r*r);}// //LEM-z' if(LEMhenkan==1){ double a=Alpha0,b=Beta,Dt=20.; if(dose>Dt)dose=(sqrt(a*a-4*b*(b*Dt*Dt-(a+2*b*Dt)*dose)) -a)/(2*b); } return dose; } /* */ //**** r-z(r)-zD,zFに変換 *************** double z1ave,z1z1ave,z1doseAve,z1stAve;//<z1>,<z1*z1>,z1D void z1moment(void){ double length1,length2,z,z1,z2; double zzpdr,zpdr,pdr,zzstpdr; zzpdr=zpdr=pdr=zzstpdr=0.; ifstream in2("r_z.txt"); in2 >>length1>>z1; while(!in2.eof()){ in2 >>length2>>z2; if(z1==0.)break; //if(z1==z2)continue; z=(z2+z1)/2; zzpdr += z*z*Pi*fabs(length2*length2-length1*length1); zpdr += z*Pi*fabs(length2*length2-length1*length1); pdr += Pi*fabs(length2*length2-length1*length1); zzstpdr += Z0*Z0*(1.-exp(-z*z/(Z0*Z0)))*Pi*fabs(length2*length2-length1*length1); length1=length2; z1=z2; //cout<<" "<<zzpdr/zpdr; } in2.close(); z1ave =zpdr/pdr; z1z1ave = zzpdr/pdr; z1doseAve =zzpdr/zpdr; z1stAve = zzstpdr/zpdr; } //IP-zの関係 ************************** double LET; void r_z(double R_site,double E){ //ローカル変数[mksA] double L_site=2.*R_site;// double M_site=Pi*R_site*R_site*L_site*Rho;// double r,dr; // double edep; // double length,dlength;// double x; // double enko;// double beta;// double L0; // ===================== beta=pow((1.-pow( (931.506*A/(E*n+931.506*A)),2) ),0.5);//β; L0=log(2.*mc2*beta*beta/MI)-log(1-beta*beta)-beta*beta; LET=0.306*10/18*z*z/(beta*beta)*L0*1.602e-11;//LET[J/m]=[MeV/cm]*1.602e-11 /* //TS計算 =================== */ R_core=0.0116*beta *1.e-6;// R_penu=6.16e-2*pow((E*n/A),1.7) *1.e-6;// K_penu=1.6021892e-10*7.8e5*(z/beta)*(z/beta) *1.e-12;// D_core=(LET/Rho -2.*Pi*K_penu*log(R_penu/R_core))/(Pi*R_core*R_core);// cout<<"D_core="<<D_core<<" R_core="<<R_core<<" R_penu="<<R_penu<<endl; // cout<<"Ene="<<E<<" MeV/u"<<" LET="<<LET/1.602e-10<<" keV/um"; ofstream out9("trackStructure.txt"); LEMhenkan=0; out9 <<0.<<" "<<track(0.)<<endl; for(length=R_core/20;length<1.1*R_penu+R_site+R_core; length *= 1.01){ out9 <<length<<" "<<track(length)<<endl; } out9.close(); ofstream out("r_z.txt"); dlength=R_site/20; //A. ================ for(length=0.; length< fabs(R_site-R_core); length += dlength){// +=R_core/20 if(R_site<R_core){ edep =track(0.)*M_site;//cout<<" R_site<R_core "; }else{ edep =Rho*L_site*Pi*R_core*R_core*track(0.); r=R_core; dr=dlength/5;//R_core/100; while(r<R_site+length){// enko=2.*Pi*r; if(r > R_site-length){ x=(length*length +r*r -R_site*R_site)/(2*r*length)*0.9999; enko = 2.*r*acos(x); } edep += Rho*dr*enko*L_site*track(r+dr/2); //cout<<length<<" "<<enko<<" "<<edep<<endl; r *= 1.01; dr = 0.01*r; } } //cout<<length<<"A "<< edep/M_site<<"Gy"<<endl; out<<length<<" "<<edep/M_site<<endl; } cout<<" A_OK"; //out<<fabs(R_site-R_core)<<" "<<0.9999*edep/M_site<<endl; //B. ======================= if(R_core/20<dlength)dlength=R_core/20; double thi_min; for(length=fabs(R_site-R_core)+dlength/20; length< R_site+R_core; length += dlength){ if(R_site<R_core){ edep=0; r =length-R_site; if(r<0)r=0.; dr=dlength/100;//R_site/20; while(r<R_site+length){// x=(length*length +r*r -R_site*R_site)/(2*r*length)*0.9999; if(x<=-1.)x=-0.999; if(x>=1.)x=0.999; enko = 2.*r*acos(x); edep += Rho*dr*enko*L_site*track(r+dr/2); r += dr; } }else{ thi_min=acos((R_site-length)/R_core);//cout<<thi_min<<"Rad"<<endl; edep=track(0.)*Rho*L_site *(R_core*R_core*(Pi-thi_min +cos(thi_min)*sin(thi_min)) );//コア r=R_core; dr=dlength;//R_core/20; while(r<R_site+length){// x=(length*length +r*r -R_site*R_site)/(2*r*length)*0.9999; enko = 2.*r*acos(x); edep += Rho*dr*enko*L_site*track(r+dr/2); r += dr; } } if(edep/M_site>track(0.))continue; out<<length<<" "<< edep/M_site<<endl; } cout<<" B_OK"; //C. ============ for(length=R_site+R_core; length<10*R_site+R_core; length *= 1.01){ edep=0.; r=length-R_site; dr=R_site/1000; while(r<R_site+length){// x=(length*length +r*r -R_site*R_site)/(2*r*length)*0.9999; enko = 2.*r*acos(x); //cout <<" "<<x; edep += Rho*dr*enko*L_site*track(r+dr/2); r += dr; } if(edep/M_site>track(0.))continue; //cout <<length<<"C "<< edep/M_site<<"Gy"<<endl; out <<length<<" "<< edep/M_site<<endl; } cout<<" C_OK"; //D. ==================== for(length=10*R_site+R_core; length<1.1*R_penu+R_site+R_core; length *= 1.01){ edep = track(length);// //cout <<length<<"D "<< edep/M_site<<"Gy"<<endl; out <<length<<" "<< edep<<endl; } cout<<" D_OK"<<endl; out.close(); } //メイン関数 int main(int argc, char* argv[]) { //ローカル変数 double energy;// double zD_dom,zD_nucl; double yD_dom,yD_nucl; double zst_dom,yst_dom; double alpha,alpha_st,doseXX; cout<<"Alpha0= "<<Alpha0<<endl; cout<<"y0= "<<Z0*Pi*R_dom*R_dom*Rho/1.602e-10<<endl; ofstream out3; //out3.open("yD.txt", ios::app); out3.open("results.txt"); //out3 <<"energy LET alpha_st doseXX"<<endl; energy=PrimEne; while(energy>.1) { LEMhenkan=0; r_z(R_dom,energy); //z_p() z1moment();// 。 zD_dom=z1doseAve; yD_dom=z1doseAve * Pi*R_dom*R_dom*Rho;// *M_dom/L_dom zst_dom=z1stAve; yst_dom=z1stAve * Pi*R_dom*R_dom*Rho;// *M_dom/L_dom // cout<<" zD_dom="<<z1doseAve<<" yD_dom= "<<yD_dom/1.602e-10<<endl; // out3 <<energy<<" "<<LET/1.602e-10<<" "<<yD_dom/1.602e-10<<" "<<z1doseAve<<endl; LEMhenkan=0; r_z(R_nucl,energy); //z_p() z1moment();// zD_nucl=z1doseAve; // yD_nucl=zD_nucl* Pi*R_nucl*R_nucl*Rho; // == 推定 ========================================== alpha_st=(Alpha0+Beta*zst_dom); /* */ // doseXX = (-alpha_st+sqrt(alpha_st*alpha_st-4.*Beta*log(0.1)))/(2*Beta); cout<<" yD_dom= "<<yD_dom/1.602e-10<<" yD_nucl="<<yD_nucl/1.602e-10<<" yst_dom="<<yst_dom/1.602e-10<<endl; // out3 <<energy<<" "<<LET/1.602e-10<<" "<<yD_dom/1.602e-10<<" "<<yst_dom/1.602e-10<<" "<< alpha_st<<" "<<doseXX<<endl; energy=energy*0.9; } out3.close(); return 0; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/10/31 02:26 編集
2020/11/01 20:58
2020/11/03 06:52
2020/11/03 08:04
2020/11/07 08:46 編集
2020/11/08 08:51 編集