Esempio n. 1
0
    def __init__(self, alpha, order):
        self.alpha = alpha
        self.warp = WarpFactorCalculator(order)

        cls = TriangleDiscretization

        from pytools import wandering_element
        from hedge.tools import normalize

        vertices = [
            cls.barycentric_to_equilateral(bary)
            for bary in wandering_element(cls.dimensions + 1)
        ]
        all_vertex_indices = range(cls.dimensions + 1)
        face_vertex_indices = cls.geometry \
                .face_vertices(all_vertex_indices)
        faces_vertices = cls.geometry.face_vertices(vertices)

        edgedirs = [normalize(v2 - v1) for v1, v2 in faces_vertices]
        opp_vertex_indices = [
            (set(all_vertex_indices) - set(fvi)).__iter__().next()
            for fvi in face_vertex_indices
        ]

        self.loop_info = zip(face_vertex_indices, edgedirs, opp_vertex_indices)
Esempio n. 2
0
    def __init__(self, alpha, order):
        self.alpha = alpha
        self.warp = WarpFactorCalculator(order)

        cls = TriangleDiscretization

        from pytools import wandering_element
        from hedge.tools import normalize

        vertices = [cls.barycentric_to_equilateral(bary)
                for bary in wandering_element(cls.dimensions + 1)]
        all_vertex_indices = range(cls.dimensions + 1)
        face_vertex_indices = cls.geometry \
                .face_vertices(all_vertex_indices)
        faces_vertices = cls.geometry.face_vertices(vertices)

        edgedirs = [normalize(v2 - v1) for v1, v2 in faces_vertices]
        opp_vertex_indices = [
            (set(all_vertex_indices) - set(fvi)).__iter__().next()
            for fvi in face_vertex_indices]

        self.loop_info = zip(
                face_vertex_indices,
                edgedirs,
                opp_vertex_indices)
Esempio n. 3
0
    def equilateral_nodes(self):
        """Generate warped nodes in equilateral coordinates (x,y)."""

        # port of Hesthaven/Warburton's Nodes3D routine

        # Set optimized parameter alpha, depending on order N
        alpha_opt = [
            0, 0, 0, 0.1002, 1.1332, 1.5608, 1.3413, 1.2577, 1.1603, 1.10153,
            0.6080, 0.4523, 0.8856, 0.8717, 0.9655
        ]
        if self.order - 1 < len(alpha_opt):
            alpha = alpha_opt[self.order - 1]
        else:
            alpha = 1

        from pytools import wandering_element

        vertices = [
            self.barycentric_to_equilateral(bary)
            for bary in wandering_element(self.dimensions + 1)
        ]
        all_vertex_indices = range(self.dimensions + 1)
        face_vertex_indices = self.geometry \
                .face_vertices(all_vertex_indices)
        faces_vertices = self.geometry \
                .face_vertices(vertices)

        bary_points = list(self.equidistant_barycentric_nodes())
        equi_points = [
            self.barycentric_to_equilateral(bp) for bp in bary_points
        ]

        from hedge.tools import normalize
        from operator import add, mul

        tri_warp = TriangleWarper(alpha, self.order)

        for fvi, (v1, v2, v3) in zip(face_vertex_indices, faces_vertices):
            # find directions spanning the face: "base" and "altitude"
            directions = [normalize(v2 - v1), normalize((v3) - (v1 + v2) / 2)]

            # the two should be orthogonal
            assert abs(numpy.dot(directions[0], directions[1])) < 1e-16

            # find the vertex opposite to the current face
            opp_vertex_index = (set(all_vertex_indices) -
                                set(fvi)).__iter__().next()

            shifted = []
            for bp, ep in zip(bary_points, equi_points):
                face_bp = [bp[i] for i in fvi]

                blend = reduce(mul,
                               face_bp) * (1 + alpha * bp[opp_vertex_index])**2

                for i in fvi:
                    denom = bp[i] + 0.5 * bp[opp_vertex_index]
                    if abs(denom) > 1e-12:
                        blend /= denom
                    else:
                        blend = 0.5  # each edge gets shifted twice
                        break

                shifted.append(ep + blend * reduce(add, (
                    tw * dir
                    for tw, dir in zip(tri_warp(face_bp), directions))))

            equi_points = shifted

        return equi_points
Esempio n. 4
0
    def equilateral_nodes(self):
        """Generate warped nodes in equilateral coordinates (x,y)."""

        # port of Hesthaven/Warburton's Nodes3D routine

        # Set optimized parameter alpha, depending on order N
        alpha_opt = [0, 0, 0, 0.1002, 1.1332, 1.5608, 1.3413, 1.2577, 1.1603,
                1.10153, 0.6080, 0.4523, 0.8856, 0.8717, 0.9655]
        if self.order-1 < len(alpha_opt):
            alpha = alpha_opt[self.order-1]
        else:
            alpha = 1

        from pytools import wandering_element

        vertices = [self.barycentric_to_equilateral(bary)
                for bary in wandering_element(self.dimensions + 1)]
        all_vertex_indices = range(self.dimensions + 1)
        face_vertex_indices = self.geometry \
                .face_vertices(all_vertex_indices)
        faces_vertices = self.geometry \
                .face_vertices(vertices)

        bary_points = list(self.equidistant_barycentric_nodes())
        equi_points = [self.barycentric_to_equilateral(bp)
                for bp in bary_points]

        from hedge.tools import normalize
        from operator import add, mul

        tri_warp = TriangleWarper(alpha, self.order)

        for fvi, (v1, v2, v3) in zip(face_vertex_indices, faces_vertices):
            # find directions spanning the face: "base" and "altitude"
            directions = [normalize(v2 - v1), normalize((v3)-(v1+v2)/2)]

            # the two should be orthogonal
            assert abs(numpy.dot(directions[0], directions[1])) < 1e-16

            # find the vertex opposite to the current face
            opp_vertex_index = (
                    set(all_vertex_indices)
                    - set(fvi)).__iter__().next()

            shifted = []
            for bp, ep in zip(bary_points, equi_points):
                face_bp = [bp[i] for i in fvi]

                blend = reduce(mul, face_bp) * (1+alpha*bp[opp_vertex_index])**2

                for i in fvi:
                    denom = bp[i] + 0.5*bp[opp_vertex_index]
                    if abs(denom) > 1e-12:
                        blend /= denom
                    else:
                        blend = 0.5  # each edge gets shifted twice
                        break

                shifted.append(ep + blend*reduce(add,
                    (tw*dir for tw, dir in zip(tri_warp(face_bp), directions))))

            equi_points = shifted

        return equi_points