MOAB: Mesh Oriented datABase  (version 5.5.0)
verdict_test.cpp File Reference
#include "moab/Core.hpp"
#include "moab/CartVect.hpp"
#include "moab/Range.hpp"
#include "moab/verdict/VerdictWrapper.hpp"
#include <iostream>
#include <iomanip>
#include <cstdio>
#include "TestUtil.hpp"
+ Include dependency graph for verdict_test.cpp:

Go to the source code of this file.

Classes

struct  test_case
 

Macros

#define MAX_NODES_PER_ELEMENT   27
 
#define MAX_TESTS_PER_ELEMENT   20
 
#define VERDICT_SIGNIFICANT_FIG   15
 
#define MAX_STR_LEN   30
 

Functions

void verdict_test1 ()
 
void verdict_unit_tests ()
 
int main (int argc, char *argv[])
 

Variables

std::string filename = TestDir + "unittest/mbtest1.vtk"
 

Macro Definition Documentation

◆ MAX_NODES_PER_ELEMENT

#define MAX_NODES_PER_ELEMENT   27

Definition at line 83 of file verdict_test.cpp.

◆ MAX_STR_LEN

#define MAX_STR_LEN   30

◆ MAX_TESTS_PER_ELEMENT

#define MAX_TESTS_PER_ELEMENT   20

Definition at line 84 of file verdict_test.cpp.

◆ VERDICT_SIGNIFICANT_FIG

#define VERDICT_SIGNIFICANT_FIG   15

Definition at line 89 of file verdict_test.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 17 of file verdict_test.cpp.

18 {
19  if( argc > 1 )
20  if( argc > 1 ) filename = std::string( argv[1] );
21 
22  int result = 0;
23 
24  result += RUN_TEST( verdict_test1 );
25  result += RUN_TEST( verdict_unit_tests );
26 
27  return result;
28 }

References filename, RUN_TEST, verdict_test1(), and verdict_unit_tests().

◆ verdict_test1()

void verdict_test1 ( )

Definition at line 29 of file verdict_test.cpp.

30 {
31  ErrorCode rval;
32  Core moab_core;
33  Interface* mb = &moab_core;
34  rval = mb->load_mesh( filename.c_str() );CHECK_ERR( rval );
35 
37  rval = mb->get_entities_by_handle( 0, entities ); // all entities from the model
38  CHECK_ERR( rval );
39 
40  VerdictWrapper vw( mb );
41  // for size methods/quality, we need a size, to compute relative sizes and stuff
42  rval = vw.set_size( 1.0 );CHECK_ERR( rval );
43  for( Range::iterator eit = entities.begin(); eit != entities.end(); ++eit )
44  {
45  EntityHandle eh = *eit;
46  EntityType etype = TYPE_FROM_HANDLE( eh );
47  if( etype == MBVERTEX || etype > MBHEX ) continue;
48  for( int quality = 0; quality < MB_QUALITY_COUNT; quality++ )
49  {
50  QualityType q = (QualityType)quality;
51  double qm;
52  rval = vw.quality_measure( eh, q, qm );
53  if( MB_NOT_IMPLEMENTED == rval ) continue;
54  if( MB_FAILURE == rval )
55  {
56  std::cerr << " failure for entity " << mb->list_entity( eh ) << " quality " << vw.quality_name( q )
57  << "\n";
58  }
59  if( MB_SUCCESS == rval )
60  {
61  std::cout << "Entity type " << (EntityType)mb->type_from_handle( eh )
62  << " id:" << mb->id_from_handle( eh ) << " quality:" << vw.quality_name( q ) << " : " << qm
63  << "\n";
64  }
65  }
66  // now compute all qualities for each entity handle
67  std::map< QualityType, double > qualities;
68 
69  rval = vw.all_quality_measures( eh, qualities );
70  if( MB_SUCCESS == rval )
71  {
72  mb->list_entity( eh );
73  for( std::map< QualityType, double >::iterator mit = qualities.begin(); mit != qualities.end(); ++mit )
74  {
75  std::cout << " " << vw.quality_name( mit->first ) << " " << mit->second << " \n";
76  }
77  }
78  }
79 
80  return;
81 }

References moab::VerdictWrapper::all_quality_measures(), CHECK_ERR, entities, ErrorCode, filename, moab::Core::get_entities_by_handle(), moab::Core::id_from_handle(), moab::Core::list_entity(), moab::Core::load_mesh(), mb, MB_NOT_IMPLEMENTED, moab::MB_QUALITY_COUNT, MB_SUCCESS, MBHEX, MBVERTEX, moab::VerdictWrapper::quality_measure(), moab::VerdictWrapper::quality_name(), moab::VerdictWrapper::set_size(), moab::Core::type_from_handle(), and moab::TYPE_FROM_HANDLE().

Referenced by main().

◆ verdict_unit_tests()

void verdict_unit_tests ( )

Definition at line 107 of file verdict_test.cpp.

108 {
109  // all test cases go here
110  test_case testcases[] = {
111  { "edge calc 1",
112  MBEDGE,
114  2,
115  { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 },
116  { 1.732050807568877, 0.0 } },
117 
118  { "edge calc 2",
119  MBEDGE,
121  2,
122  { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
123  { 1.0, 0.0 } },
124 
125  { "edge calc 3",
126  MBEDGE,
128  2,
129  { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
130  { 0.0, 0.0 } },
131 
132  { "simple wedge",
133  MBPRISM,
135  6,
136  { 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, 1.0, 1.0, -1.0, 0.0, 1.0 },
137  { 0.5, 0.0 } },
138 
139  { "singularity wedge",
140  MBPRISM,
142  6,
143  { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
144  { 0.0, 0.0 } },
145 
146  { "simple tri",
147  MBTRI,
150  3,
151  {
152  0.0,
153  0.0,
154  0.0,
155  5,
156  0.0,
157  0.0,
158  2.5,
159  4.330127,
160  0.0,
161  },
162  { 10.825317499999997, 5.999999989158383329e+01, 6.000000021683238316e+01, 1.000000000000000000e+00,
163  9.999999989075266660e-01, 1.000000000000000000e+00, 8.533333407912848181e-03, 8.533333407912848181e-03,
164  1.000000000000000000e+00, 0.0 } },
165 
166  /*
167  {
168  "singular tri",
169  MBTRI,
170  { v_tri_area, v_tri_aspect_ratio, v_tri_condition,
171  v_tri_distortion, v_tri_minimum_angle, v_tri_maximum_angle,
172  v_tri_relative_size_squared, v_tri_shape, v_tri_shape_and_size,
173  MB_UNDEFINED_QUALITY
174  },
175  3,
176  {
177  {0,0,0},
178  {0.5,0.8660254037,0},
179  {1,0,0}
180  },
181  { 123, 1234, 1234, 1234, 1234, 1234, 1234, 1234, 1234,0}
182  },
183  */
184 
185  /*
186  {
187  "simple quad",
188  MBQUAD,
189  { v_quad_skew, MB_UNDEFINED_QUALITY},
190  4,
191  {
192  {0,0,0},
193  {1,0,0},
194  {1,7,0},
195  {0,7,0 }
196  },
197  { 1.3333333333333333333, 0 }
198  },
199  */
200 
201  { "simple quad",
202  MBQUAD,
206  4,
207  {
208  2.0, 0.0, 0.0, // 1
209  1.0, 1.0, 2.0, // 2
210  0.0, 1.0, 0.0, // 3
211  0.0, 0.0, 0.0, // 0
212 
213  },
214  { 1.429964171762364344e+00, 9.245003270420482089e-02, 7.453559924999298980e-01, 7.999999999999998432e-03,
215  2.692582403567252314e+00, 5.773502691896258421e-01, 9.000000000000000000e+01, 5.678908923910092454e+01,
216  2.307927774486215888e+00, 1.114172029062311164e+00, 5.570860145311555822e-01, 5.570860145311555822e-01,
217  4.332891224131210084e-01, 9.999999999999995559e-01, 4.332891224131208419e-01, 5.570860145311553602e-01,
218  5.626795729450876360e-01, 0.0 } },
219 
220  { "tet test",
221  MBTET,
224  4,
225  {
226  -5.0,
227  -5.0,
228  -5.0,
229  -5.0,
230  5.0,
231  -5.0,
232  -5.0,
233  -5.0,
234  5.0,
235  5.0,
236  -5.0,
237  -5.0,
238 
239  },
240  { 1.666666666666666572e+02, 1.224744871391589385e+00, 1.000000000000000000e+03, 8.399473665965818681e-01,
241  3.599999999998462557e-05, 3.023810519746403209e-05, 1.000000000000000000e+00, 0.0 } },
242 
243  { "hex test",
244  MBHEX,
248  8,
249  {
250  -0.2, -0.7, -0.3, // 1
251  -0.7, 0.4, -0.6, // 2
252  -0.5, 0.5, 0.3, // 3
253  -0.3, -0.5, 0.5, // 0
254 
255  0.5, -0.8, -0.2, // 5
256  0.4, 0.4, -0.6, // 6
257  0.2, 0.5, 0.2, // 7
258  0.5, -0.3, 0.8 // 4
259  },
260  { 2.458897037399689067e-01, 1.784576525620624188e-01, 8.130624999999999103e-01, 6.209702997008308412e-01,
261  6.896219298787312768e-01, 5.245942005845132261e-01, 1.273059825673506174e+00, 4.769999999999999241e-01,
262  7.778495101180593618e-01, 7.778495101180593618e-01, 7.897852810190353345e-01, 6.738357656250002492e-01,
263  5.241428201914338780e-01, 5.321855695148176579e-01, 5.847977114834492784e-01, 0.0 } },
264 
265  // keep this one last
266  // { 0, {MB_UNDEFINED_QUALITY} , 0, {{0}} , {0} } };
267  { 0, MBMAXTYPE, { MB_UNDEFINED_QUALITY }, 0, { 0.0, 0.0 }, { 0.0, 0.0 } }
268 
269  };
270 
271  int i;
272  int j = 0;
273  double answer_from_lib;
274  double tolerance;
275  // double norm_answer_from_lib;
276 
277 #define MAX_STR_LEN 30
278 
279  char exponent[MAX_STR_LEN];
280  char* base_ptr;
281  int base;
282  bool passed = true; // have all the tests performed so far passed?
283 
284  cout.setf( ios::scientific, ios::floatfield );
285  cout.precision( VERDICT_SIGNIFICANT_FIG + 3 );
286 
287  ErrorCode merr;
288  Interface* iface = new Core();
289  VerdictWrapper* vw = new VerdictWrapper( iface );
290  EntityHandle dummy = 0;
291 
292  // loop through each test
293  for( i = 0; testcases[i].testname != 0; i++ )
294  {
295  cout << endl
296  << "[" << i << "]: "
297  << "Test case: " << testcases[i].testname << endl;
298 
299  for( j = 0; testcases[i].function[j] != MB_UNDEFINED_QUALITY; j++ )
300  {
301  /*
302  answer_from_lib =
303  (testcases[i].function[j])
304  (testcases[i].num_nodes, testcases[i].coords);
305  */
306 
307  cout << "\t #" << j + 1 << " TESTING :: " << QualityType_ToString( testcases[i].function[j] ) << endl;
308  merr = vw->quality_measure( dummy, testcases[i].function[j], answer_from_lib, testcases[i].num_nodes,
309  testcases[i].etype, testcases[i].coords );
310  if( MB_SUCCESS != merr )
311  {
312  delete vw;
313  delete iface;
314  MB_SET_ERR_RET( "Failed to compute the quality for an element" );
315  }
316 
317  sprintf( exponent, "%e", testcases[i].answer[j] );
318  base_ptr = strstr( exponent, "e" );
319 
320  base_ptr = &base_ptr[1];
321 
322  base = atoi( base_ptr );
323 
324  tolerance = pow( 10.0, -VERDICT_SIGNIFICANT_FIG ) * pow( 10.0, base );
325 
326  if( fabs( answer_from_lib - testcases[i].answer[j] ) > tolerance )
327  {
328  cout << "\t #" << j + 1 << " FAILED :: " << QualityType_ToString( testcases[i].function[j] ) << endl;
329 
330  cout << "\t\t calculated ( " << answer_from_lib << " ) and "
331  << "expected ( " << testcases[i].answer[j] << ") " << endl;
332  passed = false;
333  }
334  else
335  {
336  cout << "\t #" << j + 1 << " PASSED :: " << QualityType_ToString( testcases[i].function[j] ) << endl;
337  }
338  }
339  }
340  delete vw;
341  delete iface;
342  std::cout << endl << "All tests passed ? " << ( passed ? 1 : 0 ) << endl;
343  return;
344 }

References test_case::answer, ErrorCode, test_case::function, iface, MAX_STR_LEN, moab::MB_AREA, moab::MB_ASPECT_RATIO, moab::MB_CONDITION, moab::MB_DIAGONAL, moab::MB_DIMENSION, moab::MB_DISTORTION, moab::MB_JACOBIAN, moab::MB_LENGTH, moab::MB_MAXIMUM_ANGLE, moab::MB_MINIMUM_ANGLE, moab::MB_RELATIVE_SIZE_SQUARED, moab::MB_SCALED_JACOBIAN, MB_SET_ERR_RET, moab::MB_SHAPE, moab::MB_SHAPE_AND_SIZE, moab::MB_SHEAR, moab::MB_SHEAR_AND_SIZE, moab::MB_SKEW, moab::MB_STRETCH, MB_SUCCESS, moab::MB_TAPER, moab::MB_UNDEFINED_QUALITY, moab::MB_VOLUME, moab::MB_WARPAGE, MBEDGE, MBHEX, MBMAXTYPE, MBPRISM, MBQUAD, MBTET, MBTRI, moab::VerdictWrapper::quality_measure(), moab::QualityType_ToString(), test_case::testname, moab::tolerance, and VERDICT_SIGNIFICANT_FIG.

Referenced by main().

Variable Documentation

◆ filename

std::string filename = TestDir + "unittest/mbtest1.vtk"

Definition at line 10 of file verdict_test.cpp.

Referenced by main(), and verdict_test1().