/*! destroy_element() is a friend function of the Element and Node classes that does the following
 *
 *  1.  Update the neighbor_proc of the neighbors
 *  1.1 if neighbor is at the same proc---->ok
 *  1.2 if neighbor is at the target proc-->done when the element 
 *     is created in its new subdomain
 *  1.3 if neighbor is at a 3rd proc------->these elements are linked 
 *     for later communication
 *
 *  2.  Remove element from the hashtable
 *
 *  3.  Remove some nodes..........later not now
 */
void destroy_element(void *r_element_in, HashTable* HT_Elem_Ptr, HashTable* HT_Node_Ptr, int target_proc,
                     ELinkPtr* EL_head)
{
    
    int myid, numprocs, i;
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &myid);
    Element *r_element = (Element *) r_element_in;
    
    if(!r_element->get_refined_flag()) //if parent don't care about neighbor info
    {
        for(i = 0; i < 8; i++)
        {
            if(r_element->neigh_proc[i] == myid)
                same_proc(r_element, HT_Elem_Ptr, target_proc, i);
            
            else if(r_element->neigh_proc[i] != myid && r_element->neigh_proc[i] != target_proc
                    && r_element->neigh_proc[i] >= 0)
                diff_proc(r_element, HT_Elem_Ptr, target_proc, i, EL_head);
        }
    }
    
    HT_Elem_Ptr->remove(r_element->key, 1, stdout, myid, 26);
    
}
void destroy_element(Element* r_element, 
		     HashTable* HT_Elem_Ptr, HashTable* HT_Node_Ptr, 
		     int target_proc, ELinkPtr* EL_head)

  /*1.  Update the neighbor_proc of the neighbors
    1.1 if neighbor is at the same proc---->ok
    1.2 if neighbor is at the target proc-->done when the element 
        is created in its new subdomain
    1.3 if neighbor is at a 3rd proc------->these elements are linked 
        for later communication

    2.  Remove element from the hashtable

    3.  Remove some nodes..........later not now*/


{

  int myid, numprocs, i;
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  

  if(!r_element->get_refined_flag())//if father don't care about neighbor info
    {
      for(i=0; i<8; i++)
	{
	  if(r_element->neigh_proc[i] == myid)
	    same_proc(r_element, HT_Elem_Ptr,target_proc, i);
	  
	  else if(r_element->neigh_proc[i] != myid && 
		  r_element->neigh_proc[i] != target_proc && r_element->neigh_proc[i] >= 0)
	    diff_proc(r_element,HT_Elem_Ptr, 
		      target_proc, i, EL_head);
	}
    }

  HT_Elem_Ptr->remove(r_element->key);
}