void TestMeshWriterWithDeletedNode() throw (Exception) { // Create mesh VertexMeshReader<2,2> mesh_reader("mesh/test/data/TestVertexMesh/honeycomb_vertex_mesh_3_by_3"); MutableVertexMesh<2,2> mesh; mesh.ConstructFromMeshReader(mesh_reader); TS_ASSERT_EQUALS(mesh.GetNumNodes(), 30u); TS_ASSERT_EQUALS(mesh.GetNumElements(), 9u); /* * Delete element 0. This element contains 3 nodes that are * not contained in any other element and so will be marked * as deleted. */ mesh.DeleteElementPriorToReMesh(0); // Write mesh to file VertexMeshWriter<2,2> mesh_writer("TestMeshWriterWithDeletedNode", "vertex_mesh"); TS_ASSERT_THROWS_NOTHING(mesh_writer.WriteFilesUsingMesh(mesh)); // Read mesh back in from file std::string output_dir = mesh_writer.GetOutputDirectory(); VertexMeshReader<2,2> mesh_reader2(output_dir + "vertex_mesh"); // We should have one less element and three less nodes TS_ASSERT_EQUALS(mesh_reader2.GetNumNodes(), 27u); TS_ASSERT_EQUALS(mesh_reader2.GetNumElements(), 8u); }
/** * Check that the elements are read correctly. Checks that the output vector * for a given input file is the correct length and that if the input file * is corrupted (missing elements) then an exception is thrown. */ void TestElementsDataRead() throw(Exception) { TrianglesMeshReader<2,2> mesh_reader("mesh/test/data/disk_984_elements_indexed_from_1"); TS_ASSERT_EQUALS( mesh_reader.GetNumElements(), 984u); ElementData data1 = mesh_reader.GetNextElementData(); TS_ASSERT_EQUALS(data1.NodeIndices.size(), 3u); TS_ASSERT_EQUALS(data1.NodeIndices[0], 309u); TS_ASSERT_EQUALS(data1.NodeIndices[1], 144u); TS_ASSERT_EQUALS(data1.NodeIndices[2], 310u); TS_ASSERT_EQUALS( mesh_reader.GetNumElementAttributes(), 0u); for (unsigned i=1; i<mesh_reader.GetNumElements(); i++) { ElementData data = mesh_reader.GetNextElementData(); TS_ASSERT_EQUALS(data.AttributeValue, 0u); } TrianglesMeshReader<2,2> mesh_reader2("mesh/test/data/baddata/bad_elements_disk_522_elements"); // Reads element 0 from file TS_ASSERT_THROWS_NOTHING(mesh_reader2.GetNextElementData()); // Reads element 2 from file when expecting number 1 TS_ASSERT_THROWS_THIS(mesh_reader2.GetNextElementData(),"Data for item 1 missing"); }
void TestReadingAndWritingElementAttributes() throw(Exception) { // Read in a mesh with element attributes VertexMeshReader<2,2> mesh_reader("mesh/test/data/TestVertexMeshReader2d/vertex_mesh_with_element_attributes"); TS_ASSERT_EQUALS(mesh_reader.GetNumElements(), 2u); TS_ASSERT_EQUALS(mesh_reader.GetNumElementAttributes(), 1u); // Construct the mesh VertexMesh<2,2> mesh; mesh.ConstructFromMeshReader(mesh_reader); TS_ASSERT_EQUALS(mesh.GetElement(0)->GetUnsignedAttribute(), 97u); TS_ASSERT_EQUALS(mesh.GetElement(1)->GetUnsignedAttribute(), 152u); // Write the mesh to file // Nested scope so the reader is destroyed before we try writing to the folder again { VertexMeshWriter<2,2> mesh_writer("TestReadingAndWritingElementAttributes", "vertex_mesh_with_element_attributes"); mesh_writer.WriteFilesUsingMesh(mesh); // Now read in the mesh that was written OutputFileHandler handler("TestReadingAndWritingElementAttributes", false); VertexMeshReader<2,2> mesh_reader2(handler.GetOutputDirectoryFullPath() + "vertex_mesh_with_element_attributes"); TS_ASSERT_EQUALS(mesh_reader2.GetNumElements(), 2u); TS_ASSERT_EQUALS(mesh_reader2.GetNumElementAttributes(), 1u); // Construct the mesh again VertexMesh<2,2> mesh2; mesh2.ConstructFromMeshReader(mesh_reader); TS_ASSERT_EQUALS(mesh2.GetElement(0)->GetUnsignedAttribute(), 97u); TS_ASSERT_EQUALS(mesh2.GetElement(1)->GetUnsignedAttribute(), 152u); } // For coverage, repeat this test for a vertex mesh whose elements have faces VertexMeshReader<3,3> mesh_reader3d("mesh/test/data/TestVertexMeshWriter/vertex_mesh_3d_with_faces_and_attributes"); TS_ASSERT_EQUALS(mesh_reader3d.GetNumElements(), 1u); TS_ASSERT_EQUALS(mesh_reader3d.GetNumElementAttributes(), 1u); // Construct the mesh VertexMesh<3,3> mesh3d; mesh3d.ConstructFromMeshReader(mesh_reader3d); TS_ASSERT_EQUALS(mesh3d.GetElement(0)->GetUnsignedAttribute(), 49u); // Write the mesh to file VertexMeshWriter<3,3> mesh_writer3d("TestReadingAndWritingElementAttributes", "vertex_mesh_3d_with_faces_and_attributes"); mesh_writer3d.WriteFilesUsingMesh(mesh3d); // Now read in the mesh that was written OutputFileHandler handler3d("TestReadingAndWritingElementAttributes", false); VertexMeshReader<3,3> mesh_reader3d2(handler3d.GetOutputDirectoryFullPath() + "vertex_mesh_3d_with_faces_and_attributes"); TS_ASSERT_EQUALS(mesh_reader3d2.GetNumElements(), 1u); TS_ASSERT_EQUALS(mesh_reader3d2.GetNumElementAttributes(), 1u); // Construct the mesh again VertexMesh<3,3> mesh3d2; mesh3d2.ConstructFromMeshReader(mesh_reader3d2); TS_ASSERT_EQUALS(mesh3d2.GetElement(0)->GetUnsignedAttribute(), 49u); }
void Test1DMeshIn2DSpace() throw(Exception) { TrianglesMeshReader<1,2> mesh_reader("mesh/test/data/circle_outline"); TS_ASSERT_EQUALS(mesh_reader.GetNumNodes(), 100u); TS_ASSERT_EQUALS(mesh_reader.GetNumElements(), 100u); // Note: don't test faces (end nodes), since they are culled later TrianglesMeshReader<1,2> mesh_reader2("mesh/test/data/semicircle_outline"); TS_ASSERT_EQUALS(mesh_reader2.GetNumNodes(), 51u); TS_ASSERT_EQUALS(mesh_reader2.GetNumElements(), 50u); }
/** * Check that the nodes are read correctly. Checks that the output vector * for a given input file is the correct length and that if the input file * is corrupted (missing nodes) then an exception is thrown. */ void TestNodesDataRead() throw(Exception) { TrianglesMeshReader<2,2> mesh_reader("mesh/test/data/disk_984_elements_indexed_from_1"); TS_ASSERT_EQUALS( mesh_reader.GetNumNodes(), 543u); TrianglesMeshReader<2,2> mesh_reader2("mesh/test/data/baddata/bad_nodes_disk_522_elements"); // Reads node 0 from file TS_ASSERT_THROWS_NOTHING(mesh_reader2.GetNextNode()); // Reads node 3 from file when expecting number 1 TS_ASSERT_THROWS_THIS(mesh_reader2.GetNextNode(),"Data for item 1 missing"); }
void Test2DMeshIn3DSpace() throw(Exception) { TrianglesMeshReader<2,3> mesh_reader("mesh/test/data/slab_395_elements"); TS_ASSERT_EQUALS(mesh_reader.GetNumNodes(), 132u); TS_ASSERT_EQUALS(mesh_reader.GetNumElements(), 224u); TS_ASSERT_EQUALS(mesh_reader.GetNumFaces(), 0u); TrianglesMeshReader<2,3> mesh_reader2("mesh/test/data/disk_in_3d"); TS_ASSERT_EQUALS(mesh_reader2.GetNumNodes(), 312u); TS_ASSERT_EQUALS(mesh_reader2.GetNumElements(), 522u); // TS_ASSERT_EQUALS(mesh_reader2.GetNumFaces(), 833u); // when all faces were read TS_ASSERT_EQUALS(mesh_reader2.GetNumFaces(), 100u); // just boundary faces are read }
/** * Check that the nodes are read correctly. Checks that the output vector * for a given input file is the correct length and that if the input file * is corrupted (missing nodes) then an exception is thrown. */ void TestNodesDataRead() throw(Exception) { VertexMeshReader<2,2> mesh_reader("mesh/test/data/TestVertexMeshWriter/vertex_mesh_2d"); TS_ASSERT_EQUALS(mesh_reader.GetNumNodes(), 7u); VertexMeshReader<2,2> mesh_reader2("mesh/test/data/baddata/vertex_mesh_bad_nodes"); // Reads node 0 from file TS_ASSERT_THROWS_NOTHING(mesh_reader2.GetNextNode()); // Reads node 3 from file when expecting number 1 TS_ASSERT_THROWS_THIS(mesh_reader2.GetNextNode(), "Data for node 1 missing"); }
void TestOtherExceptions() throw(Exception) { // This should fail because SPACE_DIM doesn't match the dimension in the file TS_ASSERT_THROWS_THIS( READER_1D mesh_reader("mesh/test/data/disk_984_elements"), "SPACE_DIM != dimension read from file "); //Indexed quadratic faces TS_ASSERT_THROWS_THIS( READER_1D mesh_reader2("mesh/test/data/baddata/bad_1D_0_to_1_10_elements_quadratic", 2, 2, true), "Boundary element file should not have containing element info if it is quadratic"); //Exceptions due to unimplemented code TrianglesMeshReader<3,3> mesh_reader3("mesh/test/data/simple_cube"); TS_ASSERT_THROWS_THIS(mesh_reader3.GetNode(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader3.GetElementData(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader3.GetFaceData(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader3.GetEdgeData(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader3.GetContainingElementIndices(0), "NCL file functionality is only implemented in mesh readers for binary mesh files."); }
/** * Check that the faces are read correctly. Checks that the output vector * for a given input file is the correct length and that if the input file * is corrupted (missing faces) then an exception is thrown. */ void TestFacesDataRead() throw(Exception) { TrianglesMeshReader<2,2> mesh_reader("mesh/test/data/disk_984_elements_indexed_from_1"); // TS_ASSERT_EQUALS( mesh_reader.GetNumFaces(), 1526u); // when all faces were read TS_ASSERT_EQUALS( mesh_reader.GetNumFaces(), 100u); // just boundary faces are read TS_ASSERT_EQUALS( mesh_reader.GetNumFaceAttributes(), 1u); for (unsigned i=1; i<mesh_reader.GetNumFaces(); i++) { ElementData data = mesh_reader.GetNextFaceData(); TS_ASSERT_EQUALS(data.AttributeValue, 1u); } // First boundary face is #20, on its way through the file there's a gap between face 1 and face 10 TS_ASSERT_THROWS_THIS(READER_2D mesh_reader2("mesh/test/data/baddata/bad_faces_disk_522_elements"),"Data for item 2 missing"); }
void TestExceptions() { // The file does not exist TS_ASSERT_THROWS_THIS( READER_3D mesh_reader("no_file"), "Could not open data file no_file.pts"); // We are in the wrong dimension TS_ASSERT_THROWS_THIS( READER_2D reader("mesh/test/data/Memfem_slab"), "You have asked to read non-3D data. All Memfem data is in 3D."); MemfemMeshReader<3,3> mesh_reader2("mesh/test/data/Memfem_slab"); TS_ASSERT_EQUALS(mesh_reader2.HasNodePermutation(), false); TS_ASSERT_THROWS_THIS(mesh_reader2.rGetNodePermutation(), "Node permutations aren't supported by this reader"); TS_ASSERT_THROWS_THIS(mesh_reader2.GetNode(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader2.GetElementData(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader2.GetFaceData(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader2.GetEdgeData(0), "Random access is only implemented in mesh readers for binary mesh files."); TS_ASSERT_THROWS_THIS(mesh_reader2.GetContainingElementIndices(0), "Ncl files are only implemented in mesh readers for binary mesh files."); }
/** * Check that the elements are read correctly. Checks that the output vector * for a given input file is the correct length and that if the input file * is corrupted (missing elements) then an exception is thrown. */ void TestElementsDataRead() throw(Exception) { VertexMeshReader<2,2> mesh_reader("mesh/test/data/TestVertexMeshWriter/vertex_mesh_2d"); TS_ASSERT_EQUALS(mesh_reader.GetNumElements(), 2u); // Read element 0 from file ElementData data1 = mesh_reader.GetNextElementData(); TS_ASSERT_EQUALS(data1.NodeIndices.size(), 5u); TS_ASSERT_EQUALS(data1.NodeIndices[0], 0u); TS_ASSERT_EQUALS(data1.NodeIndices[1], 1u); TS_ASSERT_EQUALS(data1.NodeIndices[2], 2u); TS_ASSERT_EQUALS(data1.NodeIndices[3], 3u); TS_ASSERT_EQUALS(data1.NodeIndices[4], 4u); // Read element 1 from file ElementData data2 = mesh_reader.GetNextElementData(); TS_ASSERT_EQUALS(data2.NodeIndices.size(), 3u); TS_ASSERT_EQUALS(data2.NodeIndices[0], 2u); TS_ASSERT_EQUALS(data2.NodeIndices[1], 5u); TS_ASSERT_EQUALS(data2.NodeIndices[2], 6u); TS_ASSERT_EQUALS(mesh_reader.GetNumElementAttributes(), 1u); mesh_reader.Reset(); for (unsigned i=1; i<mesh_reader.GetNumElements(); i++) { ElementData data = mesh_reader.GetNextElementData(); TS_ASSERT_EQUALS(data.AttributeValue, 0u); } VertexMeshReader<2,2> mesh_reader2("mesh/test/data/baddata/vertex_mesh_bad_elements"); // Reads element 0 from file TS_ASSERT_THROWS_NOTHING(mesh_reader2.GetNextElementData()); // Reads element 2 from file when expecting number 1 TS_ASSERT_THROWS_THIS(mesh_reader2.GetNextElementData(), "Data for element 1 missing"); }
/** * Check that GetNextElementDataWithFaces() works. Checks that no errors are thrown for * all of the elements and that an error is thrown if we try to call the * function too many times. */ void TestGetNextElementDataWithFaces() throw(Exception) { // First test the case where there aren't actually any faces VertexMeshReader<3,3> mesh_reader1("mesh/test/data/TestVertexMeshWriter/vertex_mesh_3d"); // This mesh should consist of a single cubic element with eight nodes and no faces TS_ASSERT_EQUALS(mesh_reader1.GetNumElements(), 1u); VertexElementData element_0_data = mesh_reader1.GetNextElementDataWithFaces(); // Test node indices std::vector<unsigned> node_indices = element_0_data.NodeIndices; TS_ASSERT_EQUALS(node_indices.size(), 8u); for (unsigned i=0; i<8; i++) { TS_ASSERT_EQUALS(node_indices[i], i); } // Test there aren't any faces std::vector<ElementData> faces = element_0_data.Faces; TS_ASSERT_EQUALS(faces.size(), 0u); // Test an exception is thrown if we try to access the next element TS_ASSERT_THROWS_THIS(node_indices = mesh_reader1.GetNextElementDataWithFaces().NodeIndices, "Cannot get the next line from node or element file due to incomplete data"); // Now test the case where there are faces VertexMeshReader<3,3> mesh_reader2("mesh/test/data/TestVertexMeshWriter/vertex_mesh_3d_with_faces"); // This mesh should consist of a single tetrahedral element with four nodes and four faces TS_ASSERT_EQUALS(mesh_reader2.GetNumElements(), 1u); element_0_data = mesh_reader2.GetNextElementDataWithFaces(); // Test there are four nodes owned by this element node_indices = element_0_data.NodeIndices; TS_ASSERT_EQUALS(node_indices.size(), 4u); // Test the node indices are correct (use a set comparison in case of funny business relating to tetgen versions) std::set<unsigned> node_indices_expected; std::set<unsigned> node_indices_returned; for (unsigned i=0; i<4; i++) { node_indices_expected.insert(i); node_indices_returned.insert(node_indices[i]); } TS_ASSERT_EQUALS(node_indices_expected, node_indices_returned); // Test there are four faces owned by this element faces = element_0_data.Faces; TS_ASSERT_EQUALS(faces.size(), 4u); // Test the first face has the correct index and owns the correct nodes ElementData face_0 = faces[0]; TS_ASSERT_EQUALS(face_0.NodeIndices.size(), 3u); TS_ASSERT_EQUALS(face_0.NodeIndices[0], 3u); TS_ASSERT_EQUALS(face_0.NodeIndices[1], 0u); TS_ASSERT_EQUALS(face_0.NodeIndices[2], 2u); // Test an exception is thrown if we try to access the next element TS_ASSERT_THROWS_THIS(node_indices = mesh_reader2.GetNextElementDataWithFaces().NodeIndices, "Cannot get the next line from node or element file due to incomplete data"); VertexMeshReader<3,3> mesh_reader3("mesh/test/data/baddata/vertex_mesh_3d_with_faces"); // Reads element 1 from file when expecting number 0 TS_ASSERT_THROWS_THIS(mesh_reader3.GetNextElementDataWithFaces(), "Data for element 0 missing"); }