// bsfc repartitioning scheme
void create_element(ElemPack* elem2, ElementsHashTable* HT_Elem_Ptr, HashTable* HT_Node_Ptr, int myid)
{
    Element* newelement = HT_Elem_Ptr->generateElement();
    double e_error = 0;
    construct_el(newelement, elem2, HT_Node_Ptr, myid, &e_error);
    
    Element* EmTemp = (Element*) HT_Elem_Ptr->lookup(newelement->pass_key());
    if(EmTemp != NULL)
    { // update this element
      // first check that it is the same element
      // if the generation, son number, and parent keys are the same then will
      // be the same element unless the initial mesh was too fine and 
      // multiple elements had the same initial key
        assert(elem2->generation == EmTemp->get_gen());
        if(elem2->generation > 0)
        {
            assert(elem2->which_son == EmTemp->get_which_son());
        }
        // the same element...
        HT_Elem_Ptr->remove(elem2->key, 1, stdout, myid, 27);
        delete EmTemp;
    }
    if(!((*(newelement->pass_key() + 0) == 0) && (*(newelement->pass_key() + 1) == 0)))
        HT_Elem_Ptr->add(newelement->pass_key(), newelement);
    else
        delete newelement;
    //printf("processor %d just added element %u %u\n",myid, elem2->key[0], elem2->key[1]);
    if(myid == 3 && elem2->key[0] == 0)
        e_error = 0;
    
    return;
}
// bsfc repartitioning scheme
void create_element(ElemPack* elem2, HashTable* HT_Elem_Ptr, 
		    HashTable* HT_Node_Ptr, int myid)
{
  Element* newelement = new Element();
  construct_el(newelement, elem2, HT_Node_Ptr, myid);
  
  Element* EmTemp = (Element*) HT_Elem_Ptr->lookup(newelement->pass_key());
  if(EmTemp != NULL) {// update this element
    // first check that it is the same element
    // if the generation, son number, and elm_loc are the same then will
    // be the same element unless the initial mesh was too fine and 
    // multiple elements had the same initial key
    assert(elem2->generation == EmTemp->get_gen());
    if(elem2->generation > 0) {
      assert(elem2->which_son == EmTemp->get_which_son());
      int i =0;
      while(i<2) {
	if(elem2->elm_loc[i] != *(EmTemp->get_elm_loc()+i))
	  assert(0);
	i++;
      }
    }
    // the same element...
    HT_Elem_Ptr->remove(elem2->key);
    delete EmTemp;
  }
  HT_Elem_Ptr->add(newelement->pass_key(), newelement);
  //printf("processor %d just added element %u %u\n",myid, elem2->key[0], elem2->key[1]);

  return;
}
/**
 * create_element() is a friend function of the Element and Node classes. After receiving an ElemPack, create_element()
 * instances a new element, calls construct_el() to transfer data from ElemPack to the new element, and inserts the new
 * element into the Hashtable. Don't call this if s_flag is 0 (original repartitioning scheme)
 */
void create_element(ElemPack* elem2, ElementsHashTable* HT_Elem_Ptr, HashTable* HT_Node_Ptr, int myid, double* e_error)
{
    
    Element* newelement = HT_Elem_Ptr->generateElement();
    
    construct_el(newelement, elem2, HT_Node_Ptr, myid, e_error);
    
    HT_Elem_Ptr->add(newelement->pass_key(), newelement);
    
    if(!newelement->get_refined_flag()) //if parent .... don't care about neighbor info
        check_neighbor_info(newelement, HT_Elem_Ptr, myid);
    
}