~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to dolfin/mesh/MeshEditor.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:
15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17
17
//
 
18
// Modified by Benjamin Kehlet, 2012
 
19
//
18
20
// First added:  2006-05-16
19
 
// Last changed: 2012-09-27
 
21
// Last changed: 2012-10-30
20
22
 
21
23
#include <dolfin/log/dolfin_log.h>
22
24
#include <dolfin/parameter/dolfin_parameter.h>
40
42
  // Do nothing
41
43
}
42
44
//-----------------------------------------------------------------------------
43
 
void MeshEditor::open(Mesh& mesh, uint tdim, uint gdim)
 
45
void MeshEditor::open(Mesh& mesh, std::size_t tdim, std::size_t gdim)
44
46
{
45
47
  switch (tdim)
46
48
  {
63
65
  }
64
66
}
65
67
//-----------------------------------------------------------------------------
66
 
void MeshEditor::open(Mesh& mesh, CellType::Type type, uint tdim, uint gdim)
 
68
void MeshEditor::open(Mesh& mesh, CellType::Type type, std::size_t tdim, std::size_t gdim)
67
69
{
68
70
  // Clear old mesh data
69
71
  mesh.clear();
84
86
  mesh._domains.init(tdim);
85
87
 
86
88
  // Initialize temporary storage for local cell data
87
 
  vertices.resize(mesh.type().num_vertices(tdim));
88
 
  std::fill(vertices.begin(), vertices.end(), 0);
 
89
  vertices = std::vector<std::size_t>(mesh.type().num_vertices(tdim), 0);
89
90
}
90
91
//-----------------------------------------------------------------------------
91
 
void MeshEditor::open(Mesh& mesh, std::string type, uint tdim, uint gdim)
 
92
void MeshEditor::open(Mesh& mesh, std::string type, std::size_t tdim, std::size_t gdim)
92
93
{
93
94
  if (type == "point")
94
95
    open(mesh, CellType::point, tdim, gdim);
106
107
  }
107
108
}
108
109
//-----------------------------------------------------------------------------
109
 
void MeshEditor::init_vertices(uint num_vertices)
 
110
void MeshEditor::init_vertices(std::size_t num_vertices)
110
111
{
111
112
  // Check if we are currently editing a mesh
112
113
  if (!mesh)
123
124
  mesh->_geometry.init(gdim, num_vertices);
124
125
}
125
126
//-----------------------------------------------------------------------------
126
 
void MeshEditor::init_cells(uint num_cells)
 
127
void MeshEditor::init_cells(std::size_t num_cells)
127
128
{
128
129
  // Check if we are currently editing a mesh
129
130
  if (!mesh)
140
141
  mesh->_topology(tdim, 0).init(num_cells, mesh->type().num_vertices(tdim));
141
142
}
142
143
//-----------------------------------------------------------------------------
143
 
void MeshEditor::add_vertex(uint index, const Point& p)
 
144
void MeshEditor::add_vertex(std::size_t index, const Point& p)
144
145
{
145
146
  add_vertex_global(index, index, p);
146
147
}
147
148
//-----------------------------------------------------------------------------
148
 
void MeshEditor::add_vertex(uint index, const std::vector<double>& x)
 
149
void MeshEditor::add_vertex(std::size_t index, const std::vector<double>& x)
149
150
{
150
151
  add_vertex_global(index, index, x);
151
152
}
152
153
//-----------------------------------------------------------------------------
153
 
void MeshEditor::add_vertex(uint index, double x)
 
154
void MeshEditor::add_vertex(std::size_t index, double x)
154
155
{
155
156
  dolfin_assert(gdim == 1);
156
157
  std::vector<double> p(1);
158
159
  add_vertex(index, p);
159
160
}
160
161
//-----------------------------------------------------------------------------
161
 
void MeshEditor::add_vertex(uint index, double x, double y)
 
162
void MeshEditor::add_vertex(std::size_t index, double x, double y)
162
163
{
163
164
  dolfin_assert(gdim == 2);
164
165
  std::vector<double> p(2);
167
168
  add_vertex(index, p);
168
169
}
169
170
//-----------------------------------------------------------------------------
170
 
void MeshEditor::add_vertex(uint index, double x, double y, double z)
 
171
void MeshEditor::add_vertex(std::size_t index, double x, double y, double z)
171
172
{
172
173
  dolfin_assert(gdim == 3);
173
174
  std::vector<double> p(3);
177
178
  add_vertex(index, p);
178
179
}
179
180
//-----------------------------------------------------------------------------
180
 
void MeshEditor::add_vertex_global(uint local_index, uint global_index,
 
181
void MeshEditor::add_vertex_global(std::size_t local_index,
 
182
                                   std::size_t global_index,
181
183
                                   const Point& p)
182
184
{
183
185
  // Geometric dimension
184
 
  const uint gdim = mesh->geometry().dim();
 
186
  const std::size_t gdim = mesh->geometry().dim();
185
187
 
186
188
  // Add vertex
187
189
  add_vertex_common(local_index, gdim);
192
194
  mesh->_topology.set_global_index(0, local_index, global_index);
193
195
}
194
196
//-----------------------------------------------------------------------------
195
 
void MeshEditor::add_vertex_global(uint local_index, uint global_index,
 
197
void MeshEditor::add_vertex_global(std::size_t local_index,
 
198
                                   std::size_t global_index,
196
199
                                   const std::vector<double>& x)
197
200
{
198
201
  // Add vertex
203
206
  mesh->_topology.set_global_index(0, local_index, global_index);
204
207
}
205
208
//-----------------------------------------------------------------------------
206
 
void MeshEditor::add_cell(uint c, uint v0, uint v1)
 
209
void MeshEditor::add_cell(std::size_t c, std::size_t v0, std::size_t v1)
207
210
{
208
211
  dolfin_assert(tdim == 1);
209
 
  std::vector<uint> vertices(2);
 
212
  std::vector<std::size_t> vertices(2);
210
213
  vertices[0] = v0;
211
214
  vertices[1] = v1;
212
215
  add_cell(c, c, vertices);
213
216
}
214
217
//-----------------------------------------------------------------------------
215
 
void MeshEditor::add_cell(uint c, uint v0, uint v1, uint v2)
 
218
void MeshEditor::add_cell(std::size_t c, std::size_t v0, std::size_t v1,
 
219
                          std::size_t v2)
216
220
{
217
221
  dolfin_assert(tdim == 2);
218
 
  std::vector<uint> vertices(3);
 
222
  std::vector<std::size_t> vertices(3);
219
223
  vertices[0] = v0;
220
224
  vertices[1] = v1;
221
225
  vertices[2] = v2;
222
226
  add_cell(c, c, vertices);
223
227
}
224
228
//-----------------------------------------------------------------------------
225
 
void MeshEditor::add_cell(uint c, uint v0, uint v1, uint v2, uint v3)
 
229
void MeshEditor::add_cell(std::size_t c, std::size_t v0, std::size_t v1,
 
230
                          std::size_t v2, std::size_t v3)
226
231
{
227
232
  dolfin_assert(tdim == 3);
228
 
  std::vector<uint> vertices(4);
 
233
  std::vector<std::size_t> vertices(4);
229
234
  vertices[0] = v0;
230
235
  vertices[1] = v1;
231
236
  vertices[2] = v2;
232
 
  vertices[2] = v3;
 
237
  vertices[3] = v3;
233
238
  add_cell(c, c, vertices);
234
239
}
235
240
//-----------------------------------------------------------------------------
236
 
void MeshEditor::add_cell(uint c, const std::vector<uint>& v)
 
241
void MeshEditor::add_cell(std::size_t c, const std::vector<std::size_t>& v)
237
242
{
238
243
  add_cell(c, c, v);
239
244
}
240
245
//-----------------------------------------------------------------------------
241
 
void MeshEditor::add_cell(uint local_index, uint global_index,
242
 
                          const std::vector<uint>& v)
 
246
void MeshEditor::add_cell(std::size_t local_index, std::size_t global_index,
 
247
                          const std::vector<std::size_t>& v)
243
248
{
244
249
  dolfin_assert(v.size() == tdim + 1);
245
250
 
265
270
  clear();
266
271
}
267
272
//-----------------------------------------------------------------------------
268
 
void MeshEditor::add_vertex_common(uint v, uint gdim)
 
273
void MeshEditor::add_vertex_common(std::size_t v, std::size_t gdim)
269
274
{
270
275
  // Check if we are currently editing a mesh
271
276
  if (!mesh)
306
311
  next_vertex++;
307
312
}
308
313
//-----------------------------------------------------------------------------
309
 
void MeshEditor::add_cell_common(uint c, uint tdim)
 
314
void MeshEditor::add_cell_common(std::size_t c, std::size_t tdim)
310
315
{
311
316
  // Check if we are currently editing a mesh
312
317
  if (!mesh)
358
363
  vertices.clear();
359
364
}
360
365
//-----------------------------------------------------------------------------
361
 
void MeshEditor::check_vertices(const std::vector<uint>& v) const
 
366
void MeshEditor::check_vertices(const std::vector<std::size_t>& v) const
362
367
{
363
 
  for (uint i = 0; i < v.size(); ++i)
 
368
  for (std::size_t i = 0; i < v.size(); ++i)
364
369
  {
365
370
    if (num_vertices > 0 && v[i] >= num_vertices)
366
371
    {