Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    SDF *sdfp1 = NULL;
    SDF *sdfp2 = NULL;
    FILE *fp = NULL;
    fpos_t pos_npart;

    initargs(argc, argv, &sdfp1, &sdfp2, &fp);

    writeinit(fp);
    writescalars(sdfp1, fp, &pos_npart);/*writes the header for the scalars (non-structs)*/
    writestructs(sdfp1, sdfp2, fp, pos_npart);

    fclose(fp);
    SDFclose(sdfp1);
    SDFclose(sdfp2);

    return 0;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    SDF *sdfp = NULL;
    FILE *fp = NULL;

    initargs(argc, argv, &sdfp, &fp);

    writeinit(fp);
    writescalars(sdfp, fp);
    writestructs(sdfp, fp);

    fclose(fp);
    SDFclose(sdfp);

    return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv[])
{
	if(argc < 2)
	{
		usage();
		return 0;
	}
	
	int i,j,k,id;    

    double cc = 2.99792e10;
	double cc2 = cc*cc;
    
	time_in_s				= 1;
	dist_in_cm				= 6.955e7;
	mass_in_g				= 1.989e27;
    mass_in_msol            = mass_in_g/1.99e33;
	dens_in_gccm			= mass_in_g/dist_in_cm/dist_in_cm/dist_in_cm;
    energy_in_erg			= mass_in_g*dist_in_cm*dist_in_cm/time_in_s/time_in_s;
    specenergy_in_ergperg	= energy_in_erg/mass_in_g;
    pressure_in_ergperccm	= energy_in_erg/dist_in_cm/dist_in_cm/dist_in_cm;
    
    double **ptcls;
    
    SDF *sdfp;
	SPHbody *body;

		
	sdfp = SDFreadf(argv[1], (void **)&body, &gnobj, &nobj, sizeof(SPHbody),
					"x", offsetof(SPHbody, x), &conf,
					"y", offsetof(SPHbody, y), &conf,
					"z", offsetof(SPHbody, z), &conf,
					"mass", offsetof(SPHbody, mass), &conf,
					"vx", offsetof(SPHbody, vx), &conf,
					"vy", offsetof(SPHbody, vy), &conf,
					"vz", offsetof(SPHbody, vz), &conf,
					"u", offsetof(SPHbody, u), &conf,
					"h", offsetof(SPHbody, h), &conf,
					"rho", offsetof(SPHbody, rho), &conf,
					"pr", offsetof(SPHbody, pr), &conf,
					"drho_dt", offsetof(SPHbody, drho_dt), &conf,
					"udot", offsetof(SPHbody, udot), &conf,
					"temp", offsetof(SPHbody, temp), &conf,
					"He4", offsetof(SPHbody, He4), &conf,
					"C12", offsetof(SPHbody, C12), &conf,
					"O16", offsetof(SPHbody, O16), &conf,
					"Ne20", offsetof(SPHbody, Ne20), &conf,
					"Mg24", offsetof(SPHbody, Mg24), &conf,
					"Si28", offsetof(SPHbody, Si28), &conf,
					"S32", offsetof(SPHbody, S32), &conf,
					"Ar36", offsetof(SPHbody, Ar36), &conf,
					"Ca40", offsetof(SPHbody, Ca40), &conf,
					"Ti44", offsetof(SPHbody, Ti44), &conf,
					"Cr48", offsetof(SPHbody, Cr48), &conf,
					"Fe52", offsetof(SPHbody, Fe52), &conf,
					"Ni56", offsetof(SPHbody, Ni56), &conf,
					"abar", offsetof(SPHbody, abar), &conf,
					"zbar", offsetof(SPHbody, zbar), &conf,
					"ax", offsetof(SPHbody, ax), &conf,
					"ay", offsetof(SPHbody, ay), &conf,
					"az", offsetof(SPHbody, az), &conf,
					"lax", offsetof(SPHbody, lax), &conf,
					"lay", offsetof(SPHbody, lay), &conf,
					"laz", offsetof(SPHbody, laz), &conf,
//					"gax", offsetof(SPHbody, gax), &conf,
//					"gay", offsetof(SPHbody, gay), &conf,
//					"gaz", offsetof(SPHbody, gaz), &conf,
//					"grav_mass", offsetof(SPHbody, grav_mass), &conf,
					"phi", offsetof(SPHbody, phi), &conf,
//					"tacc", offsetof(SPHbody, tacc), &conf,
					"idt", offsetof(SPHbody, idt), &conf,
					"nbrs", offsetof(SPHbody, nbrs), &conf,
					"ident", offsetof(SPHbody, ident), &conf,
					"windid", offsetof(SPHbody, windid), &conf,
					NULL);
	SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
    SDFgetfloatOrDefault(sdfp, "dt",  &dt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "eps",  &eps, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "Gnewt",  &Gnewt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tolerance",  &tolerance, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "frac_tolerance",  &frac_tolerance, (float)0.0);
	//SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tvel",  &tvel, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "gamma",  &gam, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "ke",  &ke, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "pe",  &pe, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "te",  &te, (float)0.0);
	
	singlPrintf("%s has %d particles.\n", argv[1], gnobj);
    
    for(i=0;i<nobj;i++)
    {
        kin = 0;
        pot = fabs(body[i].phi*body[i].mass*energy_in_erg);
		kin += pow(body[i].vx,2.0);
		kin += pow(body[i].vy,2.0);
		kin += pow(body[i].vz,2.0);
		kin = kin*0.5*body[i].mass*energy_in_erg;
		
		if(kin>pot) mass += body[i].mass*mass_in_g;
    }

	printf("%3.3e g is unbound.\n",mass);
    
	free(body);
    SDFclose(sdfp);
	
	return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv[])
{
	if(argc < 2)
	{
		usage();
		return 0;
	}
	
	int i,j,k,id;    

    double cc = 2.99792e10;
	double cc2 = cc*cc;
    
	time_in_s				= 1;
	dist_in_cm				= 6.955e7;
	mass_in_g				= 1.989e27;
    mass_in_msol            = mass_in_g/1.99e33;
	dens_in_gccm			= mass_in_g/dist_in_cm/dist_in_cm/dist_in_cm;
    energy_in_erg			= mass_in_g*dist_in_cm*dist_in_cm/time_in_s/time_in_s;
    specenergy_in_ergperg	= energy_in_erg/mass_in_g;
    pressure_in_ergperccm	= energy_in_erg/dist_in_cm/dist_in_cm/dist_in_cm;
    
    double **ptcls;
    
    SDF *sdfp;
	SPHbody *body;
    Darkbody *nbody = malloc(sizeof(Darkbody)*1);;

		
	sdfp = SDFreadf(argv[1], (void **)&body, &gnobj, &nobj, sizeof(SPHbody),
					"x", offsetof(SPHbody, x), &conf,
					"y", offsetof(SPHbody, y), &conf,
					"z", offsetof(SPHbody, z), &conf,
					"mass", offsetof(SPHbody, mass), &conf,
					"vx", offsetof(SPHbody, vx), &conf,
					"vy", offsetof(SPHbody, vy), &conf,
					"vz", offsetof(SPHbody, vz), &conf,
					"u", offsetof(SPHbody, u), &conf,
					"h", offsetof(SPHbody, h), &conf,
					"rho", offsetof(SPHbody, rho), &conf,
					"pr", offsetof(SPHbody, pr), &conf,
					"drho_dt", offsetof(SPHbody, drho_dt), &conf,
					"udot", offsetof(SPHbody, udot), &conf,
					"temp", offsetof(SPHbody, temp), &conf,
					"He4", offsetof(SPHbody, He4), &conf,
					"C12", offsetof(SPHbody, C12), &conf,
					"O16", offsetof(SPHbody, O16), &conf,
					"Ne20", offsetof(SPHbody, Ne20), &conf,
					"Mg24", offsetof(SPHbody, Mg24), &conf,
					"Si28", offsetof(SPHbody, Si28), &conf,
					"S32", offsetof(SPHbody, S32), &conf,
					"Ar36", offsetof(SPHbody, Ar36), &conf,
					"Ca40", offsetof(SPHbody, Ca40), &conf,
					"Ti44", offsetof(SPHbody, Ti44), &conf,
					"Cr48", offsetof(SPHbody, Cr48), &conf,
					"Fe52", offsetof(SPHbody, Fe52), &conf,
					"Ni56", offsetof(SPHbody, Ni56), &conf,
					"abar", offsetof(SPHbody, abar), &conf,
					"zbar", offsetof(SPHbody, zbar), &conf,
					"ax", offsetof(SPHbody, ax), &conf,
					"ay", offsetof(SPHbody, ay), &conf,
					"az", offsetof(SPHbody, az), &conf,
					"lax", offsetof(SPHbody, lax), &conf,
					"lay", offsetof(SPHbody, lay), &conf,
					"laz", offsetof(SPHbody, laz), &conf,
//					"gax", offsetof(SPHbody, gax), &conf,
//					"gay", offsetof(SPHbody, gay), &conf,
//					"gaz", offsetof(SPHbody, gaz), &conf,
//					"grav_mass", offsetof(SPHbody, grav_mass), &conf,
					"phi", offsetof(SPHbody, phi), &conf,
//					"tacc", offsetof(SPHbody, tacc), &conf,
					"idt", offsetof(SPHbody, idt), &conf,
					"nbrs", offsetof(SPHbody, nbrs), &conf,
					"ident", offsetof(SPHbody, ident), &conf,
					"windid", offsetof(SPHbody, windid), &conf,
					NULL);
	SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
    SDFgetfloatOrDefault(sdfp, "dt",  &dt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "eps",  &eps, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "Gnewt",  &Gnewt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tolerance",  &tolerance, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "frac_tolerance",  &frac_tolerance, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tvel",  &tvel, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "gamma",  &gma, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "ke",  &ke, 0.0);
	SDFgetdoubleOrDefault(sdfp, "pe",  &pe, 0.0);
	SDFgetdoubleOrDefault(sdfp, "te",  &te, 0.0);
	
	singlPrintf("%s has %d particles.\n", argv[1], gnobj);
    
    nbody[0].ident = 0;

    j=0;
    for(i=0;i<nobj;i++)
    {
        kin = 0;
        pot = fabs(body[i].phi*body[i].mass);
		kin += pow(body[i].vx,2.0);
		kin += pow(body[i].vy,2.0);
		kin += pow(body[i].vz,2.0);
		kin = kin*0.5*body[i].mass;
        
		if(kin>pot) 
        {
            mass += body[i].mass;
            j++;
        } else 
        {
            nbody[0].mass += body[i].mass;
            nbody[0].x += body[i].mass*body[i].x;
            nbody[0].y += body[i].mass*body[i].y;
            nbody[0].z += body[i].mass*body[i].z;
            nbody[0].vx += body[i].mass*body[i].vx;
            nbody[0].vy += body[i].mass*body[i].vy;
            nbody[0].vz += body[i].mass*body[i].vz;
        }
    }
    

    nbody[0].x = nbody[0].x/nbody[0].mass;
    nbody[0].y = nbody[0].y/nbody[0].mass;
    nbody[0].z = nbody[0].z/nbody[0].mass;
    nbody[0].vx = nbody[0].vx/nbody[0].mass;
    nbody[0].vy = nbody[0].vy/nbody[0].mass;
    nbody[0].vz = nbody[0].vz/nbody[0].mass;
    
    nbody[0].lx = nbody[0].ly = nbody[0].lz = nbody[0].accmass= 0;
    

	printf("%d particles massing %3.3e g are unbound.\n",j,mass*mass_in_g);
    printf("Nbody particle %3.3e g:\ncm = [%3.3e %3.3e %3.3e]\n",nbody[0].mass*mass_in_g,nbody[0].x,nbody[0].y,nbody[0].z);
    printf("cv = [%3.3e %3.3e %3.3e]\n",nbody[0].vx,nbody[0].vy,nbody[0].vz);
    
    SPHbody *outbody = malloc(sizeof(SPHbody) * (j));
    
    
    j=0;
    for(i=0;i<nobj;i++)
    {
        kin = 0;
        pot = fabs(body[i].phi*body[i].mass);
		kin += pow(body[i].vx,2.0);
		kin += pow(body[i].vy,2.0);
		kin += pow(body[i].vz,2.0);
		kin = kin*0.5*body[i].mass;
        
		if(kin>pot) 
        {
            outbody[j].x = body[i].x;
            outbody[j].y = body[i].y;
            outbody[j].z = body[i].z;
            outbody[j].mass = body[i].mass;
            outbody[j].vx = body[i].vx;
            outbody[j].vy = body[i].vy;
            outbody[j].vz = body[i].vz;
            outbody[j].u = body[i].u;
            outbody[j].h = body[i].h;
            outbody[j].rho = body[i].rho;
            outbody[j].pr = body[i].pr;
            outbody[j].drho_dt = body[i].drho_dt;
            outbody[j].udot = body[i].udot;
            outbody[j].temp = body[i].temp;
            outbody[j].He4 = body[i].He4;
            outbody[j].C12 = body[i].C12;
            outbody[j].O16 = body[i].O16;
            outbody[j].Ne20 = body[i].Ne20;
            outbody[j].Mg24 = body[i].Mg24;
            outbody[j].Si28 = body[i].Si28;
            outbody[j].S32 = body[i].S32;
            outbody[j].Ar36 = body[i].Ar36;
            outbody[j].Ca40 = body[i].Ca40;
            outbody[j].Ti44 = body[i].Ti44;
            outbody[j].Cr48 = body[i].Cr48;
            outbody[j].Fe52 = body[i].Fe52;
            outbody[j].Ni56 = body[i].Ni56;
            outbody[j].vsound = body[i].vsound;
            outbody[j].abar = body[i].abar;
            outbody[j].zbar = body[i].zbar;
            outbody[j].ax = body[i].ax;
            outbody[j].ay = body[i].ay;
            outbody[j].az = body[i].az;
            outbody[j].lax = body[i].lax;
            outbody[j].lay = body[i].lay;
            outbody[j].laz = body[i].laz;
            outbody[j].phi = body[i].phi;
            outbody[j].idt = body[i].idt;
            outbody[j].nbrs = body[i].nbrs;
            outbody[j].ident = i;
            outbody[j].windid = body[i].windid;
            j++;
        }
    }
    
    snprintf(outfile, sizeof(outfile), "sph_%s", argv[1]);
    
    SDFwrite(outfile, j, 
			 j, outbody, sizeof(SPHbody),
			 SPHOUTBODYDESC,
			 "npart", SDF_INT, j,
			 "iter", SDF_INT, 0,
			 "dt", SDF_FLOAT, dt,
			 "eps", SDF_FLOAT, eps,
			 "Gnewt", SDF_FLOAT, Gnewt,
			 "tolerance", SDF_FLOAT, tolerance,
			 "frac_tolerance", SDF_FLOAT, frac_tolerance,
			 "ndim", SDF_INT, ndim,
			 "tpos", SDF_FLOAT, tpos,
			 "tvel", SDF_FLOAT, tvel,
			 "gamma", SDF_FLOAT, gma,
			 "ke", SDF_DOUBLE, ke,
			 "pe", SDF_DOUBLE, pe,
			 "te", SDF_DOUBLE, te,
			 NULL);
    
    snprintf(outfile, sizeof(outfile), "nbody_%s", argv[1]);
    
    pe = 0;
    ke = 0.5*nbody[0].mass*(pow(nbody[0].vx,2.0)+pow(nbody[0].vy,2.0)+pow(nbody[0].vz,2.0));
    te = ke;
    
    SDFwrite(outfile, 1, 
			 1, nbody, sizeof(Darkbody),
			 DARKOUTBODYDESC,
			 "npart", SDF_INT, 1,
			 "iter", SDF_INT, 0,
			 "dt", SDF_FLOAT, dt,
			 "eps", SDF_FLOAT, eps,
			 "Gnewt", SDF_FLOAT, Gnewt,
			 "tolerance", SDF_FLOAT, tolerance,
			 "frac_tolerance", SDF_FLOAT, frac_tolerance,
			 "ndim", SDF_INT, ndim,
			 "tpos", SDF_FLOAT, tpos,
			 "tvel", SDF_FLOAT, tvel,
			 "gamma", SDF_FLOAT, gma,
			 "ke", SDF_DOUBLE, ke,
			 "pe", SDF_DOUBLE, pe,
			 "te", SDF_DOUBLE, te,
			 NULL);
    
    free(outbody);
    free(nbody);
	free(body);
    SDFclose(sdfp);
	
	return 0;
}
Exemplo n.º 5
0
int main(int argc, char **argv[])
{
	int i,j,k;
    
	time_in_s				= 1;
	dist_in_cm				= 6.955e7;
	mass_in_g				= 1.989e27;
    sun_in_g                = 1.989e33;
	dens_in_gccm			= mass_in_g/dist_in_cm/dist_in_cm/dist_in_cm;
    energy_in_erg			= mass_in_g*dist_in_cm*dist_in_cm/time_in_s/time_in_s;
    specenergy_in_ergperg	= energy_in_erg/mass_in_g;
    pressure_in_ergperccm	= energy_in_erg/dist_in_cm/dist_in_cm/dist_in_cm;
	
    if (argc < 3){
		usage();
		return 0;
	}else {
        maxmass = atof(argv[2]);
	}
    
    SDF *sdfp;
	SPHbody *body;
	
	sdfp = SDFreadf(argv[1], (void **)&body, &gnobj, &nobj, sizeof(SPHbody),
					"x", offsetof(SPHbody, x), &conf,
					"y", offsetof(SPHbody, y), &conf,
					"z", offsetof(SPHbody, z), &conf,
					"mass", offsetof(SPHbody, mass), &conf,
					"vx", offsetof(SPHbody, vx), &conf,
					"vy", offsetof(SPHbody, vy), &conf,
					"vz", offsetof(SPHbody, vz), &conf,
					"u", offsetof(SPHbody, u), &conf,
					"h", offsetof(SPHbody, h), &conf,
					"rho", offsetof(SPHbody, rho), &conf,
					"pr", offsetof(SPHbody, pr), &conf,
					"drho_dt", offsetof(SPHbody, drho_dt), &conf,
					"udot", offsetof(SPHbody, udot), &conf,
					"temp", offsetof(SPHbody, temp), &conf,
					"He4", offsetof(SPHbody, He4), &conf,
					"C12", offsetof(SPHbody, C12), &conf,
					"O16", offsetof(SPHbody, O16), &conf,
					"Ne20", offsetof(SPHbody, Ne20), &conf,
					"Mg24", offsetof(SPHbody, Mg24), &conf,
					"Si28", offsetof(SPHbody, Si28), &conf,
					"S32", offsetof(SPHbody, S32), &conf,
					"Ar36", offsetof(SPHbody, Ar36), &conf,
					"Ca40", offsetof(SPHbody, Ca40), &conf,
					"Ti44", offsetof(SPHbody, Ti44), &conf,
					"Cr48", offsetof(SPHbody, Cr48), &conf,
					"Fe52", offsetof(SPHbody, Fe52), &conf,
					"Ni56", offsetof(SPHbody, Ni56), &conf,
					"abar", offsetof(SPHbody, abar), &conf,
					"zbar", offsetof(SPHbody, zbar), &conf,
					"ax", offsetof(SPHbody, ax), &conf,
					"ay", offsetof(SPHbody, ay), &conf,
					"az", offsetof(SPHbody, az), &conf,
					"lax", offsetof(SPHbody, lax), &conf,
					"lay", offsetof(SPHbody, lay), &conf,
					"laz", offsetof(SPHbody, laz), &conf,
//					"gax", offsetof(SPHbody, gax), &conf,
//					"gay", offsetof(SPHbody, gay), &conf,
//					"gaz", offsetof(SPHbody, gaz), &conf,
//					"grav_mass", offsetof(SPHbody, grav_mass), &conf,
					"phi", offsetof(SPHbody, phi), &conf,
//					"tacc", offsetof(SPHbody, tacc), &conf,
					"idt", offsetof(SPHbody, idt), &conf,
					"nbrs", offsetof(SPHbody, nbrs), &conf,
					"ident", offsetof(SPHbody, ident), &conf,
					"windid", offsetof(SPHbody, windid), &conf,
					NULL);
	SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
    SDFgetfloatOrDefault(sdfp, "dt",  &dt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "eps",  &eps, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "Gnewt",  &Gnewt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tolerance",  &tolerance, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "frac_tolerance",  &frac_tolerance, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tvel",  &tvel, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "gamma",  &gam, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "ke",  &ke, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "pe",  &pe, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "te",  &te, (float)0.0);
	
	singlPrintf("%s has %d particles.\n", argv[1], gnobj);
    
    for(i=0;i<nobj;i++)
    {
        tmass += body[i].mass;
    }
    
    f = maxmass*1.0e6/tmass;
    printf("Found %s has %3.3f Msun. Rescaling to %3.3f Msun by %3.3f.\n",argv[1],tmass/1.0e6,maxmass,f);
    
    fm13 = pow(f,-1.0/3.0);
	f65	= pow(f,6.0/5.0);
    
    for(i=0;i<nobj;i++)
    {
        body[i].mass    *= f;
        body[i].rho     *= f*f;
        body[i].x       *= fm13;
        body[i].y       *= fm13;
        body[i].z       *= fm13;
        body[i].h       *= fm13;
		body[i].u		*= f65;
    }
    
    snprintf(outfile, sizeof(outfile), "sub_%s", argv[1]);
    
    iter=tpos=0;
    SDFwrite(outfile, nobj, 
			 nobj, body, sizeof(SPHbody),
			 SPHOUTBODYDESC,
			 "npart", SDF_INT, nobj,
			 "iter", SDF_INT, iter,
			 "dt", SDF_FLOAT, dt,
			 "eps", SDF_FLOAT, eps,
			 "Gnewt", SDF_FLOAT, Gnewt,
			 "tolerance", SDF_FLOAT, tolerance,
			 "frac_tolerance", SDF_FLOAT, frac_tolerance,
			 "ndim", SDF_INT, ndim,
			 "tpos", SDF_FLOAT, tpos,
			 "tvel", SDF_FLOAT, tvel,
			 //"t_wind", SDF_FLOAT, twind_out,
			 //"R0", SDF_FLOAT, output_R0,
			 //"Omega0", SDF_FLOAT, cosmo.Omega0,
			 //"H0", SDF_FLOAT, cosmo.H0,
			 //"Lambda_prime", SDF_FLOAT, cosmo.Lambda,
			 //"hubble", SDF_FLOAT, output_h,
			 //"redshift", SDF_FLOAT, output_z,
			 "gamma", SDF_FLOAT, gam,
			 //"centmass", SDF_FLOAT, centmass, 
			 "ke", SDF_DOUBLE, ke,
			 "pe", SDF_DOUBLE, pe,
			 "te", SDF_DOUBLE, te,
			 NULL);
	
		
	free(body);
    SDFclose(sdfp);
	
	return 0;
}
Exemplo n.º 6
0
int main(int argc, char **argv[])
{

	time_in_s				= 1;
	dist_in_cm				= 6.955e7;
	mass_in_g				= 1.989e27;
	dens_in_gccm			= mass_in_g/dist_in_cm/dist_in_cm/dist_in_cm;
    energy_in_erg			= mass_in_g*dist_in_cm*dist_in_cm/time_in_s/time_in_s;
    specenergy_in_ergperg	= energy_in_erg/mass_in_g;
    pressure_in_ergperccm	= energy_in_erg/dist_in_cm/dist_in_cm/dist_in_cm;
	
	
	if (argc < 2){
		printf("on root: ");
		gets (argv[1]);
	}
	
	if (argc < 3){
		printf("Id: ");
		scanf(argv[2]);
	}
	
	strcpy(period,".");
	printf("start end increment: ");
	scanf("%d %d %d",&start,&end,&inc);
	
	FILE *stream, *fopen();
	/* declare a stream and prototype fopen */ 
	
	stream = fopen("out.csv","w");	
	
	fprintf(stream,"x,y,z,t,rho,Pr,T,u,cs,abar,zbar,He4,C12,O16,Ne20,Mg24,Si28,S32,Ar36,Ca40,Ti44,Cr48,Fe52,Ni56,h\n");
	
	for(i=start;i<(end+1);i+=inc)
	{
		strcpy(sdffile,argv[1]);
		strcat(sdffile,period);
		sprintf(number,"%04d",i);
		strcat(sdffile,number);
		
		SDF *sdfp;
		SPHbody *body;
		
		sdfp = SDFreadf(sdffile, (void **)&body, &gnobj, &nobj, sizeof(SPHbody),
						"x", offsetof(SPHbody, x), &conf,
						"y", offsetof(SPHbody, y), &conf,
						"z", offsetof(SPHbody, z), &conf,
						"mass", offsetof(SPHbody, mass), &conf,
						"vx", offsetof(SPHbody, vx), &conf,
						"vy", offsetof(SPHbody, vy), &conf,
						"vz", offsetof(SPHbody, vz), &conf,
						"u", offsetof(SPHbody, u), &conf,
						"h", offsetof(SPHbody, h), &conf,
						"rho", offsetof(SPHbody, rho), &conf,
						"pr", offsetof(SPHbody, pr), &conf,
						"drho_dt", offsetof(SPHbody, drho_dt), &conf,
						"udot", offsetof(SPHbody, udot), &conf,
						"temp", offsetof(SPHbody, temp), &conf,
						"He4", offsetof(SPHbody, He4), &conf,
						"C12", offsetof(SPHbody, C12), &conf,
						"O16", offsetof(SPHbody, O16), &conf,
						"Ne20", offsetof(SPHbody, Ne20), &conf,
						"Mg24", offsetof(SPHbody, Mg24), &conf,
						"Si28", offsetof(SPHbody, Si28), &conf,
						"S32", offsetof(SPHbody, S32), &conf,
						"Ar36", offsetof(SPHbody, Ar36), &conf,
						"Ca40", offsetof(SPHbody, Ca40), &conf,
						"Ti44", offsetof(SPHbody, Ti44), &conf,
						"Cr48", offsetof(SPHbody, Cr48), &conf,
						"Fe52", offsetof(SPHbody, Fe52), &conf,
						"Ni56", offsetof(SPHbody, Ni56), &conf,
						"vsound", offsetof(SPHbody, vsound), &conf,
						"abar", offsetof(SPHbody, abar), &conf,
						"zbar", offsetof(SPHbody, zbar), &conf,
						"ax", offsetof(SPHbody, ax), &conf,
						"ay", offsetof(SPHbody, ay), &conf,
						"az", offsetof(SPHbody, az), &conf,
						"lax", offsetof(SPHbody, lax), &conf,
						"lay", offsetof(SPHbody, lay), &conf,
						"laz", offsetof(SPHbody, laz), &conf,
						"phi", offsetof(SPHbody, phi), &conf,
						"sigma", offsetof(SPHbody, sigma), &conf,
						"kappa", offsetof(SPHbody, kappa), &conf,
						"nbrs", offsetof(SPHbody, nbrs), &conf,
						"ident", offsetof(SPHbody, ident), &conf,
						"windid", offsetof(SPHbody, windid), &conf,
						//"useless", offsetof(SPHbody, useless), &conf,
						NULL);
		SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
		singlPrintf("%s has %d particles.\n", sdffile, gnobj);
		SDFclose(sdfp);
		
		for(j=0;j < nobj; j++)
		{
			if (body[j].ident == atoi(argv[2])) {	
				x		= body[j].x * dist_in_cm;
				y		= body[j].y * dist_in_cm;
				z		= body[j].z * dist_in_cm;
				rho		= body[j].rho * dens_in_gccm;
				pr		= body[j].pr * pressure_in_ergperccm;
				temp	= body[j].temp;
				u		= body[j].u * energy_in_erg/mass_in_g;
				vsound	= body[j].vsound * dist_in_cm;
				
				fprintf(stream,"%3.2e,%3.2e,%3.2e,%f,%3.2e,%3.2e,%3.2e,%3.2e,%3.2e,%f,%f",x,y,z,tpos,rho,pr,temp,u,vsound,body[j].abar,body[j].zbar);
				fprintf(stream,",%f",body[j].He4);
				fprintf(stream,",%f",body[j].C12);
				fprintf(stream,",%f",body[j].O16);
				fprintf(stream,",%f",body[j].Ne20);
				fprintf(stream,",%f",body[j].Mg24);
				fprintf(stream,",%f",body[j].Si28);
				fprintf(stream,",%f",body[j].S32);
				fprintf(stream,",%f",body[j].Ar36);
				fprintf(stream,",%f",body[j].Ca40);
				fprintf(stream,",%f",body[j].Ti44);
				fprintf(stream,",%f",body[j].Cr48);
				fprintf(stream,",%f",body[j].Fe52);
				fprintf(stream,",%f",body[j].Ni56);
				fprintf(stream,",%3.2e\n",body[j].h*dist_in_cm);
			}
		}
		Free(body);
	}
		
	//close the stream file
	fclose(stream);
	
	return 0;
}
Exemplo n.º 7
0
int main(int argc, char **argv[])
{
    double dist_in_cm               = 6.955e7;
    double mass_in_g                = 1.989e27;
    double time_in_s                = 1.0;
    double dens_in_gccm             = mass_in_g/dist_in_cm/dist_in_cm/dist_in_cm;
    double energy_in_erg			= mass_in_g*dist_in_cm*dist_in_cm/time_in_s/time_in_s;
    double specenergy_in_ergperg	= energy_in_erg/mass_in_g;
    double pressure_in_ergperccm	= energy_in_erg/dist_in_cm/dist_in_cm/dist_in_cm;
    double maxrho,tot_mass;

    int gnobj, nobj;
    int conf;
    double ang;
    double time;
    float tpos;
    int threads;
    int i,j,k,nz;
    
    double x,y,z,l,h,sx,sy,ds;
    double vdotr,vdots,rho,temp,mass,kern,r,rmax;
    int hc,ic,jc;
    
    if(argc < 4)
    {
        usage();
        return 0;
    } else
    {
        ang     = atof(argv[2]);
        nz      = atoi(argv[3]);
    }
	
	SDF *sdfp;
	SPHbody *body;
    
    line *lineOut;
    lineOut = malloc(nz*sizeof(line));
		
	sdfp = SDFreadf(argv[1], (void **)&body, &gnobj, &nobj, sizeof(SPHbody),
					"x", offsetof(SPHbody, x), &conf,
					"y", offsetof(SPHbody, y), &conf,
					"z", offsetof(SPHbody, z), &conf,
					"mass", offsetof(SPHbody, mass), &conf,
					"vx", offsetof(SPHbody, vx), &conf,
					"vy", offsetof(SPHbody, vy), &conf,
					"vz", offsetof(SPHbody, vz), &conf,
					"u", offsetof(SPHbody, u), &conf,
					"h", offsetof(SPHbody, h), &conf,
					"rho", offsetof(SPHbody, rho), &conf,
//					"pr", offsetof(SPHbody, pr), &conf,
//					"drho_dt", offsetof(SPHbody, drho_dt), &conf,
//					"udot", offsetof(SPHbody, udot), &conf,
					"temp", offsetof(SPHbody, temp), &conf,
					"He4", offsetof(SPHbody, He4), &conf,
					"C12", offsetof(SPHbody, C12), &conf,
					"O16", offsetof(SPHbody, O16), &conf,
					"Ne20", offsetof(SPHbody, Ne20), &conf,
					"Mg24", offsetof(SPHbody, Mg24), &conf,
					"Si28", offsetof(SPHbody, Si28), &conf,
					"S32", offsetof(SPHbody, S32), &conf,
					"Ar36", offsetof(SPHbody, Ar36), &conf,
					"Ca40", offsetof(SPHbody, Ca40), &conf,
					"Ti44", offsetof(SPHbody, Ti44), &conf,
					"Cr48", offsetof(SPHbody, Cr48), &conf,
					"Fe52", offsetof(SPHbody, Fe52), &conf,
					"Ni56", offsetof(SPHbody, Ni56), &conf,
//					"abar", offsetof(SPHbody, abar), &conf,
//					"zbar", offsetof(SPHbody, zbar), &conf,
//					"ax", offsetof(SPHbody, ax), &conf,
//					"ay", offsetof(SPHbody, ay), &conf,
//					"az", offsetof(SPHbody, az), &conf,
//					"lax", offsetof(SPHbody, lax), &conf,
//					"lay", offsetof(SPHbody, lay), &conf,
//					"laz", offsetof(SPHbody, laz), &conf,
//					"gax", offsetof(SPHbody, gax), &conf,
//					"gay", offsetof(SPHbody, gay), &conf,
//					"gaz", offsetof(SPHbody, gaz), &conf,
//					"grav_mass", offsetof(SPHbody, grav_mass), &conf,
//					"phi", offsetof(SPHbody, phi), &conf,
//					"tacc", offsetof(SPHbody, tacc), &conf,
//					"idt", offsetof(SPHbody, idt), &conf,
//					"nbrs", offsetof(SPHbody, nbrs), &conf,
//					"ident", offsetof(SPHbody, ident), &conf,
//					"windid", offsetof(SPHbody, windid), &conf,
					//"useless", offsetof(SPHbody, useless), &conf,
					NULL);
	SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
	
	singlPrintf("%s has %d particles.\n", argv[1], gnobj);
    
    for(i=0;i<nobj;i++)
    {
        x   = body[i].x;
        y   = body[i].y;
        z   = body[i].z;
        rmax= MAX(rmax,sqrt(x*x+y*y+z*z));
    }
    
    
    if(argc > 4) rmax = atof(argv[4]);
    printf("rmax[code units] = %3.2e\n",rmax);
    
    for(i=0;i<nz;i++)
	{
		lineOut[i].r	= ((double)(i+1.0)/(double)nz)*rmax;
		lineOut[i].rho	= 0;
		//lineOut[i].v	= lineOut[i].r/tpos*dist_in_cm;
		lineOut[i].v	= 0;
	}
        
    
    ds = lineOut[i].r - lineOut[i-1].r;

    for(i=0;i<nobj;i++)
    {
        x = body[i].x;
        y = body[i].y;
        z = body[i].z;
        h = body[i].h;
		mass = body[i].mass;
        
        r = sqrt(x*x+y*y+z*z);
        l = r*r - pow(x*cos(ang)+y*sin(ang),2.0); // this is actually l^2
        if(l<4*h*h)   // the line intercepts particle i
        {
            vdotr = (body[i].vx*x + body[i].vy*y + body[i].vz*z)/r;
            if(2*h<ds)
            {
                // particle is smaller than zone
                for(j=0;j<nz;j++)
                    if(lineOut[j].r > sqrt(x*x+y*y)) break;
                j = ((j>0) ? j : j++);
                vdots = body[i].vx*cos(ang) + body[i].vy*sin(ang);
                kern = pow(ds,-3.0);
                lineOut[j-1].rho += mass*kern*dens_in_gccm;
                lineOut[j-1].v   += mass*kern*dens_in_gccm*vdots*dist_in_cm;
				lineOut[j-1].temp += mass*kern*body[i].temp;
            }
            else
            {
                for(j=0;j<nz;j++)
                {
                    sx  = lineOut[j].r*cos(ang);
                    sy  = lineOut[j].r*sin(ang);
                    r   = sqrt(pow(x-sx,2.0)+pow(y-sy,2.0)+pow(z,2.0));
                    if(r<h) // inside the particle
                    {
                        vdots = body[i].vx*cos(ang) + body[i].vy*sin(ang); // v * s^
                        
                        kern = w(h,r);
                        lineOut[j].rho += mass*kern*dens_in_gccm;
                        lineOut[j].v   += mass*kern*dens_in_gccm*vdots*dist_in_cm;
						lineOut[j].temp += mass*kern*body[i].temp;
                    }
                } 
            }

        }
    }
    
    for(i=0;i<nz;i++)
        lineOut[i].r = lineOut[i].r*dist_in_cm;
    
    for(i=0;i<nz;i++)
    {
        printf("%3.2e %3.2e %3.2e %3.2e\n",lineOut[i].r,lineOut[i].rho,lineOut[i].v,lineOut[i].temp);
        tot_mass += (4.0/3.0*3.14159)*((i>0) ? (pow(lineOut[i].r,3)-pow(lineOut[i-1].r,3))*lineOut[i].rho : 
                                       pow(lineOut[i].r,3)*lineOut[i].rho);
    }
        
    printf("tot mass = %3.2e\n",tot_mass);
    
    SDFclose(sdfp);
	free(body);
    free(lineOut);
	return 0;
}
Exemplo n.º 8
0
int main(int argc, char **argv[])
{
	if(argc < 2)
	{
		usage();
		return 0;
	}
	
	if(argc < 3)
		rhomin = 5.0e4;
	else
		rhomin = atof(argv[2]);

	
	int i,j,k,id;    

    double cc = 2.99792e10;
	double cc2 = cc*cc;
    
	time_in_s				= 1;
	dist_in_cm				= 6.955e7;
	mass_in_g				= 1.989e27;
    mass_in_msol            = mass_in_g/1.99e33;
	dens_in_gccm			= mass_in_g/dist_in_cm/dist_in_cm/dist_in_cm;
    energy_in_erg			= mass_in_g*dist_in_cm*dist_in_cm/time_in_s/time_in_s;
    specenergy_in_ergperg	= energy_in_erg/mass_in_g;
    pressure_in_ergperccm	= energy_in_erg/dist_in_cm/dist_in_cm/dist_in_cm;
    
    SDF *sdfp;
	SPHbody *body;

		
	sdfp = SDFreadf(argv[1], (void **)&body, &gnobj, &nobj, sizeof(SPHbody),
					"x", offsetof(SPHbody, x), &conf,
					"y", offsetof(SPHbody, y), &conf,
					"z", offsetof(SPHbody, z), &conf,
					"mass", offsetof(SPHbody, mass), &conf,
					"vx", offsetof(SPHbody, vx), &conf,
					"vy", offsetof(SPHbody, vy), &conf,
					"vz", offsetof(SPHbody, vz), &conf,
					"u", offsetof(SPHbody, u), &conf,
					"h", offsetof(SPHbody, h), &conf,
					"rho", offsetof(SPHbody, rho), &conf,
					"pr", offsetof(SPHbody, pr), &conf,
					"drho_dt", offsetof(SPHbody, drho_dt), &conf,
					"udot", offsetof(SPHbody, udot), &conf,
					"temp", offsetof(SPHbody, temp), &conf,
					"He4", offsetof(SPHbody, He4), &conf,
					"C12", offsetof(SPHbody, C12), &conf,
					"O16", offsetof(SPHbody, O16), &conf,
					"Ne20", offsetof(SPHbody, Ne20), &conf,
					"Mg24", offsetof(SPHbody, Mg24), &conf,
					"Si28", offsetof(SPHbody, Si28), &conf,
					"S32", offsetof(SPHbody, S32), &conf,
					"Ar36", offsetof(SPHbody, Ar36), &conf,
					"Ca40", offsetof(SPHbody, Ca40), &conf,
					"Ti44", offsetof(SPHbody, Ti44), &conf,
					"Cr48", offsetof(SPHbody, Cr48), &conf,
					"Fe52", offsetof(SPHbody, Fe52), &conf,
					"Ni56", offsetof(SPHbody, Ni56), &conf,
					"abar", offsetof(SPHbody, abar), &conf,
					"zbar", offsetof(SPHbody, zbar), &conf,
					"ax", offsetof(SPHbody, ax), &conf,
					"ay", offsetof(SPHbody, ay), &conf,
					"az", offsetof(SPHbody, az), &conf,
					"lax", offsetof(SPHbody, lax), &conf,
					"lay", offsetof(SPHbody, lay), &conf,
					"laz", offsetof(SPHbody, laz), &conf,
//					"gax", offsetof(SPHbody, gax), &conf,
//					"gay", offsetof(SPHbody, gay), &conf,
//					"gaz", offsetof(SPHbody, gaz), &conf,
//					"grav_mass", offsetof(SPHbody, grav_mass), &conf,
					"phi", offsetof(SPHbody, phi), &conf,
//					"tacc", offsetof(SPHbody, tacc), &conf,
					"idt", offsetof(SPHbody, idt), &conf,
					"nbrs", offsetof(SPHbody, nbrs), &conf,
					"ident", offsetof(SPHbody, ident), &conf,
					"windid", offsetof(SPHbody, windid), &conf,
					NULL);
	SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
    SDFgetfloatOrDefault(sdfp, "dt",  &dt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "eps",  &eps, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "Gnewt",  &Gnewt, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tolerance",  &tolerance, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "frac_tolerance",  &frac_tolerance, (float)0.0);
	//SDFgetfloatOrDefault(sdfp, "tpos",  &tpos, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "tvel",  &tvel, (float)0.0);
	SDFgetfloatOrDefault(sdfp, "gamma",  &gam, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "ke",  &ke, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "pe",  &pe, (float)0.0);
	SDFgetdoubleOrDefault(sdfp, "te",  &te, (float)0.0);
	
	singlPrintf("%s has %d particles.\n", argv[1], gnobj);

    
    rhomax = 0;
    
    for(i=0;i<nobj;i++)
		if(body[i].rho*dens_in_gccm > rhomax) 
			rhomax = body[i].rho*dens_in_gccm;
    printf("Found rhomax = %3.2e g/cc\n",rhomax);
	
	if(rhomax >= rho1p2[1]) mcore = 1.2;
	else if(rhomax >= rho1p0[1]) mcore = (1.2-1.0)/(rho1p2[1]-rho1p0[1])*(rhomax-rho1p0[1])+1.0;
	else if(rhomax >= rho0p8[1]) mcore = (1.0-0.8)/(rho1p0[1]-rho0p8[1])*(rhomax-rho0p8[1])+0.8;
	else mcore = 0.8;
	printf("Found mcore is most similar to %f msol\n",mcore);

    
    for(i=0;i<nobj;i++)
    {
        energy = 0;
        
        rho = body[i].rho*dens_in_gccm;
        if(rho > rhomin)
        {
            burn(rho);
            
            for(j=0;j<14;j++) abundin[j] = 0.;
            
            abundin[1] = 0.50;
			abundin[2] = 0.50;
			
            for(j=0;j<14;j++)
				energy += (abundin[j]-abundout[j])*ea[j]/aa[j];
            energy = energy*6.02214e23/specenergy_in_ergperg;
			
            printf("u: %3.2e",body[i].u);
            body[i].u += energy;
            printf(" + %3.2e {",energy);
            etot += energy * body[i].mass;
            tmass += body[i].mass;
            for(j=0;j<14;j++) printf("%1.3f ",abundout[j]);
            printf("}\n");
			
			/*
			 He4 = 0
			 C12 = 1
			 O16 = 2
			 Ne20= 3
			 Mg24= 4
			 Si28= 5
			 S32 = 6
			 Ar36= 7
			 Ca40= 8
			 Ti44= 9
			 Cr48= 10
			 Fe52= 11
			 Fe54= 12
			 Ni56= 13
			 */
			
            body[i].He4  = abundout[0];
            body[i].C12  = abundout[1];
            body[i].O16  = abundout[2];
            body[i].Ne20 = abundout[3];
            body[i].Mg24 = abundout[4];
            body[i].Si28 = abundout[5];
            body[i].S32  = abundout[6];
            body[i].Ar36 = abundout[7];
            body[i].Ca40 = abundout[8];
            body[i].Ti44 = abundout[9]+abundout[10];	//Cr48 -> Ti48 ignoring V48
            body[i].Cr48 = abundout[11];				//Fe52 -> Cr48
            body[i].Fe52 = abundout[12];				//Fe54 is stable
            body[i].Ni56 = abundout[13];
			k++;
        }
        else
        {
//			body[i].He4	 = 0.;
//            body[i].C12  = 0.5;
//            body[i].O16  = 0.5;
//            body[i].Ne20 = 0.;
//            body[i].Mg24 = 0.;
//            body[i].Si28 = 0.;
//            body[i].S32  = 0.;
//            body[i].Ar36 = 0.;
//            body[i].Ca40 = 0.;
//            body[i].Ti44 = 0.;
//            body[i].Cr48 = 0.; 
//            body[i].Fe52 = 0.; 
//            body[i].Ni56 = 0.;
        }

    }

	printf("Burned %3.3e g\n",tmass*mass_in_g);
    printf("~ %3.3e erg added\n",etot*energy_in_erg);
    
    snprintf(outfile, sizeof(outfile), "exp_%s", argv[1]);
    
    iter=tpos=0;
    SDFwrite(outfile, nobj, 
			 nobj, body, sizeof(SPHbody),
			 SPHOUTBODYDESC,
			 "npart", SDF_INT, nobj,
			 "iter", SDF_INT, iter,
			 "dt", SDF_FLOAT, dt,
			 "eps", SDF_FLOAT, eps,
			 "Gnewt", SDF_FLOAT, Gnewt,
			 "tolerance", SDF_FLOAT, tolerance,
			 "frac_tolerance", SDF_FLOAT, frac_tolerance,
			 "ndim", SDF_INT, ndim,
			 "tpos", SDF_FLOAT, tpos,
			 "tvel", SDF_FLOAT, tvel,
			 "gamma", SDF_FLOAT, gam,
			 "ke", SDF_DOUBLE, ke,
			 "pe", SDF_DOUBLE, pe,
			 "te", SDF_DOUBLE, te,
			 NULL);

        		
	free(body);
    SDFclose(sdfp);
	
	return 0;
}