OpenCMISS-Zinc 3.0.0 Release 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 
418  inline int merge(const Elementtemplate& elementTemplate);
419 
420 };
421 
422 inline bool operator==(const Element& a, const Element& b)
423 {
424  return a.getId() == b.getId();
425 }
426 
435 {
436 private:
437 
438  cmzn_elementtemplate_id id;
439 
440 public:
441 
442  Elementtemplate() : id(0)
443  { }
444 
445  // takes ownership of C handle, responsibility for destroying it
446  explicit Elementtemplate(cmzn_elementtemplate_id element_template_id) :
447  id(element_template_id)
448  { }
449 
450  Elementtemplate(const Elementtemplate& elementTemplate) :
451  id(cmzn_elementtemplate_access(elementTemplate.id))
452  { }
453 
454  Elementtemplate& operator=(const Elementtemplate& elementTemplate)
455  {
456  cmzn_elementtemplate_id temp_id = cmzn_elementtemplate_access(elementTemplate.id);
457  if (0 != id)
458  {
459  cmzn_elementtemplate_destroy(&id);
460  }
461  id = temp_id;
462  return *this;
463  }
464 
465  ~Elementtemplate()
466  {
467  if (0 != id)
468  {
469  cmzn_elementtemplate_destroy(&id);
470  }
471  }
472 
478  bool isValid() const
479  {
480  return (0 != id);
481  }
482 
488  cmzn_elementtemplate_id getId() const
489  {
490  return id;
491  }
492 
499  {
500  return static_cast<Element::ShapeType>(cmzn_elementtemplate_get_element_shape_type(id));
501  }
502 
517  {
518  return cmzn_elementtemplate_set_element_shape_type(id,
519  static_cast<cmzn_element_shape_type>(shapeType));
520  }
521 
528  {
529  return cmzn_elementtemplate_get_number_of_nodes(id);
530  }
531 
540  int setNumberOfNodes(int numberOfNodes)
541  {
542  return cmzn_elementtemplate_set_number_of_nodes(id, numberOfNodes);
543  }
544 
565  int defineFieldSimpleNodal(const Field& field, int componentNumber,
566  const Elementbasis& basis, int nodeIndexesCount, const int *nodeIndexesIn)
567  {
568  return cmzn_elementtemplate_define_field_simple_nodal(
569  id, field.getId(), componentNumber, basis.getId(),
570  nodeIndexesCount, nodeIndexesIn);
571  }
572 
581  Node getNode(int localNodeIndex)
582  {
583  return Node(cmzn_elementtemplate_get_node(id, localNodeIndex));
584  }
585 
595  int setNode(int localNodeIndex, const Node& node)
596  {
597  return cmzn_elementtemplate_set_node(id, localNodeIndex, node.getId());
598  }
599 };
600 
607 {
608 private:
609 
610  cmzn_elementiterator_id id;
611 
612 public:
613 
614  Elementiterator() : id(0)
615  { }
616 
617  // takes ownership of C handle, responsibility for destroying it
618  explicit Elementiterator(cmzn_elementiterator_id element_iterator_id) :
619  id(element_iterator_id)
620  { }
621 
622  Elementiterator(const Elementiterator& elementIterator) :
623  id(cmzn_elementiterator_access(elementIterator.id))
624  { }
625 
626  Elementiterator& operator=(const Elementiterator& elementIterator)
627  {
628  cmzn_elementiterator_id temp_id = cmzn_elementiterator_access(elementIterator.id);
629  if (0 != id)
630  {
631  cmzn_elementiterator_destroy(&id);
632  }
633  id = temp_id;
634  return *this;
635  }
636 
637  ~Elementiterator()
638  {
639  if (0 != id)
640  {
641  cmzn_elementiterator_destroy(&id);
642  }
643  }
644 
650  bool isValid() const
651  {
652  return (0 != id);
653  }
654 
663  {
664  return Element(cmzn_elementiterator_next(id));
665  }
666 };
667 
675 class Mesh
676 {
677 
678 protected:
679  cmzn_mesh_id id;
680 
681 public:
682 
683  Mesh() : id(0)
684  { }
685 
686  // takes ownership of C handle, responsibility for destroying it
687  explicit Mesh(cmzn_mesh_id mesh_id) : id(mesh_id)
688  { }
689 
690  Mesh(const Mesh& mesh) :
691  id(cmzn_mesh_access(mesh.id))
692  { }
693 
694  ~Mesh()
695  {
696  if (0 != id)
697  {
698  cmzn_mesh_destroy(&id);
699  }
700  }
701 
707  bool isValid() const
708  {
709  return (0 != id);
710  }
711 
712  Mesh& operator=(const Mesh& mesh)
713  {
714  cmzn_mesh_id temp_id = cmzn_mesh_access(mesh.id);
715  if (0 != id)
716  {
717  cmzn_mesh_destroy(&id);
718  }
719  id = temp_id;
720  return *this;
721  }
722 
728  cmzn_mesh_id getId() const
729  {
730  return id;
731  }
732 
739  bool containsElement(const Element& element)
740  {
741  return cmzn_mesh_contains_element(id, element.getId());
742  }
743 
751  {
752  return Elementtemplate(cmzn_mesh_create_elementtemplate(id));
753  }
754 
766  Element createElement(int identifier, const Elementtemplate& elementTemplate)
767  {
768  return Element(cmzn_mesh_create_element(id, identifier, elementTemplate.getId()));
769  }
770 
784  {
785  return Elementiterator(cmzn_mesh_create_elementiterator(id));
786  }
787 
799  int defineElement(int identifier, const Elementtemplate& elementTemplate)
800  {
801  return cmzn_mesh_define_element(id, identifier, elementTemplate.getId());
802  }
803 
811  {
812  return cmzn_mesh_destroy_all_elements(id);
813  }
814 
823  int destroyElement(const Element& element)
824  {
825  return cmzn_mesh_destroy_element(id, element.getId());
826  }
827 
839  int destroyElementsConditional(const Field& conditionalField)
840  {
841  return cmzn_mesh_destroy_elements_conditional(id,
842  conditionalField.getId());
843  }
844 
852  {
853  return Element(cmzn_mesh_find_element_by_identifier(id, identifier));
854  }
855 
868  {
869  return Differentialoperator(cmzn_mesh_get_chart_differentialoperator(
870  id, order, term));
871  }
872 
879  {
880  return cmzn_mesh_get_dimension(id);
881  }
882 
888  inline Fieldmodule getFieldmodule() const;
889 
897  {
898  return Mesh(cmzn_mesh_get_master_mesh(id));
899  }
900 
908  char *getName()
909  {
910  return cmzn_mesh_get_name(id);
911  }
912 
918  int getSize()
919  {
920  return cmzn_mesh_get_size(id);
921  }
922 
923 };
924 
925 inline bool operator==(const Mesh& a, const Mesh& b)
926 {
927  return cmzn_mesh_match(a.getId(), b.getId());
928 }
929 
930 inline Mesh Element::getMesh() const
931 {
932  return Mesh(cmzn_element_get_mesh(id));
933 }
934 
940 class MeshGroup : public Mesh
941 {
942 
943 public:
944 
945  // takes ownership of C handle, responsibility for destroying it
946  explicit MeshGroup(cmzn_mesh_group_id mesh_id) : Mesh(reinterpret_cast<cmzn_mesh_id>(mesh_id))
947  { }
948 
954  cmzn_mesh_group_id getId() const
955  {
956  return (cmzn_mesh_group_id)(id);
957  }
958 
965  int addElement(const Element& element)
966  {
967  return cmzn_mesh_group_add_element(
968  reinterpret_cast<cmzn_mesh_group_id>(id), element.getId());
969  }
970 
977  {
978  return cmzn_mesh_group_remove_all_elements(reinterpret_cast<cmzn_mesh_group_id>(id));
979  }
980 
987  int removeElement(const Element& element)
988  {
989  return cmzn_mesh_group_remove_element(reinterpret_cast<cmzn_mesh_group_id>(id),
990  element.getId());
991  }
992 
1003  int removeElementsConditional(const Field& conditionalField)
1004  {
1005  return cmzn_mesh_group_remove_elements_conditional(
1006  reinterpret_cast<cmzn_mesh_group_id>(id), conditionalField.getId());
1007  }
1008 
1009 };
1010 
1017 {
1018 private:
1019 
1020  cmzn_meshchanges_id id;
1021 
1022 public:
1023 
1024  Meshchanges() : id(0)
1025  { }
1026 
1027  // takes ownership of C handle, responsibility for destroying it
1028  explicit Meshchanges(cmzn_meshchanges_id meshchanges_id) :
1029  id(meshchanges_id)
1030  { }
1031 
1032  Meshchanges(const Meshchanges& meshchanges) :
1033  id(cmzn_meshchanges_access(meshchanges.id))
1034  { }
1035 
1036  Meshchanges& operator=(const Meshchanges& meshchanges)
1037  {
1038  cmzn_meshchanges_id temp_id = cmzn_meshchanges_access(meshchanges.id);
1039  if (0 != id)
1040  cmzn_meshchanges_destroy(&id);
1041  id = temp_id;
1042  return *this;
1043  }
1044 
1045  ~Meshchanges()
1046  {
1047  if (0 != id)
1048  cmzn_meshchanges_destroy(&id);
1049  }
1050 
1056  bool isValid() const
1057  {
1058  return (0 != id);
1059  }
1060 
1068  {
1069  return cmzn_meshchanges_get_element_change_flags(id, element.getId());
1070  }
1071 
1080  {
1081  return cmzn_meshchanges_get_number_of_changes(id);
1082  }
1083 
1090  {
1091  return cmzn_meshchanges_get_summary_element_change_flags(id);
1092  }
1093 };
1094 
1095 inline int Element::merge(const Elementtemplate& elementTemplate)
1096 {
1097  return cmzn_element_merge(id, elementTemplate.getId());
1098 }
1099 
1100 } // namespace Zinc
1101 }
1102 
1103 #endif /* CMZN_ELEMENT_HPP__ */
Definition: element.hpp:274
int addElement(const Element &element)
Definition: element.hpp:965
A single finite element from a mesh.
Definition: element.hpp:205
int setElementShapeType(enum Element::ShapeType shapeType)
Definition: element.hpp:516
int destroyAllElements()
Definition: element.hpp:810
int defineElement(int identifier, const Elementtemplate &elementTemplate)
Definition: element.hpp:799
A set of basis functions that can apply over an element of a given dimension.
Definition: element.hpp:31
Elementtemplate createElementtemplate()
Definition: element.hpp:750
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
bool isValid() const
Definition: element.hpp:650
ShapeType
Definition: element.hpp:304
Differentialoperator getChartDifferentialoperator(int order, int term)
Definition: element.hpp:867
int removeAllElements()
Definition: element.hpp:976
int getDimension()
Definition: element.hpp:135
Mesh getMesh() const
Definition: element.hpp:930
int getNumberOfFunctions()
Definition: element.hpp:188
int setNumberOfNodes(int numberOfNodes)
Definition: element.hpp:540
cmzn_mesh_group_id getId() const
Definition: element.hpp:954
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:581
bool isValid() const
Definition: element.hpp:238
Element::ChangeFlags getElementChangeFlags(const Element &element)
Definition: element.hpp:1067
bool isValid() const
Definition: element.hpp:478
int defineFieldSimpleNodal(const Field &field, int componentNumber, const Elementbasis &basis, int nodeIndexesCount, const int *nodeIndexesIn)
Definition: element.hpp:565
int removeElement(const Element &element)
Definition: element.hpp:987
cmzn_field_id getId() const
Definition: field.hpp:98
An iterator for looping through all the elements in a mesh.
Definition: element.hpp:606
Element findElementByIdentifier(int identifier)
Definition: element.hpp:851
A description of element shape and field definitions.
Definition: element.hpp:434
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:728
bool containsElement(const Element &element)
Definition: element.hpp:739
bool isValid() const
Definition: element.hpp:1056
int getSize()
Definition: element.hpp:918
bool isValid() const
Definition: element.hpp:707
cmzn_node_id getId() const
Definition: node.hpp:139
A subset of a master mesh.
Definition: element.hpp:940
char * getName()
Definition: element.hpp:908
int destroyElementsConditional(const Field &conditionalField)
Definition: element.hpp:839
Container/manager of fields and domains within a region.
Definition: fieldmodule.hpp:126
int destroyElement(const Element &element)
Definition: element.hpp:823
int getNumberOfChanges()
Definition: element.hpp:1079
int getNumberOfNodes()
Definition: element.hpp:527
Mesh getMasterMesh()
Definition: element.hpp:896
cmzn_elementbasis_id getId() const
Definition: element.hpp:125
Element::ChangeFlags getSummaryElementChangeFlags()
Definition: element.hpp:1089
cmzn_elementtemplate_id getId() const
Definition: element.hpp:488
PointSamplingMode
Definition: element.hpp:329
int getNumberOfNodes()
Definition: element.hpp:171
int setNode(int localNodeIndex, const Node &node)
Definition: element.hpp:595
Element next()
Definition: element.hpp:662
enum Element::ShapeType getElementShapeType()
Definition: element.hpp:498
enum ShapeType getShapeType()
Definition: element.hpp:406
int removeElementsConditional(const Field &conditionalField)
Definition: element.hpp:1003
Elementiterator createElementiterator()
Definition: element.hpp:783
Point object used to represent finite element nodes.
Definition: node.hpp:37
int merge(const Elementtemplate &elementTemplate)
Definition: element.hpp:1095
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:766
A finite element mesh consisting of a set of elements of fixed dimension.
Definition: element.hpp:675
int getDimension()
Definition: element.hpp:878
Fieldmodule getFieldmodule() const
Definition: fieldmodule.hpp:1613
Object describing changes to a mesh in a fieldmoduleevent.
Definition: element.hpp:1016
int setFunctionType(int chartComponent, FunctionType functionType)
Definition: element.hpp:160