MOAB: Mesh Oriented datABase  (version 5.3.1)
MeshUtilTest Class Reference
+ Inheritance diagram for MeshUtilTest:
+ Collaboration diagram for MeshUtilTest:

Public Member Functions

void test_edge_length_distribution_types ()
void test_edge_length_distribution_unique ()
void test_edge_length_distribution_empty ()
void test_lambda_distribution ()
void test_lambda_distribution_mixed ()
void test_lambda_distribution_empty ()

Private Member Functions

 CPPUNIT_TEST_SUITE (MeshUtilTest)
 CPPUNIT_TEST (test_edge_length_distribution_types)
 CPPUNIT_TEST (test_edge_length_distribution_unique)
 CPPUNIT_TEST (test_edge_length_distribution_empty)
 CPPUNIT_TEST (test_lambda_distribution)
 CPPUNIT_TEST (test_lambda_distribution_mixed)
 CPPUNIT_TEST (test_lambda_distribution_empty)
 CPPUNIT_TEST_SUITE_END ()

Detailed Description

Definition at line 39 of file MeshUtilTest.cpp.


Member Function Documentation

Definition at line 246 of file MeshUtilTest.cpp.

References CPPUNIT_ASSERT_EQUAL, MBMesquite::MeshUtil::edge_length_distribution(), MBMesquite::MsqError::error_code(), and MBMesquite::MsqError::INVALID_MESH.

{
    ArrayMesh empty( 3, 0, 0, 0, 0, 0, 0 );
    MeshUtil tool( &empty );
    SimpleStats act_results;
    MsqError err;
    tool.edge_length_distribution( act_results, err );
    CPPUNIT_ASSERT_EQUAL( MsqError::INVALID_MESH, err.error_code() );
}

Definition at line 81 of file MeshUtilTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::SimpleStats::average(), conn, CPPUNIT_ASSERT_DOUBLES_EQUAL, MBMesquite::MeshUtil::edge_length_distribution(), MBMesquite::edges, MBMesquite::EPSILON, fixed, MBMesquite::HEXAHEDRON, MBMesquite::SimpleStats::maximum(), mesh, MBMesquite::SimpleStats::minimum(), MBMesquite::PRISM, MBMesquite::PYRAMID, MBMesquite::QUADRILATERAL, MBMesquite::SimpleStats::rms(), MBMesquite::SimpleStats::standard_deviation(), MBMesquite::TETRAHEDRON, and MBMesquite::TRIANGLE.

{
    // create a mesh that contains one of each element type,
    // completely disconnected from any other element
    double coords[] = { // triangle : 0 - 2
                        0, 0, 0, 2, 0, 0, 1, 1, 0,
                        // quad : 3 - 6
                        3, 0, 0, 3, 1, 0, 3, 2, 2, 3, 0, 1,
                        // tet : 7 - 10
                        0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
                        // pyramid : 11 - 15
                        0, 0, 0, 0, -2, 0, -2, -2, 0, -1, 0, 0, 0, 0, -3,
                        // wedge : 16 - 21
                        0, 0, -2, 2, 0, -2, 1, 1, -2, 0, 0, -1.5, 2, 0, -1.5, 1, 1, -1, 5,
                        // hex : 22 - 29
                        4, 0, 0, 4, 1, 0, 4, 2, 2, 4, 0, 1, 5, 0, 0, 5, 1, 0, 5, 2, 2, 5, 0, 1
    };
    const int tri_offset       = 0;
    const int quad_offset      = tri_offset + 3;
    const int tet_offset       = quad_offset + 4;
    const int pyr_offset       = tet_offset + 4;
    const int wedge_offset     = pyr_offset + 5;
    const int hex_offset       = wedge_offset + 6;
    const int num_vtx          = hex_offset + 8;
    const int fixed[num_vtx]   = { 0 };
    EntityTopology types[]     = { TRIANGLE, QUADRILATERAL, TETRAHEDRON, PYRAMID, PRISM, HEXAHEDRON };
    const unsigned long conn[] = {
        0,  1,  2,                      // triangle
        3,  4,  5,  6,                  // quadrilateral
        7,  8,  9,  10,                 // tetrahedron
        11, 12, 13, 14, 15,             // pyramid
        16, 17, 18, 19, 20, 21,         // prism,
        22, 23, 24, 25, 26, 27, 28, 29  // hex
    };
    ArrayMesh mesh( 3, num_vtx, coords, fixed, 6, types, conn );

    // calculate expected value
    const int edges[][2] = { // triangle
                             { 0, 1 },
                             { 1, 2 },
                             { 2, 0 },
                             // quad
                             { 3, 4 },
                             { 4, 5 },
                             { 5, 6 },
                             { 6, 3 },
                             // tet
                             { 7, 8 },
                             { 8, 9 },
                             { 9, 7 },
                             { 7, 10 },
                             { 8, 10 },
                             { 9, 10 },
                             // pyramid
                             { 11, 12 },
                             { 12, 13 },
                             { 13, 14 },
                             { 14, 11 },
                             { 11, 15 },
                             { 12, 15 },
                             { 13, 15 },
                             { 14, 15 },
                             // prism
                             { 16, 17 },
                             { 17, 18 },
                             { 18, 16 },
                             { 16, 19 },
                             { 17, 20 },
                             { 18, 21 },
                             { 19, 20 },
                             { 20, 21 },
                             { 21, 19 },
                             // hex
                             { 22, 23 },
                             { 23, 24 },
                             { 24, 25 },
                             { 25, 22 },
                             { 22, 26 },
                             { 23, 27 },
                             { 24, 28 },
                             { 25, 29 },
                             { 26, 27 },
                             { 27, 28 },
                             { 28, 29 },
                             { 29, 26 }
    };
    const int num_edges = sizeof( edges ) / sizeof( edges[0] );

    double exp_min = HUGE_VAL, exp_max = -HUGE_VAL;
    double exp_avg = 0, exp_rms = 0;
    for( int i = 0; i < num_edges; ++i )
    {
        int v1 = edges[i][0];
        int v2 = edges[i][1];
        Vector3D c0( coords + 3 * v1 );
        Vector3D c1( coords + 3 * v2 );
        Vector3D diff = c1 - c0;
        double len    = sqrt( diff % diff );
        if( len < exp_min ) exp_min = len;
        if( len > exp_max ) exp_max = len;
        exp_avg += len;
        exp_rms += diff % diff;
    }

    exp_avg /= num_edges;
    exp_rms /= num_edges;
    double exp_std_dev = sqrt( exp_rms - exp_avg * exp_avg );
    exp_rms            = sqrt( exp_rms );

    SimpleStats act_results;
    MsqError err;
    MeshUtil tool( &mesh );
    tool.edge_length_distribution( act_results, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_min, act_results.minimum(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_max, act_results.maximum(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_avg, act_results.average(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_rms, act_results.rms(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_std_dev, act_results.standard_deviation(), EPSILON );
}

Definition at line 202 of file MeshUtilTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::SimpleStats::average(), conn, CPPUNIT_ASSERT_DOUBLES_EQUAL, MBMesquite::MeshUtil::edge_length_distribution(), MBMesquite::edges, MBMesquite::EPSILON, fixed, MBMesquite::SimpleStats::maximum(), mesh, MBMesquite::SimpleStats::minimum(), MBMesquite::SimpleStats::rms(), MBMesquite::SimpleStats::standard_deviation(), and MBMesquite::TETRAHEDRON.

{
    // define two-tet mesh where tets share a face
    double coords[]            = { 0, -5, 0, 0, 5, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 };
    const unsigned long conn[] = { 4, 3, 2, 0, 2, 3, 4, 1 };
    int fixed[5]               = { 0 };
    ArrayMesh mesh( 3, 5, coords, fixed, 2, TETRAHEDRON, conn );

    const int edges[][2] = { { 0, 2 }, { 0, 3 }, { 0, 4 }, { 1, 2 }, { 1, 3 }, { 1, 4 }, { 2, 3 }, { 3, 4 }, { 4, 2 } };
    const int num_edges  = sizeof( edges ) / sizeof( edges[0] );

    double exp_min = HUGE_VAL, exp_max = -HUGE_VAL;
    double exp_avg = 0, exp_rms = 0;
    for( int i = 0; i < num_edges; ++i )
    {
        int v1 = edges[i][0];
        int v2 = edges[i][1];
        Vector3D c0( coords + 3 * v1 );
        Vector3D c1( coords + 3 * v2 );
        Vector3D diff = c1 - c0;
        double len    = sqrt( diff % diff );
        if( len < exp_min ) exp_min = len;
        if( len > exp_max ) exp_max = len;
        exp_avg += len;
        exp_rms += diff % diff;
    }

    exp_avg /= num_edges;
    exp_rms /= num_edges;
    double exp_std_dev = sqrt( exp_rms - exp_avg * exp_avg );
    exp_rms            = sqrt( exp_rms );

    SimpleStats act_results;
    MsqError err;
    MeshUtil tool( &mesh );
    tool.edge_length_distribution( act_results, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_min, act_results.minimum(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_max, act_results.maximum(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_avg, act_results.average(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_rms, act_results.rms(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_std_dev, act_results.standard_deviation(), EPSILON );
}

Definition at line 256 of file MeshUtilTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::SimpleStats::average(), MBMesquite::SimpleStats::clear(), conn, CPPUNIT_ASSERT_DOUBLES_EQUAL, MBMesquite::EPSILON, fixed, MBMesquite::MeshUtil::lambda_distribution(), MBMesquite::length(), MBMesquite::SimpleStats::maximum(), MBMesquite::SimpleStats::minimum(), MBMesquite::QUADRILATERAL, MBMesquite::SimpleStats::rms(), and MBMesquite::SimpleStats::variance().

{
    // simple regular unit quad mesh one deformed corner
    double coords[]            = { 0, 2, 0, 1, 2, 0, 2, 2, 0, 0, 1, 0, 1, 1, 0, 2, 1, 0, 0, 0, 0, 1, 0, 0, 3, 0, 0 };
    const unsigned long conn[] = { 3, 4, 1, 0, 4, 5, 2, 1, 6, 7, 4, 3, 7, 8, 5, 4 };
    const int fixed[9]         = { 0 };

    // first mesh doesn't contain deformed element
    SimpleStats results;
    MsqError err;
    ArrayMesh mesh3( 3, 8, coords, fixed, 3, QUADRILATERAL, conn );
    MeshUtil tool3( &mesh3 );
    tool3.lambda_distribution( results, err );

    // lambda should be one everywhere
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, results.minimum(), 1e-12 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, results.maximum(), 1e-12 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, results.average(), 1e-12 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, results.rms(), 1e-12 );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, results.variance(), 1e-12 );

    // now try with deformed element
    ArrayMesh mesh4( 3, 9, coords, fixed, 4, QUADRILATERAL, conn );
    MeshUtil tool4( &mesh4 );
    results.clear();
    tool4.lambda_distribution( results, err );

    // expect 13 values of 1 and a few other values
    Vector3D v4( coords + 3 * 4 );
    Vector3D v5( coords + 3 * 5 );
    Vector3D v7( coords + 3 * 7 );
    Vector3D v8( coords + 3 * 8 );
    double val14   = sqrt( ( ( v4 - v5 ) * ( v8 - v5 ) ).length() );
    double val15   = sqrt( ( ( v5 - v8 ) * ( v7 - v8 ) ).length() );
    double val16   = sqrt( ( ( v4 - v7 ) * ( v8 - v7 ) ).length() );
    double exp_min = std::min( std::min( val14, val15 ), std::min( val16, 1.0 ) );
    double exp_max = std::max( std::max( val14, val15 ), val16 );
    double exp_avg = ( 13 + val14 + val15 + val16 ) / 16.0;
    double exp_rms = sqrt( ( 13 + val14 * val14 + val15 * val16 + val16 * val16 ) / 16.0 );

    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_min, results.minimum(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_max, results.maximum(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_avg, results.average(), EPSILON );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( exp_rms, results.rms(), EPSILON );
}

Definition at line 347 of file MeshUtilTest.cpp.

References CPPUNIT_ASSERT_EQUAL, MBMesquite::MsqError::error_code(), MBMesquite::MsqError::INVALID_MESH, and MBMesquite::MeshUtil::lambda_distribution().

{
    ArrayMesh empty( 3, 0, 0, 0, 0, 0, 0 );
    MeshUtil tool( &empty );
    SimpleStats act_results;
    MsqError err;
    tool.lambda_distribution( act_results, err );
    CPPUNIT_ASSERT_EQUAL( MsqError::INVALID_MESH, err.error_code() );
}

Definition at line 303 of file MeshUtilTest.cpp.

References ASSERT_NO_ERROR, conn, MBMesquite::MeshUtil::edge_length_distribution(), fixed, MBMesquite::HEXAHEDRON, mesh, MBMesquite::PRISM, MBMesquite::PYRAMID, MBMesquite::QUADRILATERAL, MBMesquite::TETRAHEDRON, and MBMesquite::TRIANGLE.

{
    // create a mesh that contains one of each element type,
    // completely disconnected from any other element
    double coords[] = { // triangle : 0 - 2
                        0, 0, 0, 2, 0, 0, 1, 1, 0,
                        // quad : 3 - 6
                        3, 0, 0, 3, 1, 0, 3, 2, 2, 3, 0, 1,
                        // tet : 7 - 10
                        0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1,
                        // pyramid : 11 - 15
                        0, 0, 0, 0, -2, 0, -2, -2, 0, -1, 0, 0, 0, 0, -3,
                        // wedge : 16 - 21
                        0, 0, -2, 2, 0, -2, 1, 1, -2, 0, 0, -1.5, 2, 0, -1.5, 1, 1, -1, 5,
                        // hex : 22 - 29
                        4, 0, 0, 4, 1, 0, 4, 2, 2, 4, 0, 1, 5, 0, 0, 5, 1, 0, 5, 2, 2, 5, 0, 1
    };
    const int tri_offset       = 0;
    const int quad_offset      = tri_offset + 3;
    const int tet_offset       = quad_offset + 4;
    const int pyr_offset       = tet_offset + 4;
    const int wedge_offset     = pyr_offset + 5;
    const int hex_offset       = wedge_offset + 6;
    const int num_vtx          = hex_offset + 8;
    const int fixed[num_vtx]   = { 0 };
    EntityTopology types[]     = { TRIANGLE, QUADRILATERAL, TETRAHEDRON, PYRAMID, PRISM, HEXAHEDRON };
    const unsigned long conn[] = {
        0,  1,  2,                      // triangle
        3,  4,  5,  6,                  // quadrilateral
        7,  8,  9,  10,                 // tetrahedron
        11, 12, 13, 14, 15,             // pyramid
        16, 17, 18, 19, 20, 21,         // prism,
        22, 23, 24, 25, 26, 27, 28, 29  // hex
    };
    ArrayMesh mesh( 3, num_vtx, coords, fixed, 6, types, conn );

    // just test that this doesn't fail for any of the element types
    SimpleStats act_results;
    MsqError err;
    MeshUtil tool( &mesh );
    tool.edge_length_distribution( act_results, err );
    ASSERT_NO_ERROR( err );
}

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