Getting element entity from vertex handle
Is there API to query element entities handle from used vertex?
Comments (6)
-
-
reporter Thanks for reply.
I am trying about you mentioned and write the code below.
vertex handle 1 is used where hex elements 1 and 2.
but adjacencies size is 0 from vertex handle 1.
What is wrong?
moab::Core *mb; int main() { mb = new moab::Core(); const unsigned NUMVTX = 27; // The number of vertexes const unsigned NUMHEX = 8; // The number of hexahedrons // This double array stores the x, y, z coordinate of each vertex. const double vertex_coords[3 * NUMVTX] = { 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 1, 1, 0, 2, 1, 0, 0, 2, 0, 1, 2, 0, 2, 2, 0, 0, 0, 1, 1, 0, 1, 2, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1, 0, 2, 1, 1, 2, 1, 2, 2, 1, 0, 0, 2, 1, 0, 2, 2, 0, 2, 0, 1, 2, 1, 1, 2, 2, 1, 2, 0, 2, 2, 1, 2, 2, 2, 2, 2 }; moab::EntityHandle conn[NUMHEX][2] = { { 1, 2, 5, 4, 10, 11, 14, 13 }, { 2, 3, 6, 5, 11, 12, 15, 14 } }; moab::ErrorCode rval; for(int i=0; i<NUMVTX; i++) { float x = vertex_coords[i*3]; float y = vertex_coords[i*3+1]; float z = vertex_coords[i*3+2]; std::vector<double> coord(3); coord[0] = x; coord[1] = y; coord[2] = z; moab::EntityHandle h; rval = mb->create_vertex( coord.data(), h ); } for(int i=0; i<2; i++) { moab::EntityHandle element; // add hexahedron moab::Range range; rval = mb->create_element( moab::MBHEX, conn[i], 8, element ); range.insert( element ); mb->add_entities(0, range); } int count; mb->get_number_entities_by_type(0, moab::MBHEX, count); printf("Total hex count is %d\n", count); // getting element from vertex handle std::vector<moab::EntityHandle> from_entities; moab::EntityHandle entity; mb->handle_from_id(moab::MBVERTEX, 2, entity); from_entities.push_back(entity); std::vector<moab::EntityHandle> adjacencies; mb->get_adjacencies( from_entities.data(), 2, 1, false, adjacencies ); printf("adjacencies: %d\n", adjacencies.size()); delete mb; }
Total hex count is 2
adjacencies: 0 -
mb->get_adjacencies( from_entities.data(), 2, 1, false, adjacencies );
is wrong
it should bemb->get_adjacencies( from_entities.data(), /*number of entities*/1, /*dimension*/ 3, false, adjacencies );
look at interface:
virtual ErrorCode get_adjacencies( const EntityHandle* from_entities, const int num_entities,
const int to_dimension, const bool create_if_missing,
std::vector< EntityHandle >& adj_entities,
const int operation_type = Interface::INTERSECT ) = 0;
-
also, this part of the code is not efficient:
`for(int i=0; i<2; i++) { moab::EntityHandle element;// add hexahedron moab::Range range; rval = mb->create_element( moab::MBHEX, conn[i], 8, element ); range.insert( element ); mb->add_entities(0, range); }
`
should be
moab::Range range;
` for(int i=0; i<2; i++) { moab::EntityHandle element;// add hexahedron rval = mb->create_element( moab::MBHEX, conn[i], 8, element ); range.insert( element ); }
mb->add_entities(0, range);`
Also,
moab::EntityHandle conn[NUMHEX][2] = { { 1, 2, 5, 4, 10, 11, 14, 13 }, { 2, 3, 6, 5, 11, 12, 15, 14 } };
Should be
moab::EntityHandle conn[2][NUMHEX] = { { 1, 2, 5, 4, 10, 11, 14, 13 }, { 2, 3, 6, 5, 11, 12, 15, 14 } };
-
reporter Thank you.
Your point was very useful for me.
I resolved this issue.
-
reporter - changed status to resolved
- Log in to comment
You can query the adjacencies for the vertex and it should give you the entity handles for all the elements containing it.