MOAB: Mesh Oriented datABase  (version 5.4.1)
TMPQualityMetricTest< QMType > Class Template Reference

#include <TMPQualityMetricTest.hpp>

+ Inheritance diagram for TMPQualityMetricTest< QMType >:
+ Collaboration diagram for TMPQualityMetricTest< QMType >:

Public Member Functions

 TMPQualityMetricTest ()
void test_negate_flag ()
void test_supported_types ()
void test_get_evaluations ()
void test_get_element_evaluations ()
void test_evaluate_2D ()
void test_evaluate_surface ()
void test_evaluate_3D ()
void test_evaluate_2D_weight ()
void test_evaluate_surface_weight ()
void test_evaluate_3D_weight ()
void test_2d_eval_ortho_quad ()
void test_surf_eval_ortho_quad ()
void test_3d_eval_ortho_hex ()
void test_gradient_common (TargetCalculator *tc)
void test_gradient_2D ()
void test_gradient_surface ()
void test_gradient_3D ()
void test_sample_indices ()
void test_evaluate_with_indices ()
void test_evaluate_fixed_indices ()
void compare_indices_and_gradient ()
void test_ideal_element_gradient ()
void compare_analytical_and_numerical_gradient ()
void test_weighted_gradients ()
void test_gradient_with_fixed_vertices ()
void compare_indices_and_hessian ()
void compare_gradient_and_hessian ()
void compare_analytical_and_numerical_hessians ()
void test_symmetric_hessian_diagonal ()
void test_weighted_hessians ()
void test_hessian_with_fixed_vertices ()
void compare_indices_and_diagonal ()
void compare_gradient_and_diagonal ()
void compare_analytical_and_numerical_diagonals ()
void test_weighted_diagonals ()
void test_diagonal_with_fixed_vertices ()
void get_nonideal_element (EntityTopology type, PatchData &pd)
void compare_analytical_and_numerical_gradients (QualityMetric *qm)
void compare_analytical_and_numerical_hessians (QualityMetric *qm)
void compare_analytical_and_numerical_diagonals (QualityMetric *qm)
void compare_analytical_and_numerical_gradients (QualityMetric *qm, PatchData &, int dim)

Protected Attributes

QualityMetricTester tester
Settings settings
IdealShapeTarget ideal
IdealShapeXY surf_target
ScaleWeight e_weight
FauxMetric< typename TMPTypes
< QMType >::MetricType
faux_pi
FauxMetric< typename TMPTypes
< QMType >::MetricType
faux_zero
FauxMetric< typename TMPTypes
< QMType >::MetricType
faux_two
TMPTypes< QMType >::TestType test_metric
NumericalMetric< typename
QMType::MetricType > 
num_metric
QMType test_qm
QMType test_qm_surf
QMType zero_qm
QMType weight_qm
QMType center_qm
Settings centerOnly
CenterMF2D triCenter
CenterMF2D quadCenter
CenterMF3D tetCenter
CenterMF3D pyrCenter
CenterMF3D priCenter
CenterMF3D hexCenter

Detailed Description

template<class QMType>
class TMPQualityMetricTest< QMType >

Definition at line 365 of file TMPQualityMetricTest.hpp.


Constructor & Destructor Documentation


Member Function Documentation

template<class QMType >
void TMPQualityMetricTest< QMType >::compare_analytical_and_numerical_diagonals ( QualityMetric qm) [inline]

Definition at line 1098 of file TMPQualityMetricTest.hpp.

References CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_MATRICES_EQUAL, MBMesquite::QualityMetric::evaluate_with_Hessian_diagonal(), MBMesquite::QualityMetric::get_evaluations(), MBMesquite::HEXAHEDRON, MSQ_CHKERR, MBMesquite::PRISM, MBMesquite::PYRAMID, MBMesquite::QUADRILATERAL, MBMesquite::TETRAHEDRON, and MBMesquite::TRIANGLE.

{
    MsqPrintError err( std::cout );
    PatchData pd;
    const EntityTopology types[] = { TRIANGLE, QUADRILATERAL, TETRAHEDRON, PYRAMID, PRISM, HEXAHEDRON };
    const int num_types          = sizeof( types ) / sizeof( types[0] );
    for( int i = 0; i < num_types; ++i )
    {
        get_nonideal_element( types[i], pd );

        std::vector< size_t > handles, indices1, indices2;
        std::vector< Vector3D > grad1, grad2;
        std::vector< Matrix3D > Hess1;
        std::vector< SymMatrix3D > Hess2;
        double qm_val1, qm_val2;
        bool rval;

        qm->get_evaluations( pd, handles, false, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( !handles.empty() );
        for( size_t j = 0; j < handles.size(); ++j )
        {
            rval = qm->QualityMetric::evaluate_with_Hessian( pd, handles[j], qm_val1, indices1, grad1, Hess1, err );
            CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
            CPPUNIT_ASSERT( rval );

            // For analytical gradient of a 2D element in the XY plane,
            // we expect all Z terms to be zero.
#ifdef PLANAR_HESSIAN
            if( TopologyInfo::dimension( types[i] ) == 2 )
                for( size_t k = 0; k < Hess1.size(); ++k )
                    Hess1[k]( 0, 2 ) = Hess1[k]( 1, 2 ) = Hess1[k]( 2, 0 ) = Hess1[k]( 2, 1 ) = Hess1[k]( 2, 2 ) = 0.0;
#endif

            rval = qm->evaluate_with_Hessian_diagonal( pd, handles[j], qm_val2, indices2, grad2, Hess2, err );
            CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
            CPPUNIT_ASSERT( rval );

            CPPUNIT_ASSERT_DOUBLES_EQUAL( qm_val1, qm_val2, 1e-6 );
            CPPUNIT_ASSERT_EQUAL( indices1.size(), indices2.size() );
            CPPUNIT_ASSERT( !indices1.empty() );
            CPPUNIT_ASSERT_EQUAL( indices1.size() * ( indices1.size() + 1 ) / 2, Hess1.size() );
            CPPUNIT_ASSERT_EQUAL( indices2.size(), Hess2.size() );

            size_t h = 0;
            std::vector< size_t >::iterator it;
            for( unsigned r = 0; r < indices1.size(); ++r )
            {
                it = std::find( indices2.begin(), indices2.end(), indices1[r] );
                CPPUNIT_ASSERT( it != indices2.end() );
                unsigned r2 = it - indices2.begin();
                // if (!utest_mat_equal(Hess1[h],Hess2[r2],0.001))
                //  assert(false);
                CPPUNIT_ASSERT_MATRICES_EQUAL( Hess1[h], Hess2[r2], 0.05 );
                h += indices1.size() - r;
            }
        }
    }
}
template<class QMType>
void TMPQualityMetricTest< QMType >::compare_analytical_and_numerical_gradients ( QualityMetric qm) [inline]

Definition at line 659 of file TMPQualityMetricTest.hpp.

    {
        PatchData pd;
        const EntityTopology types[] = { TRIANGLE, QUADRILATERAL, TETRAHEDRON, PYRAMID, PRISM, HEXAHEDRON };
        const int num_types          = sizeof( types ) / sizeof( types[0] );
        for( int i = 0; i < num_types; ++i )
        {
            get_nonideal_element( types[i], pd );
            compare_analytical_and_numerical_gradients( qm, pd, TopologyInfo::dimension( types[i] ) );
        }
    }
template<class QMType >
void TMPQualityMetricTest< QMType >::compare_analytical_and_numerical_gradients ( QualityMetric qm,
PatchData pd,
int  dim 
) [inline]

Definition at line 965 of file TMPQualityMetricTest.hpp.

References CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_VECTORS_EQUAL, MBMesquite::QualityMetric::evaluate_with_gradient(), MBMesquite::QualityMetric::get_evaluations(), and MSQ_CHKERR.

{
    MsqPrintError err( std::cout );

    std::vector< size_t > handles, indices1, indices2;
    std::vector< Vector3D > grad1, grad2;
    double qm_val1, qm_val2;
    bool rval;

    qm->get_evaluations( pd, handles, false, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( !handles.empty() );
    for( size_t j = 0; j < handles.size(); ++j )
    {
        rval = qm->QualityMetric::evaluate_with_gradient( pd, handles[j], qm_val1, indices1, grad1, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );

        // For analytical gradient of a 2D element in the XY plane,
        // we expect all Z terms to be zero.
        if( dim == 2 )
            for( size_t k = 0; k < grad1.size(); ++k )
                grad1[k][2] = 0.0;

        rval = qm->evaluate_with_gradient( pd, handles[j], qm_val2, indices2, grad2, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );

        CPPUNIT_ASSERT_DOUBLES_EQUAL( qm_val1, qm_val2, 1e-6 );
        CPPUNIT_ASSERT_EQUAL( indices1.size(), indices2.size() );
        CPPUNIT_ASSERT( !indices1.empty() );

        std::vector< size_t >::iterator it1, it2;
        for( it1 = indices1.begin(); it1 != indices1.end(); ++it1 )
        {
            it2 = std::find( indices2.begin(), indices2.end(), *it1 );
            CPPUNIT_ASSERT( it2 != indices2.end() );

            size_t idx1 = it1 - indices1.begin();
            size_t idx2 = it2 - indices2.begin();
            CPPUNIT_ASSERT_VECTORS_EQUAL( grad1[idx1], grad2[idx2], 0.01 );
        }
    }
}
template<class QMType >
void TMPQualityMetricTest< QMType >::compare_analytical_and_numerical_hessians ( QualityMetric qm) [inline]

Definition at line 1020 of file TMPQualityMetricTest.hpp.

References CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, CPPUNIT_ASSERT_MATRICES_EQUAL, MBMesquite::QualityMetric::evaluate_with_Hessian(), MBMesquite::QualityMetric::get_evaluations(), MBMesquite::HEXAHEDRON, MSQ_CHKERR, MBMesquite::PRISM, MBMesquite::PYRAMID, MBMesquite::QUADRILATERAL, MBMesquite::TETRAHEDRON, and MBMesquite::TRIANGLE.

{
    MsqPrintError err( std::cout );
    PatchData pd;
    const EntityTopology types[] = { TRIANGLE, QUADRILATERAL, TETRAHEDRON, PYRAMID, PRISM, HEXAHEDRON };
    const int num_types          = sizeof( types ) / sizeof( types[0] );
    for( int i = 0; i < num_types; ++i )
    {
        get_nonideal_element( types[i], pd );

        std::vector< size_t > handles, indices1, indices2;
        std::vector< Vector3D > grad1, grad2;
        std::vector< Matrix3D > Hess1, Hess2;
        double qm_val1, qm_val2;
        bool rval;

        qm->get_evaluations( pd, handles, false, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( !handles.empty() );
        for( size_t j = 0; j < handles.size(); ++j )
        {
            rval = qm->QualityMetric::evaluate_with_Hessian( pd, handles[j], qm_val1, indices1, grad1, Hess1, err );
            CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
            CPPUNIT_ASSERT( rval );

            // For analytical gradient of a 2D element in the XY plane,
            // we expect all Z terms to be zero.
#ifdef PLANAR_HESSIAN
            if( TopologyInfo::dimension( types[i] ) == 2 )
                for( size_t k = 0; k < Hess1.size(); ++k )
                    Hess1[k]( 0, 2 ) = Hess1[k]( 1, 2 ) = Hess1[k]( 2, 0 ) = Hess1[k]( 2, 1 ) = Hess1[k]( 2, 2 ) = 0.0;
#endif

            rval = qm->evaluate_with_Hessian( pd, handles[j], qm_val2, indices2, grad2, Hess2, err );
            CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
            CPPUNIT_ASSERT( rval );

            CPPUNIT_ASSERT_DOUBLES_EQUAL( qm_val1, qm_val2, 1e-6 );
            CPPUNIT_ASSERT_EQUAL( indices1.size(), indices2.size() );
            CPPUNIT_ASSERT( !indices1.empty() );

            std::vector< size_t >::iterator it;
            unsigned h = 0;
            for( unsigned r = 0; r < indices1.size(); ++r )
            {
                it = std::find( indices2.begin(), indices2.end(), indices1[r] );
                CPPUNIT_ASSERT( it != indices2.end() );
                unsigned r2 = it - indices2.begin();

                for( unsigned c = r; c < indices1.size(); ++c, ++h )
                {
                    it = std::find( indices2.begin(), indices2.end(), indices1[c] );
                    CPPUNIT_ASSERT( it != indices2.end() );
                    unsigned c2 = it - indices2.begin();

                    unsigned h2;
                    if( r2 <= c2 )
                        h2 = indices2.size() * r - r * ( r + 1 ) / 2 + c;
                    else
                        h2 = indices2.size() * c - c * ( c + 1 ) / 2 + r;

                    // if (!utest_mat_equal(Hess1[h],Hess2[h2],0.001))
                    //  assert(false);
                    CPPUNIT_ASSERT_MATRICES_EQUAL( Hess1[h], Hess2[h2], 0.05 );
                }
            }
        }
    }
}
template<class QMType>
void TMPQualityMetricTest< QMType >::get_nonideal_element ( EntityTopology  type,
PatchData pd 
) [inline]

Definition at line 645 of file TMPQualityMetricTest.hpp.

    {
        tester.get_nonideal_element( type, pd, true );
        // Callers assume surface elements are in XY plane.
        // Verify this assumption.
        if( TopologyInfo::dimension( type ) == 2 )
        {
            for( size_t i = 0; i < pd.num_nodes(); ++i )
            {
                CPPUNIT_ASSERT_DOUBLES_EQUAL( pd.vertex_by_index( i )[2], 0.0, 1e-6 );
            }
        }
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_2d_eval_ortho_quad ( ) [inline]

Definition at line 477 of file TMPQualityMetricTest.hpp.

    {
        MsqPrintError err( cout );
        PatchData pd;
        bool rval;
        double value;

        QMType m( &ideal, &faux_zero );
        faux_zero.count = 0;

        tester.get_ideal_element( QUADRILATERAL, true, pd );
        rval = m.evaluate( pd, 0, value, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );
        CPPUNIT_ASSERT_EQUAL( 1, faux_zero.count );
        CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, col_dot_prod( faux_zero.last_A_2D ), DBL_EPSILON );
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_3d_eval_ortho_hex ( ) [inline]

Definition at line 513 of file TMPQualityMetricTest.hpp.

    {
        MsqPrintError err( cout );
        PatchData pd;
        bool rval;
        double value;

        QMType m( &ideal, &faux_zero );
        faux_zero.count = 0;

        tester.get_ideal_element( HEXAHEDRON, true, pd );
        rval = m.evaluate( pd, 0, value, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );
        CPPUNIT_ASSERT_EQUAL( 1, faux_zero.count );

        // test that columns are orthogonal for ideal hex element
        MsqMatrix< 3, 3 > A = faux_zero.last_A_3D;
        CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, A.column( 0 ) % A.column( 1 ), 1e-6 );
        CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, A.column( 0 ) % A.column( 2 ), 1e-6 );
        CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, A.column( 1 ) % A.column( 2 ), 1e-6 );
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_diagonal_with_fixed_vertices ( ) [inline]
template<class QMType >
void TMPQualityMetricTest< QMType >::test_evaluate_2D ( ) [inline]

Definition at line 680 of file TMPQualityMetricTest.hpp.

References col_dot_prod(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, MSQ_CHKERR, MBMesquite::PatchData::num_nodes(), MBMesquite::QUADRILATERAL, MBMesquite::PatchData::set_vertex_coordinates(), MBMesquite::TRIANGLE, value(), and MBMesquite::PatchData::vertex_by_index().

{
    MsqPrintError err( cout );
    PatchData pd;
    bool rval;
    double value;

    QMType m( &ideal, &faux_pi );

    // test with aligned elements
    faux_pi.count = 0;
    tester.get_ideal_element( QUADRILATERAL, true, pd );
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_pi.count );

    // test that columns are orthogonal for ideal quad element
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, col_dot_prod( faux_pi.last_A_2D ), 1e-6 );

    // test with an element rotated about X-axis
    faux_pi.count = 0;
    tester.get_ideal_element( QUADRILATERAL, true, pd );
    // rotate by 90 degrees about X axis
    for( size_t i = 0; i < pd.num_nodes(); ++i )
    {
        Vector3D orig = pd.vertex_by_index( i );
        Vector3D newp( orig[0], -orig[2], orig[1] );
        pd.set_vertex_coordinates( newp, i, err );
    }
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_pi.count );

    // test with an element rotated about Y-axis
    faux_pi.count = 0;
    tester.get_ideal_element( TRIANGLE, true, pd );
    // rotate by -90 degrees about Y axis
    for( size_t i = 0; i < pd.num_nodes(); ++i )
    {
        Vector3D orig = pd.vertex_by_index( i );
        Vector3D newp( orig[2], orig[1], -orig[0] );
        pd.set_vertex_coordinates( newp, i, err );
    }
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_pi.count );
}
template<class QMType>
void TMPQualityMetricTest< QMType >::test_evaluate_2D_weight ( ) [inline]

Definition at line 430 of file TMPQualityMetricTest.hpp.

    {
        MsqPrintError err( cout );
        PatchData pd;
        bool rval;
        double value;

        QMType m( &ideal, &e_weight, &faux_pi );
        tester.get_ideal_element( TRIANGLE, true, pd );
        rval = m.evaluate( pd, 0, value, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );
        CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value * e_weight.value, value, DBL_EPSILON );
    }
template<class QMType >
void TMPQualityMetricTest< QMType >::test_evaluate_3D ( ) [inline]

Definition at line 790 of file TMPQualityMetricTest.hpp.

References MBMesquite::MsqMatrix< R, C >::column(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, MBMesquite::HEXAHEDRON, MSQ_CHKERR, MBMesquite::PatchData::num_nodes(), MBMesquite::PatchData::set_vertex_coordinates(), MBMesquite::TETRAHEDRON, value(), and MBMesquite::PatchData::vertex_by_index().

{
    MsqPrintError err( cout );
    PatchData pd;
    bool rval;
    double value;

    QMType m( &ideal, &faux_two );

    // test with aligned elements
    faux_two.count = 0;
    tester.get_ideal_element( HEXAHEDRON, true, pd );
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_two.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_two.count );

    // test that columns are orthogonal for ideal hex element
    MsqMatrix< 3, 3 > A = faux_two.last_A_3D;
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, A.column( 0 ) % A.column( 1 ), 1e-6 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, A.column( 0 ) % A.column( 2 ), 1e-6 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, A.column( 1 ) % A.column( 2 ), 1e-6 );

    // test with rotated element
    faux_two.count = 0;
    tester.get_ideal_element( TETRAHEDRON, true, pd );
    // rotate by 90-degrees about X axis
    for( size_t i = 0; i < pd.num_nodes(); ++i )
    {
        Vector3D orig = pd.vertex_by_index( i );
        Vector3D newp( orig[0], -orig[2], orig[1] );
        pd.set_vertex_coordinates( newp, i, err );
    }
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_two.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_two.count );
}
template<class QMType>
void TMPQualityMetricTest< QMType >::test_evaluate_3D_weight ( ) [inline]

Definition at line 461 of file TMPQualityMetricTest.hpp.

    {
        MsqPrintError err( cout );
        PatchData pd;
        bool rval;
        double value;

        QMType m( &ideal, &e_weight, &faux_two );

        tester.get_ideal_element( PRISM, true, pd );
        rval = m.evaluate( pd, 0, value, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );
        CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_two.value * e_weight.value, value, DBL_EPSILON );
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_evaluate_fixed_indices ( ) [inline]

Definition at line 555 of file TMPQualityMetricTest.hpp.

template<class QMType >
void TMPQualityMetricTest< QMType >::test_evaluate_surface ( ) [inline]

Definition at line 735 of file TMPQualityMetricTest.hpp.

References col_dot_prod(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, MSQ_CHKERR, MBMesquite::PatchData::num_nodes(), MBMesquite::QUADRILATERAL, MBMesquite::PatchData::set_vertex_coordinates(), MBMesquite::TRIANGLE, value(), and MBMesquite::PatchData::vertex_by_index().

{
    MsqPrintError err( cout );
    PatchData pd;
    bool rval;
    double value;

    QMType m( &surf_target, &faux_pi );

    // test with aligned elements
    faux_pi.count = 0;
    tester.get_ideal_element( QUADRILATERAL, true, pd );
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_pi.count );

    // test that columns are orthogonal for ideal quad element
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, col_dot_prod( faux_pi.last_A_2D ), 1e-6 );

    // test with an element rotated about X-axis
    faux_pi.count = 0;
    tester.get_ideal_element( QUADRILATERAL, true, pd );
    // rotate by 90 degrees about X axis
    for( size_t i = 0; i < pd.num_nodes(); ++i )
    {
        Vector3D orig = pd.vertex_by_index( i );
        Vector3D newp( orig[0], -orig[2], orig[1] );
        pd.set_vertex_coordinates( newp, i, err );
    }
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_pi.count );

    // test with an element rotated about Y-axis
    faux_pi.count = 0;
    tester.get_ideal_element( TRIANGLE, true, pd );
    // rotate by -90 degrees about Y axis
    for( size_t i = 0; i < pd.num_nodes(); ++i )
    {
        Vector3D orig = pd.vertex_by_index( i );
        Vector3D newp( orig[2], orig[1], -orig[0] );
        pd.set_vertex_coordinates( newp, i, err );
    }
    rval = m.evaluate( pd, 0, value, err );
    CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
    CPPUNIT_ASSERT( rval );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value, value, DBL_EPSILON );
    CPPUNIT_ASSERT_EQUAL( 1, faux_pi.count );
}
template<class QMType>
void TMPQualityMetricTest< QMType >::test_evaluate_surface_weight ( ) [inline]

Definition at line 445 of file TMPQualityMetricTest.hpp.

    {
        MsqPrintError err( cout );
        PatchData pd;
        bool rval;
        double value;

        QMType m( &surf_target, &e_weight, &faux_pi );

        tester.get_ideal_element( TRIANGLE, true, pd );
        rval = m.evaluate( pd, 0, value, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );
        CPPUNIT_ASSERT_DOUBLES_EQUAL( faux_pi.value * e_weight.value, value, DBL_EPSILON );
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_evaluate_with_indices ( ) [inline]
template<class QMType>
void TMPQualityMetricTest< QMType >::test_get_element_evaluations ( ) [inline]

Definition at line 419 of file TMPQualityMetricTest.hpp.

template<class QMType>
void TMPQualityMetricTest< QMType >::test_get_evaluations ( ) [inline]

Definition at line 413 of file TMPQualityMetricTest.hpp.

    {
        QMType edge_metric( &ideal, &faux_zero );
        tester.test_get_sample_evaluations( &zero_qm );
        tester.test_get_sample_evaluations( &edge_metric );
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_gradient_2D ( ) [inline]

Definition at line 537 of file TMPQualityMetricTest.hpp.

template<class QMType >
void TMPQualityMetricTest< QMType >::test_gradient_3D ( ) [inline]

Definition at line 894 of file TMPQualityMetricTest.hpp.

References ASSERT_NO_ERROR, MBMesquite::PatchData::attach_settings(), conn, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_VECTORS_EQUAL, MBMesquite::PatchData::fill(), MBMesquite::ElemSampleQM::handle(), MBMesquite::HEXAHEDRON, MBMesquite::MsqMatrix< R, C >::row(), settings, MBMesquite::sqr_Frobenius(), MBMesquite::transpose(), and z.

{
    MsqPrintError err( std::cout );

    // check for expected value at center of flattened hex

    // construct flattened hex
    const double z          = 0.5;
    const double vertices[] = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0,
                                0.0, 0.0, z,   1.0, 0.0, z,   1.0, 1.0, z,   0.0, 1.0, z };
    size_t conn[8]          = { 0, 1, 2, 3, 4, 5, 6, 7 };
    PatchData pd;
    pd.fill( 8, vertices, 1, HEXAHEDRON, conn, 0, err );
    ASSERT_NO_ERROR( err );

    // calculate Jacobian matrix at element center

    // derivatives of trilinear map at hex center
    const double deriv_vals[8][3] = { { -0.25, -0.25, -0.25 }, { 0.25, -0.25, -0.25 }, { 0.25, 0.25, -0.25 },
                                      { -0.25, 0.25, -0.25 },  { -0.25, -0.25, 0.25 }, { 0.25, -0.25, 0.25 },
                                      { 0.25, 0.25, 0.25 },    { -0.25, 0.25, 0.25 } };
    MsqMatrix< 8, 3 > coeff_derivs( deriv_vals );
    MsqMatrix< 8, 3 > coords( vertices );
    MsqMatrix< 3, 3 > J = transpose( coords ) * coeff_derivs;
    // calculate expected metric value
    const double expt_val = sqr_Frobenius( J );
    // calculate derivative for each element vertex
    MsqVector< 3 > expt_grad[8];
    for( int v = 0; v < 8; ++v )
        expt_grad[v] = 2 * J * transpose( coeff_derivs.row( v ) );

    // construct metric
    pd.attach_settings( &settings );
    TestGradTargetMetric< typename TMPTypes< QMType >::MetricType > tm;
    IdealShapeTarget tc;
    QMType m( &tc, 0, &tm );

    // evaluate metric
    double act_val;
    std::vector< size_t > indices;
    std::vector< Vector3D > act_grad;
    size_t h = ElemSampleQM::handle( Sample( 3, 0 ), 0 );
    m.evaluate_with_gradient( pd, h, act_val, indices, act_grad, err );
    ASSERT_NO_ERROR( err );

    // compare values
    CPPUNIT_ASSERT_DOUBLES_EQUAL( expt_val, act_val, 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[0]].data() ), act_grad[0], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[1]].data() ), act_grad[1], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[2]].data() ), act_grad[2], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[3]].data() ), act_grad[3], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[4]].data() ), act_grad[4], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[5]].data() ), act_grad[5], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[6]].data() ), act_grad[6], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[7]].data() ), act_grad[7], 1e-10 );

    // check numerical approx of gradient
    m.QualityMetric::evaluate_with_gradient( pd, h, act_val, indices, act_grad, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( expt_val, act_val, 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[0]].data() ), act_grad[0], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[1]].data() ), act_grad[1], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[2]].data() ), act_grad[2], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[3]].data() ), act_grad[3], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[4]].data() ), act_grad[4], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[5]].data() ), act_grad[5], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[6]].data() ), act_grad[6], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[7]].data() ), act_grad[7], 1e-5 );
}
template<class QMType >
void TMPQualityMetricTest< QMType >::test_gradient_common ( TargetCalculator tc) [inline]

Definition at line 832 of file TMPQualityMetricTest.hpp.

References ASSERT_NO_ERROR, MBMesquite::PatchData::attach_settings(), conn, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_VECTORS_EQUAL, MBMesquite::PatchData::fill(), MBMesquite::ElemSampleQM::handle(), MBMesquite::QUADRILATERAL, MBMesquite::MsqMatrix< R, C >::row(), MBMesquite::PatchData::set_domain(), settings, MBMesquite::sqr_Frobenius(), MBMesquite::transpose(), and MBMesquite::PlanarDomain::XY.

{
    MsqPrintError err( std::cout );

    // check for expected value at center of flattened hex

    // construct flattened hex
    const double y          = 0.5;
    const double vertices[] = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, y, 0.0, 0.0, y, 0.0 };
    size_t conn[8]          = { 0, 1, 2, 3 };
    PatchData pd;
    pd.fill( 4, vertices, 1, QUADRILATERAL, conn, 0, err );
    ASSERT_NO_ERROR( err );

    // calculate Jacobian matrix at element center

    // derivatives of bilinear map at quad center
    const double deriv_vals[] = { -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5 };
    MsqMatrix< 4, 2 > coeff_derivs( deriv_vals );
    MsqMatrix< 4, 3 > coords( vertices );
    MsqMatrix< 3, 2 > J = transpose( coords ) * coeff_derivs;
    // calculate expected metric value
    const double expt_val = sqr_Frobenius( J );
    // calculate derivative for each element vertex
    MsqVector< 3 > expt_grad[4];
    for( int v = 0; v < 4; ++v )
        expt_grad[v] = 2 * J * transpose( coeff_derivs.row( v ) );

    // construct metric
    pd.attach_settings( &settings );
    TestGradTargetMetric< typename TMPTypes< QMType >::MetricType > tm;
    // IdealShapeTarget tc;
    QMType m( tc, &tm );
    PlanarDomain plane( PlanarDomain::XY );
    pd.set_domain( &plane );

    // evaluate metric
    double act_val;
    std::vector< size_t > indices;
    std::vector< Vector3D > act_grad;
    size_t h = ElemSampleQM::handle( Sample( 2, 0 ), 0 );
    m.evaluate_with_gradient( pd, h, act_val, indices, act_grad, err );
    ASSERT_NO_ERROR( err );

    // compare values
    CPPUNIT_ASSERT_DOUBLES_EQUAL( expt_val, act_val, 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[0]].data() ), act_grad[0], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[1]].data() ), act_grad[1], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[2]].data() ), act_grad[2], 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[3]].data() ), act_grad[3], 1e-10 );

    // check numerical approx of gradient
    m.QualityMetric::evaluate_with_gradient( pd, h, act_val, indices, act_grad, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( expt_val, act_val, 1e-10 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[0]].data() ), act_grad[0], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[1]].data() ), act_grad[1], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[2]].data() ), act_grad[2], 1e-5 );
    CPPUNIT_ASSERT_VECTORS_EQUAL( Vector3D( expt_grad[indices[3]].data() ), act_grad[3], 1e-5 );
}
template<class QMType>
void TMPQualityMetricTest< QMType >::test_gradient_surface ( ) [inline]

Definition at line 541 of file TMPQualityMetricTest.hpp.

template<class QMType>
void TMPQualityMetricTest< QMType >::test_gradient_with_fixed_vertices ( ) [inline]
template<class QMType>
void TMPQualityMetricTest< QMType >::test_hessian_with_fixed_vertices ( ) [inline]
template<class QMType>
void TMPQualityMetricTest< QMType >::test_ideal_element_gradient ( ) [inline]
template<class QMType>
void TMPQualityMetricTest< QMType >::test_negate_flag ( ) [inline]

Definition at line 405 of file TMPQualityMetricTest.hpp.

    {
        CPPUNIT_ASSERT_EQUAL( 1, zero_qm.get_negate_flag() );
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_sample_indices ( ) [inline]

Definition at line 547 of file TMPQualityMetricTest.hpp.

template<class QMType>
void TMPQualityMetricTest< QMType >::test_supported_types ( ) [inline]
template<class QMType>
void TMPQualityMetricTest< QMType >::test_surf_eval_ortho_quad ( ) [inline]

Definition at line 495 of file TMPQualityMetricTest.hpp.

    {
        MsqPrintError err( cout );
        PatchData pd;
        bool rval;
        double value;

        QMType m( &surf_target, &faux_zero );
        faux_zero.count = 0;

        tester.get_ideal_element( QUADRILATERAL, true, pd );
        rval = m.evaluate( pd, 0, value, err );
        CPPUNIT_ASSERT( !MSQ_CHKERR( err ) );
        CPPUNIT_ASSERT( rval );
        CPPUNIT_ASSERT_EQUAL( 1, faux_zero.count );
        CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, col_dot_prod( faux_zero.last_A_2D ), DBL_EPSILON );
    }
template<class QMType>
void TMPQualityMetricTest< QMType >::test_weighted_diagonals ( ) [inline]
template<class QMType>
void TMPQualityMetricTest< QMType >::test_weighted_gradients ( ) [inline]
template<class QMType>
void TMPQualityMetricTest< QMType >::test_weighted_hessians ( ) [inline]

Member Data Documentation

template<class QMType>
QMType TMPQualityMetricTest< QMType >::center_qm [protected]

Definition at line 378 of file TMPQualityMetricTest.hpp.

template<class QMType>
Settings TMPQualityMetricTest< QMType >::centerOnly [protected]

Definition at line 379 of file TMPQualityMetricTest.hpp.

template<class QMType>
ScaleWeight TMPQualityMetricTest< QMType >::e_weight [protected]

Definition at line 373 of file TMPQualityMetricTest.hpp.

template<class QMType>
FauxMetric< typename TMPTypes< QMType >::MetricType > TMPQualityMetricTest< QMType >::faux_pi [protected]

Definition at line 375 of file TMPQualityMetricTest.hpp.

template<class QMType>
FauxMetric< typename TMPTypes< QMType >::MetricType > TMPQualityMetricTest< QMType >::faux_two [protected]

Definition at line 375 of file TMPQualityMetricTest.hpp.

template<class QMType>
FauxMetric< typename TMPTypes< QMType >::MetricType > TMPQualityMetricTest< QMType >::faux_zero [protected]

Definition at line 375 of file TMPQualityMetricTest.hpp.

template<class QMType>
CenterMF3D TMPQualityMetricTest< QMType >::hexCenter [protected]

Definition at line 381 of file TMPQualityMetricTest.hpp.

template<class QMType>
IdealShapeTarget TMPQualityMetricTest< QMType >::ideal [protected]

Definition at line 371 of file TMPQualityMetricTest.hpp.

template<class QMType>
NumericalMetric< typename QMType::MetricType > TMPQualityMetricTest< QMType >::num_metric [protected]

Definition at line 377 of file TMPQualityMetricTest.hpp.

template<class QMType>
CenterMF3D TMPQualityMetricTest< QMType >::priCenter [protected]

Definition at line 381 of file TMPQualityMetricTest.hpp.

template<class QMType>
CenterMF3D TMPQualityMetricTest< QMType >::pyrCenter [protected]

Definition at line 381 of file TMPQualityMetricTest.hpp.

template<class QMType>
CenterMF2D TMPQualityMetricTest< QMType >::quadCenter [protected]

Definition at line 380 of file TMPQualityMetricTest.hpp.

template<class QMType>
Settings TMPQualityMetricTest< QMType >::settings [protected]

Definition at line 370 of file TMPQualityMetricTest.hpp.

template<class QMType>
IdealShapeXY TMPQualityMetricTest< QMType >::surf_target [protected]

Definition at line 372 of file TMPQualityMetricTest.hpp.

template<class QMType>
TMPTypes< QMType >::TestType TMPQualityMetricTest< QMType >::test_metric [protected]

Definition at line 376 of file TMPQualityMetricTest.hpp.

template<class QMType>
QMType TMPQualityMetricTest< QMType >::test_qm [protected]

Definition at line 378 of file TMPQualityMetricTest.hpp.

template<class QMType>
QMType TMPQualityMetricTest< QMType >::test_qm_surf [protected]

Definition at line 378 of file TMPQualityMetricTest.hpp.

template<class QMType>
QualityMetricTester TMPQualityMetricTest< QMType >::tester [protected]

Definition at line 368 of file TMPQualityMetricTest.hpp.

template<class QMType>
CenterMF3D TMPQualityMetricTest< QMType >::tetCenter [protected]

Definition at line 381 of file TMPQualityMetricTest.hpp.

template<class QMType>
CenterMF2D TMPQualityMetricTest< QMType >::triCenter [protected]

Definition at line 380 of file TMPQualityMetricTest.hpp.

template<class QMType>
QMType TMPQualityMetricTest< QMType >::weight_qm [protected]

Definition at line 378 of file TMPQualityMetricTest.hpp.

template<class QMType>
QMType TMPQualityMetricTest< QMType >::zero_qm [protected]

Definition at line 378 of file TMPQualityMetricTest.hpp.

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