示例#1
0
from fealpy.functionspace.tools import function_space
from fealpy.mesh.TriangleMesh import TriangleMesh

degree = int(sys.argv[1])

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

mesh = TriangleMesh(point, cell)
V = function_space(mesh, 'Lagrange', degree)

ipoints = V.interpolation_points()
cell2dof = V.cell_to_dof()
fig, axes = plt.subplots(1, 3)
mesh.add_plot(axes[0])
mesh.find_point(axes[0], point=ipoints, showindex=True)

for ax in axes.reshape(-1)[1:]:
    ax.axis('tight')
    ax.axis('off')

axes[1].table(cellText=cell,
              rowLabels=['0:', '1:'],
              loc='center',
              fontsize=100)
axes[1].set_title('cell', y=0.7)
axes[2].table(cellText=cell2dof,
              rowLabels=['0:', '1:'],
              loc='center',
              fontsize=100)
示例#2
0
import sys

import numpy as np

import matplotlib.pyplot as plt

from fealpy.mesh.TriangleMesh import TriangleMesh

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

tmesh = TriangleMesh(point, cell)
fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes)
tmesh.find_point(axes, showindex=True)
tmesh.find_edge(axes, showindex=True)
tmesh.find_cell(axes, showindex=True)
plt.show()
示例#3
0
# Set the facets of the domain [0, 1]^2
mesh_info.set_facets([
    [0,1],
    [1,2],
    [2,3],
    [3,0]
    ])

# Generate the tet mesh
mesh = build(mesh_info, max_volume=(h)**2)
node = np.array(mesh.points, dtype=np.float)
cell = np.array(mesh.elements, dtype=np.int)
tmesh = TriangleMesh(node, cell)

fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes, cellcolor='w')

trirr = TriRadiusRatio(tmesh)
q = trirr.get_quality()
print('q=',max(q))
trirr.iterate_solver()
q = trirr.get_quality()
print('q=',max(q))

fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes, cellcolor='w')
#axes.quiver(tmesh.node[:, 0], tmesh.node[:, 1], p[:, 0]/NN, p[:, 1]/NN)
plt.show()
示例#4
0
cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int)

p = 0
mesh = TriangleMesh(node, cell)
mesh.uniform_refine()
node = mesh.entity('node')
cell = mesh.entity('cell')
NC = mesh.number_of_cells()
bc = mesh.entity_barycenter('cell')
if p == 0:
    integrator = mesh.integrator(1)
else:
    integrator = mesh.integrator(p + 2)

cellmeasure = mesh.entity_measure('cell')

V = VectorLagrangeFiniteElementSpace(mesh, p, spacetype='D')
b = V.source_vector(f2, integrator, cellmeasure)
c = V.scalarspace.source_vector(f1, integrator, cellmeasure)

print(b)
print(c)
print(V.number_of_global_dofs())

fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
mesh.find_node(axes, showindex=True)
mesh.find_cell(axes, showindex=True)
plt.show()
示例#5
0
mesh_info = MeshInfo()
mesh_info.set_points([(0, 0), (1, 0), (1, 1), (0, 1)])
mesh_info.set_facets([[0, 1], [1, 2], [2, 3], [3, 0]])
h = 0.05
mesh = build(mesh_info, max_volume=h**2)
node = np.array(mesh.points, dtype=np.float)
cell = np.array(mesh.elements, dtype=np.int)

NC = cell.shape[0]

n = NC // size
r = NC % size
elmdist = np.zeros(size + 1, dtype=np.int)
elmdist[1:] = n
elmdist[1:r + 1] += 1
elmdist = np.add.accumulate(elmdist)

eptr = np.arange(0, 3 * (elmdist[rank + 1] - elmdist[rank] + 1), 3)
eind = cell[elmdist[rank]:elmdist[rank + 1]].flatten()

edgecuts, part = pyparmetis.part_mesh(5, elmdist, eptr, eind, comm)

tmesh = TriangleMesh(node, cell)
tmesh.celldata['cell_process_id'] = part
fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes, cellcolor='w', markersize=200)
tmesh.find_cell(axes, color=tmesh.celldata['cell_process_id'])
plt.show()
示例#6
0
from scipy.spatial import Delaunay
from fealpy.functionspace import LagrangeFiniteElementSpace
from fealpy.mesh.TriangleMesh import TriangleMesh

degree = 4

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

mesh = TriangleMesh(point, cell)

fig = plt.figure()
axes = fig.gca()
axes.set_aspect('equal')
axes.set_axis_off()
mesh.add_plot(axes, cellcolor='w', linewidths=2)
mesh.find_point(axes, showindex=True, color='k', fontsize=20, markersize=25)

V = LagrangeFiniteElementSpace(mesh, degree)
ldof = V.number_of_local_dofs()
ipoints = V.interpolation_points()
cell2dof = V.dof.cell2dof[0]
ipoints = ipoints[cell2dof]

d = Delaunay(ipoints)
mesh2 = TriangleMesh(ipoints, d.simplices)

fig = plt.figure()
axes = fig.gca()
axes.set_aspect('equal')
axes.set_axis_off()
示例#7
0
文件: simplex.py 项目: pgh79/fealpy
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)

plt.show()
示例#8
0

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

tmesh = TriangleMesh(node, cell)
tmesh.uniform_refine(0)

node = tmesh.entity('node')
cell = tmesh.entity('cell')
ismarkedcell = np.array([True, False])
tritree = Tritree(node, cell, irule=1)
tritree.refine(ismarkedcell)
pmesh = tritree.to_conformmesh()

fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes, cellcolor='w', linewidths=1.5)
#tritree.find_node(axes, showindex=True)
#tmesh.find_cell(axes, showindex=True)
#tritree.find_edge(axes, showindex=True)
plt.show()

#fig = plt.figure()
#axes = fig.gca()
#tmesh.add_plot(axes)
#tmesh.find_node(axes, showindex=True)
#tmesh.find_edge(axes, showindex=True)
#tmesh.find_cell(axes, showindex=True)
#plt.show()
示例#9
0
import numpy as np 
import matplotlib.pyplot as plt 
from fealpy.mesh.TriangleMesh import TriangleMesh
#%matplotlib inline
# 网格顶点坐标数组
node = np.array([
    (0, 0), 
    (1, 0), 
    (1, 1),
    (0, 1)], dtype=np.float)
# 单元顶点编号数组
cell = np.array([
    (1, 2, 0), 
    (3, 0, 2)], dtype=np.int)
tmesh = TriangleMesh(node, cell) # 三角形网格实例
print(node)
print(cell)
fig, axes = plt.subplots(1,1,figsize=(8,4))
tmesh.add_plot(axes[0], cellcolor = 'r')
#tmesh.find_node(axes[0], showindex = True, markersize = 25, fontsize = 12)
#tmesh.find_cell(axes[0], showindex = True, markersize = 25, fontsize = 12)
axes[0].set_title('mesh')
plt.show()