Beispiel #1
0
main(int argc, char ** argv)
{
    check_help();

    extern char *poptarg;
    extern char *poparr[];
    int c;
    const char *param_string = "";

    while ((c = pgetopt(argc, argv, param_string,
		    "$Revision: 1.5 $", _SRC_)) != -1)
	switch(c) {
            case '?':	params_to_usage(cerr, argv[0], param_string);
	    		get_help();
	    		exit(1);
        }            

    dyn *b;
    real prev_time = -VERY_LARGE_NUMBER;
    cerr.precision(HIGH_PRECISION);

    while (b = get_dyn()) {

	real time = b->get_system_time();

	if (prev_time > -VERY_LARGE_NUMBER) {
	    real dt = time - prev_time;
	    PRC(time); PRL(dt);
	} else
	    PRL(time);
	prev_time = time;

	rmtree(b);
    }
}
bool CorporationDB::CreateMemberAttributeUpdate(MemberAttributeUpdate & attrib, uint32 newCorpID, uint32 charID) {
    // What are we doing here exactly?
    // Corporation gets a new member
    // it's new to it

    DBQueryResult res;
    DBResultRow row;
    if (!sDatabase.RunQuery(res,
        " SELECT "
        "   title, corporationDateTime, corporationID, "
        "   corpRole, rolesAtAll, rolesAtBase, "
        "   rolesAtHQ, rolesAtOther "
        " FROM character_ "
        " WHERE character_.characterID = %u ", charID))
    {
        codelog(SERVICE__ERROR, "Error in query: %s", res.error.c_str());
        return false;
    }

    if (!res.GetRow(row)) {
        codelog(SERVICE__ERROR, "Cannot find character in database");
        return false;
    }

    // this could be stored in the db
#define PRN new PyNone()
#define PRI(i) new PyInt(i)
#define PRL(i) new PyLong(i)
#define PRS(s) new PyString(s)
#define PRNI(i) (row.IsNull(i) ? PRI(0) : PRI(row.GetUInt64(i)))
#define F(name, o, n) \
    attrib.name##Old = o; \
    attrib.name##New = n

    //element                   Old Value               New Value
    F(accountKey,               PRN,                    PRN);
    // i don't even know what this could refer to
    F(baseID,                   PRN,                    PRN);
    F(characterID,              PRN,                    PRI(charID));
    F(corporationID,            PRI(row.GetUInt(2)),    PRI(newCorpID));
    // these also have to be queried from the db
    F(divisionID,               PRN,                    PRN);
    F(roles,                    PRNI(3),                PRI(0));
    F(grantableRoles,           PRNI(4),                PRI(0));
    F(grantableRolesAtBase,     PRNI(5),                PRI(0));
    F(grantableRolesAtHQ,       PRNI(6),                PRI(0));
    F(grantableRolesAtOther,    PRNI(7),                PRI(0));
    F(squadronID,               PRN,                    PRN);
    F(startDateTime,            PRL(row.GetUInt64(1)),  PRL(Win32TimeNow()));
    // another one i have no idea
    F(titleMask,                PRN,                    PRI(0));
    F(baseID,                   PRS(row.GetText(0)),    PRS(""));
#undef F
#undef PRN
#undef PRI
#undef PRS
#undef PRNI

    return true;
}
Beispiel #3
0
void star_cluster::print(ostream& s = cerr) {

  PRC(relative_mass);PRC(get_total_mass());PRL(nstar);
  PRC(relative_age);PRC(next_update_age);PRC(relative_mass);
  PRC(black_hole_mass);PRC(trlx_initial);
  PRC(rvir);PRC(nstar);PRC(x_imf);PRL(minimum_mass);

}
Beispiel #4
0
void compute_max_cod(dyn *b, vec& pos, vec& vel)
{
    // First see if the data are already known.

    if (find_qmatch(b->get_dyn_story(), "density_center_type"))
	if (streq(getsq(b->get_dyn_story(), "density_center_type"), "max")) {
	    if (twiddles(getrq(b->get_dyn_story(), "density_center_time"),
			 b->get_system_time(), TTOL)) {
		pos = getvq(b->get_dyn_story(), "density_center_pos");
		vel = getvq(b->get_dyn_story(), "density_center_vel");
		return;
	    }
	}

    real max_density = 0;

    pos = 0;
    vel = 0;

//  for_all_leaves(dyn, b, d)
    for_all_daughters(dyn, b, d) {

	real dens_time = getrq(d->get_dyn_story(), "density_time");

	if (!twiddles(dens_time, b->get_system_time(), TTOL) && print_msg) {
	    warning("compute_max_cod: using out-of-date densities.");
	    PRC(d->format_label()), PRL(dens_time);
	    if (++msg_count > MAX_MSG_COUNT) print_msg = false;
	}

	real this_density = getrq(d->get_dyn_story(), "density");

	if (this_density > 0) {
	    if (max_density < this_density) {
		max_density = this_density;
		pos = d->get_pos();
		vel = d->get_vel();
	    }
	} else if (this_density <= -VERY_LARGE_NUMBER) {
	    if (print_msg) {
		warning("compute_max_cod: density not set.");
		PRL(d->format_label());
	    }
	    if (++msg_count > MAX_MSG_COUNT) print_msg = false;
	}
    }
Beispiel #5
0
local void scale_limits(real& e1, real& e2, int option,
			int N, real M, real E)
{
    real scale = 1.0;

PRL(E);
    if (option == 3) {

	// Limits refer to kinetic energy per unit mass.  Scale to -E/M.

	scale = -E / M;

    } else if (option != 2) {

	// Limits refer to energy.  Scale to kT = -(2/3) E/N.

	scale = -E / (1.5*N);
PRL(scale);
    }

    e1 *= scale;
    e2 *= scale;
}
Beispiel #6
0
local void  addstoa(dyn * b, int m_flag)
{
    real time;
    int ndim;
    int n;
    int n_stoa;


    n = 0;
    for_all_daughters(dyn, b, bi) n++;

    PRL(n);
    cin >> n_stoa;
    cin >> ndim;
    cin >>  time;
    PRC(n_stoa); PRC(ndim); PRL(time);
    if (n != n_stoa){
	err_exit("n and n_stoa must be equal");
    }
    for_all_daughters(dyn, b, bi) {
	real mass;
	cin >> mass;
	if(m_flag)bi->set_mass(mass);
    }
Beispiel #7
0
local int add_background_stars_to_ccd(real** ccd, wavelength band,
				      real beta_PSF,
				      real arcsec_per_pixel, real fwhm,
				      bool verbose) {

  real luminosity = 0;
  real xpos, ypos;
  real ccd_size = XCCD_MAX*YCCD_MAX * pow(arcsec_per_pixel/3600., 2);
  PRL(ccd_size);

  real a = -5.86697E+00;
  real b = 9.95179E-01;
  real c = -3.74649E-02;
  real d = 6.47974E-04;
  real e = -4.38781E-06;

  int n_added=0;
  int ns_mag;
  real Mv;
  for(int imag=4; imag<31; imag++) {
    Mv = imag;
    ns_mag = (int)(ccd_size * 2.5
           * pow(10., a + b*Mv + c*pow(Mv, 2) + d*pow(Mv, 3) + e*pow(Mv, 4)));

    PRC(Mv);PRC(ns_mag);
    
    for(int i=0; i<ns_mag; i++) {
      Mv = randinter((real)imag, (real)imag+1);
      if(band!=2) {
	Mv += randinter(-0.2, 1.5);
      }
      luminosity = pow(10, (4.76-Mv)/2.5);
      xpos = randinter(0., XCCD_MAX*arcsec_per_pixel);
      ypos = randinter(0., YCCD_MAX*arcsec_per_pixel);
      if (verbose) {
	cerr << "Background star # " << n_added+1
	     << " pos (x, y): " 
	     << xpos << " " << ypos << " pixels"; 
	cerr << "         magnitudes (M): " << Mv << endl;
      }

      if(add_star_to_ccd(ccd, luminosity, xpos, ypos, beta_PSF, 
			 arcsec_per_pixel, fwhm)) 
	n_added++;
    }
  }
  return n_added;
} 
Beispiel #8
0
void mmas::mixing(usm &model) {
  int n = model.get_num_shells();
  
  real entr_min = 1e100, entr_max = 0;
  vector<real> dm;
  real m_prev = 0;
  for (int i = 0; i < n; i++) {
    mass_shell &shell  = model.get_shell(i);
    entr_min = min(entr_min, shell.entropy);
    entr_max = max(entr_max, shell.entropy);
    dm.push_back(shell.mass - m_prev);
    m_prev = shell.mass;
  }

  real M = model.star_mass;

  real alpha = 10 * square(log(entr_max/entr_min)/log(10));
  PRL(alpha);
  vector<real> m_mu;
  for (int k = 0; k < n; k++) {
    mass_shell &shell_k = model.get_shell(k);
    real X_H = 0.0;
    for (int i = 0; i < n; i++) {
      mass_shell &shell_i = model.get_shell(i);
      real fac = 0;
      for (int j = 0; j < n; j++) {
	mass_shell &shell_j = model.get_shell(j);
	fac += gij(shell_i.mass, shell_j.mass, M, alpha)*dm[j];
      }
      real xH = (4.0/shell_i.mean_mu - 3.0)/5.0;
      X_H += xH * gij(shell_i.mass, shell_k.mass, M, alpha) * dm[i] / fac;
    }
    real mmu = 4.0/(5*X_H + 3);
    m_mu.push_back(mmu);
  }

  for (int i = 0; i < n; i++) {
    mass_shell &shell = model.get_shell(i);
//     PRC(shell.mass); PRC(shell.mean_mu); PRL(m_mu[i]);
    shell.mean_mu = m_mu[i];
  }

}
Beispiel #9
0
void new_camera_position(vec &v_new,
			 vec v_old,
			 real theta_rotation,
			 real phi_rotation,
			 int nsteps,
			 int nsnap) {

  
  real theta = nsnap*theta_rotation/nsteps;
  real phi   = nsnap*phi_rotation/nsteps;

  PRC(nsnap);PRC(theta);PRL(phi);
  real r = abs(v_old);
  v_new[0] = r * sin(theta);
  v_new[1] = r * sin(theta) * cos(phi);
  v_new[2] = r * cos(theta);

  cerr << "vector = " << v_new << endl;

}
Beispiel #10
0
real stellar_evolution_constants::super_nova_kick() {
  
  // Super Nova Kick functions.
  // kick velicity imparted to the remnant during the supernova event.
  // changing the kick velocity requires recompilation.

  //	Paczynsky's velocity distribution with a dispersion
  //	of 600 km/s is prefered by Hartman.

  //	Gauss kick velocity distribution.
  //	Lyne, A.G., \& Lorimer, D.R., 1994, Nature 369, 127
  //	propose v_k = 450 +- 90 km/s
  //	this is comparable to a one dimensional gaussion
  //	of 260 km/s.

  //    Hansen & Phinney (1997, MNRAS 291, 569) kick velocity distribution.
  //    They prever a Maxwellian with a velocity dispersion of
  //    270 km/s.
  
  // selected kick distribution imparted to a newly formed neutron star
  // in a supernova. 
  PRL(v_disp);
    switch(pk) {
    case no_velocity_kick:              return 0;
             break;                                
	case Maxwellian_velocity_kick:      return random_maxwellian_velocity(v_disp);
             break;
    case internally_decided_velocity_kick:
	case Paczynski_velocity_kick:       return random_paczynski_velocity(v_disp);
             break;
	case delta_function_velocity_kick:  return v_disp;
             break;
    default:
	     cerr << "\nNo recognized option in "
		     "stellar_evolution_constants::"
		     "super_nova_kick(super_nova_kick_distribution "
	          << pk << ")"
		  << endl;
             exit(1);
    }
}  
Beispiel #11
0
local void add_bad_column(real **ccd, int n_bc, bool verbose) {

  // reset input seed.
  int input_seed = 11111111;
  int actual_seed = srandinter(input_seed);
  if (verbose) {
    cerr << "Add " << n_bc << " bad columns: ";
    PRC(input_seed);PRL(actual_seed);
  }

  for(int iy = 0; iy<n_bc; iy++) {

    int iyy = int(randinter(0., YCCD_MAX));
    if (verbose)
      cerr << "Bad column at: " << iyy << endl;

    for(int ix = 0; ix<XCCD_MAX; ix++) 
      ccd[ix][iyy] = 0;
  }

}
Beispiel #12
0
local bool read_binary_params(ifstream& in, real &m_prim, 
			      real &m_sec, real &sma, real &ecc, real &z) {

    m_prim = 1000;
    m_sec = 1000;
    sma = 0;
    ecc = 0;
    z = 1;
    while (m_prim>100.0 || m_sec>100.0 || ecc<0 || ecc>1 || z < 0.0001 || z > 0.03){   
      if(in.eof())
        return false;
    
      // reading from input file
    //  int id, tpp, tps; 
    //  real time, Rlp, Rls;
    
      in >> sma >> ecc >> m_prim >> m_sec >> z;
      //  in >>id >> time >> sma >> ecc 
      //     >> tpp >> m_prim >> Rlp >> tps >> m_sec >> Rls;
    }
    
    PRC(m_prim);PRC(m_sec);PRC(sma);PRC(ecc);PRL(z);
  return true;
}
Beispiel #13
0
local void mk_ccd(dyn* b, vec dc_pos, int project, wavelength band,
		  real distance, real reddening,
		  real upper_Llimit,
		  real xoffset, real yoffset,
		  real electrons_to_ADU, real beta_PSF,
		  real arcsec_per_pixel, real fwhm,
		  char* filename, bool add_background_stars,
		  bool add_standard_star, int input_seed,
		  bool add_cosmics, int nbad_column,
		  bool verbose) {

  PRL(band);

  real maximum_electrons = electrons_to_ADU*SATURATION_LIMIT-1;

  real half_xccd = 0.5*XCCD_MAX*arcsec_per_pixel;
  real half_yccd = 0.5*YCCD_MAX*arcsec_per_pixel;

  real **ccd = mkarray(XCCD_MAX, YCCD_MAX);
  cerr << "CCD allocated"<<endl;
  for(int ix = 0; ix<XCCD_MAX; ix++) 
    for(int iy = 0; iy<YCCD_MAX; iy++)  
      ccd[ix][iy] = 0;

  PRL(distance);

  real distance_modulus = 5 * log10(distance/10.);
  PRC(distance_modulus);
  PRL(distance);

//  magnitude_limit -= distance_modulus;
//  real magnitude_limit = t_obs/10. - distance_modulus;

//  real luminosity_limit = pow(10, (4.76-magnitude_limit)/5.5); // in V
//  PRC(magnitude_limit);
//  PRL(luminosity_limit);
  
  real pos_to_parsec = b->get_starbase()->conv_r_dyn_to_star(1)
                     * cnsts.parameters(Rsun)/cnsts.parameters(parsec);
  real pos_to_arcsec = b->get_starbase()->conv_r_dyn_to_star(1)
                     * 3600 * cnsts.parameters(Rsun)
                     / (distance*cnsts.parameters(parsec));
  

  PRC(pos_to_parsec);PRL(pos_to_arcsec);

  real xpos, ypos, zpos;
  real M_max = VERY_LARGE_NUMBER;
  real local_Mmm=0, magn;
  real luminosity, L_max = 0;
  real xmax=0, ymax=0;
  vec r;
  if (b->get_oldest_daughter()) {

    vec r_com  = b->get_pos() - dc_pos;

    for_all_leaves(dyn, b, bb) {

//      cerr << " new star: ";
//      cerr << bb->get_index()<<endl;

      r = bb->get_pos()-bb->get_parent()->get_pos();
//      PRL(r);

      switch(project) {
        case -3: xpos =  r[0];
		 ypos =  r[1];
		 zpos = -r[2];
		 break;
	case -2: xpos = -r[0];
		 ypos =  r[2];
		 zpos = -r[1];
		 break;
	case -1: xpos = -r[1];
		 ypos =  r[2];
		 zpos = -r[0];
		 break;
	case 1: xpos = r[1];
		ypos = r[2];
		zpos = r[0];
		break;
	case 2: xpos = r[0];
		ypos = r[2];
		zpos = r[1];
		break;
        case 3: xpos = r[0];
		ypos = r[1];
		zpos = r[2];
		break;
      }
      xpos = xpos * pos_to_arcsec + half_xccd - xoffset;
      ypos = ypos * pos_to_arcsec + half_yccd - yoffset;
      zpos *= pos_to_parsec;
//      PRC(zpos);
      if(distance+zpos>0) {
	real local_distance_modulus = 5 * log10((distance+zpos)/10.);
//      PRL(local_distance_modulus);

	luminosity = get_luminosity(bb, band, local_distance_modulus,
				    maximum_electrons/upper_Llimit);

//	PRL(luminosity);
	if(L_max<luminosity) {
	  L_max = luminosity;
	  M_max = 4.76 - 2.5*log10(luminosity) - local_distance_modulus;
	  local_Mmm = local_distance_modulus;
	  xmax = xpos;    //ascsec
	  ymax = ypos;
	}

	if (luminosity<=0) {
	  luminosity = 0;
	  //	  cerr << "Stellar luminosity = " << luminosity << endl;
	  //	  cerr << "        star Not added to ccd"<<endl;
	}
	else {
	  if (verbose) {
	    real nx = xpos/arcsec_per_pixel;
	    real ny = ypos/arcsec_per_pixel;
	    if (nx>=-10 && nx<=XCCD_MAX && 
		ny>=-10 && ny<=YCCD_MAX+10) {
	      cerr << "Cluster star #" << bb->get_index() 
		   << " pos (x, y): " 
	           << nx << " " << ny << " pixels" << endl; 
	      cerr << "             magnitudes (M, m): "  
		   << 4.76 - 2.5*log10(luminosity)  - local_distance_modulus
 	           << " " << 4.76 - 2.5*log10(luminosity) <<endl;
	    }
	  }
	  add_star_to_ccd(ccd, luminosity, xpos, ypos, beta_PSF, 
			  arcsec_per_pixel, fwhm);
	}
      }
    }
Beispiel #14
0
int
main(int argc, char**argv)
{
    int i, k;
    int n;
    Forceinfo force;
    Nbodyinfo nbody;

    init_nbodyinfo(&nbody);

    vtc_init_cputime();
    parse_argv(argc, argv);
    if (snapin_flag == 0 && !initcond_flag) {
	fprintf(stderr, "snapshot input file required (-i)\n");
	show_usage(argv[0]);
    }
    if (initcond_flag) {
	create_initcond(&nbody, initn);
	tstart = 0.0;
    }
    else {
	if (ionemo_flag) {
	    read_binary(snapinfile, &tstart, &nbody);
	}
	else if (usepob_flag) {
	    read_pob(snapinfile, &tstart, &nbody);
	}
	else {
	    read_ascii(snapinfile, &tstart, &nbody);
	}
    }
    n = nbody.n;
    nbody.a = (double (*)[3])malloc(sizeof(double)*3*n);
    nbody.p = (double *)malloc(sizeof(double)*n);
    if (NULL == nbody.a || NULL == nbody.p) {
	perror("main");
	exit(1);
    }
    if (tstart > tend) {
	fprintf(stderr, "start time %f larger than end time %f. abort.\n",
		tstart, tend);
	exit(1);
    }
#if DIRECT /* direct sum */
    vtc_get_default_direct_params(&force); /* get current values */
#else /* tree */
    vtc_get_default_tree_params(&force); /* get current values */
#endif /* direct/tree */

    /* modify some of them */
    force.theta = theta;
    force.eps = eps;
    force.ncrit = ncrit;
    force.node_div_crit = node_div_crit;
    force.p = me_order;
    force.negativemass = negativemass;
    force.pprad = pprad;
    force.full_dof = full_dof_flag;
    if (grape_flag) {
	force.calculator = GRAPE_FORCEONLY;
	force.calculator = GRAPE;
    }
    force.test_id = test_id;

    PR(snapinfile,s); PRL(snapoutfile,s);
    PRL(n,d); 
    PR(eps, f); PR(theta, f); PR(ncrit, d); PRL(node_div_crit, d); 


    {
	double mmin = 1e10;
	double mmax = 0.0;
	for (i = 0; i < nbody.n; i++) {
	    if (mmin > nbody.m[i]) mmin = nbody.m[i];
	    if (mmax < nbody.m[i]) mmax = nbody.m[i];
	}
	fprintf(stderr, "mmin: %e mmax: %e\n", mmin, mmax);
    }


#if COSMO
    time_integration_loop_hubble(&force, &nbody);
#else
    time_integration_loop(&force, &nbody);
#endif
#if USE_GM_API
    fprintf(stderr, "will m2_gm_finalize...\n");
    m2_gm_finalize();
    fprintf(stderr, "done m2_gm_finalize.\n");
#endif /* USE_GM_API */
    exit(0);
}
Beispiel #15
0
static void
time_integration_loop(Forceinfo *fi, Nbodyinfo *nb)
{
    int i, nstep;
    int outsnapstep, outimagestep;
    double W, K, E0, E, Q;
    double cm[3], cmv[3];
    double t = tstart;

    nstep = (int)((tend-tstart)/dt+0.1);
    dt = (tend-tstart)/nstep;
    outsnapstep = (int) (dtsnapout/dt+0.1);
    outimagestep = (int) (dtimageout/dt+0.1);
    PR(tstart,f); PR(tend,f); PR(dt,f); PRL(dtsnapout,f); PRL(dtimageout,f);

    if (cputime_flag) {
	vtc_turnon_cputime();
    }
    vtc_init_cputime();
    vtc_print_cputime("initial vtc_get_force start at");

#if DIRECT /* direct sum */
    if (grape_flag) {
	vtc_set_scale(512.0, nb->m[0]);
#if MDGRAPE2
	fi->calculator = GRAPE_FORCEONLY;
#else
	fi->calculator = GRAPE;
#endif /* MDGRAPE2 */
	vtc_get_force_direct(fi, nb);
#if CALCPOTENTIAL && MDGRAPE2
        fi->calculator = GRAPE_POTENTIALONLY;
        vtc_get_force_direct(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif /* CALCPOTENTIAL && MDGRAPE2 */
    }
    else {
#if CALCPOTENTIAL
        fi->calculator = HOST;
#endif /* CALCPOTENTIAL */
	vtc_get_force_direct(fi, nb);
    }
#else /* tree */
    if (grape_flag) {
#if NOFORCE
	fi->calculator = NOCALCULATOR;
#elif MDGRAPE2
	fi->calculator = GRAPE_FORCEONLY;
#else
	fi->calculator = GRAPE;
#endif /* NOFORCE */
	vtc_get_force_tree(fi, nb);
#if CALCPOTENTIAL && MDGRAPE2
        fi->calculator = GRAPE_POTENTIALONLY;
        vtc_get_force_tree(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif /* CALCPOTENTIAL && MDGRAPE2 */
    }
    else {
#if CALCPOTENTIAL
        fi->calculator = HOST;
#endif /* CALCPOTENTIAL */
	vtc_get_force_tree(fi, nb);
    }
#endif
    vtc_print_cputime("initial vtc_get_force end at");
    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
	    fi->ninteraction, (double)fi->ninteraction/nb->n, fi->nwalk);
    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
    W = get_potential_energy(nb);
    E = E0 = W+K;
    PR(E0, 20.17f); PR(W, 20.17f);
#endif
    PRL(K, f);
    plot_nbody(t, nb);

    /* calculate force at T=0 and quit */
    if (snapout_flag && dtsnapout == 0.0) {
	static int nout = 0;
	char fn[255];
	snapout_acc_flag = 1;
	sprintf(fn, snapoutfile, nout);
	PRL(fn, s);
	if (ionemo_flag) {
	    write_binary(fn, t, nb);
	}
	else if (usepob_flag) {
	    write_pob(fn, t, nb);
	}
	else {
	    write_ascii(fn, t, nb);
	}
	vtc_print_cputime("exit at");
#if USE_GM_API
	fprintf(stderr, "will m2_gm_finalize...\n");
	m2_gm_finalize();
	fprintf(stderr, "done m2_gm_finalize.\n");
#endif /* USE_GM_API */
    }
    for (i = 0; i < nstep; i++) {
 	if (i%outlogstep == outlogstep - 1 && cputime_flag) {
	    vtc_turnon_cputime();
	}
	else {
	    vtc_turnoff_cputime();
	}

	fprintf(stderr, "step %d\n", i);
        push_velocity(0.5*dt, nb);
        push_position(dt, nb);
	t = tstart+(i+1)*dt;
	vtc_init_cputime();
#if DIRECT /* direct sum */
	vtc_get_force_direct(fi, nb);
#else /* tree */
	vtc_get_force_tree(fi, nb);
#endif
	vtc_print_cputime("vtc_get_force end at");
        push_velocity(0.5*dt, nb);
	vtc_print_cputime("integration end at");

	plot_nbody(t, nb);
 	if (i%outlogstep == outlogstep - 1) {
	    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
		    fi->ninteraction, fi->ninteraction/nb->n, fi->nwalk);
	    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
#if MDGRAPE2
	    if (grape_flag) {
		fi->calculator = GRAPE_POTENTIALONLY;
#if DIRECT /* direct sum */
		vtc_get_force_direct(fi, nb);
#else /* tree */
		vtc_get_force_tree(fi, nb);
#endif /* direct/tree */
		fi->calculator = GRAPE_FORCEONLY;
	    }
#endif /* MDGRAPE2 */
	    W = get_potential_energy(nb);
	    E = W+K;
	    Q = K/(K-E);
	    fprintf(stderr, "\nT= %f K= %20.17f Q= %20.17f E= %20.17f Eerr= %20.17f Eabserr= %20.17f\n",
		    t, K, Q, E, (E0-E)/E0, E0-E);
#else /* CALCPOTENTIAL */
	    fprintf(stderr, "\nT= %f K= %20.17f\n", t, K);
#endif /* CALCPOTENTIAL */
	    fprintf(stderr, "step: %d\n", i);
	    get_cmterms(nb, cm, cmv);
	    fprintf(stderr, "CM  %15.13e %15.13e %15.13e\n",
		    cm[0], cm[1], cm[2]);
	    fprintf(stderr, "CMV %15.13e %15.13e %15.13e\n",
		    cmv[0], cmv[1], cmv[2]);
 	}
	if (i%outsnapstep == outsnapstep - 1 && snapout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];

	    sprintf(fn, snapoutfile, nout);
	    PRL(fn, s);
	    if (ionemo_flag) {
		write_binary(fn, t, nb);
	    }
	    else if (usepob_flag) {
		write_pob(fn, t, nb);
	    }
	    else {
		write_ascii(fn, t, nb);
	    }

	    if (command_exec_flag) {
		sprintf(cmd, "%s %s %03d", command_name, fn, nout);
		fprintf(stderr, "execute %s\n", cmd);
		system(cmd);
	    }
	    nout++;
	    PR(t, f); PRL(fn, s);
	}
	if (i%outimagestep == outimagestep - 1 && imageout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];
	    char msg[255];
	    double center[2];

	    sprintf(fn, snapoutfile, nout);
	    strcat(fn, ".gif");
	    PRL(fn, s);

	    sprintf(msg, "t: %5.3f", t);
	    center[0] = 0.0;
	    center[1] = 0.0;
	    // vtc_plotstar(fn, nb, msg, image_scale, center, 1e10, NULL, NULL);
	    // vtc_plotstar(nb->x, nb->m, nb->n, t, image_scale, fn);
	    nout++;
	    PR(t, f); PRL(fn, s);
	}
	vtc_print_cputime("exit at");
    } /* i loop */
}
Beispiel #16
0
static void
time_integration_loop_hubble(Forceinfo *fi, Nbodyinfo *nb)
{
    double zval; /* red shift at T=0 */
    double tmpzz;
    double t, t0, dt1, tpresent;
    double W, K, E0, E, Q;
    double cm[3], cmv[3];
    int step = 0;
    double tsnapout, timageout;

    t = 0.0;
    tpresent = 16.0; /* present time must be 16.0 */
    zval = 24.0;
    tmpzz = pow(1.0/(zval+1), 3.0/2.0);
    t0 = tmpzz/(1.0-tmpzz)*tpresent;
    fi->eps = (zval+1)*pow(t0/(tpresent+t0), 2.0/3.0)*eps0;
    dt1 = dt0;

    tsnapout = dtsnapout;
    timageout = dtimageout;

    PR(t0, f); PR(dt0, f); PRL(dt1, f);

    PR(tstart,f); PR(tpresent,f); PR(dt,f); PRL(dtsnapout,f); PRL(dtimageout,f);

    if (cputime_flag) {
	vtc_turnon_cputime();
    }
    vtc_init_cputime();
    vtc_print_cputime("initial vtc_get_force start at");

#if DIRECT /* direct sum */
    if (grape_flag) {
	vtc_set_scale(512.0, nb->m[0]);
	fi->calculator = GRAPE_FORCEONLY;
	vtc_get_force_direct(fi, nb);
#if CALCPOTENTIAL
        fi->calculator = GRAPE_POTENTIALONLY;
	vtc_get_force_direct(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif
    }
    else {
	vtc_get_force_direct(fi, nb);
    }
#else /* tree */
    if (grape_flag) {
	fi->calculator = GRAPE_FORCEONLY;
	vtc_get_force_tree(fi, nb);
#if CALCPOTENTIAL
        fi->calculator = GRAPE_POTENTIALONLY;
        vtc_get_force_tree(fi, nb);
	fi->calculator = GRAPE_FORCEONLY;
#endif
    }
    else {
	vtc_get_force_tree(fi, nb);
    }
#endif /* direct/tree */
    vtc_print_cputime("initial vtc_get_force end at");
    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
	    fi->ninteraction, (double)fi->ninteraction/nb->n, fi->nwalk);
    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
    W = get_potential_energy(nb);
    E = E0 = W+K;
    PR(E0, f); PR(W, f);
#endif
    PRL(K, f);
    plot_nbody(t, nb);

    /* calculate force at T=0 and quit */
    if (snapout_flag && dtsnapout == 0.0) {
	static int nout = 0;
	char fn[255];
	snapout_acc_flag = 1;
	sprintf(fn, snapoutfile, nout);
	PRL(fn, s);
	if (ionemo_flag) {
	    write_binary(fn, t, nb);
	}
	else if (usepob_flag) {
	    write_pob(fn, t, nb);
	}
	else {
	    write_ascii(fn, t, nb);
	}
	vtc_print_cputime("exit at");
	return;
    }

    while (t < tend) {
	if (fi->eps < eps) {
	    double eps1;
	    eps1 = (zval+1)*pow((t+t0)/(tpresent+t0), 2.0/3.0)*eps0;
	    fi->eps = (eps1 < eps ? eps1 : eps);
	}
	else {
	    fi->eps = eps;
	}
	if (dt1 < dt) {
	    dt1 = dt0*(t+t0)/t0;
	}
	else {
	    dt1 = dt;
	}
 	if (step%outlogstep == outlogstep - 1 && cputime_flag) {
	    vtc_turnon_cputime();
	}
	else {
	    vtc_turnoff_cputime();
	}
        push_velocity(0.5*dt1, nb);
        push_position(dt1, nb);
	vtc_init_cputime();
#if DIRECT /* direct sum */
	vtc_get_force_direct(fi, nb);
#else /* tree */
	vtc_get_force_tree(fi, nb);
#endif /* direct/tree */
	vtc_print_cputime("vtc_get_force end at");
        push_velocity(0.5*dt1, nb);
	vtc_print_cputime("integration end at");

	plot_nbody(t, nb);
 	if (step%outlogstep == outlogstep - 1) {
	    fprintf(stderr, "ninteraction: %e list_len_avg: %6.5f nwalk: %d\n",
		    fi->ninteraction, fi->ninteraction/nb->n, fi->nwalk);
	    K = get_kinetic_energy(nb);
#if CALCPOTENTIAL
	    if (grape_flag) {
		fi->calculator = GRAPE_POTENTIALONLY;
#if DIRECT /* direct sum */
		vtc_get_force_direct(fi, nb);
#else /* tree */
		vtc_get_force_tree(fi, nb);
#endif /* direct/tree */
		fi->calculator = GRAPE_FORCEONLY;
	    }
	    W = get_potential_energy(nb);
	    E = W+K;
	    Q = K/(K-E);
	    fprintf(stderr, "\nT= %f K= %f Q= %f E= %f Eerr= %f Eabserr= %f\n",
		    t, K, Q, E, (E0-E)/E0, E0-E);
#else
	    fprintf(stderr, "\nT= %f K= %f\n", t, K);
#endif
	    fprintf(stderr, "step: %d\n", step);
	    fprintf(stderr, "T: %f current eps: %f dt: %f\n",
		    t, fi->eps, dt1);
	    get_cmterms(nb, cm, cmv);
	    fprintf(stderr, "CM  %15.13e %15.13e %15.13e\n",
		    cm[0], cm[1], cm[2]);
	    fprintf(stderr, "CMV %15.13e %15.13e %15.13e\n",
		    cmv[0], cmv[1], cmv[2]);
 	}
	if (tsnapout < t && snapout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];

	    sprintf(fn, snapoutfile, nout);
	    PRL(fn, s);
	    if (ionemo_flag) {
		write_binary(fn, t, nb);
	    }
	    else if (usepob_flag) {
		write_pob(fn, t, nb);
	    }
	    else {
		write_ascii(fn, t, nb);
	    }

	    if (command_exec_flag) {
		sprintf(cmd, "%s %s %03d", command_name, fn, nout);
		fprintf(stderr, "execute %s\n", cmd);
		system(cmd);
	    }
	    nout++;
	    PR(t, f); PRL(fn, s);
	    tsnapout += dtsnapout;
	}
	if (timageout < t && imageout_flag) {
	    static int nout = 0;
	    char fn[255];
	    char cmd[255];

	    sprintf(fn, snapoutfile, nout);
	    strcat(fn, ".gif");
	    PRL(fn, s);
	    vtc_plotstar(nb->x, nb->n, t, image_scale, fn);
	    nout++;
	    PR(t, f); PRL(fn, s);
	    timageout += dtimageout;
	}
	t += dt1;
	step++;
	vtc_print_cputime("exit at");
    } /* main loop */
}
Beispiel #17
0
MyScopedPtr<T>::MyScopedPtr(T *_resource) : resource(_resource)
{
  PRL(CONSTR_P);
}
Beispiel #18
0
MyScopedPtr<T>::~MyScopedPtr()
{
  PRL(DESTR);
  delete resource;
}
Beispiel #19
0
void refine_cluster_mass2(dyn *b,		// root node
			  int verbose)		// default = 0
{
    // Self-consistently determine the total mass within the outermost
    // closed zero-velocity surface under the specified external field(s).
    // Use a point-mass approximation for the cluster potential and iterate
    // until the actual mass within the surface agrees with the mass used
    // to generate the surface.
    //
    // This code is most likely to be called from refine_cluster_mass().

    // Quit if internal forces are to be neglected.

    if (b->get_ignore_internal()) return;

    // Do nothing if all we want is to set the dyn story and the current
    // values are up to date.

    if (verbose == 0
	&& twiddles(getrq(b->get_dyn_story(), "bound_center_time"),
		    b->get_system_time(), TTOL))
	return;

    unsigned int ext = b->get_external_field();
    if (!ext || b->get_tidal_field()) return;

    // Method assumes that the external field can be characterized as
    // depending on distance from a single point -- i.e. that it has a
    // single center -- and that it is independent of velocity.  OK to
    // have multiple external fields (e.g. central mass + power law),
    // so long as they have a common center.

    int bits_set = bitcount(ext);
    vec external_center = 0;

    if (bits_set != 1) {

	if (bits_set < 1)
	    
	    return;

	else {

	    // We have multiple external fields.  Check for common center.

	    cerr << "  refine_cluster_mass2: "; PRC(ext); PRL(bits_set);

	    int bit = 0, cbit = -1;
	    for (unsigned int i = ext; i != 0; i >>= 1, bit++) {
		if (i & 01) {
		    if (cbit < 0) {
			cbit = bit;
			external_center = b->get_external_center(cbit);
		    } else {
			if (!twiddles(square(b->get_external_center(bit)
					      - external_center),
				      0)) {
			    cerr << "  refine_cluster_mass2: center " << bit
				 << " inconsistent with center " << cbit
			         << endl;
			    return;
			}
		    }
		}
	    }
	    cerr << "  common center = " << external_center << endl;
	}

    } else