int main(int argc,char **argv) { KD kd; SMX smx; int nBucket,nSmooth,i,j; FILE *fp; float fPeriod[3]; float period; nBucket = 16; nSmooth = 24; if ( argc < 4 || argc > 5 ) { fprintf(stderr,"USAGE: smooth PMcrd.DAT PMcrs.DAT [stars.dat] rho_smooth.den\n"); exit(1); } kdInit(&kd,nBucket); /* read in here */ if ( argc == 4 ) { kdReadART(kd,argv[1],argv[2],&period); } else { kdReadARTStars(kd,argv[1],argv[2],argv[3],&period); } fPeriod[0] = period; fPeriod[1] = period; fPeriod[2] = period; printf("bulding tree...\n"); kdBuildTree(kd); printf("initializing density...\n"); smInit(&smx,kd,nSmooth,fPeriod); printf("smoothing density...\n"); smSmooth(smx,smDensitySym); printf("ordering tree...\n"); kdOrder(kd); printf("writing output...\n"); /* write density file */ if ( argc == 4 ) { fp = fopen(argv[3], "w" ); } else { fp = fopen(argv[4],"wb"); } assert(fp != NULL); smOutDensityBin(smx,fp); fclose(fp); smFinish(smx); kdFinish(kd); return 0; }
/*==========================================================================*/ PyObject *nn_start(PyObject *self, PyObject *args) { KD kd; SMX smx; PyObject *kdobj; /* Nx1 Numpy arrays for smoothing length and density for calls that pass in those values from existing arrays */ PyObject *smooth = NULL, *rho=NULL, *mass=NULL; int nSmooth, nProcs; long i; float hsm; float period = BIGFLOAT; PyArg_ParseTuple(args, "Oi|f", &kdobj, &nSmooth, &period); kd = (KD)PyCapsule_GetPointer(kdobj, NULL); if(period<=0) period = BIGFLOAT; float fPeriod[3] = {period, period, period}; if(nSmooth>PyArray_DIM(kd->pNumpyPos,0)) { PyErr_SetString(PyExc_ValueError, "Number of smoothing particles exceeds number of particles in tree"); return NULL; } /* ** Check to make sure that the bounds of the simulation agree ** with the period specified, if not cause an error. */ if(!smCheckFits(kd, fPeriod)) { PyErr_SetString(PyExc_ValueError, "The particles span a region larger than the specified boxsize"); return NULL; } if(!smInit(&smx, kd, nSmooth, fPeriod)) { PyErr_SetString(PyExc_RuntimeError, "Unable to create smoothing context"); return NULL; } smSmoothInitStep(smx, nProcs); return PyCapsule_New(smx, NULL, NULL); }
int main(int argc, char * argv[]) { smInit(); return 0; }
void calc_dudt() { struct gas_particle *gp ; KD kd; int n_smooth = 64; float period[MAXDIM]; int i; double rsys, vsys; if (boxlist[0].ngas != header.nsph) { printf("<Warning, box 0 does not contain all particles, %s>\n", title); printf("<Reloading box 0, %s>\n", title); loadall(); } if (!dkernel_loaded){ dkernel_load() ; } if (!redshift_loaded){ load_redshift() ; } if (!cool_loaded ){ load_cool() ; } if (!visc_loaded) { load_visc(); } if (!divv_loaded) { divv(); } if (!meanmwt_loaded) { meanmwt_func() ; } rsys = kpcunit/1.e3 ; vsys = sqrt(msolunit/kpcunit*(GCGS*MSOLG/KPCCM))/1.e5 ; hsys = rsys*hubble_constant/vsys; if (dudt != NULL){ free(dudt); } if (boxlist[0].ngas != 0) { dudt = (double *)malloc(boxlist[0].ngas *sizeof(*dudt)); if (dudt == NULL) { printf("<sorry, no memory for hsmdivv, %s>\n",title) ; return ; } } else dudt = NULL; if (box0_smx) { kdFinish(box0_smx->kd); smFinish(box0_smx); box0_smx = NULL; } printf("<Building tree, %s>\n", title); kdInit(&kd); kdReadBox(kd, &boxlist[0], 0, 1, 0); kdBuildTree(kd); if (periodic) period[0] = period[1] = period[2] = period_size; else period[0] = period[1] = period[2] = 1e37; printf("<Calculating dudt, %s>\n", title); smInit(&box0_smx,kd,n_smooth,period); smSetBallh(box0_smx); smReSmooth(box0_smx,smDudtSym); kdOrder(kd); for(i = 0; i < boxlist[0].ngas; i++) { gp = boxlist[0].gp[i]; dudt[i] = 0.5 * kd->p[i].fDensity; } dudt_loaded = YES ; starform_loaded = NO ; }
int main(void) { float x = 119, y = 79; unsigned char Input; Model * m; unsigned char Rocks = 0; float scale; ctorAllocator( ModelAllocator, ModelAllocator->Pool ); ctorAllocator( CommandAllocator, CommandAllocator->Pool ); //ctorAllocator( DLL_Allocator, DLL_Allocator->Pool ); //ctorDL_List( &ObjectList, DLL_Allocator, ObjectFree ); m = Copy( &mdlShip ); m->Position.x = 119; m->Position.y = 79; Bullet0.m = Copy( &mdlTriangle ); Bullet0.m->Position.x = 500; Bullet0.m->Position.y = 500; Rock0.m = Copy( &mdlRockA ); Rock1.m = Copy( &mdlRockB ); Rock2.m = Copy( &mdlRockC ); Rock0.InUse = 0; Rock1.InUse = 0; Rock2.InUse = 0; smInit(); InitializeNESController(); //init_adc(); for(;;) { smFlip(); Input = ReadNESController(); m->Angle %= 360; if( m->Angle < 0 ) m->Angle += 360; if( Input & nesLeft ) --m->Angle; if( Input & nesRight ) ++m->Angle; if( Input & nesStart ) { m->Position.x = 119; m->Position.y = 79; m->Momentum = 0; m->Angle = 0; } /* if( Input & nesLeft && m->Angle != 270 ) if( m->Angle < 90 || m->Angle > 270 ) --m->Angle; else ++m->Angle; if( Input & nesRight && m->Angle != 90 ) if( m->Angle < 90 || m->Angle >= 270 ) ++m->Angle; else --m->Angle; if( Input & nesUp && m->Angle != 0 ) if( m->Angle < 180 ) --m->Angle; else ++m->Angle; if( Input & nesDown && m->Angle != 180 ) if( m->Angle < 180 ) ++m->Angle; else --m->Angle; */ //if( !(rand() % 5) ) ++Rock0.DrawAngle; //if( !(rand() % 5) ) ++Rock1.DrawAngle; //if( !(rand() % 5) ) ++Rock2.DrawAngle; Bullet0.DrawAngle += 10; if( rand() % 90 == 25 ) { if( !Rock2.InUse ) { Rock2.InUse = 1; Rock2.m->Position.x = rand() % 240; Rock2.m->Position.y = rand() % 160; Rock2.m->Scale = 0.5F + 1.0F / (rand() % 100 + 1); Rock2.m->Angle = rand() % 360; Rock2.m->Momentum = rand() % 200; } else if( !Rock0.InUse ) { Rock0.InUse = 1; Rock0.m->Position.x = rand() % 240; Rock0.m->Position.y = rand() % 160; Rock0.m->Scale = 0.5F + 1.0F / (rand() % 100 + 1); Rock0.m->Angle = rand() % 360; Rock0.m->Momentum = rand() % 200; } else if( !Rock1.InUse ) { Rock1.InUse = 1; Rock1.m->Position.x = rand() % 240; Rock1.m->Position.y = rand() % 160; Rock1.m->Scale = 0.5F + 1.0F / (rand() % 100 + 1); Rock1.m->Angle = rand() % 360; Rock1.m->Momentum = rand() % 200; } } if( Rock0.InUse ) DemiDraw( &Rock0 ); if( Rock1.InUse ) DemiDraw( &Rock1 ); if( Rock2.InUse ) DemiDraw( &Rock2 ); if( Input & nesA && (m->Momentum < 1000) ) m->Momentum += 10; if( Input & nesDown && (m->Momentum > -1000) ) m->Momentum -= 10; if( Input & nesB && !Bullet0.InUse ) { Bullet0.m->Position.x = m->Position.x + (m->Radius - 27) * Sine(m->Angle); Bullet0.m->Position.y = m->Position.y - (m->Radius - 27) * Cosine(m->Angle); Bullet0.m->Momentum = 500 + m->Momentum; Bullet0.m->Angle = m->Angle; Bullet0.InUse = 1; } if( m->Momentum != 0 ) { if( m->Momentum < 0 ) m->Momentum += 2; else m->Momentum -= 2; } m->Position.x += m->Momentum * .0025 * Sine(m->Angle); m->Position.y += m->Momentum * .0025 * -Cosine(m->Angle); /* if( m->Position.x < 0 ) m->Position.x = 239; if( m->Position.x > 239 ) m->Position.x = 0; if( m->Position.y < 0 ) m->Position.y = 159; if( m->Position.y > 159 ) m->Position.y = 0; */ Bullet0.m->Position.x += Bullet0.m->Momentum * .0025 * Sine(Bullet0.m->Angle); Bullet0.m->Position.y += Bullet0.m->Momentum * .0025 * -Cosine(Bullet0.m->Angle); if( Bullet0.m->Momentum != 0 ) { if( Bullet0.m->Momentum < 0 ) Bullet0.m->Momentum += 2; else Bullet0.m->Momentum -= 2; } else Bullet0.InUse = 0; Rock0.m->Position.x += Rock0.m->Momentum * .0025 * Sine(Rock0.m->Angle); Rock0.m->Position.y += Rock0.m->Momentum * .0025 * -Cosine(Rock0.m->Angle); Rock1.m->Position.x += Rock1.m->Momentum * .0025 * Sine(Rock1.m->Angle); Rock1.m->Position.y += Rock1.m->Momentum * .0025 * -Cosine(Rock1.m->Angle); Rock2.m->Position.x += Rock2.m->Momentum * .0025 * Sine(Rock2.m->Angle); Rock2.m->Position.y += Rock2.m->Momentum * .0025 * -Cosine(Rock2.m->Angle); smColor( smBlue ); Draw( m ); if( Bullet0.InUse ) DemiDraw( &Bullet0 ); if( Rock0.InUse && Bullet0.InUse ) { scale = Rock0.m->Radius * Rock0.m->Scale; if( Bullet0.m->Position.x >= Rock0.m->Position.x - scale && Bullet0.m->Position.x <= Rock0.m->Position.x + scale && Bullet0.m->Position.y >= Rock0.m->Position.y - scale && Bullet0.m->Position.y <= Rock0.m->Position.y + scale ) { Bullet0.InUse = 0; Rock0.InUse = 0; } } if( Rock1.InUse && Bullet0.InUse ) { scale = Rock1.m->Radius * Rock1.m->Scale; if( Bullet0.m->Position.x >= Rock1.m->Position.x - scale && Bullet0.m->Position.x <= Rock1.m->Position.x + scale && Bullet0.m->Position.y >= Rock1.m->Position.y - scale && Bullet0.m->Position.y <= Rock1.m->Position.y + scale ) { Bullet0.InUse = 0; Rock1.InUse = 0; } } if( Rock2.InUse && Bullet0.InUse ) { scale = Rock2.m->Radius * Rock2.m->Scale; if( Bullet0.m->Position.x >= Rock2.m->Position.x - scale && Bullet0.m->Position.x <= Rock2.m->Position.x + scale && Bullet0.m->Position.y >= Rock2.m->Position.y - scale && Bullet0.m->Position.y <= Rock2.m->Position.y + scale ) { Bullet0.InUse = 0; Rock2.InUse = 0; } } smWaitForFrame(); } return 0; }