/* Converts the std_pts to x^5 + y^5 */ void std2penta(const struct std *s, struct penta *p) { int i; p->total = 0; for (i=0; i < s->total; i++) { p->x5[i] = pow5(s->x[i]) + pow5(s->y[i]); p->x[i] = s->x[i]; p->color[i] = s->color[i]; p->total++; } }
int main() { unsigned long long i=2; unsigned long long somme = 0; for(i=2;i<10000000;i++) if(pow5(i/10000000)+pow5((i%10000000)/1000000)+pow5((i%1000000)/100000)+pow5((i%100000)/10000)+pow5((i%10000)/1000)+pow5((i%1000)/100)+pow5((i%100)/10)+pow5(i%10) == i) { printf("%lld\n",i); somme += i; } printf("\033[1mResultat : %lld\033[0m\n", somme); return 0; }
void Foam::equationReader::evalScalarFieldPow5 ( const equationReader * eqnReader, const label index, const label i, const label storageOffset, label& storeIndex, scalarField& x, const scalarField& source ) const { pow5(x, x); }
void Foam::equationReader::evalDimsPow5 ( const equationReader * eqnReader, const label index, const label i, const label storageOffset, label& storeIndex, dimensionSet& xDims, dimensionSet sourceDims ) const { xDims.reset(pow5(xDims)); }
OSStatus TestNote::Render(UInt64 inAbsoluteSampleFrame, UInt32 inNumFrames, AudioBufferList** inBufferList, UInt32 inOutBusCount) { float *left, *right; /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Changes to this parameter (kGlobalVolumeParam) are not being de-zippered; Left as an exercise for the reader ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */ float globalVol = GetGlobalParameter(kGlobalVolumeParam); // TestNote only writes into the first bus regardless of what is handed to us. const int bus0 = 0; int numChans = inBufferList[bus0]->mNumberBuffers; if (numChans > 2) return -1; left = (float*)inBufferList[bus0]->mBuffers[0].mData; right = numChans == 2 ? (float*)inBufferList[bus0]->mBuffers[1].mData : 0; double sampleRate = SampleRate(); double freq = Frequency() * (twopi/sampleRate); #if DEBUG_PRINT_RENDER printf("TestNote::Render %p %d %g %g\n", this, GetState(), phase, amp); #endif switch (GetState()) { case kNoteState_Attacked : case kNoteState_Sostenutoed : case kNoteState_ReleasedButSostenutoed : case kNoteState_ReleasedButSustained : { for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp < maxamp) amp += up_slope; float out = pow5(sin(phase)) * amp * globalVol; phase += freq; if (phase > twopi) phase -= twopi; left[frame] += out; if (right) right[frame] += out; } } break; case kNoteState_Released : { UInt32 endFrame = 0xFFFFFFFF; for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp > 0.0) amp += dn_slope; else if (endFrame == 0xFFFFFFFF) endFrame = frame; float out = pow5(sin(phase)) * amp * globalVol; phase += freq; left[frame] += out; if (right) right[frame] += out; } if (endFrame != 0xFFFFFFFF) { #if DEBUG_PRINT printf("TestNote::NoteEnded %p %d %g %g\n", this, GetState(), phase, amp); #endif NoteEnded(endFrame); } } break; case kNoteState_FastReleased : { UInt32 endFrame = 0xFFFFFFFF; for (UInt32 frame=0; frame<inNumFrames; ++frame) { if (amp > 0.0) amp += fast_dn_slope; else if (endFrame == 0xFFFFFFFF) endFrame = frame; float out = pow5(sin(phase)) * amp * globalVol; phase += freq; left[frame] += out; if (right) right[frame] += out; } if (endFrame != 0xFFFFFFFF) { #if DEBUG_PRINT printf("TestNote::NoteEnded %p %d %g %g\n", this, GetState(), phase, amp); #endif NoteEnded(endFrame); } } break; default : break; } return noErr; }
static void fill_table(t_tabledata *td,int tp,const t_forcerec *fr) { /* Fill the table according to the formulas in the manual. * In principle, we only need the potential and the second * derivative, but then we would have to do lots of calculations * in the inner loop. By precalculating some terms (see manual) * we get better eventual performance, despite a larger table. * * Since some of these higher-order terms are very small, * we always use double precision to calculate them here, in order * to avoid unnecessary loss of precision. */ #ifdef DEBUG_SWITCH FILE *fp; #endif int i; double reppow,p; double r1,rc,r12,r13; double r,r2,r6,rc6; double expr,Vtab,Ftab; /* Parameters for David's function */ double A=0,B=0,C=0,A_3=0,B_4=0; /* Parameters for the switching function */ double ksw,swi,swi1; /* Temporary parameters */ gmx_bool bSwitch,bShift; double ewc=fr->ewaldcoeff; double isp= 0.564189583547756; bSwitch = ((tp == etabLJ6Switch) || (tp == etabLJ12Switch) || (tp == etabCOULSwitch) || (tp == etabEwaldSwitch) || (tp == etabEwaldUserSwitch)); bShift = ((tp == etabLJ6Shift) || (tp == etabLJ12Shift) || (tp == etabShift)); reppow = fr->reppow; if (tprops[tp].bCoulomb) { r1 = fr->rcoulomb_switch; rc = fr->rcoulomb; } else { r1 = fr->rvdw_switch; rc = fr->rvdw; } if (bSwitch) ksw = 1.0/(pow5(rc-r1)); else ksw = 0.0; if (bShift) { if (tp == etabShift) p = 1; else if (tp == etabLJ6Shift) p = 6; else p = reppow; A = p * ((p+1)*r1-(p+4)*rc)/(pow(rc,p+2)*pow2(rc-r1)); B = -p * ((p+1)*r1-(p+3)*rc)/(pow(rc,p+2)*pow3(rc-r1)); C = 1.0/pow(rc,p)-A/3.0*pow3(rc-r1)-B/4.0*pow4(rc-r1); if (tp == etabLJ6Shift) { A=-A; B=-B; C=-C; } A_3=A/3.0; B_4=B/4.0; } if (debug) { fprintf(debug,"Setting up tables\n"); fflush(debug); } #ifdef DEBUG_SWITCH fp=xvgropen("switch.xvg","switch","r","s"); #endif for(i=td->nx0; (i<td->nx); i++) { r = td->x[i]; r2 = r*r; r6 = 1.0/(r2*r2*r2); if (gmx_within_tol(reppow,12.0,10*GMX_DOUBLE_EPS)) { r12 = r6*r6; } else { r12 = pow(r,-reppow); } Vtab = 0.0; Ftab = 0.0; if (bSwitch) { /* swi is function, swi1 1st derivative and swi2 2nd derivative */ /* The switch function is 1 for r<r1, 0 for r>rc, and smooth for * r1<=r<=rc. The 1st and 2nd derivatives are both zero at * r1 and rc. * ksw is just the constant 1/(rc-r1)^5, to save some calculations... */ if(r<=r1) { swi = 1.0; swi1 = 0.0; } else if (r>=rc) { swi = 0.0; swi1 = 0.0; } else { swi = 1 - 10*pow3(r-r1)*ksw*pow2(rc-r1) + 15*pow4(r-r1)*ksw*(rc-r1) - 6*pow5(r-r1)*ksw; swi1 = -30*pow2(r-r1)*ksw*pow2(rc-r1) + 60*pow3(r-r1)*ksw*(rc-r1) - 30*pow4(r-r1)*ksw; } } else { /* not really needed, but avoids compiler warnings... */ swi = 1.0; swi1 = 0.0; } #ifdef DEBUG_SWITCH fprintf(fp,"%10g %10g %10g %10g\n",r,swi,swi1,swi2); #endif rc6 = rc*rc*rc; rc6 = 1.0/(rc6*rc6); switch (tp) { case etabLJ6: /* Dispersion */ Vtab = -r6; Ftab = 6.0*Vtab/r; break; case etabLJ6Switch: case etabLJ6Shift: /* Dispersion */ if (r < rc) { Vtab = -r6; Ftab = 6.0*Vtab/r; } break; case etabLJ12: /* Repulsion */ Vtab = r12; Ftab = reppow*Vtab/r; break; case etabLJ12Switch: case etabLJ12Shift: /* Repulsion */ if (r < rc) { Vtab = r12; Ftab = reppow*Vtab/r; } break; case etabLJ6Encad: if(r < rc) { Vtab = -(r6-6.0*(rc-r)*rc6/rc-rc6); Ftab = -(6.0*r6/r-6.0*rc6/rc); } else { /* r>rc */ Vtab = 0; Ftab = 0; } break; case etabLJ12Encad: if(r < rc) { Vtab = r12-12.0*(rc-r)*rc6*rc6/rc-1.0*rc6*rc6; Ftab = 12.0*r12/r-12.0*rc6*rc6/rc; } else { /* r>rc */ Vtab = 0; Ftab = 0; } break; case etabCOUL: Vtab = 1.0/r; Ftab = 1.0/r2; break; case etabCOULSwitch: case etabShift: if (r < rc) { Vtab = 1.0/r; Ftab = 1.0/r2; } break; case etabEwald: case etabEwaldSwitch: Vtab = gmx_erfc(ewc*r)/r; Ftab = gmx_erfc(ewc*r)/r2+2*exp(-(ewc*ewc*r2))*ewc*isp/r; break; case etabEwaldUser: case etabEwaldUserSwitch: /* Only calculate minus the reciprocal space contribution */ Vtab = -gmx_erf(ewc*r)/r; Ftab = -gmx_erf(ewc*r)/r2+2*exp(-(ewc*ewc*r2))*ewc*isp/r; break; case etabRF: case etabRF_ZERO: Vtab = 1.0/r + fr->k_rf*r2 - fr->c_rf; Ftab = 1.0/r2 - 2*fr->k_rf*r; if (tp == etabRF_ZERO && r >= rc) { Vtab = 0; Ftab = 0; } break; case etabEXPMIN: expr = exp(-r); Vtab = expr; Ftab = expr; break; case etabCOULEncad: if(r < rc) { Vtab = 1.0/r-(rc-r)/(rc*rc)-1.0/rc; Ftab = 1.0/r2-1.0/(rc*rc); } else { /* r>rc */ Vtab = 0; Ftab = 0; } break; default: gmx_fatal(FARGS,"Table type %d not implemented yet. (%s,%d)", tp,__FILE__,__LINE__); } if (bShift) { /* Normal coulomb with cut-off correction for potential */ if (r < rc) { Vtab -= C; /* If in Shifting range add something to it */ if (r > r1) { r12 = (r-r1)*(r-r1); r13 = (r-r1)*r12; Vtab += - A_3*r13 - B_4*r12*r12; Ftab += A*r12 + B*r13; } } } if (ETAB_USER(tp)) { Vtab += td->v[i]; Ftab += td->f[i]; } if ((r > r1) && bSwitch) { Ftab = Ftab*swi - Vtab*swi1; Vtab = Vtab*swi; } /* Convert to single precision when we store to mem */ td->v[i] = Vtab; td->f[i] = Ftab; } /* Continue the table linearly from nx0 to 0. * These values are only required for energy minimization with overlap or TPI. */ for(i=td->nx0-1; i>=0; i--) { td->v[i] = td->v[i+1] + td->f[i+1]*(td->x[i+1] - td->x[i]); td->f[i] = td->f[i+1]; } #ifdef DEBUG_SWITCH gmx_fio_fclose(fp); #endif }
/* times the time to execute the queries on the two tables */ int time_query(MYSQL *dbase, int64 start, int64 end) { struct timeval tv1, tv2; double t; int r; int64 starty, start5, endy, end5; MYSQL_RES *result; /* the query for the gen table must use group by * on the other hand all queries on penta must give * results that are already free of duplicates. * So in order to emphasize the duplicate removal, * the queries will span the entire range */ printf("Asking for all colors for x between %lld and %lld\n", start, end); /*** Do for the gen table ***/ gettimeofday(&tv1, NULL); r = dbquery(dbase, "SELECT color FROM gen WHERE " "x>= %lld AND x< %lld GROUP BY color", start, end); if (r<0) { printf("Query on gen table failed\n"); return -1; } result = mysql_store_result(dbase); //printres(result); mysql_free_result(result); gettimeofday(&tv2, NULL); t = (tv2.tv_sec - tv1.tv_sec) + (double) (tv2.tv_usec - tv1.tv_usec) / 1000000; printf("Time taken to QUERY gen table: %lf sec\n", t); /*** Do for the std table ***/ gettimeofday(&tv1, NULL); /* (l,r) -> [l,r] x [-oo, l] * in our case, -oo is really GROUND */ starty = GROUND; endy = start; r = dbquery(dbase, "SELECT color FROM std WHERE " "y>=%lld AND y<%lld AND " "x>=%lld AND x<%lld", starty, endy, start, end); if (r<0) { printf("Query on std table failed\n"); return -1; } result = mysql_store_result(dbase); //printres(result); mysql_free_result(result); gettimeofday(&tv2, NULL); t = (tv2.tv_sec - tv1.tv_sec) + (double) (tv2.tv_usec - tv1.tv_usec) / 1000000; printf("Time taken to QUERY std table: %lf sec\n", t); /*** Do for the penta table ***/ gettimeofday(&tv1, NULL); /* (l,r) -> [l,r] x [-oo, l] -> (l^5+ -oo^5, l^5 + r^5) * in our case, -oo is really GROUND */ start5 = pow5(start) + pow5(starty); end5 = pow5(end) + pow5(endy); r = dbquery(dbase, "SELECT color FROM penta WHERE x5>=%lld AND x5<%lld", start5, end5); if (r<0) { printf("Query on penta table failed\n"); return -1; } result = mysql_store_result(dbase); //printres(result); mysql_free_result(result); gettimeofday(&tv2, NULL); t = (tv2.tv_sec - tv1.tv_sec) + (double) (tv2.tv_usec - tv1.tv_usec) / 1000000; printf("Time taken to QUERY penta table: %lf sec\n", t); return 1; }
void brownianForce::setForce() const { // get viscosity field #ifdef comp const volScalarField nufField = particleCloud_.turbulence().mu() / rho_; #else const volScalarField& nufField = particleCloud_.turbulence().nu(); #endif vector force(0,0,0); scalar dp=0; scalar alpha=0; scalar Cc = 0; scalar rhoRatio=0; scalar S0=0; scalar rho_p=0; scalar mass=0; scalar Diff_k=0; //scalar eta=0; //const scalar sqrt2 = 1.414213562;//sqrt(2.0); //const scalar sigma = physicoChemical::sigma.value(); const scalar Tc = temperature_; const scalar kb=1.38e-23; scalar f = 0.0; for(int index = 0;index < particleCloud_.numberOfParticles(); ++index) { label cellI = particleCloud_.cellIDs()[index][0]; force=vector::zero; if (cellI > -1) // particle Found { dp = particleCloud_.d(index); mass=particleCloud_.mass(index); rho_p=mass/(0.523598776*pow3(dp)); //M_PI/6=0.523598776 alpha = 2.0*lambda_/dp; Cc = 1.0 + alpha*(1.257 + 0.4*exp(-1.1/alpha)); //const scalar eta = rndGen_.sample01<scalar>(); //random number [0;1] //const scalar eta = uniform(); rhoRatio = rho_p/rho_[cellI]; scalar muc = nufField[cellI]*rho_[cellI]; S0 = 216*muc*kb*Tc/(9.869604401*pow5(dp)*sqr(rhoRatio)*Cc); //9.869604401=sqr(M_PI) f = sqrt(M_PI*S0/dt_); for(int j=0;j<3;j++) { //const scalar x = rndGen_.sample01<scalar>(); //const scalar x = (scalar)random()/INT_MAX; //const scalar eta = sqrt2*erfInv(2*x - 1.0); //const scalar eta = gaussian(); //Info<<"++++++"<<eta<<endl; //value.Su()[i] = mass*f*eta; DEMForces()[index][j] += mass*f*gaussian(); } if(verbose_ && index >=0 && index <1) { Diff_k=(kb*Tc*Cc)/(2*M_PI*muc*dp); Pout << " "<< endl; Pout << "Brownian force verbose: " << endl; Pout << "index = " << index << endl; Pout << "cellI = " << cellI << endl; Pout << "dt = " << dt_ << endl; Pout << "muf = " << muc << endl; Pout << "nuf = " << nufField[cellI] << endl; Pout << "dp = " << dp << endl; Pout << "mass = " << mass << endl; Pout << "rhop = " << rho_p << endl; Pout << "phof = " << rho_[cellI] << endl; Pout << "rhoRatio = " << rhoRatio << endl; //Pout << "sigma = " << sigma << endl; Pout << "kb = " << kb << endl; Pout << "Tf = " << Tc << endl; Pout << "lambda = " << lambda_ << endl; Pout << "Diff_k = " << Diff_k << endl; Pout << "Cc = " << Cc << endl; Pout << "Force = (" << DEMForces()[index][0]<<" "<<DEMForces()[index][1]<<" "<<DEMForces()[index][2]<<")"<< endl; //TODO TRY to display forces like below //Pout << "UTurb = " << particleCloud_.fluidTurbVel(index)<< endl; /*Pout << "Fx = " << DEMForces()[index][0] << endl; Pout << "Fy = " << DEMForces()[index][1] << endl; Pout << "Fz = " << DEMForces()[index][2] << endl;*/ Pout << " "<< endl; } /* if(twoDimensional_) { force = M_PI*pow(radius,2)*part_density_*g_.value(); } else { force = 1.333*part_density_*M_PI*pow(radius,3)*g_.value(); }*/ } } }
void Result::showResultWin(int score){ int left = -320; int right = 320; int top = 240; int bot = -240; char strbuffer[64]; // W Point pow1(left+60,top-80); Point pow2(left+140+5,bot+220); Point pow3(left+180+5,bot+300); Point pow4(left+220+5,bot+220); Point pow5(left+300+10,top-80); Point pow6(left+260+5,top-80); Point pow7(left+220+5,top-160); Point pow8(left+180+5,top-80); Point pow9(left+140+5,top-160); Point pow10(left+100+5,top-80); Point powc((pow1.x+pow5.x)/2,(pow1.y+pow2.y)/2); vector<Point> pow; pow.push_back(pow1); pow.push_back(pow2); pow.push_back(pow3); pow.push_back(pow4); pow.push_back(pow5); pow.push_back(pow6); pow.push_back(pow7); pow.push_back(pow8); pow.push_back(pow9); pow.push_back(pow10); if (firsttime){ pol_w.setCorner(pow); pol_w.setCenter(powc); Transform scale = createScale(0.1, 0.1); pol_w.applyTransform(scale); } // I Point poi1(left+340,top-80); Point poi2(left+340,bot+220); Point poi3(left+390,bot+220); Point poi4(left+390,top-80); Point poic((poi1.x+poi3.x)/2,(poi1.y+poi3.y)/2); vector<Point> poi; poi.push_back(poi1); poi.push_back(poi2); poi.push_back(poi3); poi.push_back(poi4); if (firsttime){ pol_i.setCorner(poi); pol_i.setCenter(poic); Transform scale = createScale(0.1, 0.1); pol_i.applyTransform(scale); } // N Point pon1(left+420,top-80); Point pon2(left+420,bot+220); Point pon3(left+470,bot+220); Point pon4(left+470,top-170); Point pon5(left+530,bot+220); Point pon6(left+580,bot+220); Point pon7(left+580,top-80); Point pon8(left+530,top-80); Point pon9(left+530,bot+310); Point pon10(left+470,top-80); Point ponc((pon1.x+pon6.x)/2,(pon1.y+pon6.y)/2); vector<Point> pon; pon.push_back(pon1); pon.push_back(pon2); pon.push_back(pon3); pon.push_back(pon4); pon.push_back(pon5); pon.push_back(pon6); pon.push_back(pon7); pon.push_back(pon8); pon.push_back(pon9); pon.push_back(pon10); if (firsttime){ pol_n.setCorner(pon); pol_n.setCenter(ponc); Transform scale = createScale(0.1, 0.1); pol_n.applyTransform(scale); } // Other Point pot1(left+60, top-40); Point pot2(right-60, top-40); Point pot3(right-60, top-60); Point pot4(left+60, top-60); Point potc((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2); vector<Point> pot; pot.push_back(pot1); pot.push_back(pot2); pot.push_back(pot3); pot.push_back(pot4); if (firsttime){ pol_pot1.setCorner(pot); pol_pot1.setCenter(potc); Transform scale = createScale(0.1, 0.1); pol_pot1.applyTransform(scale); } pot1.set(left+60, bot+180); pot2.set(right-60, bot+180); pot3.set(right-60, bot+200); pot4.set(left+60, bot+200); potc.set((pot1.x+pot2.x)/2,(pot2.x+pot3.x)/2); pot.clear(); pot.push_back(pot1); pot.push_back(pot2); pot.push_back(pot3); pot.push_back(pot4); if (firsttime){ pol_pot2.setCorner(pot); pol_pot2.setCenter(potc); Transform scale = createScale(0.1, 0.1); pol_pot2.applyTransform(scale); } resultframe++; if (resultframe >= 25) resultframe = 25; else { Transform scale = createScale(1.1, 1.1); pol_pot1.applyTransform(scale); pol_pot2.applyTransform(scale); pol_w.applyTransform(scale); pol_i.applyTransform(scale); pol_n.applyTransform(scale); } pol_w.draw(WHITE); fill_polygon(pol_w[0].x, pol_w[3].y, pol_w[4].x, pol_w[0].y,WHITE,WHITE); pol_i.draw(WHITE); fill_polygon(pol_i[0].x, pol_i[2].y, pol_i[2].x, pol_i[0].y,WHITE,WHITE); pol_n.draw(WHITE); fill_polygon(pol_n[0].x, pol_n[5].y, pol_n[5].x, pol_n[0].y,WHITE,WHITE); pol_pot1.draw(WHITE); pol_pot2.draw(WHITE); settextstyle(7,0,40); setcolor(WHITE); sprintf(strbuffer,"%d",score); outtextxy(getmaxx()/2-50, getmaxy()/2+100, strbuffer); firsttime = false; }