Ejemplo n.º 1
0
    def getMeshIntersections(self, line):
        field, endpoints = line
        # get Proteus mesh index for this field
        field_id = self.fieldNames.index(field)
        femFun = self.u[field_id]
        mesh = femFun.femSpace.mesh
        referenceElement = femFun.femSpace.elementMaps.referenceElement
        if referenceElement.dim == 2 and referenceElement.nNodes == 3:
            toPolyhedron = triangleVerticesToNormals
        elif referenceElement.dim == 3 and referenceElement.nNodes == 4:
            toPolyhedron = tetrahedronVerticesToNormals
        else:
            raise NotImplementedError(
                "Unable to compute mesh intersections for this element type")
        intersections = np.asarray(list(
            getMeshIntersections(mesh, toPolyhedron, endpoints)),
                                   dtype=np.double)
        endpoints = np.asarray(endpoints, np.double)
        length = norm(endpoints[1] - endpoints[0])

        length_segments = [(old_div(norm(i[0] - endpoints[0]), length),
                            old_div(norm(i[1] - endpoints[0]), length), i)
                           for i in intersections]

        segments = self.pruneDuplicateSegments(endpoints, length_segments)
        return segments
Ejemplo n.º 2
0
    def test_mesh_intersections(self):
        """
        Test correctness of intersecting a line and a tetrahedral mesh.
        """

        endpoints = np.asarray(((0, 0, 0), (1, 1, 1)))
        mesh_type = namedtuple('mesh', 'nodeArray elementNodesArray')
        nodeArray = np.asarray(([[0., 0., 0.], [0.5, 0., 0.], [1., 0., 0.],
                                 [0., 0.5, 0.], [0.5, 0.5, 0.], [1., 0.5, 0.],
                                 [0., 1., 0.], [0.5, 1., 0.], [1., 1., 0.],
                                 [0., 0., 0.5], [0.5, 0., 0.5], [1., 0., 0.5],
                                 [0., 0.5, 0.5], [0.5, 0.5, 0.5],
                                 [1., 0.5, 0.5], [0., 1., 0.5], [0.5, 1., 0.5],
                                 [1., 1., 0.5], [0., 0., 1.], [0.5, 0., 1.],
                                 [1., 0., 1.], [0., 0.5, 1.], [0.5, 0.5, 1.],
                                 [1., 0.5, 1.], [0., 1., 1.], [0.5, 1., 1.],
                                 [1., 1., 1.]]))

        elementNodesArray = np.asarray([[0, 1, 4, 13], [0, 1, 10, 13],
                                        [0, 3, 4, 13], [0, 3, 12, 13],
                                        [0, 9, 10, 13], [0, 9, 12, 13],
                                        [1, 2, 5, 14], [1, 2, 11, 14],
                                        [1, 4, 5, 14], [1, 4, 13, 14],
                                        [1, 10, 11, 14], [1, 10, 13, 14],
                                        [3, 4, 7, 16], [3, 4, 13, 16],
                                        [3, 6, 7, 16], [3, 6, 15, 16],
                                        [3, 12, 13, 16], [3, 12, 15, 16],
                                        [4, 5, 8, 17], [4, 5, 14, 17],
                                        [4, 7, 8, 17], [4, 7, 16, 17],
                                        [4, 13, 14, 17], [4, 13, 16, 17],
                                        [9, 10, 13, 22], [9, 10, 19, 22],
                                        [9, 12, 13, 22], [9, 12, 21, 22],
                                        [9, 18, 19, 22], [9, 18, 21, 22],
                                        [10, 11, 14, 23], [10, 11, 20, 23],
                                        [10, 13, 14, 23], [10, 13, 22, 23],
                                        [10, 19, 20, 23], [10, 19, 22, 23],
                                        [12, 13, 16, 25], [12, 13, 22, 25],
                                        [12, 15, 16, 25], [12, 15, 24, 25],
                                        [12, 21, 22, 25], [12, 21, 24, 25],
                                        [13, 14, 17, 26], [13, 14, 23, 26],
                                        [13, 16, 17, 26], [13, 16, 25, 26],
                                        [13, 22, 23, 26], [13, 22, 25, 26]])

        mesh = mesh_type(nodeArray=nodeArray,
                         elementNodesArray=elementNodesArray)
        toPolyhedron = tetrahedronVerticesToNormals
        eq_(getMeshIntersections(mesh, toPolyhedron, endpoints),
            set([((0.5, 0.5, 0.5), (1, 1, 1)), ((0, 0, 0), (0.5, 0.5, 0.5))]))
Ejemplo n.º 3
0
    def getMeshIntersections(self, line):
        field, endpoints = line
        # get Proteus mesh index for this field
        field_id = self.fieldNames.index(field)
        femFun = self.u[field_id]
        mesh = femFun.femSpace.mesh
        referenceElement = femFun.femSpace.elementMaps.referenceElement
        if referenceElement.dim == 2 and referenceElement.nNodes == 3:
            toPolyhedron = triangleVerticesToNormals
        elif referenceElement.dim == 3 and referenceElement.nNodes == 4:
            toPolyhedron = tetrahedronVerticesToNormals
        else:
            raise NotImplementedError("Unable to compute mesh intersections for this element type")
        intersections = np.asarray(list(getMeshIntersections(mesh, toPolyhedron, endpoints)), dtype=np.double)
        endpoints = np.asarray(endpoints, np.double)
        length = norm(endpoints[1] - endpoints[0])

        length_segments = [(old_div(norm(i[0]-endpoints[0]),length), old_div(norm(i[1]-endpoints[0]),length), i) for i in intersections]

        segments = self.pruneDuplicateSegments(endpoints, length_segments)
        return segments
Ejemplo n.º 4
0
    def test_mesh_intersections(self):
        """
        Test correctness of intersecting a line and a tetrahedral mesh.
        """

        endpoints = np.asarray(((0, 0, 0), (1, 1, 1)))
        mesh_type = namedtuple('mesh', 'nodeArray elementNodesArray')
        nodeArray = np.asarray(([[ 0. ,  0. ,  0. ],
           [ 0.5,  0. ,  0. ],
           [ 1. ,  0. ,  0. ],
           [ 0. ,  0.5,  0. ],
           [ 0.5,  0.5,  0. ],
           [ 1. ,  0.5,  0. ],
           [ 0. ,  1. ,  0. ],
           [ 0.5,  1. ,  0. ],
           [ 1. ,  1. ,  0. ],
           [ 0. ,  0. ,  0.5],
           [ 0.5,  0. ,  0.5],
           [ 1. ,  0. ,  0.5],
           [ 0. ,  0.5,  0.5],
           [ 0.5,  0.5,  0.5],
           [ 1. ,  0.5,  0.5],
           [ 0. ,  1. ,  0.5],
           [ 0.5,  1. ,  0.5],
           [ 1. ,  1. ,  0.5],
           [ 0. ,  0. ,  1. ],
           [ 0.5,  0. ,  1. ],
           [ 1. ,  0. ,  1. ],
           [ 0. ,  0.5,  1. ],
           [ 0.5,  0.5,  1. ],
           [ 1. ,  0.5,  1. ],
           [ 0. ,  1. ,  1. ],
           [ 0.5,  1. ,  1. ],
           [ 1. ,  1. ,  1. ]]))

        elementNodesArray = np.asarray([[ 0,  1,  4, 13],
           [ 0,  1, 10, 13],
           [ 0,  3,  4, 13],
           [ 0,  3, 12, 13],
           [ 0,  9, 10, 13],
           [ 0,  9, 12, 13],
           [ 1,  2,  5, 14],
           [ 1,  2, 11, 14],
           [ 1,  4,  5, 14],
           [ 1,  4, 13, 14],
           [ 1, 10, 11, 14],
           [ 1, 10, 13, 14],
           [ 3,  4,  7, 16],
           [ 3,  4, 13, 16],
           [ 3,  6,  7, 16],
           [ 3,  6, 15, 16],
           [ 3, 12, 13, 16],
           [ 3, 12, 15, 16],
           [ 4,  5,  8, 17],
           [ 4,  5, 14, 17],
           [ 4,  7,  8, 17],
           [ 4,  7, 16, 17],
           [ 4, 13, 14, 17],
           [ 4, 13, 16, 17],
           [ 9, 10, 13, 22],
           [ 9, 10, 19, 22],
           [ 9, 12, 13, 22],
           [ 9, 12, 21, 22],
           [ 9, 18, 19, 22],
           [ 9, 18, 21, 22],
           [10, 11, 14, 23],
           [10, 11, 20, 23],
           [10, 13, 14, 23],
           [10, 13, 22, 23],
           [10, 19, 20, 23],
           [10, 19, 22, 23],
           [12, 13, 16, 25],
           [12, 13, 22, 25],
           [12, 15, 16, 25],
           [12, 15, 24, 25],
           [12, 21, 22, 25],
           [12, 21, 24, 25],
           [13, 14, 17, 26],
           [13, 14, 23, 26],
           [13, 16, 17, 26],
           [13, 16, 25, 26],
           [13, 22, 23, 26],
           [13, 22, 25, 26]])

        mesh = mesh_type(nodeArray=nodeArray, elementNodesArray=elementNodesArray)
        toPolyhedron = tetrahedronVerticesToNormals
        eq_(getMeshIntersections(mesh, toPolyhedron, endpoints),
            set([((0.5, 0.5, 0.5), (1, 1, 1)), ((0, 0, 0), (0.5, 0.5, 0.5))]))