⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mesh_data.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 2 页
字号:
      // when active, use our _id_node map      libmesh_assert (_node_id_map_closed);      std::map<unsigned int,	       const Node*>::const_iterator pos = _id_node.find(fid);      if (pos == _id_node.end())        {	  std::cerr << "ERROR: Have no Node* associated with the foreign id = "		    << fid		    << std::endl;	  libmesh_error();	  return NULL;	}      else	  return pos->second;    }  else if (_compatibility_mode)      // when only in compatibility mode,       // return the node stored in the MeshBase       // under its current id      return this->_mesh.node_ptr(fid);  // should never get here  libmesh_error();  return NULL;}unsigned int MeshData::node_to_foreign_id (const Node* n) const{  libmesh_assert (n != NULL);  if (_active)    {      // when active, use our _node_id map      libmesh_assert (_node_id_map_closed);      // look it up in the map      std::map<const Node*,	       unsigned int>::const_iterator pos = _node_id.find(n);            if (pos == _node_id.end())        {	  std::cerr << "ERROR: No foreign id stored for the node "		    << "with the libMesh id = "		    << n->id()		    << std::endl;	  libmesh_error();	  return 0;	}      else	  return pos->second;    }  else if (_compatibility_mode)    // when only in compatibility mode,     // return libMesh's node id    return n->id();  // should never get here  libmesh_error();  return 0;}const Elem* MeshData::foreign_id_to_elem (const unsigned int fid) const{  if (_active)    {      // when active, use our _id_elem map      libmesh_assert (_elem_id_map_closed);            std::map<unsigned int,	       const Elem*>::const_iterator pos = _id_elem.find(fid);            if (pos == _id_elem.end())        {	  std::cerr << "ERROR: Have no Elem* associated with the foreign id = "		    << fid		    << std::endl;	  libmesh_error();	  return NULL;	}      else	  return pos->second;    }  else if (_compatibility_mode)    // when only in compatibility mode,     // return element using the libMesh id    return this->_mesh.elem(fid);  // should never get here  libmesh_error();  return NULL;}unsigned int MeshData::elem_to_foreign_id (const Elem* e) const{  libmesh_assert (e != NULL);  if (_active)    {      // when active, use our _id_elem map      libmesh_assert (_elem_id_map_closed);             // look it up in the map             std::map<const Elem*,	       unsigned int>::const_iterator pos = _elem_id.find(e);      if (pos == _elem_id.end())        {	  std::cerr << "ERROR: No foreign id stored for the element "		    << "with the libMesh id = "		    << e->id()		    << std::endl;	  libmesh_error();	  return 0;	}      else	  return pos->second;    }  else if (_compatibility_mode)    // when only in compatibility mode,     // return libMesh's element id    return e->id();  // should never get here  libmesh_error();  return 0;}void MeshData::insert_node_data (std::map<const Node*,				 std::vector<Number> >& nd,				 const bool close_elem_data){  libmesh_assert (this->_active || this->_compatibility_mode);  // these are also true in compatibility mode  libmesh_assert (this->_node_id_map_closed);  if (this->_node_data_closed)    {      std::cerr << "ERROR: Nodal data already closed!  Use clear() first!"		<< std::endl;      libmesh_error();    }  libmesh_assert (this->_node_data.empty());#ifdef DEBUG  std::map<const Node*,            std::vector<Number> >::const_iterator nd_pos = nd.begin();  std::map<const Node*,            std::vector<Number> >::const_iterator nd_end = nd.end();  // Compare entity-by-entity that the  // sizes of the std::vector's are identical.  // For this, simply take the length of the 0th  // entry as reference length, and compare this  // with the length of the 1st, 2nd...  libmesh_assert (nd_pos != nd_end);  const unsigned int reference_length = (*nd_pos).second.size();  // advance, so that we compare with the 1st  ++nd_pos;  for (; nd_pos != nd_end; ++nd_pos)    if ( (*nd_pos).second.size() != reference_length)       {	std::cerr << "ERROR: Size mismatch."		  << std::endl;	libmesh_error();      }#endif  // copy over  _node_data = nd;  // we may freely trash the nd  nd.clear();  // close node data  this->_node_data_closed = true;  // if user wants to, then close elem data, too  if (close_elem_data)    {      libmesh_assert((this->_elem_id_map_closed));      this->_elem_data_closed = true;    }}void MeshData::insert_elem_data (std::map<const Elem*,				 std::vector<Number> >& ed,				 const bool close_node_data){  libmesh_assert (this->_active || this->_compatibility_mode);  // these are also true in compatibility mode  libmesh_assert (this->_elem_id_map_closed);  if (this->_elem_data_closed)    {      std::cerr << "ERROR: Element data already closed!  Use clear() first!"		<< std::endl;      libmesh_error();    }  libmesh_assert (this->_elem_data.empty());#ifdef DEBUG  std::map<const Elem*,            std::vector<Number> >::const_iterator ed_pos = ed.begin();  std::map<const Elem*,            std::vector<Number> >::const_iterator ed_end = ed.end();  // Compare entity-by-entity that the  // sizes of the std::vector's are identical.  const unsigned int reference_length = (*ed_pos).second.size();  ++ed_pos;  for (; ed_pos != ed_end; ++ed_pos)    if ( (*ed_pos).second.size() != reference_length)       {	std::cerr << "ERROR: Size mismatch."		  << std::endl;	libmesh_error();      }#endif  // copy over  _elem_data = ed;  // we may freely trash the ed  ed.clear();  // close elem data  this->_elem_data_closed = true;  // if user wants to, then close node data, too  if (close_node_data)    {      libmesh_assert((this->_node_id_map_closed));      this->_node_data_closed = true;    }}unsigned int MeshData::n_val_per_node () const{  libmesh_assert (this->_active || this->_compatibility_mode);  libmesh_assert (this->_node_data_closed);  if (!this->_node_data.empty())    {      std::map<const Node*, 	       std::vector<Number> >::const_iterator pos = _node_data.begin();      libmesh_assert (pos != _node_data.end());      return (pos->second.size());    }  else      return 0;}unsigned int MeshData::n_node_data () const{  libmesh_assert (this->_active || this->_compatibility_mode);  libmesh_assert (this->_node_data_closed);  return this->_node_data.size();}unsigned int MeshData::n_val_per_elem () const{  libmesh_assert (this->_active || this->_compatibility_mode);  libmesh_assert (this->_elem_data_closed);  if (!_elem_data.empty())    {      std::map<const Elem*, 	       std::vector<Number> >::const_iterator pos = _elem_data.begin();      libmesh_assert (pos != _elem_data.end());      return (pos->second.size());    }  else      return 0;}unsigned int MeshData::n_elem_data () const{  libmesh_assert (this->_active || this->_compatibility_mode);  libmesh_assert (this->_elem_data_closed);  return _elem_data.size();}void MeshData::assign (const MeshData& omd){  this->_data_descriptor    = omd._data_descriptor;  this->_node_id_map_closed = omd._node_id_map_closed;  this->_node_data_closed   = omd._node_data_closed;  // we have to be able to modify our elem id maps  libmesh_assert (!this->_elem_id_map_closed);  this->_elem_data_closed   = omd._elem_data_closed;  this->_active             = omd._active;  this->_compatibility_mode = omd._compatibility_mode;  // this is ok because we do not manage the UnvHeader  // in terms of memory, but only hold a pointer to it...  this->_unv_header         = omd._unv_header;  // Now copy the foreign id maps -- but only for the   // nodes.  The nodes of the boundary mesh are actually  // nodes of the volume mesh.  this->_node_id = omd._node_id;  this->_id_node = omd._id_node;  // The element vector of the boundary mesh contains elements  // that are new, and there _cannot_ be any associated  // foreign id in the maps.  Therefore, fill the maps with  // the libMesh id's.  But only when the other MeshData  // has element ids.  if ((this->_active) && (omd._elem_id.size() != 0))    {      MeshBase::const_element_iterator       elem_it  = _mesh.elements_begin();      const MeshBase::const_element_iterator elem_end = _mesh.elements_end();      for (; elem_it != elem_end; ++elem_it)        {	  const Elem* elem = *elem_it;  	  this->add_foreign_elem_id(elem, elem->id());	}    }  // now we can safely assign omd's value  this->_elem_id_map_closed   = omd._elem_id_map_closed;    // and finally the node- and element-associated data  this->_node_data = omd._node_data;  this->_elem_data = omd._elem_data;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -