cee::ug::DataElements Class Reference

Collection of elements in a part. Examples of element types are points, triangles or hexahedrons. More...

Public Member Functions

 DataElements (bool withElementIds, size_t userPropertyCount)
 Constructs an object containing no elements. More...
 
size_t elementCount () const
 Returns number of elements. More...
 
Element::Type elementType (size_t elementIndex) const
 Returns element type for element at given index. More...
 
Element::Type singleElementType () const
 Returns the single element type used by all elements. More...
 
std::vector< unsigned int > elementNodes (size_t elementIndex) const
 Returns an array of element node indices for element at given index. More...
 
void reserve (size_t elementCount, size_t elementNodeCount)
 Sets the size of the element array in advance to increase efficiency. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void addElements (Element::Type elementType, size_t elementCount, const unsigned int elementNodes[], size_t totalElementNodeCount)
 Adds one or more elements of specified element type. More...
 
void addElementsInt (Element::Type elementType, size_t elementCount, const int elementNodes[], size_t totalElementNodeCount)
 Adds one or more elements of specified element type. More...
 
void removeAllElements ()
 Removes all elements from collection. More...
 
bool hasElementIds () const
 Returns true if element ids are used for these data elements. More...
 
int elementId (size_t elementIndex) const
 Returns the element id for the element at given index. More...
 
void setElementId (size_t elementIndex, int elementId)
 Sets the element id for the element at given index. More...
 
size_t elementIndex (int elementId) const
 Returns the index for the element with the given Id. More...
 
size_t userPropertyCount () const
 Returns the number of user properties. More...
 
void setUserProperty (size_t userPropertyIndex, size_t elementIndex, int userProperty)
 Sets a user property for an element. More...
 
int userProperty (size_t userPropertyIndex, size_t elementIndex) const
 Returns the user property with index userPropertyIndex for the given element. More...
 
size_t elementNodeCount () const
 Returns number of element nodes in collection. More...
 
size_t elementSurfaceCount () const
 Returns number of element surfaces in collection. More...
 
size_t nodesPerElement (size_t elementIndex) const
 Returns number of nodes for the given element. More...
 
size_t surfacesPerElement (size_t elementIndex) const
 Returns number of surfaces for the given element. More...
 
size_t edgesPerElement (size_t elementIndex) const
 Returns number of edges for the given element. More...
 
- Public Member Functions inherited from cee::RefCountedObject
void addRef () const
 Increments the reference count for this object. More...
 
void release () const
 Decrements the reference count for this object. More...
 
int refCount () const
 Returns the reference count for this object. More...
 
void setRefCountZero () const
 Sets the ref count to zero, but DOES NOT delete the object. More...
 
Inheritance diagram for cee::ug::DataElements:
cee::RefCountedObject

Detailed Description

Collection of elements in a part. Examples of element types are points, triangles or hexahedrons.

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!

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
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;
part->setNodes(nodes.get());
part->setElements(elements.get());

See the complete source code at: UnstructGrid: Simple model with two triangles

See also
Element
DataGeometry
DataPart
DataNodes
Tutorials
UnstructGrid: Simple model with two triangles
UnstructGrid: A simple model with results

Constructor & Destructor Documentation

cee::ug::DataElements::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.

Member Function Documentation

size_t cee::ug::DataElements::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 cee::ug::DataElements::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 cee::ug::DataElements::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 cee::ug::DataElements::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 cee::ug::DataElements::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 cee::ug::DataElements::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
size_t cee::ug::DataElements::edgesPerElement ( size_t  elementIndex) const

Returns number of edges for the given element.

size_t cee::ug::DataElements::elementCount ( ) const

Returns number of elements.

int cee::ug::DataElements::elementId ( size_t  elementIndex) const

Returns the element id for the element at given index.

size_t cee::ug::DataElements::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 cee::ug::DataElements::elementNodeCount ( ) const

Returns number of element nodes in collection.

std::vector< unsigned int > cee::ug::DataElements::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.

size_t cee::ug::DataElements::elementSurfaceCount ( ) const

Returns number of element surfaces in collection.

Element::Type cee::ug::DataElements::elementType ( size_t  elementIndex) const

Returns element type for element at given index.

See also
DataElements::Element::Type
bool cee::ug::DataElements::hasElementIds ( ) const

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

size_t cee::ug::DataElements::nodesPerElement ( size_t  elementIndex) const

Returns number of nodes for the given element.

void cee::ug::DataElements::removeAllElements ( )

Removes all elements from collection.

void cee::ug::DataElements::reserve ( size_t  elementCount,
size_t  elementNodeCount 
)

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

void cee::ug::DataElements::setElementId ( size_t  elementIndex,
int  elementId 
)

Sets the element id for the element at given index.

void cee::ug::DataElements::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.
Element::Type cee::ug::DataElements::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
size_t cee::ug::DataElements::surfacesPerElement ( size_t  elementIndex) const

Returns number of surfaces for the given element.

int cee::ug::DataElements::userProperty ( size_t  userPropertyIndex,
size_t  elementIndex 
) const

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

size_t cee::ug::DataElements::userPropertyCount ( ) const

Returns the number of user properties.