Exemple #1
0
def main():
    import numpy
    from math import pi, cos, sin
    from meshpy.tet import MeshInfo, build
    from meshpy.geometry import GeometryBuilder, Marker, \
            generate_extrusion, make_box

    from meshpy.naca import generate_naca

    geob = GeometryBuilder()

    box_marker = Marker.FIRST_USER_MARKER

    wing_length = 2
    wing_subdiv = 5

    rz_points = [
        (0, -wing_length * 1.05),
        (0.7, -wing_length * 1.05),
    ] + [(r, x) for x, r in zip(
        numpy.linspace(-wing_length, 0, wing_subdiv, endpoint=False),
        numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))] + [(1, 0)] + [
            (r, x) for x, r in zip(
                numpy.linspace(wing_length, 0, wing_subdiv, endpoint=False),
                numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
        ][::-1] + [(0.7, wing_length * 1.05), (0, wing_length * 1.05)]

    geob.add_geometry(*generate_extrusion(
        rz_points=rz_points,
        base_shape=generate_naca("0012", verbose=False, number_of_points=20),
        ring_markers=(wing_subdiv * 2 + 4) * [box_marker]))

    from meshpy.tools import make_swizzle_matrix
    swizzle_matrix = make_swizzle_matrix("z:x,y:y,x:z")
    geob.apply_transform(lambda p: numpy.dot(swizzle_matrix, p))

    def deform_wing(p):
        x, y, z = p
        return numpy.array([
            x, y + 0.1 * abs(x / wing_length)**2,
            z + 0.8 * abs(x / wing_length)**1.2
        ])

    geob.apply_transform(deform_wing)

    points, facets, _, facet_markers = make_box(
        numpy.array([-wing_length - 1, -1, -1.5]),
        numpy.array([wing_length + 1, 1, 3]))

    geob.add_geometry(points, facets, facet_markers=facet_markers)

    mesh_info = MeshInfo()
    geob.set(mesh_info)
    mesh_info.set_holes([(0, 0, 0.5)])

    mesh = build(mesh_info)
    print "%d elements" % len(mesh.elements)
    mesh.write_vtk("airfoil3d.vtk")
from matplotlib import pylab as plt
from mpl_toolkits.mplot3d import Axes3D
from meshpy.tet import MeshInfo, build

rz = [(0, 0), (1, 0), (1.5, 0.5), (2, 1), (0, 1)]

base = []

for theta in np.linspace(0, 2 * np.pi, 40):

    x = np.sin(theta)
    y = np.cos(theta)
    base.extend([(x, y)])

(points, facets, facet_holestarts,
 markers) = generate_extrusion(rz_points=rz, base_shape=base)

p_array = np.array(points)
xs = p_array[:, 0]
ys = p_array[:, 1]
zs = p_array[:, 2]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xs, ys, zs)

for f in facets:
    plt.plot(xs[list(f[0])], ys[list(f[0])], zs[list(f[0])])
plt.show()
for i_facet, poly_list in enumerate(facets):
    print(poly_list)
Exemple #3
0
def make_wingmesh():
    import numpy
    from math import pi, cos, sin
    from meshpy.tet import MeshInfo, build
    from meshpy.geometry import GeometryBuilder, Marker, \
            generate_extrusion, make_box

    geob = GeometryBuilder()

    profile_marker = Marker.FIRST_USER_MARKER

    wing_length = 2
    wing_subdiv = 5

    rz_points = [
        (0, -wing_length * 1.05),
        (0.7, -wing_length * 1.05),
    ] + [(r, x) for x, r in zip(
        numpy.linspace(-wing_length, 0, wing_subdiv, endpoint=False),
        numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))] + [(1, 0)] + [
            (r, x) for x, r in zip(
                numpy.linspace(wing_length, 0, wing_subdiv, endpoint=False),
                numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
        ][::-1] + [(0.7, wing_length * 1.05), (0, wing_length * 1.05)]

    from meshpy.naca import get_naca_points
    geob.add_geometry(*generate_extrusion(
        rz_points=rz_points,
        base_shape=get_naca_points("0012", number_of_points=20),
        ring_markers=(wing_subdiv * 2 + 4) * [profile_marker]))

    def deform_wing(p):
        x, y, z = p
        return numpy.array([
            x + 0.8 * abs(z / wing_length)**1.2,
            y + 0.1 * abs(z / wing_length)**2, z
        ])

    geob.apply_transform(deform_wing)

    points, facets, facet_markers = make_box(
        numpy.array([-1.5, -1, -wing_length - 1], dtype=numpy.float64),
        numpy.array([3, 1, wing_length + 1], dtype=numpy.float64))

    geob.add_geometry(points, facets, facet_markers=facet_markers)

    mesh_info = MeshInfo()
    geob.set(mesh_info)
    mesh_info.set_holes([(0.5, 0, 0)])

    mesh = build(mesh_info)
    print("%d elements" % len(mesh.elements))

    fvi2fm = mesh.face_vertex_indices_to_face_marker

    face_marker_to_tag = {
        profile_marker: "noslip",
        Marker.MINUS_X: "inflow",
        Marker.PLUS_X: "outflow",
        Marker.MINUS_Y: "inflow",
        Marker.PLUS_Y: "inflow",
        Marker.PLUS_Z: "inflow",
        Marker.MINUS_Z: "inflow"
    }

    def bdry_tagger(fvi, el, fn, all_v):
        face_marker = fvi2fm[fvi]
        return [face_marker_to_tag[face_marker]]

    from grudge.mesh import make_conformal_mesh
    return make_conformal_mesh(mesh.points, mesh.elements, bdry_tagger)
Exemple #4
0
def make_wingmesh():
    import numpy
    from math import pi, cos, sin
    from meshpy.tet import MeshInfo, build
    from meshpy.geometry import GeometryBuilder, Marker, \
            generate_extrusion, make_box

    geob = GeometryBuilder()

    profile_marker = Marker.FIRST_USER_MARKER

    wing_length = 2
    wing_subdiv = 5

    rz_points = [
            (0, -wing_length*1.05),
            (0.7, -wing_length*1.05),
            ] + [
                (r, x) for x, r in zip(
                    numpy.linspace(-wing_length, 0, wing_subdiv, endpoint=False),
                    numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
            ] + [(1,0)] + [
                (r, x) for x, r in zip(
                    numpy.linspace(wing_length, 0, wing_subdiv, endpoint=False),
                    numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
            ][::-1] + [
            (0.7, wing_length*1.05),
            (0, wing_length*1.05)
            ]

    from meshpy.naca import get_naca_points
    geob.add_geometry(*generate_extrusion(
        rz_points=rz_points,
        base_shape=get_naca_points("0012", number_of_points=20),
        ring_markers=(wing_subdiv*2+4)*[profile_marker]))

    def deform_wing(p):
        x, y, z = p
        return numpy.array([
            x + 0.8*abs(z/wing_length)** 1.2,
            y + 0.1*abs(z/wing_length)**2,
            z])

    geob.apply_transform(deform_wing)

    points, facets, facet_markers = make_box(
            numpy.array([-1.5,-1,-wing_length-1], dtype=numpy.float64),
            numpy.array([3,1,wing_length+1], dtype=numpy.float64))

    geob.add_geometry(points, facets, facet_markers=facet_markers)

    mesh_info = MeshInfo()
    geob.set(mesh_info)
    mesh_info.set_holes([(0.5,0,0)])

    mesh = build(mesh_info)
    print "%d elements" % len(mesh.elements)

    fvi2fm = mesh.face_vertex_indices_to_face_marker

    face_marker_to_tag = {
            profile_marker: "noslip",
            Marker.MINUS_X: "inflow",
            Marker.PLUS_X: "outflow",
            Marker.MINUS_Y: "inflow",
            Marker.PLUS_Y: "inflow",
            Marker.PLUS_Z: "inflow",
            Marker.MINUS_Z: "inflow"
            }

    def bdry_tagger(fvi, el, fn, all_v):
        face_marker = fvi2fm[fvi]
        return [face_marker_to_tag[face_marker]]

    from hedge.mesh import make_conformal_mesh
    return make_conformal_mesh(mesh.points, mesh.elements, bdry_tagger)
def generateConeMesh(plot=True):
    x0 = 0
    y0 = 0
    z0 = 1
    h = 1
    r_bottom = 1.3
    r_top = 1.5
    r_scale = r_top / r_bottom

    rz = [(0, z0),
          (1, z0),
          (r_scale, z0 + h),
          (0, z0 + h)]

    base = []

    # Create circle
    for theta in np.linspace(0, 2 * np.pi, 40):
        x = r_bottom * np.sin(theta)
        y = r_bottom * np.cos(theta)
        base.extend([(x, y)])

    (points, facets,
     facet_holestarts, markers) = generate_extrusion(rz_points=rz,
                                                     base_shape=base)

    if plot:
        p_array = np.array(points)
        xs = p_array[:, 0] + x0
        ys = p_array[:, 1] + y0
        zs = p_array[:, 2]

        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        ax.scatter(xs, ys, zs)

        for f in facets:
            plt.plot(xs[list(f[0])], ys[list(f[0])], zs[list(f[0])])

        if True:
            axLim = ax.get_w_lims()
            MAX = np.max(axLim)
            for direction in (-1, 1):
                for point in np.diag(direction * MAX * np.array([1, 1, 1])):
                    ax.plot(
                        [point[0]], [point[1]], [np.abs(point[2])], 'w')
        x = [0, 0]
        y = [0, 0]
        z = [1, 1 + 0.2]
        plt.plot(x, y, z)
        plt.show()

    mesh_info = MeshInfo()
    mesh_info.set_points(points)
    mesh_info.set_facets_ex(facets)
    mesh = build(mesh_info)
    # print(mesh.elements)

    cellList = []
    vertexList = []
    mupifMesh = Mesh.UnstructuredMesh()

    for i, p in enumerate(mesh.points):
        p = (p[0] + x0, p[1] + y0, p[2])
        vertexList.extend([Vertex.Vertex(i, i, p)])

    for i, t in enumerate(mesh.elements):
        cellList.extend([Cell.Tetrahedron_3d_lin(mupifMesh, i, i, t)])

    mupifMesh.setup(vertexList, cellList)

    return(mupifMesh)
Exemple #6
0
def main():
    import numpy
    #from math import pi, cos, sin
    from meshpy.tet import MeshInfo, build
    from meshpy.geometry import GeometryBuilder, Marker, \
            generate_extrusion, make_box

    from meshpy.naca import get_naca_points

    geob = GeometryBuilder()

    box_marker = Marker.FIRST_USER_MARKER

    wing_length = 2
    wing_subdiv = 5

    rz_points = [
            (0, -wing_length*1.05),
            (0.7, -wing_length*1.05),
            ] + [
                (r, x) for x, r in zip(
                    numpy.linspace(-wing_length, 0, wing_subdiv, endpoint=False),
                    numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
            ] + [(1, 0)] + [
                (r, x) for x, r in zip(
                    numpy.linspace(wing_length, 0, wing_subdiv, endpoint=False),
                    numpy.linspace(0.8, 1, wing_subdiv, endpoint=False))
            ][::-1] + [
            (0.7, wing_length*1.05),
            (0, wing_length*1.05)
            ]

    geob.add_geometry(*generate_extrusion(
        rz_points=rz_points,
        base_shape=get_naca_points("0012", verbose=False, number_of_points=20),
        ring_markers=(wing_subdiv*2+4)*[box_marker]))

    from meshpy.tools import make_swizzle_matrix
    swizzle_matrix = make_swizzle_matrix("z:x,y:y,x:z")
    geob.apply_transform(lambda p: numpy.dot(swizzle_matrix, p))

    def deform_wing(p):
        x, y, z = p
        return numpy.array([
            x,
            y + 0.1*abs(x/wing_length)**2,
            z + 0.8*abs(x/wing_length) ** 1.2])

    geob.apply_transform(deform_wing)

    points, facets, _, facet_markers = make_box(
            numpy.array([-wing_length-1, -1, -1.5]),
            numpy.array([wing_length+1, 1, 3]))

    geob.add_geometry(points, facets, facet_markers=facet_markers)

    mesh_info = MeshInfo()
    geob.set(mesh_info)
    mesh_info.set_holes([(0, 0, 0.5)])

    mesh = build(mesh_info)
    print("%d elements" % len(mesh.elements))
    mesh.write_vtk("airfoil3d.vtk")
def generateConeMesh(plot=True):
    x0 = 0
    y0 = 0
    z0 = 1
    h = 1
    r_bottom = 1.3
    r_top = 1.5
    r_scale = r_top / r_bottom

    rz = [(0, z0), (1, z0), (r_scale, z0 + h), (0, z0 + h)]

    base = []

    # Create circle
    for theta in np.linspace(0, 2 * np.pi, 40):
        x = r_bottom * np.sin(theta)
        y = r_bottom * np.cos(theta)
        base.extend([(x, y)])

    (points, facets, facet_holestarts,
     markers) = generate_extrusion(rz_points=rz, base_shape=base)

    if plot:
        p_array = np.array(points)
        xs = p_array[:, 0] + x0
        ys = p_array[:, 1] + y0
        zs = p_array[:, 2]

        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')
        ax.scatter(xs, ys, zs)

        for f in facets:
            plt.plot(xs[list(f[0])], ys[list(f[0])], zs[list(f[0])])

        if True:
            axLim = ax.get_w_lims()
            MAX = np.max(axLim)
            for direction in (-1, 1):
                for point in np.diag(direction * MAX * np.array([1, 1, 1])):
                    ax.plot([point[0]], [point[1]], [np.abs(point[2])], 'w')
        x = [0, 0]
        y = [0, 0]
        z = [1, 1 + 0.2]
        plt.plot(x, y, z)
        plt.show()

    mesh_info = MeshInfo()
    mesh_info.set_points(points)
    mesh_info.set_facets_ex(facets)
    mesh = build(mesh_info)
    # print(mesh.elements)

    cellList = []
    vertexList = []
    mupifMesh = Mesh.UnstructuredMesh()

    for i, p in enumerate(mesh.points):
        p = (p[0] + x0, p[1] + y0, p[2])
        vertexList.extend([Vertex.Vertex(i, i, p)])

    for i, t in enumerate(mesh.elements):
        cellList.extend([Cell.Tetrahedron_3d_lin(mupifMesh, i, i, t)])

    mupifMesh.setup(vertexList, cellList)

    return (mupifMesh)
from mpl_toolkits.mplot3d import Axes3D
from meshpy.tet import MeshInfo, build

rz = [(0, 0), (1, 0), (1.5, 0.5),  (2, 1), (0, 1)]

base = []

for theta in np.linspace(0, 2 * np.pi, 40):

    x = np.sin(theta)
    y = np.cos(theta)
    base.extend([(x, y)])


(points, facets,
 facet_holestarts, markers) = generate_extrusion(rz_points=rz, base_shape=base)


p_array = np.array(points)
xs = p_array[:, 0]
ys = p_array[:, 1]
zs = p_array[:, 2]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(xs, ys, zs)


for f in facets:
    plt.plot(xs[list(f[0])], ys[list(f[0])], zs[list(f[0])])
plt.show()