MOAB: Mesh Oriented datABase  (version 5.4.1)
verdict_test.cpp
Go to the documentation of this file.
00001 #include "moab/Core.hpp"
00002 #include "moab/CartVect.hpp"
00003 #include "moab/Range.hpp"
00004 #include "moab/verdict/VerdictWrapper.hpp"
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <cstdio>
00008 #include "TestUtil.hpp"
00009 
00010 std::string filename = TestDir + "unittest/mbtest1.vtk";
00011 
00012 using namespace moab;
00013 
00014 void verdict_test1();
00015 void verdict_unit_tests();
00016 
00017 int main( int argc, char* argv[] )
00018 {
00019     if( argc > 1 )
00020         if( argc > 1 ) filename = std::string( argv[1] );
00021 
00022     int result = 0;
00023 
00024     result += RUN_TEST( verdict_test1 );
00025     result += RUN_TEST( verdict_unit_tests );
00026 
00027     return result;
00028 }
00029 void verdict_test1()
00030 {
00031     ErrorCode rval;
00032     Core moab_core;
00033     Interface* mb = &moab_core;
00034     rval          = mb->load_mesh( filename.c_str() );CHECK_ERR( rval );
00035 
00036     Range entities;
00037     rval = mb->get_entities_by_handle( 0, entities );  // all entities from the model
00038     CHECK_ERR( rval );
00039 
00040     VerdictWrapper vw( mb );
00041     // for size methods/quality, we need a size, to compute relative sizes and stuff
00042     rval = vw.set_size( 1.0 );CHECK_ERR( rval );
00043     for( Range::iterator eit = entities.begin(); eit != entities.end(); ++eit )
00044     {
00045         EntityHandle eh  = *eit;
00046         EntityType etype = TYPE_FROM_HANDLE( eh );
00047         if( etype == MBVERTEX || etype > MBHEX ) continue;
00048         for( int quality = 0; quality < MB_QUALITY_COUNT; quality++ )
00049         {
00050             QualityType q = (QualityType)quality;
00051             double qm;
00052             rval = vw.quality_measure( eh, q, qm );
00053             if( MB_NOT_IMPLEMENTED == rval ) continue;
00054             if( MB_FAILURE == rval )
00055             {
00056                 std::cerr << " failure for entity " << mb->list_entity( eh ) << " quality " << vw.quality_name( q )
00057                           << "\n";
00058             }
00059             if( MB_SUCCESS == rval )
00060             {
00061                 std::cout << "Entity type " << (EntityType)mb->type_from_handle( eh )
00062                           << " id:" << mb->id_from_handle( eh ) << " quality:" << vw.quality_name( q ) << " : " << qm
00063                           << "\n";
00064             }
00065         }
00066         // now compute all qualities for each entity handle
00067         std::map< QualityType, double > qualities;
00068 
00069         rval = vw.all_quality_measures( eh, qualities );
00070         if( MB_SUCCESS == rval )
00071         {
00072             mb->list_entity( eh );
00073             for( std::map< QualityType, double >::iterator mit = qualities.begin(); mit != qualities.end(); ++mit )
00074             {
00075                 std::cout << "   " << vw.quality_name( mit->first ) << " " << mit->second << " \n";
00076             }
00077         }
00078     }
00079 
00080     return;
00081 }
00082 
00083 #define MAX_NODES_PER_ELEMENT 27
00084 #define MAX_TESTS_PER_ELEMENT 20
00085 
00086 #ifdef VERDICT_USE_FLOAT
00087 #define VERDICT_SIGNIFICANT_FIG 7  // 7 significant figures for floats
00088 #else
00089 #define VERDICT_SIGNIFICANT_FIG 15  // 15 significant figures for doubles
00090 #endif
00091 
00092 struct test_case
00093 {
00094     const char* testname;
00095     EntityType etype;
00096     // VerdictFunction function[MAX_TESTS_PER_ELEMENT];
00097     QualityType function[MAX_TESTS_PER_ELEMENT];
00098     int num_nodes;
00099     // note: the 1st dim. of coords must bigger than the maximum num_nodes
00100     // for any one element being tested
00101     // double coords[MAX_NODES_PER_ELEMENT][3];
00102     double coords[MAX_NODES_PER_ELEMENT * 3];
00103     double answer[MAX_TESTS_PER_ELEMENT];
00104 };
00105 using namespace std;
00106 
00107 void verdict_unit_tests()
00108 {
00109     // all test cases go here
00110     test_case testcases[] = {
00111         { "edge calc 1",
00112           MBEDGE,
00113           { MB_LENGTH, MB_UNDEFINED_QUALITY },
00114           2,
00115           { 0.0, 0.0, 0.0, 1.0, 1.0, 1.0 },
00116           { 1.732050807568877, 0.0 } },
00117 
00118         { "edge calc 2",
00119           MBEDGE,
00120           { MB_LENGTH, MB_UNDEFINED_QUALITY },
00121           2,
00122           { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
00123           { 1.0, 0.0 } },
00124 
00125         { "edge calc 3",
00126           MBEDGE,
00127           { MB_LENGTH, MB_UNDEFINED_QUALITY },
00128           2,
00129           { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
00130           { 0.0, 0.0 } },
00131 
00132         { "simple wedge",
00133           MBPRISM,
00134           { MB_VOLUME, MB_UNDEFINED_QUALITY },
00135           6,
00136           { 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 },
00137           { 0.5, 0.0 } },
00138 
00139         { "singularity wedge",
00140           MBPRISM,
00141           { MB_VOLUME, MB_UNDEFINED_QUALITY },
00142           6,
00143           { 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 },
00144           { 0.0, 0.0 } },
00145 
00146         { "simple tri",
00147           MBTRI,
00148           { MB_AREA, MB_MINIMUM_ANGLE, MB_MAXIMUM_ANGLE, MB_CONDITION, MB_SCALED_JACOBIAN, MB_SHAPE,
00149             MB_RELATIVE_SIZE_SQUARED, MB_SHAPE_AND_SIZE, MB_DISTORTION, MB_UNDEFINED_QUALITY },
00150           3,
00151           {
00152               0.0,
00153               0.0,
00154               0.0,
00155               5,
00156               0.0,
00157               0.0,
00158               2.5,
00159               4.330127,
00160               0.0,
00161           },
00162           { 10.825317499999997, 5.999999989158383329e+01, 6.000000021683238316e+01, 1.000000000000000000e+00,
00163             9.999999989075266660e-01, 1.000000000000000000e+00, 8.533333407912848181e-03, 8.533333407912848181e-03,
00164             1.000000000000000000e+00, 0.0 } },
00165 
00166         /*
00167         {
00168             "singular tri",
00169             MBTRI,
00170             { v_tri_area, v_tri_aspect_ratio, v_tri_condition,
00171               v_tri_distortion, v_tri_minimum_angle, v_tri_maximum_angle,
00172               v_tri_relative_size_squared, v_tri_shape, v_tri_shape_and_size,
00173               MB_UNDEFINED_QUALITY
00174             },
00175             3,
00176             {
00177               {0,0,0},
00178               {0.5,0.8660254037,0},
00179               {1,0,0}
00180             },
00181             { 123, 1234, 1234, 1234, 1234, 1234, 1234, 1234, 1234,0}
00182         },
00183         */
00184 
00185         /*
00186         {
00187             "simple quad",
00188             MBQUAD,
00189             { v_quad_skew, MB_UNDEFINED_QUALITY},
00190             4,
00191             {
00192               {0,0,0},
00193               {1,0,0},
00194               {1,7,0},
00195               {0,7,0 }
00196             },
00197             { 1.3333333333333333333, 0 }
00198         },
00199         */
00200 
00201         { "simple quad",
00202           MBQUAD,
00203           { MB_ASPECT_RATIO, MB_SKEW, MB_TAPER, MB_WARPAGE, MB_AREA, MB_STRETCH, MB_MAXIMUM_ANGLE, MB_MINIMUM_ANGLE,
00204             MB_CONDITION, MB_JACOBIAN, MB_SCALED_JACOBIAN, MB_SHEAR, MB_SHAPE, MB_RELATIVE_SIZE_SQUARED,
00205             MB_SHAPE_AND_SIZE, MB_SHEAR_AND_SIZE, MB_DISTORTION, MB_UNDEFINED_QUALITY },
00206           4,
00207           {
00208               2.0, 0.0, 0.0,  // 1
00209               1.0, 1.0, 2.0,  // 2
00210               0.0, 1.0, 0.0,  // 3
00211               0.0, 0.0, 0.0,  // 0
00212 
00213           },
00214           { 1.429964171762364344e+00, 9.245003270420482089e-02, 7.453559924999298980e-01, 7.999999999999998432e-03,
00215             2.692582403567252314e+00, 5.773502691896258421e-01, 9.000000000000000000e+01, 5.678908923910092454e+01,
00216             2.307927774486215888e+00, 1.114172029062311164e+00, 5.570860145311555822e-01, 5.570860145311555822e-01,
00217             4.332891224131210084e-01, 9.999999999999995559e-01, 4.332891224131208419e-01, 5.570860145311553602e-01,
00218             5.626795729450876360e-01, 0.0 } },
00219 
00220         { "tet test",
00221           MBTET,
00222           { /*MB_SHEAR,*/ MB_VOLUME, MB_CONDITION, MB_JACOBIAN, MB_SHAPE, MB_RELATIVE_SIZE_SQUARED, MB_SHAPE_AND_SIZE,
00223             MB_DISTORTION, MB_UNDEFINED_QUALITY },
00224           4,
00225           {
00226               -5.0,
00227               -5.0,
00228               -5.0,
00229               -5.0,
00230               5.0,
00231               -5.0,
00232               -5.0,
00233               -5.0,
00234               5.0,
00235               5.0,
00236               -5.0,
00237               -5.0,
00238 
00239           },
00240           { 1.666666666666666572e+02, 1.224744871391589385e+00, 1.000000000000000000e+03, 8.399473665965818681e-01,
00241             3.599999999998462557e-05, 3.023810519746403209e-05, 1.000000000000000000e+00, 0.0 } },
00242 
00243         { "hex test",
00244           MBHEX,
00245           { /*MB_ASPECT_RATIO,*/ MB_SKEW, MB_TAPER, MB_VOLUME, MB_STRETCH, MB_DIAGONAL, MB_DIMENSION, MB_CONDITION,
00246             MB_JACOBIAN, MB_SCALED_JACOBIAN, MB_SHEAR, MB_SHAPE, MB_RELATIVE_SIZE_SQUARED, MB_SHEAR_AND_SIZE,
00247             MB_SHAPE_AND_SIZE, MB_DISTORTION, MB_UNDEFINED_QUALITY },
00248           8,
00249           {
00250               -0.2, -0.7, -0.3,  // 1
00251               -0.7, 0.4,  -0.6,  // 2
00252               -0.5, 0.5,  0.3,   // 3
00253               -0.3, -0.5, 0.5,   // 0
00254 
00255               0.5,  -0.8, -0.2,  // 5
00256               0.4,  0.4,  -0.6,  // 6
00257               0.2,  0.5,  0.2,   // 7
00258               0.5,  -0.3, 0.8    // 4
00259           },
00260           { 2.458897037399689067e-01, 1.784576525620624188e-01, 8.130624999999999103e-01, 6.209702997008308412e-01,
00261             6.896219298787312768e-01, 5.245942005845132261e-01, 1.273059825673506174e+00, 4.769999999999999241e-01,
00262             7.778495101180593618e-01, 7.778495101180593618e-01, 7.897852810190353345e-01, 6.738357656250002492e-01,
00263             5.241428201914338780e-01, 5.321855695148176579e-01, 5.847977114834492784e-01, 0.0 } },
00264 
00265         // keep this one last
00266         // { 0, {MB_UNDEFINED_QUALITY} , 0, {{0}} , {0} } };
00267         { 0, MBMAXTYPE, { MB_UNDEFINED_QUALITY }, 0, { 0.0, 0.0 }, { 0.0, 0.0 } }
00268 
00269     };
00270 
00271     int i;
00272     int j = 0;
00273     double answer_from_lib;
00274     double tolerance;
00275     //   double norm_answer_from_lib;
00276 
00277 #define MAX_STR_LEN 30
00278 
00279     char exponent[MAX_STR_LEN];
00280     char* base_ptr;
00281     int base;
00282     bool passed = true;  // have all the tests performed so far passed?
00283 
00284     cout.setf( ios::scientific, ios::floatfield );
00285     cout.precision( VERDICT_SIGNIFICANT_FIG + 3 );
00286 
00287     ErrorCode merr;
00288     Interface* iface   = new Core();
00289     VerdictWrapper* vw = new VerdictWrapper( iface );
00290     EntityHandle dummy = 0;
00291 
00292     // loop through each test
00293     for( i = 0; testcases[i].testname != 0; i++ )
00294     {
00295         cout << endl
00296              << "[" << i << "]: "
00297              << "Test case: " << testcases[i].testname << endl;
00298 
00299         for( j = 0; testcases[i].function[j] != MB_UNDEFINED_QUALITY; j++ )
00300         {
00301             /*
00302             answer_from_lib =
00303               (testcases[i].function[j])
00304               (testcases[i].num_nodes, testcases[i].coords);
00305             */
00306 
00307             cout << "\t #" << j + 1 << " TESTING :: " << QualityType_ToString( testcases[i].function[j] ) << endl;
00308             merr = vw->quality_measure( dummy, testcases[i].function[j], answer_from_lib, testcases[i].num_nodes,
00309                                         testcases[i].etype, testcases[i].coords );
00310             if( MB_SUCCESS != merr )
00311             {
00312                 delete vw;
00313                 delete iface;
00314                 MB_SET_ERR_RET( "Failed to compute the quality for an element" );
00315             }
00316 
00317             sprintf( exponent, "%e", testcases[i].answer[j] );
00318             base_ptr = strstr( exponent, "e" );
00319 
00320             base_ptr = &base_ptr[1];
00321 
00322             base = atoi( base_ptr );
00323 
00324             tolerance = pow( 10.0, -VERDICT_SIGNIFICANT_FIG ) * pow( 10.0, base );
00325 
00326             if( fabs( answer_from_lib - testcases[i].answer[j] ) > tolerance )
00327             {
00328                 cout << "\t #" << j + 1 << " FAILED :: " << QualityType_ToString( testcases[i].function[j] ) << endl;
00329 
00330                 cout << "\t\t calculated ( " << answer_from_lib << " ) and "
00331                      << "expected ( " << testcases[i].answer[j] << ") " << endl;
00332                 passed = false;
00333             }
00334             else
00335             {
00336                 cout << "\t #" << j + 1 << " PASSED :: " << QualityType_ToString( testcases[i].function[j] ) << endl;
00337             }
00338         }
00339     }
00340     delete vw;
00341     delete iface;
00342     std::cout << endl << "All tests passed ? " << ( passed ? 1 : 0 ) << endl;
00343     return;
00344 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines