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); }
void nemo_main(void) /* this replaces main(argc,argv) <--- required */ { stream instr, outstr; string times = getparam("times"); real tsnap; Body *btab = NULL, *bp; int i, nbody, bits; bool first = TRUE; instr = stropen(getparam("in"), "r"); outstr = stropen(getparam("out"), "w"); for (;;) { /* infinite loop, broken only when ran out of snapshots */ get_history(instr); /* read history */ if (!get_tag_ok(instr, SnapShotTag)) break; /* check if done */ get_snap(instr, &btab, &nbody, &tsnap, &bits); /* get next */ /* Operate on the snapshot here : */ for (bp=btab, i=0; i<nbody; bp++, i++) { /* all the work goes here */ } if (first) { put_history(outstr); first = FALSE; } put_snap(outstr, &btab, &nbody, &tsnap, &bits); /* output */ } strclose(instr); if (first) { warning("No snapshots processed"); strdelete(outstr,TRUE); } else strclose(outstr); }
nemo_main() { stream instr, quadstr, outstr; Body *btab = NULL, *bp; int nbody, bits; real eps_r, eps_t, tsnap = 0.0; if (!hasvalue("out")) warning("No output supplied (out=)"); quadstr = stropen(getparam("quad"), "r"); get_history(quadstr); instr = stropen(getparam("in"), "r"); get_history(instr); get_quadfield(quadstr, &eps_r, &eps_t); get_snap(instr, &btab, &nbody, &tsnap, &bits); if (bits & PhaseSpaceBit == 0) error("not enuf info: bits = %o", bits); for (bp = btab; bp < btab+nbody; bp++) { CLRV(Acc(bp)); Phi(bp) = 0.0; } quadinter(btab, nbody, eps_r, eps_t); if (hasvalue("out")) { outstr = stropen(getparam("out"), "w"); put_history(outstr); bits = bits | PotentialBit | AccelerationBit; put_snap(outstr, &btab, &nbody, &tsnap, &bits); } }
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); }
int main(int argc, string argv[]) { stream outstr; int nmodel; real tzero = 0.0; initparam(argv, defv); layout_body(bodyfields, Precision, NDIM); nbody = getiparam("nbody"); nmodel = getiparam("nmodel"); if (nbody < 1 || nmodel < 1) error("%s: absurd value for nbody or nmodel\n", getprog()); btab = (bodyptr) allocate(nbody * SizeofBody); init_random(getiparam("seed")); outstr = stropen(getparam("out"), "w"); put_history(outstr); while (--nmodel >= 0) { plummodel(getdparam("mfrac")); if (getbparam("besort")) qsort(btab, nbody, SizeofBody, berank); if (getbparam("zerocm")) snapcenter(btab, nbody, MassField.offset); put_snap(outstr, &btab, &nbody, &tzero, bodyfields); fflush(outstr); } return (0); }
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); }
int main(int argc, string argv[]) { string prog, itags[MaxBodyFields]; stream xstr, ostr; int nold = -1; initparam(argv, defv); exprs[0] = getparam("group"); 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(&GroupField, IntType, "Group"); new_field(&GroupField + 1, NULL, NULL); layout_body(btags, Precision, NDIM); while (get_snap(xstr, &bodytab, &nbody, &tbody, itags, FALSE)) { snaptrak(); put_snap(ostr, &traktab, &ntrak, &tbody, otags); if (ntrak != nold) eprintf("[%s: wrote %d groups at t = %f]\n", getprog(), ntrak, tbody); nold = ntrak; } strclose(ostr); if (unlink(prog) != 0) error("%s: can't unlink %s\n", getprog(), prog); return (0); }
writegalaxy(stream outstr) { real tsnap = 0.0; int bits = MassBit | PhaseSpaceBit | TimeBit; if (Qkey) bits |= KeyBit; put_snap(outstr, &disk, &ndisk, &tsnap, &bits); }
void nemo_main() { stream instr, outstr; string times, ctypei, ctypeo; real tsnap; int i, nbody, bits, mode; Body *btab = NULL, *bp; proc transform, trans2; times = getparam("times"); ctypei = getparam("ctypei"); ctypeo = getparam("ctypeo"); if (streq(ctypei,"cart") && streq(ctypeo,"sph")) transform = cartesian_spherical; else if (streq(ctypei,"sph") && streq(ctypeo,"cart")) transform = spherical_cartesian; else if (streq(ctypei,"cart") && streq(ctypeo,"cyl")) transform = cartesian_cylindrical; else if (streq(ctypei,"cyl") && streq(ctypeo,"cart")) transform = cylindrical_cartesian; else error("Unimplemented ctype i/o : %s -> %s",ctypei,ctypeo); dprintf(0,"converting from %s to %s\n",ctypei,ctypeo); instr = stropen(getparam("in"), "r"); outstr = stropen(getparam("out"), "w"); get_history(instr); put_history(outstr); for (;;) { get_history(instr); /* skip over stuff we can forget */ if (!get_tag_ok(instr, SnapShotTag)) break; /* done with work in loop */ get_snap(instr, &btab, &nbody, &tsnap, &bits); if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) { continue; /* just skip it's probably a diagnostics */ } if ((bits & TimeBit) == 0) tsnap = 0.0; else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ)) continue; dprintf (1,"Transforming snapshot at time= %f bits=0x%x\n",tsnap,bits); #if 0 Qmass = MassBit & bits; Qphase = PhaseSpaceBit & bits; Qacc = AccelerationBit & bits; Qaux = AuxBit & bits; Qkey = KeyBit & bits; #endif for (bp = btab; bp < btab+nbody; bp++) { (transform)(Pos(bp),Vel(bp),Acc(bp)); } put_snap(outstr, &btab, &nbody, &tsnap, &bits); } }
void writemodel(void) { stream ostr; real tsnap = 0.0; ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &disk, &ndisk, &tsnap, bodyfields); }
void writegal(string name) { stream outstr; real tsnap = 0.0; outstr = stropen(name, "w"); put_history(outstr); put_snap(outstr, &galaxy, &ngalaxy, &tsnap, bodyfields); strclose(outstr); }
int main(int argc, string argv[]) { string prog, coords, itags[MaxBodyFields], otags[MaxBodyFields]; stream xstr, ostr; bodyptr btab = NULL, bp; int nbody; real tnow; vector cmpos, cmvel, cmacc; 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); coords = getparam("coords"); new_field(&WeightField, RealType, "Weight"); new_field(&WeightField + 1, NULL, NULL); while (get_snap(xstr, &btab, &nbody, &tnow, itags, TRUE, NULL)) { if (scanopt(coords, PosTag) && set_member(itags, PosTag)) { snapcmpos(cmpos, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Pos(bp), Pos(bp), cmpos); } eprintf("[%s: centroid position: %f,%f,%f]\n", getprog(), cmpos[0], cmpos[1], cmpos[2]); } if (scanopt(coords, VelTag) && set_member(itags, VelTag)) { snapcmvel(cmvel, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Vel(bp), Vel(bp), cmvel); } eprintf("[%s: centroid velocity: %f,%f,%f]\n", getprog(), cmvel[0], cmvel[1], cmvel[2]); } if (scanopt(coords, AccTag) && set_member(itags, AccTag)) { snapcmacc(cmacc, btab, nbody, WeightField.offset); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Acc(bp), Acc(bp), cmacc); } eprintf("[%s: cen. acceleration: %f,%f,%f]\n", getprog(), cmacc[0], cmacc[1], cmacc[2]); } 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", getprog(), prog); return (0); }
void writemodel(void) { stream ostr; real tsnap = 0.0; if (! strnull(getparam("out"))) { ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tsnap, bodyfields); strclose(ostr); } }
local void writesnap(string name, string headline) { stream outstr; real tzero = getdparam("time"); int bits = MassBit | PhaseSpaceBit | TimeBit; if (! streq(headline, "")) set_headline(headline); outstr = stropen(name, "w"); put_history(outstr); put_snap(outstr, &disktab, &ndisk, &tzero, &bits); strclose(outstr); }
void writemodel(void) { stream ostr; real tsnap = 0.0; string outfields[] = { PosTag, VelTag, MassTag, PhiTag, AuxTag, NULL }; if (! strnull(getparam("out"))) { if (strnull(getparam("auxvar"))) outfields[3] = NULL; ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tsnap, outfields); strclose(ostr); } }
output() { int nttot, nbavg, ncavg, k, bits; diagnostics(); /* compute std diagnostics */ nttot = n2bcalc + nbccalc; nbavg = (int) ((real) n2bcalc / (real) nfcalc); ncavg = (int) ((real) nbccalc / (real) nfcalc); printf("\n %10s%10s%10s%10s%10s%10s%10s\n", "tnow", "T+U", "T/U", "nttot", "nbavg", "ncavg", "cputime"); printf(" %10.3f%10.4f%10.4f%10d%10d%10d%10.2f\n\n", tnow, etot[0], etot[1]/etot[2], nttot, nbavg, ncavg, cputime()); printf("\t %10s", "cm pos"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[0][k]); printf("\n\t %10s", "cm vel"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[1][k]); printf("\n"); bits = 0; /* collect output bit flags */ if (minor_freqout > 0.0 && (minor_tout - 0.01/freq) <= tnow) { minor_tout += 1.0 / minor_freqout; bits |= TimeBit; } if (freqout > 0.0 && (tout - 0.01/freq) <= tnow) { tout += 1.0 / freqout; bits |= TimeBit | PhaseSpaceBit; if (scanopt(options, "mass") || firstmass) { bits |= MassBit; firstmass = FALSE; } if (scanopt(options, "phi")) bits |= PotentialBit; if (scanopt(options, "acc")) bits |= AccelerationBit; } if (bits != 0 && outstr != NULL) { /* output ready and able? */ put_snap(outstr, &bodytab, &nbody, &tnow, &bits); if (bits & PhaseSpaceBit) printf("\n\tparticle data written\n"); } if (*savefile) /* state file specified? */ savestate(savefile); /* save system data */ }
void nemo_main(void) { int i; char name[20]; instr = stropen(getparam("in"), "r"); if (hasvalue("out")) outstr = stropen(getparam("out"), "w"); if (hasvalue("headline")) set_headline(getparam("headline")); if (outstr) put_history(outstr); bits = TimeBit | PhaseSpaceBit | KeyBit; while (in_header()) { /* loop reading data frames */ snapcnt++; if (outstr) put_snap(outstr, &btab, &nbody, &tsnap, &bits); } if (outstr) strclose(outstr); }
void output() { int k, bits; diagnostics(); printf("\n %12s%12s%12s%12s\n", "tnow", "T+U", "T/U", "cputime"); printf(" %12.3f%12.6f%12.4f%12.2f\n\n", tnow, etot[0], etot[1]/etot[2], cputime()); printf("\t %10s", "cm pos"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[0][k]); printf("\n\t %10s", "cm vel"); for (k = 0; k < NDIM; k++) printf("%10.4f", cmphase[1][k]); printf("\n"); bits = 0; if (minor_freqout > 0.0 && (minor_tout - 0.01/freq) <= tnow) { minor_tout += 1.0 / minor_freqout; bits |= TimeBit; } if (freqout > 0.0 && (tout - 0.01/freq) <= tnow) { tout += 1.0 / freqout; bits |= TimeBit | PhaseSpaceBit; if (firstmass || scanopt(options, "mass")) bits |= MassBit; firstmass = FALSE; if (scanopt(options, "phi")) bits |= PotentialBit; if (scanopt(options, "acc")) bits |= AccelerationBit; } if (bits != 0 && outstr != NULL) { put_snap(outstr, &bodytab, &nbody, &tnow, &bits); if (bits & PhaseSpaceBit) printf("\n\tparticle data written\n"); } if ((bits & PhaseSpaceBit) != 0 && quadstr != NULL) put_quadfield(quadstr); if (*savefile) /* state file specified? */ savestate(savefile); /* save system data */ }
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); }
nemo_main() { stream instr, outstr; real tsnap, mscale; Body *btab = NULL, *bp; int i, j, n, nbody, nbodymass, bits, bitsmass, seed; rproc bfunc, btrtrans(); instr = stropen(getparam("in"), "r"); outstr = hasvalue("out") ? stropen(getparam("out"),"w") : NULL; n = getiparam("iter"); get_history(instr); if (!get_tag_ok(instr, SnapShotTag)) error("not a snapshot"); get_snap(instr, &btab, &nbody, &tsnap, &bits); if (getbparam("bodytrans")) { dprintf(0,"bodytrans scaling, iter=%d\n",n); bfunc = btrtrans(getparam("mass")); /* use bodytrans expression */ for (j=0; j<n; j++) for (bp=btab, i=0; i<nbody; bp++,i++) Mass(bp) = bfunc(bp, tsnap, i); } else { dprintf(0,"simple inline scaling, iter=%d\n",n); mscale = getdparam("mass"); for (j=0; j<n; j++) for (bp=btab, i=0; i<nbody; bp++,i++) Mass(bp) = mscale*Mass(bp); } strclose(instr); if (outstr) { put_history(outstr); put_snap(outstr, &btab, &nbody, &tsnap, &bits); strclose(outstr); } }
int main(int argc, string argv[]) { stream istr, ostr; string times, *produce, itags[MaxBodyFields], atags[MaxBodyFields]; bodyptr btab = NULL; int nbody, ntag, i; real tsnap; bool expand; initparam(argv, defv); istr = stropen(getparam("in"), "r"); get_history(istr); times = getparam("times"); expand = streq(getparam("produce"), "*"); if (! expand) { produce = burststring(getparam("produce"), ", "); layout_body(produce, Precision, NDIM); } atags[ntag = 0] = NULL; while (get_snap_t(istr, &btab, &nbody, &tsnap, itags, expand, times)) { for (i = 0; itags[i] != NULL; i++) if (! set_member(atags, itags[i])) { atags[ntag++] = itags[i]; atags[ntag] = NULL; } get_history(istr); } if (! expand) { for (i = 0; produce[i] != 0; i++) if (! set_member(atags, produce[i])) error("%s: field %s missing\n", getargv0(), produce[i]); } else produce = atags; ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tsnap, produce); strclose(ostr); return (0); }
int main(int argc, string argv[]) { stream outstr = NULL; int nmodel; real tzero = 0.0; initparam(argv, defv); layout_body(bodyfields, Precision, NDIM); npol = getdparam("n"); mpol = getdparam("m"); nbody = getiparam("nbody"); btab = (bodyptr) allocate(nbody * SizeofBody); init_random(getiparam("seed")); nmodel = getiparam("nmodel"); if (! ((npol == 1.0 && mpol == -1.0) || (npol == 0.5 && mpol == -0.5))) polysolve(getdparam("hstep"), getbparam("listmodel")); if (! strnull(getparam("out"))) { outstr = stropen(getparam("out"), "w"); put_history(outstr); } while (--nmodel >= 0) { if (npol == 1.0 && mpol == -1.0) polymodel1(); else if (npol == 0.5 && mpol == -0.5) polymodel2(); else polymodel(); if (getbparam("besort")) qsort(btab, nbody, SizeofBody, berank); if (getbparam("zerocm")) snapcenter(btab, nbody, MassField.offset); if (outstr != NULL) put_snap(outstr, &btab, &nbody, &tzero, bodyfields); fflush(outstr); } return (0); }
int main(int argc, string argv[]) { stream istr, ostr; string itags1[MaxBodyFields], itags2[MaxBodyFields]; string *produce, *otags; bodyptr btab1 = NULL, btab2 = NULL, btab; int nbody1, nbody2, nbody; real tsnap; initparam(argv, defv); if (! streq(getparam("produce"), "*")) { produce = burststring(getparam("produce"), ", "); layout_body(produce, Precision, NDIM); } else produce = NULL; istr = stropen(getparam("in1"), "r"); get_history(istr); if (! get_snap(istr, &btab1, &nbody1, &tsnap, itags1, produce == NULL)) error("%s: no data in 1st input file\n"); istr = stropen(getparam("in2"), "r"); get_history(istr); if (! get_snap(istr, &btab2, &nbody2, &tsnap, itags2, FALSE)) error("%s: no data in 2nd input file\n"); otags = set_inter(itags1, itags2); if (produce != NULL) checktags(otags, produce); eprintf("[%s: nbody = %d + %d]\n", getargv0(), nbody1, nbody2); nbody = nbody1 + nbody2; btab = (bodyptr) allocate(SizeofBody * nbody); snapstack(btab, btab1, nbody1, btab2, nbody2, otags); ostr = stropen(getparam("out"), "w"); put_history(ostr); put_snap(ostr, &btab, &nbody, &tsnap, otags); strclose(ostr); return (0); }
int main(int argc, string argv[]) { string *produce, snap_tags[MaxBodyFields], frame_tags[MaxBodyFields]; snapshot *snaplist = NULL, *ssp, frame = { NULL, 0, 0.0, NULL }; stream instr, outstr; int n, nbody, i; bodyptr btab, bp, sp; bool roff, voff; initparam(argv, defv); produce = burststring(getparam("produce"), ", "); layout_body(produce, Precision, NDIM); instr = stropen(getparam("in"), "r"); get_history(instr); snaplist = ssp = (snapshot *) allocate(sizeof(snapshot)); n = nbody = 0; while (get_snapshot(instr, *ssp, snap_tags, FALSE)) { if (! set_equal(snap_tags, produce)) error("%s: input file lacks required items\n", getprog()); n++; nbody += ssp->nbody; get_history(instr); ssp->link = (snapshot *) allocate(sizeof(snapshot)); ssp = ssp->link; } strclose(instr); eprintf("[%s: read %d frames, %d bodies]\n", getprog(), n, nbody); if (! strnull(getparam("frame"))) { instr = stropen(getparam("frame"), "r"); get_history(instr); if (! get_snapshot(instr, frame, frame_tags, FALSE)) error("%s: no snapshot in frame file\n", getprog()); strclose(instr); if (frame.nbody < n) error("%s: need at least %d points in frame\n", getprog(), n); } roff = (frame.nbody > 0) && set_member(frame_tags, PosTag); voff = (frame.nbody > 0) && set_member(frame_tags, VelTag); bp = btab = (bodyptr) allocate(nbody * SizeofBody); ssp = snaplist; for (i = 0; i < n; i++) { sp = ssp->bodies; while (sp < NthBody(ssp->bodies, ssp->nbody)) { memmove((void *) bp, (void *) sp, (size_t) SizeofBody); if (roff) { ADDV(Pos(bp), Pos(bp), Pos(NthBody(frame.bodies, i))); } if (voff) { ADDV(Vel(bp), Vel(bp), Vel(NthBody(frame.bodies, i))); } bp = NextBody(bp); sp = NextBody(sp); } ssp = ssp->link; } outstr = stropen(getparam("out"), "w"); put_history(outstr); put_snap(outstr, &btab, &nbody, &frame.time, produce); strclose(outstr); return (0); }
int main(int argc, string argv[]) { stream istr, ostr, gstr; real tnow, tgrav, eps2, tstop, dtime, tout, Mhqm, ahqm, bhqm, tol; real decrit, epot0, demin, demax, derms, de2avg, enow, denow; int nbody, ngrav; bodyptr btab = NULL, gtab = NULL, bp; string bdtags[MaxBodyFields], grtags[MaxBodyFields], *optags; gsprof *gravgsp = NULL; bool decrit_inc = FALSE; initparam(argv, defv); new_field(&EinitPBF, RealType, EinitTag); // define initial energy field layout_body(bodytags, Precision, NDIM); // layout necessary fields istr = stropen(getparam("in"), "r"); get_history(istr); if (! get_snap(istr, &btab, &nbody, &tnow, bdtags, TRUE)) error("%s: can't read input snapshot\n", getprog()); if (! (set_member(bdtags, PosTag) && set_member(bdtags, VelTag))) error("%s: required data missing from input snapshot\n", getprog()); #if defined(NBDGRAV) gstr = stropen(getparam("grav"), "r"); get_history(gstr); if (! get_snap(gstr, >ab, &ngrav, &tgrav, grtags, FALSE)) error("%s: can't read gravity snapshot\n", getprog()); if (! (set_member(grtags, MassTag) && set_member(grtags, PosTag))) error("%s: required data missing from gravity snapshot\n", getprog()); eps2 = rsqr(getdparam("eps")); #elif defined(GSPGRAV) gstr = stropen(getparam("grav"), "r"); get_history(gstr); gravgsp = get_gsprof(gstr); // read GSP for grav. field #elif defined(HQMGRAV) Mhqm = getdparam("M"); ahqm = getdparam("a"); bhqm = getdparam("b"); tol = getdparam("tol"); #endif ostr = stropen(getparam("out"), "w"); put_history(ostr); tstop = getdparam("tstop"); dtime = getdparam("dtime"); decrit = getdparam("decrit"); optags = burststring(getparam("outputs"), ","); #if defined(NBDGRAV) sumforces(btab, nbody, gtab, ngrav, eps2); // prime the pump... #elif defined(GSPGRAV) gspforces(btab, nbody, gravgsp); #elif defined(HQMGRAV) hqmforces(btab, nbody, Mhqm, ahqm, bhqm, tol); #endif epot0 = 0.0; // use as energy scale for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { epot0 += Phi(bp) / nbody; // compute avg. potential Einit(bp) = Phi(bp) + dotvp(Vel(bp), Vel(bp)) / 2; } eprintf("[%s: initial average potential = %g]\n", getprog(), epot0); put_snap(ostr, &btab, &nbody, &tnow, optags); fflush(NULL); tout = tnow + getdparam("dtout"); demin = demax = derms = 0.0; // track maximum errors while (tnow < tstop) { // enter main loop for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { ADDMULVS(Vel(bp), Acc(bp), 0.5 * dtime); // step velocities by dt/2 ADDMULVS(Pos(bp), Vel(bp), dtime); // step positions by dt } tnow = tnow + dtime; // step time to new value #if defined(NBDGRAV) if (! getbparam("frozen")) if (! get_snap(gstr, >ab, &ngrav, &tgrav, grtags, TRUE)) error("%s: can't read gravity snapshot\n", getprog()); sumforces(btab, nbody, gtab, ngrav, eps2); // get new accelerations #elif defined(GSPGRAV) gspforces(btab, nbody, gravgsp); #elif defined(HQMGRAV) hqmforces(btab, nbody, Mhqm, ahqm, bhqm, tol); #endif de2avg = 0.0; for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { ADDMULVS(Vel(bp), Acc(bp), 0.5 * dtime); // step velocities by dt/2 enow = 0.5 * dotvp(Vel(bp), Vel(bp)) + Phi(bp); denow = (enow - Einit(bp)) / ABS(epot0); // compute rel. energy change demin = MIN(demin, denow); demax = MAX(demax, denow); de2avg += rsqr(denow) / nbody; } derms = MAX(derms, rsqrt(de2avg)); if (demin < -decrit || demax > decrit) { eprintf("[%s: warning: energy error exceeds %.4e at time = %-12.8f\n" " min,max,rms = %.6g,%.6g,%.6g threshold now %.4e]\n", getprog(), decrit, tnow, demin, demax, rsqrt(de2avg), decrit * rsqrt(2.0)); decrit = decrit * rsqrt(2.0); decrit_inc = TRUE; } if (tout <= tnow) { put_snap(ostr, &btab, &nbody, &tnow, optags); tout = tout + getdparam("dtout"); } fflush(NULL); } eprintf(decrit_inc ? "[%s: WARNING: energy error: min,max,rms = %.6g,%.6g,%.6g]\n" : "[%s: energy error: min,max,rms = %.6g,%.6g,%.6g]\n", getprog(), demin, demax, derms); return (0); }
void nemo_main() { stream instr, outstr; real mscale, pscale, xscale, tsnap, escale, dscale; vector rscale, vscale, ascale; string times; int i, nbody, bits, nrscale, nvscale, nascale, kscale; Body *btab = NULL, *bp; bool Qmass, Qphase, Qacc, Qpot, Qkey, Qaux, Qeps, Qdens; nrscale = nemoinpr(getparam("rscale"),rscale,NDIM); /* RSCALE */ if (nrscale==1) for (i=1; i<NDIM; i++) rscale[i] = rscale[0]; else if (nrscale!=NDIM) error("keyword rscale needs either 1 or %d numbers", NDIM); nvscale = nemoinpr(getparam("vscale"),vscale,NDIM); /* VSCALE */ if (nvscale==1) for (i=1; i<NDIM; i++) vscale[i] = vscale[0]; else if (nvscale!=NDIM) error("keyword vscale needs either 1 or %d numbers", NDIM); nascale = nemoinpr(getparam("ascale"),ascale,NDIM); /* ASCALE */ if (nascale==1) for (i=1; i<NDIM; i++) ascale[i] = ascale[0]; else if (nascale!=NDIM) error("keyword ascale needs either 1 or %d numbers", NDIM); mscale = getdparam("mscale"); pscale = getdparam("pscale"); xscale = getdparam("xscale"); dscale = getdparam("dscale"); escale = getdparam("escale"); kscale = getiparam("kscale"); times = getparam("times"); instr = stropen(getparam("in"), "r"); /* open files */ outstr = stropen(getparam("out"), "w"); get_history(instr); put_history(outstr); for (;;) { get_history(instr); /* skip over stuff we can forget */ if (!get_tag_ok(instr, SnapShotTag)) break; /* done with work in loop */ get_snap(instr, &btab, &nbody, &tsnap, &bits); if ((bits & MassBit) == 0 && (bits & PhaseSpaceBit) == 0) { continue; /* just skip it's probably a diagnostics */ } if ((bits & TimeBit) == 0) tsnap = 0.0; else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ)) continue; dprintf (1,"Scaling snapshot at time= %f bits=0x%x\n",tsnap,bits); Qmass = MassBit & bits && !uscalar(mscale); Qphase = PhaseSpaceBit & bits &&(!uvector(rscale) || !uvector(vscale)); Qacc = AccelerationBit & bits&& !uvector(ascale); Qpot = PotentialBit & bits && !uscalar(pscale); Qaux = AuxBit & bits && !uscalar(xscale); Qkey = KeyBit & bits && (kscale!=1); Qdens = DensBit & bits && !uscalar(dscale); Qeps = EpsBit & bits && !uscalar(escale); dprintf(1,"Scaling: "); if (Qmass) dprintf(1," mass"); if (Qphase) dprintf(1," phase"); if (Qacc) dprintf(1," acc"); if (Qpot) dprintf(1," pot"); if (Qaux) dprintf(1," aux"); if (Qkey) dprintf(1," key"); if (Qdens) dprintf(1," dens"); if (Qeps) dprintf(1," eps"); dprintf(1,"\n"); if (Qmass || Qphase || Qacc || Qpot || Qaux || Qkey || Qdens || Qeps) { for (bp = btab; bp < btab+nbody; bp++) { if(Qmass) Mass(bp) *= mscale; if(Qphase) { SMULVV(Pos(bp),rscale); SMULVV(Vel(bp),vscale); } if(Qpot) Phi(bp) *= pscale; if(Qacc) { SMULVV(Acc(bp),ascale); } if(Qaux) Aux(bp) *= xscale; if(Qkey) Key(bp) *= kscale; if(Qdens) Dens(bp) *= dscale; if(Qeps) Eps(bp) *= escale; } } else { warning("No scaling applied to snapshot"); } put_snap(outstr, &btab, &nbody, &tsnap, &bits); } }
void nemo_main(void) { stream instr, outstr; real tsnap; string times, precision, keep; Body *btab = NULL, *bpi, *bpo; int i, nbody, nout, nreject, bitsi, bitso, vis, visnow, vismax; bool Qall; iproc_body sfunc; times = getparam("times"); sfunc = btitrans(getparam("select")); instr = stropen(getparam("in"), "r"); outstr = stropen(getparam("out"), "w"); precision = getparam("precision"); /* unused */ if (!streq(precision,"double")) { warning("Precision \"%s\" not supported yet, use csf convert=d2f/f2d", precision); } keep = getparam("keep"); bitso = 0; if (scanopt(keep,"all")) { Qall = TRUE; } else { Qall = FALSE; if (scanopt(keep,"mass")) bitso |= MassBit; if (scanopt(keep,"phase")) bitso |= PhaseSpaceBit; if (scanopt(keep,"phi")) bitso |= PotentialBit; if (scanopt(keep,"acc")) bitso |= AccelerationBit; if (scanopt(keep,"aux")) bitso |= AuxBit; if (scanopt(keep,"key")) bitso |= KeyBit; if (scanopt(keep,"time")) bitso |= TimeBit; } get_history(instr); put_history(outstr); for (;;) { get_history(instr); /* skip over stuff we can forget */ if (!get_tag_ok(instr, SnapShotTag)) break; /* done with work in loop */ get_snap(instr, &btab, &nbody, &tsnap, &bitsi); if ((bitsi & MassBit) == 0 && (bitsi & PhaseSpaceBit) == 0) { continue; /* just skip */ } /* do some initial output */ if ((bitsi & TimeBit) == 0) { /* if not time flag */ tsnap = 0.0; /* set time to zero */ bitsi |= TimeBit; warning("time reset to 0"); } else if (!streq(times,"all") && !within(tsnap, times, TIMEFUZZ)) continue; /* now skip this snapshot */ if (bitsi & KeyBit) dprintf(0,"Warning: Keyfield reinitialized\n"); for (bpi = btab; bpi < btab+nbody; bpi++) Key(bpi) = 0; /* set to false */ visnow = vismax = nreject = 0; do { /* loop through all particles */ visnow++; for (bpi = btab, i=0; i<nbody; bpi++,i++) { vis = (*sfunc)(bpi, tsnap, i); dprintf(2,"sfunc [%d] = %d\n",i,vis); vismax = MAX(vismax,vis); if (vis==visnow) Key(bpi) = 1; } } while (visnow < vismax); /* do all layers */ nreject = 0; for (bpi = btab, bpo = btab, i=0; i<nbody; bpi++,i++) { if (!Key(bpi)) { nreject++; /* count number of stars rejected */ continue; } if (nreject) /* only copy while out of sync */ bcopy (bpi, bpo, sizeof(Body)); Key(bpo) = i; /* counting from zero */ bpo++; } nout = nbody - nreject; if (nout) { if (Qall) { /* if all old things selected */ if (nreject) /* and some stars were rejected */ bitsi |= KeyBit; /* then explicitly add Key field */ } else bitsi = bitso; put_snap(outstr, &btab, &nout, &tsnap, &bitsi); dprintf (1,"Snapshot time=%f copied %d particles\n", tsnap,nout); } else dprintf(0,"No particles to copy at tsnap=%f\n",tsnap); } }
void nemo_main() { int i, seed, bits; real mg, mh, tsnap; double vx, vy, vz; double fmax, f0, f1, v2, vmax, vmax2; bool Qcenter = getbparam("zerocm"); bool Qphi = getbparam("addphi"); stream outstr = stropen(getparam("out"),"w"); mu = getdparam("m"); a = getdparam("a"); seed = init_xrandom(getparam("seed")); nobj = getiparam("nbody"); if (nobj%2) warning("Total number of particles reset to %d\n",2*((nobj+1)/2)); nobj = ((nobj+1)/2); if (hasvalue("headline")) set_headline(getparam("headline")); put_history(outstr); b = a - 1; btab = (Body *) allocate(2*nobj*sizeof(Body)); for(i=0, bp=btab; i<2*nobj; i++, bp++) { double eta, radius, cth, sth, phi; double psi0; eta = (double) xrandom(0.0,1.0); radius = rad(eta); if( i >= nobj ) { if( mu == 0.0 ) break; radius *= a; } if( i<nobj ) { galaxy = 1; } else { galaxy = 0; } phi = xrandom(0.0,2*M_PI); cth = xrandom(-1.0,1.0); sth = sqrt(1.0 - cth*cth); Pos(bp)[0] = (real) (radius*sth*cos(phi)); Pos(bp)[1] = (real) (radius*sth*sin(phi)); Pos(bp)[2] = (real) (radius*cth); psi0 = -pot(radius); if (Qphi) Phi(bp) = psi0; vmax2 = 2.0*psi0; vmax = sqrt(vmax2); fmax = f(psi0); f0 = fmax; f1 = 1.1*fmax; /* just some initial values */ while( f1 > f0 ) { /* pick a velocity */ v2 = 2.0*vmax2; while( v2 > vmax2 ) { /* rejection technique */ vx = vmax*xrandom(-1.0,1.0); vy = vmax*xrandom(-1.0,1.0); vz = vmax*xrandom(-1.0,1.0); v2 = vx*vx + vy*vy + vz*vz; } f0 = f((psi0 - 0.5*v2)); f1 = fmax*xrandom(0.0,1.0); } Vel(bp)[0] = vx; Vel(bp)[1] = vy; Vel(bp)[2] = vz; } mg = 1.0/nobj; mh = mu/nobj; for(i=0, bp=btab; i<2*nobj; i++, bp++) { if (i<nobj) Mass(bp) = mg; else Mass(bp) = mh; } if (Qcenter) cofm(); bits = MassBit | PhaseSpaceBit; if (Qphi) bits |= PotentialBit; nobj *= 2; tsnap = 0.0; put_snap(outstr, &btab, &nobj, &tsnap, &bits); strclose(outstr); }
int nemo_main() { int i, n, nbody, bits, ndata, count, ngrid[3]; real scale, dt, dtout, dtlog, tstop, tsnap, mass; string exefile = getparam("exe"); string rundir = getparam("outdir"); string fmt = getparam("format"); stream datstr, instr, outstr; char dname[256]; char command[256]; char fmt6[256]; float *gdata, *gd; Body *bp, *btab = NULL; if (hasvalue("header")) unfsize(getiparam("header")); n = nemoinpi(getparam("grid"),ngrid,3); if (n>0 && n<=3) { for (i=n; i<3; i++) ngrid[i] = ngrid[i-1]; } else error("%d Syntax error: %s (need 1,2 or 3 integers)", n,getparam("grid")); scale = getdparam("scale"); dt = getdparam("dt"); dtout = getdparam("dtout"); dtlog = getdparam("dtlog"); tstop = getdparam("tstop"); sprintf(fmt6,"%s %s %s %s %s %s\n",fmt,fmt,fmt,fmt,fmt,fmt); make_rundir(rundir); /* prepare the parameter file for galaxy */ sprintf(dname,"%s/%s",rundir,"galaxy.dat"); datstr = stropen(dname,"w"); fprintf(datstr,"%d %d %d\n",ngrid[0],ngrid[1],ngrid[2]); fprintf(datstr,"%g\n",scale); fprintf(datstr,"%g\n",dt); fprintf(datstr,"%g\n",dtout); fprintf(datstr,"%g\n",dtlog); fprintf(datstr,"%g\n",tstop); strclose(datstr); /* read snapshot and output it in something galaxy understands */ instr = stropen(getparam("in"),"r"); get_history(instr); if (!get_tag_ok(instr, SnapShotTag)) error("no snapshot"); get_snap(instr, &btab, &nbody, &tsnap, &bits); strclose(instr); if ( (bits & PhaseSpaceBit) == 0) error("no phasespace"); for (bp=btab;bp<btab+nbody; bp++) mass += Mass(bp); sprintf(dname,"%s/%s",rundir,"galaxy.ini"); datstr = stropen(dname,"w"); fprintf(datstr,"%g %g %d\n",tsnap,mass,nbody); for (bp=btab;bp<btab+nbody; bp++) fprintf(datstr,fmt6, Pos(bp)[0],Pos(bp)[1],Pos(bp)[2], Vel(bp)[0],Vel(bp)[1],Vel(bp)[2]); strclose(datstr); /* run the fortran program */ goto_rundir(rundir); if (run_program(exefile)) error("Problem executing %s",exefile); /* Output data from native galaxy (.res) format to snapshot */ sprintf(dname,"%s","galaxy.res"); instr = stropen(dname,"r"); sprintf(dname,"%s","galaxy.snap"); outstr = stropen(dname,"w"); put_history(outstr); ndata = 7*sizeof(float)*nbody; gdata = (float *) allocate(ndata); bits = (TimeBit | PhaseSpaceBit | PotentialBit); while (1) { count = unfread(instr,gdata,ndata); if (count <= 0) break; printf("Time=%g\n",gdata[0]); tsnap = gdata[0]; count = unfread(instr,gdata,ndata); if (count <= 0) error("Problem reading posvelphi from galaxy.res"); for (bp=btab, gd=gdata;bp<btab+nbody; bp++) { Pos(bp)[0] = *gd++; Pos(bp)[1] = *gd++; Pos(bp)[2] = *gd++; Vel(bp)[0] = *gd++; Vel(bp)[1] = *gd++; Vel(bp)[2] = *gd++; Phi(bp) = *gd++; } put_snap(outstr, &btab, &nbody, &tsnap, &bits); } }
void output(void) { real teff; int n; string outtags[MaxBodyFields]; char namebuf[256]; struct stat buf; stream outstr; string streamtags[] = { MassTag, PosTag, VelTag, PhiTag, AccTag, NULL }; diagnostics(); // compute std diagnostics if (logstr != NULL) { //fprintf(logstr, "\n %8s%8s%8s%8s%8s%8s%8s%8s\n", //"time", "|T+U|", "T", "-U", "-T/U", "|Vcom|", "|Jtot|", "CPUtot"); //fprintf(logstr, " %8.3f%8.4f%8.4f%8.4f%8.5f%8.5f%8.4f%8.2f\n", // tnow, ABS(etot[0]), etot[1], -etot[2], -etot[1]/etot[2], // absv(cmvel), absv(amvec), cputime()); } teff = tnow + dtime/8; // anticipate slightly... if (! strnull(outfile) && teff >= tout) { // time for data output? n = 0; if (scanopt(outputs, PosTag)) // if listed in outputs outtags[n++] = PosTag; // include tag in list if (scanopt(outputs, VelTag)) outtags[n++] = VelTag; if (scanopt(outputs, MassTag) || (nstep == 0)) outtags[n++] = MassTag; if (scanopt(outputs, PhiTag)) outtags[n++] = PhiTag; // select potential data if (scanopt(outputs, AccTag)) outtags[n++] = AccTag; // select acceleration data outtags[n] = NULL; sprintf(namebuf, outfile, nstep); // make up output file name if (stat(namebuf, &buf) != 0) { // no output file exists? outstr = stropen(namebuf, "w"); // create & open for output put_history(outstr); // write out hiatory data } else // else file already exists outstr = stropen(namebuf, "a"); // reopen and append output put_snap(outstr, &bodytab, &nbody, &tnow, outtags); strclose(outstr); // close up output file if (logstr != NULL) fprintf(logstr, "\n\tdata output to file %s at time %f\n", namebuf, tnow); tout += dtout; // schedule next output } if (! strnull(strfile)) { if (! streq(strfile, "-")) { sprintf(namebuf, strfile, nstep); if (stat(namebuf, &buf) != 0) { outstr = stropen(namebuf, "w"); put_history(outstr); } else outstr = stropen(namebuf, "a"); } else outstr = stdout; put_snap(outstr, &bodytab, &nbody, &tnow, streamtags); fflush(outstr); if (! streq(strfile, "-")) strclose(outstr); } if (! strnull(savefile)) // was state file given? savestate(savefile); // save data for restart forcehead = FALSE; // insure headers print fflush(NULL); // empty all output buffers }