def from_vertices_and_simplices(vertices, simplices, order=1, fix_orientation=False): """Imports a mesh from a numpy array of vertices and an array of simplices. :arg vertices: An array of vertex coordinates with shape *(ambient_dim, nvertices)* :arg simplices: An array *(nelements, nvertices)* of (mesh-wide) vertex indices. """ from meshmode.mesh import Mesh from meshmode.mesh.generation import make_group_from_vertices grp = make_group_from_vertices(vertices, simplices, order) if fix_orientation: if grp.dim != vertices.shape[0]: raise ValueError("can only fix orientation of volume meshes") from meshmode.mesh.processing import ( find_volume_mesh_element_group_orientation, flip_simplex_element_group) orient = find_volume_mesh_element_group_orientation(vertices, grp) grp = flip_simplex_element_group(vertices, grp, orient < 0) return Mesh( vertices=vertices, groups=[grp], is_conforming=True)
def from_vertices_and_simplices(vertices, simplices, order=1, fix_orientation=False): """Imports a mesh from a numpy array of vertices and an array of simplices. :arg vertices: An array of vertex coordinates with shape *(ambient_dim, nvertices)* :arg simplices: An array *(nelements, nvertices)* of (mesh-wide) vertex indices. """ from meshmode.mesh import Mesh from meshmode.mesh.generation import make_group_from_vertices grp = make_group_from_vertices(vertices, simplices, order) if fix_orientation: if grp.dim != vertices.shape[0]: raise ValueError("can only fix orientation of volume meshes") from meshmode.mesh.processing import ( find_volume_mesh_element_group_orientation, flip_simplex_element_group) orient = find_volume_mesh_element_group_orientation(vertices, grp) grp = flip_simplex_element_group(vertices, grp, orient < 0) return Mesh( vertices=vertices, groups=[grp], is_conforming=True)
def from_vertices_and_simplices(vertices, simplices, order=1, fix_orientation=False): """Imports a mesh from a numpy array of vertices and an array of simplices. :arg vertices: An array of vertex coordinates with shape *(ambient_dim, nvertices)* :arg simplices: An array *(nelements, nvertices)* of (mesh-wide) vertex indices. """ from meshmode.mesh import Mesh from meshmode.mesh.generation import make_group_from_vertices grp = make_group_from_vertices(vertices, simplices, order) if fix_orientation: from meshmode.mesh.processing import ( find_volume_mesh_element_group_orientation, flip_simplex_element_group) orient = find_volume_mesh_element_group_orientation(vertices, grp) grp = flip_simplex_element_group(vertices, grp, orient < 0) return Mesh(vertices=vertices, groups=[grp], nodal_adjacency=None, facial_adjacency_groups=None)
def from_vertices_and_simplices(vertices, simplices, order=1, fix_orientation=False): """Imports a mesh from a numpy array of vertices and an array of simplices. :arg vertices: An array of vertex coordinates with shape *(ambient_dim, nvertices)* :arg simplices: An array *(nelements, nvertices)* of (mesh-wide) vertex indices. """ from meshmode.mesh import Mesh from meshmode.mesh.generation import make_group_from_vertices grp = make_group_from_vertices(vertices, simplices, order) if fix_orientation: from meshmode.mesh.processing import ( find_volume_mesh_element_group_orientation, flip_simplex_element_group) orient = find_volume_mesh_element_group_orientation(vertices, grp) grp = flip_simplex_element_group(vertices, grp, orient < 0) return Mesh( vertices=vertices, groups=[grp], nodal_adjacency=None, facial_adjacency_groups=None)
def from_meshpy(mesh_info, order=1): """Imports a mesh from a :mod:`meshpy` *mesh_info* data structure, which may be generated by either :mod:`meshpy.triangle` or :mod:`meshpy_tet`. """ from meshmode.mesh import Mesh from meshmode.mesh.generation import make_group_from_vertices vertices = np.array(mesh_info.points).T elements = np.array(mesh_info.elements, np.int32) grp = make_group_from_vertices(vertices, elements, order) # FIXME: Should transfer boundary/volume markers return Mesh(vertices=vertices, groups=[grp], is_conforming=True)
def from_meshpy(mesh_info, order=1): """Imports a mesh from a :mod:`meshpy` *mesh_info* data structure, which may be generated by either :mod:`meshpy.triangle` or :mod:`meshpy_tet`. """ from meshmode.mesh import Mesh from meshmode.mesh.generation import make_group_from_vertices vertices = np.array(mesh_info.points).T elements = np.array(mesh_info.elements, np.int32) grp = make_group_from_vertices(vertices, elements, order) # FIXME: Should transfer boundary/volume markers return Mesh( vertices=vertices, groups=[grp], is_conforming=True)
def test_quad_single_element(visualize=False): vertices = np.array([ [0.91, 1.10], [2.64, 1.27], [0.97, 2.56], [3.00, 3.41], ]).T mg = mgen.make_group_from_vertices(vertices, np.array([[0, 1, 2, 3]], dtype=np.int32), 30, group_cls=TensorProductElementGroup) Mesh(vertices, [mg], nodal_adjacency=None, facial_adjacency_groups=None) if visualize: import matplotlib.pyplot as plt plt.plot(mg.nodes[0].reshape(-1), mg.nodes[1].reshape(-1), "o") plt.show()
def test_quad_mesh_2d(ambient_dim, filename, visualize=False): from meshmode.mesh.io import generate_gmsh, ScriptWithFilesSource logger.info("BEGIN GEN") mesh = generate_gmsh( ScriptWithFilesSource( f""" Merge "{filename}"; Mesh.CharacteristicLengthMax = 0.05; Recombine Surface "*" = 0.0001; Mesh 2; Save "output.msh"; """, [filename]), order=1, force_ambient_dim=ambient_dim, target_unit="MM", ) logger.info("END GEN") logger.info("nelements: %d", mesh.nelements) groups = [] for grp in mesh.groups: if not isinstance(grp, TensorProductElementGroup): # NOTE: gmsh isn't guaranteed to recombine all elements, so we # could still have some simplices sitting around, so skip them groups.append(grp.copy()) continue g = mgen.make_group_from_vertices(mesh.vertices, grp.vertex_indices, grp.order, group_cls=TensorProductElementGroup) assert g.nodes.shape == (mesh.ambient_dim, grp.nelements, grp.nunit_nodes) groups.append(g) mesh_from_vertices = Mesh(mesh.vertices, groups=groups, is_conforming=True) if visualize: from meshmode.mesh.visualization import write_vertex_vtk_file write_vertex_vtk_file(mesh, "quad_mesh_2d_orig.vtu") write_vertex_vtk_file(mesh_from_vertices, "quad_mesh_2d_groups.vtu")
def test_quad_single_element(): from meshmode.mesh.generation import make_group_from_vertices from meshmode.mesh import Mesh, TensorProductElementGroup vertices = np.array([ [0.91, 1.10], [2.64, 1.27], [0.97, 2.56], [3.00, 3.41], ]).T mg = make_group_from_vertices(vertices, np.array([[0, 1, 2, 3]], dtype=np.int32), 30, group_factory=TensorProductElementGroup) Mesh(vertices, [mg], nodal_adjacency=None, facial_adjacency_groups=None) if 0: import matplotlib.pyplot as plt plt.plot(mg.nodes[0].reshape(-1), mg.nodes[1].reshape(-1), "o") plt.show()
def test_quad_single_element(): from meshmode.mesh.generation import make_group_from_vertices from meshmode.mesh import Mesh, TensorProductElementGroup vertices = np.array([ [0.91, 1.10], [2.64, 1.27], [0.97, 2.56], [3.00, 3.41], ]).T mg = make_group_from_vertices( vertices, np.array([[0, 1, 2, 3]], dtype=np.int32), 30, group_factory=TensorProductElementGroup) Mesh(vertices, [mg], nodal_adjacency=None, facial_adjacency_groups=None) if 0: import matplotlib.pyplot as plt plt.plot( mg.nodes[0].reshape(-1), mg.nodes[1].reshape(-1), "o") plt.show()