OpenCMISS-Zinc C++ API Documentation
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 "opencmiss/zinc/element.h"
14 #include "opencmiss/zinc/elementfieldtemplate.hpp"
15 #include "opencmiss/zinc/field.hpp"
16 #include "opencmiss/zinc/differentialoperator.hpp"
17 #include "opencmiss/zinc/node.hpp"
18 
19 namespace OpenCMISS
20 {
21 namespace Zinc
22 {
23 
24 class Fieldmodule;
25 class Mesh;
26 class Elementtemplate;
27 
34 class Element
35 {
36 private:
37 
38  cmzn_element_id id;
39 
40 public:
41 
42  Element() : id(0)
43  { }
44 
45  // takes ownership of C handle, responsibility for destroying it
46  explicit Element(cmzn_element_id element_id) :
47  id(element_id)
48  { }
49 
50  Element(const Element& element) :
51  id(cmzn_element_access(element.id))
52  { }
53 
54  ~Element()
55  {
56  if (0 != id)
57  {
58  cmzn_element_destroy(&id);
59  }
60  }
61 
62  Element& operator=(const Element& element)
63  {
64  cmzn_element_id temp_id = cmzn_element_access(element.id);
65  if (0 != id)
66  {
67  cmzn_element_destroy(&id);
68  }
69  id = temp_id;
70  return *this;
71  }
72 
78  bool isValid() const
79  {
80  return (0 != id);
81  }
82 
87  {
88  CHANGE_FLAG_NONE = CMZN_ELEMENT_CHANGE_FLAG_NONE,
90  CHANGE_FLAG_ADD = CMZN_ELEMENT_CHANGE_FLAG_ADD,
92  CHANGE_FLAG_REMOVE = CMZN_ELEMENT_CHANGE_FLAG_REMOVE,
94  CHANGE_FLAG_IDENTIFIER = CMZN_ELEMENT_CHANGE_FLAG_IDENTIFIER,
96  CHANGE_FLAG_DEFINITION = CMZN_ELEMENT_CHANGE_FLAG_DEFINITION,
98  CHANGE_FLAG_FIELD = CMZN_ELEMENT_CHANGE_FLAG_FIELD
100  };
101 
105  typedef int ChangeFlags;
106 
110  enum FaceType
111  {
112  FACE_TYPE_INVALID = CMZN_ELEMENT_FACE_TYPE_INVALID,
114  FACE_TYPE_ALL = CMZN_ELEMENT_FACE_TYPE_ALL,
116  FACE_TYPE_ANY_FACE = CMZN_ELEMENT_FACE_TYPE_ANY_FACE,
118  FACE_TYPE_NO_FACE = CMZN_ELEMENT_FACE_TYPE_NO_FACE,
120  FACE_TYPE_XI1_0 = CMZN_ELEMENT_FACE_TYPE_XI1_0,
122  FACE_TYPE_XI1_1 = CMZN_ELEMENT_FACE_TYPE_XI1_1,
124  FACE_TYPE_XI2_0 = CMZN_ELEMENT_FACE_TYPE_XI2_0,
126  FACE_TYPE_XI2_1 = CMZN_ELEMENT_FACE_TYPE_XI2_1,
128  FACE_TYPE_XI3_0 = CMZN_ELEMENT_FACE_TYPE_XI3_0,
130  FACE_TYPE_XI3_1 = CMZN_ELEMENT_FACE_TYPE_XI3_1
132  };
133 
138  {
139  SHAPE_TYPE_INVALID = CMZN_ELEMENT_SHAPE_TYPE_INVALID,
141  SHAPE_TYPE_LINE = CMZN_ELEMENT_SHAPE_TYPE_LINE,
143  SHAPE_TYPE_SQUARE = CMZN_ELEMENT_SHAPE_TYPE_SQUARE,
145  SHAPE_TYPE_TRIANGLE = CMZN_ELEMENT_SHAPE_TYPE_TRIANGLE,
147  SHAPE_TYPE_CUBE = CMZN_ELEMENT_SHAPE_TYPE_CUBE,
149  SHAPE_TYPE_TETRAHEDRON = CMZN_ELEMENT_SHAPE_TYPE_TETRAHEDRON,
151  SHAPE_TYPE_WEDGE12 = CMZN_ELEMENT_SHAPE_TYPE_WEDGE12,
153  SHAPE_TYPE_WEDGE13 = CMZN_ELEMENT_SHAPE_TYPE_WEDGE13,
155  SHAPE_TYPE_WEDGE23 = CMZN_ELEMENT_SHAPE_TYPE_WEDGE23
157  };
158 
163  {
164  POINT_SAMPLING_MODE_INVALID = CMZN_ELEMENT_POINT_SAMPLING_MODE_INVALID,
166  POINT_SAMPLING_MODE_CELL_CENTRES = CMZN_ELEMENT_POINT_SAMPLING_MODE_CELL_CENTRES,
168  POINT_SAMPLING_MODE_CELL_CORNERS = CMZN_ELEMENT_POINT_SAMPLING_MODE_CELL_CORNERS,
170  POINT_SAMPLING_MODE_CELL_POISSON = CMZN_ELEMENT_POINT_SAMPLING_MODE_CELL_POISSON,
175  POINT_SAMPLING_MODE_SET_LOCATION = CMZN_ELEMENT_POINT_SAMPLING_MODE_SET_LOCATION,
177  POINT_SAMPLING_MODE_GAUSSIAN_QUADRATURE = CMZN_ELEMENT_POINT_SAMPLING_MODE_GAUSSIAN_QUADRATURE
182  };
183 
188  {
189  QUADRATURE_RULE_INVALID = CMZN_ELEMENT_QUADRATURE_RULE_INVALID,
191  QUADRATURE_RULE_GAUSSIAN = CMZN_ELEMENT_QUADRATURE_RULE_GAUSSIAN,
197  QUADRATURE_RULE_MIDPOINT = CMZN_ELEMENT_QUADRATURE_RULE_MIDPOINT
200  };
201 
207  cmzn_element_id getId() const
208  {
209  return id;
210  }
211 
218  {
219  return cmzn_element_get_dimension(id);
220  }
221 
234  Elementfieldtemplate getElementfieldtemplate(const Field& field, int componentNumber) const
235  {
236  return Elementfieldtemplate(cmzn_element_get_elementfieldtemplate(this->id, field.getId(), componentNumber));
237  }
238 
247  {
248  return cmzn_element_get_identifier(id);
249  }
250 
259  int setIdentifier(int identifier)
260  {
261  return cmzn_element_set_identifier(id, identifier);
262  }
263 
269  inline Mesh getMesh() const;
270 
278  Node getNode(const Elementfieldtemplate &eft, int localNodeIndex)
279  {
280  return Node(cmzn_element_get_node(this->id, eft.getId(), localNodeIndex));
281  }
282 
297  int setNode(const Elementfieldtemplate &eft, int localNodeIndex, const Node &node)
298  {
299  return cmzn_element_set_node(this->id, eft.getId(), localNodeIndex, node.getId());
300  }
301 
320  int setNodesByIdentifier(const Elementfieldtemplate &eft, int identifiersCount,
321  const int *identifiersIn)
322  {
323  return cmzn_element_set_nodes_by_identifier(this->id, eft.getId(), identifiersCount, identifiersIn);
324  }
325 
336  int getScaleFactor(const Elementfieldtemplate &eft, int scaleFactorIndex, double *valueOut)
337  {
338  return cmzn_element_get_scale_factor(this->id, eft.getId(), scaleFactorIndex, valueOut);
339  }
340 
350  int setScaleFactor(const Elementfieldtemplate &eft, int scaleFactorIndex, double value)
351  {
352  return cmzn_element_set_scale_factor(this->id, eft.getId(), scaleFactorIndex, value);
353  }
354 
365  int getScaleFactors(const Elementfieldtemplate &eft, int valuesCount,
366  double *valuesOut)
367  {
368  return cmzn_element_get_scale_factors(this->id, eft.getId(), valuesCount, valuesOut);
369  }
370 
381  int setScaleFactors(const Elementfieldtemplate &eft, int valuesCount,
382  const double *valuesIn)
383  {
384  return cmzn_element_set_scale_factors(this->id, eft.getId(), valuesCount, valuesIn);
385  }
386 
396  {
397  return static_cast<ShapeType>(cmzn_element_get_shape_type(id));
398  }
399 
409  inline int merge(const Elementtemplate& elementTemplate);
410 
411 };
412 
413 inline bool operator==(const Element& a, const Element& b)
414 {
415  return a.getId() == b.getId();
416 }
417 
424 {
425 private:
426 
427  cmzn_elementiterator_id id;
428 
429 public:
430 
431  Elementiterator() : id(0)
432  { }
433 
434  // takes ownership of C handle, responsibility for destroying it
435  explicit Elementiterator(cmzn_elementiterator_id element_iterator_id) :
436  id(element_iterator_id)
437  { }
438 
439  Elementiterator(const Elementiterator& elementIterator) :
440  id(cmzn_elementiterator_access(elementIterator.id))
441  { }
442 
443  Elementiterator& operator=(const Elementiterator& elementIterator)
444  {
445  cmzn_elementiterator_id temp_id = cmzn_elementiterator_access(elementIterator.id);
446  if (0 != id)
447  {
448  cmzn_elementiterator_destroy(&id);
449  }
450  id = temp_id;
451  return *this;
452  }
453 
454  ~Elementiterator()
455  {
456  if (0 != id)
457  {
458  cmzn_elementiterator_destroy(&id);
459  }
460  }
461 
467  bool isValid() const
468  {
469  return (0 != id);
470  }
471 
480  {
481  return Element(cmzn_elementiterator_next(id));
482  }
483 };
484 
485 } // namespace Zinc
486 }
487 
488 #endif /* CMZN_ELEMENT_HPP__ */
Definition: element.hpp:114
int getScaleFactor(const Elementfieldtemplate &eft, int scaleFactorIndex, double *valueOut)
Definition: element.hpp:336
A single finite element from a mesh.
Definition: element.hpp:34
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:51
bool isValid() const
Definition: element.hpp:467
int getScaleFactors(const Elementfieldtemplate &eft, int valuesCount, double *valuesOut)
Definition: element.hpp:365
int setScaleFactor(const Elementfieldtemplate &eft, int scaleFactorIndex, double value)
Definition: element.hpp:350
ShapeType
Definition: element.hpp:137
Elementfieldtemplate getElementfieldtemplate(const Field &field, int componentNumber) const
Definition: element.hpp:234
Mesh getMesh() const
Definition: mesh.hpp:326
int ChangeFlags
Definition: element.hpp:105
bool isValid() const
Definition: element.hpp:78
QuadratureRule
Definition: element.hpp:187
cmzn_field_id getId() const
Definition: field.hpp:103
An iterator for looping through all the elements in a mesh.
Definition: element.hpp:423
A description of element shape and field definitions.
Definition: elementtemplate.hpp:31
int getDimension()
Definition: element.hpp:217
cmzn_element_id getId() const
Definition: element.hpp:207
ChangeFlag
Definition: element.hpp:86
int setNodesByIdentifier(const Elementfieldtemplate &eft, int identifiersCount, const int *identifiersIn)
Definition: element.hpp:320
cmzn_node_id getId() const
Definition: node.hpp:136
PointSamplingMode
Definition: element.hpp:162
int setNode(const Elementfieldtemplate &eft, int localNodeIndex, const Node &node)
Definition: element.hpp:297
Element next()
Definition: element.hpp:479
enum ShapeType getShapeType()
Definition: element.hpp:395
The OpenCMISS namespace.
Definition: context.hpp:20
Point object used to represent finite element nodes.
Definition: node.hpp:34
int merge(const Elementtemplate &elementTemplate)
Definition: elementtemplate.hpp:318
int setIdentifier(int identifier)
Definition: element.hpp:259
Node getNode(const Elementfieldtemplate &eft, int localNodeIndex)
Definition: element.hpp:278
int getIdentifier()
Definition: element.hpp:246
cmzn_elementfieldtemplate_id getId() const
Definition: elementfieldtemplate.hpp:132
FaceType
Definition: element.hpp:110
A finite element mesh consisting of a set of elements of fixed dimension.
Definition: mesh.hpp:34
int setScaleFactors(const Elementfieldtemplate &eft, int valuesCount, const double *valuesIn)
Definition: element.hpp:381
A template defining field parameter mapping and interpolation over an element chart.
Definition: elementfieldtemplate.hpp:39