static int placesystems(void) { int i, j, k; /* looping vars */ double x=0, y=0; /* to hold star coordinates */ int done; /* flag to indicate done */ double dx, dy; /* delta x and y's */ int n; /* number of planet to place */ int np; /* number of planets in system */ int attempts; n = SYSTEMS; /* first planet to place */ for (i = 0; i < SYSTEMS; i++) { /* planets for each system */ np = SYSPLMIN + lrand48() % (SYSPLADD + 1); /* how many planets */ for (k = 0; k < np; k++) { /* go place the planets */ attempts = 0; do { /* do until location found */ attempts++; done = 0; /* not done yet */ dx = (drand48() * SYSWIDTH - SYSWIDTH / 2.0); dy = (drand48() * SYSWIDTH - SYSWIDTH / 2.0); if (dx * dx + dy * dy > (SYSWIDTH / 2.0) * (SYSWIDTH / 2.0)) continue; /* might orbit its way out of the galaxy */ x = planets[i].pl_x + dx; y = planets[i].pl_y + dy; if ((x > GW - SYSBORD) || (x < SYSBORD) || (y < SYSBORD) || (y > GW - SYSBORD)) continue; /* too close to border? */ done = 1; /* assume valid coord found */ for (j = 0; j < n; j++) { /* go through previous planets */ dx = fabs(x - (double) planets[j].pl_x); dy = fabs(y - (double) planets[j].pl_y); if (dx * dx + dy * dy < SYSMIN2) { /* if too close to another star */ done = 0; /* we must get another coord */ } if( ihypot( (int)dx, (int)dy) < 3000 ) done = 0; } } while (!done && attempts < 200); /* do until location found */ if (!done) return 0; /* universe too crowded, try again */ move_planet(n, (int) x, (int) y, 0); planets[n].pl_system = i + 1; /* mark the sytem number */ planets[n].pl_armies = MINARMY + lrand48() % (MAXARMY - MINARMY); n++; /* go to next planet */ } } return (n); /* return index of next planet */ }
static int placeindep(int n) /* number of planet to start with */ { int i, j; /* looping vars */ double x, y; /* to hold star coordinates */ int done; /* flag to indicate done */ double dx, dy; /* delta x and y's */ int attempts; for (i = n; i < (NUMPLANETS - (WORMPAIRS*2)); i++) { /* go through rest of planets */ x = drand48() * (GW - 2 * INDBORD) + INDBORD; /* pick initial coords */ y = drand48() * (GW - 2 * INDBORD) + INDBORD; attempts = 0; do { /* do until location found */ attempts++; done = 0; /* not done yet */ x = INDBORD + fmod(x + (3574.0 - INDBORD), GW - 2 * INDBORD); /* offset coords a little */ y = INDBORD + fmod(y + (1034.0 - INDBORD), GW - 2 * INDBORD); /* every loop */ done = 1; /* assume valid coord */ for (j = 0; j < n; j++) { /* go through previous planets */ dx = fabs(x - (double) planets[j].pl_x); dy = fabs(y - (double) planets[j].pl_y); if (dx * dx + dy * dy < SYSMIN2) { /* if planet to close */ done = 0; /* we must get another coord */ } } } while (!done && attempts < 200); /* do until location found */ if (!done) return 0; move_planet(n, (int) x, (int) y, 0); planets[n].pl_system = 0; /* mark the no sytem */ planets[n].pl_armies = MINARMY + lrand48() % (MAXARMY - MINARMY); n++; /* go to next planet */ } for (i = n; i < NUMPLANETS; i++) /* now place wormholes */ { x = drand48() * GW; /* pick intial coords */ y = drand48() * GW; attempts = 0; do { /* do until location found */ attempts++; done = 0; /* not done yet */ x = fmod(x + 3574.0, GW); /* offset coords a little */ y = fmod(y + 1034.0, GW); /* every loop */ done = 1; /* assume valid coord */ for (j = 0; j < n; j++) { /* go through previous planets */ dx = fabs(x - (double) planets[j].pl_x); dy = fabs(y - (double) planets[j].pl_y); if (dx * dx + dy * dy < SYSMIN2) { /* if planet to close */ done = 0; /* we must get another coord */ } } } while (!done && attempts < 200); /* do until location found */ if (!done) return 0; move_planet(n, (int) x, (int) y, 0); planets[n].pl_system = 0; /* mark the no system */ planets[n].pl_flags |= PLWHOLE; /* mark the planet as a wormhole */ /* the armies in a wormhole is the other wormhole's x coord */ /* the radius is the other wormhole's y coord*/ if (NUMPLANETS%2) { if (!(n%2)) { planets[n].pl_armies = planets[n-1].pl_x; planets[n].pl_radius = planets[n-1].pl_y; planets[n-1].pl_armies = planets[n].pl_x; planets[n-1].pl_radius = planets[n].pl_y; } } else { if (n%2) { planets[n].pl_armies = planets[n-1].pl_x; planets[n].pl_radius = planets[n-1].pl_y; planets[n-1].pl_armies = planets[n].pl_x; planets[n-1].pl_radius = planets[n].pl_y; } } planets[i].pl_owner = NOBODY; /* no team owns a star */ planets[i].pl_hinfo = ALLTEAM; /* all teams know its a star */ for (j = 0; j < MAXTEAM + 1; j++) { /* go put in info for teams */ planets[i].pl_tinfo[j].owner = NOBODY; /* nobody owns it */ planets[i].pl_tinfo[j].armies = 0; planets[i].pl_tinfo[j].flags = planets[i].pl_flags; } n++; /* go to next planet */ } return 1; }
int main(int argc, char *argv[]) { int j; int n; int status; char directory[256],outputdir[256]; if (argc > 4) { printf("Too many arguments.Only using first 3.\n"); } n = atoi(argv[1]); time_step = atof(argv[2]); strcpy(directory,argv[3]); nb = 2; sprintf(outputdir,"%stemp_files/",directory); status = mkdir(outputdir,S_IRWXU | S_IRWXG | S_IRWXO); if (status == -33) { printf("Status is -33 for some reason.\n"); } //sprintf(param_fname,"%sparam_file.txt",directory); read_param_file(directory); nx = params.nx; ny = params.ny; nz = params.nz; CFL = params.cfl; IndirectTerm = params.indirect; size_x = nx; size_y = ny+2*NGHY; size_z = nz; stride = size_x*size_y; pitch = size_x; pitch2d = 0; //size_t double_to_int = sizeof(double)/sizeof(int); pitch2d_int = 0 ;//pitch*(int)double_to_int; dx = 2*M_PI/nx; if (size_x % 2 == 0) NEVEN = TRUE; else NEVEN = FALSE; num_threads = 1; #ifdef _OPENMP //omp_set_num_threads(8); num_threads = omp_get_max_threads(); printf("Using %d threads\n",num_threads); #endif allocate_all(); #ifdef _FFTW allocate_conv(); #endif read_domain(directory); read_files(n,directory); //read_single_file(n,1,directory); /* if (cfl_dt < dt) { printf("Using cfl limited timestep of %.4e instead of %.4e\n",cfl_dt,dt); dt = cfl_dt; } */ //move_to_com(); read_stockholm(directory); /* for(j=0;j<size_y;j++) { dens0[j] = params.mdot/(3*M_PI*Nu(ymed(j))); vy0[j] = -1.5*Nu(ymin(j))/ymin(j); vx0[j] = pow(ymed(j),-.5); vx0[j] *= sqrt(1.0+pow(params.h,2)*pow(ymed(j),2*params.flaringindex)* (2.0*params.flaringindex - 1.5)); vx0[j] -= omf*ymed(j); } */ omf0 = omf; output_stock(outputdir); output_init(outputdir); init_rk5(); nsteps = 0; double tstart = psys[0].t; double tend = psys[0].t + time_step; double time = tstart; #ifdef _FFTW printf("Using FFTW to compute fourier transforms\n"); #endif #ifdef ARTIFICIALVISCOSITY printf("Using ARTIFICIAL VISCOSITY\n"); #endif #ifdef FARGO printf("Using FARGO TRANSPORT\n"); #endif #ifdef STOCKHOLMACC printf("Damping to current average in stockholm boundaries.\n"); #endif #ifdef NOWAVEKILLRHO printf("Not damping the density.\n"); #endif #ifdef FIXEDPSYS printf("Planetary system is FIXED.\n"); #endif printf("Starting time = %.3f\nEnding time = %.3f\n",tstart,tend); set_bc(); set_dtLt(-1.0); while ((time < tend) && nsteps<MAXSTEPS) { #ifdef FARGO compute_vmed(vx); #endif dt = cfl(); if (dt <= MINDT) { printf("Timestep has fallen below minimum!\n"); break; } if (time + dt > tend) { dt = tend-time; } printf("\r t=%.3f, dt = %.8f, %02d%% complete...",time,dt,(int)(100*(time-tstart)/(tend-tstart))); fflush(stdout); set_avg(0); potential(); #ifndef FIXEDPSYS move_planet(); #endif source_step(); set_Lamex(); viscosity(); #ifdef ARTIFICIALVISCOSITY artificial_visc(); #endif temp_to_vel(); set_bc(); vel_to_temp(); #ifdef FARGO compute_vmed(vx_temp); #endif transport_step(); time += dt; set_avg(1); set_Lamdep(); set_bc(); stockholm(); //output_psys(outputdir,nsteps); nsteps++; } // temp_to_vel(); set_dtLt(1.0); dt = tend - tstart; for(j=0;j<size_y;j++) { dbart[j]/=dt; //Lt[j]/=dt; //Lt[j+size_y]/=dt; //Ld[j]/=dt; //Ld[j+size_y]/=dt; //Lw[j]/=dt; //Lw[j+size_y]/=dt; Lw[j] = Lt[j] - Ld[j]; Lw[j+size_y] = Lt[j+size_y] - Ld[j+size_y]; drFt[j]/=dt; drFd[j]/=dt; drFdB[j]/=dt; mdotl[j]/=dt; drFnu[j]/=dt; drFw[j]/=dt; drFwB[j]/=dt; Lamex[j]/=dt; //Lamex[j+size_y]/=dt; Lamdep[j]/=dt; LamdepB[j]/=dt; dtLt[j]/=dt; dtLd[j]/=dt; dtLw[j]/=dt; dtLd_rhs[j]/=dt; mdotavg[j] /= dt; LamdepS[j + size_y*0] /= dt; LamdepS[j + size_y*1] /= dt; LamdepS[j + size_y*2] /= dt; LamdepS[j + size_y*3] /= dt; LamdepS[j + size_y*4] /= dt; LamdepS[j + size_y*5] /= dt; LamdepS[j + size_y*6] /= dt; } int mi; for(mi=1;mi<MMAX+2;mi++) { for(j=0;j<size_y;j++) { Lamex[j + size_y*mi] /= dt; drFd[j + size_y*mi] /= dt; dtLt[j + size_y*mi] /= dt; } } output(outputdir); output_torque(directory,n); output_torque(outputdir,n); free_rk5(); #ifdef _FFTW free_conv(); #endif //free_all(); return 0; }