public void addForce(int start, int end) { for (int i = start; i < end; i++) { if (bodies[i].isIn(quad)) { lock (tree) { tree.insert(bodies[i]); } } } for (int i = start; i < end; i++) { bodies[i].resetForce(); if (bodies[i].isIn(quad)) { lock (tree) { tree.updateForce(bodies[i]); } bodies[i].Update(1e11); } } }
public void addForce(int N) { BHTree tree = new BHTree(quad); Parallel.For(0, N, i => { if (bodies[i].isIn(quad)) { tree.insert(bodies[i]); } }); Parallel.For(0, N, i => { bodies[i].resetForce(); if (bodies[i].isIn(quad)) { tree.updateForce(bodies[i]); bodies[i].Update(1e11); } }); }
public void addForce(int N) { BHTree tree = new BHTree(quad); for (int i = 0; i < N; i++) { if (bodies[i].isIn(quad)) { tree.insert(bodies[i]); } } for (int i = 0; i < N; i++) { bodies[i].resetForce(); if (bodies[i].isIn(quad)) { tree.updateForce(bodies[i]); bodies[i].Update(1e11); } } }
public void insert(Body _body) { try { if (body == null) { body = _body; } else if (isExternal(this) == false) { body = _body.addBody(body); Quad nw = quad.NorthWest(); if (_body.isIn(nw)) { if (NorthWest == null) { NorthWest = new BHTree(nw); } NorthWest.insert(_body); } else { Quad ne = quad.NorthEast(); if (_body.isIn(ne)) { if (NorthEast == null) { NorthEast = new BHTree(ne); } NorthEast.insert(_body); } else { Quad sw = quad.SouthWest(); if (_body.isIn(sw)) { if (SouthWest == null) { SouthWest = new BHTree(sw); } SouthWest.insert(_body); } else { Quad se = quad.SouthEast(); if (_body.isIn(se)) { if (SouthEast == null) { SouthEast = new BHTree(se); } SouthEast.insert(_body); } } } } } else if (isExternal(this)) { Body _bodyC = body; Quad nw = quad.NorthWest(); if (_bodyC.isIn(nw)) { if (NorthWest == null) { NorthWest = new BHTree(nw); } NorthWest.insert(_bodyC); } else { Quad ne = quad.NorthEast(); if (_bodyC.isIn(ne)) { if (NorthEast == null) { NorthEast = new BHTree(ne); } NorthEast.insert(_bodyC); } else { Quad sw = quad.SouthWest(); if (_bodyC.isIn(sw)) { if (SouthWest == null) { SouthWest = new BHTree(sw); } SouthWest.insert(_bodyC); } else { Quad se = quad.SouthEast(); if (_bodyC.isIn(se)) { if (SouthEast == null) { SouthEast = new BHTree(se); } SouthEast.insert(_bodyC); } } } } insert(_body); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }