void VtkTest::check_field_attrib( const char* temp_file_name ) { 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 ); }
// Test reading Vtk vector attribute void VtkTest::test_read_vector_attrib() { 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 ) ); }
// Test reading Vtk simple (one-component) scalar attribute void VtkTest::test_read_simple_scalar_attrib() { 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) ); }