[MOAB-dev] question about the order of the vertices of triangle in MOAB

Grindeanu, Iulian R. iulian at mcs.anl.gov
Sun Jun 22 11:07:25 CDT 2014


You need to use the method
 ErrorCode  get_connectivity(const EntityHandle *entity_handles, 
                                      const int num_handles,
                                      std::vector<EntityHandle> &connectivity, 
                                      bool corners_only = false,
                                      std::vector<int> *offsets = NULL) 

It will return a std::vector of vertices, ordered in the same order you set them in.

Range is a special std-like container, in moab, to store moab entity handles. In this container, the entity handles are ordered by type and entity id (look in the manual for more details)

"unordered" means that it will not have the initial order; They are "ordered" by entity handle. This is why you get 1,2,4, instead of 2,4,1 

Iulian

________________________________________
From: moab-dev-bounces at mcs.anl.gov [moab-dev-bounces at mcs.anl.gov] on behalf of Huayi Wei [huayiwei1984 at gmail.com]
Sent: Sunday, June 22, 2014 8:21 AM
To: MOAB Dev
Subject: [MOAB-dev] question about the order of the vertices of triangle in     MOAB

Hi, Moab Developer,

I am learning how to use moab and meet a problem. I write a test to
check the order of the vertices of a triangle based Moab.  Suppose we
have two triangles (2, 4, 1) and (3, 1, 4) as following:

3--------------4
|               /  |
|           /      |
|       /          |
|   /              |
1--------------2

I create them in Moab and then get them again by `get_connectivity`. I
found the orders were changed to (1,2,4) and ( 1, 3, 4).

I check the implement of `get_connectivity`, and find a `sort` operation
in it.  But the comment of `get_connectivity` say the range is unordered!


```
     //! Gets the connectivity for a vector of elements
     /** Same as vector-based version except range is returned (unordered!)
      */
   virtual ErrorCode  get_connectivity(const EntityHandle *entity_handles,
                                         const int num_handles,
                                         Range &connectivity,
                                         bool corners_only = false) const;
```

My question is how can I get the same order  as my setting at beginning?
You know the order is important for finite element method and I want to
write some finite
element code based on Moab.

I am not familar with moab and I need your help. Thanks very much.

Best

Huayi


```
#include "moab/Core.hpp"
#include <iostream>
#include <assert.h>

using namespace moab;
using namespace std;

int main()
{
     string file_name = "order_mesh.vtk";
     Interface *iface = new Core;

     // ***************************
     // *   Create the vertexes   *
     // ***************************

     const double vertex_coords[3*4] = {0,0,0, 1,0,0, 0,1,0, 1,1,0 };

     Range vertex_handles;
     ErrorCode rval =
iface->create_vertices(vertex_coords,4,vertex_handles);
     assert(rval == MB_SUCCESS);

     // You can print out a range to see what elements it contains:
     std::cout << "Just created the following entities:"
           << vertex_handles << std::endl;

     // ***************************
     // *   Create the faces      *
     // ***************************

     EntityHandle conn[2][3] = { {2,4,1}, {3,1,4} };

     Range tri_handles;
     EntityHandle tri_handle;
     for(int i = 0; i < 2; i++)
     {
         rval = iface->create_element(MBTRI,conn[i],3,tri_handle);
         tri_handles.insert(tri_handle);
     }

     // Let's see what entities we just created:
     cout << "Just created the following entities: "
           << tri_handles << endl;

     Range::iterator tit;
     for(tit = tri_handles.begin(); tit != tri_handles.end(); tit ++)
     {
         EntityHandle tri = *tit;

         Range conn;
         iface->get_connectivity(&tri, 1, conn);

         Range::iterator cit;
         for(cit = conn.begin(); cit != conn.end(); cit ++)
         {
             cout << " " << *cit;
         }
         cout << endl;

     }

     rval = iface->write_file(file_name.c_str());

     return 0 ;
}

```




More information about the moab-dev mailing list