void load_halos(char *filename, float scale) { FILE *input; char buffer[1024]; struct min_halo halo = {0}; float max_d = 0; float delta_mvir = delta_vir(scale); float mean_density = 2.77519737e11*Om; //(Msun/h) / (comoving Mpc/h)^3 float vir_density = delta_mvir*mean_density; int n, i; if (!(input = fopen(filename, "r"))) { printf("Couldn't open file %s!\n", filename); exit(2); } for (i=0; i<3; i++) halo.a[i] = 0; while (fgets(buffer, 1024, input)) { if (buffer[0] == '#') continue; n = sscanf(buffer, "%d %d %f %f %f %f %f %d %f %f %f %f %f %f %d", &(halo.id), &(halo.descendant), &(halo.mvir), &(halo.vmax), &(halo.vrms), &(halo.rvir), &(halo.rs), &(halo.np), &(halo.pos[0]), &(halo.pos[1]), &(halo.pos[2]), &(halo.vel[0]), &(halo.vel[1]), &(halo.vel[2]), &(halo.phantom_id)); if (n < 14) continue; if (n < 15) halo.phantom_id = 0; halo.mvir = fabs(halo.mvir); if (!(halo.mvir > 0)) continue; if (!(halo.rvir > 0)) halo.rvir = cbrt(halo.mvir / (4.0*M_PI*vir_density/3.0)) * 1000.0; if (!(halo.rs > 0)) halo.rs = halo.rvir / concentration(halo.mvir, scale); //Halo mvir is assumed to be in Msun/h //Note that mvir doesn't actually *have* to be the virial mass--- //it just has to be the mass contained within whatever rvir is. halo.mass_factor = calculate_mass_factor(halo.mvir /h0, halo.rvir, halo.rs); halo.rs /= 1000.0; //Convert kpc/h to Mpc/h if (!(num_halos % 1000)) { halos = (struct min_halo *) realloc(halos, sizeof(struct min_halo)*(num_halos+1000)); if (!halos) { printf("Out of memory trying to load halos!\n"); exit(1); } } halos[num_halos] = halo; num_halos++; if (max_mvir < halo.mvir) max_mvir = halo.mvir; for (i=0; i<3; i++) if (max_d < halo.pos[i]) max_d = halo.pos[i]; } fclose(input); box_size = (int)(max_d + 0.5); //In Mpc/h comoving coordinates. max_mvir /= h0; //Now in Msun }
doublereal SurfPhase::entropy_mole() const { _updateThermo(); doublereal s = 0.0; for (size_t k = 0; k < m_kk; k++) { s += moleFraction(k) * (m_s0[k] - GasConstant * log(std::max(concentration(k) * size(k)/m_n0, SmallNumber))); } return s; }
//*****************************************************************************// void phi_solver(){ laplacian(phi_old, lap_phi); laplacian(mu_old, lap_mu); concentration(); #ifdef ISO isotropic_solverloop(); #endif #ifdef ANISO anisotropic_solverloop(); #endif phi_boundary(phi_new); phi_boundary(mu_new); phi_update(); }
int main(int argc, char *argv[]){ MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&numtasks); numworkers = numtasks - 1; MPI_Comm_rank(MPI_COMM_WORLD,&taskid); if(taskid == MASTER){ // This code fragment runs in the master porcesses // clock_t start_t, end_t, total_t; allocate_memory(); phi_initialize(); fluid_initialize(); gs_allocate(); // start_t = clock(); // printf("Starting of the program, start_t = %ld\n", start_t); for ( t = 0; t < phi_timesteps; t++ ) { #ifdef growth neuman_boundary(phi_old, MESHX); neuman_boundary(mu_old, MESHX); concentration(phi_old, mu_old, conc, MESHX); neuman_boundary(conc, MESHX); laplacian(phi_old, lap_phi, MESHX); laplacian(mu_old, lap_mu, MESHX); anisotropic_solverloop(); update(phi_old, phi_new, MESHX); update(mu_old, mu_new, MESHX); if((t%save_phi) == 0) { write2file_phi(t, MESHX,phi_old); } #endif #ifdef FLUID if (t>SMOOTH) { fluid_solver(); if((t%save_fluid) ==0) { write2file_fluid (t,u_old,v_old,MESHX); } } #endif printf("t=%d\n",t); } free_memory(); // end_t = clock(); // printf("End of the big loop, end_t = %ld\n", end_t); // total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC; // printf("Total time taken by CPU: %f\n", total_t ); printf("Exiting of the program...\n"); } else { // This code fragment runs in the worker processes gs_allocate(); for ( t = 0; t < phi_timesteps; t++ ) { if ( t > SMOOTH ) { gs_mpi(); } } free(P); free(rhs_fn); free(a_x); free(a_y); } MPI_Finalize(); return(0); }