MOAB: Mesh Oriented datABase  (version 5.5.0)
gmsh_test.cpp File Reference
#include "TestUtil.hpp"
#include "moab/Core.hpp"
#include "moab/Range.hpp"
#include "MBTagConventions.hpp"
#include <cmath>
#include <algorithm>
+ Include dependency graph for gmsh_test.cpp:

Go to the source code of this file.

Functions

void test_read_nodes ()
 
void test_read_quads ()
 
void test_read_material_set ()
 
void test_read_material_on_nodes ()
 
void test_read_geom_set ()
 
void test_read_airfoil ()
 
void test_read_t1 ()
 
void test_read_fgh ()
 
void read_file (Interface &moab, const char *input_file)
 
int main ()
 

Variables

static const char example [] = "gmsh2.msh"
 
static const char example2 [] = "airfoil_exterior.msh"
 
static const char example3 [] = "t1.msh"
 
static const char example4 [] = "ghosts.msh"
 
static const char example5 [] = "gmsh3.msh"
 

Function Documentation

◆ main()

int main ( )

Definition at line 39 of file gmsh_test.cpp.

40 {
41  int result = 0;
42 
43  result += RUN_TEST( test_read_nodes );
44  result += RUN_TEST( test_read_quads );
45  result += RUN_TEST( test_read_material_set );
47  result += RUN_TEST( test_read_geom_set );
48 
49  result += RUN_TEST( test_read_airfoil );
50  result += RUN_TEST( test_read_t1 );
51  result += RUN_TEST( test_read_fgh );
52  return result;
53 }

References RUN_TEST, test_read_airfoil(), test_read_fgh(), test_read_geom_set(), test_read_material_on_nodes(), test_read_material_set(), test_read_nodes(), test_read_quads(), and test_read_t1().

◆ read_file()

void read_file ( Interface moab,
const char *  input_file 
)

◆ test_read_airfoil()

void test_read_airfoil ( )

Definition at line 254 of file gmsh_test.cpp.

255 {
256  Core moab;
257  read_file( moab, example2 );
258 }

References example2, and read_file().

Referenced by main().

◆ test_read_fgh()

void test_read_fgh ( )

Definition at line 266 of file gmsh_test.cpp.

267 {
268  Core moab;
269  read_file( moab, example4 ); // it should find 3 partitions
270  // read partition sets
271  Tag ptag;
272  ErrorCode rval = moab.tag_get_handle( "PARALLEL_PARTITION", ptag );CHECK_ERR( rval );
273  Range psets;
274  rval = moab.get_entities_by_type_and_tag( 0, MBENTITYSET, &ptag, 0, 1, psets );CHECK_ERR( rval );
275  CHECK_EQUAL( 3, (int)psets.size() );
276  Range ents_first_set;
277  rval = moab.get_entities_by_handle( psets[0], ents_first_set );CHECK_ERR( rval );
278  CHECK_EQUAL( (int)ents_first_set.size(), 98 );
279 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, example4, MBENTITYSET, read_file(), and moab::Range::size().

Referenced by main().

◆ test_read_geom_set()

void test_read_geom_set ( )

Definition at line 222 of file gmsh_test.cpp.

223 {
224  ErrorCode rval;
225  Core moab;
226  Interface& mb = moab;
227  read_file( moab, example );
228 
229  Tag dim_tag, id_tag;
231  id_tag = mb.globalId_tag();
232 
233  Range sets;
234  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &dim_tag, 0, 1, sets );CHECK_ERR( rval );
235  CHECK_EQUAL( 1, (int)sets.size() );
236  EntityHandle set = sets.front();
237 
238  int dim;
239  rval = mb.tag_get_data( dim_tag, &set, 1, &dim );CHECK_ERR( rval );
240  CHECK_EQUAL( 2, dim );
241 
242  int id;
243  rval = mb.tag_get_data( id_tag, &set, 1, &id );CHECK_ERR( rval );
244  CHECK_EQUAL( 3, id );
245 
246  std::vector< EntityHandle > quads, contents;
247  rval = mb.get_entities_by_type( 0, MBQUAD, quads );CHECK_ERR( rval );
248  rval = mb.get_entities_by_handle( set, contents );CHECK_ERR( rval );
249  std::sort( quads.begin(), quads.end() );
250  std::sort( contents.begin(), contents.end() );
251  CHECK_EQUAL( quads, contents );
252 }

References CHECK_EQUAL, CHECK_ERR, dim, dim_tag, ErrorCode, example, moab::Range::front(), GEOM_DIMENSION_TAG_NAME, moab::Core::get_entities_by_handle(), moab::Core::get_entities_by_type(), moab::Core::get_entities_by_type_and_tag(), moab::Core::globalId_tag(), id_tag, mb, MB_TYPE_INTEGER, MBENTITYSET, MBQUAD, read_file(), moab::Range::size(), moab::Core::tag_get_data(), and moab::Core::tag_get_handle().

Referenced by main().

◆ test_read_material_on_nodes()

void test_read_material_on_nodes ( )

Definition at line 197 of file gmsh_test.cpp.

198 {
199  ErrorCode rval;
200  Core moab;
201  Interface& mb = moab;
202  read_file( moab, example5 );
203 
204  Tag mat_tag;
205  rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mat_tag );CHECK_ERR( rval );
206 
207  Range sets;
208  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, 0, 1, sets );CHECK_ERR( rval );
209  CHECK_EQUAL( 2, (int)sets.size() );
210 
211  EntityHandle set_101 = sets.front();
212  EntityHandle set_102 = sets.back();
213 
214  int id;
215  rval = mb.tag_get_data( mat_tag, &set_101, 1, &id );CHECK_ERR( rval );
216  CHECK_EQUAL( 101, id );
217 
218  rval = mb.tag_get_data( mat_tag, &set_102, 1, &id );CHECK_ERR( rval );
219  CHECK_EQUAL( 102, id );
220 }

References moab::Range::back(), CHECK_EQUAL, CHECK_ERR, ErrorCode, example5, moab::Range::front(), moab::Core::get_entities_by_type_and_tag(), MATERIAL_SET_TAG_NAME, mb, MB_TYPE_INTEGER, MBENTITYSET, read_file(), moab::Range::size(), moab::Core::tag_get_data(), and moab::Core::tag_get_handle().

Referenced by main().

◆ test_read_material_set()

void test_read_material_set ( )

Definition at line 170 of file gmsh_test.cpp.

171 {
172  ErrorCode rval;
173  Core moab;
174  Interface& mb = moab;
175  read_file( moab, example );
176 
177  Tag mat_tag;
178  rval = mb.tag_get_handle( MATERIAL_SET_TAG_NAME, 1, MB_TYPE_INTEGER, mat_tag );CHECK_ERR( rval );
179 
180  Range sets;
181  rval = mb.get_entities_by_type_and_tag( 0, MBENTITYSET, &mat_tag, 0, 1, sets );CHECK_ERR( rval );
182  CHECK_EQUAL( 1, (int)sets.size() );
183  EntityHandle set = sets.front();
184 
185  int id;
186  rval = mb.tag_get_data( mat_tag, &set, 1, &id );CHECK_ERR( rval );
187  CHECK_EQUAL( 99, id );
188 
189  std::vector< EntityHandle > quads, contents;
190  rval = mb.get_entities_by_type( 0, MBQUAD, quads );CHECK_ERR( rval );
191  rval = mb.get_entities_by_handle( set, contents );CHECK_ERR( rval );
192  std::sort( quads.begin(), quads.end() );
193  std::sort( contents.begin(), contents.end() );
194  CHECK_EQUAL( quads, contents );
195 }

References CHECK_EQUAL, CHECK_ERR, ErrorCode, example, moab::Range::front(), moab::Core::get_entities_by_handle(), moab::Core::get_entities_by_type(), moab::Core::get_entities_by_type_and_tag(), MATERIAL_SET_TAG_NAME, mb, MB_TYPE_INTEGER, MBENTITYSET, MBQUAD, read_file(), moab::Range::size(), moab::Core::tag_get_data(), and moab::Core::tag_get_handle().

Referenced by main().

◆ test_read_nodes()

void test_read_nodes ( )

Definition at line 61 of file gmsh_test.cpp.

62 {
63  const double eps = 1e-100;
64  ErrorCode rval;
65  Core moab;
66  Interface& mb = moab;
68 
69  std::vector< EntityHandle > nodes;
70  rval = mb.get_entities_by_type( 0, MBVERTEX, nodes );CHECK_ERR( rval );
71  CHECK_EQUAL( (size_t)6, nodes.size() );
72 
74 
75  std::vector< int > ids( nodes.size() );
76  rval = mb.tag_get_data( id_tag, &nodes[0], nodes.size(), &ids[0] );CHECK_ERR( rval );
77 
78  std::vector< int > sorted_ids( ids );
79  std::sort( sorted_ids.begin(), sorted_ids.end() );
80 
81  std::vector< double > coords( 3 * nodes.size() );
82  rval = mb.get_coords( &nodes[0], nodes.size(), &coords[0] );CHECK_ERR( rval );
83 
84  int idx, pos = 0;
85  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
86  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
87  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
88  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
89  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
90 
91  ++pos;
92  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
93  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
94  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
95  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
96  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
97 
98  ++pos;
99  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
100  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
101  CHECK_REAL_EQUAL( coords[3 * idx + 0], 1.0, eps );
102  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
103  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
104 
105  ++pos;
106  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
107  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
108  CHECK_REAL_EQUAL( coords[3 * idx + 0], 0.0, eps );
109  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
110  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
111 
112  ++pos;
113  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
114  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
115  CHECK_REAL_EQUAL( coords[3 * idx + 0], 2.0, eps );
116  CHECK_REAL_EQUAL( coords[3 * idx + 1], 0.0, eps );
117  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
118 
119  ++pos;
120  CHECK_EQUAL( pos + 1, sorted_ids[pos] );
121  idx = std::find( ids.begin(), ids.end(), pos + 1 ) - ids.begin();
122  CHECK_REAL_EQUAL( coords[3 * idx + 0], 2.0, eps );
123  CHECK_REAL_EQUAL( coords[3 * idx + 1], 1.0, eps );
124  CHECK_REAL_EQUAL( coords[3 * idx + 2], 0.0, eps );
125 }

References CHECK_EQUAL, CHECK_ERR, CHECK_REAL_EQUAL, eps, ErrorCode, example, moab::Core::get_coords(), moab::Core::get_entities_by_type(), moab::Core::globalId_tag(), id_tag, mb, MBVERTEX, read_file(), and moab::Core::tag_get_data().

Referenced by main().

◆ test_read_quads()

void test_read_quads ( )

Definition at line 127 of file gmsh_test.cpp.

128 {
129  ErrorCode rval;
130  Core moab;
131  Interface& mb = moab;
132  read_file( moab, example );
133 
134  std::vector< EntityHandle > quads;
135  rval = mb.get_entities_by_type( 0, MBQUAD, quads );CHECK_ERR( rval );
136  CHECK_EQUAL( (size_t)2, quads.size() );
137 
139 
140  std::vector< int > ids( quads.size() );
141  rval = mb.tag_get_data( id_tag, &quads[0], quads.size(), &ids[0] );CHECK_ERR( rval );
142 
143  if( ids[0] != 1 )
144  {
145  std::swap( ids[0], ids[1] );
146  std::swap( quads[0], quads[1] );
147  }
148 
149  int vtx_ids[4];
150  const EntityHandle* conn;
151  int len;
152 
153  const int conn1[] = { 1, 2, 3, 4 };
154  int pos = 0;
155  CHECK_EQUAL( pos + 1, ids[pos] );
156  rval = mb.get_connectivity( quads[pos], conn, len );CHECK_ERR( rval );
157  CHECK_EQUAL( 4, len );
158  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
159  CHECK_ARRAYS_EQUAL( conn1, 4, vtx_ids, len );
160 
161  const int conn2[] = { 2, 5, 6, 3 };
162  ++pos;
163  CHECK_EQUAL( pos + 1, ids[pos] );
164  rval = mb.get_connectivity( quads[pos], conn, len );CHECK_ERR( rval );
165  CHECK_EQUAL( 4, len );
166  rval = mb.tag_get_data( id_tag, conn, len, vtx_ids );CHECK_ERR( rval );
167  CHECK_ARRAYS_EQUAL( conn2, 4, vtx_ids, len );
168 }

References CHECK_ARRAYS_EQUAL, CHECK_EQUAL, CHECK_ERR, ErrorCode, example, moab::Core::get_connectivity(), moab::Core::get_entities_by_type(), moab::Core::globalId_tag(), id_tag, mb, MBQUAD, read_file(), swap(), and moab::Core::tag_get_data().

Referenced by main().

◆ test_read_t1()

void test_read_t1 ( )

Definition at line 260 of file gmsh_test.cpp.

261 {
262  Core moab;
263  read_file( moab, example3 );
264 }

References example3, and read_file().

Referenced by main().

Variable Documentation

◆ example

◆ example2

const char example2[] = "airfoil_exterior.msh"
static

Definition at line 22 of file gmsh_test.cpp.

Referenced by test_read_airfoil().

◆ example3

const char example3[] = "t1.msh"
static

Definition at line 23 of file gmsh_test.cpp.

Referenced by test_read_t1().

◆ example4

const char example4[] = "ghosts.msh"
static

Definition at line 24 of file gmsh_test.cpp.

Referenced by test_read_fgh().

◆ example5

const char example5[] = "gmsh3.msh"
static

Definition at line 25 of file gmsh_test.cpp.

Referenced by test_read_material_on_nodes().