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

Public Member Functions

void setUp ()
void tearDown ()
 MsqHessianTest ()
void accumulate_entries (const PatchData &pd, size_t elem_index, const Matrix3D *mat3d_array, MsqError &err)
void test_initialize ()
void test_axpy ()
void test_cg_solver ()
void test_cholesky_preconditioner ()

Private Member Functions

 CPPUNIT_TEST_SUITE (MsqHessianTest)
 CPPUNIT_TEST (test_initialize)
 CPPUNIT_TEST (test_axpy)
 CPPUNIT_TEST (test_cg_solver)
 CPPUNIT_TEST (test_cholesky_preconditioner)
 CPPUNIT_TEST_SUITE_END ()

Private Attributes

PatchData twoTriangles

Detailed Description

Definition at line 62 of file MsqHessianTest.cpp.


Constructor & Destructor Documentation

Definition at line 90 of file MsqHessianTest.cpp.

{}

Member Function Documentation

void MsqHessianTest::accumulate_entries ( const PatchData pd,
size_t  elem_index,
const Matrix3D mat3d_array,
MsqError err 
)

Definition at line 289 of file MsqHessianTest.cpp.

References CPPUNIT_ASSERT, MBMesquite::PatchData::element_by_index(), MBMesquite::MsqMeshEntity::get_vertex_index_array(), and MBMesquite::MsqMeshEntity::vertex_count().

{
    const MsqMeshEntity& elem = pd.element_by_index( elem_index );
    const size_t nv           = elem.vertex_count();
    const size_t* v           = elem.get_vertex_index_array();
    for( size_t r = 0; r < nv; ++r )
    {
        for( size_t c = r; c < nv; ++c )
        {
            add( v[r], v[c], *mat3d_array, err );
            CPPUNIT_ASSERT( !err );
            ++mat3d_array;
        }
    }
}
void MsqHessianTest::setUp ( ) [inline]

Definition at line 77 of file MsqHessianTest.cpp.

References CPPUNIT_ASSERT, and MBMesquite::create_two_tri_patch().

    {
        MsqPrintError err( cout );
        create_two_tri_patch( twoTriangles, err );
        CPPUNIT_ASSERT( !err );
    }
void MsqHessianTest::test_axpy ( ) [inline]

Definition at line 112 of file MsqHessianTest.cpp.

References MBMesquite::axpy(), CPPUNIT_ASSERT, GaussIntegration::initialize(), MBMesquite::Vector3D::set(), and size.

    {
        size_t i;
        MsqPrintError err( cout );

        MsqHessian::initialize( twoTriangles, err );
        CPPUNIT_ASSERT( !err );

        size_t hs = MsqHessian::size();

        Vector3D* res = new Vector3D[hs];
        Vector3D* x   = new Vector3D[hs];
        Vector3D* y   = new Vector3D[hs];
        Vector3D* ans = new Vector3D[hs];

        Matrix3D blocks[6];  // 6 blocks correspond to a triangular element (n+1)n/2 .

        blocks[0] = "4 4 7   4 5 7   7 7 3 ";
        blocks[1] = "4 8 7   3 5 7   1 2 3 ";
        blocks[2] = "4 4 7   6 5 9   1 8 5 ";
        blocks[3] = "4 4 2   4 5 3   2 3 3 ";
        blocks[4] = "2 4 7   3 2 7   1 4 3 ";
        blocks[5] = "8 4 9   4 5 7   9 7 3 ";

        accumulate_entries( twoTriangles, 0, blocks, err );
        CPPUNIT_ASSERT( !err );

        blocks[2] += blocks[5];
        blocks[5] = blocks[3];

        accumulate_entries( twoTriangles, 1, blocks, err );
        CPPUNIT_ASSERT( !err );

        Matrix3D entries_6_ans( "2 3 1   4 2 4   7 7 3" );
        CPPUNIT_ASSERT( mEntries[6] == entries_6_ans );

        x[0].set( 4, 5, 6 );
        x[1].set( 2, 5, 9 );
        x[2].set( 1, 2, 6 );
        x[3].set( 1, 5, 9 );

        y[0].set( 0, 0, 0 );
        y[1].set( 0, 0, 0 );
        y[2].set( 0, 0, 0 );
        y[3].set( 0, 0, 0 );

        axpy( res, hs, *this, x, hs, y, hs, err );
        CPPUNIT_ASSERT( !err );

        ans[0].set( 636, 635, 453 );
        ans[1].set( 365, 460, 461 );
        ans[2].set( 150, 199, 220 );
        ans[3].set( 166, 204, 174 );

        for( i = 0; i < hs; ++i )
            CPPUNIT_ASSERT( res[i] == ans[i] );

        y[0].set( 3, 2, 6 );
        y[1].set( 1, 2, 4 );
        y[2].set( 3, 6, 9 );
        y[3].set( 2, 4, 4 );

        ans[0].set( 639, 637, 459 );
        ans[1].set( 366, 462, 465 );
        ans[2].set( 153, 205, 229 );
        ans[3].set( 168, 208, 178 );

        axpy( res, hs, *this, x, hs, y, hs, err );
        CPPUNIT_ASSERT( !err );

        for( i = 0; i < hs; ++i )
            CPPUNIT_ASSERT( res[i] == ans[i] );

        delete[] res;
        delete[] x;
        delete[] y;
        delete[] ans;
    }
void MsqHessianTest::test_cg_solver ( ) [inline]

Definition at line 191 of file MsqHessianTest.cpp.

References CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, GaussIntegration::initialize(), MBMesquite::Vector3D::set(), and size.

    {
        size_t i;
        MsqPrintError err( cout );

        MsqHessian::initialize( twoTriangles, err );
        CPPUNIT_ASSERT( !err );

        size_t hs = MsqHessian::size();

        Vector3D* res = new Vector3D[hs];
        Vector3D* x   = new Vector3D[hs];
        Vector3D* y   = new Vector3D[hs];
        Vector3D* ans = new Vector3D[hs];

        Matrix3D blocks[6];  // 6 blocks correspond to a triangular element (n+!)n/2 .

        blocks[0] = "14 4 7   4 15 7   7 7 13 ";
        blocks[1] = "4 8 7   3 5 7   1 2 3 ";
        blocks[2] = "4 4 7   6 5 9   1 8 5 ";
        blocks[3] = "14 4 2   4 15 3   2 3 13 ";
        blocks[4] = "2 4 7   3 2 7   1 4 3 ";
        blocks[5] = "18 4 9   4 15 7   9 7 13 ";

        accumulate_entries( twoTriangles, 0, blocks, err );
        CPPUNIT_ASSERT( !err );

        blocks[2] -= blocks[5];
        blocks[5] = blocks[3];

        accumulate_entries( twoTriangles, 1, blocks, err );
        CPPUNIT_ASSERT( !err );

        y[0].set( 3, 2, 6 );
        y[1].set( 1, 2, 4 );
        y[2].set( 3, 6, 9 );
        y[3].set( 2, 4, 4 );

        cg_solver( x, y, err );
        CPPUNIT_ASSERT( !err );

        //     for (int i=0; i<4; ++i)
        //       cout << x[i];

        ans[0].set( 3.2338, 7.6431, -7.0735 );
        ans[1].set( -1.0068, 4.5520, -4.6628 );
        ans[2].set( -0.4361, 4.7640, -8.1006 );
        ans[3].set( -0.1218, -0.8817, -4.5571 );

        for( i = 0; i < hs; ++i )
            for( short j = 0; j < 3; ++j )
                CPPUNIT_ASSERT_DOUBLES_EQUAL( x[i][j], ans[i][j], 10e-1 );

        delete[] res;
        delete[] x;
        delete[] y;
        delete[] ans;
    }

Definition at line 250 of file MsqHessianTest.cpp.

References MBMesquite::MsqHessian::compute_preconditioner(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, GaussIntegration::initialize(), and MBMesquite::MsqHessian::zero_out().

    {
        MsqPrintError err( cout );

        MsqHessian::initialize( twoTriangles, err );
        CPPUNIT_ASSERT( !err );
        MsqHessian::zero_out();

        Matrix3D blocks[6];  // 6 blocks correspond to a triangular element (n+1)n/2 .

        blocks[0] = " 2  1    1 "
                    " 1  2.5  0.5 "
                    " 1  0.5  2.5 ";
        blocks[1] = "0 0 0   0 0 0   0 0 0 ";
        blocks[2] = "0 0 0   0 0 0   0 0 0 ";
        blocks[3] = "0 0 0   0 0 0   0 0 0 ";
        blocks[4] = "0 0 0   0 0 0   0 0 0 ";
        blocks[5] = "0 0 0   0 0 0   0 0 0 ";

        accumulate_entries( twoTriangles, 0, blocks, err );
        CPPUNIT_ASSERT( !err );

        MsqHessian::compute_preconditioner( err );
        CPPUNIT_ASSERT( !err );
        Matrix3D block_0 = mPreconditioner[0];

        Matrix3D correct( " 0.5  0.5  0.5 "
                          " 0    0.5  0  "
                          " 0    0    0.5 " );

        for( short i = 0; i < 3; ++i )
            for( short j = 0; j < 3; ++j )
                CPPUNIT_ASSERT_DOUBLES_EQUAL( block_0[i][j], correct[i][j], 10e-10 );

        //     cout << "block 0: \n" << block_0 << endl;
        //     cout << "correct: \n" << correct << endl;
    }

Definition at line 94 of file MsqHessianTest.cpp.

References CPPUNIT_ASSERT, and GaussIntegration::initialize().

    {
        MsqPrintError err( cout );

        MsqHessian::initialize( twoTriangles, err );
        CPPUNIT_ASSERT( !err );

        // Checks values of mRowStart are correct.
        size_t i, row_start[] = { 0, 4, 7, 8, 9 };
        for( i = 0; i < 5; ++i )
            CPPUNIT_ASSERT( mRowStart[i] == row_start[i] );

        // Checks values of mColIndex are correct.
        size_t col_index[] = { 0, 1, 2, 3, 1, 2, 3, 2, 3 };
        for( i = 0; i < 9; ++i )
            CPPUNIT_ASSERT( mColIndex[i] == col_index[i] );
    }

Member Data Documentation

Definition at line 74 of file MsqHessianTest.cpp.

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