コード例 #1
0
    def get_mesh(self, resolution, target_order):
        from meshmode.mesh.generation import generate_icosphere
        from meshmode.mesh.refinement import refine_uniformly
        mesh = refine_uniformly(generate_icosphere(1, target_order),
                                resolution)

        return mesh
コード例 #2
0
def test_mesh_without_vertices(ctx_factory):
    ctx = ctx_factory()
    queue = cl.CommandQueue(ctx)

    # create a mesh
    from meshmode.mesh.generation import generate_icosphere
    mesh = generate_icosphere(r=1.0, order=4)

    # create one without the vertices
    from meshmode.mesh import Mesh
    grp, = mesh.groups
    groups = [
        grp.copy(nodes=grp.nodes, vertex_indices=None) for grp in mesh.groups
    ]
    mesh = Mesh(None, groups, is_conforming=False)

    # try refining it
    from meshmode.mesh.refinement import refine_uniformly
    mesh = refine_uniformly(mesh, 1)

    # make sure the world doesn't end
    from meshmode.discretization import Discretization
    from meshmode.discretization.poly_element import \
            InterpolatoryQuadratureSimplexGroupFactory as GroupFactory
    discr = Discretization(ctx, mesh, GroupFactory(4))
    discr.nodes().with_queue(queue)

    from meshmode.discretization.visualization import make_visualizer
    make_visualizer(queue, discr, 4)
コード例 #3
0
ファイル: test_meshmode.py プロジェクト: MTCam/meshmode
def test_mesh_without_vertices(actx_factory):
    actx = actx_factory()

    # create a mesh
    mesh = mgen.generate_icosphere(r=1.0, order=4)

    # create one without the vertices
    grp, = mesh.groups
    groups = [
        grp.copy(nodes=grp.nodes, vertex_indices=None) for grp in mesh.groups
    ]
    mesh = Mesh(None, groups, is_conforming=False)

    # try refining it
    from meshmode.mesh.refinement import refine_uniformly
    mesh = refine_uniformly(mesh, 1)

    # make sure the world doesn't end
    from meshmode.discretization import Discretization
    discr = Discretization(actx, mesh,
                           InterpolatoryQuadratureSimplexGroupFactory(4))
    thaw(discr.nodes(), actx)

    from meshmode.discretization.visualization import make_visualizer
    make_visualizer(actx, discr, 4)
コード例 #4
0
ファイル: test_refinement.py プロジェクト: majosm/meshmode
def test_uniform_refinement(ctx_factory, with_adjacency):
    make_mesh = partial(generate_box_mesh, (np.linspace(
        0.0, 1.0, 2), np.linspace(0.0, 1.0, 3), np.linspace(0.0, 1.0, 2)),
                        order=4)
    mesh = make_mesh()

    from meshmode.mesh.refinement import refine_uniformly
    mesh = refine_uniformly(mesh, 1, with_adjacency=with_adjacency)
コード例 #5
0
def test_refine_surfaces(actx_factory, mesh_name, visualize=False):
    if mesh_name == "torus":
        mesh = mgen.generate_torus(10, 1, 40, 4, order=4)
    elif mesh_name == "icosphere":
        mesh = mgen.generate_icosphere(1, order=4)
    else:
        raise ValueError(f"invalid mesh name '{mesh_name}'")

    if visualize:
        actx = actx_factory()
        from meshmode.mesh.visualization import vtk_visualize_mesh
        vtk_visualize_mesh(actx, mesh, "surface.vtu")

    # check for absence of node-vertex consistency error
    from meshmode.mesh.refinement import refine_uniformly
    refined_mesh = refine_uniformly(mesh, 1)

    if visualize:
        actx = actx_factory()
        from meshmode.mesh.visualization import vtk_visualize_mesh
        vtk_visualize_mesh(actx, refined_mesh, "surface-refined.vtu")
コード例 #6
0
ファイル: generation.py プロジェクト: MTCam/meshmode
def generate_icosphere(
        r: float,
        order: int,
        *,
        uniform_refinement_rounds: int = 0,
        node_vertex_consistency_tolerance: Optional[Union[float, bool]] = None,
        unit_nodes: Optional[np.ndarray] = None):
    """
    :param r: radius of the sphere.
    :param order: order of the (simplex) elements. If *unit_nodes* is also
        provided, the orders should match.
    :param uniform_refinement_rounds: number of uniform refinement rounds to
        perform after the initial mesh was created.
    :param node_vertex_consistency_tolerance: passed to the
        :class:`~meshmode.mesh.Mesh` constructor. If *False*, no checks are
        performed.
    :param unit_nodes: if given, the unit nodes to use. Must have shape
        ``(3, nnodes)``.
    """
    mesh = generate_icosahedron(
        r,
        order,
        node_vertex_consistency_tolerance=node_vertex_consistency_tolerance,
        unit_nodes=unit_nodes)

    if uniform_refinement_rounds:
        from meshmode.mesh.refinement import refine_uniformly
        mesh = refine_uniformly(mesh, uniform_refinement_rounds)

    # ensure vertices and nodes are still on the sphere of radius r
    vertices = mesh.vertices * r / np.sqrt(np.sum(mesh.vertices**2, axis=0))
    grp, = mesh.groups
    grp = grp.copy(nodes=grp.nodes * r / np.sqrt(np.sum(grp.nodes**2, axis=0)))

    from meshmode.mesh import Mesh
    return Mesh(
        vertices, [grp],
        node_vertex_consistency_tolerance=node_vertex_consistency_tolerance,
        is_conforming=True)
コード例 #7
0
def test_harmonic_extension_exterior_3d(ctx_factory):

    dim = 3  # noqa: F841
    mesh_order = 8
    fmm_order = 3
    bdry_quad_order = mesh_order
    bdry_ovsmp_quad_order = 4 * bdry_quad_order
    qbx_order = mesh_order

    cl_ctx = ctx_factory()
    queue = cl.CommandQueue(cl_ctx)

    from meshmode.mesh.generation import generate_icosphere
    from meshmode.mesh.refinement import refine_uniformly

    radius = 2.5
    base_mesh = generate_icosphere(radius, order=mesh_order)
    mesh = refine_uniformly(base_mesh, 1)

    pre_density_discr = Discretization(
        cl_ctx, mesh,
        InterpolatoryQuadratureSimplexGroupFactory(bdry_quad_order))

    from pytential.qbx import QBXLayerPotentialSource
    qbx, _ = QBXLayerPotentialSource(
        pre_density_discr,
        fine_order=bdry_ovsmp_quad_order,
        qbx_order=qbx_order,
        fmm_order=fmm_order,
    ).with_refinement()
    density_discr = qbx.density_discr

    ntgts = 200
    rho = np.random.rand(ntgts) * 3 + radius + 0.05
    theta = np.random.rand(ntgts) * 2 * np.pi
    phi = (np.random.rand(ntgts) - 0.5) * np.pi

    nodes = density_discr.nodes().with_queue(queue)
    source = np.array([0, 1, 2])

    def test_func(x):
        return 1.0 / la.norm(x.get() - source[:, None], axis=0)

    f = cl.array.to_device(queue, test_func(nodes))

    targets = cl.array.to_device(
        queue,
        np.array([
            rho * np.cos(phi) * np.cos(theta),
            rho * np.cos(phi) * np.sin(theta), rho * np.sin(phi)
        ]))

    exact_f = test_func(targets)

    ext_f, _ = compute_harmonic_extension(queue,
                                          PointsTarget(targets),
                                          qbx,
                                          density_discr,
                                          f,
                                          loc_sign=1)

    assert np.linalg.norm(exact_f -
                          ext_f.get()) < 1e-3 * np.linalg.norm(exact_f)
コード例 #8
0
ファイル: extra_int_eq_data.py プロジェクト: isuruf/pytential
    def get_mesh(self, resolution, mesh_order):
        from meshmode.mesh.generation import generate_torus
        mesh = generate_torus(self.r_major, self.r_minor, order=mesh_order)

        from meshmode.mesh.refinement import refine_uniformly
        return refine_uniformly(mesh, resolution)