cee::ug::DataElements

class DataElements : public RefCountedObject

Collection of elements in a part.

Examples of element types are points, triangles or hexahedrons.

../_images/uml_datapart.png

See the Element::Type enum for a complete list of supported element types.

DataElements describes the connectivities for all the elements in a DataPart. The node positions are stored in the DataNodes object. All connectivity indices must refer to a valid index in the node array in the corresponding DataNodes object. A DataElements object and a DataNodes object together defines a DataPart.

Note! The class is reference counted and can be shared between multiple parts. Remember that since this object is reference counted it should never be created on the stack.

Add elements using

specifying an element type and an array of connectivities. For more efficient use, set the element array size using reserve() first. If the data elements are set to use ids, these are set using setElementId(). Call hasElementIds() on the data elements object to check of ids are expected. Whether element ids are used or not is specified upon construction of the DataElements object.

Get the number of elements in the existing element array with elementCount() and query individual elements with elementNodes(), elementType() and elementId(). In addition number of element nodes can be found using elementNodeCount() and number of element surfaces using elementSurfaceCount().

Example

Example of a simple part containing two triangles.

Create a DataNodes object which is a collection of nodes used for building the part. In this example you will use 4 nodes to create two triangles. Important! The nodes object must be set to the correct size before setting the actual node coordinates!

cee::PtrRef<cee::ug::DataNodes> nodes = new cee::ug::DataNodes(false);
nodes->resize(5);
nodes->setNode(0, cee::Vec3d(0, 1, 0));
nodes->setNode(1, cee::Vec3d(0, 0, 0));
nodes->setNode(2, cee::Vec3d(1, 0, 0));
nodes->setNode(3, cee::Vec3d(2, 0, 0));
nodes->setNode(4, cee::Vec3d(2, 1, 0));

In addition to the node coordinates, the part need to know about the connectivities. Create a DataElements object describing the connectivities for the two triangle elements.

int c[] = {0, 1, 2, 2, 3, 4};
std::vector<unsigned int> eltNodes1(c, c + 3);    // First triangle
std::vector<unsigned int> eltNodes2(c + 3, c + 6);  // Second triangle
cee::PtrRef<cee::ug::DataElements> elements = new cee::ug::DataElements(false, 0);
elements->addElement(cee::ug::Element::TRIANGLES, eltNodes1);
elements->addElement(cee::ug::Element::TRIANGLES, eltNodes2);

Add the nodes and elements to the part object

int partId = 1;
cee::PtrRef<cee::ug::DataPart> part = new cee::ug::DataPart(partId);
part->setNodes(nodes.get());
part->setElements(elements.get());

See the complete source code at: UnstructGrid: Simple Model with Two Triangles

Tutorials

Public Functions

DataElements(bool withElementIds, size_t userPropertyCount)

Constructs an object containing no elements.

The withElementIds parameter specifies if element id should be used or not for this collection.

size_t elementCount() const

Returns number of elements.

Element::Type elementType(size_t elementIndex) const

Returns element type for element at given index.

See also

DataElements::Element::Type

Element::Type singleElementType() const

Returns the single element type used by all elements.

Returns NULL_ELEMENT if there are multiple element types

See also

DataElements::Element::Type

std::vector<unsigned int> elementNodes(size_t elementIndex) const

Returns an array of element node indices for element at given index.

If no indices were found for the given elementIndex, an empty array is returned.

void reserve(size_t elementCount, size_t elementNodeCount)

Sets the size of the element array in advance to increase efficiency.

size_t addElement(Element::Type elementType, const std::vector<unsigned int> &elementNodes)

Adds an element of specified element type and corresponding array of node indices.

Number of node indices in array must match number of nodes in specified element type. Returns the index to the newly added element.

See also

DataElements::Element::Type

size_t addElement(Element::Type elementType, const unsigned int elementNodes[], size_t elementNodeCount)

Adds an element of specified element type and corresponding array of node indices.

Number of node indices in array must match number of nodes in specified element type. Returns the index to the newly added element.

See also

DataElements::Element::Type

size_t addElementInt(Element::Type elementType, const int elementNodes[], size_t elementNodeCount)

Adds an element of specified element type and corresponding array of node indices.

Number of node indices in array must match number of nodes in specified element type. Returns the index to the newly added element.

See also

DataElements::Element::Type

void addElements(Element::Type elementType, size_t elementCount, const std::vector<unsigned int> &elementNodes)

Adds an element of specified element type and corresponding array of node indices.

Number of node indices in array must match number of nodes in specified element type. Returns the index to the newly added element.

See also

DataElements::Element::Type

void addElements(Element::Type elementType, size_t elementCount, const unsigned int elementNodes[], size_t totalElementNodeCount)

Adds one or more elements of specified element type.

Number of elements are given with elementCount.

Number of node indices in array must match number of nodes in specified element type multiplied with number of elements.

See also

DataElements::Element::Type

void addElementsInt(Element::Type elementType, size_t elementCount, const int elementNodes[], size_t totalElementNodeCount)

Adds one or more elements of specified element type.

Number of elements are given with elementCount.

Number of node indices in array must match number of nodes in specified element type multiplied with number of elements.

See also

DataElements::Element::Type

void removeAllElements()

Removes all elements from collection.

bool hasElementIds() const

Returns true if element ids are used for these data elements.

int elementId(size_t elementIndex) const

Returns the element id for the element at given index.

void setElementId(size_t elementIndex, int elementId)

Sets the element id for the element at given index.

size_t elementIndex(int elementId) const

Returns the index for the element with the given Id.

The method will assert if there are no ids defined. It will return cee::UNDEFINED_SIZE_T if the the given id is not found

size_t userPropertyCount() const

Returns the number of user properties.

void setUserProperty(size_t userPropertyIndex, size_t elementIndex, int userProperty)

Sets a user property for an element.

The user property is given by an integer value.

Warning

Max 3 user properties are supported, so userPropertyIndex must be 0, 1 or 2.

int userProperty(size_t userPropertyIndex, size_t elementIndex) const

Returns the user property with index userPropertyIndex for the given element.

size_t elementNodeCount() const

Returns number of element nodes in collection.

size_t elementSurfaceCount() const

Returns number of element surfaces in collection.

size_t nodesPerElement(size_t elementIndex) const

Returns number of nodes for the given element.

size_t surfacesPerElement(size_t elementIndex) const

Returns number of surfaces for the given element.

size_t edgesPerElement(size_t elementIndex) const

Returns number of edges for the given element.