bool CommandCollection::ReadConfig() { ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("ShellExtensions")); int len=0; if(!cfg->Read(_T("ShellCmds/numcmds"), &len)) { // cbMessageBox(_T("Warning: couldn't read interpreter config data")); return false; } for(int i=0;i<len;i++) { ShellCommand interp; wxString istr=istr0(i); cfg->Read(_T("ShellCmds/I")+istr+_T("/name"), &interp.name); cfg->Read(_T("ShellCmds/I")+istr+_T("/command"), &interp.command); cfg->Read(_T("ShellCmds/I")+istr+_T("/wdir"), &interp.wdir); cfg->Read(_T("ShellCmds/I")+istr+_T("/wildcards"), &interp.wildcards); cfg->Read(_T("ShellCmds/I")+istr+_T("/menu"), &interp.menu); cfg->Read(_T("ShellCmds/I")+istr+_T("/menupriority"), &interp.menupriority); cfg->Read(_T("ShellCmds/I")+istr+_T("/cmenu"), &interp.cmenu); cfg->Read(_T("ShellCmds/I")+istr+_T("/cmenupriority"), &interp.cmenupriority); cfg->Read(_T("ShellCmds/I")+istr+_T("/envvarset"), &interp.envvarset); cfg->Read(_T("ShellCmds/I")+istr+_T("/mode"), &interp.mode); interps.Add(interp); } return true; }
//--------------------------------------------------------------------------- //Reading the parameters of simulation int Input::Read_simulation_parameters(struct Simu_para &simu_para, ifstream &infile) { if(simu_para.mark) { cout << "Attention: \"" << simu_para.keywords << "\" has been input!" << endl; hout << "Attention: \"" << simu_para.keywords << "\" has been input!" << endl; return 0; } else simu_para.mark = true; istringstream istr0(Get_Line(infile)); istr0 >> simu_para.simu_name; //Read the name of simulation istringstream istr1(Get_Line(infile)); istr1 >> simu_para.sample_num; //Read the number of samples if(simu_para.sample_num<1) { hout << "Error: the number of samples less than 1." << endl; return 0; } istringstream istr2(Get_Line(infile)); istr2 >> simu_para.create_read_network; //Read a signal to show if create a new network or read a previouse network from a file if(simu_para.create_read_network!="Create_Network"&&simu_para.create_read_network!="Read_Network") { hout << "Error: the 'create_read_network' is neither 'Create_Network' nor 'Read_Network'." << endl; return 0; } return 1; }
bool CommandCollection::ImportLegacyConfig() { ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("InterpretedLangs")); int len=0; if(!cfg->Read(_T("InterpProps/numinterps"), &len)) { return false; } for(int i=0;i<len;i++) { wxString istr=istr0(i); wxString name,exec,extensions; cfg->Read(_T("InterpProps/I")+istr+_T("/name"), &name); cfg->Read(_T("InterpProps/I")+istr+_T("/exec"), &exec); cfg->Read(_T("InterpProps/I")+istr+_T("/ext"), &extensions); int lenact=0; cfg->Read(_T("InterpProps/I")+istr+_T("/numactions"), &lenact); for(int j=0;j<lenact;j++) { ShellCommand interp; wxString jstr=istr0(j); wxString aname,command,mode,wdir,envvarset; cfg->Read(_T("InterpProps/I")+istr+_T("/actions/A")+jstr+_T("/name"), &aname); cfg->Read(_T("InterpProps/I")+istr+_T("/actions/A")+jstr+_T("/command"), &command); cfg->Read(_T("InterpProps/I")+istr+_T("/actions/A")+jstr+_T("/mode"), &mode); cfg->Read(_T("InterpProps/I")+istr+_T("/actions/A")+jstr+_T("/workingdir"), &wdir); cfg->Read(_T("InterpProps/I")+istr+_T("/actions/A")+jstr+_T("/envvarset"), &envvarset); interp.name=name+_T(" ")+aname; interp.wildcards=extensions; interp.command=command; interp.command.Replace(_T("$interpreter"),exec); interp.wdir=wdir; interp.menu=name+_T("/")+aname; interp.cmenu=name+_T("/")+aname; interp.cmenupriority=0; interp.menupriority=0; interp.envvarset=envvarset; interp.mode=mode; interps.Add(interp); } } cfg->Clear(); WriteConfig(); return true; }
bool CommandCollection::WriteConfig() { ConfigManager* cfg = Manager::Get()->GetConfigManager(_T("ShellExtensions")); //cfg->Clear(); int len=interps.GetCount(); cfg->Write(_T("ShellCmds/numcmds"), len); for(int i=0;i<len;i++) { wxString istr=istr0(i); cfg->Write(_T("ShellCmds/I")+istr+_T("/name"), interps[i].name); cfg->Write(_T("ShellCmds/I")+istr+_T("/command"), interps[i].command); cfg->Write(_T("ShellCmds/I")+istr+_T("/wdir"), interps[i].wdir); cfg->Write(_T("ShellCmds/I")+istr+_T("/wildcards"), interps[i].wildcards); cfg->Write(_T("ShellCmds/I")+istr+_T("/menu"), interps[i].menu); cfg->Write(_T("ShellCmds/I")+istr+_T("/menupriority"), interps[i].menupriority); cfg->Write(_T("ShellCmds/I")+istr+_T("/cmenu"), interps[i].cmenu); cfg->Write(_T("ShellCmds/I")+istr+_T("/cmenupriority"), interps[i].cmenupriority); cfg->Write(_T("ShellCmds/I")+istr+_T("/envvarset"), interps[i].envvarset); cfg->Write(_T("ShellCmds/I")+istr+_T("/mode"), interps[i].mode); } return true; }
//--------------------------------------------------------------------------- //Reading geometric information of the RVE int Input::Read_rve_geometry(struct Geom_RVE &geom_rve, ifstream &infile) { if(geom_rve.mark) { cout << "Attention: \"" << geom_rve.keywords << "\" has been input!" << endl; hout << "Attention: \"" << geom_rve.keywords << "\" has been input!" << endl; return 0; } else geom_rve.mark = true; //----------------------------------------------------------------------------------------------------------------------------------------- //Define the domain of RVE: the lower-left corner point of RVE and the length, width and height of RVE istringstream istr0(Get_Line(infile)); istr0 >> geom_rve.origin.x >> geom_rve.origin.y >> geom_rve.origin.z; istr0 >> geom_rve.len_x >> geom_rve.wid_y >> geom_rve.hei_z; if(geom_rve.len_x<=0||geom_rve.wid_y<=0||geom_rve.hei_z<=0) { cout << "Error: the sizes of RVE should be positive!" << endl; hout << "Error: the sizes of RVE should be positive!" << endl; return 0; } geom_rve.volume = geom_rve.len_x*geom_rve.wid_y*geom_rve.hei_z; //----------------------------------------------------------------------------------------------------------------------------------------- //Define the size range of the observation window and descrement by every step in x, y and z directions istringstream istr1(Get_Line(infile)); istr1 >> geom_rve.win_max_x >> geom_rve.win_max_y >> geom_rve.win_max_z; istringstream istr2(Get_Line(infile)); istr2 >> geom_rve.win_delt_x >> geom_rve.win_delt_y >> geom_rve.win_delt_z; istringstream istr3(Get_Line(infile)); istr3 >> geom_rve.win_min_x >> geom_rve.win_min_y >> geom_rve.win_min_z; if(geom_rve.win_max_x<=0.0||geom_rve.win_max_y<=0.0||geom_rve.win_max_z<=0.0|| geom_rve.win_max_x>geom_rve.len_x||geom_rve.win_max_y>geom_rve.wid_y||geom_rve.win_max_z>geom_rve.hei_z) { cout << "Error: the win_max in each direction of RVE should be positive and must be smaller than the size of RVE." << endl; hout << "Error: the win_max in each direction of RVE should be positive and must be smaller than the size of RVE." << endl; return 0; } if(geom_rve.win_min_x<=0.0||geom_rve.win_min_y<=0.0||geom_rve.win_min_z<=0.0|| geom_rve.win_min_x>geom_rve.win_max_x||geom_rve.win_min_y>geom_rve.win_max_y||geom_rve.win_min_z>geom_rve.win_max_z) { cout << "Error: the win_min in each direction of RVE should be positive and must be smaller than max." << endl; hout << "Error: the win_min in each direction of RVE should be positive and must be smaller than max." << endl; return 0; } if(geom_rve.win_delt_x<=0.0||geom_rve.win_delt_y<=0.0||geom_rve.win_delt_z<=0.0) { cout << "Error: the win_delt in each direction of RVE should be positive." << endl; hout << "Error: the win_delt in each direction of RVE should be positive." << endl; return 0; } //Details: +Zero for reducing the error of division int num[3] = { (int)((geom_rve.win_max_x-geom_rve.win_min_x + Zero)/geom_rve.win_delt_x), (int)((geom_rve.win_max_y-geom_rve.win_min_y + Zero)/geom_rve.win_delt_y), (int)((geom_rve.win_max_z-geom_rve.win_min_z + Zero)/geom_rve.win_delt_z) }; if(num[0]!=num[1]||num[0]!=num[2]) { cout << "Error: the numbers of cutoff times are different in three directions (x, y, z)." << endl; hout << "Error: the numbers of cutoff times are different in three directions (x, y, z)." << endl; return 0; } else geom_rve.cut_num = num[0]; //----------------------------------------------------------------------------------------------------------------------------------------- //Define the minimum size for background grids (looking for contact points) istringstream istr4(Get_Line(infile)); istr4 >> geom_rve.gs_minx >> geom_rve.gs_miny >> geom_rve.gs_minz; if(geom_rve.gs_minx<=0||geom_rve.gs_miny<=0||geom_rve.gs_minz<=0) { cout << "Error: the number of segments in each direction of RVE should be positive!" << endl; hout << "Error: the number of segments in each direction of RVE should be positive" << endl; return 0; } else if((int)(geom_rve.win_max_x/geom_rve.gs_minx)>500|| (int)(geom_rve.win_max_y/geom_rve.gs_miny)>500|| (int)(geom_rve.win_max_z/geom_rve.gs_minz)>500) { cout << "Error: the number of divisions in one of boundary is too big (>500), which leads to the memory problem!" << endl; hout << "Error: the number of divisions in one of boundary is too big (>500), which leads to the memory problem!" << endl; return 0; } return 1; }
//--------------------------------------------------------------------------- void EllipseMade::ellip_generation(ifstream &infile,string output_file,string data_file,double mod) { struct point_type { double x; double y; double z; }; double x,y,z; double x1,y1,z1; double A,B,C; double a_max,a_min,b_min,c_min; // the ellipse the max a and the min a and the min b,a is half of the long axis,b is the half of the short axis. double sita,phi; double alpha1,beta1,alpha2; double sign; double d,f; // the distance between two ellipses center double vol_ratio; int times; int k1,K,l1,L; istringstream istr0(Get_Line(infile)); //长方体区域的六条边 istr0 >> space.x0 >> space.x >> space.y0 >> space.y >> space.z0 >> space.z; istringstream istr2(Get_Line(infile)); //椭球长中短轴信息 istr2 >> a_min >> a_max >> b_min >> c_min; if (a_min>a_max) { hout << "输入的椭球长轴最小值大于最大值!" << endl; exit(0); } istringstream istr6(Get_Line(infile)); //体积百分比 istr6 >> vol_ratio; //@ // int in; // ifstream o("num.dat"); // o>>in; // o.close(); //if(in>10) in=in-10; //else if(in>5) in=in-5; //vol_ratio=vol_ratio*in; //------------------------------------------------------------- //椭球生成计数器 double delt_h = 2*sqrt(pow(c_min,2)*(pow(a_max,2)-pow(a_max-(a_min+c_min)*epsilon,2))/pow(a_max,2))/pi; double cell_volume = (space.x-space.x0)*(space.y-space.y0)*(space.z-space.z0); double ellip_volume = 0.0; ellip_ratio = 0.0; times=0; //用于随机生成的起始时间 srand((unsigned int)time(0)); do { //------------------------------------------------------------- //产生椭球 struct elliparam ell_temp; ell_temp.x=((double)(rand())/RAND_MAX)*(space.x-space.x0)+space.x0; ell_temp.y=((double)(rand())/RAND_MAX)*(space.y-space.y0)+space.y0; ell_temp.z=((double)(rand())/RAND_MAX)*(space.z-space.z0)+space.z0; ell_temp.a=((double)(rand())/RAND_MAX)*(a_max-a_min)+a_min; if(!(b_min==0&&c_min==0)) { ell_temp.b=((double)(rand())/RAND_MAX)*(ell_temp.a-b_min)+b_min; ell_temp.c=((double)(rand())/RAND_MAX)*(ell_temp.a-c_min)+c_min; } else { ell_temp.b=ell_temp.a; ell_temp.c=ell_temp.a; } alpha1 =((double)(rand())/RAND_MAX)*pi; if(alpha1>pi/2.0) { beta1 =((double)(rand())/RAND_MAX)*(2*(pi-alpha1))+(alpha1-pi/2.0); } else { beta1 =((double)(rand())/RAND_MAX)*(2*alpha1)+(pi/2.0-alpha1); } ell_temp.alpha1 =cos(alpha1); // r1 from 0 to pi ell_temp.beta1 =cos(beta1); // r2 from (pi/2-r1) to (pi/2+r1) ell_temp.gamma1 =(int)pow(-1.0,(int)fmod(rand(),2.0)+1)*sqrt(1-pow(ell_temp.alpha1,2)-pow(ell_temp.beta1,2)); // choose one in both, minus value or positive value if(alpha1>pi/2.0) { alpha2 =((double)(rand())/RAND_MAX)*(2*(pi-alpha1))+(alpha1-pi/2.0); } else { alpha2 =((double)(rand())/RAND_MAX)*(2*alpha1)+(pi/2.0-alpha1); } ell_temp.alpha2=cos(alpha2); A=1+pow(ell_temp.beta1/ell_temp.gamma1,2); B=2*(ell_temp.alpha1*ell_temp.alpha2*ell_temp.beta1)/pow(ell_temp.gamma1,2); C=pow(ell_temp.alpha1*ell_temp.alpha2/ell_temp.gamma1,2)+pow(ell_temp.alpha2,2)-1.0; ell_temp.beta2 =(-B+(int)pow(-1.0,(int)fmod(rand(),2.0)+1)*sqrt(pow(B,2)-4*A*C))/(2.0*A); ell_temp.gamma2 =-(ell_temp.beta1/ell_temp.gamma1)*ell_temp.beta2-(ell_temp.alpha1*ell_temp.alpha2/ell_temp.gamma1); sign=(ell_temp.alpha1*ell_temp.beta2)/fabs(ell_temp.alpha1*ell_temp.beta2); ell_temp.alpha3 =sign*sqrt(1-pow(ell_temp.alpha1,2)-pow(ell_temp.alpha2,2)); ell_temp.beta3 =-(ell_temp.alpha1*ell_temp.beta1+ell_temp.alpha2*ell_temp.beta2)/ell_temp.alpha3; ell_temp.gamma3 =-(ell_temp.alpha1*ell_temp.gamma1+ell_temp.alpha2*ell_temp.gamma2)/ell_temp.alpha3; ell_temp.a=(1+epsilon)*ell_temp.a; ell_temp.b=(1+epsilon)*ell_temp.b; ell_temp.c=(1+epsilon)*ell_temp.c; //--------------------------------------------------------------------------- //check this ellipse //--------------------------------------------------------------------------- //whether this ellipse intersect with other ellipses k1=(int)(sqrt(pow(ell_temp.a,2)+pow(ell_temp.b,2))/delt_h); K=4*(k1+1); sita=pi/(K/2.0); //(添加一段程序080414)考虑不与边界相交的情况 //for(int j=1;j<=K/2;j++) //{ // l1=(int)(sqrt(pow(ell_temp.a*sin(j*sita),2)+pow(ell_temp.b*sin(j*sita),2))/delt_h); // L=4*(l1+1); // phi=2*pi/L; // for(int m=1;m<=L;m++) // { // x=ell_temp.a*sin(j*sita)*cos(m*phi); // y=ell_temp.b*sin(j*sita)*sin(m*phi); // z=ell_temp.c*cos(j*sita); // x1=ell_temp.x+x*ell_temp.alpha1+y*ell_temp.alpha2+z*ell_temp.alpha3; // y1=ell_temp.y+x*ell_temp.beta1+y*ell_temp.beta2+z*ell_temp.beta3; // z1=ell_temp.z+x*ell_temp.gamma1+y*ell_temp.gamma2+z*ell_temp.gamma3; // x=x1; // y=y1; // z=z1; // if(x1<=space.x0+0.04||x1>=space.x-0.04||y1<=space.y0+0.04||y1>=space.y-0.04||z1<=space.z0+0.04||z1>=space.z-0.04) // { // times=times+1; // goto gen_again; // } // } //} for(int i=0; i<int(ellip.size()); i++) { //probably estimate d=sqrt(pow(ell_temp.x-ellip[i].x,2)+pow(ell_temp.y-ellip[i].y,2)+pow(ell_temp.z-ellip[i].z,2)); if(d>=ell_temp.a+ellip[i].a+2*epsi) { goto gene; } else if((d<ell_temp.b+ellip[i].b+2*epsi*(ellip[i].b/ellip[i].a))&&(d<ell_temp.c+ellip[i].c+2*epsi*(ellip[i].c/ellip[i].a))) { times=times+1; goto gen_again; } else { //exactly compute for(int j=1; j<=K/2; j++) { l1=(int)(sqrt(pow(ell_temp.a*sin(j*sita),2)+pow(ell_temp.b*sin(j*sita),2))/delt_h); L=4*(l1+1); phi=2*pi/L; for(int m=1; m<=L; m++) { x=ell_temp.a*sin(j*sita)*cos(m*phi); y=ell_temp.b*sin(j*sita)*sin(m*phi); z=ell_temp.c*cos(j*sita); x1=ell_temp.x+x*ell_temp.alpha1+y*ell_temp.alpha2+z*ell_temp.alpha3; y1=ell_temp.y+x*ell_temp.beta1+y*ell_temp.beta2+z*ell_temp.beta3; z1=ell_temp.z+x*ell_temp.gamma1+y*ell_temp.gamma2+z*ell_temp.gamma3; x=x1; y=y1; z=z1; x=x-ellip[i].x; y=y-ellip[i].y; z=z-ellip[i].z; x1=x*ellip[i].alpha1+y*ellip[i].beta1+z*ellip[i].gamma1; y1=x*ellip[i].alpha2+y*ellip[i].beta2+z*ellip[i].gamma2; z1=x*ellip[i].alpha3+y*ellip[i].beta3+z*ellip[i].gamma3; f=pow(x1,2)/pow(ellip[i].a,2)+pow(y1,2)/pow(ellip[i].b,2)+pow(z1,2)/pow(ellip[i].c,2)-1.0; if(f<0.0) { times=times+1; goto gen_again; } } } } gene: ; } //--------------------------------------------------------------------- //次数清零并插入椭球向量 times=0; ellip.push_back(ell_temp); //--------------------------------------------------------------------- //计算体积比 ellip_volume = ellip_volume + ellipse_volume(ell_temp,epsilon); ellip_ratio = ellip_volume/cell_volume; gen_again: ; } while(times<=N_times&&ellip_ratio<vol_ratio); //--------------------------------------------------------------------- //椭球收缩 for(int i=0; i<int(ellip.size()); i++) { ellip[i].a=ellip[i].a/(1+epsilon); ellip[i].b=ellip[i].b/(1+epsilon); ellip[i].c=ellip[i].c/(1+epsilon); } //--------------------------------------------------------------------- //画图 // if(mod!=0) draw_tecplot("generate_ellipse.dat",delt_h); //--------------------------------------------------------------------- //输出数据 if(mod!=0) output_EllipseData(output_file); //--------------------------------------------------------------------- //输入到样本数据文件 output_Datafile(data_file); }