Пример #1
0
def unstructure_mesh(h):
    mesh_info = MeshInfo()
    # Set the vertices of the domain [0, 1]^3
    mesh_info.set_points([
        (0,0,0), (1,0,0), (1,1,0), (0,1,0),
        (0,0,1), (1,0,1), (1,1,1), (0,1,1),
        ])

    # Set the facets of the domain [0, 1]^3
    mesh_info.set_facets([
        [0,1,2,3],
        [4,5,6,7],
        [0,4,5,1],
        [1,5,6,2],
        [2,6,7,3],
        [3,7,4,0],
        ])
    # Generate the tet mesh
    mesh = build(mesh_info, max_volume=(h)**3)

    point = np.array(mesh.points, dtype=np.float)
    cell = np.array(mesh.elements, dtype=np.int)

    return TetrahedronMesh(point, cell)
Пример #2
0
    def init_mesh(self, n=1, meshtype='tet'):
        node = np.array([
            [0, 0, 0],
            [1, 0, 0],
            [1, 1, 0],
            [0, 1, 0],
            [0, 0, 1],
            [1, 0, 1],
            [1, 1, 1],
            [0, 1, 1]], dtype=np.float)

        cell = np.array([
            [0, 1, 2, 6],
            [0, 5, 1, 6],
            [0, 4, 5, 6],
            [0, 7, 4, 6],
            [0, 3, 7, 6],
            [0, 2, 3, 6]], dtype=np.int)
        mesh = TetrahedronMesh(node, cell)
        mesh.uniform_bisect(n)
        mesh.delete_cell(lambda bc: (bc[:, 0] < 0.5) & (bc[:, 1] < 0.5))
        return mesh
Пример #3
0
    def init_mesh(self, n=2, meshtype='tet'):
        node = np.array([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1],
                         [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]],
                        dtype=np.float64)

        cell = np.array([[0, 1, 2, 6], [0, 5, 1, 6], [0, 4, 5, 6],
                         [0, 7, 4, 6], [0, 3, 7, 6], [0, 2, 3, 6]],
                        dtype=np.int_)
        mesh = TetrahedronMesh(node, cell)
        for i in range(n):
            mesh.bisect()

        NN = mesh.number_of_nodes()
        node = mesh.entity('node')
        cell = mesh.entity('cell')
        bc = mesh.entity_barycenter('cell')
        isDelCell = ((bc[:, 0] > 0) & (bc[:, 1] < 0))
        cell = cell[~isDelCell]
        isValidNode = np.zeros(NN, dtype=np.bool)
        isValidNode[cell] = True
        node = node[isValidNode]

        idxMap = np.zeros(NN, dtype=mesh.itype)
        idxMap[isValidNode] = range(isValidNode.sum())
        cell = idxMap[cell]
        mesh = TetrahedronMesh(node, cell)
        mesh.label()  # 标记最长边

        return mesh
Пример #4
0
mesh_info.set_facets([
    [0, 1, 2, 3],
    [4, 5, 6, 7],
    [0, 4, 5, 1],
    [1, 5, 6, 2],
    [2, 6, 7, 3],
    [3, 7, 4, 0],
])

# Generate the tet mesh
mesh = build(mesh_info, max_volume=(h)**3)

point = np.array(mesh.points, dtype=np.float)
cell = np.array(mesh.elements, dtype=np.int)

tmesh = TetrahedronMesh(point, cell)

# Partition the mesh cells into n parts
edgecuts, parts = metis.part_mesh(tmesh, nparts=n, entity='cell')

point = tmesh.point
edge = tmesh.ds.edge
face = tmesh.ds.face
cell = tmesh.ds.cell
face2cell = tmesh.ds.face2cell
cell2edge = tmesh.ds.cell_to_edge()
face2edge = tmesh.ds.face_to_edge()
isBdPoint = tmesh.ds.boundary_point_flag()

data = {
    'Point': point,
Пример #5
0
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as a3
from scipy.spatial import Delaunay

from fealpy.functionspace import LagrangeFiniteElementSpace
from fealpy.mesh.TetrahedronMesh import TetrahedronMesh
from fealpy.mesh.TriangleMesh import TriangleMesh

degree = 4
point = np.array(
    [[0, 0, 0], [1, 0, 0], [1 / 2, np.sqrt(3) / 2, 0],
     [1 / 2, np.sqrt(3) / 6, np.sqrt(6) / 3]],
    dtype=np.float)
cell = np.array([[0, 1, 2, 3]], dtype=np.int)

mesh = TetrahedronMesh(point, cell)

fig = plt.figure()
axes = fig.gca(projection='3d')
axes.set_aspect('equal')
axes.set_axis_off()
edge0 = np.array([(0, 1), (0, 3), (1, 2), (1, 3), (2, 3)], dtype=np.int)
lines = a3.art3d.Line3DCollection(point[edge0], color='k', linewidths=2)
axes.add_collection3d(lines)
edge1 = np.array([(0, 2)], dtype=np.int)
lines = a3.art3d.Line3DCollection(point[edge1],
                                  color='gray',
                                  linewidths=2,
                                  alpha=0.5)
axes.add_collection3d(lines)
#mesh.add_plot(axes,  alpha=0.3)
Пример #6
0
import numpy as np
import mpl_toolkits.mplot3d as a3
import matplotlib.colors as colors
import pylab as pl

import sys

from fealpy.mesh.TetrahedronMesh import TetrahedronMesh
from fealpy.functionspace.tools import function_space

degree = int(sys.argv[1])

ax0 = a3.Axes3D(pl.figure())

point = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, -1]],
                 dtype=np.float)

cell = np.array([[0, 1, 2, 3], [2, 1, 0, 4]], dtype=np.int)

mesh = TetrahedronMesh(point, cell)
V = function_space(mesh, 'Lagrange', degree)
cell2dof = V.cell_to_dof()
ipoints = V.interpolation_points()
mesh.add_plot(ax0)
mesh.find_point(ax0, point=ipoints, showindex=True)
mesh.print()
print('cell2dof:\n', cell2dof)
pl.show()
Пример #7
0
import numpy as np
import mpl_toolkits.mplot3d as a3
import pylab as pl

from fealpy.mesh.TetrahedronMesh import TetrahedronMesh

node = np.array([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1],
                 [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]],
                dtype=np.float)

cell = np.array([[0, 1, 2, 6], [0, 5, 1, 6], [0, 4, 5, 6], [0, 7, 4, 6],
                 [0, 3, 7, 6], [0, 2, 3, 6]],
                dtype=np.int)

mesh = TetrahedronMesh(node, cell)
mesh.uniform_refine(2)
mesh.print()
fig = pl.figure()
axes = a3.Axes3D(fig)
mesh.add_plot(axes)
mesh.find_node(axes, showindex=True)
pl.show()
Пример #8
0
    point = np.array(mesh.points, dtype=np.float)
    cell = np.array(mesh.elements, dtype=np.int)
elif example == 2:
    point = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [-0.5, -0.5, 0.5],
                      [-0.5, -0.5, -0.5]],
                     dtype=np.float)

    cell = np.array([[0, 1, 2, 3], [0, 2, 1, 4]], dtype=np.int)
elif example == 3:
    point = np.array([(0.0, -np.sqrt(3) / 3, 0.0), (0.5, np.sqrt(3) / 6, 0.0),
                      (-0.5, np.sqrt(3) / 6, 0.0), (0.0, 0.0, np.sqrt(6) / 3)],
                     dtype=np.float)
    cell = np.array([[0, 1, 2, 3]], dtype=np.int)

tmesh = TetrahedronMesh(point, cell)

#isFreePoint = ~tmesh.ds.boundary_point_flag()
#q0 = tmesh.quality()
#for i in range(100):
#    q = tmesh.quality()
#    maxq0 = np.max(q)
#    print(maxq0)
#    print('mean:', np.mean(q))
#    point0 = tmesh.point.copy()
#    grad = tmesh.grad_quality()
#    alpha = 1
#    tmesh.point[isFreePoint] -= alpha*grad[isFreePoint]
#    maxq1 = np.max(tmesh.quality())
#    while (~tmesh.is_valid()) or (maxq1 > maxq0):
#        alpha /=2
Пример #9
0
import mpl_toolkits.mplot3d as a3
import matplotlib.colors as colors
import pylab as pl

import sys

from fealpy.mesh.TetrahedronMesh import TetrahedronMesh

ax0 = a3.Axes3D(pl.figure())

point = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 0, -1]],
                 dtype=np.float)

cell = np.array([[0, 1, 2, 3], [0, 2, 1, 4]], dtype=np.int)

mesh = TetrahedronMesh(point, cell)
c, _ = mesh.circumcenter()
mesh.add_plot(ax0)
mesh.find_point(ax0, point=c)
mesh.print()

#ax1 = a3.Axes3D(pl.figure())
#
#point = np.array([
#    [-1,-1,-1],
#    [ 1,-1,-1],
#    [ 1, 1,-1],
#    [-1, 1,-1],
#    [-1,-1, 1],
#    [ 1,-1, 1],
#    [ 1, 1, 1],
Пример #10
0
import pylab as pl

from fealpy.mesh.TetrahedronMesh import TetrahedronMesh

#point = np.array([
#    [0, 0, 0],
#    [1, 0, 0],
#    [0, 1, 0],
#    [0, 0, 1]], dtype=np.float)
#
#cell = np.array([
#    [0, 1, 2, 3]], dtype=np.int)

point = np.array([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1],
                  [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]],
                 dtype=np.float)

cell = np.array([[0, 1, 2, 6], [0, 5, 1, 6], [0, 4, 5, 6], [0, 7, 4, 6],
                 [0, 3, 7, 6], [0, 2, 3, 6]],
                dtype=np.int)

mesh = TetrahedronMesh(point, cell)
for i in range(3):
    angle = mesh.dihedral_angle()
    print("max:", np.max(angle))
    print("min:", np.min(angle))
    mesh.uniform_refine()
ax0 = a3.Axes3D(pl.figure())
mesh.add_plot(ax0)
pl.show()
Пример #11
0
from fealpy.mesh.TriangleMesh import TriangleMesh
from fealpy.mesh.TetrahedronMesh import TetrahedronMesh

p1 = np.array([0, 1], dtype=np.float)
c1 = np.array([0, 1], dtype=np.int)

p2 = np.array([(0, 0), (1, 0), (0, 1)], dtype=np.float)
c2 = np.array([(0, 1, 2)], dtype=np.int)

mesh2 = TriangleMesh(p2, c2)
mesh2.print()

p3 = np.array([(0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1)], dtype=np.float)

c3 = np.array([(0, 1, 2, 3)], dtype=np.int)
mesh3 = TetrahedronMesh(p3, c3)

fig = plt.figure()
a1 = fig.add_subplot(1, 3, 1)
a2 = fig.add_subplot(1, 3, 2)
a3 = fig.add_subplot(1, 3, 3)
a1.set_title('1-simplex')
a2.set_title('2-simplex')
a3.set_title('3-simplex')

mesh2.add_plot(a2)
#mesh2.find_point(a2, showindex=True)

mesh2.add_plot(a3)
#mesh2.find_point(a3, showindex=True)
Пример #12
0
import numpy as np
from fealpy.mesh.TetrahedronMesh import TetrahedronMesh
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

node = np.array([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1],
                 [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]],
                dtype=np.float)

cell = np.array([[0, 1, 2, 6], [0, 5, 1, 6], [0, 4, 5, 6], [0, 7, 4, 6],
                 [0, 3, 7, 6], [0, 2, 3, 6]],
                dtype=np.int)

mesh = TetrahedronMesh(node, cell)
mesh.bisect()
mesh.bisect()
mesh.bisect()
mesh.bisect()
fig = plt.figure()
axes = fig.gca(projection='3d')
mesh.add_plot(axes, alpha=0, showedge=True)
mesh.find_node(axes)
mesh.find_edge(axes)
mesh.find_cell(axes)
plt.show()