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

Public Member Functions

void setUp ()
void tearDown ()
 MsqMeshEntityTest ()
void test_hex_vertices ()
void test_centroid (PatchData &pd, Vector3D &correct)
 test the centroid of the first element in the Patch
void test_centroid_tri ()
void test_centroid_quad ()
void test_centroid_hex ()
void test_unsigned_area ()
void test_unsigned_area_poly ()
void test_unsigned_area_tet ()
void test_unsigned_area_pyr ()
void test_unsigned_area_pri ()
void test_unsigned_area_hex ()
void test_all_nodes ()
void test_unsigned_area_common (EntityTopology type, const double *coords, double expected)
void test_check_element_orientation_linear ()
void test_check_element_orientation_quadratic ()
void test_check_element_orientation (EntityTopology type, int nodes)

Private Member Functions

 CPPUNIT_TEST_SUITE (MsqMeshEntityTest)
 CPPUNIT_TEST (test_hex_vertices)
 CPPUNIT_TEST (test_centroid_tri)
 CPPUNIT_TEST (test_centroid_quad)
 CPPUNIT_TEST (test_centroid_hex)
 CPPUNIT_TEST (test_unsigned_area)
 CPPUNIT_TEST (test_unsigned_area_poly)
 CPPUNIT_TEST (test_unsigned_area_tet)
 CPPUNIT_TEST (test_unsigned_area_pyr)
 CPPUNIT_TEST (test_unsigned_area_pri)
 CPPUNIT_TEST (test_unsigned_area_hex)
 CPPUNIT_TEST (test_all_nodes)
 CPPUNIT_TEST (test_check_element_orientation_linear)
 CPPUNIT_TEST (test_check_element_orientation_quadratic)
 CPPUNIT_TEST_SUITE_END ()
void test_all_nodes (EntityTopology type, unsigned num_nodes)

Private Attributes

PatchData oneHexPatch
PatchData oneTetPatch
PatchData oneQuadPatch
PatchData oneTriPatch
Vector3D e1
Vector3D e2
Vector3D e3
double tolEps

Detailed Description

Definition at line 66 of file MsqMeshEntityTest.cpp.


Constructor & Destructor Documentation

Definition at line 126 of file MsqMeshEntityTest.cpp.

{}

Member Function Documentation

void MsqMeshEntityTest::setUp ( ) [inline]

Definition at line 97 of file MsqMeshEntityTest.cpp.

References CPPUNIT_ASSERT, MBMesquite::create_one_hex_patch(), MBMesquite::create_one_quad_patch(), MBMesquite::create_one_tet_patch(), and MBMesquite::create_one_tri_patch().

    {
        tolEps = 1.e-12;

        // sets up the unit vectors
        e1.set( 1, 0, 0 );
        e2.set( 0, 1, 0 );
        e3.set( 0, 0, 1 );

        MsqPrintError err( cout );

        // creates empty Patch
        create_one_hex_patch( oneHexPatch, err );
        CPPUNIT_ASSERT( !err );
        create_one_tet_patch( oneTetPatch, err );
        CPPUNIT_ASSERT( !err );
        create_one_tri_patch( oneTriPatch, err );
        CPPUNIT_ASSERT( !err );
        create_one_quad_patch( oneQuadPatch, err );
        CPPUNIT_ASSERT( !err );
    }
void MsqMeshEntityTest::test_all_nodes ( EntityTopology  type,
unsigned  num_nodes 
) [private]

Definition at line 283 of file MsqMeshEntityTest.cpp.

References MBMesquite::MsqMeshEntity::all_nodes(), ASSERT_NO_ERROR, conn, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::PatchData::element_by_index(), MBMesquite::PatchData::fill(), fixed, MBMesquite::NodeSet::have_any_corner_node(), MBMesquite::NodeSet::have_any_mid_edge_node(), MBMesquite::NodeSet::have_any_mid_face_node(), MBMesquite::NodeSet::have_any_mid_region_node(), n, and MBMesquite::NodeSet::num_nodes().

{
    const unsigned num_vtx     = 27;
    double coords[3 * num_vtx] = { 0.0 };
    size_t conn[num_vtx];
    for( size_t i = 0; i < num_vtx; ++i )
        conn[i] = i;
    bool fixed[num_vtx] = { false };
    CPPUNIT_ASSERT( num_nodes <= num_vtx );

    MsqError err;
    PatchData pd;
    size_t n = num_nodes;
    pd.fill( num_nodes, coords, 1, &type, &n, conn, fixed, err );
    ASSERT_NO_ERROR( err );

    MsqMeshEntity& elem = pd.element_by_index( 0 );
    NodeSet all         = elem.all_nodes( err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( num_nodes, all.num_nodes() );
    CPPUNIT_ASSERT( all.have_any_corner_node() );
    bool mid_edge, mid_face, mid_reg;
    TopologyInfo::higher_order( type, num_nodes, mid_edge, mid_face, mid_reg, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( mid_edge, !!all.have_any_mid_edge_node() );
    CPPUNIT_ASSERT_EQUAL( mid_face, !!all.have_any_mid_face_node() );
    CPPUNIT_ASSERT_EQUAL( mid_reg, !!all.have_any_mid_region_node() );
}
void MsqMeshEntityTest::test_centroid ( PatchData pd,
Vector3D correct 
) [inline]

test the centroid of the first element in the Patch

Definition at line 150 of file MsqMeshEntityTest.cpp.

References CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, eps, MBMesquite::MsqMeshEntity::get_centroid(), and MBMesquite::PatchData::get_element_array().

    {
        MsqPrintError err( cout );
        double eps = 1e-6;
        Vector3D centroid;

        MsqMeshEntity* elem = pd.get_element_array( err );
        CPPUNIT_ASSERT( !err );
        elem->get_centroid( centroid, pd, err );
        CPPUNIT_ASSERT( !err );

        //     cout << "centroid: "<< centroid <<endl;
        //     cout << "correct: "<< correct <<endl;

        for( int i = 0; i < 3; ++i )
            CPPUNIT_ASSERT_DOUBLES_EQUAL( centroid[i], correct[i], eps );
    }

Definition at line 180 of file MsqMeshEntityTest.cpp.

    {
        Vector3D correct( 1.5, 1.5, 1.5 );
        test_centroid( oneHexPatch, correct );
    }

Definition at line 174 of file MsqMeshEntityTest.cpp.

    {
        Vector3D correct( 1.5, 1.5, 1.0 );
        test_centroid( oneQuadPatch, correct );
    }

Definition at line 168 of file MsqMeshEntityTest.cpp.

    {
        Vector3D correct( 1.5, 1 + 1 / ( 2.0 * sqrt( 3.0 ) ), 1.0 );
        test_centroid( oneTriPatch, correct );
    }

Definition at line 371 of file MsqMeshEntityTest.cpp.

References ASSERT_MESSAGE, ASSERT_NO_ERROR, conn, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::create_ideal_element_patch(), dim, MBMesquite::PatchData::element_by_index(), MSQ_ERRRTN, MBMesquite::PatchData::num_elements(), MBMesquite::PatchData::num_nodes(), MBMesquite::PatchData::set_vertex_coordinates(), MBMesquite::TETRAHEDRON, MBMesquite::TRIANGLE, and MBMesquite::PatchData::vertex_by_index().

{
    // get an ideal element
    MsqError err;
    PatchData pd;
    create_ideal_element_patch( pd, type, nodes, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( (size_t)1, pd.num_elements() );
    CPPUNIT_ASSERT_EQUAL( (size_t)nodes, pd.num_nodes() );
    MsqMeshEntity& elem = pd.element_by_index( 0 );
    CPPUNIT_ASSERT_EQUAL( (size_t)nodes, elem.node_count() );
    CPPUNIT_ASSERT_EQUAL( type, elem.get_element_type() );
    const size_t* conn = elem.get_vertex_index_array();

    // test that ideal element is not reported as inverted
    int inverted, tested;
    elem.check_element_orientation( pd, inverted, tested, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( 0, inverted );
    CPPUNIT_ASSERT( tested > 0 );

    bool mids[4] = { false };
    TopologyInfo::higher_order( type, nodes, mids[1], mids[2], mids[3], err );MSQ_ERRRTN( err );

    // invert element at each vertex and test
    Vector3D centroid;
    elem.get_centroid( centroid, pd, err );
    ASSERT_NO_ERROR( err );
    for( int i = 0; i < nodes; ++i )
    {
        unsigned dim, num;
        TopologyInfo::side_from_higher_order( type, nodes, i, dim, num, err );
        ASSERT_NO_ERROR( err );
        const Vector3D old_pos = pd.vertex_by_index( conn[i] );
        Vector3D new_pos       = old_pos;
        if( dim == TopologyInfo::dimension( type ) )
        {
            // move mid-element node 3/4 of the way to corner 0
            new_pos += 3 * pd.vertex_by_index( conn[0] );
            new_pos *= 0.25;
        }
        else if( dim == 0 )
        {  // if a corner vertex
            if( type == TRIANGLE || type == TETRAHEDRON )
            {
                // move tri/tet vertex past opposite side of element
                new_pos += 2 * ( centroid - old_pos );
            }
            else if( mids[1] )
            {
                // if have mid-edge nodes move 3/4 of the way to center vertex
                new_pos += 3 * centroid;
                new_pos *= 0.25;
            }
            else
            {
                // move vertex past centroid
                new_pos += 1.5 * ( centroid - old_pos );
            }
        }
        else
        {
            // otherwise move vertex past centroid
            new_pos += 2.5 * ( centroid - old_pos );
        }

        pd.set_vertex_coordinates( new_pos, conn[i], err );
        ASSERT_NO_ERROR( err );

        // test that element is inverted
        inverted = tested = 0;
        elem.check_element_orientation( pd, inverted, tested, err );
        ASSERT_NO_ERROR( err );
        std::ostringstream str;
        str << TopologyInfo::short_name( type ) << nodes << " Vertex " << i << " (Dimension " << dim << " Index " << num
            << ")";
        CppUnit::Message m( "MsqMeshEntity failed to detect inverted element" );
        m.addDetail( str.str() );
        ASSERT_MESSAGE( m, inverted > 0 );

        // move vertex back to ideal position
        pd.set_vertex_coordinates( old_pos, conn[i], err );
        ASSERT_NO_ERROR( err );
    }
}

Definition at line 343 of file MsqMeshEntityTest.cpp.

References corners, MBMesquite::HEXAHEDRON, MBMesquite::PRISM, MBMesquite::PYRAMID, MBMesquite::QUADRILATERAL, MBMesquite::TETRAHEDRON, and MBMesquite::TRIANGLE.

{
    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 )
    {
        test_check_element_orientation( types[i], TopologyInfo::corners( types[i] ) );
    }
}

Definition at line 354 of file MsqMeshEntityTest.cpp.

References MBMesquite::QUADRILATERAL, MBMesquite::TETRAHEDRON, and MBMesquite::TRIANGLE.

{
    struct ElemType
    {
        EntityTopology topo;
        unsigned nodes;
    };

    const ElemType types[] = { { TRIANGLE, 6 }, { QUADRILATERAL, 8 }, { QUADRILATERAL, 9 }, { TETRAHEDRON, 10 } };
    const int num_types    = sizeof( types ) / sizeof( types[0] );

    for( int i = 0; i < num_types; ++i )
    {
        test_check_element_orientation( types[i].topo, types[i].nodes );
    }
}

Definition at line 128 of file MsqMeshEntityTest.cpp.

References CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::Vector3D::set(), and vtx().

    {
        MsqPrintError err( cout );
        // prints out the vertices.
        const MsqVertex* ideal_vertices = oneHexPatch.get_vertex_array( err );
        CPPUNIT_ASSERT( !err );
        size_t num_vtx = oneHexPatch.num_nodes();
        CPPUNIT_ASSERT_EQUAL( size_t( 8 ), num_vtx );

        MsqVertex vtx;

        vtx.set( 1, 1, 1 );
        CPPUNIT_ASSERT_EQUAL( vtx, ideal_vertices[0] );

        vtx.set( 2, 2, 2 );
        CPPUNIT_ASSERT_EQUAL( vtx, ideal_vertices[6] );

        vtx.set( 1, 2, 2 );
        CPPUNIT_ASSERT_EQUAL( vtx, ideal_vertices[7] );
    }

Definition at line 186 of file MsqMeshEntityTest.cpp.

References MBMesquite::MsqMeshEntity::compute_unsigned_area(), and CPPUNIT_ASSERT.

    {
        MsqPrintError err( cout );
        MsqMeshEntity* tri = oneTriPatch.get_element_array( err );
        CPPUNIT_ASSERT( !err );
        CPPUNIT_ASSERT( fabs( tri->compute_unsigned_area( oneTriPatch, err ) - ( sqrt( 3.0 ) / 4.0 ) ) < tolEps );
        MsqMeshEntity* quad = oneQuadPatch.get_element_array( err );
        CPPUNIT_ASSERT( !err );
        CPPUNIT_ASSERT( fabs( quad->compute_unsigned_area( oneQuadPatch, err ) - 1.0 ) < tolEps );
    }

Definition at line 271 of file MsqMeshEntityTest.cpp.

References MBMesquite::HEXAHEDRON.

{
    const double coords[] = { 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1 };
    test_unsigned_area_common( HEXAHEDRON, coords, 1.0 );

    const double coords2[] = { 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 2, 0, 0, 0, 2, 2, 0, 2, 2, 2, 2, 0, 2, 2 };
    test_unsigned_area_common( HEXAHEDRON, coords2, 8.0 );

    const double pyr_coords[] = { -1, -1, 0, 1, -1, 0, 1, 1, 0, -1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 };
    test_unsigned_area_common( HEXAHEDRON, pyr_coords, 4.0 / 3.0 );
}

Definition at line 217 of file MsqMeshEntityTest.cpp.

References ASSERT_NO_ERROR, MBMesquite::MsqMeshEntity::compute_unsigned_area(), conn, CPPUNIT_ASSERT_DOUBLES_EQUAL, MBMesquite::PatchData::element_by_index(), MBMesquite::PatchData::fill(), fixed, and MBMesquite::POLYGON.

{
    const double coords[] = { 0, 0, 0, 1, 0, 0, 1, 1, 0, 0.5, 1.5, 0, 0, 1, 0 };
    size_t n_vtx          = 5;
    EntityTopology type   = POLYGON;
    MsqError err;

    PatchData pd;
    pd.fill( n_vtx, coords, 1, &type, &n_vtx, conn, fixed, err );
    ASSERT_NO_ERROR( err );

    double a = pd.element_by_index( 0 ).compute_unsigned_area( pd, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.25, a, 1e-8 );
}

Definition at line 262 of file MsqMeshEntityTest.cpp.

References MBMesquite::PRISM.

{
    const double coords[] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1 };
    test_unsigned_area_common( PRISM, coords, 0.5 );

    const double tet_coords[] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1 };
    test_unsigned_area_common( PRISM, tet_coords, 1.0 / 6.0 );
}

Definition at line 253 of file MsqMeshEntityTest.cpp.

References MBMesquite::PYRAMID.

{
    const double coords[] = { 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1 };
    test_unsigned_area_common( PYRAMID, coords, 1.0 / 3.0 );

    const double pyr_coords[] = { -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 0, 0, 0 };
    test_unsigned_area_common( PYRAMID, pyr_coords, 4.0 / 3.0 );
}

Definition at line 247 of file MsqMeshEntityTest.cpp.

References MBMesquite::TETRAHEDRON.

{
    const double coords[] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };
    test_unsigned_area_common( TETRAHEDRON, coords, 1.0 / 6.0 );
}

Member Data Documentation

Definition at line 93 of file MsqMeshEntityTest.cpp.

Definition at line 93 of file MsqMeshEntityTest.cpp.

Definition at line 93 of file MsqMeshEntityTest.cpp.

Definition at line 89 of file MsqMeshEntityTest.cpp.

Definition at line 91 of file MsqMeshEntityTest.cpp.

Definition at line 90 of file MsqMeshEntityTest.cpp.

Definition at line 92 of file MsqMeshEntityTest.cpp.

double MsqMeshEntityTest::tolEps [private]

Definition at line 94 of file MsqMeshEntityTest.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