MOAB: Mesh Oriented datABase  (version 5.2.1)
TMetricTest< Metric, DIM > Class Template Reference

Common tests for all target metric types. More...

#include <TargetMetricTest.hpp>

+ Inheritance diagram for TMetricTest< Metric, DIM >:
+ Collaboration diagram for TMetricTest< Metric, DIM >:

Public Types

typedef MsqMatrix< DIM, DIM > Matrix

Public Member Functions

 TMetricTest (bool shape_invariant, bool size_invariant, bool orient_invariant, bool barrier, double ideal_val)
void test_ideal_eval ()
void test_ideal_gradient ()
void test_inverted ()
void test_shape ()
void test_scale ()
void test_orient ()
void compare_anaytic_and_numeric_grads ()
void compare_anaytic_and_numeric_hess ()
void compare_eval_and_eval_with_grad ()
void compare_eval_with_grad_and_eval_with_hess ()
void test_numerical_gradient_2D ()
void test_numerical_hessian_2D ()
void test_numerical_gradient_3D ()
void test_numerical_hessian_3D ()

Public Attributes

const Matrix Zero
const Matrix I
const Matrix A
const Matrix B
const Matrix C

Private Member Functions

void test_non_ideal (bool sensitive, Matrix A, Matrix W)
 Test if metric is or is not sensitive to difference between A and W.
bool eval (TMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqError &err)
bool grad (TMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqError &err)
bool num_grad (TMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqError &err)
bool hess (TMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqMatrix< DIM, DIM > d2mdA2[3], MsqError &err)
bool num_hess (TMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqMatrix< DIM, DIM > d2mdA2[3], MsqError &err)
bool eval (AWMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqError &err)
bool grad (AWMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqError &err)
bool num_grad (AWMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqError &err)
bool hess (AWMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqMatrix< DIM, DIM > d2mdA2[3], MsqError &err)
bool num_hess (AWMetric &metric, MsqMatrix< DIM, DIM > A, MsqMatrix< DIM, DIM > W, double &value, MsqMatrix< DIM, DIM > &dmdA, MsqMatrix< DIM, DIM > d2mdA2[3], MsqError &err)
 CPPUNIT_TEST_SUITE (TMetricTest)
 CPPUNIT_TEST (test_numerical_gradient_2D)
 CPPUNIT_TEST (test_numerical_hessian_2D)
 CPPUNIT_TEST (test_numerical_gradient_3D)
 CPPUNIT_TEST (test_numerical_hessian_3D)
 CPPUNIT_TEST_SUITE_END ()

Private Attributes

Metric testMetric
const double idealVal
const bool shapeInvariant
const bool sizeInvariant
const bool orientInvariant
const bool Barrier

Detailed Description

template<class Metric, unsigned DIM>
class TMetricTest< Metric, DIM >

Common tests for all target metric types.

Commont test framework for implementations of the following types: TMetric , AWMetric

Definition at line 198 of file TargetMetricTest.hpp.


Member Typedef Documentation

template<class Metric , unsigned DIM>
typedef MsqMatrix< DIM, DIM > TMetricTest< Metric, DIM >::Matrix

Definition at line 207 of file TargetMetricTest.hpp.


Constructor & Destructor Documentation

template<class Metric , unsigned DIM>
TMetricTest< Metric, DIM >::TMetricTest ( bool  shape_invariant,
bool  size_invariant,
bool  orient_invariant,
bool  barrier,
double  ideal_val 
) [inline]

Definition at line 209 of file TargetMetricTest.hpp.

        : idealVal( ideal_val ), shapeInvariant( shape_invariant ), sizeInvariant( size_invariant ),
          orientInvariant( orient_invariant ), Barrier( barrier ), Zero( 0.0 ), I( 1.0 ), A( Avals[DIM] ),
          B( Bvals[DIM] ), C( Cvals[DIM] )
    {
    }

Member Function Documentation

template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::compare_anaytic_and_numeric_grads ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::compare_anaytic_and_numeric_hess ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::compare_eval_and_eval_with_grad ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::compare_eval_with_grad_and_eval_with_hess ( )
template<class Metric , unsigned DIM>
TMetricTest< Metric, DIM >::CPPUNIT_TEST ( test_numerical_gradient_2D  ) [private]
template<class Metric , unsigned DIM>
TMetricTest< Metric, DIM >::CPPUNIT_TEST ( test_numerical_hessian_2D  ) [private]
template<class Metric , unsigned DIM>
TMetricTest< Metric, DIM >::CPPUNIT_TEST ( test_numerical_gradient_3D  ) [private]
template<class Metric , unsigned DIM>
TMetricTest< Metric, DIM >::CPPUNIT_TEST ( test_numerical_hessian_3D  ) [private]
template<class Metric , unsigned DIM>
TMetricTest< Metric, DIM >::CPPUNIT_TEST_SUITE ( TMetricTest< Metric, DIM >  ) [private]
template<class Metric , unsigned DIM>
TMetricTest< Metric, DIM >::CPPUNIT_TEST_SUITE_END ( ) [private]
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::eval ( TMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqError err 
) [inline, private]

Definition at line 247 of file TargetMetricTest.hpp.

References MBMesquite::TMetric::evaluate(), and MBMesquite::inverse().

    {
        return metric.evaluate( A * inverse( W ), value, err );
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::eval ( AWMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqError err 
) [inline, private]

Definition at line 285 of file TargetMetricTest.hpp.

References MBMesquite::AWMetric::evaluate().

    {
        bool rval = metric.evaluate( A, W, value, err );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::grad ( TMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqError err 
) [inline, private]

Definition at line 251 of file TargetMetricTest.hpp.

References MBMesquite::TMetric::evaluate_with_grad(), MBMesquite::inverse(), and MBMesquite::transpose().

    {
        bool rval = metric.evaluate_with_grad( A * inverse( W ), value, dmdA, err );
        dmdA      = dmdA * transpose( inverse( W ) );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::grad ( AWMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqError err 
) [inline, private]

Definition at line 290 of file TargetMetricTest.hpp.

References MBMesquite::AWMetric::evaluate_with_grad().

    {
        bool rval = metric.evaluate_with_grad( A, W, value, dmdA, err );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::hess ( TMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqMatrix< DIM, DIM >  d2mdA2[3],
MsqError err 
) [inline, private]

Definition at line 265 of file TargetMetricTest.hpp.

References MBMesquite::TMetric::evaluate_with_hess(), MBMesquite::inverse(), and MBMesquite::transpose().

    {
        bool rval = metric.evaluate_with_hess( A * inverse( W ), value, dmdA, d2mdA2, err );
        dmdA      = dmdA * transpose( inverse( W ) );
        for( unsigned i = 0; i < DIM * ( DIM + 1 ) / 2; ++i )
            d2mdA2[i] = inverse( W ) * d2mdA2[i] * transpose( inverse( W ) );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::hess ( AWMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqMatrix< DIM, DIM >  d2mdA2[3],
MsqError err 
) [inline, private]

Definition at line 302 of file TargetMetricTest.hpp.

References MBMesquite::AWMetric::evaluate_with_hess().

    {
        bool rval = metric.evaluate_with_hess( A, W, value, dmdA, d2mdA2, err );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::num_grad ( TMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqError err 
) [inline, private]

Definition at line 258 of file TargetMetricTest.hpp.

References MBMesquite::TMetric::evaluate_with_grad(), MBMesquite::inverse(), and MBMesquite::transpose().

    {
        bool rval = metric.evaluate_with_grad( A * inverse( W ), value, dmdA, err );
        dmdA      = dmdA * transpose( inverse( W ) );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::num_grad ( AWMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqError err 
) [inline, private]

Definition at line 296 of file TargetMetricTest.hpp.

References MBMesquite::AWMetric::evaluate_with_grad().

    {
        bool rval = metric.evaluate_with_grad( A, W, value, dmdA, err );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::num_hess ( TMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqMatrix< DIM, DIM >  d2mdA2[3],
MsqError err 
) [inline, private]

Definition at line 274 of file TargetMetricTest.hpp.

References MBMesquite::TMetric::evaluate_with_hess(), MBMesquite::inverse(), and MBMesquite::transpose().

    {
        bool rval = metric.evaluate_with_hess( A * inverse( W ), value, dmdA, d2mdA2, err );
        dmdA      = dmdA * transpose( inverse( W ) );
        for( unsigned i = 0; i < DIM * ( DIM + 1 ) / 2; ++i )
            d2mdA2[i] = inverse( W ) * d2mdA2[i] * transpose( inverse( W ) );
        return rval;
    }
template<class Metric , unsigned DIM>
bool TMetricTest< Metric, DIM >::num_hess ( AWMetric metric,
MsqMatrix< DIM, DIM >  A,
MsqMatrix< DIM, DIM >  W,
double &  value,
MsqMatrix< DIM, DIM > &  dmdA,
MsqMatrix< DIM, DIM >  d2mdA2[3],
MsqError err 
) [inline, private]

Definition at line 308 of file TargetMetricTest.hpp.

References MBMesquite::AWMetric::evaluate_with_hess().

    {
        bool rval = metric.evaluate_with_hess( A, W, value, dmdA, d2mdA2, err );
        return rval;
    }
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_ideal_eval ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_ideal_gradient ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_inverted ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_non_ideal ( bool  sensitive,
Matrix  A,
Matrix  W 
) [private]

Test if metric is or is not sensitive to difference between A and W.

Given an active matrix A and a target matrix W, test whether or not the metric is sensitive to the difference. Fail if actual sensitivity to difference is not equal to expected sensitivity passed as the first argument

template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_numerical_gradient_2D ( )

Definition at line 215 of file TMetricTest.cpp.

References ASSERT_MATRICES_EQUAL, ASSERT_NO_ERROR, Avals, Bvals, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, MBMesquite::da(), GradTestMetricRel::evaluate(), MBMesquite::TMetric::evaluate_with_grad(), HessTestMetricRel_2::evaluate_with_grad(), GradTestMetricRel::grad(), and MBMesquite::inverse().

{
    GradTestMetricRel metric;
    HessTestMetricRel_2 metric2;
    const double Avals[] = { 1, 2, 2, 5 };
    const double Bvals[] = { -0.1, -0.15, -0.25, -0.8 };
    const MsqMatrix< 2, 2 > A( Avals );
    const MsqMatrix< 2, 2 > B( Bvals );

    MsqError err;
    MsqMatrix< 2, 2 > d;
    bool valid;
    double val, gval;

    MsqMatrix< 2, 2 > expected;
    for( int r = 0; r < 2; ++r )
        for( int c = 0; c < 2; ++c )
            expected( r, c ) = metric.grad( r, c );

    valid = metric.evaluate( A, val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( A, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( B, val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( B, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( inverse( A ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( inverse( A ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( inverse( B ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( inverse( B ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( A * inverse( B ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( A * inverse( B ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( B * inverse( A ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( B * inverse( A ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    MsqMatrix< 2, 2 > da;
    valid = metric2.evaluate_with_grad( A, val, da, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_grad( A, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( da, d, 1e-6 );

    valid = metric2.evaluate_with_grad( B, val, da, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_grad( B, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( da, d, 1e-6 );
}
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_numerical_gradient_3D ( )

Definition at line 307 of file TMetricTest.cpp.

References ASSERT_MATRICES_EQUAL, ASSERT_NO_ERROR, Avals, Bvals, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, MBMesquite::da(), GradTestMetricRel::evaluate(), MBMesquite::TMetric::evaluate_with_grad(), HessTestMetricRel_2::evaluate_with_grad(), GradTestMetricRel::grad(), and MBMesquite::inverse().

{
    GradTestMetricRel metric;
    HessTestMetricRel_2 metric2;
    const double Avals[] = { 1, 2, 3, 4, 1, 4, 3, 2, 1 };
    const double Bvals[] = { 0.1, 0.15, 0.05, 0.2, -0.1, -0.15, -0.05, -0.2, 2 };
    const MsqMatrix< 3, 3 > A( Avals );
    const MsqMatrix< 3, 3 > B( Bvals );

    MsqError err;
    MsqMatrix< 3, 3 > d;
    bool valid;
    double val, gval;

    MsqMatrix< 3, 3 > expected;
    for( int r = 0; r < 3; ++r )
        for( int c = 0; c < 3; ++c )
            expected( r, c ) = metric.grad( r, c );

    valid = metric.evaluate( A, val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( A, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( B, val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( B, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( inverse( A ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( inverse( A ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( inverse( B ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( inverse( B ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( A * inverse( B ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( A * inverse( B ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    valid = metric.evaluate( B * inverse( A ), val, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_grad( B * inverse( A ), gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( expected, d, 1e-6 );

    MsqMatrix< 3, 3 > da;
    valid = metric2.evaluate_with_grad( A, val, da, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_grad( A, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( da, d, 1e-6 );

    valid = metric2.evaluate_with_grad( B, val, da, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_grad( B, gval, d, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, gval, 1e-6 );
    ASSERT_MATRICES_EQUAL( da, d, 1e-6 );
}
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_numerical_hessian_2D ( )

Definition at line 399 of file TMetricTest.cpp.

References ASSERT_MATRICES_EQUAL, ASSERT_NO_ERROR, Avals, Bvals, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, HessTestMetricRel::evaluate_with_grad(), MBMesquite::TMetric::evaluate_with_hess(), HessTestMetricRel_2::evaluate_with_hess(), and MBMesquite::inverse().

{
    HessTestMetricRel metric;
    HessTestMetricRel_2 metric2;
    const double Avals[] = { 1, 2, 2, 5 };
    const double Bvals[] = { -0.1, -0.15, -0.25, -0.8 };
    const MsqMatrix< 2, 2 > A( Avals );
    const MsqMatrix< 2, 2 > B( Bvals );

    MsqError err;
    MsqMatrix< 2, 2 > g, gh;
    MsqMatrix< 2, 2 > h[3];
    bool valid;
    double val, hval;

    const double h_00[] = { 2, 0, 0, 10 };
    const double h_01[] = { 0, 0, -8, 0 };
    const double h_11[] = { 10, 0, 0, 2 };
    MsqMatrix< 2, 2 > h00( h_00 ), h01( h_01 ), h11( h_11 );

    valid = metric.evaluate_with_grad( A, val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( A, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[2], 1e-6 );

    valid = metric.evaluate_with_grad( B, val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( B, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[2], 1e-6 );

    valid = metric.evaluate_with_grad( inverse( A ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( inverse( A ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[2], 1e-6 );

    valid = metric.evaluate_with_grad( inverse( B ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( inverse( B ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[2], 1e-6 );

    valid = metric.evaluate_with_grad( A * inverse( B ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( A * inverse( B ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[2], 1e-6 );

    valid = metric.evaluate_with_grad( B * inverse( A ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( B * inverse( A ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[2], 1e-6 );

    MsqMatrix< 2, 2 > ah[3];
    valid = metric2.evaluate_with_hess( A, val, g, ah, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_hess( A, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[0], h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[1], h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[2], h[2], 1e-6 );

    valid = metric2.evaluate_with_hess( B, val, g, ah, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_hess( B, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[0], h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[1], h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[2], h[2], 1e-6 );
}
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_numerical_hessian_3D ( )

Definition at line 517 of file TMetricTest.cpp.

References ASSERT_MATRICES_EQUAL, ASSERT_NO_ERROR, Avals, Bvals, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, HessTestMetricRel::evaluate_with_grad(), MBMesquite::TMetric::evaluate_with_hess(), HessTestMetricRel_2::evaluate_with_hess(), and MBMesquite::inverse().

{
    HessTestMetricRel metric;
    HessTestMetricRel_2 metric2;
    const double Avals[] = { 1, 2, 3, 4, 1, 4, 3, 2, 1 };
    const double Bvals[] = { 0.1, 0.15, 0.05, 0.2, -0.1, -0.15, -0.05, -0.2, 2 };
    const MsqMatrix< 3, 3 > A( Avals );
    const MsqMatrix< 3, 3 > B( Bvals );

    MsqError err;
    MsqMatrix< 3, 3 > g, gh;
    MsqMatrix< 3, 3 > h[6];
    bool valid;
    double val, hval;

    const double h_00[] = { 2, 0, 0, 0, 10, 0, 0, 0, 10 };
    const double h_01[] = { 0, 0, 0, -8, 0, 0, 0, 0, 0 };
    const double h_02[] = { 0, 0, 0, 0, 0, 0, -8, 0, 0 };
    const double h_11[] = { 10, 0, 0, 0, 2, 0, 0, 0, 10 };
    const double h_12[] = { 0, 0, 0, 0, 0, 0, 0, -8, 0 };
    const double h_22[] = { 10, 0, 0, 0, 10, 0, 0, 0, 2 };
    MsqMatrix< 3, 3 > h00( h_00 ), h01( h_01 ), h02( h_02 ), h11( h_11 ), h12( h_12 ), h22( h_22 );

    valid = metric.evaluate_with_grad( A, val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( A, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h02, h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( h12, h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( h22, h[5], 1e-6 );

    valid = metric.evaluate_with_grad( B, val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( B, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h02, h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( h12, h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( h22, h[5], 1e-6 );

    valid = metric.evaluate_with_grad( inverse( A ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( inverse( A ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h02, h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( h12, h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( h22, h[5], 1e-6 );

    valid = metric.evaluate_with_grad( inverse( B ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( inverse( B ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h02, h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( h12, h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( h22, h[5], 1e-6 );

    valid = metric.evaluate_with_grad( A * inverse( B ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( A * inverse( B ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h02, h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( h12, h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( h22, h[5], 1e-6 );

    valid = metric.evaluate_with_grad( B * inverse( A ), val, g, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric.evaluate_with_hess( B * inverse( A ), hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( h00, h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( h01, h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( h02, h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( h11, h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( h12, h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( h22, h[5], 1e-6 );

    MsqMatrix< 3, 3 > ah[6];
    valid = metric2.evaluate_with_hess( A, val, g, ah, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_hess( A, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[0], h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[1], h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[2], h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[3], h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[4], h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[5], h[5], 1e-6 );

    valid = metric2.evaluate_with_hess( B, val, g, ah, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    valid = metric2.TMetric::evaluate_with_hess( B, hval, gh, h, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( valid );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( val, hval, 1e-6 );
    ASSERT_MATRICES_EQUAL( g, gh, 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[0], h[0], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[1], h[1], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[2], h[2], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[3], h[3], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[4], h[4], 1e-6 );
    ASSERT_MATRICES_EQUAL( ah[5], h[5], 1e-6 );
}
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_orient ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_scale ( )
template<class Metric , unsigned DIM>
void TMetricTest< Metric, DIM >::test_shape ( )

Member Data Documentation

template<class Metric , unsigned DIM>
const Matrix TMetricTest< Metric, DIM >::A

Definition at line 217 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const Matrix TMetricTest< Metric, DIM >::B

Definition at line 217 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const bool TMetricTest< Metric, DIM >::Barrier [private]

Definition at line 204 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const Matrix TMetricTest< Metric, DIM >::C

Definition at line 217 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const Matrix TMetricTest< Metric, DIM >::I

Definition at line 217 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const double TMetricTest< Metric, DIM >::idealVal [private]

Definition at line 203 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const bool TMetricTest< Metric, DIM >::orientInvariant [private]

Definition at line 204 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const bool TMetricTest< Metric, DIM >::shapeInvariant [private]

Definition at line 204 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const bool TMetricTest< Metric, DIM >::sizeInvariant [private]

Definition at line 204 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
Metric TMetricTest< Metric, DIM >::testMetric [private]

Definition at line 202 of file TargetMetricTest.hpp.

template<class Metric , unsigned DIM>
const Matrix TMetricTest< Metric, DIM >::Zero

Definition at line 217 of file TargetMetricTest.hpp.

List of all members.


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