OpenCMISS-Zinc C++ API Documentation
mesh.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 
10 #ifndef CMZN_MESH_HPP__
11 #define CMZN_MESH_HPP__
12 
13 #include "opencmiss/zinc/mesh.h"
14 #include "opencmiss/zinc/field.hpp"
15 #include "opencmiss/zinc/element.hpp"
16 #include "opencmiss/zinc/elementfieldtemplate.hpp"
17 #include "opencmiss/zinc/elementtemplate.hpp"
18 #include "opencmiss/zinc/differentialoperator.hpp"
19 
20 namespace OpenCMISS
21 {
22 namespace Zinc
23 {
24 
25 class MeshGroup;
26 
34 class Mesh
35 {
36 
37 protected:
38  cmzn_mesh_id id;
39 
40 public:
41 
42  Mesh() : id(0)
43  { }
44 
45  // takes ownership of C handle, responsibility for destroying it
46  explicit Mesh(cmzn_mesh_id mesh_id) : id(mesh_id)
47  { }
48 
49  Mesh(const Mesh& mesh) :
50  id(cmzn_mesh_access(mesh.id))
51  { }
52 
53  ~Mesh()
54  {
55  if (0 != id)
56  {
57  cmzn_mesh_destroy(&id);
58  }
59  }
60 
66  bool isValid() const
67  {
68  return (0 != id);
69  }
70 
71  Mesh& operator=(const Mesh& mesh)
72  {
73  cmzn_mesh_id temp_id = cmzn_mesh_access(mesh.id);
74  if (0 != id)
75  {
76  cmzn_mesh_destroy(&id);
77  }
78  id = temp_id;
79  return *this;
80  }
81 
87  cmzn_mesh_id getId() const
88  {
89  return id;
90  }
91 
99  inline MeshGroup castGroup();
100 
107  bool containsElement(const Element& element)
108  {
109  return cmzn_mesh_contains_element(id, element.getId());
110  }
111 
131  {
132  return Elementfieldtemplate(cmzn_mesh_create_elementfieldtemplate(id, basis.getId()));
133  }
134 
145  {
146  return Elementtemplate(cmzn_mesh_create_elementtemplate(id));
147  }
148 
161  Element createElement(int identifier, const Elementtemplate& elementTemplate)
162  {
163  return Element(cmzn_mesh_create_element(id, identifier, elementTemplate.getId()));
164  }
165 
179  {
180  return Elementiterator(cmzn_mesh_create_elementiterator(id));
181  }
182 
195  int defineElement(int identifier, const Elementtemplate& elementTemplate)
196  {
197  return cmzn_mesh_define_element(id, identifier, elementTemplate.getId());
198  }
199 
207  {
208  return cmzn_mesh_destroy_all_elements(id);
209  }
210 
219  int destroyElement(const Element& element)
220  {
221  return cmzn_mesh_destroy_element(id, element.getId());
222  }
223 
235  int destroyElementsConditional(const Field& conditionalField)
236  {
237  return cmzn_mesh_destroy_elements_conditional(id,
238  conditionalField.getId());
239  }
240 
248  {
249  return Element(cmzn_mesh_find_element_by_identifier(id, identifier));
250  }
251 
264  {
265  return Differentialoperator(cmzn_mesh_get_chart_differentialoperator(
266  id, order, term));
267  }
268 
275  {
276  return cmzn_mesh_get_dimension(id);
277  }
278 
284  inline Fieldmodule getFieldmodule() const;
285 
293  {
294  return Mesh(cmzn_mesh_get_master_mesh(id));
295  }
296 
304  char *getName()
305  {
306  return cmzn_mesh_get_name(id);
307  }
308 
314  int getSize()
315  {
316  return cmzn_mesh_get_size(id);
317  }
318 
319 };
320 
321 inline bool operator==(const Mesh& a, const Mesh& b)
322 {
323  return cmzn_mesh_match(a.getId(), b.getId());
324 }
325 
326 inline Mesh Element::getMesh() const
327 {
328  return Mesh(cmzn_element_get_mesh(id));
329 }
330 
336 class MeshGroup : public Mesh
337 {
338 
339 public:
340 
341  // takes ownership of C handle, responsibility for destroying it
342  explicit MeshGroup(cmzn_mesh_group_id mesh_id) : Mesh(reinterpret_cast<cmzn_mesh_id>(mesh_id))
343  { }
344 
345  MeshGroup()
346  { }
347 
353  cmzn_mesh_group_id getId() const
354  {
355  return (cmzn_mesh_group_id)(id);
356  }
357 
366  int addElement(const Element& element)
367  {
368  return cmzn_mesh_group_add_element(
369  reinterpret_cast<cmzn_mesh_group_id>(id), element.getId());
370  }
371 
382  int addElementsConditional(const Field& conditionalField)
383  {
384  return cmzn_mesh_group_add_elements_conditional(
385  reinterpret_cast<cmzn_mesh_group_id>(id), conditionalField.getId());
386  }
387 
394  {
395  return cmzn_mesh_group_remove_all_elements(reinterpret_cast<cmzn_mesh_group_id>(id));
396  }
397 
406  int removeElement(const Element& element)
407  {
408  return cmzn_mesh_group_remove_element(reinterpret_cast<cmzn_mesh_group_id>(id),
409  element.getId());
410  }
411 
422  int removeElementsConditional(const Field& conditionalField)
423  {
424  return cmzn_mesh_group_remove_elements_conditional(
425  reinterpret_cast<cmzn_mesh_group_id>(id), conditionalField.getId());
426  }
427 
428 };
429 
431 {
432  return MeshGroup(cmzn_mesh_cast_group(id));
433 }
434 
441 {
442 private:
443 
444  cmzn_meshchanges_id id;
445 
446 public:
447 
448  Meshchanges() : id(0)
449  { }
450 
451  // takes ownership of C handle, responsibility for destroying it
452  explicit Meshchanges(cmzn_meshchanges_id meshchanges_id) :
453  id(meshchanges_id)
454  { }
455 
456  Meshchanges(const Meshchanges& meshchanges) :
457  id(cmzn_meshchanges_access(meshchanges.id))
458  { }
459 
460  Meshchanges& operator=(const Meshchanges& meshchanges)
461  {
462  cmzn_meshchanges_id temp_id = cmzn_meshchanges_access(meshchanges.id);
463  if (0 != id)
464  cmzn_meshchanges_destroy(&id);
465  id = temp_id;
466  return *this;
467  }
468 
469  ~Meshchanges()
470  {
471  if (0 != id)
472  cmzn_meshchanges_destroy(&id);
473  }
474 
480  bool isValid() const
481  {
482  return (0 != id);
483  }
484 
495  {
496  return cmzn_meshchanges_get_element_change_flags(id, element.getId());
497  }
498 
506  {
507  return cmzn_meshchanges_get_number_of_changes(id);
508  }
509 
516  {
517  return cmzn_meshchanges_get_summary_element_change_flags(id);
518  }
519 };
520 
521 } // namespace Zinc
522 }
523 
524 #endif /* CMZN_MESH_HPP__ */
int addElement(const Element &element)
Definition: mesh.hpp:366
A single finite element from a mesh.
Definition: element.hpp:34
int addElementsConditional(const Field &conditionalField)
Definition: mesh.hpp:382
int destroyAllElements()
Definition: mesh.hpp:206
int defineElement(int identifier, const Elementtemplate &elementTemplate)
Definition: mesh.hpp:195
A set of basis functions that can apply over an element of a given dimension.
Definition: elementbasis.hpp:28
Elementtemplate createElementtemplate()
Definition: mesh.hpp:144
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:51
Elementfieldtemplate createElementfieldtemplate(const Elementbasis &basis)
Definition: mesh.hpp:130
Differentialoperator getChartDifferentialoperator(int order, int term)
Definition: mesh.hpp:263
int removeAllElements()
Definition: mesh.hpp:393
Mesh getMesh() const
Definition: mesh.hpp:326
cmzn_mesh_group_id getId() const
Definition: mesh.hpp:353
int ChangeFlags
Definition: element.hpp:105
Describes the derivative of a field to evaluate.
Definition: differentialoperator.hpp:26
Element::ChangeFlags getElementChangeFlags(const Element &element)
Definition: mesh.hpp:494
int removeElement(const Element &element)
Definition: mesh.hpp:406
cmzn_field_id getId() const
Definition: field.hpp:103
An iterator for looping through all the elements in a mesh.
Definition: element.hpp:423
MeshGroup castGroup()
Definition: mesh.hpp:430
Element findElementByIdentifier(int identifier)
Definition: mesh.hpp:247
A description of element shape and field definitions.
Definition: elementtemplate.hpp:31
cmzn_element_id getId() const
Definition: element.hpp:207
cmzn_mesh_id getId() const
Definition: mesh.hpp:87
bool containsElement(const Element &element)
Definition: mesh.hpp:107
bool isValid() const
Definition: mesh.hpp:480
int getSize()
Definition: mesh.hpp:314
bool isValid() const
Definition: mesh.hpp:66
A subset of a master mesh.
Definition: mesh.hpp:336
char * getName()
Definition: mesh.hpp:304
int destroyElementsConditional(const Field &conditionalField)
Definition: mesh.hpp:235
Container/manager of fields and domains within a region.
Definition: fieldmodule.hpp:135
int destroyElement(const Element &element)
Definition: mesh.hpp:219
int getNumberOfChanges()
Definition: mesh.hpp:505
Mesh getMasterMesh()
Definition: mesh.hpp:292
cmzn_elementbasis_id getId() const
Definition: elementbasis.hpp:122
Element::ChangeFlags getSummaryElementChangeFlags()
Definition: mesh.hpp:515
cmzn_elementtemplate_id getId() const
Definition: elementtemplate.hpp:85
int removeElementsConditional(const Field &conditionalField)
Definition: mesh.hpp:422
The OpenCMISS namespace.
Definition: context.hpp:20
Elementiterator createElementiterator()
Definition: mesh.hpp:178
Element createElement(int identifier, const Elementtemplate &elementTemplate)
Definition: mesh.hpp:161
A finite element mesh consisting of a set of elements of fixed dimension.
Definition: mesh.hpp:34
int getDimension()
Definition: mesh.hpp:274
Fieldmodule getFieldmodule() const
Definition: fieldmodule.hpp:1791
Object describing changes to a mesh in a fieldmoduleevent.
Definition: mesh.hpp:440
A template defining field parameter mapping and interpolation over an element chart.
Definition: elementfieldtemplate.hpp:39