MOAB: Mesh Oriented datABase  (version 5.2.1)
VtkTest Class Reference
+ Inheritance diagram for VtkTest:
+ Collaboration diagram for VtkTest:

Public Member Functions

void setUp ()
void tearDown ()
 VtkTest ()
void check_8hex_structured (Mesh &mesh)
void check_8hex_block (Mesh &mesh, std::vector< Mesh::VertexHandle >::iterator connectivity)
void check_4quad_structured (Mesh &mesh)
void check_4quad_block (Mesh &mesh, std::vector< Mesh::VertexHandle >::iterator connectivity)
void test_read_unstructured ()
void test_read_unstructured (const char *filename)
void test_read_structured_2d_points ()
void test_read_structured_3d_points ()
void test_read_structured_grid ()
void test_read_rectilinear_grid ()
void test_read_simple_scalar_attrib ()
void test_read_vector_attrib ()
void test_read_field_attrib ()
void test_write_field_attrib ()
void check_field_attrib (const char *file)
void test_read_fixed_attrib ()
void test_write ()
void test_read_quadratic ()
void test_read_quadratic (const char *filename)
void test_write_quadratic ()
void test_elements ()
int tri_check_validity (const MBMesquite::MsqMeshEntity *element_array, size_t num_elements, const MBMesquite::MsqVertex *vtx_array, size_t num_vertices)
int tet_validity_check (const MBMesquite::MsqMeshEntity *element_array, size_t num_elements, const MBMesquite::MsqVertex *vtx_array)

Private Member Functions

 CPPUNIT_TEST_SUITE (VtkTest)
 CPPUNIT_TEST (test_elements)
 CPPUNIT_TEST (test_read_unstructured)
 CPPUNIT_TEST (test_read_structured_2d_points)
 CPPUNIT_TEST (test_read_structured_3d_points)
 CPPUNIT_TEST (test_read_structured_grid)
 CPPUNIT_TEST (test_read_rectilinear_grid)
 CPPUNIT_TEST (test_read_simple_scalar_attrib)
 CPPUNIT_TEST (test_read_vector_attrib)
 CPPUNIT_TEST (test_read_field_attrib)
 CPPUNIT_TEST (test_write_field_attrib)
 CPPUNIT_TEST (test_read_fixed_attrib)
 CPPUNIT_TEST (test_read_quadratic)
 CPPUNIT_TEST (test_write_quadratic)
 CPPUNIT_TEST (test_write)
 CPPUNIT_TEST_SUITE_END ()

Detailed Description

Definition at line 312 of file mesquite/unit/VtkTest.cpp.


Constructor & Destructor Documentation

VtkTest::VtkTest ( ) [inline]

Definition at line 347 of file mesquite/unit/VtkTest.cpp.

{}

Member Function Documentation

void VtkTest::check_4quad_block ( Mesh mesh,
std::vector< Mesh::VertexHandle >::iterator  connectivity 
)

Definition at line 485 of file mesquite/unit/VtkTest.cpp.

References CPPUNIT_ASSERT, MBMesquite::Mesh::vertices_get_coordinates(), and MBMesquite::Vector3D::within_tolerance_box().

Referenced by check_4quad_structured(), and test_read_unstructured().

{
    MsqPrintError err( cout );
    const int base_corners[]   = { 0, 1, 3, 4 };
    const int corner_offsets[] = { 0, 1, 4, 3 };
    for( int quad = 0; quad < 4; ++quad )
    {
        for( int node = 0; node < 4; ++node )
        {
            const int index = base_corners[quad] + corner_offsets[node];
            const int x     = index % 3;
            const int y     = index / 3;
            const Vector3D expected_coords( 1.5 * x, 1.5 * y, 0.0 );
            MsqVertex actual_coords;
            Mesh::VertexHandle* conn_ptr = &*connectivity;
            ++connectivity;
            mesh.vertices_get_coordinates( conn_ptr, &actual_coords, 1, err );
            CPPUNIT_ASSERT( !err );
            CPPUNIT_ASSERT( expected_coords.within_tolerance_box( actual_coords, DBL_EPSILON ) );
        }
    }
}

Definition at line 463 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, check_4quad_block(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::Mesh::elements_get_attached_vertices(), and MBMesquite::Mesh::get_all_elements().

Referenced by test_read_structured_2d_points().

{
    MsqPrintError err( cout );

    std::vector< Mesh::ElementHandle > elems( 4 );
    std::vector< Mesh::VertexHandle > verts( 9 );
    std::vector< size_t > offsets( 5 );

    mesh.get_all_elements( elems, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), (size_t)4 );

    mesh.elements_get_attached_vertices( arrptr( elems ), elems.size(), verts, offsets, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( verts.size() == 16 );
    CPPUNIT_ASSERT( offsets.size() == 5 );

    check_4quad_block( mesh, verts.begin() );
}
void VtkTest::check_8hex_block ( Mesh mesh,
std::vector< Mesh::VertexHandle >::iterator  connectivity 
)

Definition at line 436 of file mesquite/unit/VtkTest.cpp.

References CPPUNIT_ASSERT, MBMesquite::Mesh::vertices_get_coordinates(), MBMesquite::Vector3D::within_tolerance_box(), and z.

Referenced by check_8hex_structured(), and test_read_unstructured().

{
    MsqPrintError err( cout );
    const int base_corners[]   = { 0, 1, 3, 4, 9, 10, 12, 13 };
    const int corner_offsets[] = { 0, 1, 4, 3, 9, 10, 13, 12 };

    for( int hex = 0; hex < 8; ++hex )
    {
        for( int node = 0; node < 8; ++node )
        {
            const int index = base_corners[hex] + corner_offsets[node];
            const int x     = index % 3;
            const int y     = ( index / 3 ) % 3;
            const int z     = index / 9;
            const Vector3D expected_coords( 1.5 * x, 1.5 * y, 1.5 * z );
            MsqVertex actual_coords;
            Mesh::VertexHandle* conn_ptr = &*connectivity;
            ++connectivity;
            mesh.vertices_get_coordinates( conn_ptr, &actual_coords, 1, err );
            CPPUNIT_ASSERT( !err );
            CPPUNIT_ASSERT( expected_coords.within_tolerance_box( actual_coords, DBL_EPSILON ) );
        }
    }
}

Definition at line 414 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, check_8hex_block(), CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::Mesh::elements_get_attached_vertices(), and MBMesquite::Mesh::get_all_elements().

Referenced by test_read_rectilinear_grid(), test_read_structured_3d_points(), and test_read_structured_grid().

{
    MsqPrintError err( cout );

    std::vector< Mesh::ElementHandle > elems( 8 );
    std::vector< Mesh::VertexHandle > verts( 64 );
    std::vector< size_t > offsets( 9 );

    mesh.get_all_elements( elems, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), (size_t)8 );

    mesh.elements_get_attached_vertices( arrptr( elems ), elems.size(), verts, offsets, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT( verts.size() == 64 );
    CPPUNIT_ASSERT( offsets.size() == 9 );

    check_8hex_block( mesh, verts.begin() );
}
void VtkTest::check_field_attrib ( const char *  file)

Definition at line 713 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::MeshImpl::get_all_elements(), INT, mesh, MBMesquite::MeshImpl::read_vtk(), MBMesquite::MeshImpl::tag_get(), MBMesquite::MeshImpl::tag_get_element_data(), and MBMesquite::MeshImpl::tag_properties().

Referenced by test_read_field_attrib(), and test_write_field_attrib().

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    std::vector< Mesh::ElementHandle > elems;
    mesh.get_all_elements( elems, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), (size_t)8 );

    std::string name;
    Mesh::TagType type;
    unsigned tagsize;

    void* th = mesh.tag_get( "test_field elem_vects", err );
    CPPUNIT_ASSERT( !err );

    mesh.tag_properties( th, name, type, tagsize, err );
    CPPUNIT_ASSERT( !err && type == Mesh::DOUBLE && tagsize == 3 );

    double elem_data[24];
    mesh.tag_get_element_data( th, 8, arrptr( elems ), elem_data, err );
    CPPUNIT_ASSERT( !err );

    for( int i = 0; i < 8; ++i )
        CPPUNIT_ASSERT( Vector3D( elem_data + 3 * i ) == Vector3D( i + 1, i + 1, i + 1 ) );

    th = mesh.tag_get( "test_field elem_ids", err );
    CPPUNIT_ASSERT( !err );

    mesh.tag_properties( th, name, type, tagsize, err );
    CPPUNIT_ASSERT( !err && type == Mesh::INT && tagsize == 1 );

    int elem_ids[8];
    mesh.tag_get_element_data( th, 8, arrptr( elems ), elem_ids, err );
    CPPUNIT_ASSERT( !err );

    for( int i = 0; i < 8; ++i )
        CPPUNIT_ASSERT( elem_ids[i] == i + 1 );

    th = mesh.tag_get( "field1", err );
    CPPUNIT_ASSERT( !err );

    mesh.tag_properties( th, name, type, tagsize, err );
    CPPUNIT_ASSERT( !err && type == Mesh::INT && tagsize == 1 );

    int values[8];
    mesh.tag_get_element_data( th, 8, arrptr( elems ), values, err );
    CPPUNIT_ASSERT( !err );

    for( int i = 0; i < 8; ++i )
        CPPUNIT_ASSERT( values[i] == 8 - i );
}
void VtkTest::setUp ( ) [inline]

Definition at line 341 of file mesquite/unit/VtkTest.cpp.

{}
void VtkTest::tearDown ( ) [inline]

Definition at line 344 of file mesquite/unit/VtkTest.cpp.

{}

Definition at line 1046 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, CPPUNIT_ASSERT, MBMesquite::PatchData::get_element_array(), MBMesquite::PatchIterator::get_next_patch(), MBMesquite::PatchData::get_vertex_array(), MBMesquite::Instruction::initialize_vertex_byte(), MBMesquite::PatchData::num_elements(), MBMesquite::PatchData::num_free_vertices(), MBMesquite::PatchData::num_nodes(), MBMesquite::MeshImpl::read_vtk(), MBMesquite::PatchSet::set_mesh(), MBMesquite::PatchData::set_mesh(), and tri_check_validity().

{
    MBMesquite::MsqPrintError err( cout );
    MeshImpl mMesh;
    mMesh.read_vtk( MESH_FILES_DIR "2D/vtk/tris/untangled/equil_tri2.vtk", err );
    ASSERT_NO_ERROR( err );
    MBMesquite::MeshDomainAssoc mesh_and_domain = MBMesquite::MeshDomainAssoc( &mMesh, 0 );
    MBMesquite::Instruction::initialize_vertex_byte( &mesh_and_domain, 0, err );
    ASSERT_NO_ERROR( err );

    // Retrieve a patch
    MBMesquite::PatchData pd;
    pd.set_mesh( &mMesh );
    VertexPatches patch_set;
    patch_set.set_mesh( &mMesh );
    PatchIterator patches( &patch_set );
    patches.get_next_patch( pd, err );
    ASSERT_NO_ERROR( err );

    int free_vtx = pd.num_free_vertices();
    //    std::cout << "nb of free vertices: " << free_vtx << std::endl;
    CPPUNIT_ASSERT( free_vtx == 1 );

    MBMesquite::MsqMeshEntity* element_array = pd.get_element_array( err );
    ASSERT_NO_ERROR( err );
    size_t num_elements = pd.num_elements();
    CPPUNIT_ASSERT( num_elements == 6 );

    const MBMesquite::MsqVertex* vtx_array = pd.get_vertex_array( err );
    ASSERT_NO_ERROR( err );
    size_t num_vertices = pd.num_nodes();
    CPPUNIT_ASSERT( num_vertices == 7 );

    CPPUNIT_ASSERT( tri_check_validity( element_array, num_elements, vtx_array, num_vertices ) == 1 );

    patches.get_next_patch( pd, err );
    ASSERT_NO_ERROR( err );

    element_array = pd.get_element_array( err );
    ASSERT_NO_ERROR( err );
    num_elements = pd.num_elements();
    CPPUNIT_ASSERT( num_elements == 6 );

    vtx_array = pd.get_vertex_array( err );
    ASSERT_NO_ERROR( err );
    num_vertices = pd.num_nodes();
    CPPUNIT_ASSERT( num_vertices == 7 );

    CPPUNIT_ASSERT( tri_check_validity( element_array, num_elements, vtx_array, num_vertices ) == 1 );
}

Definition at line 704 of file mesquite/unit/VtkTest.cpp.

References check_field_attrib(), simple_field_attrib, structured_3d_points_data, and temp_file_name.

{
    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_3d_points_data, file );
    fputs( simple_field_attrib, file );
    fclose( file );
    check_field_attrib( temp_file_name );
}

Definition at line 799 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::MeshImpl::elements_get_attached_vertices(), fixed, fixed_vertex_attrib, MBMesquite::MeshImpl::get_all_elements(), mesh, MBMesquite::MeshImpl::read_vtk(), structured_3d_points_data, temp_file_name, and MBMesquite::MeshImpl::vertices_get_fixed_flag().

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_3d_points_data, file );
    fputs( fixed_vertex_attrib, file );
    fclose( file );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    std::vector< Mesh::ElementHandle > elems;
    mesh.get_all_elements( elems, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), (size_t)8 );

    std::vector< Mesh::VertexHandle > verts;
    std::vector< size_t > offsets;
    mesh.elements_get_attached_vertices( arrptr( elems ), elems.size(), verts, offsets, err );
    ASSERT_NO_ERROR( err );

    // get unique list of vertices
    std::vector< Mesh::VertexHandle >::iterator new_end;
    std::sort( verts.begin(), verts.end() );
    new_end = std::unique( verts.begin(), verts.end() );
    verts.resize( new_end - verts.begin() );
    CPPUNIT_ASSERT_EQUAL( verts.size(), (size_t)27 );

    // get fixed flag
    std::vector< bool > fixed;
    mesh.vertices_get_fixed_flag( arrptr( verts ), fixed, verts.size(), err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( verts.size(), fixed.size() );

    for( int i = 0; i < 27; ++i )
    {
        bool should_be_fixed = ( i != 13 );
        CPPUNIT_ASSERT_EQUAL( should_be_fixed, (bool)fixed[i] );
    }
}

Definition at line 873 of file mesquite/unit/VtkTest.cpp.

References CPPUNIT_ASSERT, quadratic_unstructured_data, and temp_file_name.

Referenced by test_write_quadratic().

{
    FILE* file = fopen( temp_file_name, "w+" );
    CPPUNIT_ASSERT( file );
    int rval = fputs( quadratic_unstructured_data, file );
    fclose( file );
    if( rval == EOF ) remove( temp_file_name );
    CPPUNIT_ASSERT( rval != EOF );

    test_read_quadratic( temp_file_name );
    remove( temp_file_name );
}
void VtkTest::test_read_quadratic ( const char *  filename)

Definition at line 886 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, conn, corners, CPPUNIT_ASSERT, CPPUNIT_ASSERT_DOUBLES_EQUAL, CPPUNIT_ASSERT_EQUAL, edges, MBMesquite::MeshImpl::elements_get_attached_vertices(), MBMesquite::MeshImpl::elements_get_topologies(), MBMesquite::faces, MBMesquite::MeshImpl::get_all_elements(), hex_corners, hex_faces, MBMesquite::HEXAHEDRON, MBMesquite::Vector3D::length(), mesh, NUM_ELEM, MBMesquite::PRISM, MBMesquite::PYRAMID, MBMesquite::QUADRILATERAL, MBMesquite::MeshImpl::read_vtk(), MBMesquite::TETRAHEDRON, MBMesquite::TRIANGLE, u, and MBMesquite::MeshImpl::vertices_get_coordinates().

{
    const size_t NUM_ELEM = 8;

    MeshImpl mesh;
    MsqPrintError err( cout );

    mesh.read_vtk( filename, err );
    ASSERT_NO_ERROR( err );

    std::vector< Mesh::ElementHandle > elems( NUM_ELEM );
    mesh.get_all_elements( elems, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), NUM_ELEM );

    std::vector< Mesh::VertexHandle > conn;
    std::vector< size_t > offsets;
    mesh.elements_get_attached_vertices( arrptr( elems ), elems.size(), conn, offsets, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( conn.size(), (size_t)108 );

    EntityTopology types[NUM_ELEM];
    mesh.elements_get_topologies( arrptr( elems ), types, NUM_ELEM, err );
    ASSERT_NO_ERROR( err );

    static const double hex_corners[] = { 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0,
                                          1.0, -1.0, 1.0,  1.0, 1.0, 1.0,  -1.0, 1.0, 1.0,  -1.0, -1.0, 1.0 };
    static const double tet_corners[] = { 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0 };
    static const double pyr_corners[] = { 1.0,  -1.0, -1.0, 1.0,  1.0, -1.0, -1.0, 1.0,
                                          -1.0, -1.0, -1.0, -1.0, 0.0, 0.0,  1.0 };
    static const double pri_corners[] = { -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0,
                                          -1.0, -1.0, 1.0,  1.0, 1.0, 1.0,  -1.0, 1.0, 1.0 };
    static const unsigned hex_edges[] = { 0, 1, 1, 2, 2, 3, 3, 0, 0, 4, 1, 5, 2, 6, 3, 7, 4, 5, 5, 6, 6, 7, 7, 4 };
    static const unsigned tet_edges[] = { 0, 1, 1, 2, 2, 0, 0, 3, 1, 3, 2, 3 };
    static const unsigned pri_edges[] = { 0, 1, 1, 2, 2, 0, 0, 3, 1, 4, 2, 5, 3, 4, 4, 5, 5, 3 };
    static const unsigned pyr_edges[] = { 0, 1, 1, 2, 2, 3, 3, 0, 0, 4, 1, 4, 2, 4, 3, 4 };
    static const unsigned hex_faces[] = { 4, 0, 1, 5, 4, 4, 1, 2, 6, 5, 4, 2, 3, 7, 6,
                                          4, 3, 0, 4, 7, 4, 3, 2, 1, 0, 4, 4, 5, 6, 7 };
    static const struct
    {
        EntityTopology topology;
        unsigned num_corners;
        unsigned num_edges;
        unsigned num_faces;   // if non-zero expect mid-face nodes
        unsigned num_region;  // if non-zero expect mid-region node
        const double* corners;
        const unsigned* edges;
        const unsigned* faces;
    } expected_elems[NUM_ELEM] = { { MBMesquite::HEXAHEDRON, 8, 12, 0, 0, hex_corners, hex_edges, hex_faces },
                                   { MBMesquite::HEXAHEDRON, 8, 12, 6, 1, hex_corners, hex_edges, hex_faces },
                                   { MBMesquite::TETRAHEDRON, 4, 6, 0, 0, tet_corners, tet_edges, 0 },
                                   { MBMesquite::QUADRILATERAL, 4, 4, 0, 0, hex_corners, hex_edges, 0 },
                                   { MBMesquite::QUADRILATERAL, 4, 4, 0, 1, hex_corners, hex_edges, 0 },
                                   { MBMesquite::TRIANGLE, 3, 3, 0, 0, tet_corners, tet_edges, 0 },
                                   { MBMesquite::PRISM, 6, 9, 0, 0, pri_corners, pri_edges, 0 },
                                   { MBMesquite::PYRAMID, 5, 8, 0, 0, pyr_corners, pyr_edges, 0 } };

    MsqVertex have;
    std::vector< Mesh::VertexHandle >::iterator v_it = conn.begin();
    for( unsigned i = 0; i < NUM_ELEM; ++i )
    {
        CPPUNIT_ASSERT_EQUAL( expected_elems[i].topology, types[i] );

        size_t vtx_start = offsets[i];
        size_t vtx_end   = offsets[i + 1];
        size_t conn_len  = expected_elems[i].num_corners + expected_elems[i].num_edges + expected_elems[i].num_faces +
                          expected_elems[i].num_region;
        CPPUNIT_ASSERT_EQUAL( conn_len, vtx_end - vtx_start );

        for( unsigned c = 0; c < expected_elems[i].num_corners; ++c, ++v_it )
        {
            Vector3D expected( expected_elems[i].corners + 3 * c );
            mesh.vertices_get_coordinates( &*v_it, &have, 1, err );
            ASSERT_NO_ERROR( err );
            expected -= have;
            CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, expected.length(), DBL_EPSILON );
        }

        for( unsigned m = 0; m < expected_elems[i].num_edges; ++m, ++v_it )
        {
            unsigned start_idx = expected_elems[i].edges[2 * m];
            unsigned end_idx   = expected_elems[i].edges[2 * m + 1];
            Vector3D start( expected_elems[i].corners + 3 * start_idx );
            Vector3D end( expected_elems[i].corners + 3 * end_idx );
            Vector3D expected = 0.5 * ( start + end );

            mesh.vertices_get_coordinates( &*v_it, &have, 1, err );
            ASSERT_NO_ERROR( err );

            expected -= have;
            CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, expected.length(), DBL_EPSILON );
        }

        const unsigned* f_it = expected_elems[i].faces;
        for( unsigned m = 0; m < expected_elems[i].num_faces; ++m, ++v_it )
        {
            Vector3D expected( 0, 0, 0 );
            const unsigned face_size = *f_it;
            ++f_it;
            CPPUNIT_ASSERT( face_size == 3u || face_size == 4u );
            for( unsigned f = 0; f < face_size; ++f, ++f_it )
                expected += Vector3D( expected_elems[i].corners + 3 * *f_it );
            expected /= face_size;

            mesh.vertices_get_coordinates( &*v_it, &have, 1, err );
            ASSERT_NO_ERROR( err );

            expected -= have;
            CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, expected.length(), DBL_EPSILON );
        }

        if( expected_elems[i].num_region )
        {
            CPPUNIT_ASSERT_EQUAL( 1u, expected_elems[i].num_region );

            Vector3D expected( 0, 0, 0 );
            for( unsigned m = 0; m < expected_elems[i].num_corners; ++m )
                expected += Vector3D( expected_elems[i].corners + 3 * m );
            expected /= expected_elems[i].num_corners;

            mesh.vertices_get_coordinates( &*v_it, &have, 1, err );
            ASSERT_NO_ERROR( err );

            expected -= have;
            CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, expected.length(), DBL_EPSILON );

            ++v_it;
        }
    }
}

Definition at line 613 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, check_8hex_structured(), mesh, MBMesquite::MeshImpl::read_vtk(), rectilinear_grid_data, and temp_file_name.

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    FILE* file = fopen( temp_file_name, "w+" );
    fputs( rectilinear_grid_data, file );
    fclose( file );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    check_8hex_structured( mesh );
}

Definition at line 630 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::MeshImpl::get_all_elements(), INT, mesh, MBMesquite::MeshImpl::read_vtk(), simple_scalar_attrib, structured_3d_points_data, MBMesquite::MeshImpl::tag_get(), MBMesquite::MeshImpl::tag_get_element_data(), MBMesquite::MeshImpl::tag_properties(), and temp_file_name.

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_3d_points_data, file );
    fputs( simple_scalar_attrib, file );
    fclose( file );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    std::vector< Mesh::ElementHandle > elems;
    mesh.get_all_elements( elems, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), (size_t)8 );

    void* th = mesh.tag_get( "global_id", err );
    CPPUNIT_ASSERT( !err );

    std::string name;
    Mesh::TagType type;
    unsigned tagsize;
    mesh.tag_properties( th, name, type, tagsize, err );
    CPPUNIT_ASSERT( !err && type == Mesh::INT && tagsize == 1 );

    int elem_data[8];
    mesh.tag_get_element_data( th, 8, arrptr( elems ), elem_data, err );
    CPPUNIT_ASSERT( !err );

    for( int i = 0; i < 8; ++i )
        CPPUNIT_ASSERT( elem_data[i] == ( 1 + i ) );
}

Definition at line 562 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, check_4quad_structured(), mesh, MBMesquite::MeshImpl::read_vtk(), structured_2d_points_data, and temp_file_name.

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_2d_points_data, file );
    fclose( file );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    check_4quad_structured( mesh );
}

Definition at line 579 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, check_8hex_structured(), mesh, MBMesquite::MeshImpl::read_vtk(), structured_3d_points_data, and temp_file_name.

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_3d_points_data, file );
    fclose( file );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    check_8hex_structured( mesh );
}

Definition at line 596 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, check_8hex_structured(), mesh, MBMesquite::MeshImpl::read_vtk(), structured_grid_data, and temp_file_name.

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_grid_data, file );
    fclose( file );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    check_8hex_structured( mesh );
}

Definition at line 509 of file mesquite/unit/VtkTest.cpp.

References CPPUNIT_ASSERT, mixed_unstructured_data, and temp_file_name.

Referenced by test_write().

{
    FILE* file = fopen( temp_file_name, "w+" );
    CPPUNIT_ASSERT( file );
    int rval = fputs( mixed_unstructured_data, file );
    fclose( file );
    if( rval == EOF ) remove( temp_file_name );
    CPPUNIT_ASSERT( rval != EOF );

    test_read_unstructured( temp_file_name );
}
void VtkTest::test_read_unstructured ( const char *  filename)

Definition at line 521 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, check_4quad_block(), check_8hex_block(), conn, CPPUNIT_ASSERT_EQUAL, MBMesquite::MeshImpl::elements_get_attached_vertices(), MBMesquite::MeshImpl::get_all_elements(), MBMesquite::HEXAHEDRON, mesh, MBMesquite::MIXED, MBMesquite::PRISM, MBMesquite::PYRAMID, MBMesquite::QUADRILATERAL, MBMesquite::MeshImpl::read_vtk(), MBMesquite::TETRAHEDRON, and MBMesquite::TRIANGLE.

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    mesh.read_vtk( filename, err );
    ASSERT_NO_ERROR( err );

    // Get mesh data
    std::vector< Mesh::VertexHandle > conn;
    std::vector< Mesh::ElementHandle > elems( 38 );
    std::vector< size_t > offsets( 39 );
    mesh.get_all_elements( elems, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), (size_t)38 );
    mesh.elements_get_attached_vertices( arrptr( elems ), elems.size(), conn, offsets, err );
    ASSERT_NO_ERROR( err );

    unsigned i;
    struct meshdata
    {
        EntityTopology type;
        size_t nodes;
        size_t count;
    };
    meshdata list[] = { { MBMesquite::HEXAHEDRON, 8, 8 }, { MBMesquite::QUADRILATERAL, 4, 4 },
                        { MBMesquite::PYRAMID, 5, 4 },    { MBMesquite::TETRAHEDRON, 4, 6 },
                        { MBMesquite::TRIANGLE, 3, 14 },  { MBMesquite::PRISM, 6, 2 },
                        { MBMesquite::MIXED, 0, 0 } };

    // Count expected lenght of connectivity list
    size_t conn_len = 0;
    for( i = 0; list[i].nodes; ++i )
        conn_len += list[i].nodes * list[i].count;
    CPPUNIT_ASSERT_EQUAL( conn_len, conn.size() );

    check_8hex_block( mesh, conn.begin() );
    check_4quad_block( mesh, conn.begin() + 64 );
}

Definition at line 667 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::arrptr(), ASSERT_NO_ERROR, CPPUNIT_ASSERT, CPPUNIT_ASSERT_EQUAL, MBMesquite::MeshImpl::get_all_elements(), mesh, MBMesquite::MeshImpl::read_vtk(), simple_vector_attrib, structured_3d_points_data, MBMesquite::MeshImpl::tag_get(), MBMesquite::MeshImpl::tag_get_element_data(), MBMesquite::MeshImpl::tag_properties(), and temp_file_name.

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_3d_points_data, file );
    fputs( simple_vector_attrib, file );
    fclose( file );

    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    std::vector< Mesh::ElementHandle > elems;
    mesh.get_all_elements( elems, err );
    CPPUNIT_ASSERT( !err );
    CPPUNIT_ASSERT_EQUAL( elems.size(), (size_t)8 );

    void* th = mesh.tag_get( "hexvect", err );
    CPPUNIT_ASSERT( !err );

    std::string name;
    Mesh::TagType type;
    unsigned tagsize;
    mesh.tag_properties( th, name, type, tagsize, err );
    CPPUNIT_ASSERT( !err && type == Mesh::DOUBLE && tagsize == 3 );

    double elem_data[24];
    mesh.tag_get_element_data( th, 8, arrptr( elems ), elem_data, err );
    CPPUNIT_ASSERT( !err );

    for( int i = 0; i < 8; ++i )
        CPPUNIT_ASSERT( Vector3D( elem_data + 3 * i ) == Vector3D( i + 1, i + 1, i + 1 ) );
}

Definition at line 844 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, CPPUNIT_ASSERT, mesh, mixed_unstructured_data, MBMesquite::MeshImpl::read_vtk(), temp_file_name, test_read_unstructured(), and MBMesquite::MeshImpl::write_vtk().

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    // Create file containing unstructured mesh test case
    FILE* file = fopen( temp_file_name, "w+" );
    CPPUNIT_ASSERT( file );
    int rval = fputs( mixed_unstructured_data, file );
    fclose( file );
    if( rval == EOF ) remove( temp_file_name );
    CPPUNIT_ASSERT( rval != EOF );

    // Read unstructured mesh file
    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    // Write unstructured mesh file back out
    mesh.write_vtk( temp_file_name, err );
    if( err ) remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    // Check if file contained expected mesh
    test_read_unstructured( temp_file_name );
    remove( temp_file_name );
}

Definition at line 772 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, check_field_attrib(), mesh, MBMesquite::MeshImpl::read_vtk(), simple_field_attrib, structured_3d_points_data, temp_file_name, and MBMesquite::MeshImpl::write_vtk().

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    // Create file containing unstructured mesh test case
    FILE* file = fopen( temp_file_name, "w+" );
    fputs( structured_3d_points_data, file );
    fputs( simple_field_attrib, file );
    fclose( file );

    // Read unstructured mesh file
    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    // Write unstructured mesh file back out
    mesh.write_vtk( temp_file_name, err );
    if( err ) remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    // Check if file contained expected mesh
    check_field_attrib( temp_file_name );
}

Definition at line 1018 of file mesquite/unit/VtkTest.cpp.

References ASSERT_NO_ERROR, CPPUNIT_ASSERT, mesh, quadratic_unstructured_data, MBMesquite::MeshImpl::read_vtk(), temp_file_name, test_read_quadratic(), and MBMesquite::MeshImpl::write_vtk().

{
    MeshImpl mesh;
    MsqPrintError err( cout );

    // Create file containing unstructured mesh test case
    FILE* file = fopen( temp_file_name, "w+" );
    CPPUNIT_ASSERT( file );
    int rval = fputs( quadratic_unstructured_data, file );
    fclose( file );
    if( rval == EOF ) remove( temp_file_name );
    CPPUNIT_ASSERT( rval != EOF );

    // Read unstructured mesh file
    mesh.read_vtk( temp_file_name, err );
    remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    // Write unstructured mesh file back out
    mesh.write_vtk( temp_file_name, err );
    if( err ) remove( temp_file_name );
    ASSERT_NO_ERROR( err );

    // Check if file contained expected mesh
    test_read_quadratic( temp_file_name );
    remove( temp_file_name );
}
int VtkTest::tet_validity_check ( const MBMesquite::MsqMeshEntity element_array,
size_t  num_elements,
const MBMesquite::MsqVertex vtx_array 
)

Definition at line 1138 of file mesquite/unit/VtkTest.cpp.

References MBMesquite::MsqMeshEntity::get_vertex_indices().

{
    int valid   = 1;
    double dEps = 1.e-13;
    double x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4;
    std::vector< size_t > vertex_indices;

    for( size_t i = 0; i < num_elements; i++ )
    {
        element_array[i].get_vertex_indices( vertex_indices );

        x1 = vtx_array[vertex_indices[0]][0];
        y1 = vtx_array[vertex_indices[0]][1];
        z1 = vtx_array[vertex_indices[0]][2];

        x2 = vtx_array[vertex_indices[1]][0];
        y2 = vtx_array[vertex_indices[1]][1];
        z2 = vtx_array[vertex_indices[1]][2];

        x3 = vtx_array[vertex_indices[2]][0];
        y3 = vtx_array[vertex_indices[2]][1];
        z3 = vtx_array[vertex_indices[2]][2];

        x4 = vtx_array[vertex_indices[3]][0];
        y4 = vtx_array[vertex_indices[3]][1];
        z4 = vtx_array[vertex_indices[3]][2];

        double dDX2 = x2 - x1;
        double dDX3 = x3 - x1;
        double dDX4 = x4 - x1;

        double dDY2 = y2 - y1;
        double dDY3 = y3 - y1;
        double dDY4 = y4 - y1;

        double dDZ2 = z2 - z1;
        double dDZ3 = z3 - z1;
        double dDZ4 = z4 - z1;

        /* dDet is proportional to the cell volume */
        double dDet = dDX2 * dDY3 * dDZ4 + dDX3 * dDY4 * dDZ2 + dDX4 * dDY2 * dDZ3 - dDZ2 * dDY3 * dDX4 -
                      dDZ3 * dDY4 * dDX2 - dDZ4 * dDY2 * dDX3;

        /* Compute a length scale based on edge lengths. */
        double dScale = ( sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) + ( z1 - z2 ) * ( z1 - z2 ) ) +
                          sqrt( ( x1 - x3 ) * ( x1 - x3 ) + ( y1 - y3 ) * ( y1 - y3 ) + ( z1 - z3 ) * ( z1 - z3 ) ) +
                          sqrt( ( x1 - x4 ) * ( x1 - x4 ) + ( y1 - y4 ) * ( y1 - y4 ) + ( z1 - z4 ) * ( z1 - z4 ) ) +
                          sqrt( ( x2 - x3 ) * ( x2 - x3 ) + ( y2 - y3 ) * ( y2 - y3 ) + ( z2 - z3 ) * ( z2 - z3 ) ) +
                          sqrt( ( x2 - x4 ) * ( x2 - x4 ) + ( y2 - y4 ) * ( y2 - y4 ) + ( z2 - z4 ) * ( z2 - z4 ) ) +
                          sqrt( ( x3 - x4 ) * ( x3 - x4 ) + ( y3 - y4 ) * ( y3 - y4 ) + ( z3 - z4 ) * ( z3 - z4 ) ) ) /
                        6.;

        /* Use the length scale to get a better idea if the tet is flat or
           just really small. */
        if( fabs( dScale ) < dEps ) { return ( valid = 0 ); }
        else
        {
            dDet /= ( dScale * dScale * dScale );
        }

        if( dDet > dEps ) { valid = 1; }
        else if( dDet < -dEps )
        {
            valid = -1;
        }
        else
        {
            valid = 0;
        }
    }  // end for i=1,numElements

    return ( valid );
}
int VtkTest::tri_check_validity ( const MBMesquite::MsqMeshEntity element_array,
size_t  num_elements,
const MBMesquite::MsqVertex vtx_array,
size_t  num_vertices 
)

Definition at line 1097 of file mesquite/unit/VtkTest.cpp.

References b, and MBMesquite::MsqMeshEntity::get_vertex_indices().

Referenced by test_elements().

{

    /* check that the simplicial mesh is still valid,
       based on right handedness. Returns a 1 or a 0 */
    int valid   = 1;
    double dEps = 1.e-13;

    double x1, x2, x3, y1, y2, y3;  // z1, z2, z3;
    std::vector< size_t > vertex_indices;

    for( size_t i = 0; i < num_elements; i++ )
    {
        element_array[i].get_vertex_indices( vertex_indices );

        x1 = vtx_array[vertex_indices[0]][0];
        y1 = vtx_array[vertex_indices[0]][1];
        x2 = vtx_array[vertex_indices[1]][0];
        y2 = vtx_array[vertex_indices[1]][1];
        x3 = vtx_array[vertex_indices[2]][0];
        y3 = vtx_array[vertex_indices[2]][1];

        double a = x2 * y3 - x3 * y2;
        double b = y2 - y3;
        double c = x3 - x2;

        double area = .5 * ( a + b * x1 + c * y1 );
        if( area < dEps )
        {
            //          printf("x1 y1 = %f %f\n",x1,y1);
            //          printf("x2 y3 = %f %f\n",x2,y2);
            //          printf("x3 y3 = %f %f\n",x3,y3);
            //          printf("area = %f\n",area);
            valid = 0;
        }
    }

    return ( valid );
}

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