// Reset the frame counter void RerecordingStop() { // Write the final time and Stop the timer ReRecTimer.Stop(); // Update status bar WriteStatus(); }
// Frame advance // --------------- void FrameAdvance() { // Update status bar WriteStatus(); // If a game is not started, return if (Core::GetState() == Core::CORE_UNINITIALIZED) return; // Play to the next frame if (g_FrameStep) { Run(); Core::SetState(Core::CORE_RUN); } }
// When a new frame is drawn void FrameUpdate() { // Write to the status bar WriteStatus(); /* I don't think the frequent update has any material speed inpact at all, but should it have you can controls the update speed by changing the "% 10" in this line */ //if (g_FrameCounter % 10 == 0) WriteStatus(); // Pause if frame stepping is on if(g_FrameStep) { Pause(); Core::SetState(Core::CORE_PAUSE); } // Count one frame g_FrameCounter++; }
//---------------------------------------------------------------------------- void TestTriTri::AdjustTriangle (int iXPos, int iYPos) { int i, iDx, iDy; if ( m_iTriangle == 0 ) { if ( m_iSelect == -1 ) { iDx = iXPos - m_iXMouseStart; iDy = iYPos - m_iYMouseStart; for (i = 0; i < 3; i++) { m_aiX0[i] += iDx; m_aiY0[i] += iDy; } } else { m_aiX0[m_iSelect] = iXPos; m_aiY0[m_iSelect] = iYPos; } } else if ( m_iTriangle == 1 ) { if ( m_iSelect == -1 ) { iDx = iXPos - m_iXMouseStart; iDy = iYPos - m_iYMouseStart; for (i = 0; i < 3; i++) { m_aiX1[i] += iDx; m_aiY1[i] += iDy; } } else { m_aiX1[m_iSelect] = iXPos; m_aiY1[m_iSelect] = iYPos; } } GetIntersecting(); WriteStatus(); }
// Turn on frame stepping void FrameStepOnOff() { /* Turn frame step on or off. If a game is running and we turn this on it means that the game will pause after the next frame update */ g_FrameStep = !g_FrameStep; // Update status bar WriteStatus(); // If a game is not started, return if(Core::GetState() == Core::CORE_UNINITIALIZED) return; // Run the emulation if we turned off framestepping if (!g_FrameStep) { Run(); Core::SetState(Core::CORE_RUN); } }
int main(int argc, char *argv[]){ # ifdef UNIX static char state[256]; initstate(1997,state,256); # else Exit_wait(1); # endif Set_comment_char(';'); StartTime(); char *cfgfile="Params.dta"; if(argc>1)cfgfile=argv[1]; int no_remove=1; if(argc>2)if(strstr(argv[2],"new"))no_remove=0; Open_param_file(cfgfile); int nions,i; Read_param("Number of ions: %d",&nions); Read_param("Ionisation degree: %d",&i); ion_charge=i; double imass=1.; Set_stop(0); if(Read_param("Ion mass: %lf",&imass)){ printf("Non-symmetric plasma specified!\n"); non_symm=1; } char tmpstr[256]; int sep_cm=0; if(Read_param("Center-of-mass for components: %s",tmpstr)){ if(strstr(tmpstr,"separate")){ printf("Plasma with separated center of masses specified!\n"); sep_cm=1; } } Plasma *TheGas; // allocation of the Gas double bdens, bTv; int bq; int bunch=Read_param("Bunch propagation: %lf, %lf, %d",&bdens,&bTv,&bq); if(bunch>0){ printf("Bunch in plasma specified!\n"); if(bunch!=3){ msg_error("Invalid bunch specification!\n"); exit(1); } bunch=1; bTv=sqrt(3*nions*i*bTv); // converting temperature to velocity TheGas=(Plasma *)new PlasmaBunch(bdens,bTv,bq,nions,i,imass); } else{ TheGas=new Plasma(nions,i,imass); bunch=0; } Plasma &Gas=*TheGas; Gas.non_symm=non_symm; Gas.one_center=1-sep_cm; char dataname[50]; Read_param("Data name: %s",dataname); strncpy(Gas.dataname,dataname,50); char ofile[256], pfile[256]="poten.dat"; strcat(strcpy(pfile,dataname),".pot"); Read_param("Output file: %s",ofile); if(strstr(ofile,"default")){ strcpy(ofile,dataname); strcat(ofile,".eq"); } Read_param("Log file: %s",logfile); if(strstr(logfile,"default")){ strcpy(logfile,dataname); strcat(logfile,".log"); } Parameter *p; int np=InitParameters(&p); double T,Gamma; potspec_t reader; reader.read_spec(cfgfile); Gas.potential=reader.potential; strncpy(Gas.charpot,reader.charpot,50); /* Read_param("Potential: %s",tmpstr); strncpy(Gas.charpot,tmpstr,50); if(strstr(tmpstr,"Kelbg"))Gas.potential=PotentialKELBG; else if(strstr(tmpstr,"Lennard-Johnes"))Gas.potential=PotentialJONES; else if(strstr(tmpstr,"Deutsch"))Gas.potential=PotentialDEUTSCH; else if(strstr(tmpstr,"Erf"))Gas.potential=PotentialERF; else if(strstr(tmpstr,"Cutoff")){ if(!strcmp(tmpstr,"Cutoff1")){ Gas.potential=PotentialCUT1; } else{ Gas.potential=PotentialCUT; Read_param("Cutoff value*: %lf",&E_cut); } } else if(strstr(tmpstr,"ln")){ Gas.potential=PotentialLN; Read_param("Cutoff value*: %lf",&E_cut); } else if(strstr(tmpstr,"table")){ Gas.potential=PotentialTAB; Read_param("Potential table file: %s",tmpstr); Close_param_file(); ReadPotential(tmpstr); Open_param_file(cfgfile); } else serror("Unknown potential type specified!\n"); Read_param("Pauli part: %s",tmpstr); if(strstr(tmpstr,"n"))Pauli_part=0; double Lambda, Lambda_set; Read_param("R0: %s",tmpstr); if(strstr(tmpstr,"default"))Lambda_set=0.; else Lambda_set=atof(tmpstr); double Clam_ep=1.,Clam_ee=1; Read_param("e-e R0 coefficient: %lf",&Clam_ee); Read_param("e-p R0 coefficient: %lf",&Clam_ep); */ int ask=0; Read_param("Dialog: %s",tmpstr); if(strstr(tmpstr,"y"))ask=1; auto_rf=0; Gf=10.; Read_param("Random force strength: %s",tmpstr); if(strstr(tmpstr,"auto"))auto_rf=1; else if(strstr(tmpstr,"fluct"))auto_rf=2; if(!sscanf(tmpstr,"%lf",&Gf) && auto_rf==0)serror("Can't read Random force strength\n"); Read_param("Scale velocities: %s",tmpstr); if(strstr(tmpstr,"y"))scale_vel=1; Read_param("Delta: %lf",&delta); Read_param("Trajectory write interval: %ld",&wr_int); if(wr_int<=0)wr_int=-1; int new_rec=0; long wr_ions=0, wr_enseq=-1; Set_stop(0); if(Read_param("Ions write interval: %ld",&wr_ions)){ new_rec=1; if(!Read_param("Electrons write sequence: %ld",&wr_enseq))wr_enseq=-1; } Set_stop(1); Read_param("Steps to check equillibrium: %ld",&chk_nsteps); Read_param("Steps with random force: %ld",&rf_nsteps); Read_param("Check steps with random force: %ld",&tst_nsteps); Read_param("Steps in equillibrium: %ld",&eq_nsteps); Read_param("Time step in equillibrium: %lf",&eq_dt); Read_param("Time step for random force: %lf",&rf_dt0); char trfile[256]="trajectory"; int wr_tr=0; Set_stop(0); /*int pot_corr=0; if(Read_param("Potential correction: %s",tmpstr)){ if(strstr(tmpstr,"y")){ pot_corr=1; strcat(Gas.charpot," corr."); } }*/ if(Read_param("Total energy stability: %lf",&stab_acc))e_stab=1; if(Read_param("Positive cutoff: %lf",&E_negcut))neg_cut=1; else neg_cut=0; if(!Read_param("Random generator *:>",tmpstr))strcpy(tmpstr,"3"); cList rndlist(tmpstr); int nrepeats=1; if(!Read_param("Repeats: %d",&nrepeats))nrepeats=1; char mdistrfile[256]="r-r.distrib"; double rr_r0=0., rr_r1=-1.; if(Read_param("Write r-r distribution: %s",tmpstr)){ if(strstr(tmpstr,"y")){ write_distr=1; if(!Read_param("r-r file: %s",mdistrfile)||strstr(mdistrfile,"default")){ strcpy(mdistrfile,"%s%d.rr"); } if(Read_param("r-r range: %lf, %lf",&rr_r0,&rr_r1)!=2){ rr_r0=0.; rr_r1=-1.; } } } if(Read_param("Soft step: %s",tmpstr)){ if(strstr(tmpstr,"n"))soft_step=0; } if(Read_param("Soft random force: %s",tmpstr)){ if(strstr(tmpstr,"y")){ rf_sw_off=1; Set_stop(1); Read_param("Switch off steps: %ld",&sw_nsteps); Set_stop(0); } else rf_sw_off=0; } if(Read_param("Relative step: %s",tmpstr)){ if(strstr(tmpstr,"y"))rel_step=1; } if(Read_param("Animation : %s",&tmpstr)){ if(strstr(tmpstr,"y")){ if(!Read_param("Film directory: %s",filmdir)||strstr(filmdir,"default")){ strcpy(filmdir,"film/"); } } } in_cs=-1.; Read_param("Initial cluster size: %lf",&in_cs); int restart=0,load_fried=0; int new_input=0; char inptrj[256]; if(Read_param("Restart: %s",tmpstr)){ if(strstr(tmpstr,"y")){ restart=1; if(Read_param("Load Friedemann: %s",tmpstr)){ if(strstr(tmpstr,"y"))load_fried=1; } if(Read_param("Input from: %s",inptrj))new_input=1; } } long wtype=0; if(Read_param("Trajectory file: %s",&trfile)){ if(strstr(trfile,"default"))strcpy(trfile,"%s%d.r"); Set_stop(1); wr_tr=1; Read_param("In output:>",tmpstr); if(strstr(tmpstr,"vel"))wtype|=VEL; if(strstr(tmpstr,"coord"))wtype|=COORD; if(strstr(tmpstr,"flow"))wtype|=FLOW; Set_stop(0); } else printf("Warning: no trajectory file\n"); int mc_one=0; int mc_diff=0; int auto_adjust=1; double mc_inistep; int no_equilibr=0; Set_stop(1); if(Read_param("Equilibration procedure: %s",tmpstr)){ if(strstr(tmpstr,"monte-carlo")){ Set_stop(1); mc_equil=1; Read_param("One particle MC-step: %s",tmpstr); if(strstr(tmpstr,"y")){ mc_one=1; // rf_dt0/=Gas.n; } Read_paramn(2,"MC step mode and value: %s %lf",tmpstr, &mc_inistep); if(strstr(tmpstr,"auto"))auto_adjust=1; else if(strstr(tmpstr,"stable"))auto_adjust=0; else serror("Unknown MC step mode.\n"); Set_stop(0); mc_diff=0; if(Read_param("MC different temperatures: %s",tmpstr)){ if(strstr(tmpstr,"y")){ if(mc_one)serror("Can use different MC temperatures\n" "only in MC one-particle mode!\n"); mc_diff=1; } } } else{ mc_equil=0; if(strstr(tmpstr,"off"))no_equilibr=1; else if(!strstr(tmpstr,"random-force")){ serror("Unknown equilibration procedure: %s\n",tmpstr); } } } Set_stop(0); mc_calc=0; if(Read_param("Equilibrium calculation: %s",tmpstr)){ if(strstr(tmpstr,"monte-carlo")){ Set_stop(1); mc_calc=1; Read_param("One particle MC-step: %s",tmpstr); if(strstr(tmpstr,"y")){ mc_one=1; // rf_dt0/=Gas.n; } Read_paramn(2,"MC step mode and value: %s %lf",tmpstr, &mc_inistep); if(strstr(tmpstr,"auto"))auto_adjust=1; else if(strstr(tmpstr,"stable"))auto_adjust=0; else serror("Unknown MC step mode.\n"); Set_stop(0); mc_diff=0; if(Read_param("MC different temperatures: %s",tmpstr)){ if(strstr(tmpstr,"y")){ if(mc_one)serror("Can use different MC temperatures\n" "only in MC one-particle mode!\n"); mc_diff=1; } } } } //# ifdef UNIX char out_dirs[250]="./",out_dirl[250]="./"; if(Read_param("Data output directory: %s",out_dirs)){ if(out_dirs[strlen(out_dirs)-1]!='/')strcat(out_dirs,"/"); sprintf(tmpstr,out_dirs,dataname); strcpy(out_dirs,tmpstr); # ifdef UNIX if(mkdir(out_dirs,S_IRWXU|S_IRGRP|S_IROTH)){ if(errno!=EEXIST)serror("Can not create directory: %s.\n%s\n", out_dirs,strerror(errno)); } sprintf(tmpstr,"cp %s %s%s.cfg",cfgfile,out_dirs,dataname); //strcat(strcat(tmpstr,dataname),".cfg"); if(system(tmpstr)==-1) printf("\nExec: %s\n",strerror(errno)); # else if(_mkdir(out_dirs)){ if(errno!=EEXIST)serror("Can not create directory: %s.\n%s\n", out_dirs,strerror(errno)); } char cfgfilef[_MAX_PATH], out_dirsf[_MAX_PATH]; _fullpath(cfgfilef, cfgfile, _MAX_PATH); _fullpath(out_dirsf, out_dirs, _MAX_PATH); sprintf(tmpstr,"copy %s %s%s.cfg",cfgfilef,out_dirsf,dataname); //strcat(strcat(tmpstr,dataname),".cfg"); if(system(tmpstr)==-1) printf("\nExec: %s\n",strerror(errno)); # endif strcpy(ofile,strcat(strcpy(tmpstr,out_dirs),ofile)); strcpy(mdistrfile,strcat(strcpy(tmpstr,out_dirs),mdistrfile)); strcpy(sfile,strcat(strcpy(tmpstr,out_dirs),sfile)); strcpy(pfile,strcat(strcpy(tmpstr,out_dirs),pfile)); if(wr_film){ strcpy(filmdir,strcat(strcpy(tmpstr,out_dirs),ofile)); # ifdef UNIX if(mkdir(filmdir,S_IRWXU|S_IRGRP|S_IROTH)){ # else if(_mkdir(filmdir)){ # endif if(errno!=EEXIST)serror("Can not create directory: %s.\n%s\n", filmdir,strerror(errno) ); } strcat(filmdir,dataname); } } if(Read_param("Process output directory: %s",out_dirl)){ if(out_dirl[strlen(out_dirl)]!='/')strcat(out_dirl,"/"); sprintf(tmpstr,out_dirl,dataname); strcpy(out_dirl,tmpstr); # ifdef UNIX if(mkdir(out_dirl,S_IRWXU|S_IRGRP|S_IROTH)){ # else if(_mkdir(out_dirl)){ # endif if(errno!=EEXIST)serror("Can not create directory: %s.\n%s\n", out_dirl,strerror(errno)); } strcpy(logfile,strcat(strcpy(tmpstr,out_dirl),logfile)); strcpy(trfile,strcat(strcpy(tmpstr,out_dirl),trfile)); } //# endif // UNIX int spwn_trj=0; if(Read_param("Spawn trajectories: %s",tmpstr)){ if(strstr(tmpstr,"y")){ spwn_trj=1; //Read_paramn(1,"Spawn frame: %d",&spwn_frame); no_test=1; // no RF test for equilibrartion } } Gas.stable_ions=0; if(Read_param("Stable ions: %s",tmpstr)){ if(strstr(tmpstr,"y")){ Gas.stable_ions=1; } } int repc_i=0; if(!Read_param("Repeat counter start: %d",&repc_i))repc_i=0; int irescale=0; if(Read_param("Ion velocity rescale: %s",tmpstr)){ if(strstr(tmpstr,"y"))irescale=1; if(strstr(tmpstr,"reset"))irescale=2; } /* int limrescale=0; if(Read_param("Rescale on electron temperature reached: %lf %ld",&limTe,&limstpe)==2){ limrescale=1; limspec=0x2; limrescale_switch(0); } */ int limrescale=0; int inc_mes=0; if(Read_param("Incremental measurement (T0,dT,mes_steps): %lf,%lf,%ld",&incT0,&incdT,&incStp)==3){ inc_mes=1; fixT=incT0; limstpe=1; limstpi=1; } Set_stop(1); Gas.ini_Te=Gas.ini_Ti=1.; // by default equal temperatures Read_param("Initial velocity distribution: %s",tmpstr); if(strstr(tmpstr,"maxwell"))in_distr=MAXWELL; else if(strstr(tmpstr,"max_polak"))in_distr=MAXWELL_P; else if(strstr(tmpstr,"zero")){ if(mc_equil){ in_distr=MAXWELL; printf("Warning: setting 'maxwell' initial vel. distribution for MC!\n"); } else in_distr=ZEROVEL; } else if(strstr(tmpstr,"separate")){ in_distr=SEPARATE; int &ndistr=Gas.idistr; int nr; char relstr[200]; for(i=0;i<2;i++){ if(i==0)nr= Read_param("Electron velocity distribution: %s %lf %s",tmpstr,&Gas.ini_Te,relstr); else{ nr= Read_param("Ion velocity distribution: %s %lf %s",tmpstr,&Gas.ini_Ti,relstr); Gas.edistr=ndistr; } if(nr<2){ serror("Can't read velocity distribution parameters!\n"); } if(nr>=2){ if(strstr(relstr,"abs")){ if(i==0)Gas.rel_Te=0; else Gas.rel_Ti=0; } } if(strstr(tmpstr,"maxwell"))ndistr=MAXWELL; else if(strstr(tmpstr,"max_polak"))ndistr=MAXWELL_P; else if(strstr(tmpstr,"zero"))ndistr=ZEROVEL; else { printf("Warning: unknown distribution '%s', setting to 'zero'\n",tmpstr); ndistr=ZEROVEL; } } } else{ printf("Warning: unknown distribution '%s', setting to 'zero'\n",tmpstr); in_distr=ZEROVEL; } Close_param_file(); Statistics sT(&Gas.T),sEcoul(&Gas.Ecoul),sEpotent(&Gas.Epotent),sQuant(&Gas.Quant), sEtot(&Gas.Etot); Statistics sTi(&Gas.Ti),sTe(&Gas.Te); const int nstat=7; Statistics *stats[nstat]={&sT,&sEcoul,&sEpotent,&sQuant,&sEtot,&sTi,&sTe}; SetTableform(GNU); if(no_remove){ no_remove=CheckData(sfile,ofile,dataname,np,p,ask); } if(restart && !wr_tr && !new_input)serror("No trajectory file specified, cannot restart.\n"); if(restart && new_input && wr_tr) if(!strcmp(trfile,inptrj)) serror("Equal names for input and output trj-files.\n"); FILE *f1; if(!no_remove || no_remove==2){ if(!no_remove)f1=Err_fopen(ofile,"wt"); else f1=Err_fopen(ofile,"at"); BeginFrame(f1,dataname,np,p); fprintf(f1,"%9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s %9.9s\n", "T","Ecoul","Epotent","Equant","dT","dEcoul","dEpotent","dEquant"); fclose(f1); } double t=0; f1=fopen(logfile,"rt"); if(f1){ if(!restart && !no_remove){ fclose(f1); remove(logfile); } else {// reading 'log' time fseek(f1,0,SEEK_END); long pos=ftell(f1)-4; do{ fseek(f1,pos,SEEK_SET); if(fgetc(f1)=='\n'){ fscanf(f1,"%lf",&t); //printf("new t: %f\n",t); break; } pos--; }while(pos>=0); fclose(f1); } } int ccount=CurrentCount(np,p); WriteStatus(!ccount,sfile,dataname,np,p); do{ //Gamma=get_pc(p[0]); //T=get_pc(p[1]); char ctrfile[256]; sprintf(ctrfile,trfile,dataname,ccount); char ss[100]; sprintf(ss,"%s%d",dataname,ccount); sprintf(distrfile,mdistrfile,dataname,ccount); // StatusLine(str,np,p); //show_status(440,str); long i,n,m,nf=0; //Gas.adjustTG(T,Gamma); AdjustGas(Gas,p,np); T=Gas.par_T; Gamma=Gas.par_Gamma; double me=0.9109534e-30; double qe=1.602e-19; double Kb=1.38e-23; double unit_t=qe*qe/(4*M_PI*8.854e-12)*sqrt(me); // overcoming g++ bug with -O3 double jojo=Kb*T*1.e4; //printf("c2: %e\n",jojo); jojo=jojo*jojo*jojo; jojo=sqrt(jojo); //printf("c21: %e\n",jojo); unit_t/=jojo; //printf("c3:\n"); double unit_h=Kb*T*1e4*unit_t; double h_qwer=1.0545887e-34; reader.calc_lambda(T,Gas.ini_Te,Gas.ini_Ti,Gas.mass); /* if(!non_symm){ if(Lambda_set!=0.0){ Lambda=Lambda_set/unit_l; equal_lambda=0; } else { Lambda=0.179*sqrt(T); equal_lambda=1; } Lambda_pauli=0.179*sqrt(T); //non_symm=0; Lambda_ee=Lambda_pp=Lambda*Clam_ee; if(fabs(Clam_ee-1.)>1e-5)equal_lambda=0; Lambda_ep=Lambda*Clam_ep; } else{ if(Lambda_set!=0.0){ serror("Can not setup lambda for nonsymmetric plasma.\n"); //Lambda=Lambda_set/unit_l; //Lambda_ep=Lambda*Clam_ep; //Lambda_ee=Lambda*Clam_ee; //equal_lambda=0; } else{ if(strstr(Gas.charpot,"Deutsch")){ printf("Setting lambda values for Deutsch potential !!!\n"); Lambda_pauli=h_qwer/(unit_h); Lambda=Lambda_pauli/sqrt(2*M_PI); double m_ee=0.5, m_pp=0.5*Gas.mass, m_ep=Gas.mass/(1.+Gas.mass); Lambda_ee=Lambda/sqrt(m_ee); Lambda_pp=Lambda/sqrt(m_pp); Lambda_ep=Lambda/sqrt(m_ep); } else { //if(strstr(Gas.charpot,"Kelbg")){ printf("Setting lambda values for Kelbg potential !!!\n"); Lambda_pauli=h_qwer/(unit_h); Lambda=Lambda_pauli; double m_ee=0.5, m_pp=0.5*Gas.mass, m_ep=Gas.mass/(1.+Gas.mass); double t_ep=Gas.ini_Te; double t_pp=Gas.ini_Ti; double t_ee=Gas.ini_Te; Lambda_ee=Lambda/sqrt(2*m_ee*t_ee); Lambda_pp=Lambda/sqrt(2*m_pp*t_pp); Lambda_ep=Lambda/sqrt(2*m_ep*t_ep); } } } */ if(rel_step)rf_dtcoeff=1./Gas.Wpe; double kk=(1.602e-19)*(1.602e-19)/(4*M_PI*1.38e-23*T*1e4*8.854e-12); printf("Simulation parameters:\n"); printf("Gamma =%f\n" "L=%f=%12e m\n" "lambda=%f=%12e m\n" "1/Wp=%f\n" "Rd=%f\n",Gamma,Gas.L, Gas.L*kk,reader.Lambda,reader.Lambda*kk,1./Gas.Wpe,RDebye); printf("Density = %1.2e cm^(-3)\n" "T= %f K\n",Gas.par_density*1e19,T*1e4); printf("Time step relations:\n"); printf("dtrf*Wp= %f, dteq*Wp= %f\n", (rel_step ? rf_dt0 : rf_dt0*Gas.Wpe), (rel_step ? eq_dt : eq_dt*Gas.Wpe)); double t_inter=RDebye/sqrt(2*getEmax(Gas)); printf("dtrf/tint= %f, dteq/tint= %f\n", rf_dt0*rf_dtcoeff/t_inter, eq_dt*rf_dtcoeff/t_inter); reader.calc_correction(Gas.par_T); reader.write_pot(pfile, Gas.L); /* //if(ccount==1)t/=Gas.Wpe; if(pot_corr){ //Correction(IONION,Gas.potential,Gas.par_T); Correction(IONELC,Gas.potential,Gas.par_T); Correction(ELCELC,Gas.potential,Gas.par_T); }*/ Statistics rs[nstat]; int repi=0; int repc=repc_i; do{ //through nrepeats printf("\nStarting calculation #%d...\n",repc); flm_count=0; if(repc>0){ repi++; sprintf(tmpstr,"%02d",repc); if(repi>1){ distrfile[strlen(distrfile)-2]=0; ctrfile[strlen(ctrfile)-2]=0; } strcat(distrfile,tmpstr); strcat(ctrfile,tmpstr); } if(write_distr){ DRRee.init(rr_r0,(rr_r1>0 ? rr_r1 : Gas.L/2),400); DRRep.init(rr_r0,(rr_r1>0 ? rr_r1 : Gas.L/2),400); if(non_symm)DRRpp.init(0,(rr_r1>0 ? rr_r1 : Gas.L/2),400); } long ftype=wtype; if(restart){ printf("restarting...\n"); if((mc_equil && spwn_trj) || mc_calc){ mc_equil=-1; MC = new mc_simm(Gas,mc_inistep*Gas.L /*Gas.L/Gas.n*/,0.5, mc_one,mc_diff); if(!MC)serror("Cannot allocate MCsimm\n"); MC->auto_adjust=auto_adjust; } else mc_equil=0; if(!new_input)strcpy(inptrj,ctrfile); if(load_fried){ LoadFriedemann(inptrj,Gas); Gas.dt=eq_dt; if(rel_step)Gas.dt/=Gas.Wpe; if(eq_nsteps<wr_int)eq_nsteps=wr_int; m=wr_int; n=eq_nsteps/m; Gas.ext_force=void_force1; wr_tr=0; ftype=0; } else{ Gas.dt=(rel_step ? eq_dt/Gas.Wpe : eq_dt); Trajectory.Check(inptrj,wtype,Gas,wr_int,wr_ions,wr_enseq,new_input); if(Trajectory.wtype !=0 && !new_input){ Gas.dt=Trajectory.AdjustInterval(Gas.dt); } long stp; if(!new_input){ stp=Trajectory.ReloadGas(Gas,1); t=stp*Trajectory.file_dt(); nf=(long)(t/Gas.dt/wr_int+0.01); } else{ stp=Trajectory.ReloadGas(Gas,0); t=0; nf=0; } printf("t= %f, nf= %ld, %f\n",t,nf,(t/Gas.dt/wr_int)); //serror("Restart is not yet implemented !\n"); Gas.ext_force=void_force1; } //restart=0; } else{ rand_init=rndlist.step(); if(rand_init<0){ rndlist.rewind(); rand_init=rndlist.step(); } strcat(distrfile,"e"); if((mc_equil && (!spwn_trj || (repc==repc_i && spwn_trj))) || mc_calc){ mc_equil=1; MC = new mc_simm(Gas,mc_inistep*Gas.L /*Gas.L/Gas.n*/,0.5, mc_one,mc_diff); if(!MC)serror("Cannot allocate MCsimm\n"); MC->auto_adjust=auto_adjust; } if(!no_equilibr){ if(!spwn_trj || (spwn_trj && repc==repc_i)){ limrescale_switch(0); Equillibrium(t,Gas,stats,nstat); limrescale_switch(limrescale); } } else{ Gas.r0=0.05; Gas.init_config(in_cs,in_distr); } distrfile[strlen(distrfile)-1]=0; // deleting 'e' if(mc_equil){ if(spwn_trj){ Gas.init_vel(in_distr); } else if(!mc_calc){ delete MC; mc_equil=-1; } else mc_equil=1; } Gas.dt=eq_dt; if(rel_step)Gas.dt/=Gas.Wpe; } if(irescale){ if(irescale==1)Gas.ivel_scale(1.); else Gas.init_vel(in_distr); } if(eq_nsteps<wr_int)eq_nsteps=wr_int; if(wr_int>0){ n=eq_nsteps/wr_int; m=wr_int; } else if(eq_nsteps>=500){ n=eq_nsteps/500; m=500; } else{ n=1; m=eq_nsteps; } if(wr_tr && (!restart || new_input || (restart && ftype==0))){ //WriteHeader(ctrfile,wtype,Gas,Gamma,T, ss,m); // initializing PlasmaRec Trajectory.Clear(); Trajectory.Init(ctrfile,wtype,Gas,wr_int,wr_ions,wr_enseq); } if(wr_tr && (restart && ftype==0)){ //WriteStep(ctrfile,wtype,Gas,0); } Statistics statsl[nstat]; Trajectory.valid=wr_tr; // new cycle if(bunch){ PlasmaBunch *pb=(PlasmaBunch *)&Gas; pb->start_bunch(); } for(i=nf;i<n;i++){ double term_c=1.; if(Gas.stable_ions)term_c=(double)Gas.ne/Gas.n; printf("Equilibrium calculation: %f%% complete, T= %f Et=%f\n",(i+1)*100./n,Gas.T,Gas.T*3/2*term_c+Gas.Epotent/Gas.n); if(StopStatus(sfile,3)){ StopStatus(sfile,-1); serror("Program interrupted!\n"); } if(mc_equil && spwn_trj){ mc_equil=1; double ratio=MC->get_ratio(); if(ratio<1e-10)printf("Estimated randomization steps: infinity\n"); else printf("Estimated randomization steps: %d\n",(int)(Gas.n*Gas.L/MC->dc[1]/ratio)); } MoveIt(t,m,m,Gas,stats,statsl,nstat); //if(wr_tr)WriteStep(ctrfile,wtype,Gas,i); if(write_distr)WriteDRR(distrfile); if(wr_film)WriteFilm(filmdir,Gas); } if(bunch){ PlasmaBunch *pb=(PlasmaBunch *)&Gas; pb->stop_bunch(); } if(write_distr)WriteDRR(distrfile); for(i=0;i<nstat;i++)rs[i]+=*(stats[i]); repc++; if(new_input)restart=0; }while(repc<nrepeats); if(spwn_trj)delete MC; f1=Err_fopen(ofile,"at"); MiddleFrame(f1,np,p); int gn=Gas.n; //fprintf(f1,"%9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f\n", // sT.av()*T,sEcoul.av()/gn,sEpotent.av()/gn,sQuant.av()/gn, // sT.dev()*T,sEcoul.dev()/gn,sEpotent.dev()/gn,sQuant.dev()/gn); fprintf(f1,"%9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f\n", rs[0].av()*T,rs[1].av()/gn,rs[2].av()/gn,rs[3].av()/gn, rs[0].dev()*T,rs[1].dev()/gn,rs[2].dev()/gn,rs[3].dev()/gn); fclose(f1); ccount=CycleCount(np,p); WriteStatus(!ccount,sfile,dataname,np,p); restart=0; repc=0; }while(ccount); return 0; }
//---------------------------------------------------------------------------- bool TestTriTri::OnInitialize () { WriteStatus(); return true; }
//---------------------------------------------------------------------------- bool TestTriTri::OnChar (char cCharCode, long) { switch ( cCharCode ) { // select next intersection type case 't': m_eType = Type((m_eType+1) % TT_MAX); GetIntersecting(); return true; // rotate velocity vector of active triangle case '+': case '=': if ( m_iTriangle == 0 ) m_uiAngle0 = (m_uiAngle0 + 1) % MAX_ANGLE; else if ( m_iTriangle == 1 ) m_uiAngle1 = (m_uiAngle1 + 1) % MAX_ANGLE; GetIntersecting(); WriteStatus(); return true; // rotate velocity vector of active triangle case '-': case '_': if ( m_iTriangle == 0 ) { if ( m_uiAngle0 > 0 ) m_uiAngle0--; else m_uiAngle0 = MAX_ANGLE - 1; } else if ( m_iTriangle == 1 ) { if ( m_uiAngle1 > 0 ) m_uiAngle1--; else m_uiAngle1 = MAX_ANGLE - 1; } GetIntersecting(); WriteStatus(); return true; // increase speed of active triangle case '>': case '.': if ( m_iTriangle == 0 ) { if ( m_uiSpeed0 < MAX_SPEED ) m_uiSpeed0++; } else if ( m_iTriangle == 1 ) { if ( m_uiSpeed1 < MAX_SPEED ) m_uiSpeed1++; } GetIntersecting(); WriteStatus(); return true; // decrease speed of active triangle case '<': case ',': if ( m_iTriangle == 0 ) { if ( m_uiSpeed0 > 0 ) m_uiSpeed0--; } else if ( m_iTriangle == 1 ) { if ( m_uiSpeed1 > 0 ) m_uiSpeed1--; } GetIntersecting(); WriteStatus(); return true; // exit program case 'q': case 'Q': case VK_ESCAPE: PostMessage(GetWindowHandle(),WM_DESTROY,0,0); return true; } return false; }