~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to dolfin/mesh/SubMesh.cpp

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
SubMesh::SubMesh(const Mesh& mesh, const SubDomain& sub_domain)
36
36
{
37
37
  // Create mesh function and mark sub domain
38
 
  MeshFunction<uint> sub_domains(mesh, mesh.topology().dim());
 
38
  MeshFunction<std::size_t> sub_domains(mesh, mesh.topology().dim());
39
39
  sub_domains = 0;
40
40
  sub_domain.mark(sub_domains, 1);
41
41
 
44
44
}
45
45
//-----------------------------------------------------------------------------
46
46
SubMesh::SubMesh(const Mesh& mesh,
47
 
                 const MeshFunction<uint>& sub_domains, uint sub_domain)
 
47
                 const MeshFunction<std::size_t>& sub_domains, std::size_t sub_domain)
48
48
{
49
49
  // Create sub mesh
50
50
  init(mesh, sub_domains, sub_domain);
56
56
}
57
57
//-----------------------------------------------------------------------------
58
58
void SubMesh::init(const Mesh& mesh,
59
 
                   const MeshFunction<uint>& sub_domains, uint sub_domain)
 
59
                   const MeshFunction<std::size_t>& sub_domains, std::size_t sub_domain)
60
60
{
61
61
  // Open mesh for editing
62
62
  MeshEditor editor;
64
64
              mesh.topology().dim(), mesh.geometry().dim());
65
65
 
66
66
  // Extract cells
67
 
  std::set<uint> cells;
 
67
  std::set<std::size_t> cells;
68
68
  for (CellIterator cell(mesh); !cell.end(); ++cell)
69
69
  {
70
70
    if (sub_domains[*cell] == sub_domain)
72
72
  }
73
73
 
74
74
  // Map to keep track of new local indices for vertices
75
 
  std::map<uint, uint> local_vertex_indices;
 
75
  std::map<std::size_t, std::size_t> local_vertex_indices;
76
76
 
77
77
  // Add cells
78
78
  editor.init_cells(cells.size());
79
 
  uint current_cell = 0;
80
 
  uint current_vertex = 0;
81
 
  for (std::set<uint>::iterator cell_it = cells.begin();
 
79
  std::size_t current_cell = 0;
 
80
  std::size_t current_vertex = 0;
 
81
  for (std::set<std::size_t>::iterator cell_it = cells.begin();
82
82
       cell_it != cells.end(); ++cell_it)
83
83
  {
84
 
    std::vector<uint> cell_vertices;
 
84
    std::vector<std::size_t> cell_vertices;
85
85
    Cell cell(mesh, *cell_it);
86
86
    for (VertexIterator vertex(cell); !vertex.end(); ++vertex)
87
87
    {
88
 
      const uint parent_vertex_index = vertex->index();
89
 
      uint local_vertex_index = 0;
90
 
      std::map<uint, uint>::iterator vertex_it
 
88
      const std::size_t parent_vertex_index = vertex->index();
 
89
      std::size_t local_vertex_index = 0;
 
90
      std::map<std::size_t, std::size_t>::iterator vertex_it
91
91
        = local_vertex_indices.find(parent_vertex_index);
92
92
      if (vertex_it != local_vertex_indices.end())
93
 
      {
94
93
        local_vertex_index = vertex_it->second;
95
 
      }
96
94
      else
97
95
      {
98
96
        local_vertex_index = current_vertex++;
105
103
 
106
104
  // Add vertices
107
105
  editor.init_vertices(local_vertex_indices.size());
108
 
  for (std::map<uint, uint>::iterator it = local_vertex_indices.begin();
 
106
  for (std::map<std::size_t, std::size_t>::iterator it = local_vertex_indices.begin();
109
107
       it != local_vertex_indices.end(); ++it)
110
108
  {
111
109
    Vertex vertex(mesh, it->first);
112
110
    if (MPI::num_processes() > 1)
113
111
      error("SubMesh::init not working in parallel");
 
112
 
114
113
    // FIXME: Get global vertex index
115
114
    editor.add_vertex(it->second, vertex.point());
116
115
  }
119
118
  editor.close();
120
119
 
121
120
  // Build local-to-parent mapping for vertices
122
 
  boost::shared_ptr<MeshFunction<unsigned int> > parent_vertex_indices
 
121
  boost::shared_ptr<MeshFunction<std::size_t> > parent_vertex_indices
123
122
    = data().create_mesh_function("parent_vertex_indices", 0);
124
 
  for (std::map<uint, uint>::iterator it = local_vertex_indices.begin();
 
123
  for (std::map<std::size_t, std::size_t>::iterator it = local_vertex_indices.begin();
125
124
       it != local_vertex_indices.end(); ++it)
 
125
  {
126
126
    (*parent_vertex_indices)[it->second] = it->first;
 
127
  }
127
128
}
128
129
//-----------------------------------------------------------------------------