当前位置: 首页>>代码示例>>C++>>正文


C++ MeshEditor::initCells方法代码示例

本文整理汇总了C++中MeshEditor::initCells方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshEditor::initCells方法的具体用法?C++ MeshEditor::initCells怎么用?C++ MeshEditor::initCells使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MeshEditor的用法示例。


在下文中一共展示了MeshEditor::initCells方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........

  CellType::Type type;
  double t;
  unsigned int id, tdim, gdim, num_vertices, num_cells, num_entities;
  std::ifstream in;
  std::list<dVertex> vlist;
  std::list<dCell> dmesh;
  for(std::vector<std::string>::iterator it = chkp_files.begin(); 
      it != chkp_files.end(); ++it) { 

    in.open(it->c_str(), std::ifstream::binary);

    if(in.good()) {
      in.read((char *)&id, sizeof(unsigned int));
      in.read((char *)&t, sizeof(double));
      
      in.read((char *)&type, sizeof(CellType::Type));
      in.read((char *)&tdim, sizeof(unsigned int));
      in.read((char *)&gdim, sizeof(unsigned int));

      in.read((char *)&num_vertices, sizeof(unsigned int));
      in.read((char *)&num_cells, sizeof(unsigned int));
      in.read((char *)&num_entities, sizeof(unsigned int));

      double *coords = new double[gdim *num_vertices];
      in.read((char *)coords, (gdim * num_vertices) * sizeof(double));
      
      std::list<dVertex> _vlist;
      int vi = 0;
      for(unsigned int i = 0; i < gdim * num_vertices; i += gdim) {
	switch(gdim)
	{
	case 2:
	  _vlist.push_back(dVertex(vi++,  Point(coords[i], coords[i+1]))); break;
	case 3:
	  _vlist.push_back(dVertex(vi++,  Point(coords[i], coords[i+1], coords[i+2]))); break;
	}
      }
      delete[] coords;

      unsigned int *cells = new unsigned int[num_entities * num_cells];
      in.read((char *)cells, (num_entities * num_cells) * sizeof(unsigned int));

      unsigned int *mapping = new unsigned int[_vlist.size()];
      in.read((char *)mapping, _vlist.size() * sizeof(unsigned int));

      unsigned int *mp = &mapping[0];
      std::map<unsigned int, unsigned int> vmap;      
      for(std::list<dVertex>::iterator it = _vlist.begin(); 
	  it != _vlist.end(); ++it) 
	vmap[it->id] = *(mp++);
      delete[] mapping;	
      
      Array<unsigned int> v;
      for(unsigned int i = 0; i < num_entities * num_cells; i += num_entities) {
	v.clear();
	for(unsigned int j = 0; j < num_entities; j++)
	  v.push_back(vmap[cells[i+j]]);
	dmesh.push_back(dCell(v));
      }
      delete[] cells;

      unsigned int num_ghost;
      in.read((char *)&num_ghost, sizeof(unsigned int));
      unsigned int *ghosts = new unsigned int[2 * num_ghost];
      in.read((char *)ghosts, 2*num_ghost * sizeof(unsigned int));
      
      std::set<unsigned int> ghost_set;
      for (unsigned int i = 0; i < 2 * num_ghost; i += 2)
	ghost_set.insert(ghosts[i]);
      delete[] ghosts;

      for(std::list<dVertex>::iterator it = _vlist.begin(); 
	  it != _vlist.end(); ++it) 
	if(ghost_set.find(it->id) == ghost_set.end()) 
	  vlist.push_back(dVertex(vmap[it->id], it->p));
    }
    in.close();
  }

  Mesh mesh;
  MeshEditor editor;
  editor.open(mesh, type, tdim, gdim);
  editor.initVertices(vlist.size());
  editor.initCells(dmesh.size());

  
  for(std::list<dVertex>::iterator it = vlist.begin(); it != vlist.end(); ++it)
    editor.addVertex(it->id, it->p);

  unsigned int ci = 0;
  for(std::list<dCell>::iterator it = dmesh.begin(); it != dmesh.end(); ++it)
    editor.addCell(ci++, it->vertices);
  
  editor.close();

  File mesh_file("mesh.xml");
  mesh_file << mesh;

}
开发者ID:njansson,项目名称:unicorn-hpc,代码行数:101,代码来源:extract.cpp


注:本文中的MeshEditor::initCells方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。