コード例 #1
0
ファイル: snaprholist.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  string prog, itags[MaxBodyFields];
  stream xstr;
  int nprof, nbody, nsamp;
  real *prof1, *prof2, rrange[2], tnow;
  bodyptr btab = NULL;

  initparam(argv, defv);
  layout_body(fields, Precision, NDIM);
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  xstr = execmap(prog);
  get_history(xstr);
  nprof = getiparam("nprof");
  prof1 = (real *) allocate((2 + nprof) * sizeof(real));
  prof2 = (real *) allocate((2 + nprof) * sizeof(real));
  setrange(rrange, getparam("rrange"));
  nsamp = 0;
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, FALSE)) {
    setprofile(prof1, prof2, nprof, rrange, btab, nbody);
    nsamp++;
  }
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getargv0(), prog);
  if (nsamp == 0)
    error("%s: no data in input\n", getargv0());
  listdensity(prof1, prof2, nprof, rrange, nsamp);
  return (0);
}
コード例 #2
0
ファイル: gsp.c プロジェクト: jasminegrosso/zeno
real r_mass_gsp(gsprof *gsp, real m)
{
    int n = gsp->npoint - 1, k = 0;

    if (m < 0 || m > gsp->mtot)
        error("%s.r_mass_gsp: undefined for m = %g\n", getargv0(), m);
    if (m < gsp->mass[0])
	return (gsp->radius[0] * rpow(m / gsp->mass[0], 1/(3+gsp->alpha)));
    else if (m > gsp->mass[n])
	return (gsp->radius[n] *
		  rpow((gsp->mtot - m) / (gsp->mtot - gsp->mass[n]),
		       1 / (3 + gsp->beta)));
    while (gsp->mass[k] == gsp->mass[k+1])
        k++;
    while (gsp->mass[n] == gsp->mass[n-1] ||
	   gsp->mass[n-1] == gsp->mass[n-2])
        n--;
    if (gsp->rm_coef == NULL) {
	gsp->rm_coef = (real *) allocate(3 * gsp->npoint * sizeof(real));
	if (k > 0 || n < gsp->npoint - 1)
	    eprintf("[%s.r_mass_gsp: spline range %d to %d]\n",
		    getargv0(), k, n);
	spline(gsp->rm_coef, gsp->mass + k, gsp->radius + k, n + 1 - k);
	if (isnan((double) gsp->rm_coef[0]))
	    error("%s.r_mass_gsp: spline fit undefined\n", getargv0());
    }
    return (seval(m, gsp->mass + k, gsp->radius + k, gsp->rm_coef, n + 1 - k));
}
コード例 #3
0
ファイル: snapforce.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
    stream istr, ostr;
    real eps2, tnow;
    int nforce, nbody, i;
    bodyptr btab = NULL;
    string intags[MaxBodyFields];

    initparam(argv, defv);
    layout_body(bodytags, Precision, NDIM);
    istr = stropen(getparam("in"), "r");
    get_history(istr);
    ostr = stropen(getparam("out"), "w");
    put_history(ostr);
    eps2 = rsqr(getdparam("eps"));
    nforce = -1;				/* use nforce as flag...    */
    while (get_snap(istr, &btab, &nbody, &tnow, intags, FALSE)) {
        if (nforce == -1 && ! set_member(intags, MassTag))
	    error("%s: Mass data missing from 1st snapshot\n", getargv0());
	if (! set_member(intags, PosTag))
	    error("%s: %s data missing\n", getargv0(), PosTag);
	if (nforce == -1)
	   nforce = (strnull(getparam("nforce")) ?
		       nbody : MIN(getiparam("nforce"), nbody));
	for (i = 0; i < nforce; i++)
	    sum1force(btab, nbody, i, eps2);
	put_snap(ostr, &btab, &nforce, &tnow, bodytags);
    }
    return (0);
}
コード例 #4
0
ファイル: snapgsp.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  stream istr, ostr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;
  string intags[MaxBodyFields];
  gsprof *gsp;

  initparam(argv, defv);
  layout_body(bodyfields, Precision, NDIM);
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  if (! get_snap(istr, &btab, &nbody, &tnow, intags, FALSE))
    error("%s: snapshot input failed\n", getargv0());
  if (! set_member(intags, PosTag))
    error("%s: position data missing\n", getargv0());
  if (! set_member(intags, MassTag))
    error("%s: mass data missing\n", getargv0());
  gsp = snapgsp(btab, nbody, getiparam("npoint"),
		getdparam("alpha"), getdparam("beta"));
  if (! strnull(getparam("out"))) {
    ostr = stropen(getparam("out"), "w");
    put_history(ostr);
    put_gsprof(ostr, gsp);
    strclose(ostr);
  }
  return (0);
}
コード例 #5
0
ファイル: snapobject.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
    stream istr, ostr;
    string itags[MaxBodyFields];

    initparam(argv, defv);
    new_field(&LinkField, IntType, LinkTag);	/* use int's worth of space */
    new_field(&LinkField + 1, NULL, NULL);
    layout_body(bodytags, Precision, NDIM);
    istr = stropen(getparam("in"), "r");
    get_history(istr);
    if (! get_snap(istr, &btab, &nbody, &tnow, itags, TRUE))
        error("%s: snapshot input failed\n", getargv0());
    if (! set_member(itags, PosTag))
        error("%s: %s data missing\n", getargv0(), PosTag);
    if (getbparam("subkey") && ! set_member(itags, KeyTag))
        error("%s: %s data missing\n", getargv0(), KeyTag);
    findobj(getdparam("bcrit"),	getiparam("nmin"), getbparam("subkey"));
    ostr = stropen(getparam("out"), "w");
    put_history(ostr);
    put_snap(ostr, &btab, &nbody, &tnow,
             set_union(itags, set_cons(KeyTag, NULL)));
    strclose(ostr);
    return (0);
}
コード例 #6
0
ファイル: gspdisk.c プロジェクト: jasminegrosso/zeno
real pickdist(real eta, real sigma)
{
  static real eta0 = -1.0, sigcorr;
  int niter;
  real x, y, q;

  if (eta != eta0) {
    sigcorr =
      rsqrt(8 * eta /
	      (bessel_K(0.75, 1/(32*eta)) / bessel_K(0.25, 1/(32*eta)) - 1));
    eprintf("[%s: sigma correction factor = %f]\n", getargv0(), sigcorr);
    eta0 = eta;
  }
  niter = 0;
  do {
    x = xrandom(-1.0, 1.0);
    y = xrandom(0.0, YMAX);
    q = rexp(- 0.5 * rsqr(fmap(x)) - eta * rsqr(rsqr(fmap(x)))) *
      (1 + x*x) / rsqr(1 - x*x);
    if (q > YMAX)				/* should not ever happen   */
      error("%s: guess out of bounds\n  x = %f  q = %f > %f\n",
	    getargv0(), x, q, YMAX);
    niter++;
    if (niter > 1000)
      error("%s: 1000 iterations without success\n", getargv0());
  } while (y > q || x*x == 1);			/* 2nd test prevents infty  */
  return (sigcorr * sigma * fmap(x));
}
コード例 #7
0
ファイル: snapview.c プロジェクト: joshuabarnes/zeno
void keyboard(unsigned char key, int x, int y)
{
    int i;

    switch (key) {
      case 27:
	exit(0);
        break;
      case 32:
        if (! getdata())
	    eprintf("[%s: at end of file]\n", getargv0());
        glutPostRedisplay();
	break;
      case 'a':
        eprintf("[%s: angles thetax=%.2f thetay=%.2f thetaz=%.2f]\n",
		getargv0(), thetax, thetay, thetaz);
	break;
      case 'b':
        eprintf("[%s: mouse buttons adjust %s, %s, %s]\n", getargv0(),
		butlabels[butbind[0]],
		butlabels[butbind[1]],
		butlabels[butbind[2]]);
	break;
      case 'm':
        butbind[2] = COLORMAP;
	break;
      case 'p':
        butbind[1] = PERSPECT;
	break;
      case 'r':
	mouseval[XYANGLES][0] = 0;
	mouseval[XYANGLES][1] = 0;
	mouseval[ZANGLE][0] = 0;
	glutPostRedisplay();
	break;
      case 'R':
        for (i = 0; i < NVALUES; i++)
            mouseval[i][0] = mouseval[i][1] = 0.0;
	glutPostRedisplay();
	break;
      case 's':
        butbind[2] = VSCALE;
	break;
      case 't':
        butbind[2] = TRANSLATE;
	break;
      case 'v':
	writeview();
	break;
      case 'z':
        butbind[1] = ZANGLE;
	break;
      default:
	eprintf("[%s: keystroke %d ignored]\n", getargv0(), (int) key);
    }
}
コード例 #8
0
ファイル: snaptestdisk.c プロジェクト: jasminegrosso/zeno
void readsphr(string name)
{
    stream instr;
    real tsnap;
    string infields[MaxBodyFields];

    instr = stropen(name, "r");
    get_history(instr);
    if (! get_snap(instr, &spheroid, &nspheroid, &tsnap, infields, FALSE))
        error("readsphr in %s: no data in input file\n", getargv0());
    strclose(instr);
    if (! (set_member(infields, MassTag) && set_member(infields, PosTag)))
        error("readsphr in %s: required data missing\n", getargv0());
}
コード例 #9
0
ファイル: gspmodel.c プロジェクト: jasminegrosso/zeno
void setauxvar(bodyptr btab, int nbody)
{
    bodyptr bp;
    vector jvec;
    real jtot, etot, r0, r1, r;

    if (streq(getparam("auxvar"), "mass"))
	for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp))
	    Aux(bp) = mass_gsp(ggsp, absv(Pos(bp)));
    else if (streq(getparam("auxvar"), "rperi"))
	for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
	    CROSSVP(jvec, Pos(bp), Vel(bp));
	    jtot = absv(jvec);
	    etot = 0.5 * dotvp(Vel(bp), Vel(bp)) + Phi(bp);
	    r0 = 0.0;
	    r1 = absv(Pos(bp));
	    r = 0.5 * (r0 + r1);
	    while ((r1 - r0) > TOL * r) {
		if (rsqrt(2 * (etot - phi_gsp(ggsp, r))) > jtot/r)
		    r1 = r;
		else
		    r0 = r;
		r = 0.5 * (r0 + r1);
	    }
	    Aux(bp) = r;
	}
    else
	error("%s: unknown auxvar option %s\n",
	      getargv0(), getparam("auxvar"));
}
コード例 #10
0
ファイル: snapobject.c プロジェクト: jasminegrosso/zeno
void findobj(real bcrit, int nmin, bool subkey)
{
    bodyptr p, q;
    int nobj;

    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) {
        Link(p) = p;
        Key(p) = (subkey && Key(p) == 0 ? -1 : 0);
    }
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
        if (Key(p) > -1)
            for (q = btab; q < p; q = NextBody(q))
                if (Key(q) > -1 && distv(Pos(p), Pos(q)) < bcrit)
                    linkpart(p, q);
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) {
        Link(p) = toplink(p);
        Key(Link(p))++;
    }
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
        if (Key(Link(p)) < nmin)
            Link(p) = NULL;
    nobj = 0;
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
        if (Link(p) == p)
            Key(p) = ++nobj;
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
        Key(p) = (Link(p) != NULL ? Key(Link(p)) : 0);
    eprintf("[%s: %d objects found at t = %.3f]\n", getargv0(), nobj, tnow);
}
コード例 #11
0
ファイル: code_io.c プロジェクト: Milkyway-at-home/nemo
restorestate(string file)
{
    stream str;
    string program, version;

    str = stropen(file, "r");			/* open state input file    */
    program = get_string(str, "program");
    version = get_string(str, "version");
    if (! streq(program, getargv0()) ||		/* check program, version   */
	  ! streq(version, getparam("VERSION")))
	printf("warning: state file may be outdated\n\n");
    headline = get_string(str, "headline");	/* read control parameters  */
    get_data(str, "freq", RealType, &freq, 0);
    get_data(str, "tol", RealType, &tol, 0);
    get_data(str, "eps", RealType, &eps, 0);
    get_data(str, "fcells", RealType, &fcells, 0);
    options = get_string(str, "options");
    get_data(str, "tstop", RealType, &tstop, 0);
    get_data(str, "freqout", RealType, &freqout, 0);
    get_data(str, "minor_freqout", RealType, &minor_freqout, 0);
    get_data(str, "tnow", RealType, &tnow, 0);	/* read state variables     */
    get_data(str, "tout", RealType, &tout, 0);
    get_data(str, "minor_tout", RealType, &minor_tout, 0);
    get_data(str, "nstep", IntType, &nstep, 0);
    get_data(str, "rmin", RealType, rmin, NDIM, 0);
    get_data(str, "rsize", RealType, &rsize, 0);
    get_data(str, "nbody", IntType, &nbody, 0);
    bodytab = (bodyptr) allocate(nbody * sizeof(body));
    if (bodytab == NULL)
	error("restorestate: not enuf memory\n");
    get_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0);
    strclose(str);
}
コード例 #12
0
ファイル: snapset.c プロジェクト: jasminegrosso/zeno
void execmap(string prog)
{
  int mappid, mapstat;
  char histbuf[512];

  mappid = fork();
  if (mappid == 0) {				// if this is child process
    sprintf(histbuf, "HISTORY=%s", *ask_history());
    execl(prog, getargv0(), getparam("in"), getparam("out"),
	  getparam("times"), getparam("require"), getparam("produce"),
	  getparam("passall"), getparam("seed"), histbuf, NULL);
    error("%s: execl %s failed\n", getargv0(), prog);
  }
  while (wait(&mapstat) != mappid)
    eprintf("[%s: waiting on subprocess %d]\n", getargv0(), mappid);
}
コード例 #13
0
ファイル: snapset.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  string *mdtab, *names, *exprs, prog;
  int nexp = 0, i, j;

  initparam(argv, defv);
  mdtab = getmapdefs();				// get list of mapping vars
  for (i = 0; mdtab[i] != NULL; i += 2)
    if (getparamstat(mdtab[i]) & ARGPARAM)	// if var has assigned value
      nexp++;
  eprintf("[%s: %scounted %d variable assignments]\n", getprog(),
	  nexp > 0 ? "" : "warning: ", nexp);
  names = (string *) allocate(sizeof(string *) * (nexp + 1));
  exprs = (string *) allocate(sizeof(string *) * (nexp + 1));
  for (i = j = 0; mdtab[i] != NULL; i += 2)
    if (getparamstat(mdtab[i]) & ARGPARAM) {	// if var has assigned value
      exprs[j] = getparam(mdtab[i]);		// list value given as expr
      names[j] = mdtab[i+1];			// and name of access macro
      j++;
    }
  exprs[j] = names[j] = NULL;
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, NULL,
	   strnull(getparam("t")) ? NULL : getparam("t"),
	   Precision, NDIM, TRUE);
  execmap(prog);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getargv0(), prog);
  return (0);
}
コード例 #14
0
ファイル: smooth.c プロジェクト: jasminegrosso/zeno
local int ball_gather(smxptr sm, real r2ball, real *ri)
{
    kdnode *ntab = sm->kd->ntab;
    bodyptr *bptr = sm->kd->bptr;
    int cp, nball, pj;
    real dist2;

    nball = 0;
    cp = KDROOT;
    do {
        Intersect(ntab[cp], r2ball, ri, GetNextCell);
						/* got intersection to test */
        if (cp < sm->kd->nsplit) {
            cp = Lower(cp);
            continue;
        } else {
            for (pj = ntab[cp].first; pj <= ntab[cp].last; ++pj) {
		DISTSQV(dist2, ri, Pos(bptr[pj]));
                if (dist2 < r2ball) {
                    sm->r2list[nball] = dist2;
                    sm->inlist[nball++] = pj;
                }
            }
        }
      GetNextCell:
        SetNext(cp);
    } while (cp != KDROOT);
    if (nball > sm->nsmooth + EXTLIST)
	error("%s: gathered list overflow\n", getargv0());
    return (nball);
}
コード例 #15
0
ファイル: gspsphere.c プロジェクト: jasminegrosso/zeno
void gspsphere(void)
{
    real gamma0, mcut, r, sig2, eint = 0.0;
    static real *sig2tab = NULL;
    bodyptr bp;

    nbody = getiparam("nbody");
    assert(nbody > 0);
    gamma0 = getdparam("gamma");
    mcut = getdparam("mcut");
    assert(0.0 < mcut && mcut <= 1.0);
    if (sig2tab == NULL)
        sig2tab = calc_sig2_gsp(gsp, ggsp, 0.0);
    if (btab == NULL)
        btab = (bodyptr) allocate(nbody * SizeofBody);
    for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) {
        Mass(bp) = gsp->mtot / nbody;
        r = r_mass_gsp(gsp, xrandom(0.0, mcut * gsp->mtot));
	pickshell(Pos(bp), NDIM, r);
	CLRV(Vel(bp));
	Rho(bp) = rho_gsp(gsp, r);
	sig2 = sig2_gsp(gsp, ggsp, 0.0, sig2tab, r);
        EntFunc(bp) = sig2 / rpow(Rho(bp), gamma0 - 1);
	Uintern(bp) = sig2 / (gamma0 - 1);
	eint += Mass(bp) * Uintern(bp);
    }
    eprintf("[%s: thermal energy = %f]\n", getargv0(), eint);
}
コード例 #16
0
ファイル: calcsig.c プロジェクト: jasminegrosso/zeno
real *calc_sig2_gsp(gsprof *testprof, gsprof *massprof, real beta_aniso)
{
    real *sig2, rsig[2], avgerr, maxerr, locerr;
    int n, i;

    tgsp = testprof;
    mgsp = massprof;
    beta_a = beta_aniso;
    sig2 = (real *) allocate(4 * tgsp->npoint * sizeof(real));
    n = tgsp->npoint - 1;
    rsig[0] = tgsp->radius[n];
    if (tgsp->density[n] > 0.0)
        rsig[1] = - mgsp->mtot / ((2*beta_a + tgsp->beta - 1) * rsig[0]) +
                  (mgsp->mtot - mass_gsp(mgsp, rsig[0])) /
                  ((2 * beta_a + mgsp->beta + tgsp->beta + 2) * rsig[0]);
    else
        rsig[1] = 0.0;
    sig2[n] = rsig[1];
    avgerr = maxerr = 0.0;
    for (i = n - 1; i >= 0; i--) {
        locerr = diffstep(rsig, rsig, 2, sigdiff, tgsp->radius[i] - rsig[0]);
        sig2[i] = rsig[1];
        avgerr = avgerr + locerr / n;
        maxerr = MAX(maxerr, locerr);
    }
    eprintf("[%s.calc_sig2_gsp:  avgerr = %f  maxerr = %f]\n",
            getargv0(), avgerr, maxerr);
    spline(sig2 + n + 1, tgsp->radius, sig2, n + 1);
    return (sig2);
}
コード例 #17
0
ファイル: snaprect.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  string prog, itags[MaxBodyFields], otags[MaxBodyFields];
  stream xstr, ostr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;

  initparam(argv, defv);
  exprs[0] = getparam("weight");
  prog = mktemp((string) copxstr("/tmp/sm_XXXXXX", sizeof(char)));
  buildmap(prog, names, exprs, types, NULL, Precision, NDIM, TRUE);
  xstr = execmap(prog);
  if (get_tag_ok(xstr, "History"))
    skip_item(xstr);
  get_history(xstr);
  ostr = stropen(getparam("out"), "w");
  put_history(ostr);
  new_field(&WeightField, RealType, "Weight");
  new_field(&WeightField + 1, NULL, NULL);
  while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE)) {
    snaprect(btab, nbody);
    del_tag(otags, itags, "Weight");
    put_snap(ostr, &btab, &nbody, &tnow, otags);
  }
  strclose(ostr);
  if (unlink(prog) != 0)
    error("%s: can't unlink %s\n", getargv0(), prog);
  return (0);
}
コード例 #18
0
ファイル: gspdisk.c プロジェクト: jasminegrosso/zeno
void listdisk(int nlist)
{
  int i;
  real r, phi, vcir, omega, Adisk, kappa, sigma1, sigma2,
       mu_eff, sig_r, sig_p, sig_z, vrad, vorb2, vorb;

  printf("#%5s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s\n",
	 "r", "vcir", "omega", "kappa", "sig_z", "sig_r", "sig_p", "vorb",
	 "Q", "rhomid", "fmax");
  for (i = 1; i <= nlist; i++) {			/* loop over radii  */
    r = (i * rcut) / ((real) nlist);
    vcir = seval(r, &rdtab[0], &vctab[0], &vctab[NTAB], NTAB);
    omega = vcir / r;
    Adisk = (omega - spldif(r, &rdtab[0], &vctab[0], &vctab[NTAB], NTAB)) / 2;
    if (omega - Adisk < 0.0)
      error("%s: kappa undefined (omega - Adisk < 0)\n"
	    "  r, omega, Adisk = %f %f %f\n", getargv0(), r, omega, Adisk);
    kappa = 2 * rsqrt(rsqr(omega) - Adisk * omega);
    sigma1 = rsqr(alpha1) * mdisk1 * rexp(- alpha1 * r) / TWO_PI;
    sigma2 = rsqr(alpha2) * mdisk2 * rexp(- alpha2 * r) / TWO_PI;
    mu_eff = (r_mu>0 ? 1 + (mu - 1) * (r / (r + r_mu)) : mu);
    sig_z = rsqrt(PI * (sigma1 + sigma2) * zdisk);
    sig_r = mu_eff * sig_z;
    sig_p = (0.5 * kappa / omega) * sig_r;
    vorb2 = rsqr(vcir) + rsqr(sig_r) * (1 - 2 * alpha1 * r) - rsqr(sig_p) +
      (r_mu>0 ? rsqr(sig_z) * r * mu_eff*(2*mu-2)*r_mu/rsqr(r+r_mu) : 0);
    vorb = rsqrt(MAX(vorb2, 0.0));
    printf("%6.4f %6.4f %6.2f %6.2f %6.4f %6.4f %6.4f %6.4f "
	   "%6.3f %6.1f %6.1f\n",
	   r, vcir, omega, kappa, sig_z, sig_r, sig_p, vorb,
	   kappa * sig_r / (3.358*(sigma1+sigma2)), sigma1/(2*zdisk),
	   sigma1 / (2*zdisk * rsqrt(rqbe(2*PI)) * sig_z*sig_r*sig_p));
  }
}
コード例 #19
0
ファイル: quadcode_io.c プロジェクト: Milkyway-at-home/nemo
int savestate(string file)
{
    stream str;

    str = stropen(file, "a");			/* open state output file   */
    fseek(str, 0L, 0);				/* rewind stream to origin  */
    put_string(str, "program", getargv0());
    put_string(str, "version", getparam("VERSION"));
    put_string(str, "headline", headline);	/* save control parameters  */
    put_data(str, "freq", RealType, &freq, 0);
    put_data(str, "mode", IntType, &mode, 0);
    put_data(str, "eps1", RealType, &eps1, 0);
    put_data(str, "eps2", RealType, &eps2, 0);
    put_string(str, "options", options);
    put_data(str, "tstop", RealType, &tstop, 0);
    put_data(str, "minor_freqout", RealType, &minor_freqout, 0);
    put_data(str, "freqout", RealType, &freqout, 0);
    put_data(str, "tnow", RealType, &tnow, 0);	/* save state variables     */
    put_data(str, "minor_tout", RealType, &minor_tout, 0);
    put_data(str, "tout", RealType, &tout, 0);
    put_data(str, "nbody", IntType, &nbody, 0);
    put_data(str, "bodytab", AnyType, bodytab, nbody, sizeof(body), 0);
    put_data(str, "qfld", AnyType, &qfld, sizeof(qfld), 0);
    strclose(str);
}
コード例 #20
0
ファイル: snaplist.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  string *datafields, *bodyfields, times, ifmt, rfmt;
  stream istr;
  bodyptr btab = NULL;
  int nbody;
  real tnow;
  string intags[MaxBodyFields];

  initparam(argv, defv);
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  datafields = burststring(getparam("fields"), ", ");
  if (set_member(datafields, TimeTag))
    bodyfields = set_diff(datafields, set_cons(TimeTag, NULL));
  else
    bodyfields = datafields;
  layout_body(bodyfields, Precision, NDIM);
  times = getparam("times");
  ifmt = getparam("ifmt");
  rfmt = getparam("rfmt");
  print_header(datafields, getparam("hfmt"), getparam("keyhead"),
	       burststring(getparam("auxhead"), ", "));
  while (get_snap_t(istr, &btab, &nbody, &tnow, intags, FALSE, times)) {
    if (! set_subset(intags, bodyfields))
      error("%s: one or more required fields not found\n", getargv0());
    print_data(btab, nbody, tnow, datafields, ifmt, rfmt);
    skip_history(istr);
  }
  return (0);
}
コード例 #21
0
ファイル: snaprotate.c プロジェクト: jasminegrosso/zeno
void rotate(snapshot *snap, string *tags, string *vecs, char axis,
	    real thetax, real thetay, real thetaz)
{
  matrix rmat;
  bodyptr bp;

  switch (tolower(axis)) {
    case 'x':
      xmatrix(rmat, thetax);
      break;
    case 'y':
      ymatrix(rmat, thetay);
      break;
    case 'z':
      zmatrix(rmat, thetaz);
      break;
    default:
      error("%s: unknown axis %c\n", getargv0(), axis);
  }
  if (set_member(tags, PosTag) && set_member(vecs, PosTag))
    for_all_bodies(bp, *snap)
      rotatevec(Pos(bp), rmat);
  if (set_member(tags, VelTag) && set_member(vecs, VelTag))
    for_all_bodies(bp, *snap)
      rotatevec(Vel(bp), rmat);
  if (set_member(tags, AccTag) && set_member(vecs, AccTag))
    for_all_bodies(bp, *snap)
      rotatevec(Acc(bp), rmat);
  if (set_member(tags, AuxVecTag) && set_member(vecs, AuxVecTag))
    for_all_bodies(bp, *snap)
      rotatevec(AuxVec(bp), rmat);
}
コード例 #22
0
ファイル: ftoc.c プロジェクト: Milkyway-at-home/nemo
void header(stream outstr)
{
    fprintf(outstr,"/* THIS FILE HAS BEEN CREATED BY %s - do not edit */\n\n",
            getargv0());
    fprintf(outstr,"#include <stdinc.h>\n\n");
    fprintf(outstr,"string defv[] = {\n");
}
コード例 #23
0
ファイル: treecode.c プロジェクト: jasminegrosso/zeno
local void testdata(void) {
  real rsc, vsc, r, v, x, y;
  bodyptr p;

  float scale = 1.0f;
  float vscale = 1.0f;
  float mscale = 1.0f;

  if (nbody < 1)				// check for silly values
    error("%s: absurd value for nbody\n", getargv0());
  bodytab = (bodyptr) allocate(nbody * sizeof(body));
						// alloc space for bodies
  rsc = (3 * PI) / 16;				// set length scale factor
  vsc = rsqrt(1.0 / rsc);			// find speed scale factor
  for (p = bodytab; p < bodytab+nbody; p++) {	// loop over particles
    Type(p) = BODY;				// tag as a body
    //Mass(p) = 1.0 / nbody;			// set masses equal
    // Set mass randomly, like in brute
    Mass(p) = (rand() / (float) RAND_MAX) * mscale;
    x = xrandom(0.0, MFRAC);			// pick enclosed mass
    r = 1.0 / rsqrt(rpow(x, -2.0/3.0) - 1);	// find enclosing radius
    pickshell(Pos(p), NDIM, rsc * r);		// pick position vector
    do {					// select from fn g(x)
      x = xrandom(0.0, 1.0);			// for x in range 0:1
      y = xrandom(0.0, 0.1);			// max of g(x) is 0.092
    } while (y > x*x * rpow(1 - x*x, 3.5));	// using von Neumann tech
    v = x * rsqrt(2.0 / rsqrt(1 + r*r));	// find resulting speed
    pickshell(Vel(p), NDIM, vsc * v);		// pick velocity vector
  }
  tnow = 0.0;					// set elapsed model time
}
コード例 #24
0
ファイル: gspdisk.c プロジェクト: jasminegrosso/zeno
void makedisk(void)
{
  real m, r, phi, vcir, omega, Adisk, kappa, sigma1, sigma2,
       mu_eff, sig_r, sig_p, sig_z, vrad, vorb2, vorb, vphi;
  double Trr = 0.0, Tpp = 0.0, Tzz = 0.0;
  int i;
  bodyptr dp;

  for (i = 0; i < ndisk; i++) {			/* loop initializing bodies */
    m = mdtab[NTAB-1] * ((real) i + 0.5) / ndisk;
    r = seval(m, &mdtab[0], &rdtab[0], &rdtab[NTAB], NTAB);
    vcir = seval(r, &rdtab[0], &vctab[0], &vctab[NTAB], NTAB);
    omega = vcir / r;
    Adisk = (omega - spldif(r, &rdtab[0], &vctab[0], &vctab[NTAB], NTAB)) / 2;
    if (omega - Adisk < 0.0)
      error("%s: kappa undefined (omega - Adisk < 0)\n"
	    "  r, omega, Adisk = %f %f %f\n", getargv0(), r, omega, Adisk);
    kappa = 2 * rsqrt(rsqr(omega) - Adisk * omega);
    sigma1 = rsqr(alpha1) * mdisk1 * rexp(- alpha1 * r) / TWO_PI;
    sigma2 = rsqr(alpha2) * mdisk2 * rexp(- alpha2 * r) / TWO_PI;
    mu_eff = (r_mu>0 ? 1 + (mu - 1) * (r / (r + r_mu)) : mu);
    sig_z = rsqrt(PI * (sigma1 + sigma2) * zdisk);
    sig_r = mu_eff * sig_z;
    sig_p = (0.5 * kappa / omega) * sig_r;
    vorb2 = rsqr(vcir) + rsqr(sig_r) * (1 - 2 * alpha1 * r) - rsqr(sig_p) +
      (r_mu>0 ? rsqr(sig_z) * r * mu_eff*(2*mu-2)*r_mu/rsqr(r+r_mu) : 0);
    vorb = rsqrt(MAX(vorb2, 0.0));
    dp = NthBody(disk, i);			/* set up ptr to disk body  */
    Mass(dp) = mdisk1 / ndisk;
    phi = xrandom(0.0, TWO_PI);
    Pos(dp)[0] = r * rsin(phi);
    Pos(dp)[1] = r * rcos(phi);
    Pos(dp)[2] = zdisk * ratanh(xrandom(-1.0, 1.0));
    vrad = (eta > 0 ? pickdist(eta, sig_r) : grandom(0.0, sig_r));
    vphi = (eta > 0 ? pickdist(eta, sig_p) : grandom(0.0, sig_p)) + vorb;
    Vel(dp)[0] = vrad * rsin(phi) + vphi * rcos(phi);
    Vel(dp)[1] = vrad * rcos(phi) - vphi * rsin(phi);
    Vel(dp)[2] = grandom(0.0, sig_z);
    Trr += Mass(dp) * rsqr(sig_r) / 2;
    Tpp += Mass(dp) * (rsqr(vorb) + rsqr(sig_p)) / 2;
    Tzz += Mass(dp) * rsqr(sig_z) / 2;
  }
  eprintf("[%s: Trr = %f  Tpp = %f  Tzz = %f]\n", getargv0(), Trr, Tpp, Tzz);
}
コード例 #25
0
ファイル: snapstack.c プロジェクト: jasminegrosso/zeno
void setvect(vector vect, string *values)
{
  int i;

  for (i = 0; i < NDIM; i++) {
    if (values[i] == NULL)
      error("%s: not enough values\n", getargv0());
    vect[i] = atof(values[i]);
  }
}
コード例 #26
0
ファイル: gspeval.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  stream fstr, istr, ostr;
  gsprof *gsp;
  bodyptr btab = NULL, p;
  int nbody;
  real tnow, r;
  string intags[MaxBodyFields];

  initparam(argv, defv);
  layout_body(bodyfields, Precision, NDIM);
  fstr = stropen(getparam("gsp"), "r");
  get_history(fstr);
  gsp = get_gsprof(fstr);
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  if (! get_snap(istr, &btab, &nbody, &tnow, intags, TRUE))
    error("%s: snapshot input failed\n", getargv0());
  if (! set_member(intags, PosTag))
    error("%s: position data missing\n", getargv0());
  if (streq(getparam("option"), "rho"))
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
      Aux(p) = rho_gsp(gsp, absv(Pos(p)));
  else if (streq(getparam("option"), "drho"))
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
      Aux(p) = drho_gsp(gsp, absv(Pos(p)));
  else if (streq(getparam("option"), "mass"))
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
      Aux(p) = mass_gsp(gsp, absv(Pos(p)));
  else if (streq(getparam("option"), "phi"))
    for (p = btab; p < NthBody(btab, nbody); p = NextBody(p))
      Aux(p) = phi_gsp(gsp, absv(Pos(p)));
  else 
    error("%s: unknown option %s\n", getargv0(), getparam("option"));
  if (! strnull(getparam("out"))) {
    ostr = stropen(getparam("out"), "w");
    put_history(ostr);
    put_snap(ostr, &btab, &nbody, &tnow, set_union(bodyfields, intags));
    strclose(ostr);
  }
  return (0);
}
コード例 #27
0
ファイル: snapshape.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  stream istr;
  string bodytags[] = { PosTag, NULL }, intags[MaxBodyFields];
  bodyptr btab = NULL, bp;
  int nbody, nshell, n;
  real tnow, vals[3];
  matrix tmpm, qmat;
  vector v1, v2, v3;

  initparam(argv, defv);
  istr = stropen(getparam("in"), "r");
  get_history(istr);
  layout_body(bodytags, Precision, NDIM);
  printf("#%11s %3s %11s %11s %11s\n",
	 "time", "n", "r_rms", "c/a", "b/a");
  while (get_snap(istr, &btab, &nbody, &tnow, intags, FALSE)) {
    if (! set_member(intags, PosTag))
      error("%s: %s data missing\n", getargv0(), PosTag);
    if (nbody % getiparam("nbin") != 0)
      error("%s: nbin does not divide number of bodies\n", getargv0());
    nshell = nbody / getiparam("nbin");
    for (n = 0; n < nbody; n += nshell) {
      CLRM(qmat);
      for (bp = NthBody(btab, n); bp < NthBody(btab, n + nshell);
	   bp = NextBody(bp)) {
	OUTVP(tmpm, Pos(bp), Pos(bp));
	ADDM(qmat, qmat, tmpm);
      }
      eigensolve(v1, v2, v3, vals, qmat);
      printf(" %11.6f %3d %11.6f %11.6f %11.6f\n",
	     tnow, n / nshell, rsqrt(tracem(qmat) / nshell),
	     rsqrt(vals[2] / vals[0]), rsqrt(vals[1] / vals[0]));
      if (getbparam("listvec")) {
	printf("#\t\t\t\t\t\t\t%8.5f  %8.5f  %8.5f\n", v1[0], v1[1], v1[2]);
	printf("#\t\t\t\t\t\t\t%8.5f  %8.5f  %8.5f\n", v2[0], v2[1], v2[2]);
	printf("#\t\t\t\t\t\t\t%8.5f  %8.5f  %8.5f\n", v3[0], v3[1], v3[2]);
      }
    }
  }
  return (0);
}
コード例 #28
0
ファイル: gspdisk.c プロジェクト: jasminegrosso/zeno
void setprof(void)
{
  int j;
  real r, msphr;

  rdtab[0] = mdtab[0] = vctab[0] = 0.0;
  for (j = 1; j < NTAB; j++) {
    r = rcut * rpow(((real) j) / (NTAB - 1), 2.0);
    rdtab[j] = r;
    mdtab[j] = 1 - rexp(- alpha1 * r) - alpha1 * r * rexp(- alpha1 * r);
    msphr = (sphr != NULL ? mass_gsp(sphr, r) : 0.0);
    vctab[j] = rsqrt(msphr / r - gdisk(r) * r);
  }
  eprintf("[%s: rcut = %8.4f/alpha  M(rcut) = %8.6f mdisk]\n",
	  getargv0(), rdtab[NTAB-1] * alpha1, mdtab[NTAB-1]);
  if ((mdtab[0] == mdtab[1]) || (mdtab[NTAB-2] == mdtab[NTAB-1]))
      error("%s: disk mass table is degenerate\n", getargv0());
  spline(&rdtab[NTAB], &mdtab[0], &rdtab[0], NTAB);	/* for r_d = r_d(m) */
  spline(&vctab[NTAB], &rdtab[0], &vctab[0], NTAB);	/* for v_c = v_c(r) */
}
コード例 #29
0
ファイル: gspdisk.c プロジェクト: jasminegrosso/zeno
int main(int argc, string argv[])
{
  float tmp1, tmp2;

  initparam(argv, defv);
  if (sscanf(getparam("mdisk"), "%f,%f", &tmp1, &tmp2) == 2) {
    mdisk1 = tmp1;
    mdisk2 = tmp2;
    if (sscanf(getparam("alpha"), "%f,%f", &tmp1, &tmp2) != 2)
      error("%s: must specify two alpha values\n", getargv0());
    alpha1 = tmp1;
    alpha2 = tmp2;
    if (sscanf(getparam("epsilon"), "%f,%f", &tmp1, &tmp2) != 2)
      error("%s: must specify two epsilon values\n", getargv0());
    epsilon1 = tmp1;
    epsilon2 = tmp2;
  } else {
    mdisk1 = getdparam("mdisk");
    mdisk2 = 0.0;
    alpha1 = getdparam("alpha");
    alpha2 = 12.0;			 /* nonzero value stops div by zero */
    epsilon1 = getdparam("epsilon");
    epsilon2 = -1.0;
  }
  zdisk = getdparam("zdisk");
  mu = getdparam("mu");
  r_mu = getdparam("r_mu");
  eta = getdparam("eta");
  rcut = getdparam("rcut");
  readgsp();
  setprof();
  layout_body(bodyfields, Precision, NDIM);
  ndisk = getiparam("ndisk");
  disk = (bodyptr) allocate(ndisk * SizeofBody);
  init_random(getiparam("seed"));
  if (getiparam("nlist") > 0)
    listdisk(getiparam("nlist"));
  makedisk();
  writemodel();
  return (0);
}
コード例 #30
0
ファイル: snaprholist.c プロジェクト: jasminegrosso/zeno
stream execmap(string prog)
{
  int handle[2];
  char handbuf[32];
  string names[] = { MassTag, NULL }, exprs[] = { NULL, NULL };

  exprs[0] = getparam("mass");
  buildmap(prog, names, exprs, NULL, NULL, Precision, NDIM, TRUE);
  pipe(handle);
  if (fork() == 0) {                            // if this is child process
    close(handle[0]);
    sprintf(handbuf, "-%d", handle[1]);
    execl(prog, getargv0(), getparam("in"), handbuf, getparam("times"),
	  getparam("require"), MassTag "," PosTag,
	  strnull(getparam("require")) ? "true" : "false",
	  getparam("seed"), NULL);
    error("%s: execl %s failed\n", getargv0(), prog);
  }
  close(handle[1]);
  sprintf(handbuf, "-%d", handle[0]);
  return (stropen(handbuf, "r"));
}