コード例 #1
0
    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.");
    }
コード例 #2
0
    /**
     * 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");
    }