OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
element.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_ELEMENT_HPP__
11 #define CMZN_ELEMENT_HPP__
12 
13 #include "zinc/element.h"
14 #include "zinc/field.hpp"
15 #include "zinc/differentialoperator.hpp"
16 #include "zinc/node.hpp"
17 
18 namespace OpenCMISS
19 {
20 namespace Zinc
21 {
22 
32 {
33 private:
34 
35  cmzn_elementbasis_id id;
36 
37 public:
38 
39  Elementbasis() : id(0)
40  { }
41 
42  // takes ownership of C handle, responsibility for destroying it
43  explicit Elementbasis(cmzn_elementbasis_id element_basis_id) :
44  id(element_basis_id)
45  { }
46 
47  Elementbasis(const Elementbasis& elementBasis) :
48  id(cmzn_elementbasis_access(elementBasis.id))
49  { }
50 
51  Elementbasis& operator=(const Elementbasis& elementBasis)
52  {
53  cmzn_elementbasis_id temp_id = cmzn_elementbasis_access(elementBasis.id);
54  if (0 != id)
55  {
56  cmzn_elementbasis_destroy(&id);
57  }
58  id = temp_id;
59  return *this;
60  }
61 
62  ~Elementbasis()
63  {
64  if (0 != id)
65  {
66  cmzn_elementbasis_destroy(&id);
67  }
68  }
69 
75  bool isValid() const
76  {
77  return (0 != id);
78  }
79 
86  {
87  FUNCTION_TYPE_INVALID = CMZN_ELEMENTBASIS_FUNCTION_TYPE_INVALID,
89  FUNCTION_TYPE_CONSTANT = CMZN_ELEMENTBASIS_FUNCTION_TYPE_CONSTANT,
91  FUNCTION_TYPE_LINEAR_LAGRANGE = CMZN_ELEMENTBASIS_FUNCTION_TYPE_LINEAR_LAGRANGE,
94  FUNCTION_TYPE_QUADRATIC_LAGRANGE = CMZN_ELEMENTBASIS_FUNCTION_TYPE_QUADRATIC_LAGRANGE,
97  FUNCTION_TYPE_CUBIC_LAGRANGE = CMZN_ELEMENTBASIS_FUNCTION_TYPE_CUBIC_LAGRANGE,
100  FUNCTION_TYPE_LINEAR_SIMPLEX = CMZN_ELEMENTBASIS_FUNCTION_TYPE_LINEAR_SIMPLEX,
107  FUNCTION_TYPE_QUADRATIC_SIMPLEX = CMZN_ELEMENTBASIS_FUNCTION_TYPE_QUADRATIC_SIMPLEX,
115  FUNCTION_TYPE_CUBIC_HERMITE = CMZN_ELEMENTBASIS_FUNCTION_TYPE_CUBIC_HERMITE
118  };
119 
125  cmzn_elementbasis_id getId() const
126  {
127  return id;
128  }
129 
136  {
137  return cmzn_elementbasis_get_dimension(id);
138  }
139 
147  enum FunctionType getFunctionType(int chartComponent)
148  {
149  return static_cast<FunctionType>(cmzn_elementbasis_get_function_type(id, chartComponent));
150  }
151 
160  int setFunctionType(int chartComponent, FunctionType functionType)
161  {
162  return cmzn_elementbasis_set_function_type(id, chartComponent,
163  static_cast<cmzn_elementbasis_function_type>(functionType));
164  }
165 
172  {
173  return cmzn_elementbasis_get_number_of_nodes(id);
174  }
175 
189  {
190  return cmzn_elementbasis_get_number_of_functions(id);
191  }
192 
193 };
194 
195 class Fieldmodule;
196 class Mesh;
197 class Elementtemplate;
198 
205 class Element
206 {
207 private:
208 
209  cmzn_element_id id;
210 
211 public:
212 
213  Element() : id(0)
214  { }
215 
216  // takes ownership of C handle, responsibility for destroying it
217  explicit Element(cmzn_element_id element_id) :
218  id(element_id)
219  { }
220 
221  Element(const Element& element) :
222  id(cmzn_element_access(element.id))
223  { }
224 
225  ~Element()
226  {
227  if (0 != id)
228  {
229  cmzn_element_destroy(&id);
230  }
231  }
232 
238  bool isValid() const
239  {
240  return (0 != id);
241  }
242 
247  {
248  CHANGE_FLAG_NONE = CMZN_ELEMENT_CHANGE_FLAG_NONE,
250  CHANGE_FLAG_ADD = CMZN_ELEMENT_CHANGE_FLAG_ADD,
252  CHANGE_FLAG_REMOVE = CMZN_ELEMENT_CHANGE_FLAG_REMOVE,
254  CHANGE_FLAG_IDENTIFIER = CMZN_ELEMENT_CHANGE_FLAG_IDENTIFIER,
256  CHANGE_FLAG_DEFINITION = CMZN_ELEMENT_CHANGE_FLAG_DEFINITION,
258  CHANGE_FLAG_FIELD = CMZN_ELEMENT_CHANGE_FLAG_FIELD
260  };
261 
265  typedef int ChangeFlags;
266 
270  enum FaceType
271  {
272  FACE_TYPE_INVALID = CMZN_ELEMENT_FACE_TYPE_INVALID,
274  FACE_TYPE_ALL = CMZN_ELEMENT_FACE_TYPE_ALL,
276  FACE_TYPE_XI1_0 = CMZN_ELEMENT_FACE_TYPE_XI1_0,
278  FACE_TYPE_XI1_1 = CMZN_ELEMENT_FACE_TYPE_XI1_1,
280  FACE_TYPE_XI2_0 = CMZN_ELEMENT_FACE_TYPE_XI2_0,
282  FACE_TYPE_XI2_1 = CMZN_ELEMENT_FACE_TYPE_XI2_1,
284  FACE_TYPE_XI3_0 = CMZN_ELEMENT_FACE_TYPE_XI3_0,
286  FACE_TYPE_XI3_1 = CMZN_ELEMENT_FACE_TYPE_XI3_1
288  };
289 
290  Element& operator=(const Element& element)
291  {
292  cmzn_element_id temp_id = cmzn_element_access(element.id);
293  if (0 != id)
294  {
295  cmzn_element_destroy(&id);
296  }
297  id = temp_id;
298  return *this;
299  }
300 
305  {
306  SHAPE_TYPE_INVALID = CMZN_ELEMENT_SHAPE_TYPE_INVALID,
308  SHAPE_TYPE_LINE = CMZN_ELEMENT_SHAPE_TYPE_LINE,
310  SHAPE_TYPE_SQUARE = CMZN_ELEMENT_SHAPE_TYPE_SQUARE,
312  SHAPE_TYPE_TRIANGLE = CMZN_ELEMENT_SHAPE_TYPE_TRIANGLE,
314  SHAPE_TYPE_CUBE = CMZN_ELEMENT_SHAPE_TYPE_CUBE,
316  SHAPE_TYPE_TETRAHEDRON = CMZN_ELEMENT_SHAPE_TYPE_TETRAHEDRON,
318  SHAPE_TYPE_WEDGE12 = CMZN_ELEMENT_SHAPE_TYPE_WEDGE12,
320  SHAPE_TYPE_WEDGE13 = CMZN_ELEMENT_SHAPE_TYPE_WEDGE13,
322  SHAPE_TYPE_WEDGE23 = CMZN_ELEMENT_SHAPE_TYPE_WEDGE23
324  };
325 
330  {
331  POINT_SAMPLING_MODE_INVALID = CMZN_ELEMENT_POINT_SAMPLING_MODE_INVALID,
333  POINT_SAMPLING_MODE_CELL_CENTRES = CMZN_ELEMENT_POINT_SAMPLING_MODE_CELL_CENTRES,
335  POINT_SAMPLING_MODE_CELL_CORNERS = CMZN_ELEMENT_POINT_SAMPLING_MODE_CELL_CORNERS,
337  POINT_SAMPLING_MODE_CELL_POISSON = CMZN_ELEMENT_POINT_SAMPLING_MODE_CELL_POISSON,
342  POINT_SAMPLING_MODE_SET_LOCATION = CMZN_ELEMENT_POINT_SAMPLING_MODE_SET_LOCATION
344  };
345 
351  cmzn_element_id getId() const
352  {
353  return id;
354  }
355 
362  {
363  return cmzn_element_get_dimension(id);
364  }
365 
374  {
375  return cmzn_element_get_identifier(id);
376  }
377 
386  int setIdentifier(int identifier)
387  {
388  return cmzn_element_set_identifier(id, identifier);
389  }
390 
396  inline Mesh getMesh() const;
397 
407  {
408  return static_cast<ShapeType>(cmzn_element_get_shape_type(id));
409  }
410 
411  int merge(const Elementtemplate& elementTemplate);
412 
413 };
414 
415 inline bool operator==(const Element& a, const Element& b)
416 {
417  return a.getId() == b.getId();
418 }
419 
428 {
429 private:
430 
431  cmzn_elementtemplate_id id;
432 
433 public:
434 
435  Elementtemplate() : id(0)
436  { }
437 
438  // takes ownership of C handle, responsibility for destroying it
439  explicit Elementtemplate(cmzn_elementtemplate_id element_template_id) :
440  id(element_template_id)
441  { }
442 
443  Elementtemplate(const Elementtemplate& elementTemplate) :
444  id(cmzn_elementtemplate_access(elementTemplate.id))
445  { }
446 
447  Elementtemplate& operator=(const Elementtemplate& elementTemplate)
448  {
449  cmzn_elementtemplate_id temp_id = cmzn_elementtemplate_access(elementTemplate.id);
450  if (0 != id)
451  {
452  cmzn_elementtemplate_destroy(&id);
453  }
454  id = temp_id;
455  return *this;
456  }
457 
458  ~Elementtemplate()
459  {
460  if (0 != id)
461  {
462  cmzn_elementtemplate_destroy(&id);
463  }
464  }
465 
471  bool isValid() const
472  {
473  return (0 != id);
474  }
475 
481  cmzn_elementtemplate_id getId() const
482  {
483  return id;
484  }
485 
486  enum Element::ShapeType getElementShapeType()
487  {
488  return static_cast<Element::ShapeType>(cmzn_elementtemplate_get_element_shape_type(id));
489  }
490 
491  int setElementShapeType(enum Element::ShapeType shapeType)
492  {
493  return cmzn_elementtemplate_set_element_shape_type(id,
494  static_cast<cmzn_element_shape_type>(shapeType));
495  }
496 
503  {
504  return cmzn_elementtemplate_get_number_of_nodes(id);
505  }
506 
515  int setNumberOfNodes(int numberOfNodes)
516  {
517  return cmzn_elementtemplate_set_number_of_nodes(id, numberOfNodes);
518  }
519 
540  int defineFieldSimpleNodal(const Field& field, int componentNumber,
541  const Elementbasis& basis, int nodeIndexesCount, const int *nodeIndexesIn)
542  {
543  return cmzn_elementtemplate_define_field_simple_nodal(
544  id, field.getId(), componentNumber, basis.getId(),
545  nodeIndexesCount, nodeIndexesIn);
546  }
547 
556  Node getNode(int localNodeIndex)
557  {
558  return Node(cmzn_elementtemplate_get_node(id, localNodeIndex));
559  }
560 
570  int setNode(int localNodeIndex, const Node& node)
571  {
572  return cmzn_elementtemplate_set_node(id, localNodeIndex, node.getId());
573  }
574 };
575 
582 {
583 private:
584 
585  cmzn_elementiterator_id id;
586 
587 public:
588 
589  Elementiterator() : id(0)
590  { }
591 
592  // takes ownership of C handle, responsibility for destroying it
593  explicit Elementiterator(cmzn_elementiterator_id element_iterator_id) :
594  id(element_iterator_id)
595  { }
596 
597  Elementiterator(const Elementiterator& elementIterator) :
598  id(cmzn_elementiterator_access(elementIterator.id))
599  { }
600 
601  Elementiterator& operator=(const Elementiterator& elementIterator)
602  {
603  cmzn_elementiterator_id temp_id = cmzn_elementiterator_access(elementIterator.id);
604  if (0 != id)
605  {
606  cmzn_elementiterator_destroy(&id);
607  }
608  id = temp_id;
609  return *this;
610  }
611 
612  ~Elementiterator()
613  {
614  if (0 != id)
615  {
616  cmzn_elementiterator_destroy(&id);
617  }
618  }
619 
625  bool isValid() const
626  {
627  return (0 != id);
628  }
629 
638  {
639  return Element(cmzn_elementiterator_next(id));
640  }
641 };
642 
650 class Mesh
651 {
652 
653 protected:
654  cmzn_mesh_id id;
655 
656 public:
657 
658  Mesh() : id(0)
659  { }
660 
661  // takes ownership of C handle, responsibility for destroying it
662  explicit Mesh(cmzn_mesh_id mesh_id) : id(mesh_id)
663  { }
664 
665  Mesh(const Mesh& mesh) :
666  id(cmzn_mesh_access(mesh.id))
667  { }
668 
669  ~Mesh()
670  {
671  if (0 != id)
672  {
673  cmzn_mesh_destroy(&id);
674  }
675  }
676 
682  bool isValid() const
683  {
684  return (0 != id);
685  }
686 
687  Mesh& operator=(const Mesh& mesh)
688  {
689  cmzn_mesh_id temp_id = cmzn_mesh_access(mesh.id);
690  if (0 != id)
691  {
692  cmzn_mesh_destroy(&id);
693  }
694  id = temp_id;
695  return *this;
696  }
697 
703  cmzn_mesh_id getId() const
704  {
705  return id;
706  }
707 
714  bool containsElement(const Element& element)
715  {
716  return cmzn_mesh_contains_element(id, element.getId());
717  }
718 
726  {
727  return Elementtemplate(cmzn_mesh_create_elementtemplate(id));
728  }
729 
741  Element createElement(int identifier, const Elementtemplate& elementTemplate)
742  {
743  return Element(cmzn_mesh_create_element(id, identifier, elementTemplate.getId()));
744  }
745 
759  {
760  return Elementiterator(cmzn_mesh_create_elementiterator(id));
761  }
762 
774  int defineElement(int identifier, const Elementtemplate& elementTemplate)
775  {
776  return cmzn_mesh_define_element(id, identifier, elementTemplate.getId());
777  }
778 
786  {
787  return cmzn_mesh_destroy_all_elements(id);
788  }
789 
798  int destroyElement(const Element& element)
799  {
800  return cmzn_mesh_destroy_element(id, element.getId());
801  }
802 
814  int destroyElementsConditional(const Field& conditionalField)
815  {
816  return cmzn_mesh_destroy_elements_conditional(id,
817  conditionalField.getId());
818  }
819 
827  {
828  return Element(cmzn_mesh_find_element_by_identifier(id, identifier));
829  }
830 
843  {
844  return Differentialoperator(cmzn_mesh_get_chart_differentialoperator(
845  id, order, term));
846  }
847 
854  {
855  return cmzn_mesh_get_dimension(id);
856  }
857 
863  inline Fieldmodule getFieldmodule() const;
864 
872  {
873  return Mesh(cmzn_mesh_get_master_mesh(id));
874  }
875 
883  char *getName()
884  {
885  return cmzn_mesh_get_name(id);
886  }
887 
893  int getSize()
894  {
895  return cmzn_mesh_get_size(id);
896  }
897 
898 };
899 
900 inline bool operator==(const Mesh& a, const Mesh& b)
901 {
902  return cmzn_mesh_match(a.getId(), b.getId());
903 }
904 
905 inline Mesh Element::getMesh() const
906 {
907  return Mesh(cmzn_element_get_mesh(id));
908 }
909 
915 class MeshGroup : public Mesh
916 {
917 
918 public:
919 
920  // takes ownership of C handle, responsibility for destroying it
921  explicit MeshGroup(cmzn_mesh_group_id mesh_id) : Mesh(reinterpret_cast<cmzn_mesh_id>(mesh_id))
922  { }
923 
929  cmzn_mesh_group_id getId() const
930  {
931  return (cmzn_mesh_group_id)(id);
932  }
933 
940  int addElement(const Element& element)
941  {
942  return cmzn_mesh_group_add_element(
943  reinterpret_cast<cmzn_mesh_group_id>(id), element.getId());
944  }
945 
952  {
953  return cmzn_mesh_group_remove_all_elements(reinterpret_cast<cmzn_mesh_group_id>(id));
954  }
955 
962  int removeElement(const Element& element)
963  {
964  return cmzn_mesh_group_remove_element(reinterpret_cast<cmzn_mesh_group_id>(id),
965  element.getId());
966  }
967 
978  int removeElementsConditional(const Field& conditionalField)
979  {
980  return cmzn_mesh_group_remove_elements_conditional(
981  reinterpret_cast<cmzn_mesh_group_id>(id), conditionalField.getId());
982  }
983 
984 };
985 
992 {
993 private:
994 
995  cmzn_meshchanges_id id;
996 
997 public:
998 
999  Meshchanges() : id(0)
1000  { }
1001 
1002  // takes ownership of C handle, responsibility for destroying it
1003  explicit Meshchanges(cmzn_meshchanges_id meshchanges_id) :
1004  id(meshchanges_id)
1005  { }
1006 
1007  Meshchanges(const Meshchanges& meshchanges) :
1008  id(cmzn_meshchanges_access(meshchanges.id))
1009  { }
1010 
1011  Meshchanges& operator=(const Meshchanges& meshchanges)
1012  {
1013  cmzn_meshchanges_id temp_id = cmzn_meshchanges_access(meshchanges.id);
1014  if (0 != id)
1015  cmzn_meshchanges_destroy(&id);
1016  id = temp_id;
1017  return *this;
1018  }
1019 
1020  ~Meshchanges()
1021  {
1022  if (0 != id)
1023  cmzn_meshchanges_destroy(&id);
1024  }
1025 
1031  bool isValid() const
1032  {
1033  return (0 != id);
1034  }
1035 
1036  Element::ChangeFlags getElementChangeFlags(const Element& element)
1037  {
1038  return cmzn_meshchanges_get_element_change_flags(id, element.getId());
1039  }
1040 
1049  {
1050  return cmzn_meshchanges_get_number_of_changes(id);
1051  }
1052 
1053  Element::ChangeFlags getSummaryElementChangeFlags()
1054  {
1055  return cmzn_meshchanges_get_summary_element_change_flags(id);
1056  }
1057 };
1058 
1059 inline int Element::merge(const Elementtemplate& elementTemplate)
1060 {
1061  return cmzn_element_merge(id, elementTemplate.getId());
1062 }
1063 
1064 } // namespace Zinc
1065 }
1066 
1067 #endif /* CMZN_ELEMENT_HPP__ */
Definition: element.hpp:274
int addElement(const Element &element)
Definition: element.hpp:940
A single finite element from a mesh.
Definition: element.hpp:205
int destroyAllElements()
Definition: element.hpp:785
int defineElement(int identifier, const Elementtemplate &elementTemplate)
Definition: element.hpp:774
A set of basis functions that can apply over an element of a given dimension.
Definition: element.hpp:31
Elementtemplate createElementtemplate()
Definition: element.hpp:725
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
bool isValid() const
Definition: element.hpp:625
ShapeType
Definition: element.hpp:304
Differentialoperator getChartDifferentialoperator(int order, int term)
Definition: element.hpp:842
int removeAllElements()
Definition: element.hpp:951
int getDimension()
Definition: element.hpp:135
Mesh getMesh() const
Definition: element.hpp:905
int getNumberOfFunctions()
Definition: element.hpp:188
int setNumberOfNodes(int numberOfNodes)
Definition: element.hpp:515
cmzn_mesh_group_id getId() const
Definition: element.hpp:929
int ChangeFlags
Definition: element.hpp:265
Describes the derivative of a field to evaluate.
Definition: differentialoperator.hpp:26
Node getNode(int localNodeIndex)
Definition: element.hpp:556
bool isValid() const
Definition: element.hpp:238
bool isValid() const
Definition: element.hpp:471
int defineFieldSimpleNodal(const Field &field, int componentNumber, const Elementbasis &basis, int nodeIndexesCount, const int *nodeIndexesIn)
Definition: element.hpp:540
int removeElement(const Element &element)
Definition: element.hpp:962
cmzn_field_id getId() const
Definition: field.hpp:98
An iterator for looping through all the elements in a mesh.
Definition: element.hpp:581
Element findElementByIdentifier(int identifier)
Definition: element.hpp:826
A description of element shape and field definitions.
Definition: element.hpp:427
int getDimension()
Definition: element.hpp:361
FunctionType
Definition: element.hpp:85
cmzn_element_id getId() const
Definition: element.hpp:351
ChangeFlag
Definition: element.hpp:246
enum FunctionType getFunctionType(int chartComponent)
Definition: element.hpp:147
cmzn_mesh_id getId() const
Definition: element.hpp:703
bool containsElement(const Element &element)
Definition: element.hpp:714
bool isValid() const
Definition: element.hpp:1031
int getSize()
Definition: element.hpp:893
bool isValid() const
Definition: element.hpp:682
cmzn_node_id getId() const
Definition: node.hpp:139
A subset of a master mesh.
Definition: element.hpp:915
char * getName()
Definition: element.hpp:883
int destroyElementsConditional(const Field &conditionalField)
Definition: element.hpp:814
Container/manager of fields and domains within a region.
Definition: fieldmodule.hpp:126
int destroyElement(const Element &element)
Definition: element.hpp:798
int getNumberOfChanges()
Definition: element.hpp:1048
int getNumberOfNodes()
Definition: element.hpp:502
Mesh getMasterMesh()
Definition: element.hpp:871
cmzn_elementbasis_id getId() const
Definition: element.hpp:125
cmzn_elementtemplate_id getId() const
Definition: element.hpp:481
PointSamplingMode
Definition: element.hpp:329
int getNumberOfNodes()
Definition: element.hpp:171
int setNode(int localNodeIndex, const Node &node)
Definition: element.hpp:570
Element next()
Definition: element.hpp:637
enum ShapeType getShapeType()
Definition: element.hpp:406
int removeElementsConditional(const Field &conditionalField)
Definition: element.hpp:978
Elementiterator createElementiterator()
Definition: element.hpp:758
Point object used to represent finite element nodes.
Definition: node.hpp:37
int setIdentifier(int identifier)
Definition: element.hpp:386
int getIdentifier()
Definition: element.hpp:373
bool isValid() const
Definition: element.hpp:75
FaceType
Definition: element.hpp:270
Element createElement(int identifier, const Elementtemplate &elementTemplate)
Definition: element.hpp:741
A finite element mesh consisting of a set of elements of fixed dimension.
Definition: element.hpp:650
int getDimension()
Definition: element.hpp:853
Fieldmodule getFieldmodule() const
Definition: fieldmodule.hpp:1577
Object describing changes to a mesh in a fieldmoduleevent.
Definition: element.hpp:991
int setFunctionType(int chartComponent, FunctionType functionType)
Definition: element.hpp:160