3 * A class used to represent internal nodes in the tree
5 final class Cell extends Node
8 public final int NSUB; // 1 << NDIM
11 * The children of this cell node. Each entry may contain either
12 * another cell or a body.
21 subp = new Node[NSUB];
26 * Descend Tree and insert particle. We're at a cell so
27 * we need to move down the tree.
28 * @param p the body to insert into the tree
31 * @param tree the root of the tree
32 * @return the subtree with the new body inserted
34 public Node loadTree(Body p, MathVector xpic, int l, Tree tree)
36 // move down one level
37 int si = oldSubindex(xpic, l);
40 if(rt instanceof Body) {
42 subp[si] = rtb.loadTree(p, xpic, l >> 1, tree);
43 } else if(rt instanceof Cell) {
45 subp[si] = rtc.loadTree(p, xpic, l >> 1, tree);
54 * Descend tree finding center of mass coordinates
55 * @return the mass of this node
57 public double hackcofm()
60 MathVector tmpPos = new MathVector();
61 MathVector tmpv = new MathVector();
62 for (int i=0; i < NSUB; i++) {
66 if(r instanceof Body) {
69 } else if(r instanceof Cell) {
74 tmpv.multScalar(r.pos, mr);
75 tmpPos.addition(tmpv);
86 * Recursively walk the tree to do hackwalk calculation
88 public HG walkSubTree(double dsq, HG hg)
90 if (subdivp(dsq, hg)) {
91 for (int k = 0; k < this.NSUB; k++) {
94 if(r instanceof Body) {
96 hg = rb.walkSubTree(dsq / 4.0, hg);
97 } else if(r instanceof Cell) {
99 hg = rc.walkSubTree(dsq / 4.0, hg);
110 * Decide if the cell is too close to accept as a single term.
111 * @return true if the cell is too close.
113 public boolean subdivp(double dsq, HG hg)
115 MathVector dr = new MathVector();
116 dr.subtraction(pos, hg.pos0);
117 double drsq = dr.dotProduct();
119 // in the original olden version drsp is multiplied by 1.0
124 * Return a string represenation of a cell.
125 * @return a string represenation of a cell.
127 /*public String toString()
129 return "Cell " + super.toString();