void polymodel(void) { gsl_interp_accel *pmsplacc = gsl_interp_accel_alloc(); bodyptr p; real rad, phi, vel, psi, vr, vp, a, E, J; vector rhat, vtmp, vper; for (p = btab; p < NthBody(btab, nbody); p = NextBody(p)) { rad = rad_m(xrandom(0.0, mtot)); phi = gsl_spline_eval(pmspline, (double) rad, pmsplacc); vel = pick_v(phi); psi = pick_psi(); vr = vel * rcos(psi); vp = vel * rsin(psi); Mass(p) = mtot / nbody; pickshell(rhat, NDIM, 1.0); MULVS(Pos(p), rhat, rad); pickshell(vtmp, NDIM, 1.0); a = dotvp(vtmp, rhat); MULVS(vper, rhat, - a); ADDV(vper, vper, vtmp); a = absv(vper); MULVS(vper, vper, vp / a); MULVS(Vel(p), rhat, vr); ADDV(Vel(p), Vel(p), vper); Phi(p) = phi; E = phi + 0.5 * rsqr(vel); J = rad * ABS(vp); Aux(p) = Kprime * rpow(phi1 - E, npol - 1.5) * rpow(J, 2 * mpol); } gsl_interp_accel_free(pmsplacc); }
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")); }
void snapstack(bodyptr btab, bodyptr bt1, int nb1, bodyptr bt2, int nb2, string *tags) { vector deltar, deltav; bodyptr bp; int i; setvect(deltar, burststring(getparam("deltar"), ", ")); setvect(deltav, burststring(getparam("deltav"), ", ")); for (i = 0; i < nb1; i++) { bp = NthBody(btab, i); memcpy(bp, NthBody(bt1, i), SizeofBody); if (set_member(tags, PosTag)) { ADDMULVS(Pos(bp), deltar, 0.5); } if (set_member(tags, VelTag)) { ADDMULVS(Vel(bp), deltav, 0.5); } } for (i = 0; i < nb2; i++) { bp = NthBody(btab, i + nb1); memcpy(bp, NthBody(bt2, i), SizeofBody); if (set_member(tags, PosTag)) { ADDMULVS(Pos(bp), deltar, -0.5); } if (set_member(tags, VelTag)) { ADDMULVS(Vel(bp), deltav, -0.5); } } }
int equalBody(const Body* a, const Body* b) { if (Mass(a) != Mass(b)) { mw_printf("mass differ\n"); return FALSE; } if (Type(a) != Type(b)) { mw_printf("type ndiffer\n"); return FALSE; } if (!equalVector(&Pos(a), &Pos(b))) { mw_printf("pos differ\n"); return FALSE; } if (!equalVector(&Vel(a), &Vel(b))) { mw_printf("VElocity differ\n"); return FALSE; } return TRUE; }
void makedisk(bool randspin) { int i; bodyptr bp; double m, r, v, phi; matrix xmat, zmat; vector tmpv; for (i = 0; i < ndisk; i++) { // loop initializing bodies bp = NthBody(disk, i); // set ptr to body number i m = mdtab[NTAB-1] * ((double) i + 0.5) / ndisk; r = gsl_interp_eval(rm_spline, mdtab, rdtab, m, NULL); v = gsl_interp_eval(vr_spline, rdtab, vctab, r, NULL); phi = xrandom(0.0, 2 * M_PI); Pos(bp)[0] = r * sin(phi); Pos(bp)[1] = r * cos(phi); Pos(bp)[2] = 0.0; Vel(bp)[0] = v * cos(phi); Vel(bp)[1] = - v * sin(phi); Vel(bp)[2] = 0.0; pickshell(AuxVec(bp), NDIM, 1.0); if (randspin) { xmatrix(xmat, acos(AuxVec(bp)[2])); zmatrix(zmat, atan2(AuxVec(bp)[0], AuxVec(bp)[1])); MULMV(tmpv, xmat, Pos(bp)); MULMV(Pos(bp), zmat, tmpv); MULMV(tmpv, xmat, Vel(bp)); MULMV(Vel(bp), zmat, tmpv); } } }
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 printCell(cellptr cell) { printf("[X: %lf %lf %lf][M: %lf][V: %lf %lf %lf]", Pos(cell)[0], Pos(cell)[1], Pos(cell)[2], Mass(cell), Vel(cell)[0], Vel(cell)[1], Vel(cell)[2] ); }
void snapcenter(bodyptr btab, int nbody, int woff) { vector cmpos, cmvel; bodyptr bp; snapcmpos(cmpos, btab, nbody, woff); snapcmvel(cmvel, btab, nbody, woff); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { SUBV(Pos(bp), Pos(bp), cmpos); SUBV(Vel(bp), Vel(bp), cmvel); } }
void printBody(bodyptr body) { printf("[X: %lf %lf %lf][M: %lf][V: %lf %lf %lf]", Pos(body)[0], Pos(body)[1], Pos(body)[2], Mass(body), Vel(body)[0], Vel(body)[1], Vel(body)[2] ); }
void snaprect(bodyptr btab, int nbody) { matrix qmat, tmpm; bodyptr bp; vector frame[3], tmpv; static vector oldframe[3] = { { 1.0, 0.0, 0.0, }, { 0.0, 1.0, 0.0, }, { 0.0, 0.0, 1.0, }, }; int i; snapcenter(btab, nbody, WeightField.offset); CLRM(qmat); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { OUTVP(tmpm, Pos(bp), Pos(bp)); MULMS(tmpm, tmpm, Weight(bp)); ADDM(qmat, qmat, tmpm); } eigenvect(frame[0], frame[1], frame[2], qmat); if (dotvp(oldframe[0], frame[0]) < 0.0) MULVS(frame[0], frame[0], -1.0); if (dotvp(oldframe[2], frame[2]) < 0.0) MULVS(frame[2], frame[2], -1.0); CROSSVP(frame[1], frame[2], frame[0]); printvect("e_x:", frame[0]); printvect("e_y:", frame[1]); printvect("e_z:", frame[2]); for (bp = btab; bp < NthBody(btab, nbody); bp = NextBody(bp)) { if (PosField.offset != BadOffset) { for (i = 0; i < NDIM; i++) tmpv[i] = dotvp(Pos(bp), frame[i]); SETV(Pos(bp), tmpv); } if (VelField.offset != BadOffset) { for (i = 0; i < NDIM; i++) tmpv[i] = dotvp(Vel(bp), frame[i]); SETV(Vel(bp), tmpv); } if (AccField.offset != BadOffset) { for (i = 0; i < NDIM; i++) tmpv[i] = dotvp(Acc(bp), frame[i]); SETV(Acc(bp), tmpv); } if (AuxVecField.offset != BadOffset) { for (i = 0; i < NDIM; i++) tmpv[i] = dotvp(AuxVec(bp), frame[i]); SETV(AuxVec(bp), tmpv); } } for (i = 0; i < NDIM; i++) SETV(oldframe[i], frame[i]); }
local void stepsystem(void) { bodyptr p1, p2, p; p1 = bodytab + MAX(nstatic, 0); // set dynamic body range p2 = bodytab + nbody + MIN(nstatic, 0); for (p = p1; p < p2; p++) { // loop over body range ADDMULVS(Vel(p), Acc(p), 0.5 * dtime); // advance v by 1/2 step ADDMULVS(Pos(p), Vel(p), dtime); // advance r by 1 step } treeforce(); for (p = p1; p < p2; p++) { // loop over body range ADDMULVS(Vel(p), Acc(p), 0.5 * dtime); // advance v by 1/2 step } nstep++; // count another time step tnow = tnow + dtime; // finally, advance time }
char* showBody(const Body* p) { char* buf; char* vel; char* pos; if (!p) return NULL; vel = showVector(Vel(p)); pos = showVector(Pos(p)); if (0 > asprintf(&buf, "body { \n" " mass = %g\n" " position = %s\n" " velocity = %s\n" " ignore = %s\n" " };\n", Mass(p), pos, vel, showBool(ignoreBody(p)))) { mw_fail("asprintf() failed\n"); } free(vel); free(pos); return buf; }
mwvector nbCenterOfMom(const NBodyState* st) { int i; const Body* b; int nbody = st->nbody; mwvector cm = ZERO_VECTOR; mwvector tmp; Kahan mass; Kahan pos[3]; CLEAR_KAHAN(mass); memset(pos, 0, sizeof(pos)); for (i = 0; i < nbody; ++i) { b = &st->bodytab[i]; tmp = mw_mulvs(Vel(b), Mass(b)); KAHAN_ADD(pos[0], tmp.x); KAHAN_ADD(pos[1], tmp.y); KAHAN_ADD(pos[2], tmp.z); KAHAN_ADD(mass, Mass(b)); } X(cm) = pos[0].sum / mass.sum; Y(cm) = pos[1].sum / mass.sum; Z(cm) = pos[2].sum / mass.sum; W(cm) = mass.sum; return cm; }
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); }
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 }
/* Advance velocity by half a timestep */ static inline void bodyAdvanceVel(Body* p, const mwvector a, const real dtHalf) { mwvector dv; dv = mw_mulvs(a, dtHalf); /* get velocity increment */ mw_incaddv(Vel(p), dv); /* advance v by 1/2 step */ }
void MidiInputDeviceMidiShare::KeyOffTask(long date, short ref, long a1, long a2, long a3) { MidiInputDeviceMidiShare* driver = (MidiInputDeviceMidiShare*)MidiGetInfo(ref); MidiEvPtr ev =(MidiEvPtr)a1; driver->DispatchNoteOn(Pitch(ev),Vel(ev),Chan(ev)); MidiFreeEv(ev); }
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); }
/* Advance body position by 1 timestep */ static inline void bodyAdvancePos(Body* p, const real dt) { mwvector dr; dr = mw_mulvs(Vel(p), dt); /* get position increment */ mw_incaddv(Pos(p), dr); /* advance r by 1 step */ }
int read_snapshot( bodyptr *btab_ptr, /* gets particle array */ int *nobj_ptr, /* gets number of bodies */ stream instr /* stream to read from */ ) { int nobj, cs, i; real *mbuf, *mp, *pbuf, *pp; bodyptr bp; for(;;) { /* loop until done or proper snapshot */ if (!get_tag_ok(instr,SnapShotTag)) return 0; get_set(instr, SnapShotTag); if (!get_tag_ok(instr,ParametersTag)) { get_tes(instr,SnapShotTag); continue; } get_set(instr, ParametersTag); get_data(instr, NobjTag, IntType, &nobj, 0); if (nobj < 1) error("read_snapshot: %s = %d is absurd", NobjTag, nobj); if (get_tag_ok(instr,TimeTag)) get_data(instr,TimeTag, RealType, &tsnap, 0); else { dprintf(0,"No time tag: time=0.0 assumed\n"); tsnap = 0.0; } get_tes(instr, ParametersTag); if (!get_tag_ok(instr,ParticlesTag)) { get_tes(instr,SnapShotTag); continue; } get_set(instr, ParticlesTag); get_data(instr, CoordSystemTag, IntType, &cs, 0); if (cs != CSCode(Cartesian, NDIM, 2)) error("read_snapshot: cannot handle %s = %d", CoordSystemTag, cs); mbuf = mp = (real *) allocate(nobj * sizeof(real)); pbuf = pp = (real *) allocate(nobj * 2 * NDIM * sizeof(real)); get_data(instr, MassTag, RealType, mbuf, nobj, 0); get_data(instr, PhaseSpaceTag, RealType, pbuf, nobj, 2, NDIM, 0); get_tes(instr, ParticlesTag); get_tes(instr, SnapShotTag); *btab_ptr = bp = (bodyptr) allocate(nobj * sizeof(body)); for (i = 0; i < nobj; i++) { Type(bp) = BODY; Mass(bp) = *mp++; SETV(Pos(bp), pp); pp += NDIM; SETV(Vel(bp), pp); pp += NDIM; bp++; } free(mbuf); free(pbuf); *nobj_ptr = nobj; return 1; } }
/* -------------------------------------------------------- Real time echo management task -------------------------------------------------------- */ void MSALARMAPI EchoTask( long d,short ref,long el,long a2, long a3) { MidiEvPtr e; short v,p; e= (MidiEvPtr)el; v = Vel(e)+MSParam[kVel]; p = Pitch(e)+MSParam[kPitch]; if ( ((v>0)&&(v<128)) && ((p>=0)&&(p<128)) ) { Vel(e) = v; Pitch(e) = p; MidiSendAt(ref, MidiCopyEv(e), d); if( !MidiTask(EchoTask, d+MSParam[kDelay], ref, el, 0, 0)) MidiFreeEv(e); } else MidiFreeEv(e); }
static void SongPosLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { f->count = 3; f->data[3] = SongPos; f->data[2] = Pitch(e); f->data[1] = Vel(e); f->runStat = 0; MidiFreeCell (e); }
bodyptr convertStruct(particle* particles, int count) { bodyptr bodies = (bodyptr) malloc(count * sizeof(body)); bodyptr body = bodies; particle * p; for (p = particles; p < particles + count; p++) { Pos(body)[0] = p->x; Pos(body)[1] = p->y; Pos(body)[2] = p->z; Mass(body) = p->m; Vel(body)[0] = p->vx; Vel(body)[1] = p->vy; Vel(body)[2] = p->vz; Type((nodeptr) body) = BODY; body++; } return bodies; }
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 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); }
void MidiInputDeviceMidiShare::ReceiveEvents(short ref) { MidiInputDeviceMidiShare* driver = (MidiInputDeviceMidiShare*)MidiGetInfo(ref); MidiEvPtr ev; while ((ev = MidiGetEv(ref))) switch(EvType(ev)) { case typeCtrlChange: if (MidiGetField(ev,0) == 0) driver->DispatchBankSelectMsb(MidiGetField(ev,0),Chan(ev)); else if (MidiGetField(ev,0) == 32) driver->DispatchBankSelectLsb(MidiGetField(ev,0),Chan(ev)); else driver->DispatchControlChange(MidiGetField(ev,0),MidiGetField(ev,0),Chan(ev)); MidiFreeEv(ev); break; case typePitchWheel: driver->DispatchPitchbend(((MidiGetField(ev,0)+(MidiGetField(ev,1) << 7)) - 8192),Chan(ev)); MidiFreeEv(ev); break; case typeNote: driver->DispatchNoteOn(Pitch(ev),Vel(ev),Chan(ev)); MidiTask(KeyOffTask,Date(ev)+Dur(ev),ref,(long)ev,0,0); break; case typeKeyOn: if (Vel(ev) > 0) driver->DispatchNoteOn(Pitch(ev),Vel(ev),Chan(ev)); else driver->DispatchNoteOff(Pitch(ev),Vel(ev),Chan(ev)); MidiFreeEv(ev); break; case typeKeyOff: driver->DispatchNoteOff(Pitch(ev),Vel(ev),Chan(ev)); MidiFreeEv(ev); break; } }
nemo_main() { stream instr; real tsnap, x, y, v, d; int i, nbody, bits, iy, ny, nout; Body *btab = NULL, *bp; Grid g; real yrange[MAXY], sumd[MAXY], sumvd[MAXY], sumxd[MAXY]; bool Qmass = getbparam("mass"); instr = stropen(getparam("in"), "r"); /* open input file */ ny = nemoinpr(getparam("y"),yrange,MAXY); if (ny<2) error("yrange syntax error or not enuf slices"); #if 0 inia_grid(&g, ny, yrange); #else inil_grid(&g, ny-1, yrange[0], yrange[ny-1]); #endif get_history(instr); /* accumulate data history */ for(;;) { /* loop for all times */ get_history(instr); /* for paranoidici */ if (!get_tag_ok(instr, SnapShotTag)) /* check if done */ break; get_snap(instr, &btab, &nbody, &tsnap, &bits); /* get one */ if ((bits & PhaseSpaceBit) == 0) continue; /* if no positions - skip */ for (i=0; i<ny; i++) sumd[i] = sumxd[i] = sumvd[i] = 0.0; for (bp = btab; bp < btab+nbody; bp++) { /* loop all bodies */ y = Pos(bp)[1]; iy = index_grid(&g, y); if (iy < 0) continue; d = Qmass ? Mass(bp) : Dens(bp); x = Pos(bp)[0]; v = Vel(bp)[1]; sumd[iy] += d; sumvd[iy] += v*d; sumxd[iy] += x*d; } break; /* for now just first snapshot */ } nout = 0; for (i=0; i<ny-1; i++) { if (sumd[i] > 0.0) { nout++; printf("%g %g %g %g\n",value_grid(&g, (real)i+0.5), sumxd[i]/sumd[i], sumvd[i]/sumd[i], sumd[i]); } } if (nout==0) warning("No densities found in slices %s",getparam("y")); } /* nemo_main() */
void testdisk(void) { int ndisk, i; real rmin2, rmax2, eps2, sigma, r_i, theta_i, m_i, v_i; bodyptr gp, sp; ndisk = getiparam("ndisk"); ngalaxy = ndisk + (getbparam("nosphr") ? 0 : nspheroid); galaxy = (bodyptr) allocate(ngalaxy * SizeofBody); rmin2 = rsqr(getdparam("rmin")); rmax2 = rsqr(getdparam("rmax")); eps2 = rsqr(getdparam("eps")); sigma = getdparam("sigma"); init_random(getiparam("seed")); for (i = 0; i < ndisk; i++) { /* build disk */ gp = NthBody(galaxy, i); Mass(gp) = 0.0; /* set mass to zero */ r_i = rsqrt(rmin2 + i * (rmax2 - rmin2) / (ndisk - 1.0)); theta_i = xrandom(0.0, TWO_PI); Pos(gp)[0] = r_i * rsin(theta_i); /* set positions */ Pos(gp)[1] = r_i * rcos(theta_i); Pos(gp)[2] = 0.0; if (r_i < rsph[NTAB-1]) m_i = seval(r_i, &rsph[0], &msph[0], &msph[NTAB], NTAB); else m_i = msph[NTAB-1]; v_i = rsqrt(MAX(m_i, 0.0) * r_i*r_i / rpow(r_i*r_i + eps2, 1.5)); /* set velocities */ Vel(gp)[0] = grandom( v_i * rcos(theta_i), sigma); Vel(gp)[1] = grandom(- v_i * rsin(theta_i), sigma); Vel(gp)[2] = grandom( 0.0, sigma); } if (! getbparam("nosphr")) for (i = 0; i < nspheroid; i++) { /* append spheroid */ sp = NthBody(spheroid, i); gp = NthBody(galaxy, ndisk + i); memcpy(gp, sp, SizeofBody); } if (getbparam("zerocm")) snapcenter(galaxy, ngalaxy, MassField.offset); }
static void NoteLinearizeMth (MidiEvPtr e, Ev2StreamPtr f) { Byte status = NoteOn + Chan(e); if( f->runStat== status) f->count= 2; else { f->runStat= f->data[3] = status; f->count = 3; } f->data[2] = Pitch(e); f->data[1] = Vel(e); }
void render(void) { int step, oldc, newc; bodyptr bp; float cval; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective((GLdouble) fview, (GLdouble) ((double) wscreen) / hscreen, (GLdouble) 0.01 * dview, (GLdouble) 100.0 * dview); glGetFloatv(GL_PROJECTION_MATRIX, &projmat[0][0]); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); glTranslatef(xoff, yoff, -dview); glRotatef(-thetaz, 0.0, 0.0, 1.0); /* same map as snaprotate */ glRotatef(-thetay, 0.0, 1.0, 0.0); glRotatef(-thetax, 1.0, 0.0, 0.0); glGetFloatv(GL_MODELVIEW_MATRIX, &viewmat[0][0]); glBegin(vectoroff == -1 ? GL_POINTS : GL_LINES); step = (actval == -1 ? 1 : rceil((float) nbody / (float) maxfast)); oldc = -1; for (bp = btab; bp < NthBody(btab, nbody); bp = NthBody(bp, step)) { if (scalaroff == -1 && ! dopcolor) newc = Key(bp); else { if (! dopcolor) cval = (SelectReal(bp, scalaroff) - cmidpt) / crange; else cval = (dotvp(Vel(bp), znorm) - cmidpt) / crange; newc = (cval > 1.0 ? 0x0000ff : cval > 0.6 ? 0x006fdf : cval > 0.2 ? 0x00cf7f : cval > -0.2 ? 0x00ff00 : cval > -0.6 ? 0x7fcf00 : cval > -1.0 ? 0xbf8f00 : 0xff4f00); } if (oldc != newc) glColor3f(RVAL(newc), GVAL(newc), BVAL(newc)); oldc = newc; glVertex3f(Pos(bp)[0], Pos(bp)[1], Pos(bp)[2]); if (vectoroff != -1) glVertex3f(Pos(bp)[0] + vscale * SelectVect(bp, vectoroff)[0], Pos(bp)[1] + vscale * SelectVect(bp, vectoroff)[1], Pos(bp)[2] + vscale * SelectVect(bp, vectoroff)[2]); } glEnd(); if (actval != -1) { glColor3f(RVAL(bcolor), GVAL(bcolor), BVAL(bcolor)); glutWireCube(refscale); } glPopMatrix(); }