int EnvelopeFreeEdit::getpointx(int n) const { const int lx=w()-10; int npoints=Penvpoints; float sum=0; for(int i=1; i<npoints; ++i) sum+=getdt(i)+1; float sumbefore=0;//the sum of all points before the computed point for(int i=1; i<=n; ++i) sumbefore+=getdt(i)+1; return (int) (sumbefore/(float) sum*lx); }
/*--------------------------------------------------- * The main loop for the simulation * ------------------------------------------------*/ void jobbody() { int j, ik, iv, nc, ns, iStep; double dtc; void RKtvd3(int ik, double dt); void gettherm(int nc, double **q, double **qs, double *p, double *t, double *gam1, double *rgas1, double *cv1); void gettrans(int nc, double **qs, double *t, double *gam1, double *cv1, double *mu, double *cond, double **diff); double getdt(int step); void saveData(int step); void saveDataT(double time); FILE *outId, *fp; outId = fopen("outInfo.dat", "a"); fp = fopen("evoData.dat", "w"); Ttot = config2.t0; nc = config1.Nc; gettherm(nc, U.q, U.qs, U.pre, U.tem, U.gam, U.rg, U.cv); gettrans(nc, U.qs, U.tem, U.gam, U.cv, U.mu, U.kt, U.di); config1.SamplesT = 1; for(iStep = config1.iStep0; iStep <= config1.nStep; iStep++) { /* 1. Preserve the last time step solution */ for(j = 0; j<nc; j++) { for(iv = 0; iv<neqv; iv++) qo[j][iv] = U.q[j][iv]; if(config1.gasModel != 0) for(ns = 0; ns<config1.nspec; ns++) qso[j][ns] = U.qs[j][ns]; } /* 2. Calculate time step */ dtc = getdt(iStep); /* 3. Rung-kutta iteration */ for(ik = 0; ik < timeOrder; ik++) { RKtvd3(ik, dtc); gettherm(nc, U.q, U.qs, U.pre, U.tem, U.gam, U.rg, U.cv); gettrans(nc, U.qs, U.tem, U.gam, U.cv, U.mu, U.kt, U.di); } /* 4. Output result */ Ttot = Ttot + dtc*tref; //Ttot = Ttot + dtc; if(iStep % 50 == 0) printf("iStep: %d / total: %d\n", iStep, config1.nStep); if(iStep % config1.Samples == 0) { fprintf(outId, "istep = %d, flow_time = %e s. \n", iStep, Ttot); saveData(iStep); } if(iStep % config1.SamplesT == 0) { saveDataT(Ttot); } } printf("simulation complete! \n"); fprintf(outId,"\n nStep = %d\n", config1.nStep); fprintf(outId," Actual flow time = %e \n", Ttot); fclose(outId); fclose(fp); }
void EnvelopeFreeEdit::draw(void) { int ox=x(),oy=y(),lx=w(),ly=h(); //if (env->Pfreemode==0) // env->converttofree(); const int npoints=Penvpoints; if (active_r()) fl_color(FL_BLACK); else fl_color(90,90,90); if (!active_r()) currentpoint=-1; fl_rectf(ox,oy,lx,ly); //Margins ox+=5;oy+=5;lx-=10;ly-=10; //draw the lines fl_color(FL_GRAY); fl_line_style(FL_SOLID); fl_line(ox+2,oy+ly/2,ox+lx-2,oy+ly/2); //draws the evelope points and lines Fl_Color alb=FL_WHITE; if (!active_r()) alb=fl_rgb_color(180,180,180); fl_color(alb); int oldxx=0,xx=0,oldyy=0,yy=getpointy(0); fl_rectf(ox-3,oy+yy-3,6,6); for (int i=1; i<npoints; ++i){ oldxx=xx;oldyy=yy; xx=getpointx(i);yy=getpointy(i); if (i==currentpoint || (ctrldown && i==lastpoint)) fl_color(FL_RED); else fl_color(alb); fl_line(ox+oldxx,oy+oldyy,ox+xx,oy+yy); fl_rectf(ox+xx-3,oy+yy-3,6,6); } //draw the last moved point point (if exists) if (lastpoint>=0){ fl_color(FL_CYAN); fl_rectf(ox+getpointx(lastpoint)-5,oy+getpointy(lastpoint)-5,10,10); } //draw the sustain position if(Penvsustain>0){ fl_color(FL_YELLOW); xx=getpointx(Penvsustain); fl_line(ox+xx,oy+0,ox+xx,oy+ly); } //Show the envelope duration and the current line duration fl_font(FL_HELVETICA|FL_BOLD,10); float time=0.0; if (currentpoint<=0 && (!ctrldown||lastpoint <= 0)){ fl_color(alb); for(int i=1; i<npoints; ++i) time+=getdt(i); } else { fl_color(FL_RED); time=getdt(lastpoint); } char tmpstr[20]; if (time<1000.0) snprintf((char *)&tmpstr,20,"%.1fms",time); else snprintf((char *)&tmpstr,20,"%.2fs",time/1000.0); fl_draw(tmpstr,ox+lx-20,oy+ly-10,20,10,FL_ALIGN_RIGHT,NULL,0); if (lastpoint>=0){ snprintf((char *)&tmpstr,20,"%d", Penvval[lastpoint]); fl_draw(tmpstr,ox+lx-20,oy+ly-23,20,10,FL_ALIGN_RIGHT,NULL,0); } }