def test_properties_MultiPolyMesherIo(self):
        io = MultiPolyMesherIo(())
        self.assertIsInstance(io, MultiPolyMesherIo)

        io.check_topology = True
        self.assertEqual(True, io.check_topology)

        io.return_cell_polygons = False
        self.assertEqual(False, io.return_cell_polygons)

        points = ((1, 1, 2), (1, 2, 3), (2, 3, 4), (3, 4, 5))
        io.points = points
        self.assertArraysEqual(points, io.points)

        cells = (1, 5, 9, 13)
        io.cells = cells
        self.assertArraysEqual(cells, io.cells)

        cell_polygons = (2, 4)
        io.cell_polygons = cell_polygons
        self.assertArraysEqual(cell_polygons, io.cell_polygons)

        out_poly = ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0))
        pi1 = PolyInput(out_poly)
        pi1.bias = 2.718
        pi2 = PolyInput(out_poly)
        pi2.bias = 0.618
        io.poly_inputs = (pi1, pi2)
        self.assertTupleStringsEqual((pi1, pi2), io.poly_inputs)

        rp1 = RefinePoint((5, 0, -3), 3.1, False)
        rp2 = RefinePoint((-2, -2, 1), -0.4, True)
        io.refine_points = (rp1, rp2)
        self.assertTupleStringsEqual((rp1, rp2), io.refine_points)
예제 #2
0
    def test_check_for_intersections(self):
        io = MultiPolyMesherIo(())
        poly_input = PolyInput(outside_polygon=((0, 0, 0), (100, 0, 0),
                                                (100, 10, 0), (0, -10, 0)))
        io.poly_inputs = (poly_input, )

        expected = \
            "Error: Input polygon segments intersect. The segment defined by points 0 and 1 of outer " \
            "polygon 0 intersects with the segment defined by points 2 and 3 of outer polygon 0.\n"

        (success, errors) = mesh_utils.check_mesh_input_topology(io)
        self.assertEqual(False, success)
        self.assertEqual(expected, errors)
예제 #3
0
 def test_generate_2dm(self):
     io = MultiPolyMesherIo(())
     _ = mesh_utils.generate_2dm(io, "fname.2dm")
     self.assertTrue(os.path.isfile("fname.2dm"))
     self.assertTrue(
         filecmp.cmp("../test_files/python/fname.2dm", "fname.2dm"),
         "Files not equal")
예제 #4
0
    def test_check_for_intersections_2(self):
        io = MultiPolyMesherIo(())
        io.check_topology = True

        outside_poly = ((0, 0, 0), (100, 0, 0), (100, 100, 0), (0, 100, 0))
        inside_polys = (((10, 50, 0), (90, 50, 0), (90, 90, 0), (10, 10, 0)), )
        poly_input = PolyInput(outside_poly, inside_polys)
        io.poly_inputs = (poly_input, )

        expected = \
            "---Error: Input polygon segments intersect. The segment defined by points 0 and 1 of inner " \
            "polygon 0 of outer polygon 0 intersects with the segment defined by points 2 and 3 of inner " \
            "polygon 0 of outer polygon 0.\n" \
            "\n\n"

        (success, errors) = mesh_utils.generate_mesh(io)
        self.assertEqual(False, success)
        self.assertEqual(expected, errors)
예제 #5
0
    def test_case_4(self):
        # build test case 4 polys
        out_a = (0, 60, 10, 60, 20, 60, 30, 60, 30, 50, 30, 40, 30, 30, 30, 20,
                 30, 10, 30, 0, 20, 0, 10, 0, 0, 0, 0, 10, 0, 20, 0, 30, 0, 40,
                 0, 50)
        in_a1 = (10, 50, 10, 40, 20, 40, 20, 50)
        in_a2 = (10, 20, 10, 10, 20, 10, 20, 20)
        outside_poly = self.array_to_vec_pt3d(out_a)
        inside_polys = (self.array_to_vec_pt3d(in_a1),
                        self.array_to_vec_pt3d(in_a2))
        bias = 1.0
        poly_input_a = PolyInput(outside_polygon=outside_poly,
                                 inside_polygons=inside_polys,
                                 bias=bias)

        out_b = (30, 60, 40, 60, 50, 60, 60, 60, 70, 60, 70, 50, 70, 40, 70,
                 30, 70, 20, 70, 10, 70, 0, 60, 0, 50, 0, 40, 0, 40, 10, 30,
                 10, 30, 20, 40, 20, 40, 30, 30, 30, 30, 40, 40, 40, 40, 50,
                 30, 50)
        in_b1 = (50, 50, 50, 40, 60, 40, 60, 50)
        in_b2 = (50, 20, 50, 10, 60, 10, 60, 20)

        outside_poly_b = self.array_to_vec_pt3d(out_b)
        inside_polys_b = (self.array_to_vec_pt3d(in_b1),
                          self.array_to_vec_pt3d(in_b2))
        bias_b = 1.0
        poly_input_b = PolyInput(outside_poly_b, inside_polys_b, bias=bias_b)

        io = MultiPolyMesherIo(())
        io.poly_inputs = (poly_input_a, poly_input_b)

        # Value Error when file not specified
        with self.assertRaises(ValueError) as context:
            mesh_utils.generate_2dm(io, '')
        self.assertTrue('file_name not specifed. Aborting mesh procedure.' in
                        str(context.exception))

        # mesh the polys
        (success, result) = mesh_utils.generate_2dm(io, "out_file.2dm", 3)
        self.assertTrue(success)
        self.assertTrue(os.path.isfile("out_file.2dm"))
        self.assertFileLinesEqual("../test_files/python/out_file.2dm",
                                  "out_file.2dm")
 def test_creating_MultiPolyMesherIo(self):
     io = MultiPolyMesherIo(())
     self.assertIsInstance(io, MultiPolyMesherIo)
     self.assertEqual(False, io.check_topology)
     self.assertEqual(True, io.return_cell_polygons)
     self.assertEqual(0, len(io.points))
     self.assertEqual(0, len(io.cells))
     self.assertEqual(0, len(io.cell_polygons))
     self.assertEqual(0, len(io.poly_inputs))
     self.assertEqual(0, len(io.refine_points))
예제 #7
0
    def test_check_for_intersections_4(self):
        io = MultiPolyMesherIo(())
        io.check_topology = True

        outside_poly1 = ((0, 0, 0), (0, 100, 0), (100, 100, 0), (100, 0, 0))
        outside_poly2 = ((10, 10, 0), (10, 110, 0), (110, 110, 0), (110, 10,
                                                                    0))
        poly_input1 = PolyInput(outside_poly1)
        poly_input2 = PolyInput(outside_poly2)
        io.poly_inputs = (poly_input1, poly_input2)

        expected = \
            "---Error: Input polygon segments intersect. The segment defined by points 1 and 2 of outer " \
            "polygon 0 intersects with the segment defined by points 0 and 1 of outer polygon 1.\n" \
            "Error: Input polygon segments intersect. The segment defined by points 2 and 3 of outer " \
            "polygon 0 intersects with the segment defined by points 3 and 0 of outer polygon 1.\n" \
            "\n\n"

        (success, errors) = mesh_utils.generate_mesh(io)
        self.assertEqual(False, success)
        self.assertEqual(expected, errors)
예제 #8
0
 def test_simple_polygon(self):
     outside_poly = [(0, 10, 0), (0, 20, 0), (0, 30, 0), (0, 40, 0),
                     (0, 50, 0), (0, 60, 0), (0, 70, 0), (0, 80, 0),
                     (0, 90, 0), (0, 100, 0), (10, 100, 0), (20, 100, 0),
                     (30, 100, 0), (40, 100, 0), (50, 100, 0), (60, 100, 0),
                     (70, 100, 0), (80, 100, 0), (90, 100, 0),
                     (100, 100, 0), (100, 90, 0), (100, 80, 0),
                     (100, 70, 0), (100, 60, 0), (100, 50, 0), (100, 40, 0),
                     (100, 30, 0), (100, 20, 0), (100, 10, 0), (100, 0, 0),
                     (90, 0, 0), (80, 0, 0), (70, 0, 0), (60, 0, 0),
                     (50, 0, 0), (40, 0, 0), (30, 0, 0), (20, 0, 0),
                     (10, 0, 0), (0, 0, 0)]
     inside_polys = [[(40, 40, 0), (50, 40, 0), (60, 40, 0), (60, 50, 0),
                      (60, 60, 0), (50, 60, 0), (40, 60, 0), (40, 50, 0)]]
     input_poly = PolyInput(outside_poly, inside_polys)
     input = MultiPolyMesherIo(())
     input.poly_inputs = [input_poly]
     status, error = mesh_utils.generate_mesh(input)
     self.assertEqual(139, len(input.points))
     self.assertEqual(1150, len(input.cells))
     self.assertTrue(status)
     self.assertEqual(error, '')
예제 #9
0
    def test_repeated_first_and_last(self):
        # build test case 4 polys
        out_a = (0, 60, 10, 60, 20, 60, 30, 60, 30, 50, 30, 40, 30, 30, 30, 20,
                 30, 10, 30, 0, 20, 0, 10, 0, 0, 0, 0, 10, 0, 20, 0, 30, 0, 40,
                 0, 50, 0, 60)
        in_a1 = (10, 50, 10, 40, 20, 40, 20, 50, 10, 50)
        in_a2 = (10, 20, 10, 10, 20, 10, 20, 20, 10, 20)
        outside_poly = self.array_to_vec_pt3d(out_a)
        inside_polys = (self.array_to_vec_pt3d(in_a1),
                        self.array_to_vec_pt3d(in_a2))
        bias = 1.0
        poly_input_a = PolyInput(outside_polygon=outside_poly,
                                 inside_polygons=inside_polys,
                                 bias=bias)

        out_b = (30, 60, 40, 60, 50, 60, 60, 60, 70, 60, 70, 50, 70, 40, 70,
                 30, 70, 20, 70, 10, 70, 0, 60, 0, 50, 0, 40, 0, 40, 10, 30,
                 10, 30, 20, 40, 20, 40, 30, 30, 30, 30, 40, 40, 40, 40, 50,
                 30, 50)
        in_b1 = (50, 50, 50, 40, 60, 40, 60, 50)
        in_b2 = (50, 20, 50, 10, 60, 10, 60, 20)

        outside_poly_b = self.array_to_vec_pt3d(out_b)
        inside_polys_b = (self.array_to_vec_pt3d(in_b1),
                          self.array_to_vec_pt3d(in_b2))
        bias_b = 1.0
        poly_input_b = PolyInput(outside_poly_b, inside_polys_b, bias=bias_b)

        io = MultiPolyMesherIo(())
        io.poly_inputs = (poly_input_a, poly_input_b)

        # mesh the polys
        (success,
         result) = mesh_utils.generate_2dm(io, "out_file_02_repeated.2dm", 3)
        self.assertTrue(success)
        self.assertTrue(os.path.isfile("out_file_02_repeated.2dm"))
        self.assertFileLinesEqual("../test_files/python/out_file.2dm",
                                  "out_file_02_repeated.2dm")