testing/icgen/random_verschillende_resoluties_N-GenIC/gadget3_64/subfind_loctree.c
void subfind_loctree_update_node_recursive(int no, int sib, int father)
{
  int j, jj, p, pp = 0, nextsib, suns[8];
  double mass;
  double s[3];

  if(no >= All.MaxPart)
    {
      for(j = 0; j < 8; j++)
	suns[j] = Nodes[no].u.suns[j];	/* this "backup" is necessary because the nextnode entry will
					   overwrite one element (union!) */
      if(last >= 0)
	{
	  if(last >= All.MaxPart)
	    Nodes[last].u.d.nextnode = no;
	  else
	    Nextnode[last] = no;
	}

      last = no;

      mass = 0;
      s[0] = 0;
      s[1] = 0;
      s[2] = 0;

      for(j = 0; j < 8; j++)
	{
	  if((p = suns[j]) >= 0)
	    {
	      /* check if we have a sibling on the same level */
	      for(jj = j + 1; jj < 8; jj++)
		if((pp = suns[jj]) >= 0)
		  break;

	      if(jj < 8)	/* yes, we do */
		nextsib = pp;
	      else
		nextsib = sib;

	      subfind_loctree_update_node_recursive(p, nextsib, no);

	      if(p >= All.MaxPart)	/* an internal node or pseudo particle */
		{
		  mass += Nodes[p].u.d.mass;	/* we assume a fixed particle mass */
		  s[0] += Nodes[p].u.d.mass * Nodes[p].u.d.s[0];
		  s[1] += Nodes[p].u.d.mass * Nodes[p].u.d.s[1];
		  s[2] += Nodes[p].u.d.mass * Nodes[p].u.d.s[2];
		}
	      else		/* a particle */
		{
		  mass += P[p].Mass;
		  s[0] += P[p].Mass * P[p].Pos[0];
		  s[1] += P[p].Mass * P[p].Pos[1];
		  s[2] += P[p].Mass * P[p].Pos[2];
		}
	    }
	}

      if(mass > 0)
	{
	  s[0] /= mass;
	  s[1] /= mass;
	  s[2] /= mass;
	}
      else
	{
	  s[0] = Nodes[no].center[0];
	  s[1] = Nodes[no].center[1];
	  s[2] = Nodes[no].center[2];
	}

      Nodes[no].u.d.s[0] = s[0];
      Nodes[no].u.d.s[1] = s[1];
      Nodes[no].u.d.s[2] = s[2];
      Nodes[no].u.d.mass = mass;

      Nodes[no].u.d.sibling = sib;
      Nodes[no].u.d.father = father;
    }
  else				/* single particle or pseudo particle */
    {
      if(last >= 0)
	{
	  if(last >= All.MaxPart)
	    Nodes[last].u.d.nextnode = no;
	  else
	    Nextnode[last] = no;
	}

      last = no;

      if(no < All.MaxPart)	/* only set it for single particles */
	Father[no] = father;
    }
}
/* this routine computes the multipole moments for a given internal node and
 * all its subnodes using a recursive computation.  Note that the moments of
 * the daughter nodes are already stored in single precision. For very large
 * particle numbers, loss of precision may results for certain particle
 * distributions
 */
this routine computes the multipole moments for a given internal node and
all its subnodes using a recursive computation.  Note that the moments of
the daughter nodes are already stored in single precision. For very large
particle numbers, loss of precision may results for certain particle
distributions
this routine computes the multipole moments for a given internal node and all its subnodes using a recursive computation . Note that the moments of the daughter nodes are already stored in single precision . For very large particle numbers loss of precision may results for certain particle distributions
void subfind_loctree_update_node_recursive(int no, int sib, int father)
{
  int j, jj, p, pp = 0, nextsib, suns[8];
  double mass;
  double s[3];
  if(no >= All.MaxPart)
    {
      for(j = 0; j < 8; j++)
	suns[j] = Nodes[no].u.suns[j];	
      if(last >= 0)
	{
	  if(last >= All.MaxPart)
	    Nodes[last].u.d.nextnode = no;
	  else
	    Nextnode[last] = no;
	}
      last = no;
      mass = 0;
      s[0] = 0;
      s[1] = 0;
      s[2] = 0;
      for(j = 0; j < 8; j++)
	{
	  if((p = suns[j]) >= 0)
	    {
	      for(jj = j + 1; jj < 8; jj++)
		if((pp = suns[jj]) >= 0)
		  break;
	      if(jj < 8)	
		nextsib = pp;
	      else
		nextsib = sib;
	      subfind_loctree_update_node_recursive(p, nextsib, no);
	      if(p >= All.MaxPart)	
		{
		  mass += Nodes[p].u.d.mass;	
		  s[0] += Nodes[p].u.d.mass * Nodes[p].u.d.s[0];
		  s[1] += Nodes[p].u.d.mass * Nodes[p].u.d.s[1];
		  s[2] += Nodes[p].u.d.mass * Nodes[p].u.d.s[2];
		}
	      else		
		{
		  mass += P[p].Mass;
		  s[0] += P[p].Mass * P[p].Pos[0];
		  s[1] += P[p].Mass * P[p].Pos[1];
		  s[2] += P[p].Mass * P[p].Pos[2];
		}
	    }
	}
      if(mass > 0)
	{
	  s[0] /= mass;
	  s[1] /= mass;
	  s[2] /= mass;
	}
      else
	{
	  s[0] = Nodes[no].center[0];
	  s[1] = Nodes[no].center[1];
	  s[2] = Nodes[no].center[2];
	}
      Nodes[no].u.d.s[0] = s[0];
      Nodes[no].u.d.s[1] = s[1];
      Nodes[no].u.d.s[2] = s[2];
      Nodes[no].u.d.mass = mass;
      Nodes[no].u.d.sibling = sib;
      Nodes[no].u.d.father = father;
    }
  else				
    {
      if(last >= 0)
	{
	  if(last >= All.MaxPart)
	    Nodes[last].u.d.nextnode = no;
	  else
	    Nextnode[last] = no;
	}
      last = no;
      if(no < All.MaxPart)	
	Father[no] = father;
    }
}
void subfind_loctree_update_node_recursive ( int no , int sib , int father ) { int j , jj , p , pp = 0 , nextsib , suns [ 8 ] ; double mass ; double s [ 3 ] ; if ( no >= All . MaxPart ) { for ( j = 0 ; j < 8 ; j ++ ) suns [ j ] = Nodes [ no ] . u . suns [ j ] ; if ( last >= 0 ) { if ( last >= All . MaxPart ) Nodes [ last ] . u . d . nextnode = no ; else Nextnode [ last ] = no ; } last = no ; mass = 0 ; s [ 0 ] = 0 ; s [ 1 ] = 0 ; s [ 2 ] = 0 ; for ( j = 0 ; j < 8 ; j ++ ) { if ( ( p = suns [ j ] ) >= 0 ) { for ( jj = j + 1 ; jj < 8 ; jj ++ ) if ( ( pp = suns [ jj ] ) >= 0 ) break ; if ( jj < 8 ) nextsib = pp ; else nextsib = sib ; subfind_loctree_update_node_recursive ( p , nextsib , no ) ; if ( p >= All . MaxPart ) { mass += Nodes [ p ] . u . d . mass ; s [ 0 ] += Nodes [ p ] . u . d . mass * Nodes [ p ] . u . d . s [ 0 ] ; s [ 1 ] += Nodes [ p ] . u . d . mass * Nodes [ p ] . u . d . s [ 1 ] ; s [ 2 ] += Nodes [ p ] . u . d . mass * Nodes [ p ] . u . d . s [ 2 ] ; } else { mass += P [ p ] . Mass ; s [ 0 ] += P [ p ] . Mass * P [ p ] . Pos [ 0 ] ; s [ 1 ] += P [ p ] . Mass * P [ p ] . Pos [ 1 ] ; s [ 2 ] += P [ p ] . Mass * P [ p ] . Pos [ 2 ] ; } } } if ( mass > 0 ) { s [ 0 ] /= mass ; s [ 1 ] /= mass ; s [ 2 ] /= mass ; } else { s [ 0 ] = Nodes [ no ] . center [ 0 ] ; s [ 1 ] = Nodes [ no ] . center [ 1 ] ; s [ 2 ] = Nodes [ no ] . center [ 2 ] ; } Nodes [ no ] . u . d . s [ 0 ] = s [ 0 ] ; Nodes [ no ] . u . d . s [ 1 ] = s [ 1 ] ; Nodes [ no ] . u . d . s [ 2 ] = s [ 2 ] ; Nodes [ no ] . u . d . mass = mass ; Nodes [ no ] . u . d . sibling = sib ; Nodes [ no ] . u . d . father = father ; } else { if ( last >= 0 ) { if ( last >= All . MaxPart ) Nodes [ last ] . u . d . nextnode = no ; else Nextnode [ last ] = no ; } last = no ; if ( no < All . MaxPart ) Father [ no ] = father ; } }
this routine computes the multipole moments for a given internal node and
 all its subnodes using a recursive computation.
this routine computes the multipole moments for a given internal node and all its subnodes using a recursive computation .
/* this "backup" is necessary because the nextnode entry will
					   overwrite one element (union!) */ /* check if we have a sibling on the same level */ /* yes, we do */ /* an internal node or pseudo particle */ /* we assume a fixed particle mass */ /* a particle */ /* single particle or pseudo particle */ /* only set it for single particles */