static private void vp(List <Body> bv, int nstep) { MathVector dacc = MathVector.makeMathVector(); MathVector dvel = MathVector.makeMathVector(); double dthf = 0.5 * BH.DTIME; for (int i = 0; i < bv.Count; ++i) { Body b = bv[i]; MathVector acc1 = b.newAcc.cloneMathVector(); if (nstep > 0) { dacc.subtraction2(acc1, b.acc); dvel.multScalar2(dacc, dthf); dvel.addition(b.vel); b.vel = dvel.cloneMathVector(); } b.acc = acc1.cloneMathVector(); dvel.multScalar2(b.acc, dthf); MathVector vel1 = b.vel.cloneMathVector(); vel1.addition(dvel); MathVector dpos = vel1.cloneMathVector(); dpos.multScalar1(BH.DTIME); dpos.addition(b.pos); b.pos = dpos.cloneMathVector(); vel1.addition(dvel); b.vel = vel1.cloneMathVector(); } }
/** * Descend tree finding center of mass coordinates * * @return the mass of this node */ public override double hackcofm() { double mq = 0.0; MathVector tmpPos = MathVector.makeMathVector(); MathVector tmpv = MathVector.makeMathVector(); for (int i = 0; i < NSUB; i++) { Node r = this.subp[i]; if (r != null) { double mr = r.hackcofm(); mq = mr + mq; tmpv.multScalar2(r.pos, mr); tmpPos.addition(tmpv); } } mass = mq; pos = tmpPos; pos.divScalar(mass); return(mq); }
/** * Create the testdata used in the benchmark. * * @param nbody the number of bodies to create */ public void createTestData(int nbody) { MathVector cmr = MathVector.makeMathVector(); MathVector cmv = MathVector.makeMathVector(); bodyTab = new List <Body>(); double rsc = 3.0 * 3.1415 / 16.0; double vsc = Math.Sqrt(1.0 / rsc); double seed = 123.0; int k; for (int i = 0; i < nbody; i++) { Body p = Body.makeBody(); bodyTab.Add(p); p.mass = 1.0 / (double)nbody; seed = BH.myRand(seed); double t1 = BH.xRand(0.0, 0.999, seed); t1 = Math.Pow(t1, (-2.0 / 3.0)) - 1.0; double r = 1.0 / Math.Sqrt(t1); double coeff = 4.0; for (k = 0; k < MathVector.NDIM; k++) { seed = BH.myRand(seed); r = BH.xRand(0.0, 0.999, seed); p.pos.setValue(k, coeff * r); } cmr.addition(p.pos); double x = 0.0; double y = 0.0; do { seed = BH.myRand(seed); x = BH.xRand(0.0, 1.0, seed); seed = BH.myRand(seed); y = BH.xRand(0.0, 0.1, seed); } while(y > x * x * Math.Pow(1.0 - x * x, 3.5)); double v = Math.Sqrt(2.0) * x / Math.Pow(1.0 + r * r, 0.25); double rad = vsc * v; double rsq = 0.0; do { for (k = 0; k < MathVector.NDIM; k++) { seed = BH.myRand(seed); p.vel.setValue(k, BH.xRand(-1.0, 1.0, seed)); } rsq = p.vel.dotProduct(); } while(rsq > 1.0); double rsc1 = rad / Math.Sqrt(rsq); p.vel.multScalar1(rsc1); cmv.addition(p.vel); } cmr.divScalar((double)nbody); cmv.divScalar((double)nbody); this.bodyTabRev = new List <Body>(); for (int j = 0; j < this.bodyTab.Count; ++j) { Body b = this.bodyTab[j]; b.pos.subtraction1(cmr); b.vel.subtraction1(cmv); this.bodyTabRev.Add(b); } }