MOAB: Mesh Oriented datABase  (version 5.4.1)
TQualityMetricTest Class Reference
+ Inheritance diagram for TQualityMetricTest:
+ Collaboration diagram for TQualityMetricTest:

Public Member Functions

void test_inverse_mean_ratio_grad ()
void test_inverse_mean_ratio_hess ()
void test_inverse_mean_ratio_hess_diag ()
void regression_inverse_mean_ratio_grad ()
void regression_inverse_mean_ratio_hess ()

Private Member Functions

 CPPUNIT_TEST_SUITE (TQualityMetricTest)
REGISTER_TMP_TESTS CPPUNIT_TEST (test_inverse_mean_ratio_grad)
 CPPUNIT_TEST (test_inverse_mean_ratio_hess)
 CPPUNIT_TEST (test_inverse_mean_ratio_hess_diag)
 CPPUNIT_TEST (regression_inverse_mean_ratio_grad)
 CPPUNIT_TEST (regression_inverse_mean_ratio_hess)
 CPPUNIT_TEST_SUITE_END ()

Detailed Description

Definition at line 47 of file TQualityMetricTest.cpp.


Member Function Documentation

Definition at line 106 of file TQualityMetricTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::PatchData::attach_settings(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_VECTORS_EQUAL, MBMesquite::TQualityMetric::evaluate_with_gradient(), MBMesquite::IdealWeightInverseMeanRatio::evaluate_with_gradient(), MBMesquite::PatchData::fill(), MBMesquite::ElementQM::get_evaluations(), MBMesquite::TMPQualityMetric::get_evaluations(), MBMesquite::PatchData::set_domain(), TMPQualityMetricTest< TQualityMetric >::settings, and MBMesquite::TRIANGLE.

{
    MsqError err;
    TInverseMeanRatio tm;
    IdealShapeTarget target;
    TQualityMetric metric( &target, &tm );
    const double coords[]  = { -0.80000000000000004, -0.80000000000000004, 0,
                              0.00000000000000000,  2.00000000000000000,  0,
                              -1.73205079999999990, 1.00000000000000000,  0 };
    const size_t indices[] = { 0, 1, 2 };
    PatchData pd;
    pd.fill( 3, coords, 1, TRIANGLE, indices, 0, err );
    pd.attach_settings( &settings );
    PlanarDomain dom( PlanarDomain::XY, coords[0] );
    pd.set_domain( &dom );

    IdealWeightInverseMeanRatio ref_metric;

    double exp_val, act_val;
    std::vector< size_t > exp_idx, act_idx, handles;
    std::vector< Vector3D > exp_grad, act_grad;

    handles.clear();
    ref_metric.get_evaluations( pd, handles, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, handles.size() );
    const size_t hand1 = handles.front();
    handles.clear();
    metric.get_evaluations( pd, handles, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, handles.size() );
    const size_t hand2 = handles.front();

    bool exp_rval, act_rval;
    exp_rval = ref_metric.evaluate_with_gradient( pd, hand1, exp_val, exp_idx, exp_grad, err );
    ASSERT_NO_ERROR( err );
    act_rval = metric.evaluate_with_gradient( pd, hand2, act_val, act_idx, act_grad, err );
    ASSERT_NO_ERROR( err );

    CPPUNIT_ASSERT( exp_rval );
    CPPUNIT_ASSERT( act_rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_val - 1.0, act_val, 1e-5 );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, exp_idx.size() );
    CPPUNIT_ASSERT_EQUAL( (size_t)3, act_idx.size() );

    std::vector< size_t > sorted( exp_idx );
    std::sort( sorted.begin(), sorted.end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, sorted[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, sorted[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, sorted[2] );

    sorted = act_idx;
    std::sort( sorted.begin(), sorted.end() );
    CPPUNIT_ASSERT_EQUAL( (size_t)0, sorted[0] );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, sorted[1] );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, sorted[2] );

    const size_t idx_map[] = { std::find( act_idx.begin(), act_idx.end(), exp_idx[0] ) - act_idx.begin(),
                               std::find( act_idx.begin(), act_idx.end(), exp_idx[1] ) - act_idx.begin(),
                               std::find( act_idx.begin(), act_idx.end(), exp_idx[2] ) - act_idx.begin() };
    CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[0], act_grad[idx_map[0]], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[1], act_grad[idx_map[1]], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[2], act_grad[idx_map[2]], 1e-5 );
}

Definition at line 171 of file TQualityMetricTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::PatchData::attach_settings(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_MATRICES_EQUAL, CPPUNIT_ASSERT_VECTORS_EQUAL, MBMesquite::TQualityMetric::evaluate_with_Hessian(), MBMesquite::IdealWeightInverseMeanRatio::evaluate_with_Hessian(), MBMesquite::PatchData::fill(), fixed, MBMesquite::ElementQM::get_evaluations(), MBMesquite::TMPQualityMetric::get_evaluations(), MBMesquite::PatchData::set_domain(), TMPQualityMetricTest< TQualityMetric >::settings, MBMesquite::transpose(), and MBMesquite::TRIANGLE.

{
    MsqError err;
    TInverseMeanRatio tm;
    IdealShapeTarget target;
    TQualityMetric metric( &target, &tm );
    const double coords[] = { 4.158984727, 4.6570859130000004, 5, 4.51742825, 4.51742825, 5, 4.3103448279999999, 5, 5 };
    const bool fixed[]    = { false, false, true };
    const size_t indices[] = { 0, 1, 2 };
    PatchData pd;
    pd.fill( 3, coords, 1, TRIANGLE, indices, fixed, err );
    pd.attach_settings( &settings );
    PlanarDomain dom( PlanarDomain::XY, coords[2] );
    pd.set_domain( &dom );

    IdealWeightInverseMeanRatio ref_metric;

    double exp_val, act_val;
    std::vector< size_t > exp_idx, act_idx, handles;
    std::vector< Vector3D > exp_grad, act_grad;
    std::vector< Matrix3D > exp_hess, act_hess;

    handles.clear();
    ref_metric.get_evaluations( pd, handles, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, handles.size() );
    const size_t hand1 = handles.front();
    handles.clear();
    metric.get_evaluations( pd, handles, false, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, handles.size() );
    const size_t hand2 = handles.front();

    // first make sure that non-TMP IMR metric works correctly
    bool exp_rval, act_rval;
    exp_rval = ref_metric.evaluate_with_Hessian( pd, hand1, exp_val, exp_idx, exp_grad, exp_hess, err );
    ASSERT_NO_ERROR( err );
    act_rval = ref_metric.QualityMetric::evaluate_with_Hessian( pd, hand1, act_val, act_idx, act_grad, act_hess, err );
    CPPUNIT_ASSERT( exp_rval );
    CPPUNIT_ASSERT( act_rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_val, act_val, 1e-5 );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, exp_idx.size() );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, act_idx.size() );

    if( act_idx[0] == exp_idx[0] )
    {
        CPPUNIT_ASSERT_EQUAL( exp_idx[1], act_idx[1] );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[0], act_grad[0], 1e-5 );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[1], act_grad[1], 1e-5 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[0], act_hess[0], 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[1], act_hess[1], 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[2], act_hess[2], 5e-3 );
    }
    else
    {
        CPPUNIT_ASSERT_EQUAL( exp_idx[0], act_idx[1] );
        CPPUNIT_ASSERT_EQUAL( exp_idx[1], act_idx[0] );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[0], act_grad[1], 1e-5 );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[1], act_grad[0], 1e-5 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[0], act_hess[2], 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[1], transpose( act_hess[1] ), 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[2], act_hess[0], 5e-3 );
    }

    // now compare TMP metric with non-TMP metric
    act_rval = metric.evaluate_with_Hessian( pd, hand2, act_val, act_idx, act_grad, act_hess, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( act_rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_val - 1.0, act_val, 1e-5 );
    CPPUNIT_ASSERT_EQUAL( (size_t)2, act_idx.size() );

#ifdef PLANAR_HESSIAN
    // zero derivatives with respect to Z
    for( int i = 0; i < 2; ++i )
        exp_grad[i][2] = 0.0;
    for( int i = 0; i < 3; ++i )
    {
        for( int j = 0; j < 3; ++j )
            exp_hess[i][j][2] = exp_hess[i][2][j] = 0.0;
    }
#else
    // don't compare double out-of-plane term because metrics
    // make varying assumptions about behavior of Hessian
    for( int i = 0; i < 3; ++i )
        exp_hess[i][2][2] = act_hess[i][2][2] = 0.0;
#endif

    if( act_idx[0] == exp_idx[0] )
    {
        CPPUNIT_ASSERT_EQUAL( exp_idx[1], act_idx[1] );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[0], act_grad[0], 1e-5 );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[1], act_grad[1], 1e-5 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[0], act_hess[0], 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[1], act_hess[1], 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[2], act_hess[2], 5e-3 );
    }
    else
    {
        CPPUNIT_ASSERT_EQUAL( exp_idx[0], act_idx[1] );
        CPPUNIT_ASSERT_EQUAL( exp_idx[1], act_idx[0] );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[0], act_grad[1], 1e-5 );
        CPPUNIT_ASSERT_VECTORS_EQUAL( exp_grad[1], act_grad[0], 1e-5 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[0], act_hess[2], 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[1], transpose( act_hess[1] ), 5e-3 );
        CPPUNIT_ASSERT_MATRICES_EQUAL( exp_hess[2], act_hess[0], 5e-3 );
    }
}

List of all members.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines